diff --git a/app/Benchmarks/doc_mutating_generated.swift b/app/Benchmarks/doc_mutating_generated.swift index cd64730f1..eb42ced0d 100644 --- a/app/Benchmarks/doc_mutating_generated.swift +++ b/app/Benchmarks/doc_mutating_generated.swift @@ -183,7 +183,7 @@ public final class BenchDocChangeRequest: Dflat.ChangeRequest { guard let toolbox = toolbox as? SQLitePersistenceToolbox else { return nil } switch _type { case .creation: - guard let insert = toolbox.connection.prepareStatement("INSERT INTO benchdoc (__pk0, p) VALUES (?1, ?2)") else { return nil } + guard let insert = toolbox.connection.prepareStaticStatement("INSERT INTO benchdoc (__pk0, p) VALUES (?1, ?2)") else { return nil } title.bindSQLite(insert, parameterId: 1) let atom = self._atom toolbox.flatBufferBuilder.clear() @@ -205,7 +205,7 @@ public final class BenchDocChangeRequest: Dflat.ChangeRequest { _type = .none return .updated(atom) } - guard let update = toolbox.connection.prepareStatement("REPLACE INTO benchdoc (__pk0, p, rowid) VALUES (?1, ?2, ?3)") else { return nil } + guard let update = toolbox.connection.prepareStaticStatement("REPLACE INTO benchdoc (__pk0, p, rowid) VALUES (?1, ?2, ?3)") else { return nil } title.bindSQLite(update, parameterId: 1) toolbox.flatBufferBuilder.clear() let offset = atom.to(flatBufferBuilder: &toolbox.flatBufferBuilder) @@ -219,7 +219,7 @@ public final class BenchDocChangeRequest: Dflat.ChangeRequest { _type = .none return .updated(atom) case .deletion: - guard let deletion = toolbox.connection.prepareStatement("DELETE FROM benchdoc WHERE rowid=?1") else { return nil } + guard let deletion = toolbox.connection.prepareStaticStatement("DELETE FROM benchdoc WHERE rowid=?1") else { return nil } _rowid.bindSQLite(deletion, parameterId: 1) guard SQLITE_DONE == sqlite3_step(deletion) else { return nil } _type = .none diff --git a/src/parser/dflatc.swift b/src/parser/dflatc.swift index 4f9de1cef..8a24a54b6 100644 --- a/src/parser/dflatc.swift +++ b/src/parser/dflatc.swift @@ -810,7 +810,7 @@ func GenChangeRequest(_ structDef: Struct, code: inout String) { code += " switch field {\n" for indexedField in indexedFields { code += " case \"\(indexedField.keyName)\":\n" - code += " guard let insert = sqlite.prepareStatement(\"INSERT INTO \(tableName)__\(indexedField.keyName) (rowid, \(indexedField.keyName)) VALUES (?1, ?2)\") else { return false }\n" + code += " guard let insert = sqlite.prepareStaticStatement(\"INSERT INTO \(tableName)__\(indexedField.keyName) (rowid, \(indexedField.keyName)) VALUES (?1, ?2)\") else { return false }\n" code += " rowid.bindSQLite(insert, parameterId: 1)\n" code += " let retval = \(GetIndexedFieldExpr(structDef, indexedField: indexedField)).evaluate(object: .table(table))\n" code += " if retval.unknown {\n" @@ -895,7 +895,7 @@ func GenChangeRequest(_ structDef: Struct, code: inout String) { if indexedFields.count > 0 { code += " let indexSurvey = toolbox.connection.indexSurvey(\(structDef.name).indexFields, table: \(structDef.name).table)\n" } - code += " guard let insert = toolbox.connection.prepareStatement(\"INSERT INTO \(tableName) (\(primaryKeys.enumerated().map { "__pk\($0.offset)" }.joined(separator: ", ")), p) VALUES (?1, \(primaryKeys.enumerated().map { "?\($0.offset + 2)" }.joined(separator: ", ")))\") else { return nil }\n" + code += " guard let insert = toolbox.connection.prepareStaticStatement(\"INSERT INTO \(tableName) (\(primaryKeys.enumerated().map { "__pk\($0.offset)" }.joined(separator: ", ")), p) VALUES (?1, \(primaryKeys.enumerated().map { "?\($0.offset + 2)" }.joined(separator: ", ")))\") else { return nil }\n" for (i, field) in primaryKeys.enumerated() { code += " \(field.name).bindSQLite(insert, parameterId: \(i + 1))\n" } @@ -911,7 +911,7 @@ func GenChangeRequest(_ structDef: Struct, code: inout String) { code += " _rowid = sqlite3_last_insert_rowid(toolbox.connection.sqlite)\n" for (i, indexedField) in indexedFields.enumerated() { code += " if indexSurvey.full.contains(\"\(indexedField.keyName)\") {\n" - code += " guard let i\(i) = toolbox.connection.prepareStatement(\"INSERT INTO \(tableName)__\(indexedField.keyName) (rowid, \(indexedField.keyName)) VALUES (?1, ?2)\") else { return nil }\n" + code += " guard let i\(i) = toolbox.connection.prepareStaticStatement(\"INSERT INTO \(tableName)__\(indexedField.keyName) (rowid, \(indexedField.keyName)) VALUES (?1, ?2)\") else { return nil }\n" code += " _rowid.bindSQLite(i\(i), parameterId: 1)\n" code += " let r\(i) = \(GetIndexedFieldExpr(structDef, indexedField: indexedField)).evaluate(object: .object(atom))\n" code += " if r\(i).unknown {\n" @@ -935,7 +935,7 @@ func GenChangeRequest(_ structDef: Struct, code: inout String) { if indexedFields.count > 0 { code += " let indexSurvey = toolbox.connection.indexSurvey(\(structDef.name).indexFields, table: \(structDef.name).table)\n" } - code += " guard let update = toolbox.connection.prepareStatement(\"REPLACE INTO \(tableName) (\(primaryKeys.enumerated().map { "__pk\($0.offset)" }.joined(separator: ", ")), p, rowid) VALUES (?1, ?2, \(primaryKeys.enumerated().map { "?\($0.offset + 3)" }.joined(separator: ", ")))\") else { return nil }\n" + code += " guard let update = toolbox.connection.prepareStaticStatement(\"REPLACE INTO \(tableName) (\(primaryKeys.enumerated().map { "__pk\($0.offset)" }.joined(separator: ", ")), p, rowid) VALUES (?1, ?2, \(primaryKeys.enumerated().map { "?\($0.offset + 3)" }.joined(separator: ", ")))\") else { return nil }\n" for (i, field) in primaryKeys.enumerated() { code += " \(field.name).bindSQLite(update, parameterId: \(i + 1))\n" } @@ -953,7 +953,7 @@ func GenChangeRequest(_ structDef: Struct, code: inout String) { code += " let or\(i) = \(GetIndexedFieldExpr(structDef, indexedField: indexedField)).evaluate(object: .object(o))\n" code += " let r\(i) = \(GetIndexedFieldExpr(structDef, indexedField: indexedField)).evaluate(object: .object(atom))\n" code += " if or\(i).unknown != r\(i).unknown || or\(i).result != r\(i).result {\n" - code += " guard let u\(i) = toolbox.connection.prepareStatement(\"REPLACE INTO \(tableName)__\(indexedField.keyName) (rowid, \(indexedField.keyName)) VALUES (?1, ?2)\") else { return nil }\n" + code += " guard let u\(i) = toolbox.connection.prepareStaticStatement(\"REPLACE INTO \(tableName)__\(indexedField.keyName) (rowid, \(indexedField.keyName)) VALUES (?1, ?2)\") else { return nil }\n" code += " _rowid.bindSQLite(u\(i), parameterId: 1)\n" code += " let r\(i) = \(GetIndexedFieldExpr(structDef, indexedField: indexedField)).evaluate(object: .object(atom))\n" code += " if r\(i).unknown {\n" @@ -968,11 +968,11 @@ func GenChangeRequest(_ structDef: Struct, code: inout String) { code += " _type = .none\n" code += " return .updated(atom)\n" code += " case .deletion:\n" - code += " guard let deletion = toolbox.connection.prepareStatement(\"DELETE FROM \(tableName) WHERE rowid=?1\") else { return nil }\n" + code += " guard let deletion = toolbox.connection.prepareStaticStatement(\"DELETE FROM \(tableName) WHERE rowid=?1\") else { return nil }\n" code += " _rowid.bindSQLite(deletion, parameterId: 1)\n" code += " guard SQLITE_DONE == sqlite3_step(deletion) else { return nil }\n" for (i, indexedField) in indexedFields.enumerated() { - code += " if let d\(i) = toolbox.connection.prepareStatement(\"DELETE FROM \(tableName)__\(indexedField.keyName) WHERE rowid=?1\") {\n" + code += " if let d\(i) = toolbox.connection.prepareStaticStatement(\"DELETE FROM \(tableName)__\(indexedField.keyName) WHERE rowid=?1\") {\n" code += " _rowid.bindSQLite(d\(i), parameterId: 1)\n" code += " sqlite3_step(d\(i))\n" code += " }\n" diff --git a/src/sqlite/SQLiteConnection.swift b/src/sqlite/SQLiteConnection.swift index e05682a18..321261df1 100644 --- a/src/sqlite/SQLiteConnection.swift +++ b/src/sqlite/SQLiteConnection.swift @@ -65,7 +65,7 @@ public final class SQLiteConnection { } return prepared } - public func prepareStatement(_ statement: StaticString) -> OpaquePointer? { + public func prepareStaticStatement(_ statement: StaticString) -> OpaquePointer? { guard let sqlite = sqlite else { return nil } let identifier = statement.utf8Start if let prepared = staticPool[identifier] { @@ -110,7 +110,7 @@ extension SQLiteConnection { } // Otherwise, we need to check the database. First setup a SAVEPOINT so we can view the rowid in a consistent view. if !savepoint { - let sp = self.prepareStatement("SAVEPOINT dflat_idx") + let sp = self.prepareStaticStatement("SAVEPOINT dflat_idx") guard SQLITE_DONE == sqlite3_step(sp) else { return IndexSurvey() } savepoint = true } diff --git a/src/sqlite/SQLiteTransactionContext.swift b/src/sqlite/SQLiteTransactionContext.swift index a4ce4f884..48cbad880 100644 --- a/src/sqlite/SQLiteTransactionContext.swift +++ b/src/sqlite/SQLiteTransactionContext.swift @@ -49,12 +49,12 @@ public final class SQLiteTransactionContext: TransactionContext { } static func transactionalUpdate(toolbox: SQLitePersistenceToolbox, updater: (_: SQLitePersistenceToolbox) -> UpdatedObject?) throws -> UpdatedObject { - let savepoint = toolbox.connection.prepareStatement("SAVEPOINT dflat_txn") + let savepoint = toolbox.connection.prepareStaticStatement("SAVEPOINT dflat_txn") guard SQLITE_DONE == sqlite3_step(savepoint) else { throw TransactionError.others } let retval = updater(toolbox) guard let updatedObject = retval else { let errcode = sqlite3_extended_errcode(toolbox.connection.sqlite) - let rollback = toolbox.connection.prepareStatement("ROLLBACK TO dflat_txn") + let rollback = toolbox.connection.prepareStaticStatement("ROLLBACK TO dflat_txn") // We cannot handle the situation where the rollback failed. let status = sqlite3_step(rollback) assert(status == SQLITE_DONE) @@ -67,11 +67,11 @@ public final class SQLiteTransactionContext: TransactionContext { throw TransactionError.others } } - let release = toolbox.connection.prepareStatement("RELEASE dflat_txn") + let release = toolbox.connection.prepareStaticStatement("RELEASE dflat_txn") let status = sqlite3_step(release) if status == SQLITE_FULL { // In case of disk full, rollback. - let rollback = toolbox.connection.prepareStatement("ROLLBACK TO dflat_txn") + let rollback = toolbox.connection.prepareStaticStatement("ROLLBACK TO dflat_txn") let status = sqlite3_step(rollback) assert(status == SQLITE_DONE) throw TransactionError.diskFull diff --git a/src/sqlite/SQLiteWorkspace.swift b/src/sqlite/SQLiteWorkspace.swift index bc240337b..5b3738ff2 100644 --- a/src/sqlite/SQLiteWorkspace.swift +++ b/src/sqlite/SQLiteWorkspace.swift @@ -181,10 +181,10 @@ public final class SQLiteWorkspace: Workspace { Self.snapshot = nil return retval } - let begin = pointee.prepareStatement("BEGIN") + let begin = pointee.prepareStaticStatement("BEGIN") sqlite3_step(begin) let retval = closure() - let commit = pointee.prepareStatement("COMMIT") + let commit = pointee.prepareStaticStatement("COMMIT") sqlite3_step(commit) Self.snapshot = nil return retval @@ -397,7 +397,7 @@ public final class SQLiteWorkspace: Workspace { private func invokeChangesHandler(_ transactionalObjectTypes: [ObjectIdentifier], connection: SQLiteConnection, resultPublishers: [ObjectIdentifier: ResultPublisher], tableState: SQLiteTableState, changesHandler: Workspace.ChangesHandler) -> Bool { let txnContext = SQLiteTransactionContext(state: tableState, objectTypes: transactionalObjectTypes, changesTimestamp: state.changesTimestamp.load(), connection: connection) - let begin = connection.prepareStatement("BEGIN") + let begin = connection.prepareStaticStatement("BEGIN") guard SQLITE_DONE == sqlite3_step(begin) else { return false } @@ -406,15 +406,15 @@ public final class SQLiteWorkspace: Workspace { txnContext.destroy() // This transaction is aborted by user. rollback. if txnContext.aborted { - let rollback = connection.prepareStatement("ROLLBACK") + let rollback = connection.prepareStaticStatement("ROLLBACK") let status = sqlite3_step(rollback) precondition(status == SQLITE_DONE) return false } - let commit = connection.prepareStatement("COMMIT") + let commit = connection.prepareStaticStatement("COMMIT") let status = sqlite3_step(commit) if SQLITE_FULL == status { - let rollback = connection.prepareStatement("ROLLBACK") + let rollback = connection.prepareStaticStatement("ROLLBACK") let status = sqlite3_step(rollback) precondition(status == SQLITE_DONE) return false @@ -481,7 +481,7 @@ extension SQLiteWorkspace { // It is OK to create connection, etc. before acquiring the lock as long as we don't do mutation. tableSpace.lock() defer { tableSpace.unlock() } - let begin = connection.prepareStatement("BEGIN") + let begin = connection.prepareStaticStatement("BEGIN") // If we cannot start a transaction, nothing we can do, just wait for re-trigger. guard SQLITE_DONE == sqlite3_step(begin) else { return } // Make sure the table exists before we query. @@ -505,10 +505,10 @@ extension SQLiteWorkspace { } } // Try to commit. - let commit = connection.prepareStatement("COMMIT") + let commit = connection.prepareStaticStatement("COMMIT") let status = sqlite3_step(commit) if SQLITE_FULL == status { - let rollback = connection.prepareStatement("ROLLBACK") + let rollback = connection.prepareStaticStatement("ROLLBACK") let status = sqlite3_step(rollback) precondition(status == SQLITE_DONE) // In case we failed, trigger a redo a few seconds later. diff --git a/src/tests/monster_mutating_generated.swift b/src/tests/monster_mutating_generated.swift index 14659278d..05acbcf0d 100644 --- a/src/tests/monster_mutating_generated.swift +++ b/src/tests/monster_mutating_generated.swift @@ -143,7 +143,7 @@ extension MyGame.Sample.Monster: SQLiteDflat.SQLiteAtom { guard let sqlite = ((toolbox as? SQLitePersistenceToolbox).map { $0.connection }) else { return false } switch field { case "mana": - guard let insert = sqlite.prepareStatement("INSERT INTO mygame__sample__monster__mana (rowid, mana) VALUES (?1, ?2)") else { return false } + guard let insert = sqlite.prepareStaticStatement("INSERT INTO mygame__sample__monster__mana (rowid, mana) VALUES (?1, ?2)") else { return false } rowid.bindSQLite(insert, parameterId: 1) let retval = MyGame.Sample.Monster.mana.evaluate(object: .table(table)) if retval.unknown { @@ -153,7 +153,7 @@ extension MyGame.Sample.Monster: SQLiteDflat.SQLiteAtom { } guard SQLITE_DONE == sqlite3_step(insert) else { return false } case "equipped__type": - guard let insert = sqlite.prepareStatement("INSERT INTO mygame__sample__monster__equipped__type (rowid, equipped__type) VALUES (?1, ?2)") else { return false } + guard let insert = sqlite.prepareStaticStatement("INSERT INTO mygame__sample__monster__equipped__type (rowid, equipped__type) VALUES (?1, ?2)") else { return false } rowid.bindSQLite(insert, parameterId: 1) let retval = MyGame.Sample.Monster.equipped._type.evaluate(object: .table(table)) if retval.unknown { @@ -163,7 +163,7 @@ extension MyGame.Sample.Monster: SQLiteDflat.SQLiteAtom { } guard SQLITE_DONE == sqlite3_step(insert) else { return false } case "equipped__Orb__name": - guard let insert = sqlite.prepareStatement("INSERT INTO mygame__sample__monster__equipped__Orb__name (rowid, equipped__Orb__name) VALUES (?1, ?2)") else { return false } + guard let insert = sqlite.prepareStaticStatement("INSERT INTO mygame__sample__monster__equipped__Orb__name (rowid, equipped__Orb__name) VALUES (?1, ?2)") else { return false } rowid.bindSQLite(insert, parameterId: 1) let retval = MyGame.Sample.Monster.equipped.as(MyGame.Sample.Orb.self).name.evaluate(object: .table(table)) if retval.unknown { @@ -265,7 +265,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { switch _type { case .creation: let indexSurvey = toolbox.connection.indexSurvey(Monster.indexFields, table: Monster.table) - guard let insert = toolbox.connection.prepareStatement("INSERT INTO mygame__sample__monster (__pk0, __pk1, p) VALUES (?1, ?2, ?3)") else { return nil } + guard let insert = toolbox.connection.prepareStaticStatement("INSERT INTO mygame__sample__monster (__pk0, __pk1, p) VALUES (?1, ?2, ?3)") else { return nil } name.bindSQLite(insert, parameterId: 1) color.bindSQLite(insert, parameterId: 2) let atom = self._atom @@ -279,7 +279,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { guard SQLITE_DONE == sqlite3_step(insert) else { return nil } _rowid = sqlite3_last_insert_rowid(toolbox.connection.sqlite) if indexSurvey.full.contains("mana") { - guard let i0 = toolbox.connection.prepareStatement("INSERT INTO mygame__sample__monster__mana (rowid, mana) VALUES (?1, ?2)") else { return nil } + guard let i0 = toolbox.connection.prepareStaticStatement("INSERT INTO mygame__sample__monster__mana (rowid, mana) VALUES (?1, ?2)") else { return nil } _rowid.bindSQLite(i0, parameterId: 1) let r0 = MyGame.Sample.Monster.mana.evaluate(object: .object(atom)) if r0.unknown { @@ -290,7 +290,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { guard SQLITE_DONE == sqlite3_step(i0) else { return nil } } if indexSurvey.full.contains("equipped__type") { - guard let i1 = toolbox.connection.prepareStatement("INSERT INTO mygame__sample__monster__equipped__type (rowid, equipped__type) VALUES (?1, ?2)") else { return nil } + guard let i1 = toolbox.connection.prepareStaticStatement("INSERT INTO mygame__sample__monster__equipped__type (rowid, equipped__type) VALUES (?1, ?2)") else { return nil } _rowid.bindSQLite(i1, parameterId: 1) let r1 = MyGame.Sample.Monster.equipped._type.evaluate(object: .object(atom)) if r1.unknown { @@ -301,7 +301,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { guard SQLITE_DONE == sqlite3_step(i1) else { return nil } } if indexSurvey.full.contains("equipped__Orb__name") { - guard let i2 = toolbox.connection.prepareStatement("INSERT INTO mygame__sample__monster__equipped__Orb__name (rowid, equipped__Orb__name) VALUES (?1, ?2)") else { return nil } + guard let i2 = toolbox.connection.prepareStaticStatement("INSERT INTO mygame__sample__monster__equipped__Orb__name (rowid, equipped__Orb__name) VALUES (?1, ?2)") else { return nil } _rowid.bindSQLite(i2, parameterId: 1) let r2 = MyGame.Sample.Monster.equipped.as(MyGame.Sample.Orb.self).name.evaluate(object: .object(atom)) if r2.unknown { @@ -322,7 +322,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { return .updated(atom) } let indexSurvey = toolbox.connection.indexSurvey(Monster.indexFields, table: Monster.table) - guard let update = toolbox.connection.prepareStatement("REPLACE INTO mygame__sample__monster (__pk0, __pk1, p, rowid) VALUES (?1, ?2, ?3, ?4)") else { return nil } + guard let update = toolbox.connection.prepareStaticStatement("REPLACE INTO mygame__sample__monster (__pk0, __pk1, p, rowid) VALUES (?1, ?2, ?3, ?4)") else { return nil } name.bindSQLite(update, parameterId: 1) color.bindSQLite(update, parameterId: 2) toolbox.flatBufferBuilder.clear() @@ -338,7 +338,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { let or0 = MyGame.Sample.Monster.mana.evaluate(object: .object(o)) let r0 = MyGame.Sample.Monster.mana.evaluate(object: .object(atom)) if or0.unknown != r0.unknown || or0.result != r0.result { - guard let u0 = toolbox.connection.prepareStatement("REPLACE INTO mygame__sample__monster__mana (rowid, mana) VALUES (?1, ?2)") else { return nil } + guard let u0 = toolbox.connection.prepareStaticStatement("REPLACE INTO mygame__sample__monster__mana (rowid, mana) VALUES (?1, ?2)") else { return nil } _rowid.bindSQLite(u0, parameterId: 1) let r0 = MyGame.Sample.Monster.mana.evaluate(object: .object(atom)) if r0.unknown { @@ -353,7 +353,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { let or1 = MyGame.Sample.Monster.equipped._type.evaluate(object: .object(o)) let r1 = MyGame.Sample.Monster.equipped._type.evaluate(object: .object(atom)) if or1.unknown != r1.unknown || or1.result != r1.result { - guard let u1 = toolbox.connection.prepareStatement("REPLACE INTO mygame__sample__monster__equipped__type (rowid, equipped__type) VALUES (?1, ?2)") else { return nil } + guard let u1 = toolbox.connection.prepareStaticStatement("REPLACE INTO mygame__sample__monster__equipped__type (rowid, equipped__type) VALUES (?1, ?2)") else { return nil } _rowid.bindSQLite(u1, parameterId: 1) let r1 = MyGame.Sample.Monster.equipped._type.evaluate(object: .object(atom)) if r1.unknown { @@ -368,7 +368,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { let or2 = MyGame.Sample.Monster.equipped.as(MyGame.Sample.Orb.self).name.evaluate(object: .object(o)) let r2 = MyGame.Sample.Monster.equipped.as(MyGame.Sample.Orb.self).name.evaluate(object: .object(atom)) if or2.unknown != r2.unknown || or2.result != r2.result { - guard let u2 = toolbox.connection.prepareStatement("REPLACE INTO mygame__sample__monster__equipped__Orb__name (rowid, equipped__Orb__name) VALUES (?1, ?2)") else { return nil } + guard let u2 = toolbox.connection.prepareStaticStatement("REPLACE INTO mygame__sample__monster__equipped__Orb__name (rowid, equipped__Orb__name) VALUES (?1, ?2)") else { return nil } _rowid.bindSQLite(u2, parameterId: 1) let r2 = MyGame.Sample.Monster.equipped.as(MyGame.Sample.Orb.self).name.evaluate(object: .object(atom)) if r2.unknown { @@ -382,18 +382,18 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { _type = .none return .updated(atom) case .deletion: - guard let deletion = toolbox.connection.prepareStatement("DELETE FROM mygame__sample__monster WHERE rowid=?1") else { return nil } + guard let deletion = toolbox.connection.prepareStaticStatement("DELETE FROM mygame__sample__monster WHERE rowid=?1") else { return nil } _rowid.bindSQLite(deletion, parameterId: 1) guard SQLITE_DONE == sqlite3_step(deletion) else { return nil } - if let d0 = toolbox.connection.prepareStatement("DELETE FROM mygame__sample__monster__mana WHERE rowid=?1") { + if let d0 = toolbox.connection.prepareStaticStatement("DELETE FROM mygame__sample__monster__mana WHERE rowid=?1") { _rowid.bindSQLite(d0, parameterId: 1) sqlite3_step(d0) } - if let d1 = toolbox.connection.prepareStatement("DELETE FROM mygame__sample__monster__equipped__type WHERE rowid=?1") { + if let d1 = toolbox.connection.prepareStaticStatement("DELETE FROM mygame__sample__monster__equipped__type WHERE rowid=?1") { _rowid.bindSQLite(d1, parameterId: 1) sqlite3_step(d1) } - if let d2 = toolbox.connection.prepareStatement("DELETE FROM mygame__sample__monster__equipped__Orb__name WHERE rowid=?1") { + if let d2 = toolbox.connection.prepareStaticStatement("DELETE FROM mygame__sample__monster__equipped__Orb__name WHERE rowid=?1") { _rowid.bindSQLite(d2, parameterId: 1) sqlite3_step(d2) } diff --git a/src/tests/monster_v2_mutating_generated.swift b/src/tests/monster_v2_mutating_generated.swift index 272deef54..125aa687b 100644 --- a/src/tests/monster_v2_mutating_generated.swift +++ b/src/tests/monster_v2_mutating_generated.swift @@ -139,7 +139,7 @@ extension MyGame.SampleV2.Monster: SQLiteDflat.SQLiteAtom { guard let sqlite = ((toolbox as? SQLitePersistenceToolbox).map { $0.connection }) else { return false } switch field { case "mana": - guard let insert = sqlite.prepareStatement("INSERT INTO mygame__samplev2__monster__mana (rowid, mana) VALUES (?1, ?2)") else { return false } + guard let insert = sqlite.prepareStaticStatement("INSERT INTO mygame__samplev2__monster__mana (rowid, mana) VALUES (?1, ?2)") else { return false } rowid.bindSQLite(insert, parameterId: 1) let retval = MyGame.SampleV2.Monster.mana.evaluate(object: .table(table)) if retval.unknown { @@ -149,7 +149,7 @@ extension MyGame.SampleV2.Monster: SQLiteDflat.SQLiteAtom { } guard SQLITE_DONE == sqlite3_step(insert) else { return false } case "hp": - guard let insert = sqlite.prepareStatement("INSERT INTO mygame__samplev2__monster__hp (rowid, hp) VALUES (?1, ?2)") else { return false } + guard let insert = sqlite.prepareStaticStatement("INSERT INTO mygame__samplev2__monster__hp (rowid, hp) VALUES (?1, ?2)") else { return false } rowid.bindSQLite(insert, parameterId: 1) let retval = MyGame.SampleV2.Monster.hp.evaluate(object: .table(table)) if retval.unknown { @@ -159,7 +159,7 @@ extension MyGame.SampleV2.Monster: SQLiteDflat.SQLiteAtom { } guard SQLITE_DONE == sqlite3_step(insert) else { return false } case "equipped__type": - guard let insert = sqlite.prepareStatement("INSERT INTO mygame__samplev2__monster__equipped__type (rowid, equipped__type) VALUES (?1, ?2)") else { return false } + guard let insert = sqlite.prepareStaticStatement("INSERT INTO mygame__samplev2__monster__equipped__type (rowid, equipped__type) VALUES (?1, ?2)") else { return false } rowid.bindSQLite(insert, parameterId: 1) let retval = MyGame.SampleV2.Monster.equipped._type.evaluate(object: .table(table)) if retval.unknown { @@ -169,7 +169,7 @@ extension MyGame.SampleV2.Monster: SQLiteDflat.SQLiteAtom { } guard SQLITE_DONE == sqlite3_step(insert) else { return false } case "equipped__Orb__name": - guard let insert = sqlite.prepareStatement("INSERT INTO mygame__samplev2__monster__equipped__Orb__name (rowid, equipped__Orb__name) VALUES (?1, ?2)") else { return false } + guard let insert = sqlite.prepareStaticStatement("INSERT INTO mygame__samplev2__monster__equipped__Orb__name (rowid, equipped__Orb__name) VALUES (?1, ?2)") else { return false } rowid.bindSQLite(insert, parameterId: 1) let retval = MyGame.SampleV2.Monster.equipped.as(MyGame.SampleV2.Orb.self).name.evaluate(object: .table(table)) if retval.unknown { @@ -179,7 +179,7 @@ extension MyGame.SampleV2.Monster: SQLiteDflat.SQLiteAtom { } guard SQLITE_DONE == sqlite3_step(insert) else { return false } case "wear__Orb__name": - guard let insert = sqlite.prepareStatement("INSERT INTO mygame__samplev2__monster__wear__Orb__name (rowid, wear__Orb__name) VALUES (?1, ?2)") else { return false } + guard let insert = sqlite.prepareStaticStatement("INSERT INTO mygame__samplev2__monster__wear__Orb__name (rowid, wear__Orb__name) VALUES (?1, ?2)") else { return false } rowid.bindSQLite(insert, parameterId: 1) let retval = MyGame.SampleV2.Monster.wear.as(MyGame.SampleV2.Orb.self).name.evaluate(object: .table(table)) if retval.unknown { @@ -281,7 +281,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { switch _type { case .creation: let indexSurvey = toolbox.connection.indexSurvey(Monster.indexFields, table: Monster.table) - guard let insert = toolbox.connection.prepareStatement("INSERT INTO mygame__samplev2__monster (__pk0, __pk1, p) VALUES (?1, ?2, ?3)") else { return nil } + guard let insert = toolbox.connection.prepareStaticStatement("INSERT INTO mygame__samplev2__monster (__pk0, __pk1, p) VALUES (?1, ?2, ?3)") else { return nil } name.bindSQLite(insert, parameterId: 1) color.bindSQLite(insert, parameterId: 2) let atom = self._atom @@ -295,7 +295,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { guard SQLITE_DONE == sqlite3_step(insert) else { return nil } _rowid = sqlite3_last_insert_rowid(toolbox.connection.sqlite) if indexSurvey.full.contains("mana") { - guard let i0 = toolbox.connection.prepareStatement("INSERT INTO mygame__samplev2__monster__mana (rowid, mana) VALUES (?1, ?2)") else { return nil } + guard let i0 = toolbox.connection.prepareStaticStatement("INSERT INTO mygame__samplev2__monster__mana (rowid, mana) VALUES (?1, ?2)") else { return nil } _rowid.bindSQLite(i0, parameterId: 1) let r0 = MyGame.SampleV2.Monster.mana.evaluate(object: .object(atom)) if r0.unknown { @@ -306,7 +306,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { guard SQLITE_DONE == sqlite3_step(i0) else { return nil } } if indexSurvey.full.contains("hp") { - guard let i1 = toolbox.connection.prepareStatement("INSERT INTO mygame__samplev2__monster__hp (rowid, hp) VALUES (?1, ?2)") else { return nil } + guard let i1 = toolbox.connection.prepareStaticStatement("INSERT INTO mygame__samplev2__monster__hp (rowid, hp) VALUES (?1, ?2)") else { return nil } _rowid.bindSQLite(i1, parameterId: 1) let r1 = MyGame.SampleV2.Monster.hp.evaluate(object: .object(atom)) if r1.unknown { @@ -317,7 +317,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { guard SQLITE_DONE == sqlite3_step(i1) else { return nil } } if indexSurvey.full.contains("equipped__type") { - guard let i2 = toolbox.connection.prepareStatement("INSERT INTO mygame__samplev2__monster__equipped__type (rowid, equipped__type) VALUES (?1, ?2)") else { return nil } + guard let i2 = toolbox.connection.prepareStaticStatement("INSERT INTO mygame__samplev2__monster__equipped__type (rowid, equipped__type) VALUES (?1, ?2)") else { return nil } _rowid.bindSQLite(i2, parameterId: 1) let r2 = MyGame.SampleV2.Monster.equipped._type.evaluate(object: .object(atom)) if r2.unknown { @@ -328,7 +328,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { guard SQLITE_DONE == sqlite3_step(i2) else { return nil } } if indexSurvey.full.contains("equipped__Orb__name") { - guard let i3 = toolbox.connection.prepareStatement("INSERT INTO mygame__samplev2__monster__equipped__Orb__name (rowid, equipped__Orb__name) VALUES (?1, ?2)") else { return nil } + guard let i3 = toolbox.connection.prepareStaticStatement("INSERT INTO mygame__samplev2__monster__equipped__Orb__name (rowid, equipped__Orb__name) VALUES (?1, ?2)") else { return nil } _rowid.bindSQLite(i3, parameterId: 1) let r3 = MyGame.SampleV2.Monster.equipped.as(MyGame.SampleV2.Orb.self).name.evaluate(object: .object(atom)) if r3.unknown { @@ -339,7 +339,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { guard SQLITE_DONE == sqlite3_step(i3) else { return nil } } if indexSurvey.full.contains("wear__Orb__name") { - guard let i4 = toolbox.connection.prepareStatement("INSERT INTO mygame__samplev2__monster__wear__Orb__name (rowid, wear__Orb__name) VALUES (?1, ?2)") else { return nil } + guard let i4 = toolbox.connection.prepareStaticStatement("INSERT INTO mygame__samplev2__monster__wear__Orb__name (rowid, wear__Orb__name) VALUES (?1, ?2)") else { return nil } _rowid.bindSQLite(i4, parameterId: 1) let r4 = MyGame.SampleV2.Monster.wear.as(MyGame.SampleV2.Orb.self).name.evaluate(object: .object(atom)) if r4.unknown { @@ -360,7 +360,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { return .updated(atom) } let indexSurvey = toolbox.connection.indexSurvey(Monster.indexFields, table: Monster.table) - guard let update = toolbox.connection.prepareStatement("REPLACE INTO mygame__samplev2__monster (__pk0, __pk1, p, rowid) VALUES (?1, ?2, ?3, ?4)") else { return nil } + guard let update = toolbox.connection.prepareStaticStatement("REPLACE INTO mygame__samplev2__monster (__pk0, __pk1, p, rowid) VALUES (?1, ?2, ?3, ?4)") else { return nil } name.bindSQLite(update, parameterId: 1) color.bindSQLite(update, parameterId: 2) toolbox.flatBufferBuilder.clear() @@ -376,7 +376,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { let or0 = MyGame.SampleV2.Monster.mana.evaluate(object: .object(o)) let r0 = MyGame.SampleV2.Monster.mana.evaluate(object: .object(atom)) if or0.unknown != r0.unknown || or0.result != r0.result { - guard let u0 = toolbox.connection.prepareStatement("REPLACE INTO mygame__samplev2__monster__mana (rowid, mana) VALUES (?1, ?2)") else { return nil } + guard let u0 = toolbox.connection.prepareStaticStatement("REPLACE INTO mygame__samplev2__monster__mana (rowid, mana) VALUES (?1, ?2)") else { return nil } _rowid.bindSQLite(u0, parameterId: 1) let r0 = MyGame.SampleV2.Monster.mana.evaluate(object: .object(atom)) if r0.unknown { @@ -391,7 +391,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { let or1 = MyGame.SampleV2.Monster.hp.evaluate(object: .object(o)) let r1 = MyGame.SampleV2.Monster.hp.evaluate(object: .object(atom)) if or1.unknown != r1.unknown || or1.result != r1.result { - guard let u1 = toolbox.connection.prepareStatement("REPLACE INTO mygame__samplev2__monster__hp (rowid, hp) VALUES (?1, ?2)") else { return nil } + guard let u1 = toolbox.connection.prepareStaticStatement("REPLACE INTO mygame__samplev2__monster__hp (rowid, hp) VALUES (?1, ?2)") else { return nil } _rowid.bindSQLite(u1, parameterId: 1) let r1 = MyGame.SampleV2.Monster.hp.evaluate(object: .object(atom)) if r1.unknown { @@ -406,7 +406,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { let or2 = MyGame.SampleV2.Monster.equipped._type.evaluate(object: .object(o)) let r2 = MyGame.SampleV2.Monster.equipped._type.evaluate(object: .object(atom)) if or2.unknown != r2.unknown || or2.result != r2.result { - guard let u2 = toolbox.connection.prepareStatement("REPLACE INTO mygame__samplev2__monster__equipped__type (rowid, equipped__type) VALUES (?1, ?2)") else { return nil } + guard let u2 = toolbox.connection.prepareStaticStatement("REPLACE INTO mygame__samplev2__monster__equipped__type (rowid, equipped__type) VALUES (?1, ?2)") else { return nil } _rowid.bindSQLite(u2, parameterId: 1) let r2 = MyGame.SampleV2.Monster.equipped._type.evaluate(object: .object(atom)) if r2.unknown { @@ -421,7 +421,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { let or3 = MyGame.SampleV2.Monster.equipped.as(MyGame.SampleV2.Orb.self).name.evaluate(object: .object(o)) let r3 = MyGame.SampleV2.Monster.equipped.as(MyGame.SampleV2.Orb.self).name.evaluate(object: .object(atom)) if or3.unknown != r3.unknown || or3.result != r3.result { - guard let u3 = toolbox.connection.prepareStatement("REPLACE INTO mygame__samplev2__monster__equipped__Orb__name (rowid, equipped__Orb__name) VALUES (?1, ?2)") else { return nil } + guard let u3 = toolbox.connection.prepareStaticStatement("REPLACE INTO mygame__samplev2__monster__equipped__Orb__name (rowid, equipped__Orb__name) VALUES (?1, ?2)") else { return nil } _rowid.bindSQLite(u3, parameterId: 1) let r3 = MyGame.SampleV2.Monster.equipped.as(MyGame.SampleV2.Orb.self).name.evaluate(object: .object(atom)) if r3.unknown { @@ -436,7 +436,7 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { let or4 = MyGame.SampleV2.Monster.wear.as(MyGame.SampleV2.Orb.self).name.evaluate(object: .object(o)) let r4 = MyGame.SampleV2.Monster.wear.as(MyGame.SampleV2.Orb.self).name.evaluate(object: .object(atom)) if or4.unknown != r4.unknown || or4.result != r4.result { - guard let u4 = toolbox.connection.prepareStatement("REPLACE INTO mygame__samplev2__monster__wear__Orb__name (rowid, wear__Orb__name) VALUES (?1, ?2)") else { return nil } + guard let u4 = toolbox.connection.prepareStaticStatement("REPLACE INTO mygame__samplev2__monster__wear__Orb__name (rowid, wear__Orb__name) VALUES (?1, ?2)") else { return nil } _rowid.bindSQLite(u4, parameterId: 1) let r4 = MyGame.SampleV2.Monster.wear.as(MyGame.SampleV2.Orb.self).name.evaluate(object: .object(atom)) if r4.unknown { @@ -450,26 +450,26 @@ public final class MonsterChangeRequest: Dflat.ChangeRequest { _type = .none return .updated(atom) case .deletion: - guard let deletion = toolbox.connection.prepareStatement("DELETE FROM mygame__samplev2__monster WHERE rowid=?1") else { return nil } + guard let deletion = toolbox.connection.prepareStaticStatement("DELETE FROM mygame__samplev2__monster WHERE rowid=?1") else { return nil } _rowid.bindSQLite(deletion, parameterId: 1) guard SQLITE_DONE == sqlite3_step(deletion) else { return nil } - if let d0 = toolbox.connection.prepareStatement("DELETE FROM mygame__samplev2__monster__mana WHERE rowid=?1") { + if let d0 = toolbox.connection.prepareStaticStatement("DELETE FROM mygame__samplev2__monster__mana WHERE rowid=?1") { _rowid.bindSQLite(d0, parameterId: 1) sqlite3_step(d0) } - if let d1 = toolbox.connection.prepareStatement("DELETE FROM mygame__samplev2__monster__hp WHERE rowid=?1") { + if let d1 = toolbox.connection.prepareStaticStatement("DELETE FROM mygame__samplev2__monster__hp WHERE rowid=?1") { _rowid.bindSQLite(d1, parameterId: 1) sqlite3_step(d1) } - if let d2 = toolbox.connection.prepareStatement("DELETE FROM mygame__samplev2__monster__equipped__type WHERE rowid=?1") { + if let d2 = toolbox.connection.prepareStaticStatement("DELETE FROM mygame__samplev2__monster__equipped__type WHERE rowid=?1") { _rowid.bindSQLite(d2, parameterId: 1) sqlite3_step(d2) } - if let d3 = toolbox.connection.prepareStatement("DELETE FROM mygame__samplev2__monster__equipped__Orb__name WHERE rowid=?1") { + if let d3 = toolbox.connection.prepareStaticStatement("DELETE FROM mygame__samplev2__monster__equipped__Orb__name WHERE rowid=?1") { _rowid.bindSQLite(d3, parameterId: 1) sqlite3_step(d3) } - if let d4 = toolbox.connection.prepareStatement("DELETE FROM mygame__samplev2__monster__wear__Orb__name WHERE rowid=?1") { + if let d4 = toolbox.connection.prepareStaticStatement("DELETE FROM mygame__samplev2__monster__wear__Orb__name WHERE rowid=?1") { _rowid.bindSQLite(d4, parameterId: 1) sqlite3_step(d4) }