Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id C99F0632DA5 for ; Sat, 2 May 2009 23:26:59 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 18939-04 for ; Sat, 2 May 2009 23:26:47 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id 09EEB632D96 for ; Sat, 2 May 2009 23:26:57 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.3/8.14.3) with ESMTP id n432Qnw2086069 for ; Sat, 2 May 2009 23:26:49 -0300 (ADT) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.3/8.14.3/Submit) id n431xs8h074668 for pgsql-php@postgresql.org; Sat, 2 May 2009 22:59:54 -0300 (ADT) (envelope-from news) From: ljb X-Newsgroups: pgsql.interfaces.php Subject: Re: pg_transaction_status() unreliable?! Date: Sun, 3 May 2009 01:59:54 +0000 (UTC) Organization: Hub.Org Networking Services Lines: 33 Message-ID: References: <20090501170302.2eb5eb84.wmoran@potentialtech.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: slrn/0.9.9p1 (Linux) To: pgsql-php@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.666 tagged_above=0 required=5 tests=AWL=-0.666, PLING_QUERY=1.333 X-Spam-Level: X-Archive-Number: 200905/2 X-Sequence-Number: 4022 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? 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. 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.