Unlock a record or file¶
unlock |
Unlock a record or file |
Contents
SYNTAX
unlock file_id
If the program currently has a record selected from the specified file, unlock deselects it, and allows it to be accessed by other users. The data in the file’s record buffer(s) is not affected, but the record may no longer be written back or deleted..
If the program currently has a read lock or write lock on the file, the lock is removed.
The file access commands find, next, match, prev and read automatically place a lock on the record they retrieve if the file is open in update mode.
A locked record is automatically unlocked by any of the following events:
1 |
A clear command with no arguments, or clear record_id that explicitly clears the record buffer. |
2 |
A write command on the file. Writing a record back deselects it. |
3 |
A delete command on the file. |
4 |
A successful writelock or readlock on the file by the current program. |
5 |
An unlock command on the file. The record remains in the buffer but cannot be written back. |
6 |
A find, next, match, prev or read which attempts to read another record into the same buffer, whether successful or not. |
7 |
The file is closed. If it is subsequently opened the buffer contents remain the same, but the record is deselected. |
Locking a file¶
A file is locked by use of the readlock and writelock commands.
A read lock prevents the file from being updated by any process, including the process that placed the lock. This enables the records in a file to be examined with the knowledge that records are not currently being amended by other users.
A write lock prevents the file from being locked or updated by any other process. This enables the update of more than one record in a file, with the knowledge that no other user is updating the file. First the write lock is obtained, then the updates are made. Finally, the write lock is removed, freeing all the updated records simultaneously.
NOTES
On single-user operating systems which do not support record locking, the unlock command is ignored.
EXAMPLE
openfile FF name = "tmpdata/tmpfields" create traps = CP_FFERR
writelock FF
/* statements requiring file lock */
unlock FF
return
CP_FFERR:
error "Unable to create temporary file"
return
RELATED TOPICS |