On Sat, Feb 12, 2005 at 04:35:40PM -0800, David Wheeler wrote:
> On Feb 12, 2005, at 10:11 AM, Tim Bunce wrote:
> 
> >>>That's starting to get might complex, isn't it?
> >>
> >>Uh, "mite". :-)
> >
> >Or "mighty", perhaps.
> 
> Quite.
> 
> So, I'm looking at your new_child() stuff, instead.

That's a much bigger can of worms! (And one that's hard to tell how
deep it is before you really get into it. Driver migration issues
may be painful, for example.)

> I'm not entirely 
> clear on how to implement it (DBI->connect() seems pretty 
> complex--necessary?), but it seems to be the best approach to getting 
> what I want (no resetting of attributes in connect_cached()). Is it as 
> simple as:
> 
>   sub new_child {
>       my $handle = shift;
>       my $child = bless {}, 'SomePackage';
>       # Set attributes....
>       return $child;
>   }

No :) Having per-class new_child() method is just a simple repackaging of
the existing DBI::new_dbh (_drh, _sth) functions. That much is simple, I think.

Then add in the setting of attributes. Perhaps by calling a new set_attr(\%attr)
method from within new_child().

> ? And the modifying connect() and friends to use it, perhaps instead of 
> the $connect_closure?

$connect_closure is only used by clone()
DBI->connect and DBI->connect_cached don't need changing.

The DBD::_::connect method then becomes just something like

        my $dbh = $drh->new_child($attr) or return;
        $dbh->connect(...) or return;
        return $dbh;

then we kindly ask driver authors to remove their DBD::foo::dr::connect
method (so the DBI's default one get used) and implement most of
the logic in a new DBD::foo::db::connect method instead.

(The same applies to DBD::foo::db::prepare.)

Then we have to face the fact that driver authors will (naturally) want
their drivers to be compatible with old versions of the DBI.

One way would be to have the driver provide a DBI version compatibility value.
If set to high enough version then the DBI's (internal) load_driver method
would delete DBD::foo::dr::connect if DBD::foo::db::connect exists.

Are you having fun yet? :)

Tim.

Reply via email to