4D v13.4

SET QUERY AND LOCK

Home

 
4D v13.4
SET QUERY AND LOCK

SET QUERY AND LOCK 


 

SET QUERY AND LOCK ( lock ) 
Parameter Type   Description
lock  Boolean in True = Lock the records found by queries False = Do not lock records

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 if a record that is already locked is found:

  • The query is stopped and the system variable OK is set to 0,
  • The current selection is cleared,
  • The LockedSet system set contains the locked record that caused the query to be stopped.

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 afterward.

SET QUERY AND LOCK only modifies the behavior for query commands, in other words:

However, SET QUERY AND LOCK does not affect other commands that modify the current selection such as ALL RECORDS, RELATE MANY, etc.

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 commands QUERY and 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

If the command is not called in the context of a transaction, an error is generated.

 
PROPERTIES 

Product: 4D
Theme: Queries
Number: 661

This command modifies the LockedSet system setThis command modifies the Error system variable

 
INDEX

Alphabetical list of commands

 
HISTORY 

Created: 4D v11 SQL

 
SEE ALSO 

QUERY