Merge branch 'development'

This commit is contained in:
Gwendal Roué committed 2024-01-06 19:56:07 +01:00
commit 181ccd8d7d
7 files changed
+120 -6

No files matched your search

+7 -1
View File
@@ -7,7 +7,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
#### 6.x Releases
- `6.24.x` Releases - [6.24.0](#6240)
- `6.24.x` Releases - [6.24.0](#6240) - [6.24.1](#6241)
- `6.23.x` Releases - [6.23.0](#6230)
- `6.22.x` Releases - [6.22.0](#6220)
- `6.21.x` Releases - [6.21.0](#6210)
@@ -122,6 +122,12 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
---
## 6.24.1
Released January 6, 2024
- **New**: [#1477](https://github.com/groue/GRDB.swift/pull/1477): Remove shadow tables from database dump
## 6.24.0
Released January 6, 2024
+1 -1
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'GRDB.swift'
s.version = '6.24.0'
s.version = '6.24.1'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.summary = 'A toolkit for SQLite databases, with a focus on application development.'
+35 -2
View File
@@ -129,6 +129,9 @@ extension Database {
///
/// > Note: Internal SQLite and GRDB schema objects are not recorded
/// > (those with a name that starts with "sqlite_" or "grdb_").
/// >
/// > [Shadow tables](https://www.sqlite.org/vtab.html#xshadowname) are
/// > not recorded, starting SQLite 3.37+.
///
/// - Parameters:
/// - format: The output format.
@@ -252,7 +255,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 +269,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.
+3
View File
@@ -120,6 +120,9 @@ extension DatabaseReader {
///
/// > Note: Internal SQLite and GRDB schema objects are not recorded
/// > (those with a name that starts with "sqlite_" or "grdb_").
/// >
/// > [Shadow tables](https://www.sqlite.org/vtab.html#xshadowname) are
/// > not recorded, starting SQLite 3.37+.
///
/// - Parameters:
/// - format: The output format.
+1 -1
View File
@@ -15,7 +15,7 @@
<a href="https://github.com/groue/GRDB.swift/actions/workflows/CI.yml"><img alt="CI Status" src="https://github.com/groue/GRDB.swift/actions/workflows/CI.yml/badge.svg?branch=master"></a>
</p>
**Latest release**: January 6, 2024 • [version 6.24.0](https://github.com/groue/GRDB.swift/tree/v6.24.0) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 5 to GRDB 6](Documentation/GRDB6MigrationGuide.md)
**Latest release**: January 6, 2024 • [version 6.24.1](https://github.com/groue/GRDB.swift/tree/v6.24.1) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 5 to GRDB 6](Documentation/GRDB6MigrationGuide.md)
**Requirements**: iOS 11.0+ / macOS 10.13+ / tvOS 11.0+ / watchOS 4.0+ &bull; SQLite 3.19.3+ &bull; Swift 5.7+ / Xcode 14+
+1 -1
View File
@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>6.24.0</string>
<string>6.24.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
+72
View File
@@ -1336,6 +1336,78 @@ 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")
t.column("body")
}
try db.execute(sql: "INSERT INTO document VALUES (1, 'Hello world!')")
try db.create(virtualTable: "document_ft", using: FTS4()) { t in
t.synchronize(withTable: "document")
t.column("body")
}
let stream = TestStream()
try db.dumpContent(to: stream)
print(stream.output)
XCTAssertEqual(stream.output, """
sqlite_master
CREATE TABLE "document" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "body");
CREATE TRIGGER "__document_ft_ai" AFTER INSERT ON "document" BEGIN
INSERT INTO "document_ft"("docid", "body") VALUES(new."id", new."body");
END;
CREATE TRIGGER "__document_ft_au" AFTER UPDATE ON "document" BEGIN
INSERT INTO "document_ft"("docid", "body") VALUES(new."id", new."body");
END;
CREATE TRIGGER "__document_ft_bd" BEFORE DELETE ON "document" BEGIN
DELETE FROM "document_ft" WHERE docid=old."id";
END;
CREATE TRIGGER "__document_ft_bu" BEFORE UPDATE ON "document" BEGIN
DELETE FROM "document_ft" WHERE docid=old."id";
END;
CREATE VIRTUAL TABLE "document_ft" USING fts4(body, content="document");
document
1|Hello world!
document_ft
Hello world!
""")
}
}
func test_dumpContent_ignores_GRDB_internal_tables() throws {
let dbQueue = try makeDatabaseQueue()
var migrator = DatabaseMigrator()
migrator.registerMigration("v1") { db in
try db.create(table: "player") { t in
t.autoIncrementedPrimaryKey("id")
}
}
try migrator.migrate(dbQueue)
try dbQueue.read { db in
let stream = TestStream()
try db.dumpContent(to: stream)
print(stream.output)
XCTAssertEqual(stream.output, """
sqlite_master
CREATE TABLE "player" ("id" INTEGER PRIMARY KEY AUTOINCREMENT);
player
""")
}
}
// MARK: - Support Databases
private func makeValuesDatabase() throws -> DatabaseQueue {