Click or drag to resize

DbRLock Function

Lock a record in a shared database file, optionally retaining previous record locks.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.08
Syntax
 FUNCTION DbRLock(
	 uRecId AS USUAL
) AS USUAL
View Source

Parameters

uRecId
Type: Usual
The ID (usually a record number) of the record to be locked.  If specified, record locks held by the current process are retained.  If not specified, all locks held by the current process are released and the current record is assumed.

Return Value

Type: Usual
TRUE if the record lock is obtained; otherwise, FALSE.  An attempt to lock a record in an empty database returns TRUE.
Remarks
If a database file is opened in shared mode, you must obtain a record lock before attempting any operation that writes to the database file. For each invocation of DBRLock(), there is one attempt to lock the target record, and the result is returned as a logical value.  An attempt to obtain a record lock fails if another process currently has a file lock or record lock on the target record. If DBRLock() is successful, the record is locked and other processes are prevented from updating the record until the lock is released.  DBRLock() provides a shared lock, allowing other users read-only access to the locked record while allowing only the current process to modify it. A record lock remains in effect until you explicitly unlock it (with DBUnlock(), for example), close the database file, or attempt another file or record lock (with RLock() or DBRLock() with no argument).  DBRLock() when specified with an argument does not release records locks held by the current process.  Instead, it adds the newly locked records to the lock list (see DBRLockList()). By default, DBRLock() operates on the currently selected work area.  It will operate on an unselected work area if you specify it as part of an aliased expression.  This feature is useful since DBRLock() does not automatically attempt a record lock for related files. Refer to "Concurrency Control" in the Programmer's Guide for  more information on record locking.
Examples
This example deletes a record from a shared database file DBRLock():
X#
USE customer INDEX custname SHARED NEW
SEEK "Smith"
IF Found()
        IF Customer->DBRLock()
                DELETE
                QOut("Smith deleted")
        ELSE
                QOut("Record in use by another")
        ENDIF
ELSE
        QOut("Smith not in customer file")
ENDIF
CLOSE
This example specifies DBRLock() as an aliased expression to lock a record in an unselected work area:
X#
USE sales SHARED NEW
USE customer SHARED NEW
IF !Sales->DBRLock()
        QOut("The current sales record is in use")
ENDIF
See Also

Reference

DBServer:LockCurrentRecord
DBServer:LockSelection
DBServer:RLockList
DBServer:RLockVerify
DBServer:Unlock
UNLOCK
USE