KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: LOCK TABLE is only for the current SQL session
PRODUCT: 4D | VERSION: 13.4 | PLATFORM: Mac & Win
Published On: December 20, 2013

When using the SQL command LOCK TABLE it is important to understand that the LOCK only lasts for the duration of the current SQL session and will unlock automatically once End SQL is reached.

The following demonstrates bad code:

Begin SQL
   -- lock table
   LOCK TABLE PERSO IN SHARE MODE;
End SQL

// table is no longer locked
/* doing stuff here will NOT be operating on a locked table */


Begin SQL
   -- this is not needed here
   UNLOCK TABLE PERSO;
End SQL




The following code example is much better:
Begin SQL
   -- lock table
   LOCK TABLE PERSO IN SHARE MODE;

   -- table is locked
   /* do some SQL stuff while the table is locked */

   -- unlock table

   UNLOCK TABLE PERSO;
End SQL