Skip site navigation (1) Skip section navigation (2)

Documentation improvement for PQgetResult

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: pgsql-docs(at)postgresql(dot)org
Cc: Marko Kreen <markokr(at)gmail(dot)com>
Subject: Documentation improvement for PQgetResult
Date: 2010-08-06 13:53:38
Message-ID: AANLkTikP5a0yHUNYJC+p+KadnyNH+Wmbt=QkZ=rZYE9O@mail.gmail.com (view raw or flat)
Thread:
Lists: 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

Responses

pgsql-docs by date

Next:From: Tom LaneDate: 2010-08-06 14:20:18
Subject: Re: Documentation improvement for PQgetResult
Previous:From: pgsql-docsDate: 2010-08-06 03:47:54
Subject: pgsql-docs@news.hub.org 32% OFF on Pfizer!

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group