I\'m using Perl\'s DBI module. I prepare a statement using placeholders, then execute the query.
Is it possible to print out the final query that was executed without ma
If you don't want to create your own tracer module (as suggested by Sinan), you are better off just trying to print the argument hash before it is passed to $sth->execute()
. This is especially true, since the "Trace" functionality is DBMS dependent and $sth->{Statement}
only returns the SQL placeholder statement. Here's what I did.
...
while (my $row = $csv->getline_hr($fh)) {
my $cval = "";
my $tquery = $query;
foreach my $j (@cols) {
$cval = $row->{$j};
$tquery =~ s/\?/\'$cval\'/;
}
print "$tquery\n\n";
$rc = $sth->execute(@{$row}{@cols});
}
Where I have used Text::CSV... NOTE: This is not exact, due to DBMS implementation dependent handling of {'}s.