views:

61

answers:

2

I want to find the exact SQL statements that are generated by a Perl ORM package such as Class::DBI. I am not looking for SQL generated for simple inserts and deletes, but for row modifications that result from slightly complicated object manipulations (inserting rows in a table which is a child of a row in a parent table, for example)

Is there some way to get it?

+2  A: 

Since you said "such as"…

You can set the environment variable DBIC_TRACE to 1 if you are using DBIx::Class (which has a Class::DBI compatibility layer).

David Dorward
I think that DBI::Profile would be similarly useful, although I haven' t tried it and my general loathing of ORMs dissuades me from trying :)
brian d foy
+5  A: 

Class::DBI uses DBI under the hood, so you can enable tracing of all SQL statements via an environment variable:

DBI_TRACE=3=dbi.log your-perl-script

Or inside of Perl, before executing any statements:

use DBI;
DBI->trace(2, 'dbi.log');

See http://search.cpan.org/~timb/DBI/DBI.pm#TRACING

rjh
Thanks - Tried it. Works like a charm :)
Gurunandan