开发者

How can i found out if there is transaction open in MySQL?

开发者 https://www.devze.com 2022-12-29 16:16 出处:网络
How can i find out if there is transaction open in mySQL? I need to start new one if there is no transactio开发者_JAVA百科n open, but i don\'t want to start new one if there is one running, because th

How can i find out if there is transaction open in mySQL? I need to start new one if there is no transactio开发者_JAVA百科n 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消