Details
-
Type:
Task
-
Status: Open
-
Priority:
Minor
-
Resolution: Unresolved
-
Fix Version/s: None
-
Component/s: None
-
Labels:
Description
SHORT VERSION: Could we have a START TRANSACTION IF EXISTS that does not commit existing transaction?
–
LONG VERSION:
Sometimes, when a procedure is called, there are possible 2 cases:
1) The procedure has been called by a trigger: I want to continue the active transaction.
2) Called by the cli, I want to be sure that a transaction exists.
But START TRANSACTION commits existing transaction. A snippet like this does NOT solve the problem:
IF NOT @@in_transaction THEN SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; START TRANSACTION; END IF;
Because, if the procedure is called by a trigger, I get:
ERROR 1422 (HY000): Explicit or implicit commit is not allowed in stored function or trigger.
START TRANSACTION IF EXISTS would solve the problem.
Gliffy Diagrams
Attachments
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
technically, you can DECLARE HANDLER to intercept this error. You can even wrap that in a nice procedure, like (not tested)
CREATE PROCEDURE START_TRANSACTION_IF_NOT_EXISTS() BEGIN DECLARE EXIT HANDLER nop FOR MYSQL_ERROR_CODE 1422 BEGIN END; IF NOT @@in_transaction THEN SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; START TRANSACTION; END IF; END