Hi All,
Not sure if this is the right pgsql-* "channel" to post to, but I was
hoping maybe someone could answer a question from one of my fellow
developers. Please read below:
So, following the documentation, we wrote a little ASYNC version of
exec. here is the code:
PGresult *PGClient::exec(char *query) {
PGresult *result;
if (conn == NULL) {
ERROR("PGClient calling exec when a connection hasn't been
established yet");
return NULL;
}
if (PQsendQuery(conn,query)==0) {
ERROR("PGClient wasn't able to sendQuery");
return NULL;
}
int socketFD = PQsocket(conn);
pollfd pfd;
pfd.fd = socketFD;
pfd.events = POLLIN|POLLRDHUP;
consumeSome:
if (poll(&pfd,1,PG_EXEC_TIMEOUT*1000) == 0) {
ERROR("PGClient is timing out ");
return NULL;
}
if (PQconsumeInput(conn)==0) {
ERROR("PGClient detected trouble when trying to consumeInput");
return NULL;
}
if (PQisBusy(conn))
goto consumeSome;
result = PQgetResult(conn);
if (PQisBusy(conn)) {
// something is wrong, because this is telling us that there is
more data on the way,
but there shouldn't be.
ERROR("PGClient had a weird case where more data is on its way");
}
PGresult *tempResult=PQgetResult(conn);
if (tempResult!=0) {
// we either had multiple SQL queries that return multiple
results or something weird
happened here, caller should close connection
ERROR("PGClient had a weird case where multiple results were
returned");
}
return result;
}
So, assuming that every query we pass in is just a simple, 1 result-
set-returning query, we should never see PQisBusy returning a non-
NULL after we do the PQgetResult. BUT every now and then, in our
code, the PQisBusy function returns a non-NULL and we get that
ERROR("PGClient had a weird case where more data is on its way")...
BUT when we do tempResult=PQgetResult, then it is ALWAYS null... can
someone please explain how PQisBusy can return true (when we aren't
expecting it to) but then PQgetResult returns nothing?
If there's any knowledge of why PQisBusy returns not-null, yet nothign
comes our of PQgetResult, could you let me know what's going on?
Any help much appreciated!
--Richard
--
Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance