![]() |
|
Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Interpolate binds into SQL on error - DBI subclassingby jZed (Prior) |
on Oct 11, 2005 at 18:51 UTC ( #499253=snippet: print w/replies, xml ) | Need Help?? |
update Added Corion's fix to support questions marks in the bind values. package MyDBI; use base qw(DBI); package MyDBI::db; use base qw(DBI::db); package MyDBI::st; use base qw(DBI::st); sub execute { my($sth,@binds)=@_; my $rv = eval { $sth->SUPER::execute(@binds) }; return $rv unless $@; my $errmsg = $sth->errstr; my $err = $sth->err ; my $stmt = $sth->{Statement}; @binds = map { $sth->{Database}->quote($_) unless DBI::looks_like_number($_); $_; } @binds; $stmt =~ s/\?/shift @binds/eg; return $sth->set_err( $err, sprintf "Execution Error: %s\nReconstructed SQL=\n<\n%s\n>\n" , $errmsg, $stmt ); } 1;
|
|