Snapper - XML Application SourceForge.net Logo  


NAME

SharkAPI::DB.pm -- Database Functions


DESCRIPTION

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);


OBJECT INTERFACE

new ( $dsn, $user, $password, $options )

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:


DATABASE INTERACTION OBJECT INTERFACE

db_sql ( $sql, @args )

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.

db_fetch ( $sth )

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.

db_done ( $sth )

This function executes finish on the statement handle. No logging occurs.

db_log ( &logfunction )

This function sets the logging function to be called for logging operations. The log function is passed the string to log.

db_rows ( $sth )

This function executes rows on the statement handle and returns the result.

db_prep ( $sql )

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.

db_exec ( $sth, @args )

This function executes the statement handle and passes the args array. The result is logged. If the execute fails then an error is logged.


SEE ALSO

perl

Snapper

SharkAPI


AUTHOR

Bill Walz, bill@landsharklinux.com


COPYRIGHT

The SharkAPI::DB module is Copyright (c) 2002 Albacore Technology, LLC The SharkAPI::DB module is commercial licensed software


Valid HTML 4.01!
Content owned by Albacore Technology is copyright 1999-2000 Albacore Technology, LLC All rights reserved.