On Fri, Aug 09, 2002 at 01:47:55AM -0700, Michael G Schwern wrote:
> An Ima::DBI user recently pointed out that DBI->connect_cached is not using
> Apache::DBI like DBI->connect does and DBI->connect_cached has slightly
> different semantics from Apache::DBI.
>
> sub connect_cached {
> # XXX we expect Apache::DBI users to still call connect()
> my ($class, $dsn, $user, $pass, $attr) = @_;
> ($attr ||= {})->{dbi_connect_method} = 'connect_cached';
> return $class->connect($dsn, $user, $pass, $attr);
> }
>
> There's a problem with the logic in the comment above. Apache::DBI is
> supposed to be transparently used by DBI. So, in effect, there are no
> Apache::DBI users. More pragmatically, I write a lot of dual-natured
> programs. Stuff that might be run under Apache::Registry or might be
> a stand-alone. I like using connect_cached() because I don't have to
> store a global $Dbh, but I thought I was getting the performance boosts of
> Apache::DBI where applicable.
>
> So I guess the question is, why doesn't DBI->connect_cached just defer to
> Apache::DBI->connect?
They (slightly) have different semantics so I'd be reluctant to
transparently substitute one for another.
But how about a new method:
DBI->connect_method("connect");
DBI->connect_method("Apache::DBI::connect"); # effectively what "use Apache::DBI;"
does now
DBI->connect_method("connect_cached");
which would set the method name used by DBI->connect when it
calls the drivers connect method:
$drh->$connect_method(...)
Umm, a more general approach would be
$attr = DBI->connect_attributes;
$attr->{dbi_connect_method} = "connect_cached";
where DBI->connect_attributes returns a ref to the hash that provides
default attributes for connect calls.
Tim.