libpq: how to retrieve query result?

Started by Вячеслав Блинниковabout 15 years ago4 messagesgeneral
Jump to latest

I retrieve asynchronous queries results using PQgetResult() which returns
NULL not in case of some error, but when results end - so there is no way to
know if database responded successfully or there happened some error?
For example, error can happen when column names are miswritten.

#2Fredric Fredricson
Fredric.Fredricson@bonetmail.com
In reply to: Вячеслав Блинников (#1)
Re: libpq: how to retrieve query result?

On 01/17/2011 09:00 PM, ???????? ????????? wrote:

I retrieve asynchronous queries results using PQgetResult() which
returns NULL not in case of some error, but when results end - so
there is no way to know if database responded successfully or there
happened some error?
For example, error can happen when column names are miswritten.

I'm no authority on this but my understanding is that it if PQsendQuery
returns "OK" the query was successful (for some definition of "successful").

/Fredric

#3Dmitriy Igrishin
dmitigr@gmail.com
In reply to: Вячеслав Блинников (#1)
Re: libpq: how to retrieve query result?

Hey

17 января 2011 г. 23:00 пользователь Вячеслав Блинников
<slavmfm@gmail.com>написал:

I retrieve asynchronous queries results using PQgetResult() which returns
NULL not in case of some error, but when results end - so there is no way to
know if database responded successfully or there happened some error?
For example, error can happen when column names are miswritten.

Use PQresultStatus. See also PQresultErrorField.

--
// Dmitriy.

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Вячеслав Блинников (#1)
Re: libpq: how to retrieve query result?

=?KOI8-R?B?99HexdPMwdcg4szJzs7Jy8/X?= <slavmfm@gmail.com> writes:

I retrieve asynchronous queries results using PQgetResult() which returns
NULL not in case of some error, but when results end - so there is no way to
know if database responded successfully or there happened some error?
For example, error can happen when column names are miswritten.

Huh? You'll get back a PGresult with error status if the query failed.
NULL implies that you already collected the PGresult and there's nothing
more to do.

regards, tom lane