Reputation: 8450
I have some code that does a LOCK TABLE on a table in my database.
After the lock, I do a SELECT from this same table. My mysql API interface gives the following error:
mysqlsel/db server: Table 'Mytable' was not locked with LOCK TABLES
According some googling, this relays to the error code: ER_TABLE_NOT_LOCKED
Why would this code generate this error? I would not expect it to give an error if I do not lock it at all, and I certainly do not expect an error if I lock it either.
Upvotes: 2
Views: 1053
Reputation: 8450
I think I solved my own question by 'RTM',
A session that requires locks must acquire all the locks that it needs in a single
LOCK TABLES
statement. While the locks thus obtained are held, the session can access only the locked tables. For example, in the following sequence of statements, an error occurs for the attempt to access t2 because it was not locked in theLOCK TABLES
statement:
I locked multiple tables in separate lock statements,
So if I do:
LOCK TABLES Mytable WRITE
LOCK TABLES Mytable2 WRITE
... a subsequent SELECT FROM Mytable
probably triggers this error...
Upvotes: 1