views:

30

answers:

1

How can i find out if there is transaction open in mySQL? I need to start new one if there is no transaction open, but i don't want to start new one if there is one running, because that would commit that running transaction.

UPDATE:

i need to query database in one method of my application, but that query could be called as part of bigger transaction, or just as it should be a transaction on its own. Changing application to track if it has open a transaction would be more difficult, as it could started from many pieces of code. Although it would be possible, i'm looking for solution that would be faster to implement. Simple if statement in sql would be effortless.

Thank you

A: 

I am assuming you are doing this as a one-off and not trying to establish something that can be done programatically. You can get the list of currently active processes using: SHOW PROCESSLIST

http://dev.mysql.com/doc/refman/5.1/en/show-processlist.html

If you want something programatic, then I would suggest an explicit lock on a table, at the beginning of your transaction and release it at the end.

W Devauld
no, i want to be able to do it programatically. It doesn't sound like something that couldn't be done, but i didn't find anything which would indicate it's possible :|
praksant