Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id F28449FB776 for ; Mon, 5 Mar 2007 08:57:18 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 57145-01 for ; Mon, 5 Mar 2007 08:57:15 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from tiggs.net (206-223-169-74.beanfield.net [206.223.169.74]) by postgresql.org (Postfix) with ESMTP id 0A41C9FB73B for ; Mon, 5 Mar 2007 08:57:16 -0400 (AST) Received: from localhost (206-223-169-82.beanfield.net [206.223.169.82]) by tiggs.net (Postfix) with ESMTP id B0AB327E4F2; Mon, 5 Mar 2007 06:57:17 -0600 (CST) Received: from tiggs.net ([206.223.169.74]) by localhost (mx1.hub.org [206.223.169.82]) (amavisd-new, port 10024) with ESMTP id 67966-10; Mon, 5 Mar 2007 12:57:17 +0000 (UTC) Received: from [10.0.1.201] (unknown [68.187.34.210]) by tiggs.net (Postfix) with ESMTP id D79E427E4BD; Mon, 5 Mar 2007 06:57:16 -0600 (CST) Message-ID: <45EC13B1.3070601@tiggs.net> Date: Mon, 05 Mar 2007 06:57:21 -0600 From: Charley Tiggs User-Agent: Thunderbird 1.5.0.10 (Macintosh/20070221) MIME-Version: 1.0 To: mikie CC: pgsql-php@postgresql.org Subject: Re: transactions from PHP - double COMMIT required? References: <45E70C9A.200@bugs.unl.edu.ar> <200703011353.07621.xzilla@users.sourceforge.net> <45E81DC5.6090308@bugs.unl.edu.ar> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.136 tagged_above=0 required=5 tests=BAYES_50, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200703/22 X-Sequence-Number: 3734 mikie wrote: > Perhaps I should ask again: is it my responsibility to check if the > transaction failed and issue a ROLLBACK command, or will the PG server > do it automatically? If it were me, I'd assume that responsibility as a matter of course. Several folks here have given you names of abstraction layers that will make that simple for you. By using ADOdb or PearDB or MDB, if the transaction fails, it will rollback for you. If you're not going to use one of those abstraction layers, assume that your request is going to fail and capture the error and rollback yourself. At least then, you're guaranteed a rollback no matter what you pass to the server. Try this: In a text file, enter all of your queries. Start with "BEGIN;" and end with "COMMIT;". Be sure to include the error that you mentioned at the appropriate place. Login to db using psql command line utility and issue the following command: \i /path/to/file_with_commands.txt On my system, when I encounter the error, it does not automatically issue a rollback. I have to issue the rollback manually. However, if I run the file as follows: psql mydb myusername -f /path/to/file_with_commands.txt The file will be processed to the end and a rollback will be issued. At point of error, I start seeing entries about transaction aborted, waiting til end of file to rollback. I think libpq behaves as if you are using the \i switch from within the psql shell. Charley