             do {
                 let d = try projected.map({ (name, id) throws -> (String, Term) in
                     guard let t = store.term(for: row[id]) else {
+                        throw SQLiteQuadStore.SQLiteQuadStoreError.idAccessError
+                    }
+                    return (name, t)
+                })
+                let r = TermResult(bindings: Dictionary(uniqueKeysWithValues: d))
+                return r
+            } catch {
+                return nil
+            }
+        }
+        return AnyIterator(results.makeIterator())
+    }
+}
+
+public struct SQLitePreparedPlan: NullaryQueryPlan {
+    var dbh: SQLite.Statement
+    var projected: [String: String]
+    var store: SQLiteQuadStore
+    public var selfDescription: String { return "SQLite Prepared Plan" }
+    public func evaluate() throws -> AnyIterator<TermResult> {
+        let projected = self.projected
+        let map = Dictionary(uniqueKeysWithValues: dbh.columnNames.enumerated().map { ($1, $0) })
+        let store = self.store
+        let results = dbh.lazy.compactMap { (row) -> TermResult? in
+            do {
+                let d = try projected.map({ (name, colName) throws -> (String, Term) in
+                    guard let i = map[colName], let id : Int64 = row[i] as? Int64, let t = store.term(for: id) else {
                         throw SQLiteQuadStore.SQLiteQuadStoreError.idAccessError
                     }
                     return (name, t)

            // )
        })
        try db.run(quadsTable.createIndex(graphColumn))
        try db.run(quadsTable.createIndex(predColumn, objColumn, graphColumn, subjColumn))

        try db.run(termsTable.create { t in     // CREATE TABLE "terms" (
            t.column(idColumn, primaryKey: .autoincrement) //     "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,

                    termValueColumn <- iri
                ))
            }
        }
    }
    
