pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bill Moran <wmoran@potentialtech.com>
To: ljb <ljb1813@pobox.com>
Cc: pgsql-php@postgresql.org
Subject: Re: pg_transaction_status() unreliable?!
Date: Mon, 4 May 2009 15:34:21 -0400
Message-ID: <20090504153421.2e940587.wmoran@potentialtech.com> (raw)
In-Reply-To: <gtitqq$26l3$1@news.hub.org>
References: <20090501170302.2eb5eb84.wmoran@potentialtech.com>
	<gtitqq$26l3$1@news.hub.org>

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 ;)

> I think perhaps you are not. You can sometimes sort of get away
> with a single call, but it isn't a good idea to rely on it.

Doesn't make much sense to me.  I know there's only a single query,
and thus I know there's only a single result.

> I duplicated your result by doing the COMMIT but only doing
> pg_get_result once; then pg_transaction_status gave me the odd
> PGSQL_TRANSACTION_ACTIVE. But if I loop on pg_get_result (it returns a
> result handle, then false the next time), I get the expected IDLE status.

It appears as if this has fixed the problem.  It's random enough that
I can't be sure yet, though.  In any event, I owe you a beer at some
point.  Thanks!

-- 
Bill Moran
http://www.potentialtech.com
http://people.collaborativefusion.com/~wmoran/



view thread (6+ messages)  latest in thread

Message-ID: <20090504153421.2e940587.wmoran@potentialtech.com>
Permalink:  ../20090504153421.2e940587.wmoran@potentialtech.com/
Also on:    postgresql.org/message-id/20090504153421.2e940587.wmoran@potentialtech.com

 · 

reply

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, ljb1813@pobox.com
  Subject: Re: pg_transaction_status() unreliable?!
  In-Reply-To: <20090504153421.2e940587.wmoran@potentialtech.com>
  References: <20090501170302.2eb5eb84.wmoran@potentialtech.com> <gtitqq$26l3$1@news.hub.org> <20090504153421.2e940587.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