[ CC'ing Edmund on this thread in case he is not on the dbi-users list] Tim Bunce wrote: > On Tue, Apr 30, 2002 at 03:34:26PM -0400, Geoffrey Young wrote: > >>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; > > > Don't do that. > > It (connect_cached) stashes away $dbh based on connect string info > *and* all the attributes. You should set all the atributes you > require in the connect() and then not change them later. > > That way connections that require different attributes are sure to > get different handles.
That's actually a mod_perl advisory. Since if you have two scripts wanting to reuse the same connection via Apache::DBI they *must* use the exactly the same connect string. Now if one script wants LongReadLen = 40 and the other LongReadLen = 80, they have to modify that after connect(). If they supply different connect strings, the service will need roughly a twice bigger number of connection, and so on. Is it possible to deep copy $dbh, when handing it off Apache::DBI::connect()? Then any changes will be local and won't affect the cached copy. >>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? > > > I think the Apache::DBI subclass can override the STORE method and > track attribute changes itself. That sounds like a good solution. Edmund? I raised this issue, since in the mod_perl book Eric and I are working on, we say that the connect string shouldn't change in order to be able to reuse connections. I guess we must warn users that any changes to $dbh will persist, which renders the advisory useless and doesn't provide any solution :( __________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com