diff --git a/GRDB/QueryInterface/Schema/TableDefinition.swift b/GRDB/QueryInterface/Schema/TableDefinition.swift index d09e3183b9..7596eaeb84 100644 --- a/GRDB/QueryInterface/Schema/TableDefinition.swift +++ b/GRDB/QueryInterface/Schema/TableDefinition.swift @@ -241,8 +241,16 @@ public struct TableOptions: OptionSet { /// Creates a without rowid table. See public static let withoutRowID = TableOptions(rawValue: 1 << 2) -#if GRDBCUSTOMSQLITE - /// Creates a strict table. See +#if GRDBCUSTOMSQLITE || GRDBCIPHER + /// Creates a STRICT table + /// + /// See + public static let strict = TableOptions(rawValue: 1 << 3) +#else + /// Creates a STRICT table + /// + /// See + @available(iOS 15.4, macOS 12.4, tvOS 15.4, watchOS 8.5, *) // SQLite 3.37+ public static let strict = TableOptions(rawValue: 1 << 3) #endif } @@ -641,12 +649,17 @@ public final class TableDefinition { var tableOptions: [String] = [] -#if GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE || GRDBCIPHER if options.contains(.strict) { tableOptions.append("STRICT") } +#else + if #available(iOS 15.4, macOS 12.4, tvOS 15.4, watchOS 8.5, *) { + if options.contains(.strict) { + tableOptions.append("STRICT") + } + } #endif - if options.contains(.withoutRowID) { tableOptions.append("WITHOUT ROWID") } diff --git a/Makefile b/Makefile index c13ee2cdd7..72dc5c48a2 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ # make distclean - Restore repository to a pristine state default: test -smokeTest: test_framework_GRDBiOS_maxTarget test_framework_GRDBiOS_minTarget test_framework_SQLCipher4Encrypted test_framework_GRDBCustomSQLiteiOS_maxTarget test_SPM +smokeTest: test_framework_GRDBiOS_maxTarget test_framework_GRDBiOS_minTarget test_framework_SQLCipher3 test_framework_SQLCipher4Encrypted test_framework_GRDBCustomSQLiteiOS_maxTarget test_SPM # Requirements # ============ diff --git a/Tests/GRDBTests/TableDefinitionTests.swift b/Tests/GRDBTests/TableDefinitionTests.swift index f9ee530830..e63c134d69 100644 --- a/Tests/GRDBTests/TableDefinitionTests.swift +++ b/Tests/GRDBTests/TableDefinitionTests.swift @@ -44,10 +44,21 @@ class TableDefinitionTests: GRDBTestCase { ) WITHOUT ROWID """) } + } + + func testStrictTableCreationOption() throws { + guard sqlite3_libversion_number() >= 3037000 else { + throw XCTSkip("STRICT tables are not available") + } + #if !GRDBCUSTOMSQLITE && !GRDBCIPHER + guard #available(iOS 15.4, macOS 12.4, tvOS 15.4, watchOS 8.5, *) else { + throw XCTSkip("STRICT tables are not available") + } + #endif -#if GRDBCUSTOMSQLITE + let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.create(table: "test3", options: [.strict, .withoutRowID]) { t in + try db.create(table: "test3", options: [.strict]) { t in t.column("id", .integer).primaryKey() t.column("a", .integer) t.column("b", .real) @@ -63,7 +74,7 @@ class TableDefinitionTests: GRDBTestCase { "c" TEXT, \ "d" BLOB, \ "e" ANY\ - ) STRICT, WITHOUT ROWID + ) STRICT """) do { @@ -72,7 +83,6 @@ class TableDefinitionTests: GRDBTestCase { } catch DatabaseError.SQLITE_CONSTRAINT_DATATYPE { } } -#endif } func testColumnLiteral() throws {