On Fri, Apr 05, 2002 at 09:25:32PM -0800, Jeff Zucker wrote:
> Tim Bunce wrote:
> >
>
> [other good advice snipped but heeded]
>
> I've added the bitmask checking for IMA_STUB, IMA_KEEP_ERR,
> IMA_COPY_STMT, and IMA_FUNC_REDIRECT.
>
> > > sub set_err {
> > > my($h,$errnum,$msg,$state)=@_;
> > > $msg = $errnum unless defined $msg;
> > > #z
> > > # Avert your eyes if you don't want to see a horrendous kludge
> > > # (and check DBI::var::FETCH for the other half)
> > > $DBI::zerr = $errnum;
> > > ...
> >
> > You can reasonably assume that's going in the wrong direction :)
> > Talk to me about the problems you were trying to solve here.
> > There's bound to be a better way.
>
> The problem is that $DBI::err and friends are not being set. Another
> way I can get around that with almost as good results and without
> inventing any new variables like $DBI::zerr, is to patch DBI.pm like so:
>
> sub DBI::var::STORE {
> return $DBI::var::STORE_PP(@_) if $DBI::PurePerl;
> Carp::croak("Can't modify \$DBI::${$_[0]} special variable")
> }
>
> But maybe I'm missing a more obvious way to let $DBI::err be set on its
> own. Or maybe I'm just not fetching it via the pointers correctly.
The answer probably lies in a good emulation of DBI::var::FETCH,
especially the 'last handle' concept.
$DBI::lasth, $DBI::rows, $DBI::err and friends are tied scalars and
DBI::var::FETCH is called whenever they are accessed. For $DBI::err,
for example, DBI::var::FETCH basically does $DBI::lasth->{err}, and
for $DBI::rows it does $DBI::lasth->rows.
So if you kept a $DBI::PurePerl::lasth set to the handle of the
last DBI method call then implementing DBI::var::FETCH should be
fairly simple.
One slight downside is that $DBI::PurePerl::lasth will hold a reference
to the last handle thus potentially preventing global destruction.
The DBI plays naughty low-level tricks to avoid that.
But we'll need $DBI::PurePerl::lasth to emulate $DBI::lasth so
we have to face it. Optionally using this
http://search.cpan.org/doc/LUKKA/WeakRef-0.01/WeakRef.pm
if available will help.
Tim.