Using Btrieve Transactions

If you have a number of modifications to make to a file, and you must be sure that either all or none of those modifications are made, include the operations for making those modifications in a Btrieve transaction.

To include a group of operations within a Btrieve transaction, you enclose those operations between a Begin Transaction (19) operation and an End Transaction (20) operation.

Btrieve commits to disk the changes made inside a transaction only when the application performs the End Transaction operation. Prior to performing the End Transaction operation, Btrieve makes all modifications in memory. (See Shadow Paging.)

Should a system failure occur before the application finishes performing all the operations included in the transaction, Btrieve ignores any changes previously made within the transaction.

When you restart the system after the failure, the Btrieve file contains the same information it contained before the Begin Transaction operation was performed.

NetWare Btrieve 6.1x provides two types of transactions:

The type you use depends on how severely you want to restrict other clients' access to the file you are modifying.

Prior to 6.0, Btrieve allowed only exclusive transactions. When a Btrieve task operates on a file inside an exclusive transaction, Btrieve locks that entire file for the duration of the transaction. Once a file is locked in an exclusive transaction, other clients can read the file, but they cannot make changes to it.

As this inability to make changes implies, a Btrieve client (client 2, for example) can begin an exclusive transaction on a file, even if another client (client 1, for example) currently has the file (or a portion of it) already locked. However, client 2 cannot perform any operation that requires a position block (even standard Get or Step operations) until client 1 releases whatever locks it has on the file.

Versions of Btrieve prior to 6.0 allowed other applications (or, in the case of NetWare Communication Services, other clients) to see the changes to the files involved in an exclusive transaction before the transaction ended.

Btrieve versions 6.0 and later do not allow other applications or clients to see the changes involved in any transaction (exclusive or concurrent) until the transaction ends, regardless of which version of Btrieve was used to create the file originally.

When an application operates on a file inside a concurrent transaction, Btrieve locks only the affected records, or (at most) only the affected pages in the file.

Btrieve locks the data page that contains a record being modified in an insert, update, or delete operation. Additionally, if the record is a variable-length record, Btrieve locks all the variable pages containing portions of the record. Finally, Btrieve locks any index pages that will be modified as a result of the insert, update, or delete operation.

As with exclusive transactions, other tasks can always read data that is locked from within a concurrent transaction.

In any Btrieve data file, multiple tasks can have their own concurrent transactions operating, in which they are performing insert, update, or delete operations, or in which they are performing Get or Step operations that contain read lock biases. The only restriction on these activities is that no two tasks can lock the same record or page simultaneously from their respective concurrent transactions.

The following additional features apply to concurrent transactions: