From: | Forest Wilkinson <lyris-pg(at)tibit(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Empty queries guaranteed to work? |
Date: | 2003-05-27 22:53:26 |
Message-ID: | 41r7dvgk50cs46thfsk7shdbg9tbjeninq@4ax.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Tom Lane mentioned in this post that an empty query can be sent to the
server to determine whether the connection is still good:
http://archives.postgresql.org/pgsql-hackers/2001-10/msg00643.php
Is a query of "" guaranteed to work as long as the connection is good?
What about ";" or " "?
Background:
I am maintaining some postgres client code (C++/libpq) that, during
exception handling for a failed query, must determine whether the
database connection is still good. This check is currently done by
sending a "select version()" query and checking the result. However,
even that simple query fails with PGRES_FATAL_ERROR when the
connection is still good, if executed in an aborted transaction. (I
have no idea why in the world a fatal error would be reported, when
the connection is perfectly good and a rollback is all that's needed.)
I need to be able to distinguish this situation from a real fatal
error, and PQstatus() appears to be unreliable for this purpose. A ""
query that returns PGRES_EMPTY_QUERY seems to be a good indicator that
the connection is good, even within aborted transactions. Now I just
need to know whether this is documented and guaranteed to work.
Suggestions of alternative methods are welcome.
From | Date | Subject | |
---|---|---|---|
Next Message | mallah | 2003-05-27 23:57:54 | Re: Getting rid of accents.. |
Previous Message | Ian Barwick | 2003-05-27 22:15:02 | Re: Getting rid of accents.. |