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

Re: Documentation improvement for PQgetResult

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
Cc: pgsql-docs(at)postgresql(dot)org, Marko Kreen <markokr(at)gmail(dot)com>
Subject: Re: Documentation improvement for PQgetResult
Date: 2010-08-06 14:20:18
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-docs
Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com> writes:
> 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
> ( 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?


I'm not convinced we need to do anything about that, since AFAIR no one
has ever reported such a failure from the field (which might well
indicate that Marko's analysis is wrong, anyway).  But if we were to do
something about it, changing the documentation would be the wrong
response, because that coding pattern is all over the place.  It'd be
better to kluge PQgetResult so it only returns a bad-connection error
object once per query, or something like that.

			regards, tom lane

In response to


pgsql-docs by date

Next:From: Robert HaasDate: 2010-08-06 17:55:20
Subject: Re: Patch for "big features" section of release notes
Previous:From: Daniele VarrazzoDate: 2010-08-06 13:53:38
Subject: Documentation improvement for PQgetResult

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