From 4a5d4d6e49a37ba81dd6983e313e0e2aec6751ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 6 Jun 2023 08:06:06 +0200 Subject: [PATCH 1/9] Fix Xcode 15 warnings --- GRDB/Core/FetchRequest.swift | 4 ++-- .../Request/QueryInterfaceRequest.swift | 2 +- GRDB/QueryInterface/SQL/Table.swift | 24 +++++++++---------- GRDB/Utils/Pool.swift | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/GRDB/Core/FetchRequest.swift b/GRDB/Core/FetchRequest.swift index c916c2d58..8d9d1d526 100644 --- a/GRDB/Core/FetchRequest.swift +++ b/GRDB/Core/FetchRequest.swift @@ -217,8 +217,8 @@ public struct AnyFetchRequest { /// /// // AnyFetchRequest /// let rowRequest = playerRequest.asRequest(of: Row.self) - public func asRequest(of type: RowDecoder.Type) -> AnyFetchRequest { - AnyFetchRequest(request: request) + public func asRequest(of type: T.Type) -> AnyFetchRequest { + AnyFetchRequest(request: request) } } diff --git a/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift b/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift index 9ff5482db..626ac8eb8 100644 --- a/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift +++ b/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift @@ -436,7 +436,7 @@ extension QueryInterfaceRequest: DerivableRequest { } } - public func with(_ cte: CommonTableExpression) -> Self { + public func with(_ cte: CommonTableExpression) -> Self { with { $0.relation.ctes[cte.tableName] = cte.cte } diff --git a/GRDB/QueryInterface/SQL/Table.swift b/GRDB/QueryInterface/SQL/Table.swift index 3b5486a7f..0bad29a8e 100644 --- a/GRDB/QueryInterface/SQL/Table.swift +++ b/GRDB/QueryInterface/SQL/Table.swift @@ -298,10 +298,10 @@ extension Table { /// let maxScore: Int = row[1] /// } /// ``` - public func select( + public func select( _ selection: [any SQLSelectable], - as type: RowDecoder.Type = RowDecoder.self) - -> QueryInterfaceRequest + as type: T.Type = T.self) + -> QueryInterfaceRequest { all().select(selection, as: type) } @@ -328,10 +328,10 @@ extension Table { /// let maxScore: Int = row[1] /// } /// ``` - public func select( + public func select( _ selection: any SQLSelectable..., - as type: RowDecoder.Type = RowDecoder.self) - -> QueryInterfaceRequest + as type: T.Type = T.self) + -> QueryInterfaceRequest { all().select(selection, as: type) } @@ -353,11 +353,11 @@ extension Table { /// let request = playerTable.select(sql: "IFNULL(name, ?)", arguments: [defaultName], as: String.self) /// let names = try request.fetchAll(db) // [String] /// ``` - public func select( + public func select( sql: String, arguments: StatementArguments = StatementArguments(), - as type: RowDecoder.Type = RowDecoder.self) - -> QueryInterfaceRequest + as type: T.Type = T.self) + -> QueryInterfaceRequest { all().select(SQL(sql: sql, arguments: arguments), as: type) } @@ -376,10 +376,10 @@ extension Table { /// let request = playerTable.select(literal: "IFNULL(name, \(defaultName))", as: String.self) /// let names = try request.fetchAll(db) // [String] /// ``` - public func select( + public func select( literal sqlLiteral: SQL, - as type: RowDecoder.Type = RowDecoder.self) - -> QueryInterfaceRequest + as type: T.Type = T.self) + -> QueryInterfaceRequest { all().select(sqlLiteral, as: type) } diff --git a/GRDB/Utils/Pool.swift b/GRDB/Utils/Pool.swift index d6303f4e7..6e1014c75 100644 --- a/GRDB/Utils/Pool.swift +++ b/GRDB/Utils/Pool.swift @@ -163,7 +163,7 @@ final class Pool { /// Blocks until no element is used, and runs the `barrier` function before /// any other element is dequeued. - func barrier(execute barrier: () throws -> T) rethrows -> T { + func barrier(execute barrier: () throws -> R) rethrows -> R { try barrierQueue.sync(flags: [.barrier]) { itemsGroup.wait() return try barrier() From ea1353bd6c96a752458985d17d2c269495bb58b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 6 Jun 2023 08:13:43 +0200 Subject: [PATCH 2/9] Remove invalid documentation link --- GRDB/Core/FetchRequest.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/GRDB/Core/FetchRequest.swift b/GRDB/Core/FetchRequest.swift index 8d9d1d526..80ed0e8ea 100644 --- a/GRDB/Core/FetchRequest.swift +++ b/GRDB/Core/FetchRequest.swift @@ -58,10 +58,6 @@ /// - ``makePreparedRequest(_:forSingleResult:)`` /// - ``PreparedRequest`` /// -/// ### Database Observation Support -/// -/// - ``databaseRegion(_:)`` -/// /// ### Adapting the Fetched Rows /// /// - ``adapted(_:)`` From c3664e2b16b1096d02c3ee625faa769aef1e5c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 6 Jun 2023 08:15:02 +0200 Subject: [PATCH 3/9] Fix Xcode 15 DocC warnings --- GRDB/Core/StatementColumnConvertible.swift | 2 +- GRDB/QueryInterface/SQL/SQLExpression.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/GRDB/Core/StatementColumnConvertible.swift b/GRDB/Core/StatementColumnConvertible.swift index 6c63c2ced..3b18bcb9a 100644 --- a/GRDB/Core/StatementColumnConvertible.swift +++ b/GRDB/Core/StatementColumnConvertible.swift @@ -89,7 +89,7 @@ public protocol StatementColumnConvertible { /// /// Do not check for `NULL` in your implementation of this method. Null /// database values are handled - /// in ``fromStatement(_:atUncheckedIndex:)-2i8y6``. + /// in ``StatementColumnConvertible/fromStatement(_:atUncheckedIndex:)-2i8y6``. /// /// For example, here is the how Int64 adopts StatementColumnConvertible: /// diff --git a/GRDB/QueryInterface/SQL/SQLExpression.swift b/GRDB/QueryInterface/SQL/SQLExpression.swift index a085c1d2c..fa8d1db7c 100644 --- a/GRDB/QueryInterface/SQL/SQLExpression.swift +++ b/GRDB/QueryInterface/SQL/SQLExpression.swift @@ -1965,7 +1965,7 @@ extension SQLSpecificExpressible { /// Returns an aliased column with the same name as the coding key. /// - /// See ``forKey(_:)-3xk0``. + /// See . public func forKey(_ key: some CodingKey) -> SQLSelection { forKey(key.stringValue) } From 3a1c2117461fa5b40b92e50aa32c79380c0933a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Rou=C3=A9?= Date: Thu, 8 Jun 2023 12:17:27 +0200 Subject: [PATCH 4/9] Address #1389 by forcing the user to specify a tracked region This is technically a breaking change, but nobody will notice it. --- .../Extension/ValueObservation.md | 6 +-- GRDB/ValueObservation/ValueObservation.swift | 37 ++++++++++--------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/GRDB/Documentation.docc/Extension/ValueObservation.md b/GRDB/Documentation.docc/Extension/ValueObservation.md index ac5fdb6ab..4b61af095 100644 --- a/GRDB/Documentation.docc/Extension/ValueObservation.md +++ b/GRDB/Documentation.docc/Extension/ValueObservation.md @@ -159,7 +159,7 @@ let cancellable = try sharedObservation While the standard ``tracking(_:)`` method lets you track changes to a fetched value and receive any changes to it, sometimes your use case might require more granular control. -Consider a scenario where you'd like to get a specific Player's row, but only when their `score` column changes. You can use ``tracking(region:fetch:)`` to do just that: +Consider a scenario where you'd like to get a specific Player's row, but only when their `score` column changes. You can use ``tracking(region:_:fetch:)`` to do just that: ```swift let observation = ValueObservation.tracking( @@ -172,7 +172,7 @@ let observation = ValueObservation.tracking( ) ``` -This ``tracking(region:fetch:)`` method lets you entirely separate the **observed region** from the **fetched value** itself, for maximum flexibility. See ``DatabaseRegionConvertible`` for more information about the regions that can be tracked. +This ``tracking(region:_:fetch:)`` method lets you entirely separate the **observed region(s)** from the **fetched value** itself, for maximum flexibility. See ``DatabaseRegionConvertible`` for more information about the regions that can be tracked. ## ValueObservation Performance @@ -228,7 +228,7 @@ When needed, you can help GRDB optimize observations and reduce database content - ``tracking(_:)`` - ``trackingConstantRegion(_:)`` -- ``tracking(region:fetch:)`` +- ``tracking(region:_:fetch:)`` - ``tracking(regions:fetch:)`` ### Creating a Shared Observation diff --git a/GRDB/ValueObservation/ValueObservation.swift b/GRDB/ValueObservation/ValueObservation.swift index 6859dfa51..696eae6a1 100644 --- a/GRDB/ValueObservation/ValueObservation.swift +++ b/GRDB/ValueObservation/ValueObservation.swift @@ -722,50 +722,53 @@ extension ValueObservation { /// /// ```swift /// // Tracks the full database - /// let observation = ValueObservation.tracking + /// let observation = ValueObservation.tracking( /// region: .fullDatabase, /// fetch: { db in ... }) /// /// // Tracks the full 'player' table - /// let observation = ValueObservation.tracking + /// let observation = ValueObservation.tracking( /// region: Player.all(), /// fetch: { db in ... }) /// /// // Tracks the full 'player' table - /// let observation = ValueObservation.tracking + /// let observation = ValueObservation.tracking( /// region: Table("player"), /// fetch: { db in ... }) /// /// // Tracks the row with id 42 in the 'player' table - /// let observation = ValueObservation.tracking + /// let observation = ValueObservation.tracking( /// region: Player.filter(id: 42), /// fetch: { db in ... }) /// /// // Tracks the 'score' column in the 'player' table - /// let observation = ValueObservation.tracking + /// let observation = ValueObservation.tracking( /// region: Player.select(Column("score"), /// fetch: { db in ... }) /// /// // Tracks the 'score' column in the 'player' table - /// let observation = ValueObservation.tracking + /// let observation = ValueObservation.tracking( /// region: SQLRequest("SELECT score FROM player"), /// fetch: { db in ... }) /// /// // Tracks both the 'player' and 'team' tables - /// let observation = ValueObservation.tracking + /// let observation = ValueObservation.tracking( /// region: Player.all(), Team.all(), /// fetch: { db in ... }) /// ``` /// - /// - parameter region: A list of observed regions. + /// - parameter region: A region to observe. + /// - parameter otherRegions: A list of supplementary regions + /// to observe. /// - parameter fetch: The closure that fetches the observed value. public static func tracking( - region: any DatabaseRegionConvertible..., + region: any DatabaseRegionConvertible, + _ otherRegions: any DatabaseRegionConvertible..., fetch: @escaping (Database) throws -> Value) -> Self where Reducer == ValueReducers.Fetch { - tracking(regions: region, fetch: fetch) + tracking(regions: [region] + otherRegions, fetch: fetch) } /// Creates a `ValueObservation` that notifies the fetched value whenever @@ -778,37 +781,37 @@ extension ValueObservation { /// /// ```swift /// // Tracks the full database - /// let observation = ValueObservation.tracking + /// let observation = ValueObservation.tracking( /// regions: [.fullDatabase], /// fetch: { db in ... }) /// /// // Tracks the full 'player' table - /// let observation = ValueObservation.tracking + /// let observation = ValueObservation.tracking( /// regions: [Player.all()], /// fetch: { db in ... }) /// /// // Tracks the full 'player' table - /// let observation = ValueObservation.tracking + /// let observation = ValueObservation.tracking( /// regions: [Table("player")], /// fetch: { db in ... }) /// /// // Tracks the row with id 42 in the 'player' table - /// let observation = ValueObservation.tracking + /// let observation = ValueObservation.tracking( /// regions: [Player.filter(id: 42)], /// fetch: { db in ... }) /// /// // Tracks the 'score' column in the 'player' table - /// let observation = ValueObservation.tracking + /// let observation = ValueObservation.tracking( /// regions: [Player.select(Column("score")], /// fetch: { db in ... }) /// /// // Tracks the 'score' column in the 'player' table - /// let observation = ValueObservation.tracking + /// let observation = ValueObservation.tracking( /// regions: [SQLRequest("SELECT score FROM player")], /// fetch: { db in ... }) /// /// // Tracks both the 'player' and 'team' tables - /// let observation = ValueObservation.tracking + /// let observation = ValueObservation.tracking( /// regions: [Player.all(), Team.all()], /// fetch: { db in ... }) /// ``` From 89899432baa92fd6a5e740f2a73846fb3c18a172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 11 Jun 2023 12:39:26 +0200 Subject: [PATCH 5/9] Failing test for #1390 --- Tests/GRDBTests/FTS5TableBuilderTests.swift | 38 +++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Tests/GRDBTests/FTS5TableBuilderTests.swift b/Tests/GRDBTests/FTS5TableBuilderTests.swift index 3f6da1618..b44dc6589 100644 --- a/Tests/GRDBTests/FTS5TableBuilderTests.swift +++ b/Tests/GRDBTests/FTS5TableBuilderTests.swift @@ -334,5 +334,43 @@ class FTS5TableBuilderTests: GRDBTestCase { } } } + + // Regression test for + func testIssue1390() throws { +#if GRDBCUSTOMSQLITE || GRDBCIPHER + guard sqlite3_libversion_number() >= 3035000 else { + throw XCTSkip("UPSERT is not available") + } +#else + guard #available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) else { + throw XCTSkip("UPSERT is not available") + } +#endif + + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + struct Content: Codable, Hashable, PersistableRecord { + var id: String + var text: String + } + + try db.create(table: "content") { t in + t.primaryKey("id", .text) + t.column("text", .text) + } + + try db.create(virtualTable: "fts", using: FTS5()) { t in + t.tokenizer = .porter() + t.synchronize(withTable: "content") + t.column("id").notIndexed() + t.column("text") + } + + try db.inTransaction { + try Content(id: "foobar", text: "baz").upsert(db) + return .commit + } + } + } } #endif From ea7ebe1ff5aa21f8ed52c86f86a859d3d648b5b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 11 Jun 2023 12:43:58 +0200 Subject: [PATCH 6/9] Fix failing test for #1390 --- GRDB/Record/MutablePersistableRecord+Upsert.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/GRDB/Record/MutablePersistableRecord+Upsert.swift b/GRDB/Record/MutablePersistableRecord+Upsert.swift index 9cca9cd20..4374c1960 100644 --- a/GRDB/Record/MutablePersistableRecord+Upsert.swift +++ b/GRDB/Record/MutablePersistableRecord+Upsert.swift @@ -434,6 +434,15 @@ extension MutablePersistableRecord { // Rowid is the last column let rowid: Int64 = row[row.count - 1] let returned = try decode(row) + + // Now that we have fetched the values we need, we could stop + // there. But let's make sure we fully consume the cursor + // anyway, until SQLITE_DONE. This is necessary, for example, + // for upserts in tables that are synchronized with an + // FTS5 table. + // See + while try cursor.next() != nil { } + return (rowid, returned) } From 4f00e405c3ad37678511d510e70c838b0be74e71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 11 Jun 2023 15:40:02 +0200 Subject: [PATCH 7/9] CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b1ddd195..b964591a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -113,6 +113,12 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: --- +## Next Version + +- **Fixed**: Fixed Xcode 15 warnings +- **Fixed**: [#1391](https://github.com/groue/GRDB.swift/pull/1391) Fix upsert in FTS5-synchronized tables + + ## 6.15.0 Released June 2, 2023 • [diff](https://github.com/groue/GRDB.swift/compare/v6.14.0...v6.15.0) From 459726f9af56e09f6337ec4fe3b250cb31c26180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Rou=C3=A9?= Date: Thu, 15 Jun 2023 14:17:48 +0200 Subject: [PATCH 8/9] Improve documentation of erase() --- GRDB/Core/DatabaseWriter.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GRDB/Core/DatabaseWriter.swift b/GRDB/Core/DatabaseWriter.swift index 16956c6f1..7d9480e11 100644 --- a/GRDB/Core/DatabaseWriter.swift +++ b/GRDB/Core/DatabaseWriter.swift @@ -468,7 +468,7 @@ extension DatabaseWriter { // MARK: - Erasing the content of the database - /// Erases the content of the database. + /// Erase the database: delete all content, drop all tables, etc. @_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails public func erase() throws { try barrierWriteWithoutTransaction { try $0.erase() } @@ -687,7 +687,7 @@ extension DatabaseWriter { } } - /// Erases the content of the database. + /// Erase the database: delete all content, drop all tables, etc. /// /// - note: [**🔥 EXPERIMENTAL**](https://github.com/groue/GRDB.swift/blob/master/README.md#what-are-experimental-features) @available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) From b27e378cfa680c781a2223d42e67b713c33f6a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 17 Jun 2023 12:04:26 +0200 Subject: [PATCH 9/9] v6.15.1 --- CHANGELOG.md | 6 ++++-- GRDB.swift.podspec | 2 +- README.md | 2 +- Support/Info.plist | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b964591a8..baed700a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: #### 6.x Releases -- `6.15.x` Releases - [6.15.0](#6150) +- `6.15.x` Releases - [6.15.0](#6150) - [6.15.1](#6151) - `6.14.x` Releases - [6.14.0](#6140) - `6.13.x` Releases - [6.13.0](#6130) - `6.12.x` Releases - [6.12.0](#6120) @@ -113,7 +113,9 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: --- -## Next Version +## 6.15.1 + +Released June 17, 2023 • [diff](https://github.com/groue/GRDB.swift/compare/v6.15.0...v6.15.1) - **Fixed**: Fixed Xcode 15 warnings - **Fixed**: [#1391](https://github.com/groue/GRDB.swift/pull/1391) Fix upsert in FTS5-synchronized tables diff --git a/GRDB.swift.podspec b/GRDB.swift.podspec index e4c0412c3..594701479 100644 --- a/GRDB.swift.podspec +++ b/GRDB.swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GRDB.swift' - s.version = '6.15.0' + s.version = '6.15.1' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'A toolkit for SQLite databases, with a focus on application development.' diff --git a/README.md b/README.md index 427af3037..636350339 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ CI Status

-**Latest release**: June 2, 2023 • [version 6.15.0](https://github.com/groue/GRDB.swift/tree/v6.15.0) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 5 to GRDB 6](Documentation/GRDB6MigrationGuide.md) +**Latest release**: June 17, 2023 • [version 6.15.1](https://github.com/groue/GRDB.swift/tree/v6.15.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+ • SQLite 3.19.3+ • Swift 5.7+ / Xcode 14+ diff --git a/Support/Info.plist b/Support/Info.plist index cfe37d1e2..f5b1cc90d 100644 --- a/Support/Info.plist +++ b/Support/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 6.15.0 + 6.15.1 CFBundleSignature ???? CFBundleVersion