E R wrote:
> Hi,
> 
> I'd like to trace all SQL calls made but also print out the
> information available from caller(). That will give me good
> information about why I am accessing the database.
> 
> Is there a way to do this with DBI (or DBD::Oracle in particular)?
> Can I insert my own trace handler somewhere?
> 
> I am not averse to modifying the source code.
> 
> Thanks,
> ER
> 
> 

DBIx::Log4perl (http://search.cpan.org/dist/DBIx-Log4perl/) will do this
depending on what you mean by "SQL calls". If you mean output the SQL
passed to DBI->prepare directly or via selectxxx_yyyy methods then yes.

You can configure Log::Log4perl to show the call chain also. By default,
DBIx::Log4perl will log all DBI method calls but these can be restricted
to SQL only or other combinations.

It also has the advantages that a) you do not need to change any code
other than your DBI->connect to DBIx::Log4perl->connect b) the logging
can be turned off and on whilst your program is running from an external
defn file c) it logs all DBI method calls which fail with loads of detail.

There are also "undocumented" (I believe) callbacks in DBI you could use
to do something similar. I think Tim may have posted an example of
callbacks some time back.

Martin


Reply via email to