Mark Stosberg wrote:
> Larry offers the following suggesting for disconnecting
> in CAP::DBH to work well in conjunction with lazy loading.
> 
> 
>>From: Larry Leszczynski <[EMAIL PROTECTED]>
>>To: Mark Stosberg <[EMAIL PROTECTED]>
>>
>>Hi Mark -
>>
>>I've been using your C::A::Plugin modules lately - work great, thanks!
>>
>>I'm attaching/appending a small patch to C::A::P::DBH that adds a
>>"dbh_is_connected" method.  This gets me around a problem in my app where
>>I reach the teardown() phase and try to disconnect the database: if it has
>>not yet been connected, it gets connected and then immediately
>>disconnected.  So this lets me do:
>>
>>   $self->dbh->disconnect() if $self->dbh->dbh_is_connected();
>>
>>It can be called with or without a handle name.  If that handle has
>>previously been connected, it returns a true value (actually, the handle
>>name), otherwise it returns 0.
> 
> 
> Does anyone have a better idea? One alternative I thought of is to use the 
> hook
> system to implement this "maybe disconnect" logic automatically at the end of
> the teardown phase.
> 
> I think that should work fine with Apache::DBI. Are there cases where you 
> /wouldn't/
> want the functionality to automatic?

Well Apache::DBI covers the mod_perl world, but how about the FastCGI
and Persistant Perl people? Another factor to consider are the people
who use database pooling (I don't know if any serious C::A heads use it
or not, but hey) like SQL Relay (http://sqlrelay.sourceforge.net/). I
don't know what the practices are with that area.

As long as there's a way to turn it off I think it would be great,
especially if the common case were on by default.

> While Larry's solution is OK, it would seem a shame if it meant that
> most people wouldn't use it to implement identical functionality in
> teardown when that could be automated.

You might even be able to implement it in terms of his suggestion. Add
the is_connected() method and use it in the teardown hook.

-- 
Michael Peters
Developer
Plus Three, LP


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/[email protected]/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to