ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / Managing databases / HFSQL / HFSQL functions
  • Modifying the type of lock for a record
  • Effect of lock mode
  • Lock failure
  • Number of locks
  • Native SQL Server Connector: Lock in write mode
  • Managing locks in OLE DB
  • Persistence of lock
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Locks a record and restricts the access to this record for all the other applications. Then, the record can be unlocked by HUnlockRecNum.
Remark: Several cases may occur after the call to HLockRecNum:
  • The record is already locked by another application: the lock cannot be performed.
  • The data file containing the record is entirely locked: the lock cannot be performed.
An automatic management of lock errors and modification conflicts is performed by default (except in the code of stored procedures). This assisted management of errors can be customized or disabled at any time by HOnError.
HErrorLock returns True if a lock problem occurs.
Caution: HLockRecNum must be used with great care: when locked, the record is not read again. Therefore, it may have been deleted or modified since the last access to this record. It is recommended to use HRead with a lock option.
Java This function is available for HFSQL data files only. It is not available for the data files accessed by JDBC.
Example
// Lock a record in the Customer data file
HLockRecNum(Customer, hRecNumCurrent, hLockReadWrite)
// Process on the record
...
// Restore access to the record
HUnlockRecNum()
Syntax
<Result> = HLockRecNum([<Data file> [, <Record to lock>]] [, <Lock>])
<Result>: Boolean
  • True if the operation was performed,
  • False if a problem occurs. HError is used to identify the error.
<Data file>: Optional character string
Name of the data file used.
If this name is not specified, HLockRecNum will use the last data file used by the last HFSQL function (function starting with "H").
<Record to lock>: Optional integer
Number of the record to lock.
If this parameter is not specified, HLockRecNum will handle the current record.
Native Connectors (Native Accesses) HLockRecNum locks the current record only. You cannot specify a record number other than the current one (to specify the current record number, use the hRecNumCurrent constant).
<Lock>: Optional integer constant
Used to define the type of lock set on the record.
hLockNoNo lock: the record can be read or modified by another application.
hLockReadWriteLock in read/write: the record in the data file cannot be read or modified by another application.
The other application will not be able to lock the record or the data file.
hLockWrite
(default value)
Lock in write mode: the record in the data file can be read, but cannot be modified by another application.
The other application will not be able to lock the record or the data file.
Remarks

Modifying the type of lock for a record

To modify the type of record lock, call HLockRecNum and specify the requested type of lock. There is no need to unlock the record beforehand.

Effect of lock mode

If the data file lock mode is set to hModeMono (see HMode), HLockRecNum has no effect.

Lock failure

If the record is already locked, the lock request is retried HNbRetry times (50 by default).
If the data file cannot be locked after H.NbRetry attempts, HErrorLock returns True. The H.Level variable indicates whether the record or the data file is locked.

Number of locks

The number of records that can be individually locked in a data file is unlimited.
WINDEVWEBDEV - Server codeReports and QueriesAjaxStored proceduresNative Connectors (Native Accesses)

Native SQL Server Connector: Lock in write mode

HLockRecNum locks the record in write mode, not in read-only. Therefore, HLockRecNum prevents the record from being modified by another computer.
HLockRecNum used on a locked record does NOT return a lock error (because only a read operation is performed).
However, HModify will return a lock error on the locked record.
WINDEVWEBDEV - Server codeReports and QueriesAjaxStored proceduresOLE DB

Managing locks in OLE DB

HLockRecNum is not supported. This function generates the non-fatal error "Invalid operation for this type of database".
WINDEVWEBDEV - Server codeAjaxNative Connectors (Native Accesses)

Persistence of lock

With the Native SQLServer and Sybase Connectors, re-reading a record that was locked by HLockRecNum unlocks the record.
Component: wd290hf.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 07/06/2023

Send a report | Local help