From: Bill Moran <wmoran@potentialtech.com>
To: Kenneth Marshall <ktm@rice.edu>
Cc: ljb <ljb1813@pobox.com>
Cc: pgsql-php@postgresql.org
Subject: Re: pg_transaction_status() unreliable?!
Date: Mon, 4 May 2009 16:57:04 -0400
Message-ID: <20090504165704.b8a0027d.wmoran@potentialtech.com> (raw)
In-Reply-To: <20090504194806.GC13811@it.is.rice.edu>
References: <20090501170302.2eb5eb84.wmoran@potentialtech.com>
<gtitqq$26l3$1@news.hub.org>
<20090504153421.2e940587.wmoran@potentialtech.com>
<20090504194806.GC13811@it.is.rice.edu>
In response to Kenneth Marshall <ktm@rice.edu>:
> On Mon, May 04, 2009 at 03:34:21PM -0400, Bill Moran wrote:
> > In response to ljb <ljb1813@pobox.com>:
> >
> > > wmoran@potentialtech.com wrote:
> > > >
> > > > I'm having some ugly fun here. It doesn't seem as if
> > > > pg_transaction_status() is reliable in the least.
> > > >
> > > > For example, I'm doing the equivalent of the following:
> > > >
> > > > pg_send_query_params($conn, 'BEGIN', array());
> > > > pg_get_result($conn);
> > > > ... some other queries, each using pg_send_query_params() and
> > > > pg_get_result() ...
> > > > pg_send_query_params($conn, 'COMMIT', array());
> > > > pg_get_result($conn);
> > > > echo pg_transaction_status($conn);
> > > >
> > > > Now, amazingly enough, pg_transaction_status() returns
> > > > PGSQL_TRANSACTION_ACTIVE after the commit. This makes no sense to
> > > > me at all ... it should return PGSQL_TRANSACTION_IDLE, since the
> > > > connection is no longer in a transaction.
> > > >
> > > > Is anyone else seeing this? I have assertions failing all over the
> > > > place because my code thinks that transactions have been left
> > > > uncommitted.
> > >
> > > One needs to loop on pg_get_result() until it returns False. Are you doing
> > > this?
> >
> > No. There's no documented reason that I can see to do so ;)
> >
> Here is the statement in that manual to which he is referring:
>
> PQgetResult
>
> Waits for the next result from a prior PQsendQuery, PQsendQueryParams,
> PQsendPrepare, or PQsendQueryPrepared call, and returns it. A null
> pointer is returned when the command is complete and there will be no
> more results.
>
> PGresult *PQgetResult(PGconn *conn);
>
>
> PQgetResult must be called repeatedly until it returns a null pointer,
> indicating that the command is done. (If called when no command is
> active, PQgetResult will just return a null pointer at once.) Each
> non-null result from PQgetResult should be processed using the same
> PGresult accessor functions previously described. Don't forget to
> free each result object with PQclear when done with it. Note that
> PQgetResult
>
> ...
Not that it says anything about PQtransactionStatus being affected by
the use of it. If I read this literally, PQgetResult could return a
result set that is incomplete, which begs the question: how do I merge
the remaining part of the result set when I get it back next time?
Of course, that's not the intended usage, which leads me to wonder
what's going on when I know factually that I have no more query
results pending, yet I have to call it again (apparently) to update
the client's internal status data structures.
Oh well, I guess that's just the quirks of the client library.
--
Bill Moran
http://www.potentialtech.comhttp://people.collaborativefusion.com/~wmoran/
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: wmoran@potentialtech.com, ktm@rice.edu, ljb1813@pobox.com
Subject: Re: pg_transaction_status() unreliable?!
In-Reply-To: <20090504165704.b8a0027d.wmoran@potentialtech.com>
References: <20090501170302.2eb5eb84.wmoran@potentialtech.com> <gtitqq$26l3$1@news.hub.org> <20090504153421.2e940587.wmoran@potentialtech.com> <20090504194806.GC13811@it.is.rice.edu> <20090504165704.b8a0027d.wmoran@potentialtech.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox