Skip to content

Commit 2e59493

Browse files
committed
Skip tests for older versions of SQLite
1 parent 1d6167f commit 2e59493

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Tests/SQLiteTests/ConnectionTests.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,21 @@ class ConnectionTests : SQLiteTestCase {
156156
}
157157

158158
func test_transaction_rollsBackTransactionsIfCommitsFail() {
159+
let sqliteVersion = String(describing: try! db.scalar("SELECT sqlite_version()")!)
160+
.split(separator: ".").flatMap { Int($0) }
161+
// PRAGMA defer_foreign_keys only supported in SQLite >= 3.8.0
162+
guard sqliteVersion[0] == 3 && sqliteVersion[1] >= 8 else {
163+
NSLog("skipping test for SQLite version \(sqliteVersion)")
164+
return
165+
}
159166
// This test case needs to emulate an environment where the individual statements succeed, but committing the
160167
// transaction fails. Using deferred foreign keys is one option to achieve this.
161168
try! db.execute("PRAGMA foreign_keys = ON;")
169+
try! db.execute("PRAGMA defer_foreign_keys = ON;")
162170
let stmt = try! db.prepare("INSERT INTO users (email, manager_id) VALUES (?, ?)", "alice@example.com", 100)
163171

164172
do {
165173
try db.transaction {
166-
try db.execute("PRAGMA defer_foreign_keys = ON;")
167174
try stmt.run()
168175
}
169176
XCTFail("expected error")

0 commit comments

Comments
 (0)