Skip to main content

This version of the product is no longer supported, and this documentation is no longer updated regularly. See the latest version of this content.Opens in a new tab

FILELOCK

Locks a MultiValue file.

Synopsis

FILELOCK [filevar] [,locktype] [ON ERROR statements] [LOCKED statements]

Arguments

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.

Description

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. The statements argument can be the NULL placeholder keyword, a single statement, or a block of statements terminated by the END keyword. A block of statements has specific line break requirements: each statement must be on its own line; there must be a line break between the LOCKED keyword and the first line.

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. The statements argument can be the NULL placeholder keyword, a single statement, or a block of statements terminated by the END keyword. A block of statements has specific line break requirements: each statement must be on its own line; there must be a line break between the ON ERROR keyword and the first line.

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.

Lock Promotion

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.

See Also

FeedbackOpens in a new tab