Skip to content

Commit 6caa27c

Browse files
authored
Merge pull request groue#1288 from jcavar/feature/strict-support
Add support for .strict table option in 3.37+
2 parents 9531a7f + 6ca3bb0 commit 6caa27c

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

GRDB/QueryInterface/Schema/TableDefinition.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,16 @@ public struct TableOptions: OptionSet {
241241
/// Creates a without rowid table. See <https://www.sqlite.org/withoutrowid.html>
242242
public static let withoutRowID = TableOptions(rawValue: 1 << 2)
243243

244-
#if GRDBCUSTOMSQLITE
245-
/// Creates a strict table. See <https://www.sqlite.org/stricttables.html>
244+
#if GRDBCUSTOMSQLITE || GRDBCIPHER
245+
/// Creates a STRICT table
246+
///
247+
/// See <https://www.sqlite.org/stricttables.html>
248+
public static let strict = TableOptions(rawValue: 1 << 3)
249+
#else
250+
/// Creates a STRICT table
251+
///
252+
/// See <https://www.sqlite.org/stricttables.html>
253+
@available(iOS 15.4, macOS 12.4, tvOS 15.4, watchOS 8.5, *) // SQLite 3.37+
246254
public static let strict = TableOptions(rawValue: 1 << 3)
247255
#endif
248256
}
@@ -641,12 +649,17 @@ public final class TableDefinition {
641649

642650
var tableOptions: [String] = []
643651

644-
#if GRDBCUSTOMSQLITE
652+
#if GRDBCUSTOMSQLITE || GRDBCIPHER
645653
if options.contains(.strict) {
646654
tableOptions.append("STRICT")
647655
}
656+
#else
657+
if #available(iOS 15.4, macOS 12.4, tvOS 15.4, watchOS 8.5, *) {
658+
if options.contains(.strict) {
659+
tableOptions.append("STRICT")
660+
}
661+
}
648662
#endif
649-
650663
if options.contains(.withoutRowID) {
651664
tableOptions.append("WITHOUT ROWID")
652665
}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# make distclean - Restore repository to a pristine state
99

1010
default: test
11-
smokeTest: test_framework_GRDBiOS_maxTarget test_framework_GRDBiOS_minTarget test_framework_SQLCipher4Encrypted test_framework_GRDBCustomSQLiteiOS_maxTarget test_SPM
11+
smokeTest: test_framework_GRDBiOS_maxTarget test_framework_GRDBiOS_minTarget test_framework_SQLCipher3 test_framework_SQLCipher4Encrypted test_framework_GRDBCustomSQLiteiOS_maxTarget test_SPM
1212

1313
# Requirements
1414
# ============

Tests/GRDBTests/TableDefinitionTests.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,21 @@ class TableDefinitionTests: GRDBTestCase {
4444
) WITHOUT ROWID
4545
""")
4646
}
47+
}
48+
49+
func testStrictTableCreationOption() throws {
50+
guard sqlite3_libversion_number() >= 3037000 else {
51+
throw XCTSkip("STRICT tables are not available")
52+
}
53+
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
54+
guard #available(iOS 15.4, macOS 12.4, tvOS 15.4, watchOS 8.5, *) else {
55+
throw XCTSkip("STRICT tables are not available")
56+
}
57+
#endif
4758

48-
#if GRDBCUSTOMSQLITE
59+
let dbQueue = try makeDatabaseQueue()
4960
try dbQueue.inDatabase { db in
50-
try db.create(table: "test3", options: [.strict, .withoutRowID]) { t in
61+
try db.create(table: "test3", options: [.strict]) { t in
5162
t.column("id", .integer).primaryKey()
5263
t.column("a", .integer)
5364
t.column("b", .real)
@@ -63,7 +74,7 @@ class TableDefinitionTests: GRDBTestCase {
6374
"c" TEXT, \
6475
"d" BLOB, \
6576
"e" ANY\
66-
) STRICT, WITHOUT ROWID
77+
) STRICT
6778
""")
6879

6980
do {
@@ -72,7 +83,6 @@ class TableDefinitionTests: GRDBTestCase {
7283
} catch DatabaseError.SQLITE_CONSTRAINT_DATATYPE {
7384
}
7485
}
75-
#endif
7686
}
7787

7888
func testColumnLiteral() throws {

0 commit comments

Comments
 (0)