Please enable JavaScript to view this site.

R:BASE 11 Help

Navigation: Command Index > S > SET

LOCK

Scroll Prev Top Next More

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. The CLEAR TABLE LOCKS command may be used to clear all table locks, which must be used with MULTI set to OFF and while connected to the database.

 

LIST displays locked tables with a letter next to the table name for the type of multi-user lock.

 

(L) for a local lock

(R) for a remote lock

(C) for a cursor lock

(r) for a row lock

 

LIST tells you whether the lock is a row, cursor, local, or remote lock. 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 list of locked tables may be acquired using the (CVAL('TABLELOCKS')) function. The list of locked views may be acquired using the (CVAL('VIEWLOCKS')) function.

 

The lock status for a table may be acquired using the GetLock parameter for the GETVAL function. The lock type on a table/view may be acquired using the GetLockType parameter for the GETVAL function.

 

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