[Dbix-class] Get generated SQL
matt.lawrence at ymogen.net
Tue Mar 11 16:39:23 GMT 2008
Matt Lawrence wrote:
> Matt S Trout wrote:
>> Have you considered writing some code to interpolate the bind
>> For copy+paste into an SQL CLI prompt it's a bit inconvenient to
>> the ?s manually.
> I was contemplating it, but never got around to it.
>> (we're currently rounding up for 0.8100, so if somebody gets a patch
>> this together in the next week or so with tests you've a good chance of
>> it being applied)
> I'll see if I can find some time this week(end) to finish it off then.
> Where would you recommend the tests to go?
I found some time last night to work on this. I put the tests in a new
file t/as_sql.t, they are pretty basic: just calling each new method
once and checking the output is as expected
There are now 2 cursor methods that are proxied from the resultset:
as_sql and as_static_sql.
as_sql leaves placeholders in the sql string and passes back the raw
values that go into it, as_static_sql replaces the placeholders using
the quote method from DBI, with optional data type mapping via arguments
(either name-based or positional). This seems to me to be an acceptable
compromise between fully-automatic data_type mapping (which seems at
first glance to be non-trivial and usually unnecessary) and total
disregard of data_type (which will bite Pg bytea columns et al)
More information about the DBIx-Class