Search Postgresql Archives

Re: taking actions on rollback (PHP)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 26 Apr 2008 23:14:07 +0200
Martijn van Oosterhout <kleptog@xxxxxxxxx> 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( !@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



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux