Record locking

The file access commands find, next, match, prev and read automatically place a lock on the record they retrieve if the relevant file is open in update mode. The record is now selected and available for update. It cannot be accessed for update by other users. However, if other users have the file open in read-only mode, or use the [u] versions of file access commands, they are normally able to access a record even if it is locked. (Some operating systems do not support this feature, and a locked record is locked from everybody.)

An attempt to access a locked record generates the trappable error condition riu (Record in use). See Traps.

If a file has been locked by readlock or writelock, all the records in it are locked and attempts to read them cause Record in use. The exception to this is a write lock by the current program.


Record unlocking

A locked record must be unlocked before it can be accessed by other users. The unlock command, which takes a file name as its argument, unlocks and deselects any record from that file which the current program is holding locked. The data in the file’s record buffer(s) is not affected, but the record may no longer be written back or deleted.


Automatic unlocking of a record

A locked record is automatically unlocked by any of the following events:

1

The record is deleted.

2

The record is written back using the write command. The writekl command writes a record back and keeps it locked.

3

An attempt is made to read another record into the same buffer. The attempt does not have to succeed.

4

A clear command with no arguments is executed. The cleardata command may be used to execute a global clear without unlocking records.

5

The record buffer is explicitly cleared with the clear command.


ODBC databases

Certain ODBC databases do not support standard record locking. In such databases two clients are allowed to have the same record read for update, but a write[kl] or delete command on this record by the second client will fail. This condition can be trapped by the ue trap. See ODBC record locking for more details.


RELATED TOPICS

Keyed files

File locking