Search Postgresql Archives

Re: pg_query transaction: auto rollback? begin or start?? commit or end???

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

 



Thanks Chris and Karsten. I still don't quite understand why invalid
state/record-mismatch would also not trigger auto rollback. How can I
even include something *outside* a transaction *inside* it- shouldn't
everything between "begin" and "end" be subject to auto rollback no
matter what?

Also what is the best way to check if transaction is 'read write'
after doing 'pg_query("begin transaction read write;", $connection);'.
pg_transaction_status() doesn't quite do it (read write=?=2).

http://us2.php.net/function.pg_transaction_status
"The status can be PGSQL_TRANSACTION_IDLE (currently idle),
PGSQL_TRANSACTION_ACTIVE (a command is in progress),
PGSQL_TRANSACTION_INTRANS (idle, in a valid transaction block), or
PGSQL_TRANSACTION_INERROR (idle, in a failed transaction block).
PGSQL_TRANSACTION_UNKNOWN is reported if the connection is bad.
PGSQL_TRANSACTION_ACTIVE is reported only when a query has been sent
to the server and not yet completed."
Cheers, Bill

On Wed, Jul 23, 2008 at 3:02 AM, Karsten Hilbert
<Karsten.Hilbert@xxxxxxx> wrote:
> On Wed, Jul 23, 2008 at 01:15:30PM +1000, Chris wrote:
>
>> >> Now *any* error inside transaction will trigger auto rollback for
>> >> *all* inserts so I don't need to explicitly issue conditional
>> >> rollback? Also is "begin/commit transaction" == "start/end
>> >> transaction"??
>>
>> What if something gets an invalid state (eg you expect a record to have
>> 'active = 156' but it's something else).
>>
>> So in some cases yes you'll need to do a rollback. On the other hand, if
>> you don't explicitly do a commit, everything is rolled back.
>>
>> Yes "begin" == "start transaction" and "commit" == "end transaction".
>
> "commit" really is not a well-chosen name for what it is. It
> is often clearer to think in terms of the triple
>
> begin
>
>                rollback
> end
>
> where begin/end are the standard begin/end transaction
> commands while rollback is only ever needed when you detect
> a condition someplace logically *outside* the transaction
> itself and based on that want to undo the transaction that
> is in progress.
>
> Because no matter whether you issue commit or rollback - if
> there was an error *inside* the transaction it'll rollback
> in any case (unless the error was handled somehow).
>
> Karsten
> --
> GPG key ID E4071346 @ wwwkeys.pgp.net
> E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346
>
> --
> Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general


[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