Is it possible to obtain the SQL statements generated by Class::DBI?
Question
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?
Solution
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');
OTHER TIPS
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).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow