On Thu, Nov 14, 2013 at 02:07:41PM -0800, David E. Wheeler wrote:
> On Nov 14, 2013, at 9:17 AM, David E. Wheeler <da...@justatheory.com> wrote:
> 
> > The error about "foo" not existing is gone, overridden by the second
> > error about "bar" missing. This can lead to hard-to-find bugs. What
> > if the second query depended on a condition set up by the first, and
> > the first failed? As a user, I would only see the second error, and
> > think that the first statement had succeeded. It would take me quite
> > a while to figure out that it had not, in fact, succeeded.

You'd need to write the callback code in the way you'd naturally write
it when not using RaiseError. Which typically means something like:

    $dbh->do('SET search_path = ?', undef, 'foo')
        or return;

> I’m also finding it means I can’t do error handling in the callback.

I'm not sure what you mean there.

> I have to do this to get it to ignore errors:
> 
>                         $dbh->do('SET search_path = ?', undef, 'foo');
>                         $dbh->set_err(undef) if $dbh->err;
> 
> I feel a little dirty.

Ignoring errors isn't a common action.

> > All of which is to say, your fix in 1.630 certainly improves the
> > situation, but since callbacks are really userland code, I think it
> > would be beneficial to change callbacks to run in an outer context,
> > with the outer DBI handles passed to them. Possible?
> 
> This would eliminate all of these problems, no?

Probably. There are three main down-sides to consider:
1. compatibility - the risk of breaking some existing callback code
2. performance - the cost of getting the outer handle
3. pure-perl compatibility

There is an undocumented DBI::_handles function that returns the inner
and outer handles for a given (inner or outer) handle. Perl code within
DBI.pm, such as the connect_cached callback logic, would need to call
that (or something like it) to get the outer handle to pass to the callback.

The DBI::_handles implementation in lib/DBI/PurePerl.pm doesn't support
getting the outer handle from an inner one. That's probably fixable by
adding a weakref.

I don't have a strong opinion on this.

Tim.

Reply via email to