xHarbour Reference Documentation > Command Reference xHarbour Developers Network  

SET DBFLOCKSCHEME

Selects the locking scheme for shared database access.

Syntax

SET DBFLOCKSCHEME TO <nLockScheme>

Arguments

TO <nLockScheme>
This is a numeric value defining the locking scheme for record locks in shared database access. Values listed in the following table or #define constants from the DBINFO.CH file can be used for <nLockScheme>

Constants for SET DBFLOCKSCHEME
ConstantValueDescription
DB_DBFLOCK_DEFAULT0Default locking scheme
DB_DBFLOCK_CLIP1Clipper 5.2 locking scheme
DB_DBFLOCK_CL532Clipper 5.3 locking scheme
DB_DBFLOCK_VFP3Visual FoxPro locking scheme
DB_DBFLOCK_CL53EXT4Emulated shared locking
DB_DBFLOCK_XHB645Locking scheme for files > 4GB

Description

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

Info

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

Example

   #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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe