in reply to Printing SQL query in Perl
I'm assuming you want to do it for more than the one SQL statement you showed. I've no idea what exec_select is - it is not a DBI method but I presume at some stage in your code something calls the prepare and execute methods and you have that statement handle. You can use the Statement attribute to retrieve the SQL executed and the ParamValues attribute to get the bound parameters something like this:
my $s = $h->prepare(q/select * from mje where a = ?/); $s->execute(1); my $sql = $s->{Statement}; my $pvals = $s->{ParamValues}; my $params = ''; foreach (keys %$pvals) { $params .= " $_ = $pvals->{$_}" } print "$sql $params\n"; # outputs select * from mje where a = ? 1 = 1
Now if you look at DBI callbacks you can add a callback to the execute method and output whatever you like.
However, I naturally find DBIx::Log4perl much more straight forward to as use as I wrote it.
|
|---|