NAME

DBD::Log - a logging mechanism for the DBI.

SYNOPSIS

  use strict;
  use IO::File;
  use DBD::mysql;
  use DBD::Log;

  my $dbh = DBI->connect("DBI:mysql:database=test");

  my $fh = new IO::File "file", O_WRONLY|O_APPEND;
  $dbh = DBD::Log->new( dbi     => $dbh,
                        logFH   => $fh,
                        logThis => [ 'update', 'select' ],
                      );

  my $sth = $dbh->prepare("UPDATE table SET field=?, other=?, foo=?");
  $sth->execute('green', 'good', 'bar');

  # this logs into 'file':
  #
  # 1105018817    UPDATE table SET field='green', other='good', foo='bar'

  $dbh->dbiLogging(1);
  $sth = $dbh->prepare("SELECT * FROM the_other_table WHERE username LIKE ?");
  $sth->execute('%-idiots');
  $sth->execute('%-guests');

  # this logs
  #
  # 1105018818    [prepare] SELECT * FROM the_other_table WHERE username LIKE ?
  # 1105018818    SELECT * FROM the_other_table WHERE username LIKE '%-idiots'
  # 1105018819    SELECT * FROM the_other_table WHERE username LIKE '%-guests'

DESCRIPTION

Appends logging to the DBI interface, but limits to the executed sql-statements. Written to support all the DBD::Drivers out there, but some (like Oracle) might cause problems.

Do not expect to overload the DBI without any consequences.

REQUIRMENTS

DBI, DBD::Something, IO::File & Carp

FUNCTIONS

logThis()

array-ref of sql-commands (eg: insert, update, delete, etc) to log. If left empty logs; insert, update, delete, select, create & drop

If set to [ 'all' ] logs everything.

logFH()

The filehandle used for logging. You must supply your own, since I just could not figure out if you like to append or overwrite.

dbiLogging()

0 or 1.

If set to 1 will log all the actions/function-calls of/to the DBI interface as well.

dbi()

the $dbh of your script goes in here. $dbh->{LongReadLen} should be set as $dbi->dbi->{LongReadLen}

LOGFORMAT

The logs are tab-seperated and in the following format:

  time    ([$function])    statement    @rest

time

CORE::time of the writedown of the line.

[$function]

The called DBI function. Only when $self->dbiLogging is TRUE.

statement.

The compiled statement.

rest

Any excess parameters to the function that DBD::Log could not parse.

BUGS / QUIRKS / CAVEATS

This does not work well with DBD::Something!

I have not had the opportunity, nor the time, to test this package against all the DBD::Drivers out there. Things might break do to your specific needs.

Why is $dbh->{mysql_insertid} empty?

Since the real DBI is stored in ->dbi, all those special flags are stored there 2. To get to mysql_insert_id(), go fetch $dbi->dbi->{mysql_insert_id}

SEE ALSO

DBI, DBD::Log::Sth

AUTHORS

  Hartog C. de Mik   <hartog@2organize.com>   Lead Developer

COPYRIGHT

(c) 2004 - 2organize, all rights reserved.