From dd5ce280b56fd3ee7997de6abe414eac1d9b07b7 Mon Sep 17 00:00:00 2001 From: Martin Pfundmair Date: Fri, 29 Apr 2022 16:10:03 +0900 Subject: [PATCH 01/11] Fix apple docs links --- Documentation/FullTextSearch.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/FullTextSearch.md b/Documentation/FullTextSearch.md index 40e0fdad6..e6f19a36b 100644 --- a/Documentation/FullTextSearch.md +++ b/Documentation/FullTextSearch.md @@ -737,11 +737,11 @@ The SQLite built-in tokenizers for [FTS3, FTS4](#fts3-and-fts4-tokenizers) and [ Generally speaking, matches may fail when content and query don't use the same [unicode normalization](http://unicode.org/reports/tr15/). SQLite actually exhibits inconsistent behavior in this regard. -For example, for "aimé" to match "aimé", they better have the same normalization: the NFC "aim\u{00E9}" form may not match its NFD "aime\u{0301}" equivalent. Most strings that you get from Swift, UIKit and Cocoa use NFC, so be careful with NFD inputs (such as strings from the HFS+ file system, or strings that you can't trust like network inputs). Use [String.precomposedStringWithCanonicalMapping](https://developer.apple.com/reference/swift/string/1407210-precomposedstringwithcanonicalma) to turn a string into NFC. +For example, for "aimé" to match "aimé", they better have the same normalization: the NFC "aim\u{00E9}" form may not match its NFD "aime\u{0301}" equivalent. Most strings that you get from Swift, UIKit and Cocoa use NFC, so be careful with NFD inputs (such as strings from the HFS+ file system, or strings that you can't trust like network inputs). Use [String.precomposedStringWithCanonicalMapping](https://developer.apple.com/documentation/foundation/nsstring/1412645-precomposedstringwithcanonicalma) to turn a string into NFC. -Besides, if you want "fi" to match the ligature "fi" (U+FB01), then you need to normalize your indexed contents and inputs to NFKC or NFKD. Use [String.precomposedStringWithCompatibilityMapping](https://developer.apple.com/reference/swift/string/1407834-precomposedstringwithcompatibili) to turn a string into NFKC. +Besides, if you want "fi" to match the ligature "fi" (U+FB01), then you need to normalize your indexed contents and inputs to NFKC or NFKD. Use [String.precomposedStringWithCompatibilityMapping](https://developer.apple.com/documentation/foundation/nsstring/1412625-precomposedstringwithcompatibili) to turn a string into NFKC. -Unicode normalization is not the end of the story, because it won't help "Encyclopaedia" match "Encyclopædia", "Mueller", "Müller", "Grossmann", "Großmann", or "Diyarbakır", "DIYARBAKIR". The [String.applyingTransform](https://developer.apple.com/reference/swift/string/1643133-applyingtransform) method can help. +Unicode normalization is not the end of the story, because it won't help "Encyclopaedia" match "Encyclopædia", "Mueller", "Müller", "Grossmann", "Großmann", or "Diyarbakır", "DIYARBAKIR". The [String.applyingTransform](https://developer.apple.com/documentation/foundation/nsstring/1407787-applyingtransform) method can help. GRDB lets you write [custom FTS5 tokenizers](FTS5Tokenizers.md) that can transparently deal with all these issues. For FTS3 and FTS4, you'll need to pre-process your strings before injecting them in the full-text engine. From 1b3f1ed39349ec1abbebb8141dab5266f3070a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 30 Apr 2022 13:26:25 +0200 Subject: [PATCH 02/11] Fix typo --- Tests/GRDBTests/ValueObservationTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/GRDBTests/ValueObservationTests.swift b/Tests/GRDBTests/ValueObservationTests.swift index 0f6566e6b..2d412987f 100644 --- a/Tests/GRDBTests/ValueObservationTests.swift +++ b/Tests/GRDBTests/ValueObservationTests.swift @@ -649,7 +649,7 @@ class ValueObservationTests: GRDBTestCase { try test(makeDatabasePool()) } - func tesCancellableInvalidation2() throws { + func testCancellableInvalidation2() throws { // Test that observation stops when cancellable is deallocated func test(_ dbWriter: DatabaseWriter) throws { try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } From 819ee588c98723520df0cacfcd654275d118f92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 30 Apr 2022 13:31:31 +0200 Subject: [PATCH 03/11] Failing test for #1209 --- Tests/GRDBTests/ValueObservationTests.swift | 49 +++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/Tests/GRDBTests/ValueObservationTests.swift b/Tests/GRDBTests/ValueObservationTests.swift index 2d412987f..8481af673 100644 --- a/Tests/GRDBTests/ValueObservationTests.swift +++ b/Tests/GRDBTests/ValueObservationTests.swift @@ -694,6 +694,55 @@ class ValueObservationTests: GRDBTestCase { try test(makeDatabasePool()) } + func testIssue1209() throws { + func test(_ dbWriter: Writer) throws { + try dbWriter.write { + try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") + } + + // We'll start N observations + let N = 100 + + // We'll wait for initial value notification before modifying the database + let initialValueExpectation = expectation(description: "") + initialValueExpectation.expectedFulfillmentCount = N + + // The test will pass if we get change notifications + let changeExpectation = expectation(description: "") + changeExpectation.expectedFulfillmentCount = N + + // Observe N times + let cancellables = (0..=5.6) && canImport(_Concurrency) // MARK: - Async Await From 06b536705386e95228d36ba1a0063cafc6d219af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 30 Apr 2022 14:01:51 +0200 Subject: [PATCH 04/11] Default transaction kind is `.deferred` in read-only connections This applies to both connections open in read-only mode, and pragma query_only. --- GRDB/Core/Database.swift | 40 +++++++++++++++++++++-------- Tests/GRDBTests/DatabaseTests.swift | 30 ++++++++++++++++++++++ 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index 32ec98efb..9f5256d56 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -546,6 +546,11 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib finally: endReadOnly) } + /// Returns whether database connection is read-only. + var isReadOnly: Bool { + _readOnlyDepth > 0 || configuration.readonly + } + // MARK: - Snapshots #if SQLITE_ENABLE_SNAPSHOT @@ -939,10 +944,16 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib /// This method is not reentrant: you can't nest transactions. /// /// - parameters: - /// - kind: The transaction type (default nil). If nil, the transaction - /// type is configuration.defaultTransactionKind, which itself - /// defaults to .deferred. See - /// for more information. + /// - kind: The transaction type (default nil). + /// + /// If nil, and the database connection is read-only, the transaction + /// kind is `.deferred`. + /// + /// If nil, and the database connection is not read-only, the + /// transaction kind is `configuration.defaultTransactionKind`. + /// + /// See for + /// more information. /// - block: A block that executes SQL statements and return either /// .commit or .rollback. /// - throws: The error thrown by the block. @@ -1055,7 +1066,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib // // For those two reasons, we open a transaction instead of a // top-level savepoint. - try inTransaction(configuration.defaultTransactionKind, block) + try inTransaction { try block() } return } @@ -1123,13 +1134,20 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib /// Begins a database transaction. /// - /// - parameter kind: The transaction type (default nil). If nil, the - /// transaction type is configuration.defaultTransactionKind, which itself - /// defaults to .deferred. See - /// for more information. - /// - throws: The error thrown by the block. + /// - parameter kind: The transaction type (default nil). + /// + /// If nil, and the database connection is read-only, the transaction kind + /// is `.deferred`. + /// + /// If nil, and the database connection is not read-only, the transaction + /// kind is `configuration.defaultTransactionKind`. + /// + /// See for + /// more information. + /// - throws: A DatabaseError whenever an SQLite error occurs. public func beginTransaction(_ kind: TransactionKind? = nil) throws { - let kind = kind ?? configuration.defaultTransactionKind + // SQLite throws an error for non-deferred transactions when read-only. + let kind = kind ?? (isReadOnly ? .deferred : configuration.defaultTransactionKind) try execute(sql: "BEGIN \(kind.rawValue) TRANSACTION") assert(sqlite3_get_autocommit(sqliteConnection) == 0) } diff --git a/Tests/GRDBTests/DatabaseTests.swift b/Tests/GRDBTests/DatabaseTests.swift index 4ed00d41e..51335b2c0 100644 --- a/Tests/GRDBTests/DatabaseTests.swift +++ b/Tests/GRDBTests/DatabaseTests.swift @@ -566,6 +566,36 @@ class DatabaseTests : GRDBTestCase { } } + func testReadOnlyTransaction() throws { + // query_only pragma was added in SQLite 3.8.0 http://www.sqlite.org/changes.html#version_3_8_0 + guard sqlite3_libversion_number() >= 3008000 else { + return + } + + dbConfiguration.defaultTransactionKind = .immediate + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + do { + sqlQueries.removeAll() + try db.inSavepoint { .commit } + try db.inTransaction { .commit } + try db.inTransaction(.immediate) { .commit } + XCTAssertEqual(Set(sqlQueries), ["BEGIN IMMEDIATE TRANSACTION", "COMMIT TRANSACTION"]) + } + + try db.readOnly { + sqlQueries.removeAll() + try db.inSavepoint { .commit } + try db.inTransaction { .commit } + XCTAssertEqual(Set(sqlQueries), ["BEGIN DEFERRED TRANSACTION", "COMMIT TRANSACTION"]) + do { + try db.inTransaction(.immediate) { .commit } + XCTFail("Expected error") + } catch DatabaseError.SQLITE_READONLY { } + } + } + } + func testCheckpoint() throws { do { // Not a WAL database From 5082207bb0413b08947e65da3901a7441f4fb7b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 30 Apr 2022 14:06:17 +0200 Subject: [PATCH 05/11] Don't notify read-only transactions --- GRDB/Core/Database.swift | 4 +++- GRDB/Core/TransactionObserver.swift | 28 +++++++++++++++++++--------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index 9f5256d56..dd3764895 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -233,7 +233,9 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib setupDefaultFunctions() setupDefaultCollations() setupAuthorizer() - observationBroker.installCommitAndRollbackHooks() + if !configuration.readonly { + observationBroker.installCommitAndRollbackHooks() + } try activateExtendedCodes() #if SQLITE_HAS_CODEC diff --git a/GRDB/Core/TransactionObserver.swift b/GRDB/Core/TransactionObserver.swift index c9a0a0982..ffdd7cf02 100644 --- a/GRDB/Core/TransactionObserver.swift +++ b/GRDB/Core/TransactionObserver.swift @@ -220,8 +220,7 @@ class DatabaseObservationBroker { /// Prepares observation of changes that are about to be performed by the statement. func statementWillExecute(_ statement: Statement) { - // If any observer observes row deletions, we'll have to disable - if transactionObservations.isEmpty == false { + if !database.isReadOnly && !transactionObservations.isEmpty { // As statement executes, it may trigger database changes that will // be notified to transaction observers. As a consequence, observers // may disable themselves with stopObservingDatabaseChangesUntilNextTransaction() @@ -310,7 +309,7 @@ class DatabaseObservationBroker { // SQLITE_CONSTRAINT error) databaseDidRollback(notifyTransactionObservers: false) case .cancelledCommit(let error): - databaseDidRollback(notifyTransactionObservers: true) + databaseDidRollback(notifyTransactionObservers: !database.isReadOnly) throw error default: break @@ -382,7 +381,7 @@ class DatabaseObservationBroker { case .commit: databaseDidCommit() case .rollback: - databaseDidRollback(notifyTransactionObservers: true) + databaseDidRollback(notifyTransactionObservers: !database.isReadOnly) default: break } @@ -391,6 +390,8 @@ class DatabaseObservationBroker { #if SQLITE_ENABLE_PREUPDATE_HOOK // Called from sqlite3_preupdate_hook private func databaseWillChange(with event: DatabasePreUpdateEvent) { + assert(!database.isReadOnly, "Read-only transactions are not notified") + if savepointStack.isEmpty { // Notify now for (observation, predicate) in statementObservations where predicate.evaluate(event) { @@ -405,6 +406,8 @@ class DatabaseObservationBroker { // Called from sqlite3_update_hook private func databaseDidChange(with event: DatabaseEvent) { + assert(!database.isReadOnly, "Read-only transactions are not notified") + // We're about to call the databaseDidChange(with:) method of // transaction observers. In this method, observers may disable // themselves with stopObservingDatabaseChangesUntilNextTransaction() @@ -430,8 +433,10 @@ class DatabaseObservationBroker { // Called from sqlite3_commit_hook and databaseDidCommitEmptyDeferredTransaction() private func databaseWillCommit() throws { notifyBufferedEvents() - for observation in transactionObservations { - try observation.databaseWillCommit() + if !database.isReadOnly { + for observation in transactionObservations { + try observation.databaseWillCommit() + } } } @@ -439,9 +444,12 @@ class DatabaseObservationBroker { private func databaseDidCommit() { savepointStack.clear() - for observation in transactionObservations { - observation.databaseDidCommit(database) + if !database.isReadOnly { + for observation in transactionObservations { + observation.databaseDidCommit(database) + } } + databaseDidEndTransaction() } @@ -485,7 +493,7 @@ class DatabaseObservationBroker { try databaseWillCommit() databaseDidCommit() } catch { - databaseDidRollback(notifyTransactionObservers: true) + databaseDidRollback(notifyTransactionObservers: !database.isReadOnly) throw error } } @@ -495,6 +503,7 @@ class DatabaseObservationBroker { savepointStack.clear() if notifyTransactionObservers { + assert(!database.isReadOnly, "Read-only transactions are not notified") for observation in transactionObservations { observation.databaseDidRollback(database) } @@ -566,6 +575,7 @@ class DatabaseObservationBroker { savepointStack.clear() for (event, statementObservations) in eventsBuffer { + assert(statementObservations.isEmpty || !database.isReadOnly, "Read-only transactions are not notified") for (observation, predicate) in statementObservations where predicate.evaluate(event) { event.send(to: observation) } From fb18a3938fd4c43c18f440856f100ce44e06e05c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 30 Apr 2022 14:14:09 +0200 Subject: [PATCH 06/11] Database.isolated(readOnly: true) avoids triggering database observation Fix failing test for #1209 --- GRDB/Core/Database.swift | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index dd3764895..0b40f9955 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -1018,13 +1018,20 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib /// - parameter readOnly: If true, writes are forbidden. func isolated(readOnly: Bool = false, _ block: () throws -> T) throws -> T { var result: T? - try inSavepoint { - if readOnly { - result = try self.readOnly(block) - } else { - result = try block() + if readOnly { + // Enter read-only mode before starting a transaction, so that the + // transaction commit does not trigger database observation. + try self.readOnly { + try inSavepoint { + result = try block() + return .commit + } + } + } else { + try inSavepoint { + result = try block() + return .commit } - return .commit } return result! } From c5eba4741d8a0929a5d8e498c8af8b8b46ce78b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 30 Apr 2022 15:42:57 +0200 Subject: [PATCH 07/11] Test that read-only transactions are not notified --- .../GRDBTests/TransactionObserverTests.swift | 87 ++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/Tests/GRDBTests/TransactionObserverTests.swift b/Tests/GRDBTests/TransactionObserverTests.swift index f7c5ae16b..2c38fa4b8 100644 --- a/Tests/GRDBTests/TransactionObserverTests.swift +++ b/Tests/GRDBTests/TransactionObserverTests.swift @@ -1,5 +1,5 @@ import XCTest -import GRDB +@testable import GRDB private class Observer : TransactionObserver { var lastCommittedEvents: [DatabaseEvent] = [] @@ -1784,4 +1784,89 @@ class TransactionObserverTests: GRDBTestCase { } } } + + // MARK: - Read-Only Connection + + func testReadOnlyConnection() throws { + let dbQueue = try makeDatabaseQueue(filename: "database.sqlite") + try setupArtistDatabase(in: dbQueue) + + dbConfiguration.readonly = true + let readOnlyQueue = try makeDatabaseQueue(filename: "database.sqlite") + + let observer = Observer() + readOnlyQueue.add(transactionObserver: observer, extent: .databaseLifetime) + + try readOnlyQueue.inDatabase { db in + do { + try db.execute(sql: """ + BEGIN; + COMMIT; + """) + XCTAssertEqual(observer.didChangeCount, 0) + XCTAssertEqual(observer.willCommitCount, 0) + XCTAssertEqual(observer.didCommitCount, 0) + XCTAssertEqual(observer.didRollbackCount, 0) + #if SQLITE_ENABLE_PREUPDATE_HOOK + XCTAssertEqual(observer.willChangeCount, 0) + #endif + } + + do { + try db.execute(sql: """ + BEGIN; + SELECT * FROM artists; + COMMIT; + """) + XCTAssertEqual(observer.didChangeCount, 0) + XCTAssertEqual(observer.willCommitCount, 0) + XCTAssertEqual(observer.didCommitCount, 0) + XCTAssertEqual(observer.didRollbackCount, 0) + #if SQLITE_ENABLE_PREUPDATE_HOOK + XCTAssertEqual(observer.willChangeCount, 0) + #endif + } + } + } + + func testReadOnlyBlock() throws { + let dbQueue = try makeDatabaseQueue() + try setupArtistDatabase(in: dbQueue) + + let observer = Observer() + dbQueue.add(transactionObserver: observer, extent: .databaseLifetime) + + try dbQueue.inDatabase { db in + try db.readOnly { + do { + try db.execute(sql: """ + BEGIN; + COMMIT; + """) + XCTAssertEqual(observer.didChangeCount, 0) + XCTAssertEqual(observer.willCommitCount, 0) + XCTAssertEqual(observer.didCommitCount, 0) + XCTAssertEqual(observer.didRollbackCount, 0) + #if SQLITE_ENABLE_PREUPDATE_HOOK + XCTAssertEqual(observer.willChangeCount, 0) + #endif + } + + do { + try db.execute(sql: """ + BEGIN; + SELECT * FROM artists; + COMMIT; + """) + XCTAssertEqual(observer.didChangeCount, 0) + XCTAssertEqual(observer.willCommitCount, 0) + XCTAssertEqual(observer.didCommitCount, 0) + XCTAssertEqual(observer.didRollbackCount, 0) + #if SQLITE_ENABLE_PREUPDATE_HOOK + XCTAssertEqual(observer.willChangeCount, 0) + #endif + } + } + } + } } From b89ce00361cc0125aa60155e94797c9ec9de4452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 30 Apr 2022 15:46:45 +0200 Subject: [PATCH 08/11] Document that read-only transactions are not notified --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ef128fc1..9f8d0bef4 100644 --- a/README.md +++ b/README.md @@ -6683,6 +6683,8 @@ By default, database holds weak references to its transaction observers: they ar **A transaction observer is notified of all database changes**: inserts, updates and deletes. This includes indirect changes triggered by ON DELETE and ON UPDATE actions associated to [foreign keys](https://www.sqlite.org/foreignkeys.html#fk_actions), and [SQL triggers](https://www.sqlite.org/lang_createtrigger.html). > :point_up: **Note**: Some changes are not notified: changes to internal system tables (such as `sqlite_master`), changes to [`WITHOUT ROWID`](https://www.sqlite.org/withoutrowid.html) tables, and the deletion of duplicate rows triggered by [`ON CONFLICT REPLACE`](https://www.sqlite.org/lang_conflict.html) clauses (this last exception might change in a future release of SQLite). +> +> :point_up: **Note**: Transactions performed during read-only database accesses are not notified. Notified changes are not actually written to disk until the [transaction](#transactions-and-savepoints) commits, and the `databaseDidCommit` callback is called. On the other side, `databaseDidRollback` confirms their invalidation: @@ -6794,7 +6796,7 @@ class PlayerScoreObserver: TransactionObserver { } ``` -When the `observes(eventsOfKind:)` method returns false for all event kinds, the observer is still notified of commits and rollbacks: +When the `observes(eventsOfKind:)` method returns false for all event kinds, the observer is still notified of commits and rollbacks (except during read-only database accesses): ```swift class PureTransactionObserver: TransactionObserver { From f17a78616529aeb5099790590e237f7a2dc8c2dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 30 Apr 2022 15:57:20 +0200 Subject: [PATCH 09/11] CHANGELOG --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2d9dea0a..836948a4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,6 +90,11 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: --- +## Next Release + +- **Fixed**: [#1213](https://github.com/groue/GRDB.swift/pull/1213) by [@groue](https://github.com/groue): Fix crash when the number of active ValueObservations is high +- **Breaking Change**: Transactions performed during a read-only database access are no longer notified to transaction observers. This is, strictly speaking, a breaking change. However it should have no impact since read-only transactions have very little interest. + ## 5.23.0 Released April 16, 2022 • [diff](https://github.com/groue/GRDB.swift/compare/v5.22.2...v5.23.0) From 3632edb238a42fad8d2fd86517bad8f4c8c4fe3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 1 May 2022 11:34:18 +0200 Subject: [PATCH 10/11] Mention SwiftUI support in the README --- README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9f8d0bef4..fc83c7e88 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ See [Why Adopt GRDB?](Documentation/WhyAdoptGRDB.md) if you are looking for your ## Features -GRDB ships with: +Programming tools for both database beginners and SQLite experts: - [Access to raw SQL and SQLite](#sqlite-api) - [Records](#records): Fetching and persistence methods for your custom structs and class hierarchies. @@ -72,18 +72,21 @@ GRDB ships with: - [WAL Mode Support](#database-pools): Extra performance for multi-threaded applications. - [Migrations]: Transform your database as your application evolves. - [Database Observation]: Observe database changes and transactions. -- [Swift Concurrency]: `try await` your database (Xcode 13.3.1+). -- [Combine Support]: Access and observe the database with Combine publishers. -- [RxSwift Support](http://github.com/RxSwiftCommunity/RxGRDB): Access and observe the database with RxSwift observables. - [Full-Text Search] - [Encryption](#encryption) - [Support for Custom SQLite Builds](Documentation/CustomSQLiteBuilds.md) +In-depth integration with our programming environment: + +- [Swift Concurrency]: `try await` your database (Xcode 13.3.1+). +- [SwiftUI](http://github.com/groue/GRDBQuery): Access and observe the database from your SwiftUI views. +- [Combine](Documentation/Combine.md): Access and observe the database with Combine publishers. +- [RxSwift](http://github.com/RxSwiftCommunity/RxGRDB): Access and observe the database with RxSwift observables. ## Usage
- Start using the database in four easy steps + Start using the database in four steps ```swift import GRDB From 5b254eec16f8c6d4442f3ad7e1c907f66ebebfb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 1 May 2022 11:43:14 +0200 Subject: [PATCH 11/11] v5.24.0 --- CHANGELOG.md | 7 +++++- Documentation/FullTextSearch.md | 4 ++-- Documentation/Migrations.md | 2 +- GRDB.swift.podspec | 2 +- Makefile | 6 ++--- README.md | 40 ++++++++++++++++----------------- Support/Info.plist | 2 +- 7 files changed, 34 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 836948a4f..4cf1ca54e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: #### 5.x Releases +- `5.24.x` Releases - [5.24.0](#5240) - `5.23.x` Releases - [5.23.0](#5230) - `5.22.x` Releases - [5.22.0](#5220) | [5.22.1](#5221) | [5.22.2](#5222) - `5.21.x` Releases - [5.21.0](#5210) @@ -90,8 +91,12 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: --- -## Next Release +## 5.24.0 +Released May 1, 2022 • [diff](https://github.com/groue/GRDB.swift/compare/v5.23.0...v5.24.0) + +- **Fixed**: [#1203](https://github.com/groue/GRDB.swift/pull/1203) by [@EvanHahn](https://github.com/EvanHahn): Fix changelog links +- **Fixed**: [#1212](https://github.com/groue/GRDB.swift/pull/1212) by [@MartinP7r](https://github.com/MartinP7r): Fix apple docs links - **Fixed**: [#1213](https://github.com/groue/GRDB.swift/pull/1213) by [@groue](https://github.com/groue): Fix crash when the number of active ValueObservations is high - **Breaking Change**: Transactions performed during a read-only database access are no longer notified to transaction observers. This is, strictly speaking, a breaking change. However it should have no impact since read-only transactions have very little interest. diff --git a/Documentation/FullTextSearch.md b/Documentation/FullTextSearch.md index e6f19a36b..061a39433 100644 --- a/Documentation/FullTextSearch.md +++ b/Documentation/FullTextSearch.md @@ -304,7 +304,7 @@ let pattern = FTS3Pattern(matchingAnyTokenIn: "") // nil let pattern = FTS3Pattern(matchingAnyTokenIn: "*") // nil ``` -FTS3Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/5.23/Structs/StatementArguments.html): +FTS3Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/5.24/Structs/StatementArguments.html): ```swift let documents = try Document.fetchAll(db, @@ -587,7 +587,7 @@ let pattern = FTS5Pattern(matchingAnyTokenIn: "") // nil let pattern = FTS5Pattern(matchingAnyTokenIn: "*") // nil ``` -FTS5Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/5.23/Structs/StatementArguments.html): +FTS5Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/5.24/Structs/StatementArguments.html): ```swift let documents = try Document.fetchAll(db, diff --git a/Documentation/Migrations.md b/Documentation/Migrations.md index 7f03ce470..861035a10 100644 --- a/Documentation/Migrations.md +++ b/Documentation/Migrations.md @@ -77,7 +77,7 @@ try dbQueue.read { db in } ``` -See the [DatabaseMigrator reference](http://groue.github.io/GRDB.swift/docs/5.23/Structs/DatabaseMigrator.html) for more migrator methods. +See the [DatabaseMigrator reference](http://groue.github.io/GRDB.swift/docs/5.24/Structs/DatabaseMigrator.html) for more migrator methods. ## The `eraseDatabaseOnSchemaChange` Option diff --git a/GRDB.swift.podspec b/GRDB.swift.podspec index 03f54ea5d..a6f07e5f8 100644 --- a/GRDB.swift.podspec +++ b/GRDB.swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GRDB.swift' - s.version = '5.23.0' + s.version = '5.24.0' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'A toolkit for SQLite databases, with a focus on application development.' diff --git a/Makefile b/Makefile index e67ebf38d..a583d2ad0 100644 --- a/Makefile +++ b/Makefile @@ -538,10 +538,10 @@ ifdef JAZZY --author 'Gwendal Roué' \ --author_url https://github.com/groue \ --github_url https://github.com/groue/GRDB.swift \ - --github-file-prefix https://github.com/groue/GRDB.swift/tree/v5.23.0 \ - --module-version 5.23.0 \ + --github-file-prefix https://github.com/groue/GRDB.swift/tree/v5.24.0 \ + --module-version 5.24.0 \ --module GRDB \ - --root-url http://groue.github.io/GRDB.swift/docs/5.23/ \ + --root-url http://groue.github.io/GRDB.swift/docs/5.24/ \ --output Documentation/Reference \ --xcodebuild-arguments -project,GRDB.xcodeproj,-scheme,GRDBiOS else diff --git a/README.md b/README.md index fc83c7e88..7f7829973 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,13 @@ --- -**Latest release**: April 16, 2022 • [version 5.23.0](https://github.com/groue/GRDB.swift/tree/v5.23.0) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 4 to GRDB 5](Documentation/GRDB5MigrationGuide.md) +**Latest release**: May 1, 2022 • [version 5.24.0](https://github.com/groue/GRDB.swift/tree/v5.24.0) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 4 to GRDB 5](Documentation/GRDB5MigrationGuide.md) **Requirements**: iOS 11.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+ • SQLite 3.8.5+ • Swift 5.3+ / Xcode 12+ | Swift version | GRDB version | | -------------- | ----------------------------------------------------------- | -| **Swift 5.3+** | **v5.23.0** | +| **Swift 5.3+** | **v5.24.0** | | Swift 5.2 | [v5.12.0](https://github.com/groue/GRDB.swift/tree/v5.12.0) | | Swift 5.1 | [v4.14.0](https://github.com/groue/GRDB.swift/tree/v4.14.0) | | Swift 5 | [v4.14.0](https://github.com/groue/GRDB.swift/tree/v4.14.0) | @@ -321,7 +321,7 @@ Documentation #### Reference -- [GRDB Reference](http://groue.github.io/GRDB.swift/docs/5.23/index.html) (generated by [Jazzy](https://github.com/realm/jazzy)) +- [GRDB Reference](http://groue.github.io/GRDB.swift/docs/5.24/index.html) (generated by [Jazzy](https://github.com/realm/jazzy)) #### Getting Started @@ -613,7 +613,7 @@ do { > > :warning: **Warning**: The SQLite version that ships with old operating systems (prior to OSX 10.12, tvOS 10.0, and watchOS 3.0) outputs statement arguments in the [trace events](#how-do-i-print-a-request-as-sql), regardless of the `publicStatementArguments` flag. -See [Configuration](http://groue.github.io/GRDB.swift/docs/5.23/Structs/Configuration.html) for more details and configuration options. +See [Configuration](http://groue.github.io/GRDB.swift/docs/5.24/Structs/Configuration.html) for more details and configuration options. SQLite API @@ -670,7 +670,7 @@ try dbQueue.write { db in } ``` -The `?` and colon-prefixed keys like `:score` in the SQL query are the **statements arguments**. You pass arguments with arrays or dictionaries, as in the example above. See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.23/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. +The `?` and colon-prefixed keys like `:score` in the SQL query are the **statements arguments**. You pass arguments with arrays or dictionaries, as in the example above. See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.24/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. You can also embed query arguments right into your SQL queries, with the `literal` argument label, as in the example below. See [SQL Interpolation] for more details. @@ -928,7 +928,7 @@ try dbQueue.read { db in let dictionary = try Dictionary(uniqueKeysWithValues: cursor) ``` -- **Cursors adopt the [Cursor](http://groue.github.io/GRDB.swift/docs/5.23/Protocols/Cursor.html) protocol, which looks a lot like standard [lazy sequences](https://developer.apple.com/reference/swift/lazysequenceprotocol) of Swift.** As such, cursors come with many convenience methods: `compactMap`, `contains`, `dropFirst`, `dropLast`, `drop(while:)`, `enumerated`, `filter`, `first`, `flatMap`, `forEach`, `joined`, `joined(separator:)`, `max`, `max(by:)`, `min`, `min(by:)`, `map`, `prefix`, `prefix(while:)`, `reduce`, `reduce(into:)`, `suffix`: +- **Cursors adopt the [Cursor](http://groue.github.io/GRDB.swift/docs/5.24/Protocols/Cursor.html) protocol, which looks a lot like standard [lazy sequences](https://developer.apple.com/reference/swift/lazysequenceprotocol) of Swift.** As such, cursors come with many convenience methods: `compactMap`, `contains`, `dropFirst`, `dropLast`, `drop(while:)`, `enumerated`, `filter`, `first`, `flatMap`, `forEach`, `joined`, `joined(separator:)`, `max`, `max(by:)`, `min`, `min(by:)`, `map`, `prefix`, `prefix(while:)`, `reduce`, `reduce(into:)`, `suffix`: ```swift // Prints all Github links @@ -1007,7 +1007,7 @@ let rows = try Row.fetchAll(db, arguments: ["name": "Arthur"]) ``` -See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.23/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. +See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.24/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. Unlike row arrays that contain copies of the database rows, row cursors are close to the SQLite metal, and require a little care: @@ -1292,7 +1292,7 @@ GRDB ships with built-in support for the following value types: - Generally speaking, all types that adopt the [DatabaseValueConvertible](#custom-value-types) protocol. -Values can be used as [statement arguments](http://groue.github.io/GRDB.swift/docs/5.23/Structs/StatementArguments.html): +Values can be used as [statement arguments](http://groue.github.io/GRDB.swift/docs/5.24/Structs/StatementArguments.html): ```swift let url: URL = ... @@ -1763,7 +1763,7 @@ try dbQueue.inDatabase { db in // or dbPool.writeWithoutTransaction } ``` -Transactions can't be left opened unless you set the [allowsUnsafeTransactions](http://groue.github.io/GRDB.swift/docs/5.23/Structs/Configuration.html) configuration flag: +Transactions can't be left opened unless you set the [allowsUnsafeTransactions](http://groue.github.io/GRDB.swift/docs/5.24/Structs/Configuration.html) configuration flag: ```swift // fatal error: A transaction has been left opened at the end of a database access @@ -1875,7 +1875,7 @@ try dbQueue.write { db in } ``` -The `?` and colon-prefixed keys like `:name` in the SQL query are the statement arguments. You set them with arrays or dictionaries (arguments are actually of type [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.23/Structs/StatementArguments.html), which happens to adopt the ExpressibleByArrayLiteral and ExpressibleByDictionaryLiteral protocols). +The `?` and colon-prefixed keys like `:name` in the SQL query are the statement arguments. You set them with arrays or dictionaries (arguments are actually of type [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.24/Structs/StatementArguments.html), which happens to adopt the ExpressibleByArrayLiteral and ExpressibleByDictionaryLiteral protocols). ```swift insertStatement.arguments = ["name": "Arthur", "score": 1000] @@ -1958,7 +1958,7 @@ See also `Database.execute(sql:)` in the [Executing Updates](#executing-updates) > :point_up: **Note**: it is a programmer error to reuse a prepared statement that has failed: GRDB may crash if you do so. -For more information about prepared statements, see the [Statement reference](http://groue.github.io/GRDB.swift/docs/5.23/Classes/Statement.html). +For more information about prepared statements, see the [Statement reference](http://groue.github.io/GRDB.swift/docs/5.24/Classes/Statement.html). ### Prepared Statements Cache @@ -2701,7 +2701,7 @@ try Place.fetchSet(db, sql: "SELECT ...", arguments:...) // Set try Place.fetchOne(db, sql: "SELECT ...", arguments:...) // Place? ``` -See [fetching methods](#fetching-methods) for information about the `fetchCursor`, `fetchAll`, `fetchSet` and `fetchOne` methods. See [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.23/Structs/StatementArguments.html) for more information about the query arguments. +See [fetching methods](#fetching-methods) for information about the `fetchCursor`, `fetchAll`, `fetchSet` and `fetchOne` methods. See [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.24/Structs/StatementArguments.html) for more information about the query arguments. > :point_up: **Note**: for performance reasons, the same row argument to `init(row:)` is reused during the iteration of a fetch query. If you want to keep the row for later use, make sure to store a copy: `self.row = row.copy()`. @@ -3141,7 +3141,7 @@ protocol EncodableRecord { } ``` -See [DatabaseColumnDecodingStrategy](https://groue.github.io/GRDB.swift/docs/5.23/Enums/DatabaseColumnDecodingStrategy.html) and [DatabaseColumnEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.23/Enums/DatabaseColumnEncodingStrategy.html) to learn about all available strategies. +See [DatabaseColumnDecodingStrategy](https://groue.github.io/GRDB.swift/docs/5.24/Enums/DatabaseColumnDecodingStrategy.html) and [DatabaseColumnEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.24/Enums/DatabaseColumnEncodingStrategy.html) to learn about all available strategies. ### Date and UUID Coding Strategies @@ -3163,7 +3163,7 @@ protocol EncodableRecord { } ``` -See [DatabaseDateDecodingStrategy](https://groue.github.io/GRDB.swift/docs/5.23/Enums/DatabaseDateDecodingStrategy.html), [DatabaseDateEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.23/Enums/DatabaseDateEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.23/Enums/DatabaseUUIDEncodingStrategy.html) to learn about all available strategies. +See [DatabaseDateDecodingStrategy](https://groue.github.io/GRDB.swift/docs/5.24/Enums/DatabaseDateDecodingStrategy.html), [DatabaseDateEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.24/Enums/DatabaseDateEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.24/Enums/DatabaseUUIDEncodingStrategy.html) to learn about all available strategies. There is no customization of uuid decoding, because UUID can already decode all its encoded variants (16-bytes blobs and uuid strings, both uppercase and lowercase). @@ -4688,7 +4688,7 @@ Player // SELECT * FROM player ``` -Raw SQL snippets are also accepted, with eventual [arguments](http://groue.github.io/GRDB.swift/docs/5.23/Structs/StatementArguments.html): +Raw SQL snippets are also accepted, with eventual [arguments](http://groue.github.io/GRDB.swift/docs/5.24/Structs/StatementArguments.html): ```swift // SELECT DATE(creationDate), COUNT(*) FROM player WHERE name = 'Arthur' GROUP BY date(creationDate) @@ -5594,7 +5594,7 @@ try Player.customRequest().fetchAll(db) // [Player] - The `adapted(_:)` method eases the consumption of complex rows with [row adapters](#row-adapters). See [Joined Queries Support](#joined-queries-support) for some sample code that uses this method. -- [AnyFetchRequest](http://groue.github.io/GRDB.swift/docs/5.23/Structs/AnyFetchRequest.html): a type-erased request. +- [AnyFetchRequest](http://groue.github.io/GRDB.swift/docs/5.24/Structs/AnyFetchRequest.html): a type-erased request. ## Joined Queries Support @@ -6896,7 +6896,7 @@ DatabaseRegion helps [ValueObservation] and [DatabaseRegionObservation] track ch For example, if you observe the region of `Player.select(max(Column("score")))`, then you'll get be notified of all changes performed on the `score` column of the `player` table (updates, insertions and deletions), even if they do not modify the value of the maximum score. However, you will not get any notification for changes performed on other database tables, or updates to other columns of the player table. -For more details, see the [reference](https://groue.github.io/GRDB.swift/docs/5.23/Structs/DatabaseRegion.html). +For more details, see the [reference](https://groue.github.io/GRDB.swift/docs/5.24/Structs/DatabaseRegion.html). #### The DatabaseRegionConvertible Protocol @@ -8236,7 +8236,7 @@ When this is the case, there are two possible explanations: try db.execute(sql: "UPDATE player SET name = ?", arguments: [name]) ``` -For more information, see [Double-quoted String Literals Are Accepted](https://sqlite.org/quirks.html#dblquote), and [Configuration.acceptsDoubleQuotedStringLiterals](http://groue.github.io/GRDB.swift/docs/5.23/Structs/Configuration.html#/s:4GRDB13ConfigurationV33acceptsDoubleQuotedStringLiteralsSbvp). +For more information, see [Double-quoted String Literals Are Accepted](https://sqlite.org/quirks.html#dblquote), and [Configuration.acceptsDoubleQuotedStringLiterals](http://groue.github.io/GRDB.swift/docs/5.24/Structs/Configuration.html#/s:4GRDB13ConfigurationV33acceptsDoubleQuotedStringLiteralsSbvp). @@ -8377,7 +8377,7 @@ This chapter has [moved](Documentation/Concurrency.md#database-snapshots). #### DatabaseWriter and DatabaseReader Protocols -This chapter was removed. See the references of [DatabaseReader](http://groue.github.io/GRDB.swift/docs/5.23/Protocols/DatabaseReader.html) and [DatabaseWriter](http://groue.github.io/GRDB.swift/docs/5.23/Protocols/DatabaseWriter.html). +This chapter was removed. See the references of [DatabaseReader](http://groue.github.io/GRDB.swift/docs/5.24/Protocols/DatabaseReader.html) and [DatabaseWriter](http://groue.github.io/GRDB.swift/docs/5.24/Protocols/DatabaseWriter.html). #### Asynchronous APIs @@ -8430,7 +8430,7 @@ This chapter was renamed to [Embedding SQL in Query Interface Requests]. [Sharing a Database]: Documentation/SharingADatabase.md [FAQ]: #faq [Database Observation]: #database-changes-observation -[SQLRequest]: http://groue.github.io/GRDB.swift/docs/5.23/Structs/SQLRequest.html +[SQLRequest]: http://groue.github.io/GRDB.swift/docs/5.24/Structs/SQLRequest.html [SQL literal]: Documentation/SQLInterpolation.md#sql-literal [Identifiable]: https://developer.apple.com/documentation/swift/identifiable [Query Interface Organization]: Documentation/QueryInterfaceOrganization.md diff --git a/Support/Info.plist b/Support/Info.plist index 179a239cf..587e94083 100644 --- a/Support/Info.plist +++ b/Support/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 5.23.0 + 5.24.0 CFBundleSignature ???? CFBundleVersion