@@ -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