On Wed, Jun 22, 2005 at 06:21:58PM -0400, Sam Tregar wrote:
> On Wed, 22 Jun 2005, Tim Bunce wrote:
> 
> > I'd rather go with ChildHandles as per the outline in my previous email.
> 
> If you insist.  I don't understand the use of "child" here.  What is
> the "parent"?

For a driver handle the children are the database handles.
For a database handle the children are the statement handles.
$h->{ChildHandles} gives you the children of that handle.

Does that make sense?

> > Your patch uses a global $DBI::active_handles which will grow
> > without bound.
> 
> It is bounded by the number of handles created by a program.  Surely
> that can't be infinite!

Not infinite, but a $dbh->do("INSERT ...") while (...) will create
and destroy a statement handle on each iteration in most drivers.

> > The $dbh->{ActiveHandles} will return _all_ handles, not only those
> > that are the child of the $dbh.
> 
> That's exactly what I need - a way to find all DBI handles.  I'm
> willing to scratch a few adjacent itches though, if it'll get me what
> I need.

Thanks.

> > Using weaken($parent->{ChildHandles}{$h} = $h) avoids the need
> > for a global,
> 
> Do you really want a hash used instead of an array?  It seems like the
> most common operation will be to iterate through the list of handles,
> which suggests an array to me.

True. (I tend to think of hashes for the cheaper delete and random access
behaviour but neither are relevant here.)

We still need to address the purging of destroyed handles.
This should work well enough:

    if ($HAS_WEAKEN && $parent) { # drivers don't have parents
        my $ch = $parent->{ChildHandles} ||= [];
        # purge destroyed handles occasionally
        @$ch = grep { $_ } @$ch if @$ch % 120 == 0 && @$ch;
        push @$ch, $h;
        Scalar::Util::weaken($ch->[-1]); 
    }


> > $dbh->{ChildHandles} will only return children of that $dbh, and
> > $drh->{ChildHandles} can be used to find all the connections for a
> > particular driver handle.
> 
> That makes sense.  So then to find all handles I would iterate through
> %installed_drh and call ChildHandles recursively on down?

Yeap. Most people would just use $dbh->{ChildHandles} and a few
would use $dbh->{Driver}->{ChildHandles} and iterate over those.

Feel free to add a %hash = DBI->installed_drivers; method that'll
return a copy of %installed_drh. It's overdue anyway.

> > There should be no need for any DBI.xs code to support ChildHandles
> > as it lives in the attribute cache as a simple hash ref. It should
> > also 'just work' for DBI::PurePerl.
> 
> I'll give that a try.  I'm not sure about the no-XS part though, since
> it looks to me like DBI.xs has to know about all attributes.  I might
> be missing some magic though.

It only needs to know about those that need special treatment.

> > I'd be grateful if you could rework the patch along those lines.
> 
> Will do.

Thanks Sam.

Tim.

Reply via email to