I noticed that START TRANSACTION automatically COMMIT previous queries. Due to this and the fact that I have several stored procedures called until the end of the whole transaction, I need to check if I am inside START TRANSACTION or not. As I read the manual, I realized that autocommit is set to false inside a START TRANSACTION , but that doesn't look like this. I wrote the following procedure:
CREATE DEFINER=`root`@`localhost` PROCEDURE `test_transaction`() BEGIN show session variables like 'autocommit'; start transaction; show session variables like 'autocommit'; COMMIT; show session variables like 'autocommit'; END
But each show session variables like 'autocommit'; shows autocommit = ON while I was expecting the second to be autocommit = OFF.
How to check if I am inside START TRANSACTION ?
I need to do this check because I have procedure1 that needs START TRANSACTION , then it calls procedure2, which also needs START TRANSACTION . But suppose I have a third different_procedure procedure, which should also call procedure2, but in this case different_procedure does not use START TRANSACTION . In this scenario, I need procedure2 to check if START TRANSACTION been started. Hope this is clear enough.
thanks
source share