version 11
SET QUERY AND LOCK (lock)
Parameter | Type | Description | |
lock | Boolean | True = Lock the records found by queries | |
False = Do not lock records |
Description
The SET QUERY AND LOCK command can be used to request the automatic locking of records found by all queries that follow the calling of this command in the current transaction. This means that the records cannot be modified by a process other than the current process between a query and the handling of results.
By default, the records found by queries are not locked. Pass True in the lock parameter to activate locking.
It is imperative for this command to be used within a transaction. If it is called outside of this context, an error is generated. This allows for better control of record locking. The records found will stay locked as long as the transaction has not been terminated (whether validated or cancelled). After the transaction is completed, all the records are unlocked.
The records are locked for all the tables in the current transaction.
When a SET QUERY AND LOCK(True) statement has been executed, the query commands (for example QUERY) adopt a specific functioning when records that are already locked are found during the query:
- The system variable OK is set to 0,
- The current selection is cleared,
- The LockedSet system set is updated: it contains the locked records found by the query.
Consequently, in this context it is necessary to test the LockedSet set after a fruitless query (current selection empty and/or OK variable set to 0) in order to determine the cause of the failure.
Call SET QUERY AND LOCK(False) in order to disable this mechanism afterwards.
Example
In this example, it is not possible to delete a client who would have been passed from category "C" to category "A" in another process between the QUERY and the DELETE SELECTION:
START TRANSACTION SET QUERY AND LOCK(True) QUERY([Customers];[Customers]Catégorie="C") `At this moment, the records found are automatically locked for all other processes DELETE SELECTION([Customers]) SET QUERY AND LOCK(False) VALIDATE TRANSACTION
Error Handling
If the command is not called in the context of a transaction, an error is generated.
See Also