Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lock on table

Status
Not open for further replies.

tcardoso

Programmer
Jan 31, 2005
56
PT
Hello

If I do:

Code:
1) mysql_query('LOCK TABLE tablename');
2) mysql_query('SELECT * from tablename where condition=0');
3) if (cond) {
4)  mysql_query('UPDATE tablename SET condition=1 WHERE condition=0');
5) }
6) mysql_query('UNLOCK TABLE tablename');

What happens when another process arrives on 1 and tablename is already locked it wait until the table is unlocked?

Imagine something go very wrong and the code its interrupted in 3) for example, the table will stay locked. How will I solve that/How can I implicity release all locks?

Thanks
 
At worse, you would need to use a mysql command line (ie. telnet or SSH in) and "UNLOCK TABLES;"

This is about all you would need to do
 
Sorry but you didn't answer my question. What happen when another process arrives on LOCK TABLE tablename and the tablename is already locked? He waits? for how long?

the lock table command returns any value? (success or error value)

Thanks
 
Sorry. From the tests that I ran on this, they continue to successfully lock the table. And returns a success message.

SM
 
Yes. but a table is locked, another process arrives the instruction to lock the table, and it can't access it (its locked). So does it wait until the table gets unlocked and it lock the table?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top