RLock Function (String, Usual) | |
Lock the current record.
Namespace:
XSharp.RT
Assembly:
XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax FUNCTION RLock(
cRecordNumberList AS STRING,
uArea AS USUAL
) AS LOGIC
public static bool RLock(
string cRecordNumberList,
Usual uArea
)
Request Example
View SourceParameters
- cRecordNumberList
- Type: String
Specifies that RLOCK( ) attempts to lock multiple records.
The character expression cRecordNumberList specifies one or more record numbers, separated by commas, that RLOCK( ) attempts to lock.
For example, to attempt record locks on the first four records in a table, cRecordNumberList should contain 1, 2, 3, 4.
- uArea
- Type: Usual
Specifies the work area name or number for a table on which the operation must be performed.
Return Value
Type:
Logic
TRUE if the record lock(s) is (are) obtained; otherwise, FALSE.
If you try to lock more than one record and one of them fails then
locks that were successful are released again.
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 RLock(), 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 RLock() is successful, the record is locked and other processes are prevented from updating the record until the lock is released.
RLock() 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() without an argument).
By default, this function operates on the currently selected work area.
It can be made to operate on an unselected work area by specifying
it within an aliased expression or by calling the overload that accepts a workarea
parameter (a workarea number or alias ).
This feature is useful since RLock() does not automatically attempt a record lock for related files.
Examples
This example deletes a record in a shared database file using RLock():
1USE customer INDEX custname SHARED NEW
2SEEK "Smith"
3IF Customer->Found()
4 IF Customer->RLock()
5 Customer->DBDelete()
6 QOut("Smith deleted")
7 ELSE
8 QOut("Record in use by another")
9 ENDIF
10ELSE
11 QOut("Smith not in Customer file")
12ENDIF
13CLOSE
See Also