Re: taking actions on rollback (PHP)

From: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: taking actions on rollback (PHP)
Date: 2008-04-26 22:19:03
Message-ID: 20080427001903.626b7684@dawn.webthatworks.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, 26 Apr 2008 23:14:07 +0200
Martijn van Oosterhout <kleptog(at)svana(dot)org> wrote:

> On Sat, Apr 26, 2008 at 10:52:12PM +0200, Ivan Sergio Borgonovo
> wrote:
> > How am I going to see if the transaction succeeded without
> > checking what happens for each statement and getting the cleanup
> > code execute?
>
> You basically actually check for the errors in the earlier
> pg_query() calls, since they will tell you. If you can't be
> bothered, you could just do at the end of the transaction:

> if( !pg_query("select 1") )
> pg_query("rollback');
> // DO CLEANUP HERE
> }
> else
> { pg_query("commit"); }

I can guess the logic... but I'd like to be sure I got it.

Why does
if( !pg_query("commit;") )
doesn't report any error back?

So an error stays around and after a failure of any statement after
the begin all the following statement (on the same connection???) will
fail. Is it?

BTW your code had to be changed to
if( !(at)pg_query("select 1") )
pg_query("rollback');
// DO CLEANUP HERE
}
else
{ pg_query("commit"); }

Otherwise php get nervous, fail and the cleanup code doesn't get
executed and furthermore it seems that with a pending failed
transaction other statement fail too.
That was curious since I opened 2 pages from the same browser just to
check if the cleanup code was going to be executed and keep the form
I was submitting easy to be refilled with a back.

Form -> several errors +
ERROR: current transaction is aborted, commands ignored until end of
transaction block

Testing page that give me a view on the tables that should be
cleaned up -> refresh ->
ERROR: current transaction is aborted, commands ignored until end of
transaction block

With the added @ everything seemed to be OK.
I had to refresh a second time to get rid of the error.
I'd like to be sure I've understood how it works since I wouldn't
like the error went away just by chance and under heavy load I may
have troubles.

I'm using pg_connect not pg_pconnect.

Why did I get the
ERROR: current transaction is aborted, commands ignored until end of
transaction block
from 2 different pages?

> Have a nice day,

thanks, you've been very helpful.

--
Ivan Sergio Borgonovo
http://www.webthatworks.it

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert Treat 2008-04-27 00:33:28 Re: How to modify ENUM datatypes?
Previous Message wstrzalka 2008-04-26 22:11:20 PITR problem