Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 1904D6324D5 for ; Mon, 4 May 2009 16:34:29 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 30618-10 for ; Mon, 4 May 2009 16:34:24 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.potentialtech.com (internet.potentialtech.com [66.167.251.6]) by mail.postgresql.org (Postfix) with ESMTP id 9456263224A for ; Mon, 4 May 2009 16:34:24 -0300 (ADT) Received: from vanquish.ws.pitbpa0.priv.collaborativefusion.com (pr40.pitbpa0.pub.collaborativefusion.com [206.210.89.202]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.potentialtech.com (Postfix) with ESMTPSA id A263DEBC3F; Mon, 4 May 2009 15:34:22 -0400 (EDT) Date: Mon, 4 May 2009 15:34:21 -0400 From: Bill Moran To: ljb Cc: pgsql-php@postgresql.org Subject: Re: pg_transaction_status() unreliable?! Message-Id: <20090504153421.2e940587.wmoran@potentialtech.com> In-Reply-To: References: <20090501170302.2eb5eb84.wmoran@potentialtech.com> X-Mailer: Sylpheed 2.6.0 (GTK+ 2.14.7; i386-portbld-freebsd7.1) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.333 tagged_above=0 required=5 tests=PLING_QUERY=1.333 X-Spam-Level: * X-Archive-Number: 200905/3 X-Sequence-Number: 4023 In response to ljb : > 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/