FILELOCK [filevar] [,locktype] [ON ERROR statements] [LOCKED statements]
|filevar||Optional — A file variable name used to refer to a MultiValue file. This filevar is supplied by the OPEN statement. If not specified, the default file is locked.|
|locktype||Optional — The type of lock requested, specified by the keyword SHARED or EXCLUSIVE. If not specified, the default is EXCLUSIVE.|
The FILELOCK statement is used to lock a MultiValue file. It takes the file identifier filevar, defined by the OPEN statement.
You can optionally specify a LOCKED clause. This clause is executed if filevar refers to a file that has already been locked by another user. The clause is executed if locktype conflicts with an existing lock. The LOCKED clause is optional, but strongly recommended; if no LOCKED clause is specified, program execution waits indefinitely for the conflicting lock to be released.
If a file is locked by another user, the STATUS function returns the process ID (pid) of the user holding the lock.
You can optionally specify an ON ERROR clause. If file lock fails, the ON ERROR clause is executed. This may occur if filevar does not refer to a currently open file.
You can release a file lock by issuing a FILEUNLOCK, issuing a RELEASE with no record ID, or by closing the file.
File and Record Locking
A FILELOCK is equivalent to taking a RECORDLOCK on all records in the file. For FILELOCK to exclusively lock a file, not only must no other user have a conflicting FILELOCK, but no other user may have a RECORDLOCKU or RECORDLOCKL for any record of the file. You can check the status of file locks and record locks using the RECORDLOCKED function.
If you have a shared lock on a file, then request an exclusive lock on the same file, MVBasic attempts to get the exclusive lock. If it is successful, your shared lock is promoted to an exclusive lock. The result is that you hold one exclusive lock, not two locks.