[TDR Generic Table] [MySQL Protocol Compatibility Interface] Optimistic Lock

1. Attribute Description

Multi-step operations are common in database access, such as getting a record, processing it locally, and writing it back to the database. Since TcaplusDB does not support transactions and cannot guarantee the atomicity of multi-step operations, TcaplusDB implements a simple optimistic locking function through the record version number attribute to solve the atomicity problem of multi-step operations.

The record version number is a built-in field of TcaplusDB. It is read-only to users and is represented by __version__. When a new record is inserted, its version number is 1. Each time the record is updated, the version number of the record will be automatically increased by 1.

2. Preparations

Refer to Preparation document, create mysql_table table, and use MySQL Client to connect to TcaplusDB successfully.

3. SQL Examples

-- Assume that the record version number got here is 6
SELECT __version__, v1, v2 FROM mysql_table WHERE k1=1 AND k2=2 AND k3='one';

/*
 * do something
 */

-- If the update state is executed successfully, the record version number changes to 7
UPDATE mysql_table SET v1=1, v2=2 WHERE k1=1 AND k2=2 AND k3='one' AND __version__=6;

4. FAQ

For details, see Meaning and Handling of Error Codes.

5. Other Reference Documents

None

results matching ""

    No results matching ""