Tim Bunce wrote:
On Thu, Sep 29, 2005 at 10:49:48AM -0700, Jeff Zucker wrote:
package MyDbi;
use base 'DBI';
package MyDbi::db;
use base 'DBI::db';
sub prepare {
my($self,@connect_args) = @_;
return bless $self->SUPER::prepare(@connect_args), 'MyDbi::st';
}
That prepare (and especially the bless) shouldn't be needed.
(That's one of the ways DBI make subclassing easier.)
Yet when I remove it, normal execute() is called, not the
MyDbi::st::execute(). So how do I get the program to use my overloaded
execute()?
I'd rework it this way (untested):
sub execute {
my($sth,@binds)[EMAIL PROTECTED];
my $rv = eval { $sth->SUPER::execute(@binds) };
return $rv unless $@;
my $stmt = $sth->{Statement};
for my $b (@binds) {
$b = $sth->{Database}->quote($b) unless DBI::looks_like_number($b);
$stmt =~ s/\?/$b/;
}
return $sth->set_err($sth->err, sprintf "Execution Error: %s (Reconstructed SQL =
%s)\n" , $sth->errstr, $stmt));
}
That's good (except we need to catch the $sth->err and $sth->errstr just
after the SUPER::execute, otherwise we're getting the err on the call to
$sth->{Database}->quote().
Did you remove this line on purpose?
$b = q{NULL} unless defined $b;
And as long as I'm asking - is there a better way to do this all (get a
cut-and-pasteable interpolation of the placeholders into the SQL)? I
couldn't see that there is a portable way to do it from within
HandleError or trace.
--
Jeff