X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2FEE29DC82F for ; Sun, 12 Feb 2006 04:58:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 51266-03 for ; Sun, 12 Feb 2006 04:58:13 -0400 (AST) X-Greylist: delayed 00:06:36.761 by SQLgrey- Received: from mail102.csoft.net (lilly.csoft.net [63.111.22.101]) by postgresql.org (Postfix) with SMTP id D59A39DC87E for ; Sun, 12 Feb 2006 04:58:09 -0400 (AST) Received: (qmail 1719 invoked by uid 3922); 12 Feb 2006 08:51:50 -0000 Date: Sun, 12 Feb 2006 03:51:50 -0500 (EST) From: Michael Allman To: pgsql-jdbc@postgresql.org Subject: prepare() method error Message-ID: <20060212031201.V9299@yvyyl> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200602/86 X-Sequence-Number: 14683 Hi all, I've been testing the XA implementation and found a bug. The PGXAConnection prepare(Xid) method may return a value of XA_OK when it should throw an XAException instead. This can lead to an inconsistent TPC outcome. For example, if you attempt to insert a row which violates a uniqueness constraint and then prepare the transaction branch, the prepare() method returns XA_OK erroneously because the PREPARE TRANSACTION statement executes without throwing an exception even though the transaction is not prepared. As a workaround, I've added a query after the PREPARE TRANSACTION query in the prepare() method which searches the pg_prepared_xacts table for a row with the given gid just "prepared". If it doesn't find the corresponding row, it throws an XAException with a suitable error code (I chose XA_RBROLLBACK). It would be cleaner if the driver could determine the success/failure of the PREPARE TRANSACTION statement from the query itself. For instance, have the executeUpdate("PREPARE TRANSACTION " ....) return normally if and only if it actually prepares a transaction. If it doesn't prepare, throw a meaningful SQLException. Michael