NAME
VUser::ExtLib::SQL - Common functions for handling SQL with in vuser
DESCRIPTION
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.
Class Methods
new
VUser::ExtLib::SQL->new($cfg, $paramters);
- $cfg
-
The config hash
- $paramters
-
{ user => 'foo', password => 'bar', dsn => 'dbi:mysql:database=baz', macros => { 'u' => 'username', 'p' => 'password' } }
execute
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 %
- %-option
-
This will be replaced by the value of --option passed in when vuser is called.
- %$option
-
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.
- %\option
-
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().
db_connect
Connect to the database.
Returns a DBI database handle.
Instance Methods
dsn
user
password
AUTHORS
Randy Smith <perlstalker@vuser.org>
LICENSE
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