Transactions reduce the possibility of lost data. 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 transaction. By defining explicit transactions, you can force the MicroKernel to treat multiple Btrieve operations as an atomic unit. To include a group of operations within a transaction, you enclose those operations between a Begin Transaction operation (19) and an End Transaction operation (20).
The MicroKernel provides two kinds of locks: explicit and implicit. When a client specifically requests the lock by including the lock request with a Btrieve operation code, that lock is called an explicit lock. However, even when a client does not explicitly request a lock, the MicroKernel may lock an affected record or page as the result of an action that the client performs. In this situation, the lock that the MicroKernel makes is called an
implicit lock (see
Implicit Record Locks and
Implicit Locks).
When a client attempts to update or delete a record, either external to any transaction or from within a
concurrent transaction, the MicroKernel
implicitly tries to lock that record on behalf of the client. In an exclusive transaction, an implicit record lock is unnecessary because the MicroKernel locks the entire file prior to performing the Update or Delete operation. (See
File Locks).
With no implicit locks retained, client 1 no longer has an implicit record lock on record A, meaning that client 2 can successfully read and lock the record. However, client 2 reads the old image of record A, because client 1 has not committed the new image. When client 1 ends its transaction (committing the changed image of record A) and client 2 attempts to update record A, the MicroKernel returns Status Code 80 (Conflict) because client 2’s image of that record is no longer valid. (See the example in Table
38.)
The MicroKernel tries, on behalf of the client, to implicitly lock the records that are modified during execution of an Insert, Update, or Delete operation if the modification occurs either outside of a transaction or from within a concurrent transaction. (In an exclusive transaction, an implicit record or page lock is unnecessary because the MicroKernel locks the entire file prior to performing an Update or Delete operation. In the case of an Insert operation, the MicroKernel requests a file lock if the client does not have one yet. See
File Locks) As with implicit record locks, the MKDE provides implicit page locks; the client does not explicitly request them.