[Database] sqlite3 transaction [Transaction Processing]

Source: Internet
Author: User
Tags savepoint

> Transaction

Begin transaction

Commit transaction

Rollback transaction


> No nest transaction

Use savepoint instead.

Savepoints are a method of creating transactions, similar to begin and commit, since t that the savepoint and release commands are named and may be nested.

Create savepoint

Release

> Three types of transaction

Deferred/immediate/exclusive

    // From My Sqlite3 wrapper: SqliteDataTypes

///<summary>
/// Three types of transactions in SQLite: Deferred, Immediate and Exclusive
/// The default transaction behavior is deferred.
///<summary>
enum TransactionType
{
///<summary>
/// Deferred Transaction is the default transaction in SQLite.
/// Statement can be "BEGIN DEFERRED" or "BEGIN".
/// Deferred means that no locks are acquired on the database until the database is first accessed.
/// Thus with a deferred transaction, the BEGIN statement itself does nothing to the filesystem.
/// 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.
///</summary>
kDeferred = 0,

///<summary>
/// Deferred Transaction is the default transaction in SQLite.
/// Statement is "BEGIN IMMEDIATE".
/// If the transaction is immediate, then 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, it is 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.
///</summary>
kImmediate = 1,

///<summary>
/// Statement is "BEGIN EXCLUSIVE".
/// An exclusive transaction causes EXCLUSIVE locks to be acquired on all databases.
/// After a BEGIN EXCLUSIVE, no other database connection
/// except for read_uncommitted connections will be able to read the database
/// and no other connection without exception will be able to write the database
/// until the transaction is complete.
///<summary>
kExclusive = 2
};

> Official documentation

Http://www.sqlite.org/lang_transaction.html

Http://www.sqlite.org/lang_savepoint.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.