How to test for an existing connection? (ESQL/C)
Posted in 1999
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
Hi- I'm using esql/C in a fastcgi. In my FCGI_Accept() loop I want the program to test to see if a connection exists first and then try to connect if it isn't already. Does anyone know the most elegant way to do this? Is there a simple system query I could perform to do this? I'd like to avoid maintaining a static variable. I also don't want the "connection exists" test to be labor intensive for the database. There must be some simple quey for this right? ideas? expert opinions? I look forward to replies. Ciao, -Michael Sent via Deja.com http://www.deja.com/ Before you buy.
I don't know how fast it is, but the simplest thing is to try getting on with whatever you'd like to do if the connection is there, and see whether it fails with an error indicating that there isn't a connection. Or is that too simplistic? The other question is: can't your Fast CGI code keep track of whether a connection has been created? andisl@idt.net wrote: > I'm using esql/C in a fastcgi. In my FCGI_Accept() loop I want the program > to test to see if a connection exists first and then try to connect if it > isn't already. Does anyone know the most elegant way to do this? Is there a > simple system query I could perform to do this? I'd like to avoid > maintaining a static variable. I also don't want the "connection exists" > test to be labor intensive for the database. There must be some simple quey > for this right? ideas? expert opinions? I look forward to replies. -- Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net) Guardian of DBD::Informix v0.62 -- see http://www.perl.com/CPAN #include <disclaimer.h>
What I'm most interested in is the simplest successful query that is not
dependent on tables that we've created. That way the function is portable to
other informix systems. Some people do...
SELECT current FROM informix.dual
...apparently "dual" is a system table that should always be available. This
is what I have in there now but I'm not sure that it's the best way.
Yes my fast-cgi can keep track of whether or not I'm already connected, but
I was thinking that if the connection was somehow mysteriously broken then
the cgi should be smart enough to reconnect.
-Michael
In article <384C9959.B97F57C3@earthlink.net>,
Jonathan Leffler <jleffler@earthlink.net> wrote:
> I don't know how fast it is, but the simplest thing is to try getting on with
> whatever you'd like to do if the connection is there, and see whether it fails
> with an error indicating that there isn't a connection. Or is that too
> simplistic?
>
> The other question is: can't your Fast CGI code keep track of whether a
> connection has been created?
>
> andisl@idt.net wrote:
>
> > I'm using esql/C in a fastcgi. In my FCGI_Accept() loop I want the program
> > to test to see if a connection exists first and then try to connect if it
> > isn't already. Does anyone know the most elegant way to do this? Is there a
> > simple system query I could perform to do this? I'd like to avoid
> > maintaining a static variable. I also don't want the "connection exists"
> > test to be labor intensive for the database. There must be some simple quey
> > for this right? ideas? expert opinions? I look forward to replies.
>
> --
> Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net)
> Guardian of DBD::Informix v0.62 -- see http://www.perl.com/CPAN
> #include <disclaimer.h>
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
finast@my-deja.com wrote:
> What I'm most interested in is the simplest successful query that is not
> dependent on tables that we've created. That way the function is portable to
> other informix systems. Some people do...
>
> SELECT current FROM informix.dual>
> ...apparently "dual" is a system table that should always be available. This
> is what I have in there now but I'm not sure that it's the best way.
Well, if you think a SELECT is the best way to go, then SELECT TabID FROM
"informix".systables WHERE tabid = 1; is pretty reliable. It will work
on any extant Informix database 4.00 or later.
On the other hand, you could consider something less complex, like:
PREPARE p_testconn FROM "BEGIN WORK";
FREE p_testconn;
This might be defeated if someone executes SET DEFERRED_PREPARE ON,
I suppose, but otherwise should allow you to diagnose a broken
connection.
> Yes my fast-cgi can keep track of whether or not I'm already connected, but
> I was thinking that if the connection was somehow mysteriously broken then
> the cgi should be smart enough to reconnect.
So it should pay attention to the error status of any and every
statement, and if the error is due to a broken connection, it needs
to react appropriately. Obviously, the greatest chance for the
connection breaking is while it is not in use, but it could happen
at any stage.
> In article <384C9959.B97F57C3@earthlink.net>,
> Jonathan Leffler <jleffler@earthlink.net> wrote:
> > I don't know how fast it is, but the simplest thing is to try getting on with
> > whatever you'd like to do if the connection is there, and see whether it fails
> > with an error indicating that there isn't a connection. Or is that too
> > simplistic?
> >
> > The other question is: can't your Fast CGI code keep track of whether a
> > connection has been created?
> >
> > andisl@idt.net wrote:
> >
> > > I'm using esql/C in a fastcgi. In my FCGI_Accept() loop I want the program
> > > to test to see if a connection exists first and then try to connect if it
> > > isn't already. Does anyone know the most elegant way to do this? Is there a
> > > simple system query I could perform to do this? I'd like to avoid
> > > maintaining a static variable. I also don't want the "connection exists"
> > > test to be labor intensive for the database. There must be some simple quey
> > > for this right? ideas? expert opinions? I look forward to replies.
> >
> > --
> > Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net)
> > Guardian of DBD::Informix v0.62 -- see http://www.perl.com/CPAN
> > #include <disclaimer.h>
> >
> >
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
--
Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net)
Guardian of DBD::Informix v0.62 -- see http://www.perl.com/CPAN
#include <disclaimer.h>