I have noticed that START TRANSACTION
automatically COMMIT
the previous queries. Because of this and the fact that I have several stored procedure called before the end of the whole transaction, I need to check if I am inside a START TRANSACTION
or not. Reading the manual I understood that autocommit is set to false inside a START TRANSACTION
, but it doesn't seem like this. I have written 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';
show autocommit=ON while I expected the second to be autocommit=OFF.
How can I check if I am inside a START TRANSACTION
?
I need to perform this check because I have procedure1 that need START TRANSACTION
then it calls procedure2 that also need START TRANSACTION
. But let's suppose I have a third procedure different_procedure that also need to call procedure2 but in this case different_procedure doesn't use START TRANSACTION
. In this scenario I need procedure2 to check if START TRANSACTION
was initiated. I hope this is enough clear.
FUNCTION
approach does not work anymore. See bugs.mysql.com/bug.php?id=102531 for reference. However, doing the same thing as aPROCEDURE
with anout
parameter still seems to work in 5.7 and 8.0. – Tranquilizer