My favorites | Sign in
Project Logo
                
Search
for
Updated Jun 11, 2007 by myron.alexander
Labels: Featured
TransactionLogic  
How the interface handles transactions.

Transaction Handling by the Interface

The interface aims to maximize transaction handling flexibility without sacrificing simplicity. It does so by defining transaction modes of operation and allowing the developer to choose the mode on connection.

Transaction Modes

There are four transaction modes:

The transaction modes are enumerated in dbapi.sqlite3.TransactionMode.

User Transaction Mode

Provides the most control for the developer (user of the library) as the interface will not handle any transaction events leaving the developer the ability to handle transactionality as they see fit.

Auto Commit Mode

A direct derivative of the User mode and is almost identical except in one case, batch operations are performed in a transaction.

On Modify Mode

Creates a transaction on execution of an operation that modifies data. The connection starts without a transaction.

Always Mode

A transaction is created on connection and the mode ensures that a transaction is always in effect. If the transaction is ended for any reason, a new transaction is started.

Transaction Types

The transaction types are taken from SQLite3.

Deferred

No locks are acquired on the database until the database is first accessed. Thus with a deferred transaction, the BEGIN statement itself does nothing. Locks are not acquired until the first read or write operation. The first read operation against a database creates a SHARED lock and the first write operation creates a RESERVED lock. Because the acquisition of locks is deferred until they are needed, it is possible that another thread or process could create a separate transaction and write to the database after the BEGIN on the current thread has executed.

Immediate

RESERVED locks are acquired on all databases as soon as the BEGIN command is executed, without waiting for the database to be used. After a BEGIN IMMEDIATE, you are guaranteed that no other thread or process will be able to write to the database or do a BEGIN IMMEDIATE or BEGIN EXCLUSIVE. Other processes can continue to read from the database, however.

Exclusive

EXCLUSIVE locks are acquired on all databases. After a BEGIN EXCLUSIVE, you are guaranteed that no other thread or process will be able to read or write the database until the transaction is complete.


Sign in to add a comment
Hosted by Google Code