public override void EndTransaction() { if (Connection.State != ConnectionState.Open) { throw new InvalidOperationException("Database is not open."); } if (Interlocked.Decrement(ref transactionCount) > 0) { return; } if (currentTransaction == null) { if (shouldCommit) { throw new InvalidOperationException("Transaction missing."); } return; } if (shouldCommit) { currentTransaction.Commit(); shouldCommit = false; } else { currentTransaction.Rollback(); } currentTransaction.Dispose(); currentTransaction = null; }
public Task<IDisposable> Open() { Debug.WriteLine("Opening database: {0}", this.dbFile); db = new SQLiteConnection(dbFile); #if DEBUG this.databaseThreadId = Environment.CurrentManagedThreadId; #endif return Task.FromResult<IDisposable>(new Disposable(() => { if (db != null) { db.Dispose(); db = null; } })); }