My app consists of a function in which I’m trying to lock a table, update it (using a stored procedure) and then unlock it. The code goes something like:
LOCK TABLE mytable WRITE;
CALL myStoredProc;
UNLOCK TABLES;
When the function is called, it errors out when the CALL myStoredProc; part is executed giving the following error message:
Table 'proc' was not locked with LOCK TABLES
I tried locking mysql.proc along with mytable but that didn’t seem to help. Any ideas on this type of scenario?
Update:
The first stored procedure goes as follows:
CALL mystoredproc2(NOW());
UPDATE mytable SET _column = NOW();
SELECT * FROM mytable WHERE _column > NOW();
As you see, the above stored procedure nests another one. The second one simply contains an update statement:
UPDATE mytable2 SET _column = _now;
FYI: I’ve also locked mytable2 in the lock statement but that doesn’t work either.
I moved the nested
mystoredproc2stored procedure outside themystoredprocas a series of SQL statements and that did the trick.