On 11/4/05, Mark Stosberg <[EMAIL PROTECTED]> 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?

Apache::DBI overrides disconnect so that it effectively becomes a
no-op.  If you closed your database handles after every request, it
kind of defeats the purpose of Apache::DBI.  But what you are
proposing would not affect or conflict with Apache::DBI (if that was
the question).

> 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.

I think a config option to disconnect the database (if it was
connected) at the teardown phase would be fine.

One thing that does bring up is that someone might want to register a
hook at the teardown stage that requires the database.  It might be
nice if you added a 'dbh_teardown' hook.  It would get called at the
standard CGIApp teardown stage, but it happens just before the
database is disconnected.

An example of what someone might want to do at the teardown phase
would be a logging system that writes some statistics to a database
based on the request.

Cheers,

Cees

---------------------------------------------------------------------
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