D Eloquence Library

The LOCK Function

The LOCK function locks a database, a data set or an item. The syntax is as follows:

   idb_lock(base,qual,mode,status)

   int base;
   void *qual;
   int mode;
   int status[10];
The parameters are:

base
Identifies the database. This must be the return value from the idb_open call
qual
Identifies a data set, data item or lock qualifier, depending on the mode used. Refer to the description below for information on qualifier and Mode. Refer to the idb_find parameters dset and item for information on specifying the data set or data item.
mode
The modes available listed below.
status
A pointer to an array of at least 10 elements used to indicate the success or failure of the function call (see below).

Description

The idb_lock function locks the whole database, a data set or data items depending on mode.

idb_lock modes
Mode Target Wait Description
1databaseWrite WaitLock database for writing
2databaseWrite
3data setWrite WaitLock data set for writing
4data setWrite
5predicateWrite WaitLock using for writing
6predicateWriteusing predicate spec
11databaseRead WaitLock database for reading
12databaseRead
13data setRead WaitLock data set for reading
14data setRead
15predicateRead WaitLock for reading
16predicateReadusing predicate spec

A read lock allows concurrent read locks. A write lock does not allow any concurrent lock (it is a lock for WRITE).

A wait lock will block execution until lock is available. A lock without wait will return status error if lock is not available.

A lock with wait will fail and return status error if another lock has already been granted and the requested lock is not available.

The Lock Descriptor Format (next page) will explain how to set up predicate specification. Using predicate specification it is possible to lock database, data set(s) or (a group of) data item(s) to be locked.

Return value

Returns 0 if successful, otherwise gives error code.

Status codes

If idb-lock was successfully executed, the status array will contain the following values:

Status codes
ElementMeaning
0S_OK
11
20
31
40
5DB_LOCK | (open_mode << 12)
60
70
8mode
90

Example

   if(idb_lock(dbid,"ORDER",4,status))
      error_handler();
This will lock ORDER data set.


Eloquence Database Manual - 19 DEC 2002