> -----Original Message-----
> From: Curtis Hawthorne [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, July 31, 2001 3:48 PM
> To: Geoffrey Young; [EMAIL PROTECTED]
> Subject: Re: mod_perl/DBI problem
>
>
> 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.
hmph, it's been a while since I've done any Registry.pm work...
basically, all my stuff is OO now, so I use a method handler that inherits
from a base Util class and call
my $dbh = $self->connect;
where Util::connect() contains the eval() construct. that works like a
charm.
I don't understand why the eval() isn't working as it should, but maybe its
a windows thing or maybe I'm missing something - using eval() as an
exception handling mechansim ought to execute the code every time,
regardless of whether perl has seen it already. perhaps its a nested eval()
thing...
at any rate, your suggestions below are good ones to follow - I think you're
on the right path. try creating a util package, or at least a subroutine
within your script that contains the eval() and passes $dbh back to you and
see if that helps. almost there :)
--Geoff
>
> 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
> >
>