0

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

marianboda
  • 771
  • 6
  • 14
  • 1
    Your intent sounds confused. Perhaps if you explained what you were trying to do, we could help suggest a cleaner solution? I've never had to check if a txn was already open, you usually "know" based on code flow... – Steven Schlansker May 10 '10 at 21:18

1 Answers1

0

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
  • 72
  • 4
  • 1
    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 :| – marianboda May 10 '10 at 21:04