VUser::ExtLib::SQL - Common functions for handling SQL with in vuser
VUser::ExtLib::SQL contains common functions and features for working with databases. It has both a functional and an object-oriented interface. The OO interface offers more features such as macros.
VUser::ExtLib::SQL->new($cfg, $paramters);
The config hash
{ user => 'foo', password => 'bar', dsn => 'dbi:mysql:database=baz', macros => { 'u' => 'username', 'p' => 'password' } }
Execute a SQL query.
There are a few predefined macros that you can use in your SQL. The values will be quoted and escaped before being inserted into the SQL. You can specify your own custom macros if you use the OO interface for VUser::ExtLib::SQL. See new above.
Unquoted %
This will be replaced by the value of --option passed in when vuser is called.
This will be replaced by the value of $args{option} passed to execute(). option may only match \w or -. For example:
my $db = VUser::ExtUtil::SQL->new(...); my $sth = $db->execute($opts, "select * from foo where bar = %$bar", {bar => 'baz'} ); # Possibly get results with $sth->fetchrow_* $sth->finish;
execute() returns the statement handle after $sth->execute() has been run. Remember to run $sth->finish() on the returned statement handle when you're done with it.
WARNING: This is a very dangerous option and must be handled with care. If you don't need to use it, don't use it.
Replace the option with the unescaped value of the option. This does not use placeholders like the other options above. All quoting, escaping, etc. is left to the caller to handle before passing the value to execute().
Connect to the database.
Returns a DBI database handle.
Randy Smith <perlstalker@vuser.org>
This file is part of vuser. vuser is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. vuser is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with vuser; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
To install VUser::ExtLib::SQL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm VUser::ExtLib::SQL
CPAN shell
perl -MCPAN -e shell install VUser::ExtLib::SQL
For more information on module installation, please visit the detailed CPAN module installation guide.