Documentation improvement for PQgetResult - Mailing list pgsql-docs

From Daniele Varrazzo
Subject Documentation improvement for PQgetResult
Date
Msg-id AANLkTikP5a0yHUNYJC+p+KadnyNH+Wmbt=QkZ=rZYE9O@mail.gmail.com
Whole thread Raw
Responses Re: Documentation improvement for PQgetResult  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-docs
Hello,

documentation about the PQgetResult function suggests to "[call]
repeatedly until it returns a null pointer, indicating that the
command is done". This has lead psycopg developers to write code with
the pattern:

    while (NULL != (res = PQgetResult(conn))) {
        /* do something with res */
        PQclear(res);
    }

Marko Kreen has pointed out
(http://lists.initd.org/pipermail/psycopg/2010-July/007149.html) that
this can lead to an infinite loop if the connection goes bad at the
rightly wrong time, advising then to check for the connection status
in the middle of the loop. libpq code seems actually returning
PQmakeEmptyPGresult(conn, PGRES_FATAL_ERROR) in case of something
unexpected.

If this is the case (I've not managed to reproduce it but the libpq
code seems clear), shouldn't the function documentation warn for this
risk, advising to check the connection status in the middle of the
loop and bail out if it's bad? Would it be better to perform a check
on the connection or on the result?

Thank you, cheers.

-- Daniele

pgsql-docs by date:

Previous
From: pgsql-docs@news.hub.org
Date:
Subject: pgsql-docs@news.hub.org 32% OFF on Pfizer!
Next
From: Tom Lane
Date:
Subject: Re: Documentation improvement for PQgetResult