From a64b09d12153d1ecd3830d41840b41be9fcdbbf6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gwendal=20Roue=CC=81?=
Date: Tue, 4 Feb 2025 19:06:27 +0100
Subject: [PATCH 1/6] Failing test for #1715
---
Tests/GRDBTests/DatabaseWriterTests.swift | 51 +++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/Tests/GRDBTests/DatabaseWriterTests.swift b/Tests/GRDBTests/DatabaseWriterTests.swift
index 34f8dc8f3..0fcc3b487 100644
--- a/Tests/GRDBTests/DatabaseWriterTests.swift
+++ b/Tests/GRDBTests/DatabaseWriterTests.swift
@@ -415,6 +415,57 @@ class DatabaseWriterTests : GRDBTestCase {
// MARK: - Task Cancellation
+ // Regression test for .
+ func test_write_is_possible_after_read_cancelled_after_database_access() async throws {
+ // When a read access is cancelled, DatabaseQueue needs to execute
+ // `PRAGMA query_only=0` in order to restore the read/write access.
+ //
+ // Here we test that this pragma can run from a cancelled read.
+ //
+ // Small difficulty: some SQLite versions (seen with 3.43.2) execute
+ // the `query_only` pragma at compile time, not only at execution
+ // time (yeah, that's an SQLite bug). The problem of this bug is
+ // that even if the `PRAGMA query_only=0` is not executed due to
+ // Task cancellation, its side effect is still executed when it is
+ // compiled, unintentionally. A cancelled `PRAGMA query_only=0`
+ // still works!
+ //
+ // To avoid this SQLite bug from messing with our test, we perform
+ // two reads: one that compiles and cache `PRAGMA query_only`
+ // statements, and a second read that we cancel. This time the
+ // `PRAGMA query_only=0` triggers its side effect if and only if it
+ // is actually executed (the behavior we are testing).
+ func test(_ dbWriter: some DatabaseWriter) async throws {
+ let semaphore = AsyncSemaphore(value: 0)
+ let cancelledTaskMutex = Mutex?>(nil)
+ let task = Task {
+ await semaphore.wait()
+
+ // First read, not cancelled, so that all `query_only`
+ // pragma statements are compiled (see above).
+ try await dbWriter.read { db in }
+
+ // Second read, cancelled.
+ try await dbWriter.read { db in
+ try XCTUnwrap(cancelledTaskMutex.load()).cancel()
+ }
+ }
+ cancelledTaskMutex.store(task)
+ semaphore.signal()
+ // Wait until reads are completed
+ try? await task.value
+
+ // Write access is restored after read cancellation (no error is thrown)
+ try await dbWriter.write { db in
+ try db.execute(sql: "CREATE TABLE test(a)")
+ }
+ }
+
+ try await test(makeDatabaseQueue())
+ try await test(makeDatabasePool())
+ try await test(AnyDatabaseWriter(makeDatabaseQueue()))
+ }
+
func test_writeWithoutTransaction_is_cancelled_by_Task_cancellation_performed_before_database_access() async throws {
func test(_ dbWriter: some DatabaseWriter) async throws {
let semaphore = AsyncSemaphore(value: 0)
From 5a4d9b5cb9a09940dbe6172e1c128a43bffd8d9f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gwendal=20Roue=CC=81?=
Date: Tue, 4 Feb 2025 19:31:28 +0100
Subject: [PATCH 2/6] Let PRAGMA QUERY_ONLY statements run from a cancelled
database access
Fix #1715
---
GRDB/Core/Database.swift | 6 ++++++
GRDB/Core/Statement.swift | 4 ++++
GRDB/Core/StatementAuthorizer.swift | 9 +++++++++
3 files changed, 19 insertions(+)
diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift
index 3d7419ce5..545a76255 100644
--- a/GRDB/Core/Database.swift
+++ b/GRDB/Core/Database.swift
@@ -1288,6 +1288,12 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
return
}
+ // Suspension should not prevent adjusting the read-only mode.
+ // See .
+ if statement.isQueryOnlyPragma {
+ return
+ }
+
// How should we interrupt the statement?
enum Interrupt {
case abort // Rollback and throw SQLITE_ABORT
diff --git a/GRDB/Core/Statement.swift b/GRDB/Core/Statement.swift
index f2792af31..be07f9eaf 100644
--- a/GRDB/Core/Statement.swift
+++ b/GRDB/Core/Statement.swift
@@ -92,6 +92,9 @@ public final class Statement {
/// The effects on the database (reported by `sqlite3_set_authorizer`).
private(set) var authorizerEventKinds: [DatabaseEventKind] = []
+ /// If true, the statement executes is a `PRAGMA QUERY_ONLY` statement.
+ private(set) var isQueryOnlyPragma = false
+
/// A boolean value indicating if the prepared statement makes no direct
/// changes to the content of the database file.
///
@@ -160,6 +163,7 @@ public final class Statement {
self.invalidatesDatabaseSchemaCache = authorizer.invalidatesDatabaseSchemaCache
self.transactionEffect = authorizer.transactionEffect
self.authorizerEventKinds = authorizer.databaseEventKinds
+ self.isQueryOnlyPragma = authorizer.isQueryOnlyPragma
}
deinit {
diff --git a/GRDB/Core/StatementAuthorizer.swift b/GRDB/Core/StatementAuthorizer.swift
index 169b5dc5f..fb27043a5 100644
--- a/GRDB/Core/StatementAuthorizer.swift
+++ b/GRDB/Core/StatementAuthorizer.swift
@@ -41,6 +41,9 @@ final class StatementAuthorizer {
/// savepoint statement.
var transactionEffect: Statement.TransactionEffect?
+ /// If true, the statement executes is a `PRAGMA QUERY_ONLY` statement.
+ var isQueryOnlyPragma = false
+
private var isDropStatement = false
init(_ database: Database) {
@@ -67,6 +70,7 @@ final class StatementAuthorizer {
databaseEventKinds = []
invalidatesDatabaseSchemaCache = false
transactionEffect = nil
+ isQueryOnlyPragma = false
isDropStatement = false
}
@@ -192,6 +196,11 @@ final class StatementAuthorizer {
}
return SQLITE_OK
+ case SQLITE_PRAGMA:
+ if let cString1 {
+ isQueryOnlyPragma = sqlite3_stricmp(cString1, "query_only") == 0
+ }
+ return SQLITE_OK
default:
return SQLITE_OK
}
From 78b2796f4601e4dd41a773d6b9099310e63166c0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gwendal=20Roue=CC=81?=
Date: Wed, 5 Feb 2025 08:00:29 +0100
Subject: [PATCH 3/6] CHANGELOG
---
CHANGELOG.md | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 789ba740b..4936ab22f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -132,6 +132,11 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
---
+## Next Release
+
+- **New**: Expose `sqlite3_libversion_number` as `Database.sqliteLibVersionNumber` by [@groue](https://github.com/groue) in [#1713](https://github.com/groue/GRDB.swift/pull/1713)
+- **Fixed**: DatabaseQueue restores its read/write abilities when an async read-only database access is cancelled by [@groue](https://github.com/groue) in [#1716](https://github.com/groue/GRDB.swift/pull/1716)
+
## 7.0.0
Released January 26, 2025
From ef36727d9ad4496747657faee00f6d96c45f269b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gwendal=20Rou=C3=A9?=
Date: Wed, 5 Feb 2025 13:38:19 +0100
Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=8E=B5=20Whatever=20Lola=20wants,=20L?=
=?UTF-8?q?ola=20gets?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Address https://github.com/RxSwiftCommunity/RxGRDB/issues/72
Based on https://github.com/swiftlang/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md#preconcurrency-attribute-on-nominal-declarations
See also https://www.massicotte.org/preconcurrency#working-with-swift-5
"Whatever Lola wants, Lola gets" because the Swift language is a blind and cruel mistress.
---
GRDB/Core/DatabaseRegionObservation.swift | 1 +
1 file changed, 1 insertion(+)
diff --git a/GRDB/Core/DatabaseRegionObservation.swift b/GRDB/Core/DatabaseRegionObservation.swift
index 8d9cd97b0..ec6319721 100644
--- a/GRDB/Core/DatabaseRegionObservation.swift
+++ b/GRDB/Core/DatabaseRegionObservation.swift
@@ -83,6 +83,7 @@ extension DatabaseRegionObservation {
/// - parameter onChange: The closure to execute when a transaction has
/// modified the observed region.
/// - returns: A DatabaseCancellable that can stop the observation.
+ @preconcurrency // For RxGRDB, see
public func start(
in writer: any DatabaseWriter,
onError: @escaping @Sendable (Error) -> Void,
From 430530f5f1bfe8f5b6bd2d1804ead68a784873d0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gwendal=20Rou=C3=A9?=
Date: Wed, 5 Feb 2025 14:08:28 +0100
Subject: [PATCH 5/6] CHANGELOG
---
CHANGELOG.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4936ab22f..9d3a62922 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -136,6 +136,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
- **New**: Expose `sqlite3_libversion_number` as `Database.sqliteLibVersionNumber` by [@groue](https://github.com/groue) in [#1713](https://github.com/groue/GRDB.swift/pull/1713)
- **Fixed**: DatabaseQueue restores its read/write abilities when an async read-only database access is cancelled by [@groue](https://github.com/groue) in [#1716](https://github.com/groue/GRDB.swift/pull/1716)
+- **New**: Allow RxGRDB to compile without warning by [@groue](https://github.com/groue) in [#1717](https://github.com/groue/GRDB.swift/pull/1717)
## 7.0.0
From 073209f1dcba9a603400c1c7dd1128e9122efde9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gwendal=20Rou=C3=A9?=
Date: Wed, 5 Feb 2025 15:34:09 +0100
Subject: [PATCH 6/6] v7.1.0
---
CHANGELOG.md | 5 ++++-
GRDB.swift.podspec | 2 +-
README.md | 2 +-
Support/Info.plist | 2 +-
4 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9d3a62922..cd7aadd63 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
#### 7.x Releases
+- `7.1.x` Releases - [7.1.0](#710)
- `7.0.x` Releases - [7.0.0](#700)
- `7.0.0` Betas - [7.0.0-beta](#700-beta) - [7.0.0-beta.2](#700-beta2) - [7.0.0-beta.3](#700-beta3) - [7.0.0-beta.4](#700-beta4) - [7.0.0-beta.5](#700-beta5) - [7.0.0-beta.6](#700-beta6) - [7.0.0-beta.7](#700-beta7)
@@ -132,7 +133,9 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
---
-## Next Release
+## 7.1.0
+
+Released February 5, 2025
- **New**: Expose `sqlite3_libversion_number` as `Database.sqliteLibVersionNumber` by [@groue](https://github.com/groue) in [#1713](https://github.com/groue/GRDB.swift/pull/1713)
- **Fixed**: DatabaseQueue restores its read/write abilities when an async read-only database access is cancelled by [@groue](https://github.com/groue) in [#1716](https://github.com/groue/GRDB.swift/pull/1716)
diff --git a/GRDB.swift.podspec b/GRDB.swift.podspec
index 61cb0ed7a..1685f257a 100644
--- a/GRDB.swift.podspec
+++ b/GRDB.swift.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'GRDB.swift'
- s.version = '7.0.0'
+ s.version = '7.1.0'
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 c9dc7c20b..fe43721f7 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@
-**Latest release**: January 26, 2025 • [version 7.0.0](https://github.com/groue/GRDB.swift/tree/v7.0.0) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 6 to GRDB 7](Documentation/GRDB7MigrationGuide.md)
+**Latest release**: February 5, 2025 • [version 7.1.0](https://github.com/groue/GRDB.swift/tree/v7.1.0) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 6 to GRDB 7](Documentation/GRDB7MigrationGuide.md)
**Requirements**: iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 7.0+ • SQLite 3.20.0+ • Swift 6+ / Xcode 16+
diff --git a/Support/Info.plist b/Support/Info.plist
index 9057c987a..4c6d2e8b6 100644
--- a/Support/Info.plist
+++ b/Support/Info.plist
@@ -15,7 +15,7 @@
CFBundlePackageType
FMWK
CFBundleShortVersionString
- 7.0.0
+ 7.1.0
CFBundleSignature
????
CFBundleVersion