On Fri, Sep 30, 2005 at 09:25:31AM -0700, Jeff Zucker wrote: > 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()?
It should 'just work', Not that the subclass test http://search.cpan.org/src/TIMB/DBI-1.48/t/30subclass.t has a prepare (only to ++ a counter) but doesn't rebless the handle. Try digging some more. > >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(). Good point. Just copy the values right after the execute. > Did you remove this line on purpose? > > $b = q{NULL} unless defined $b; Yeap. quote() on an undef returns NULL and looks_like_number returns undef (false) for undef. So it wasn't needed. > 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. I'm not sure enough about what you're trying to do. Tim.