Merge branch 'development'

This commit is contained in:
Gwendal Roué committed 2023-04-01 17:22:35 +02:00
commit 3184334535
17 files changed
+161 -77

No files matched your search

+32 -12
View File
@@ -38,6 +38,18 @@ jobs:
fail-fast: false
matrix:
include:
- xcode: "Xcode_14.2.app"
runsOn: macOS-12
destination: "platform=macOS"
name: "macOS"
- xcode: "Xcode_14.2.app"
runsOn: macOS-12
destination: "OS=16.2,name=iPhone 14"
name: "iOS"
- xcode: "Xcode_14.2.app"
runsOn: macOS-12
destination: "OS=16.1,name=Apple TV"
name: "tvOS"
- xcode: "Xcode_14.1.app"
runsOn: macOS-12
destination: "platform=macOS"
@@ -46,10 +58,6 @@ jobs:
runsOn: macOS-12
destination: "OS=16.1,name=iPhone 14"
name: "iOS"
- xcode: "Xcode_14.1.app"
runsOn: macOS-12
destination: "OS=16.1,name=Apple TV"
name: "tvOS"
- xcode: "Xcode_14.0.1.app"
runsOn: macOS-12
destination: "platform=macOS"
@@ -72,6 +80,9 @@ jobs:
fail-fast: false
matrix:
include:
- xcode: "Xcode_14.2.app"
runsOn: macOS-12
name: "Xcode 14.2"
- xcode: "Xcode_14.1.app"
runsOn: macOS-12
name: "Xcode 14.1"
@@ -92,9 +103,9 @@ jobs:
fail-fast: false
matrix:
include:
- xcode: "Xcode_14.1.app"
- xcode: "Xcode_14.2.app"
runsOn: macOS-12
name: "Xcode 14.1"
name: "Xcode 14.2"
steps:
- uses: actions/checkout@v3
- name: ${{ matrix.name }}
@@ -109,9 +120,12 @@ jobs:
fail-fast: false
matrix:
include:
- xcode: "Xcode_14.1.app"
- xcode: "Xcode_14.2.app"
runsOn: macOS-12
name: "Xcode 14.1"
name: "Xcode 14.2"
- xcode: "Xcode_14.0.1.app"
runsOn: macOS-12
name: "Xcode 14.0.1"
steps:
- uses: actions/checkout@v3
- name: ${{ matrix.name }}
@@ -126,9 +140,12 @@ jobs:
fail-fast: false
matrix:
include:
- xcode: "Xcode_14.1.app"
- xcode: "Xcode_14.2.app"
runsOn: macOS-12
name: "Xcode 14.1"
name: "Xcode 14.2"
- xcode: "Xcode_14.0.1.app"
runsOn: macOS-12
name: "Xcode 14.0.1"
steps:
- uses: actions/checkout@v3
- name: ${{ matrix.name }}
@@ -143,9 +160,12 @@ jobs:
fail-fast: false
matrix:
include:
- xcode: "Xcode_14.1.app"
- xcode: "Xcode_14.2.app"
runsOn: macOS-12
name: "Xcode 14.1"
name: "Xcode 14.2"
- xcode: "Xcode_14.0.1.app"
runsOn: macOS-12
name: "Xcode 14.0.1"
steps:
- uses: actions/checkout@v3
- name: ${{ matrix.name }}
+7 -1
View File
@@ -7,7 +7,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
#### 6.x Releases
- `6.10.x` Releases - [6.10.0](#6100)
- `6.10.x` Releases - [6.10.0](#6100) - [6.10.1](#6101)
- `6.9.x` Releases - [6.9.0](#690) - [6.9.1](#691) - [6.9.2](#692)
- `6.8.x` Releases - [6.8.0](#680)
- `6.7.x` Releases - [6.7.0](#670)
@@ -108,6 +108,12 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
---
## 6.10.1
Released April 1, 2023 • [diff](https://github.com/groue/GRDB.swift/compare/v6.10.0...v6.10.1)
- **Fixed**: [#1357](https://github.com/groue/GRDB.swift/pull/1357) `QueryInterfaceRequest.fetchCount` no longer executes invalid SQL queries for some requests.
## 6.10.0
Released March 20, 2023 • [diff](https://github.com/groue/GRDB.swift/compare/v6.9.2...v6.10.0)
-1
View File
@@ -21,7 +21,6 @@ To release a new GRDB version:
- Check tag authors: `git for-each-ref --format '%(refname) %(authorname)' refs/tags`
- Push to the master & development branch
- `pod trunk push --allow-warnings GRDB.swift.podspec`
- Update https://github.com/groue/WWDCCompanion
- Update [performance comparison](https://github.com/groue/GRDB.swift/wiki/Performance):
`make test_performance | Tests/parsePerformanceTests.rb | Tests/generatePerformanceReport.rb`
+1 -1
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'GRDB.swift'
s.version = '6.10.0'
s.version = '6.10.1'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.summary = 'A toolkit for SQLite databases, with a focus on application development.'
+29 -25
View File
@@ -225,21 +225,22 @@ extension DatabaseQueue: DatabaseReader {
public func asyncRead(_ value: @escaping (Result<Database, Error>) -> Void) {
writer.async { db in
do {
// The transaction guarantees snapshot isolation against eventual
// external connection.
try db.beginTransaction(.deferred)
try db.beginReadOnly()
} catch {
value(.failure(error))
return
defer {
// Ignore error because we can not notify it.
try? db.commit()
try? db.endReadOnly()
}
value(.success(db))
// Ignore error because we can not notify it.
try? db.endReadOnly()
try? db.commit()
do {
// Enter read-only mode before starting a transaction, so that the
// transaction commit does not trigger database observation.
// See <https://github.com/groue/GRDB.swift/pull/1213>.
try db.beginReadOnly()
try db.beginTransaction(.deferred)
value(.success(db))
} catch {
value(.failure(error))
}
}
}
@@ -273,20 +274,23 @@ extension DatabaseQueue: DatabaseReader {
writer.execute { db in
// ... and that no transaction is opened.
GRDBPrecondition(!db.isInsideTransaction, "must not be called from inside a transaction.")
do {
try db.beginTransaction(.deferred)
try db.beginReadOnly()
} catch {
value(.failure(error))
return
defer {
// Ignore error because we can not notify it.
try? db.commit()
try? db.endReadOnly()
}
value(.success(db))
// Ignore error because we can not notify it.
try? db.endReadOnly()
try? db.commit()
do {
// Enter read-only mode before starting a transaction, so that the
// transaction commit does not trigger database observation.
// See <https://github.com/groue/GRDB.swift/pull/1213>.
try db.beginReadOnly()
try db.beginTransaction(.deferred)
value(.success(db))
} catch {
value(.failure(error))
}
}
}
+8 -5
View File
@@ -289,14 +289,13 @@ public protocol DatabaseWriter: DatabaseReader {
/// ```
///
/// - note: Usage of this method is discouraged, because waiting on the
/// returned ``DatabaseFuture`` blocks a thread. You may prefer the
/// asynchronous version of this method: ``spawnConcurrentRead(_:)``.
/// returned ``DatabaseFuture`` blocks a thread. You may prefer
/// ``spawnConcurrentRead(_:)`` instead.
/// - parameter value: A closure which accesses the database.
func concurrentRead<T>(_ value: @escaping (Database) throws -> T) -> DatabaseFuture<T>
// Exposed for RxGRDB and GRBCombine. Naming is not stabilized.
/// Schedules read-only database operations for execution, and
/// returns immediately.
/// Schedules read-only database operations for execution.
///
/// - note: [**🔥 EXPERIMENTAL**](https://github.com/groue/GRDB.swift/blob/master/README.md#what-are-experimental-features)
///
@@ -311,7 +310,7 @@ public protocol DatabaseWriter: DatabaseReader {
/// by the database writer.
///
/// In the example below, the number of players is fetched concurrently with
/// the player insertion. Yet the future is guaranteed to return zero:
/// the player insertion. Yet it is guaranteed to return zero:
///
/// ```swift
/// try writer.writeWithoutTransaction { db in
@@ -334,6 +333,10 @@ public protocol DatabaseWriter: DatabaseReader {
/// }
/// ```
///
/// - important: The database operations are executed immediately,
/// or asynchronously, depending on the actual class
/// of `DatabaseWriter`.
///
/// - parameter value: A closure which accesses the database. Its argument
/// is a `Result` that provides the database connection, or the failure
/// that would prevent establishing the read access to the database.
+13 -7
View File
@@ -454,7 +454,7 @@ class DatabaseObservationBroker {
if savepointStack.isEmpty {
// Notify now
for statementObservation in statementObservations where statementObservation.predicate.evaluate(event) {
for statementObservation in statementObservations where statementObservation.tracksEvent(event) {
statementObservation.transactionObservation.databaseWillChange(with: event)
}
} else {
@@ -479,7 +479,7 @@ class DatabaseObservationBroker {
if savepointStack.isEmpty {
// Notify now
for statementObservation in statementObservations where statementObservation.predicate.evaluate(event) {
for statementObservation in statementObservations where statementObservation.tracksEvent(event) {
statementObservation.transactionObservation.databaseDidChange(with: event)
}
} else {
@@ -639,7 +639,7 @@ class DatabaseObservationBroker {
for (event, statementObservations) in eventsBuffer {
assert(statementObservations.isEmpty || !database.isReadOnly, "Read-only transactions are not notified")
for statementObservation in statementObservations where statementObservation.predicate.evaluate(event) {
for statementObservation in statementObservations where statementObservation.tracksEvent(event) {
event.send(to: statementObservation.transactionObservation)
}
}
@@ -969,12 +969,18 @@ final class TransactionObservation {
struct StatementObservation {
var transactionObservation: TransactionObservation
/// Filters database events that should be notified.
var predicate: DatabaseEventPredicate
/// A predicate that filters database events that should be notified.
///
/// Call this predicate as a method:
///
/// ```
/// if observation.tracksEvent(event) { ... }
/// ```
var tracksEvent: DatabaseEventPredicate
init(transactionObservation: TransactionObservation, trackingEvents predicate: DatabaseEventPredicate) {
self.transactionObservation = transactionObservation
self.predicate = predicate
self.tracksEvent = predicate
}
}
@@ -1447,7 +1453,7 @@ enum DatabaseEventPredicate {
/// statement authorizer.
case matching(observedEventKinds: [DatabaseEventKind], authorizerEventKinds: [DatabaseEventKind])
func evaluate(_ event: some DatabaseEventProtocol) -> Bool {
func callAsFunction(_ event: some DatabaseEventProtocol) -> Bool {
switch self {
case .all:
return true
+3 -18
View File
@@ -1,3 +1,5 @@
// swiftlint:disable:next line_length
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER && (compiler(>=5.7.1) || !(os(macOS) || targetEnvironment(macCatalyst))))
/// An instance of WALSnapshot records the state of a WAL mode database for some
/// specific point in history.
///
@@ -20,13 +22,6 @@
///
/// See <https://www.sqlite.org/c3ref/snapshot.html>.
final class WALSnapshot: Sendable {
// Xcode 14 (Swift 5.7) ships with a macOS SDK that misses snapshot support.
// Xcode 14.1 (Swift 5.7.1) ships with a macOS SDK that has snapshot support.
// This is the meaning of (compiler(>=5.7.1) || !(os(macOS) || targetEnvironment(macCatalyst)))
// swiftlint:disable:next line_length
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER && (compiler(>=5.7.1) || !(os(macOS) || targetEnvironment(macCatalyst))))
static let available = true
let sqliteSnapshot: UnsafeMutablePointer<sqlite3_snapshot>
init(_ db: Database) throws {
@@ -67,15 +62,5 @@ final class WALSnapshot: Sendable {
func compare(_ other: WALSnapshot) -> CInt {
sqlite3_snapshot_cmp(sqliteSnapshot, other.sqliteSnapshot)
}
#else
static let available = false
init(_ db: Database) throws {
throw DatabaseError(resultCode: .SQLITE_MISUSE, message: "snapshots are not available")
}
func compare(_ other: WALSnapshot) -> CInt {
preconditionFailure("snapshots are not available")
}
#endif
}
#endif
+2
View File
@@ -167,3 +167,5 @@ extension ValueObservation {
where Reducer == ValueReducers.Fetch<Value>
{ preconditionFailure() }
}
// swiftlint:enable all
+6 -1
View File
@@ -612,7 +612,12 @@ extension SQLRelation {
guard !isDistinct else {
return try fetchTrivialCount(db)
}
// <https://github.com/groue/GRDB.swift/issues/1357>
guard selection.allSatisfy(\.isTriviallyCountable) else {
return try fetchTrivialCount(db)
}
// SELECT expr1, expr2, ... FROM tableName ...
// ->
// SELECT COUNT(*) FROM tableName ...
@@ -244,6 +244,18 @@ extension SQLSelection {
return .literal(sqlLiteral.qualified(with: alias))
}
}
/// Supports SQLRelation.fetchCount.
///
/// See <https://github.com/groue/GRDB.swift/issues/1357>
var isTriviallyCountable: Bool {
switch impl {
case .aliasedExpression, .literal:
return false
case .allColumns, .qualifiedAllColumns, .expression:
return true
}
}
}
extension [SQLSelection] {
+10 -2
View File
@@ -52,10 +52,13 @@ MAX_IOS_DESTINATION := $(shell xcrun simctl list -j devices available | Scripts/
MIN_TVOS_DESTINATION := $(shell xcrun simctl list -j devices available | Scripts/destination.rb | grep tvOS | sort -n | head -1 | cut -wf 3 | sed 's/\(.*\)/"platform=tvOS Simulator,id=\1"/')
MAX_TVOS_DESTINATION := $(shell xcrun simctl list -j devices available | Scripts/destination.rb | grep tvOS | sort -rn | head -1 | cut -wf 3 | sed 's/\(.*\)/"platform=tvOS Simulator,id=\1"/')
# If xcpretty is available, use it for xcodebuild output
# If xcbeautify or xcpretty is available, use it for xcodebuild output
XCPRETTY =
XCBEAUTIFY_PATH := $(shell command -v xcbeautify 2> /dev/null)
XCPRETTY_PATH := $(shell command -v xcpretty 2> /dev/null)
ifdef XCPRETTY_PATH
ifdef XCBEAUTIFY_PATH
XCPRETTY = | xcbeautify
else ifdef XCPRETTY_PATH
XCPRETTY = | xcpretty -c
endif
@@ -128,6 +131,7 @@ test_framework_GRDBCustomSQLiteOSX: SQLiteCustom
$(XCODEBUILD) \
-project GRDBCustom.xcodeproj \
-scheme GRDBCustom \
-destination "platform=macOS" \
$(TEST_ACTIONS) \
$(XCPRETTY)
@@ -249,6 +253,7 @@ test_install_SPM_Project:
$(XCODEBUILD) \
-project Tests/SPM/PlainProject/Plain.xcodeproj \
-scheme Plain \
-destination "platform=macOS" \
-configuration Release \
clean build \
$(XCPRETTY)
@@ -266,6 +271,7 @@ test_install_SPM_macos_release:
$(XCODEBUILD) \
-project Tests/SPM/macos/macos.xcodeproj \
-scheme macos \
-destination "platform=macOS" \
-configuration Release \
clean build \
$(XCPRETTY)
@@ -283,6 +289,7 @@ test_install_customSQLite: SQLiteCustom
$(XCODEBUILD) \
-project Tests/CustomSQLite/CustomSQLite.xcodeproj \
-scheme CustomSQLite \
-destination "platform=macOS" \
-configuration Release \
clean build \
$(XCPRETTY)
@@ -357,6 +364,7 @@ test_performance:
$(XCODEBUILD) \
-project Tests/Performance/GRDBPerformance/GRDBPerformance.xcodeproj \
-scheme GRDBOSXPerformanceComparisonTests \
-destination "platform=macOS" \
build-for-testing test-without-building
# Target that setups SQLite custom builds with extra compilation options.
+2 -2
View File
@@ -11,13 +11,13 @@
---
**Latest release**: March 20, 2023 • [version 6.10.0](https://github.com/groue/GRDB.swift/tree/v6.10.0) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 5 to GRDB 6](Documentation/GRDB6MigrationGuide.md)
**Latest release**: April 1, 2023 • [version 6.10.1](https://github.com/groue/GRDB.swift/tree/v6.10.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+
| Swift version | GRDB version |
| -------------- | ----------------------------------------------------------- |
| **Swift 5.7+** | **v6.10.0** |
| **Swift 5.7+** | **v6.10.1** |
| Swift 5.3 | [v5.26.1](https://github.com/groue/GRDB.swift/tree/v5.26.1) |
| 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) |
-1
View File
@@ -62,7 +62,6 @@ opt_in_rules:
- sorted_first_last
- sorted_imports
- toggle_bool
- unused_capture_list
- vertical_parameter_alignment_on_call
- yoda_condition
+1 -1
View File
@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>6.10.0</string>
<string>6.10.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
@@ -136,6 +136,21 @@ class QueryInterfaceRequestTests: GRDBTestCase {
}
}
// Regression test for <https://github.com/groue/GRDB.swift/issues/1357>
func testIssue1357() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
let request = tableRequest
.annotated(with: Column("name").forKey("alt"))
.filter(Column("alt").detached)
XCTAssertEqual(try request.fetchCount(db), 0)
XCTAssertEqual(lastSQLQuery, """
SELECT COUNT(*) FROM (SELECT *, "name" AS "alt" FROM "readers" WHERE "alt")
""")
}
}
// MARK: - Select
@@ -782,7 +782,11 @@ class ValueObservationTests: GRDBTestCase {
assertValueObservationRecordingMatch(recorded: counts, expected: [0, 1, 2])
// Observation was ended
#if compiler(>=5.8)
await fulfillment(of: [cancellationExpectation], timeout: 2)
#else
wait(for: [cancellationExpectation], timeout: 2)
#endif
}
try await AsyncTest(test).run { try DatabaseQueue() }
@@ -816,7 +820,11 @@ class ValueObservationTests: GRDBTestCase {
assertValueObservationRecordingMatch(recorded: counts, expected: [0, 1, 2])
// Observation was ended
#if compiler(>=5.8)
await fulfillment(of: [cancellationExpectation], timeout: 2)
#else
wait(for: [cancellationExpectation], timeout: 2)
#endif
}
try await AsyncTest(test).run { try DatabaseQueue() }
@@ -854,7 +862,11 @@ class ValueObservationTests: GRDBTestCase {
assertValueObservationRecordingMatch(recorded: counts, expected: [0, 1, 2])
// Observation was ended
#if compiler(>=5.8)
await fulfillment(of: [cancellationExpectation], timeout: 2)
#else
wait(for: [cancellationExpectation], timeout: 2)
#endif
}
try await AsyncTest(test).run { try DatabaseQueue() }
@@ -889,7 +901,11 @@ class ValueObservationTests: GRDBTestCase {
assertValueObservationRecordingMatch(recorded: counts, expected: [0])
// Observation was ended
#if compiler(>=5.8)
await fulfillment(of: [cancellationExpectation], timeout: 2)
#else
wait(for: [cancellationExpectation], timeout: 2)
#endif
}
try await AsyncTest(test).run { try DatabaseQueue() }
@@ -936,7 +952,11 @@ class ValueObservationTests: GRDBTestCase {
XCTAssertEqual(cancelledValue, "cancelled loop")
// Make sure observation was cancelled as well
#if compiler(>=5.8)
await fulfillment(of: [cancellationExpectation], timeout: 2)
#else
wait(for: [cancellationExpectation], timeout: 2)
#endif
}
try await AsyncTest(test).run { try DatabaseQueue() }