import XCTest import GRDB #if GRDB_COMPARE import SQLite #endif private let insertedRowCount = 20_000 // Here we insert rows, referencing statement arguments by index. class InsertPositionalValuesTests: XCTestCase { func testSQLite() { let databaseFileName = "GRDBPerformanceTests-\(ProcessInfo.processInfo.globallyUniqueString).sqlite" let databasePath = (NSTemporaryDirectory() as NSString).appendingPathComponent(databaseFileName) defer { let dbQueue = try! DatabaseQueue(path: databasePath) try! dbQueue.inDatabase { db in XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, insertedRowCount) XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT MIN(i0) FROM items")!, 0) XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT MAX(i9) FROM items")!, insertedRowCount - 1) } try! FileManager.default.removeItem(atPath: databasePath) } measure { _ = try? FileManager.default.removeItem(atPath: databasePath) var connection: OpaquePointer? = nil sqlite3_open_v2(databasePath, &connection, 0x00000004 /*SQLITE_OPEN_CREATE*/ | 0x00000002 /*SQLITE_OPEN_READWRITE*/, nil) sqlite3_exec(connection, "CREATE TABLE items (i0 INT, i1 INT, i2 INT, i3 INT, i4 INT, i5 INT, i6 INT, i7 INT, i8 INT, i9 INT)", nil, nil, nil) sqlite3_exec(connection, "BEGIN TRANSACTION", nil, nil, nil) var statement: OpaquePointer? = nil sqlite3_prepare_v2(connection, "INSERT INTO items (i0, i1, i2, i3, i4, i5, i6, i7, i8, i9) VALUES (?,?,?,?,?,?,?,?,?,?)", -1, &statement, nil) for i in Int64(0).. Void in db.shouldCacheStatements = true for i in 0..