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_);
PGresult* must_be_null_ = PQgetResult(connection_);
ConnStatusType status_ = PQstatus(connection_);
if(status_ == CONNECTION_BAD)
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.
Dmitriy Chumack mailto:saint(at)apriorit(dot)com
Software Developer of ApriorIT
pgsql-interfaces by date
|Next:||From: Sandeep Khandelwal||Date: 2006-10-16 07:07:53|
|Subject: Bulk Load and Extract from PostgreSQL|
|Previous:||From: Jeroen T. Vermeulen||Date: 2006-10-12 05:19:16|
|Subject: Re: libpq - check PGconn* - is it valid|