Well, that works perfectly, but doesn't do anything :-).

As far as I can tell, because my database connection code is at the top of
my module that the CGI script uses, the code is only run the first time that
the script runs.  If the connection times out and is caught by the eval code
you suggested below, the script writes an error to the log but is still
running because I apparently don't have $r->terminate_child.  The next time
the script runs, it has already evaluated all the code in the module, so it
doesn't try to connect to the database again, and doesn't consult the
%Connected hash and doesn't realize that it doesn't have a connection.  My
script merrily goes on its way calling subs in the module and quickly errors
out.

Pseudo code of my module:
eval {
    &connect_to_database;
};

if($@) {
    &writeerror;
    &clear(%Connected);
}

sub dostuff {
    return &manipulatedatabase;
}

sub dothings {
    return &querydatabase;
}

So, should I rewrite it so that it makes a new connection (but not really
because of Apache::DBI) in each sub, or have the script call a subroutine
that gives it a database handle to pass to each sub, go at it a completely
different way, or am I way off in my analysis of the problem?

Really confused,

Curtis H.

----- Original Message -----
From: "Geoffrey Young" <[EMAIL PROTECTED]>
To: "'Curtis Hawthorne'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, July 31, 2001 11:49 AM
Subject: RE: mod_perl/DBI problem


>
>
> > -----Original Message-----
> > From: Geoffrey Young [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, July 31, 2001 12:46 PM
> > To: 'Curtis Hawthorne'; [EMAIL PROTECTED]
> > Subject: RE: mod_perl/DBI problem
>
> >
> > yup, looks like mod_perl doesn't offer that to windows.
> >
> > well, I don't do windows, but maybe something like this would work...
> >
> > call $dbh->all_handlers, which should return a reference to
> > %Connected.  my
> > thought is that since windows has only one process, that
> > %Connected will
> > only contain a single entry.  removing that entry should have
> > the desired
> > effect...
>
> well, I can see the flaw in this already - it won't work if you connect to
> more than one database, using more than one userid, etc.
>
> but for a single connection it may work ok, otherwise you would have to
> follow the algorithm in Apache::DBI to get the $Idx for your connection
and
> delete that key...
>
> anyway, HTH
>
> --Geoff
>

Reply via email to