DBI trace?

Andrew Fabbro andrew-wants-no-spam at fabbro.org
Mon Nov 24 21:35:51 CET 2003


Skip Montanaro <skip at pobox.com> wrote:
> I don't know.  What is DBI->trace?  If you describe what you're looking for,
> perhaps someone will have some ideas about whether or not it exists
> currently or might be fairly easily implemented.

I guess that would help, eh?  Sorry ;0

DBI->trace allows you dump the entire conversation between perl and
the database to a file.  It's sort of like running your database calls
with a "-v" to see everything that the call is doing.  There are
various levels of verbosity, depending on how deep you want to get.

It's very helpful for seeing exactly what the parameters passed to
your database are after interpolation, if your program is saying to
the database what you think it is saying, if the database is giving
more error output than you are seeing from perl, etc.

You can do this within the DB - for example, in postgres you can
change the logging levels in the postgresql.conf and bounce the DB. 
But obviously, you don't want to have to bounce the DB every time you
want to debug.

Here's an example (specifically, this was done with
        DBI->trace(1,'/tmp/dbi.log')
in perl):


    -> DBI->connect(dbi:Pg:dbname=SANDBOX, andrew, ****,
HASH(0x834e070))
pg_db_login
    <- connect('dbname=SANDBOX' 'andrew' ...)= DBI::db=HASH(0x8136970)
at DBI.pm
line 582
dbd_db_STORE
    <- STORE('PrintError' 1)= 1 at DBI.pm line 622
dbd_db_STORE
    <- STORE('AutoCommit' 1)= 1 at DBI.pm line 622
dbd_db_STORE
    <- STORE('Username' 'andrew')= 1 at DBI.pm line 625
    <- connect= DBI::db=HASH(0x8136970)
dbd_db_STORE
    <- STORE('dbi_connect_closure' CODE(0x8366194))= 1 at DBI.pm line
639
dbd_st_prepare: statement = >
                SELECT *
                FROM gl
                WHERE transaction_date >= ? AND transaction_date < ?
AND
                        ( account_credit = ? OR account_debit = ? )<
dbd_st_preparse: statement = >
                SELECT *
                FROM gl
                WHERE transaction_date >= ? AND transaction_date < ?
AND
                        ( account_credit = ? OR account_debit = ? )<
    <- prepare('
                SELECT *
                FROM gl
                WHERE transaction_date >= ? AND transaction_date < ?
AND
                        ( account_credit = ? OR account_debit = ? )')=
DBI::st=HASH(0x834de48) at Accounting_Utils.pm line 367
dbd_bind_ph
dbd_st_rebind
dbd_bind_ph
dbd_st_rebind
dbd_bind_ph
dbd_st_rebind
dbd_bind_ph
dbd_st_rebind
dbd_st_execute
    <- execute('2003-10-01' '2003-09-01' ...)= '0E0' at
Accounting_Utils.pm
line 372
dbd_st_FETCH
1   <- FETCH('NAME')= [ 'glid' 'account_debit' 'amount'
'account_credit'
'transaction_date' 'reconciled' 'ref' 'note' 'last_modified'
'modified_by' ] at
Accounting_Utils.pm line 376
dbd_st_fetch
1   <- fetch= undef row-1 at Accounting_Utils.pm line 376
    <- fetchrow_hashref= undef row-1 at Accounting_Utils.pm line 376
    <- finish= 1 at Accounting_Utils.pm line 383
dbd_db_disconnect
    <- disconnect= 1 at Accounting_Utils.pm line 384
dbd_st_destroy
    <- DESTROY= undef at index.cgi line 195
dbd_db_destroy
    <- DESTROY= undef at index.cgi line 195
dbd_st_FETCH
1   <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch
dbd_st_FETCH
1   <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch
dbd_st_FETCH
1   <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190

dbd_st_fetch
dbd_st_FETCH
1   <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch
dbd_st_FETCH
1   <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch
dbd_st_FETCH
1   <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch
dbd_st_FETCH
1   <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch
dbd_st_FETCH
1   <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch
dbd_st_FETCH
1   <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch
dbd_st_FETCH
1   <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch
dbd_st_FETCH
1   <- FETCH('NAME')= [ 'monthyear' 'account_number' 'amount' ] at
index.cgi
line 190
dbd_st_fetch

(etc.)




More information about the Python-list mailing list