dbi debugging aid

gav on 2002-09-19T15:29:41

Want to know what sql you're throwing at the database but you're binding variables. This should do the trick:

use Text::Wrap;
my $temp = $sql;
$temp =~ s/\?/$dbh->quote($_)/e for @data;
print $cgi->pre(wrap('','',$temp));



trace

Matts on 2002-09-19T16:20:41

DBI->trace(2) is your friend.

Bug

vsergu on 2002-09-19T18:50:54

What happens if one of your values contains a question mark? I had a similar bug in the DBI-ish class I was writing in PHP a few weeks back.

Re:Bug

gav on 2002-09-19T21:34:12

Doh. I didn't think of that :(

This works for that case:

my $i = 0;
$temp =~ s/\?/$dbh->quote($data[$i++])/ge;