xHarbour Reference Documentation > Command Reference |
Selects the locking scheme for shared database access.
SET DBFLOCKSCHEME TO <nLockScheme>
Constants for SET DBFLOCKSCHEME
Constant | Value | Description |
---|---|---|
DB_DBFLOCK_DEFAULT | 0 | Default locking scheme |
DB_DBFLOCK_CLIP | 1 | Clipper 5.2 locking scheme |
DB_DBFLOCK_CL53 | 2 | Clipper 5.3 locking scheme |
DB_DBFLOCK_VFP | 3 | Visual FoxPro locking scheme |
DB_DBFLOCK_CL53EXT | 4 | Emulated shared locking |
DB_DBFLOCK_XHB64 | 5 | Locking scheme for files > 4GB |
This setting defines the locking scheme used for record locks with shared database access. The default locking scheme is DBFLOCK_DEFAULT.
The locking scheme used as the default depends on the RDD used for opening a database. When the DBFCDX RDD is used, the default locking scheme is DBFLOCK_VFP. For DBF, DBFFPT, DBFDBT and DBFNTX the DBFLOCK_CLIP locking scheme is used as the default.
Note: In the NTX header file, there is a flag which informs that DBFLOCK_CL53 should be used.
The DBFLOCKSCHEME command needs to be set before opening a database file. Different locking schemes can be set for each work area, but one file should never be accessed with different locking schemes at the same time. Always use UNLOCK to release all locks before changing the locking scheme for a database file.
Setting the locking scheme to 1 will lock the database files like CA-Clipper 5.2 does. To use CA-Clipper 5.3's locking scheme, set DBFLOCKSCHEME to 2. This will emulate shared locks using exclusive locks. Visual FoxPro's locking scheme is selected with DBFLOCKSCHEME set to 3.
When using locking scheme 4, a shared locking will be emulated. This scheme is very useful with systems that do not support shared locks. Although there are no problems with xHarbour, be cautious when using this scheme with a Clipper application in a network environment. Note that the file size is up to 4GB which makes this locking scheme the finest for use with a FAT32 file system. It can also be used for DBFNTX and DBFCDX.
When using files larger than 4GB, use scheme 5. This locking scheme requires large file support by the operating system. Note that it does not reduce the size of the file. This scheme was tested successfully on aLinux systems.
Note: The DBFLOCK_CL53 locking scheme uses the same locking scheme as the locking scheme that COMIX for CA-Clipper uses.
On POSIX (Linux and other *nixes) platforms SHARED locks are used when possible in all locking schemes. So it's not necessary to set DBFLOCK_CL53 which cannot work when 32bit file IO is used (maximum lock offset has 31bit).
In DOS/Windows the DBFLOCK_CL53 will be probably the most efficient for multi-user applications.
The locking scheme selected for an open database file can be checked with function DbInfo(DBI_LOCKSCHEME).
See also: | Set(), DbInfo(), DbRLock(), RddSetDefault(), RLock() |
Category: | Database commands , SET commands , xHarbour extensions |
Header: | DbInfo.ch |
Source: | rdd\dbcmd.c, rtl\set.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
#include "DbInfo.ch" REQUEST DBFCDX PROCEDURE Main() LOCAL aStruct := { { "FIELD1", "C", 30, 0 }, ; { "FIELD2", "N", 10, 2 } } RddSetDefault( "DBFCDX" ) SET DBFLOCKSCHEME TO DB_DBFLOCK_CL53 DbCreate( "test", aStruct, "DBFCDX") USE Test SHARED APPEND BLANK IF ! NetErr() FIELD1->"This is a test" FIELD2->100 ? "Append operation completed" COMMIT ELSE ? "Append operation failed" ENDIF RETURN
http://www.xHarbour.com