Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 656B39FB83D for ; Thu, 1 Mar 2007 08:19:01 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 21572-04 for ; Thu, 1 Mar 2007 08:18:52 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.228]) by postgresql.org (Postfix) with ESMTP id 177D19FB62C for ; Thu, 1 Mar 2007 08:18:56 -0400 (AST) Received: by nz-out-0506.google.com with SMTP id r28so482810nza for ; Thu, 01 Mar 2007 04:18:55 -0800 (PST) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=Zr0so4OWT6N0bs6IFHnESxkUx/zU2aAiDJzaqU2fryRs8Cp/tdpgMGHfL68rUli3l2lAB9utWlxNwASnqsWfnXTQe+TQbozFxFVJwm0L9CBfVghpI394PbUHXkyPj85VHTO2Pf2dNupIDSkix++C7/1vPZyyReAtgWqwPA3CWPA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=EpP3yyqkHxoQ/T+GgL48hkFHplfAuoNZGzQFVl5/G4qpoDD8cXtvYd6oQjTFm8u/VtB+x39TVomWuKcjnaNkc5SDjW00nj4EEzzomgSkfIer2wJ0Ac59u5f/1368bs5DvqbjL8Qll5G4anpYiUVqsdADo82AnvKUQCvkN3xRKpc= Received: by 10.115.17.1 with SMTP id u1mr251232wai.1172751534979; Thu, 01 Mar 2007 04:18:54 -0800 (PST) Received: by 10.114.113.16 with HTTP; Thu, 1 Mar 2007 04:18:54 -0800 (PST) Message-ID: Date: Thu, 1 Mar 2007 07:18:54 -0500 From: "David Legault" To: mikie Subject: Re: transactions from PHP - double COMMIT required? Cc: pgsql-php@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_61986_6212159.1172751534920" References: <20070301131523.fgfm83nb9y2kgo4c@imp3.uta.fi> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/4 X-Sequence-Number: 3716 ------=_Part_61986_6212159.1172751534920 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline If you are using PHP5 (and the PDO PGSQL) I would suggest you use exceptions to trap the error try { $db->beginTransaction(); // other queries here, if one fails, an exception is thrown $db->commit(); } catch (Exception $e) { // do whatever with error $db->rollback(); } On 3/1/07, mikie wrote: > > > > 2007/3/1, Mihail Mihailov : > > > > Hi, > > > > I think you should use ROLLBACK if the query cannot be executed. > > one can commit only results of the queries that work. > > Try ROLLBACK statement. > > > > The thing is that when I try my transaction from psql console then the > command ROLLBACK is being issued by the postgres server itself right after I > close my transaction with COMMIT;. According to transaction logic and idea - > if something goes wrong then the entire transaction is being cancelled by > ROLLBACK - it is the server responsibility to rollback such transaction. > > Now, when I try to do some inserts within my transaction I don't know if > they will fail or not. Eitherway I am closing my transaction with the > COMMIT; command - is that correct way ? > It works logically OK from within psql console (I start with BEGIN and > then close my sql commands with commit) but it does not work this way from > within PHP script. I believe there is some issue with PHP - I am not sure if > PHP processor applies some changes to my query and thus ignores the commit > command? > > -- > Mike > > ------=_Part_61986_6212159.1172751534920 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline If you are using PHP5 (and the PDO PGSQL) I would suggest you use exceptions to trap the error

try {

 $db->beginTransaction();

 // other queries here, if one fails, an exception is thrown

 $db->commit();
}
catch (Exception $e) {

 // do whatever with error
 $db->rollback();
}

On 3/1/07, mikie < mikie.pl@gmail.com> wrote:


2007/3/1, Mihail Mihailov < Mihail.Mihailov@uta.fi>:
Hi,

I think you should use ROLLBACK if the query cannot be executed.
one can commit only results of the queries that work.
Try ROLLBACK statement.

The thing is that when I try my transaction from psql console then the command ROLLBACK is being issued by the postgres server itself right after I close my transaction with COMMIT;. According to transaction logic and idea - if something goes wrong then the entire transaction is being cancelled by ROLLBACK - it is the server responsibility to rollback such transaction.

Now, when I try to do some inserts within my transaction I don't know if they will fail or not. Eitherway I am closing my transaction with the COMMIT; command - is that correct way ?
It works logically OK from within psql console (I start with BEGIN and then close my sql commands with commit) but it does not work this way from within PHP script. I believe there is some issue with PHP - I am not sure if PHP processor applies some changes to my query and thus ignores the commit command?

--
Mike


------=_Part_61986_6212159.1172751534920--