             
             switch db.statementCompletion {
             case .TransactionErrorRollback:
-                // The transactionObserver has rollbacked the transaction.
+                // A transactionObserver has rollbacked the transaction.
                 // Don't lose this information.
                 // Next step: updateStatementDidFail()
                 break
             default:
+                db.statementCompletion = .TransactionRollback
                 // Next step: updateStatementDidExecute()
-                db.statementCompletion = .TransactionRollback
             }
             }, dbPointer)
     }

        }
    }
    
    public func addTransactionObserver(transactionObserver: TransactionObserverType) {
        preconditionValidQueue()
        transactionObservers.append(transactionObserver)
    }
    
    public func removeTransactionObserver(transactionObserver: TransactionObserverType) {
        preconditionValidQueue()
        if let index = transactionObservers.indexOf({ observer in observer === transactionObserver}) {
            transactionObservers.removeAtIndex(index)
        }
    }
    
    private func beginTransaction(kind: TransactionKind? = nil) throws {
        switch kind ?? configuration.defaultTransactionKind {
        case .Deferred:

            let db = unsafeBitCast(dbPointer, Database.self)
            
            // Notify change event
            if !db.transactionObservers.isEmpty {
                db.didChangeWithEvent(DatabaseEvent(
                    kind: DatabaseEvent.Kind(rawValue: updateKind)!,
                    databaseName: String.fromCString(databaseName)!,
                    tableName: String.fromCString(tableName)!,
                    rowID: rowID))
            }
            }, dbPointer)
        
        
        sqlite3_commit_hook(sqliteConnection, { dbPointer in
            let db = unsafeBitCast(dbPointer, Database.self)
            
            do {
                try db.willCommit()
                db.statementCompletion = .TransactionCommit
                // Next step: updateStatementDidExecute()
                return 0
            } catch {
                db.statementCompletion = .TransactionErrorRollback(error)
                // Next step: sqlite3_rollback_hook callback
                return 1
            }
            }, dbPointer)
