LEGAL
#===========================================================================
Copyright (C) 2008 by Nik Ogura. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Bug reports and comments to nik.ogura@gmail.com.
#===========================================================================
NAME
CGI::Lazy::DB
SYNOPSIS
use CGI::Lazy;
my $q = CGI::Lazy->new('/path/to/config/');
my $dbh = $q->db->dbh; #just get the dbh, and use it by hand
$q->db->do('select...."); #use the db object's abstraction for queries with no return value
my $value = $q->db->getarray($query, @binds); #get an array of arrays.
my $value = $q->db->gethash($query, $binds, $key ); #get a hash of hashes
my $value = $q->db->gethashlist($query, @binds); #get ordered array of hashrefs. (This is probably the most useful)
DESCRIPTION
CGI::Lazy database object. Contains convenience methods for common db operations and holds base database handle for object.
METHODS
config ()
Returns config object.
dbh
Returns default database handle
do ( query, binds )
Runs a given query with bind values specified. Does not expect a return value
query
raw sql to be run
binds
array or literal values to be bound
get ( query, binds )
Runs a given query with bind values specified. Returns first value found.
query
raw sql to be run
binds
array ref to values to be bound or list of binds. If first element is a reference, it will be assumed that that is an array ref and it is all of the binds
getarray ( query, binds )
Runs a given query with bind values specified. Returns array of arrays from DBI::fetchall_arrayref
query
raw sql to be run
binds
array ref to values to be bound or list of binds. If first element is a reference, it will be assumed that that is an array ref and it is all of the binds
gethash ( query, binds, key )
Runs a given query with bind values specified. Returns hashref from DBI::fetchall_hashref
query
raw sql to be run
binds
array ref to values to be bound
key
field to use as key for main hash
gethashlist ( query, binds )
Runs a given query with bind values specified. Returns array of hashrefs
query
raw sql to be run
binds
array ref to values to be bound or list of binds. If first element is a reference, it will be assumed that that is an array ref and it is all of the binds
new ( q )
Constructor. Builds or inherits database handle and returns DB object.
Database handles may be handled in one of 3 ways:
1) built from username, password, and connect string specified in the config file
2) build in the cgi and explicitly passed to the Lazy object on object creation.
3) a known variable that is in scope in the cgi can be specified, in which case the program will look for this variable, and pick it up.
Note: with mod_perl option 3 is a little more hairy. You will need to specify the mod_perl request handler being used, e.g. ModPerl::Registry or ModPerl::PerlRun in the apache config.
q
Lazy Object
q ()
Returns CGI::Lazy object
recordset ( args )
Creates and returns a CGI::Lazy::DB::RecordSet object.
See CGI::Lazy::DB::RecordSet for more information.
args
hashref of RecordSet properties
type ()
Returns driver type from database handle object. Necessary for specifying different behaviors dependant on databse capabilities.