Click to See Complete Forum and Search --> : [RESOLVED] Transactions


ss1289
05-12-2008, 11:54 AM
Is there any way to determine or check if a transaction is in process? Like in php or something?

chazzy
05-12-2008, 12:27 PM
huh?

ss1289
05-12-2008, 12:35 PM
How to check if "BEGIN" has already been called in SQL but nothing has been called to end the transaction yet?
Basically how to check if I'm in the middle of a transaction.

chazzy
05-12-2008, 03:59 PM
this has more to do with how you interact with the DB than the db itself. you probably want to use an ORM that supports this kind of operation.

ss1289
05-12-2008, 04:04 PM
I figured out that php has a function called pg_transaction_status that returns the status of a transaction. It does just what I needed. Also, the function is written in C.

chazzy
05-12-2008, 05:24 PM
are you using pgsql (maybe he didn't read the sticky at the top of the forum.... )? either way, i don't think that this function is going to give you the information you're looking for (unless i'm still not getting it based on the few words you've mentioned on here). based on the constants that are being returned, it looks like it's more about whether the connection's active or not, and if the server's currently processing data. See:


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.

ss1289
05-12-2008, 05:43 PM
Yea, sorry, I'm using pgsql. I never know whether to post in the php or sql forums with questions like these because I don't know if the solution is in php or sql.

But PGSQL_TRANSACTION_INTRANS was what I was looking for.

I also figured out that I can check it by running "BEGIN" to check to see if it throws a notice returning "transaction already in progress" to see if I already have a transaction running, same for COMMITS and ABORTS about whether a transaction exists.