mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Fix failing test that dumpContent ignores shadow tables
This commit is contained in:
1 parent
b9ac9b1ca8
commit
a00a3f7c80
2 files changed
+36
-2
No files matched your search
@@ -252,7 +252,7 @@ extension Database {
|
||||
""")
|
||||
for row in sqlRows {
|
||||
let name: String = row[1]
|
||||
if Database.isSQLiteInternalTable(name) || Database.isGRDBInternalTable(name) {
|
||||
if try ignoresObject(named: name) {
|
||||
continue
|
||||
}
|
||||
stream.writeln(row[0])
|
||||
@@ -266,12 +266,42 @@ extension Database {
|
||||
ORDER BY name COLLATE NOCASE
|
||||
""")
|
||||
.filter {
|
||||
!(Database.isSQLiteInternalTable($0) || Database.isGRDBInternalTable($0))
|
||||
try !ignoresObject(named: $0)
|
||||
}
|
||||
if tables.isEmpty { return }
|
||||
stream.write("\n")
|
||||
try _dumpTables(tables, format: format, tableHeader: .always, stableOrder: true, to: &stream)
|
||||
}
|
||||
|
||||
private func ignoresObject(named name: String) throws -> Bool {
|
||||
if Database.isSQLiteInternalTable(name) { return true }
|
||||
if Database.isGRDBInternalTable(name) { return true }
|
||||
if try isShadowTable(name) { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
private func isShadowTable(_ tableName: String) throws -> Bool {
|
||||
#if GRDBCUSTOMSQLITE || GRDBCIPHER
|
||||
// Maybe SQLCipher is too old: check actual version
|
||||
if sqlite3_libversion_number() >= 3037000 {
|
||||
guard let table = try table(tableName) else {
|
||||
// Not a table
|
||||
return false
|
||||
}
|
||||
return table.kind == .shadow
|
||||
}
|
||||
#else
|
||||
if #available(iOS 15.4, macOS 12.4, tvOS 15.4, watchOS 8.5, *) { // SQLite 3.37+
|
||||
guard let table = try table(tableName) else {
|
||||
// Not a table
|
||||
return false
|
||||
}
|
||||
return table.kind == .shadow
|
||||
}
|
||||
#endif
|
||||
// Don't know
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/// Options for printing table names.
|
||||
|
||||
@@ -1337,6 +1337,10 @@ final class DatabaseDumpTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
func test_dumpContent_ignores_shadow_tables() throws {
|
||||
guard sqlite3_libversion_number() >= 3037000 else {
|
||||
throw XCTSkip("Can't detect shadow tables")
|
||||
}
|
||||
|
||||
try makeDatabaseQueue().write { db in
|
||||
try db.create(table: "document") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
|
||||
Reference in new issue
Block a user