     private func databaseDidChange(with event: DatabaseEvent) {
         if savepointStack.isEmpty {
             // Notify now
-            for (observation, predicate) in activeTransactionObservations where predicate(event) {
+            for (observation, predicate) in statementObservations where predicate.evaluate(event) {
                 observation.databaseDidChange(with: event)
             }
         } else {
             // Buffer
-            savepointStack.eventsBuffer.append((event: event.copy(), observations: activeTransactionObservations))
+            savepointStack.eventsBuffer.append((event: event.copy(), statementObservations: statementObservations))
         }
     }
     
     // Called from sqlite3_commit_hook and emptyDeferredTransactionDidCommit()
     private func databaseWillCommit() throws {
         notifyBufferedEvents()
-        for observation in transactionObservations {
+        for observation in observations {
             try observation.databaseWillCommit()
         }
     }

        // Activate the transaction observers that are interested in the actions
        // performed by the statement.
        let databaseEventKinds = statement.databaseEventKinds
        var activeTransactionObservations: [(TransactionObservation, DatabaseEventPredicate)] = []
        
        for observation in transactionObservations {
            let kinds = databaseEventKinds.filter(observation.observes)
            if kinds.isEmpty { continue }
            let predicate: DatabaseEventPredicate = { event in kinds.contains { kind in event.isOfKind(kind) } }
            activeTransactionObservations.append((observation, predicate))
        }
        
        self.activeTransactionObservations = activeTransactionObservations
    }
    
    func updateStatementDidFail(_ statement: UpdateStatement) throws {
        // Wait for next statement
        activeTransactionObservations = []
        
        // Reset transactionState before databaseDidRollback eventually
        // executes other statements.


#endif

enum DatabaseEventPredicate {
    case `true`
    case function((DatabaseEventProtocol) -> Bool)
    
    func evaluate(_ event: DatabaseEventProtocol) -> Bool {
        switch self {
        case .true: return true
        case .function(let f): return f(event)
        }
    }
}

/// The SQLite savepoint stack is described at
/// https://www.sqlite.org/lang_savepoint.html
