[Database]SQLite3 Transaction [事务处理]

>> 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, except that the SAVEPOINT and RELEASE commands are named and may be nested.

Create SAVEPOINT

Release

>> 三种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
};


>>官方文档

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

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

转载于:https://www.cnblogs.com/piaoger/archive/2011/11/25/2262895.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值