| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Locks a record for write access.
DbRLock( [<xRecno>] ) --> lSuccess
The return value is .T. (true) when the record <xRecno> is successfully locked, otherwise .F. (false) is returned.
The DbRLock() function attempts to lock the record identified by <xRecno> in the current work area, and return .T. (true) if the record is locked.
If <xRecno> is not specified, all active record locks are removed and the current record is locked. When a particular record is specified with <xRecno>, the function places a lock on this record and adds it to the list of active record locks. This list can be retrieved with function DbRLockList().
Use DbRUnLock() to release locks from individual records.
| See also: | DbRLockList(), DbRUnlock(), DbUnlock(), DbUnlockAll(), FLock(), NetRecLock(), RLock(), UNLOCK |
| Category: | Database functions , Network functions |
| Source: | rdd\dbcmd.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example attempts to lock multiple records belonging to a
// transaction and unlocks all if a single lock is not successful
PROCEDURE Main
LOCAL cTransActID := "01234"
LOCAL nCount := 0
USE Accounts INDEX Transact
SEEK (cTransActID)
DO WHILE FIELD->TRANSACTID == cTransActID
IF DbRLock( Recno() )
nCount ++ // successful lock
SKIP // proceed to next record
ELSE
nCount := -1 // lock failed on this record
DbRUnlock() // release all previous locks
ENDIF
ENDDO
IF nCount > 0
<transaction code with locked records goes here>
ENDIF
RETURN
http://www.xHarbour.com