By ralt on
Hi,
If I lock a table during a hook - let's say, before inserting datas into the database, will it be locked until I unlock it myself in another hook - say, after datas are submitted ? The question is : will the lock be preserved until I unlock it?
Comments
Can't be 100% sure without
Can't be 100% sure without testing but looking at the code for db_lock_table it seems the table would remain locked (regardless of how many functions you pass through) until you call db_unlock_tables. db_lock_table doesn't set any global or static variables it just performs a MySQL query to put a lock on the table, so the lock would be held with MySQL and not PHP/Drupal. I can only assume that the lock wouldn't be lifted until another database call was made to unlock the tables, which is what db_unlock_tables does.
There's no guarantee though that another function (outside of the scope of your custom modules) won't call db_unlock_tables itself in the middle of your code processing, which would obviously then release the lock on your table.
Hope that helps!