 private enum Source<T: FetchedResult> {
     case SQL(String, StatementArguments?)
     case FetchRequest(GRDB.FetchRequest<T>)
-
-    func fetchAll(db: DatabaseReader) -> [T] {
+    
+    func selectStatement(db: Database) throws -> SelectStatement {
         switch self {
         case .SQL(let sql, let arguments):
-            return T.fetchAll(db, sql, arguments: arguments)
+            let statement = try db.selectStatement(sql)
+            if let arguments = arguments {
+                statement.arguments = arguments
+            }
+            return statement
         case .FetchRequest(let fetchRequest):
-            return fetchRequest.fetchAll(db)
+            return try fetchRequest.selectStatement(db)
         }
     }
 }


// MARK: - <TransactionObserverType>
extension FetchedResultsController : TransactionObserverType {
    public func databaseDidChangeWithEvent(event: DatabaseEvent) { }
    public func databaseWillCommit() throws { }
    public func databaseDidRollback(db: Database) { }
    public func databaseDidCommit(db: Database) {
        let newResults = source.fetchAll(db)
        
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
            let oldResults = self.fetchedResults!

    
    /// The source
    private let source: Source<T>
    
    /// The observed tables. Set in performFetch()
    private var observedTables: Set<String>? = nil
    
    /// True if databaseDidCommit(db) should compute changes
    private var fetchedResultsDidChange = false

    /// The databaseWriter
    public let database: DatabaseWriter
