SharkAPI::DB.pm -- Database Functions
This module contains some DBI wrappers for the SharkAPI. By using the
simple wrappers a single point of database access and error/status logging
can be achieved, along with code size reduction. Native DBI/DBD functions
can still be used on the object.
Example:
#
# Construct DB object and connect
#
my $dsn = "dbi:Pg:dbname=$dbmain";
my $db = SharkAPI::DB->new($dsn, $user, $pass,{ AutoCommit => 1 });
# setup logging function
$db->db_log(sub {my ($data) = @_;mylog('SQL',$data);});
Example:
#
# Grab Last Order
#
$sth = $db->db_sql(q{
SELECT custnum,custname,address,phone,suburb,ubd,comments,
lastorder_num,lastorder_date,bad_cust,
discount,deliv_charge
FROM customers
WHERE custnum = ?
},$old_cust_id);
@d = $db->db_fetch($sth);
$db->db_done($sth);
New creates the DB object. It either returns the object on
successful creation or undef upon failure. $! is the
error code if any. The object contains the following hash
members:
This function does a prepare on the passed sql statement and then
executes the statement passing the args array. The statement and
execute call along witht the passed args are logged via the logging
function. A DBI statement handle is returned.
If the prepare fails then an error is logged and no statement handle
is returned.
If the execute fails then an error is logged and the statement handle
is cleaned up, and nothing is returned.
This function executes fetchrow on the passed statement handle. If
$self->{'log_fetch'} is non zero then the values returned are
logged via the logging function. The results array is returned.
This function executes finish on the statement handle. No logging
occurs.
This function sets the logging function to be called for logging
operations. The log function is passed the string to log.
This function executes rows on the statement handle and returns the
result.
This function only executes the prepare function on the sql statement
and returns the DBI statement handle. The prepare is logged. If the
prepare fails then nothing is returned.
This function executes the statement handle and passes the args array.
The result is logged. If the execute fails then an error is logged.
perl
Snapper
SharkAPI
Bill Walz, bill@landsharklinux.com
The SharkAPI::DB module is Copyright (c) 2002 Albacore Technology, LLC
The SharkAPI::DB module is commercial licensed software
|