Setting the DBIC_TRACE environment variable to true:
BEGIN { $ENV{DBIC_TRACE} = 1 }
generates very helpful output, especially showing the SQL query that is being executed, but the SQL query is all on one line.
Is there a way to push it through some kinda "sql tidy" routine to format it better, perhaps breaking it up over multiple lines? Failing that, could anyone give me a nudge into where in the code I'd need to hack to add such a hook? And what the best tool is to accept a badly formatted SQL query and push out a nicely formatted one?
"nice formatting" in this context simply means better than "all on one line". I'm not particularly fussed about specific styles of formatting queries
Thanks!
From the documentation of DBIx::Class::Storage
In other words, you should set
debugobj
in that class to an object that subclasses DBIx::Class::Storage::Statistics. In your subclass, you can reformat the query the way you want it to be.First, thanks for the pointers! Partial answer follows ....
What I've got so far ... first some scaffolding:
And the definition of My::DBIx::Class::Storage::Statistics being:
Which solves the problem about how to hook in to get the SQL query for me to "pretty-ify".
Then I run a query:
However SQL::Parser barfs on the SQL generated by DBIx::Class:
So ... is there a better parser than SQL::Parser for the job?
As of DBIx::Class 0.08124 it's built in.
Just set
$ENV{DBIC_TRACE_PROFILE}
toconsole
orconsole_monochrome
.