From: | Dmitriy Chumack <saint(at)apriorit(dot)com> |
---|---|
To: | pgsql-interfaces(at)postgresql(dot)org |
Subject: | Re: [2] libpq - check PGconn* - is it valid |
Date: | 2006-10-12 15:26:00 |
Message-ID: | 14310614201.20061012182600@apriorit.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-interfaces |
I try to use async libpq functions to test connection to db.
I have such a piece of code:
bool check_connection(PGconn* connection_)
{
int rv_ = PQsendQuery(connection_, "select 0");
PGresult* result_ = PQgetResult(connection_);
if(result_)
PQclear(result_);
PGresult* must_be_null_ = PQgetResult(connection_);
ConnStatusType status_ = PQstatus(connection_);
if(status_ == CONNECTION_BAD)
return false;
else
return true;
}
And I have a few problems with this code:
1) I have to call PQgetResult twice (second call returns null),
otherwice from time to time PQsendQuery will return error
"another command is already in progress".
2) when there is no network connection in call of both PQsendQuery
and PQgetResult, then PQstatus returns CONNECTION_BAD. But when
connection is ok in PQsendQuery call and is bad in PQgetResult
call, then PQstatus returns CONNECTION_OK !!!
3) when there is no connections in PQsendQuery and PQgetResult, then
PQgetResult hangs and it will hang (my patience end after 10
minutes) until a connection come back again. It's better then
PQexec, but not that I need. I want that PQgetResult returns
after a timeout.
I use libpq that comes with PostgreSQL 8.1.3 on Fedora Core 5 x86_64.
Does anyone have any suggestions?
Thanks in advance.
--
Best regards,
Dmitriy Chumack mailto:saint(at)apriorit(dot)com
Software Developer of ApriorIT
From | Date | Subject | |
---|---|---|---|
Next Message | Sandeep Khandelwal | 2006-10-16 07:07:53 | Bulk Load and Extract from PostgreSQL |
Previous Message | Jeroen T. Vermeulen | 2006-10-12 05:19:16 | Re: libpq - check PGconn* - is it valid |