LOCK
Top  Previous  Next

Operating Condition

Syntax: SET LOCK tbllist ON/OFF

Default: OFF

Mode: Multi-user

SET LOCK manually sets locks on or removes locks from tables specified in the list of tables (tbllist). Use the command whenever you want a procedure or transaction to have exclusive use of tables. Setting LOCK to off disables locks for each of the tables in tbllist.

In command or procedure files it is sometimes necessary to prevent access to a table or group of tables while certain operations are performed. Although R:BASE handles most locks automatically according to the command that is running, at times you might want more control over table locking. SET LOCK provides you explicit control over access to tables during processing by the commands that retrieve and update data.

If R:BASE cannot lock all the tables listed after SET LOCK, it issues a message saying that not all tables are available to be locked. R:BASE does not lock any tables unless it can lock all tables listed, and it sets an error code when SET LOCK fails.

Group the tables used into one SET LOCK command to avoid tying up needed resources. Be sure to issue the SET LOCK OFF command to remove the locks after processing is complete. Locks set with this command are cumulative. You need to issue one SET LOCK OFF command for each SET LOCK ON command that you have entered for a given table. The user who set the table locks must issue SET LOCK OFF; otherwise no other user can access the locked tables until the first user exits the database.

LIST displays locked tables in reverse video. With LIST TABLE, on the other hand, the type of multi-user locks is displayed. Only the highest priority lock is displayed for each table.

LIST TABLE tells you whether the lock is an edit, row, cursor, local, or remote lock. Edit, row, and cursor locks are set by R:BASE as part of its internal concurrency control. A local lock is set by a SET LOCK command issued at the workstation that issued the LIST TABLE command. And a remote lock is set by a command that obtains a table lock and is issued from a workstation other than the workstation that issued the LIST TABLE command.

The first command line below sets an exclusive lock on the customer table. The second command line sets additional exclusive locks on the transmaster and transdetail tables. These exclusive locks prevent access to the three tables by any user other than the one who issued the SET LOCK ON commands. The SET LOCK OFF command removes the locks on all three tables.
 
SET LOCK customer ON  
SET LOCK transmaster, transdetail ON  
SET LOCK customer, transmaster, transdetail OFF