hi Tim and all - it's been a long time :)

Stas and I just ran across something interesting concerning Apache::DBI and $dbh 
attributes.  I think it involves a both a bug and a place for enhancements.

we all know how Apache::DBI works - it stashes away $dbh based on connect string info. 
however, connect string info is limiting, so nice thing to do is strip down your 
connect() 
call to the bare minimum and add attributes to $dbh after the fact:

my $dbh = DBI->connect($dbase, $user, $pass);
$dbh->{AutoCommit} = 0;

well, this works, but only for AutoCommit.  the other $dbh-only attributes (like 
RowCacheSize) are inherited by future $dbh instantiations under Apache::DBI.  I think 
this 
is a bug, since the DBI docs indicate that these attributes are local to the current 
$dbh, 
yet AutoCommit and RowCacheSize behave differently (see sample handler below).

now, mind you, it is still the same $dbh technically, since Apache::DBI just stashes 
it 
away, so it may not be a bug.  the problem I have is that it is DWIMy for AutoCommit 
but 
not for the other attributes.

to take this a step further, what would be really DWIMy is for DBI to clear all of the 
$dbh attributes not specified in the connect() call (including stuff like LongReadLen) 
if 
dbi_connect_method = 'Apache'.  that seems like the right thing, since with 
Apache::DBI 
wat we want a "new" $dbh, just without the connect overhead.  and DBI seems like a 
reasonable place to do it, especially since DBI->connect is kinda action-at-a-distance 
anyway wrt Apache::DBI.

maybe I'm missing something design-wise, though?

anyway, thanks for listening...

--Geoff

package CommitTest;

use Apache::Constants qw(OK);
use DBI;

use strict;

sub handler {

   my $r = shift;

   my @connect = qw(dbi:Oracle:HELM geoff geoff);

   $r->send_http_header('text/plain');

   my $dbh = DBI->connect(@connect) or die $DBI::errstr;

   print "AutoCommit is: ", $dbh->{AutoCommit}, "\n";
   print "RowCacheSize is: ", $dbh->{RowCacheSize}, "\n";

   $dbh->{AutoCommit} = 0;
   $dbh->{RowCacheSize} = 1;

   print "AutoCommit is now: ", $dbh->{AutoCommit}, "\n";
   print "RowCacheSize is now: ", $dbh->{RowCacheSize}, "\n";

   $dbh = DBI->connect(@connect) or die $DBI::errstr;

   print "AutoCommit for new dbh is: ", $dbh->{AutoCommit}, "\n";
   print "RowCacheSize for new dbh is: ", $dbh->{RowCacheSize}, "\n";

   print "done\n";

   return OK ;
}

1;

Reply via email to