mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Merge pull request #1288 from jcavar/feature/strict-support
Add support for .strict table option in 3.37+
This commit is contained in:
3 files changed
+32
-9
No files matched your search
@@ -241,8 +241,16 @@ public struct TableOptions: OptionSet {
|
||||
/// Creates a without rowid table. See <https://www.sqlite.org/withoutrowid.html>
|
||||
public static let withoutRowID = TableOptions(rawValue: 1 << 2)
|
||||
|
||||
#if GRDBCUSTOMSQLITE
|
||||
/// Creates a strict table. See <https://www.sqlite.org/stricttables.html>
|
||||
#if GRDBCUSTOMSQLITE || GRDBCIPHER
|
||||
/// Creates a STRICT table
|
||||
///
|
||||
/// See <https://www.sqlite.org/stricttables.html>
|
||||
public static let strict = TableOptions(rawValue: 1 << 3)
|
||||
#else
|
||||
/// Creates a STRICT table
|
||||
///
|
||||
/// See <https://www.sqlite.org/stricttables.html>
|
||||
@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")
|
||||
}
|
||||
|
||||
@@ -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
|
||||
# ============
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user