Compare commits

..
Author SHA1 Message Date
Tim De Jong 3dd3bbf0c5 vscode config 2025-10-12 18:03:57 +02:00
Tim De Jong d7cf0f9e59 NSError bridging is not available, or doesn't work the same on non-Darwin platforms. Skip testNSErrorBridging on these platforms. 2025-10-12 18:03:57 +02:00
Tim De Jong 389c3e0d4a Use #if !canImport(Combine) per test case (as done by @marcprux) and throw an XCTSkip for these test cases. This gives a better impression how many tests are skipped on Linux/non-Darwin platforms. 2025-10-12 18:03:57 +02:00
Tim De Jong a212bf9e89 It should be canImport(Darwin) not os(Darwin) 2025-10-12 18:03:57 +02:00
Tim De Jong 65186104cc Integrated upstream changes.
Some tests depend on Combine which is not available on non-Darwin platforms. Fix this.
2025-10-12 18:03:57 +02:00
Tim De Jong 2f108508fa Fixed DatabaseSnapshotTests on non-darwin platforms 2025-10-12 18:03:57 +02:00
Tim De Jong 5513eab099 Fixed the tests in DatabaseQueueTests.swift 2025-10-12 18:03:57 +02:00
Tim De Jong 2ad2d20a89 Fixed the unit tests in DatabasePoolConcurrencyTests. 2025-10-12 18:03:57 +02:00
Tim De Jong dd90fe6e62 Ignore ValueObservationRecorderTests.swift on non-Darwin platforms. 2025-10-12 18:03:57 +02:00
Tim De Jong 691207567a Ignore FailureTestCase.swift entirely on non-Darwin platforms for now. 2025-10-12 18:03:57 +02:00
Tim De Jong c7f1dd7470 Fixed import in CGFloatTests.swift to work under non-Darwin platforms. 2025-10-12 18:03:57 +02:00
Tim De Jong 8e5b9ca9bd Fixed UUID fromDatabaseValue for non-Darwin platforms 2025-10-12 18:03:56 +02:00
Tim De Jong dc7d47c066 Fixed databaseValue build for non-Darwin platforms. 2025-10-12 18:03:56 +02:00
Tim De Jong 14f60ad48f Fixed fromDatabaseValue build under non-Darwin platforms 2025-10-12 18:03:56 +02:00
Tim De Jong e758fde941 Removed #if !os(Linux) in NSString.swift, NSData.swift and Date.swift. 2025-10-12 17:43:25 +02:00
Tim De Jong 7477e1cff8 Removed the #if !os(Linux) compiler directive in the Decimal extension, as it compiles fine under swift 6 2025-10-12 17:43:15 +02:00
Tim De Jong 2d6fe172c3 Import Foundation for CGFloat on non-Darwin platforms 2025-10-12 17:43:02 +02:00
Tim De Jong 0526853dde Fixed some linker errors caused by WAL absence on Linux. 2025-10-12 17:42:49 +02:00
Gwendal Roué a60810f28e Merge pull request #1819 from groue/dev/SQLCipher-cleanup
Accept multiple SQLCipher libraries
2025-10-12 15:46:52 +02:00
Gwendal Roué c35095c6da Enable more tests 2025-10-12 14:58:06 +02:00
Gwendal Roué f878d99733 Use SQLITE_HAS_CODEC instead of GRDBCIPHER when testing for SQLCipher availability
GRDBCIPHER is now just a marker for importing SQLCipher with CocoaPods.

Also, enable all APIs that used to be disabled with SQLCipher, and skip tests that require a specific SQLite version.
2025-10-12 14:49:59 +02:00
Gwendal Roué 48a17ce490 Merge pull request #1826 from groue/dev/snapshot-cleanup
Simplify the compiler checks for the availability of SQLite snapshots
2025-10-12 14:27:06 +02:00
Gwendal Roué 361a482b1e Enable SQLITE_ENABLE_SNAPSHOT by default and introduce SQLITE_DISABLE_SNAPSHOT 2025-10-12 14:03:09 +02:00
Gwendal Roué 8cba324d6e Refactor the SQLite import
We can not use `#if Trait` because Xcode does not enable those compiler flags. Always count on Apple for delivering the best quality software.

So now we import the default SPM SQLite last, after all other cases have been excluded.

The GRDB framework (GRDB.xcodeproj and GRDB via CocoaPods) is distinct from the default SPM trait, so we detect it with GRDBFRAMEWORK.
2025-10-04 17:56:06 +02:00
Gwendal Roué 17e1683b66 Bump CI to macOS 15 and Xcode 16.4 2025-10-04 17:56:06 +02:00
Gwendal Roué b1b83abd8b Simplify the compiler checks for the availability of SQLite snapshots 2025-10-04 14:15:13 +02:00
Gwendal Roué d06c9ed6b5 Enable SQLITE_ENABLE_SNAPSHOT in the Xcode GRDB framework 2025-10-04 14:15:13 +02:00
Gwendal Roué 9a98ed6292 Enable SQLITE_ENABLE_SNAPSHOT in the GRDBSQLite trait, on Darwin platforms 2025-10-04 14:15:13 +02:00
Gwendal Roué 5cc85a98f3 Only depend on GRDBSQLite when the default GRDBSQLite trait is active. 2025-10-04 13:53:38 +02:00
Gwendal Roué edc1d646f0 [BREAKING] Bump minimum Swift version to 6.1 2025-10-04 13:53:38 +02:00
Gwendal Roué ab09078842 Fix failing test for merged migration that merges itself 2025-10-03 09:36:22 +02:00
Gwendal Roué 267e1ea5a6 Add failing test for merged migration that merges itself 2025-10-03 09:34:26 +02:00
Gwendal Roué 18497b68fd Merge branch 'development' 2025-10-02 08:11:07 +02:00
Gwendal Roué 19e33e2e7d v7.8.0 2025-10-02 08:10:52 +02:00
Gwendal Roué 76e0815907 Merge pull request #1818 from groue/dev/obsolete-migrations
Merged Migrations
2025-10-02 08:06:24 +02:00
Gwendal Roué 85ad232b0b Support for migrations that merge previous migrations 2025-10-01 17:24:00 +02:00
Gwendal Roué db695cf7dc Merge branch 'development' 2025-09-29 21:14:01 +02:00
Gwendal Roué 76a7be8404 v7.7.1 2025-09-29 20:29:44 +02:00
Gwendal Roué 196c33ba63 Merge pull request #1822 from groue/dev/issue-1820
Fix the save() method for record types with attached triggers
2025-09-29 20:26:12 +02:00
Gwendal Roué 50a74f7b03 Cleanup 2025-09-29 19:43:41 +02:00
Gwendal Roué 3f27fb9289 Fix #1820
The regression was introduced by c7bbebc
2025-09-29 19:35:00 +02:00
Gwendal Roué 62fdd41d75 Failing regression test for #1820 2025-09-29 19:34:15 +02:00
127 changed files with 1542 additions and 691 deletions

No files matched your search

+24 -24
View File
@@ -1,4 +1,4 @@
# https://github.com/actions/runner-images/blob/main/images/macos/macos-14-Readme.md
# https://github.com/actions/runner-images/blob/main/images/macos/macos-15-Readme.md
name: "GRDB CI"
@@ -40,17 +40,17 @@ jobs:
fail-fast: false
matrix:
include:
- xcode: "Xcode_16.1.app"
runsOn: macOS-14
- xcode: "Xcode_16.4.app"
runsOn: macOS-15
destination: "platform=macOS"
name: "macOS"
- xcode: "Xcode_16.1.app"
runsOn: macOS-14
destination: "OS=18.1,name=iPhone 16 Pro"
- xcode: "Xcode_16.4.app"
runsOn: macOS-15
destination: "OS=18.5,name=iPhone 16 Pro"
name: "iOS"
- xcode: "Xcode_16.1.app"
runsOn: macOS-14
destination: "OS=18.1,name=Apple TV"
- xcode: "Xcode_16.4.app"
runsOn: macOS-15
destination: "OS=18.5,name=Apple TV"
name: "tvOS"
steps:
- uses: actions/checkout@v5
@@ -66,9 +66,9 @@ jobs:
fail-fast: false
matrix:
include:
- xcode: "Xcode_16.1.app"
runsOn: macOS-14
name: "Xcode 16.1"
- xcode: "Xcode_16.4.app"
runsOn: macOS-15
name: "Xcode 16.4"
steps:
- uses: actions/checkout@v5
- name: ${{ matrix.name }}
@@ -83,9 +83,9 @@ jobs:
fail-fast: false
matrix:
include:
- xcode: "Xcode_16.1.app"
runsOn: macOS-14
name: "Xcode 16.1"
- xcode: "Xcode_16.4.app"
runsOn: macOS-15
name: "Xcode 16.4"
steps:
- uses: actions/checkout@v5
- name: ${{ matrix.name }}
@@ -100,9 +100,9 @@ jobs:
fail-fast: false
matrix:
include:
- xcode: "Xcode_16.1.app"
runsOn: macOS-14
name: "Xcode 16.1"
- xcode: "Xcode_16.4.app"
runsOn: macOS-15
name: "Xcode 16.4"
steps:
- uses: actions/checkout@v5
- name: ${{ matrix.name }}
@@ -117,9 +117,9 @@ jobs:
fail-fast: false
matrix:
include:
- xcode: "Xcode_16.1.app"
runsOn: macOS-14
name: "Xcode 16.1"
- xcode: "Xcode_16.4.app"
runsOn: macOS-15
name: "Xcode 16.4"
steps:
- uses: actions/checkout@v5
- name: ${{ matrix.name }}
@@ -134,9 +134,9 @@ jobs:
fail-fast: false
matrix:
include:
- xcode: "Xcode_16.1.app"
runsOn: macOS-14
name: "Xcode 16.1"
- xcode: "Xcode_16.4.app"
runsOn: macOS-15
name: "Xcode 16.4"
steps:
- uses: actions/checkout@v5
- name: ${{ matrix.name }}
+1 -1
View File
@@ -2,4 +2,4 @@ version: 1
builder:
configs:
- documentation_targets: [GRDB]
swift_version: 6.0
swift_version: 6.1
+7
View File
@@ -0,0 +1,7 @@
{
"editor.formatOnSave": false,
"editor.insertSpaces": true,
"editor.tabSize": 4,
"editor.detectIndentation": false,
"editor.trimAutoWhitespace": false
}
+14 -1
View File
@@ -7,7 +7,8 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
#### 7.x Releases
- `7.7.x` Releases - [7.7.0](#770)
- `7.8.x` Releases - [7.8.0](#780)
- `7.7.x` Releases - [7.7.0](#770) - [7.7.1](#771)
- `7.6.x` Releases - [7.6.0](#760) - [7.6.1](#761)
- `7.5.x` Releases - [7.5.0](#750)
- `7.4.x` Releases - [7.4.0](#740) - [7.4.1](#741)
@@ -139,6 +140,18 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
---
## 7.8.0
Released October 2, 2025
- **New**: Merged Migrations by [@groue](https://github.com/groue) in [#1818](https://github.com/groue/GRDB.swift/pull/1818)
## 7.7.1
Released September 29, 2025
- **Fixed**: Fix the save() method for record types with attached triggers by [@groue](https://github.com/groue) in [#1822](https://github.com/groue/GRDB.swift/pull/1822)
## 7.7.0
Released September 23, 2025
@@ -382,7 +382,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 6.0;
SWIFT_VERSION = 6.1;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
@@ -411,7 +411,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 6.0;
SWIFT_VERSION = 6.1;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
@@ -427,7 +427,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemoTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 6.0;
SWIFT_VERSION = 6.1;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GRDBDemo.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/GRDBDemo";
};
@@ -444,7 +444,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemoTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 6.0;
SWIFT_VERSION = 6.1;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GRDBDemo.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/GRDBDemo";
};
+3 -3
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'GRDB.swift'
s.version = '7.7.0'
s.version = '7.8.0'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.summary = 'A toolkit for SQLite databases, with a focus on application development.'
@@ -9,7 +9,7 @@ Pod::Spec.new do |s|
s.source = { :git => 'https://github.com/groue/GRDB.swift.git', :tag => "v#{s.version}" }
s.module_name = 'GRDB'
s.swift_versions = ['6']
s.swift_versions = ['6.1']
s.ios.deployment_target = '13.0'
s.osx.deployment_target = '10.15'
s.watchos.deployment_target = '7.0'
@@ -21,7 +21,7 @@ Pod::Spec.new do |s|
ss.framework = 'Foundation'
ss.library = 'sqlite3'
ss.xcconfig = {
'OTHER_SWIFT_FLAGS' => '$(inherited) -D SQLITE_ENABLE_FTS5',
'OTHER_SWIFT_FLAGS' => '$(inherited) -D SQLITE_ENABLE_FTS5 -D GRDBFRAMEWORK',
}
end
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
#if !canImport(Darwin)
+9 -6
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
extension Database {
@@ -138,7 +141,7 @@ extension Database {
}
}
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Returns information about a table or a view
func table(_ tableName: String) throws -> TableInfo? {
for schemaID in try fetchSchemaIdentifiers() {
@@ -572,7 +575,7 @@ extension Database {
/// - precondition: table exists.
private func fetchTableHasRowID(_ table: DatabaseObjectID) throws -> Bool {
// Prefer PRAGMA table_list if available
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
// Maybe SQLCipher is too old: check actual version
if sqlite3_libversion_number() >= 3037000 {
return try self.table(for: table)!.isWithoutRowIDTable == false
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
+35 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
@@ -2018,6 +2021,34 @@ extension Database {
}
#endif
extension Database {
/// Returns the count of changes executed by one statement execution.
func countChanges<T>(_ count: inout Int, forTable tableName: String, updates: () throws -> T) throws -> T {
// Database.changesCount calls sqlite3_changes(), whose documentation says:
//
// > https://sqlite.org/c3ref/changes.html
// > Changes to a view that are intercepted by INSTEAD OF triggers are not counted.
//
// We want to support INSTEAD OF triggers, so we prefer to use
// sqlite3_total_changes() for views.
//
// At the same time, FTS5 has sqlite3_total_changes() report changes
// even when database is not changed (https://github.com/groue/GRDB.swift/issues/1820)
//
// Well, let's do our best:
if try viewExists(tableName) {
let prevCount = totalChangesCount
let result = try updates()
count = totalChangesCount - prevCount
return result
} else {
let result = try updates()
count = changesCount
return result
}
}
}
extension Database {
// MARK: - Database-Related Types
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
/// A custom SQL function or aggregate.
+2 -2
View File
@@ -684,7 +684,7 @@ extension DatabasePool: DatabaseReader {
// MARK: - WAL Snapshot Transactions
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
/// Returns a long-lived WAL snapshot transaction on a reader connection.
func walSnapshotTransaction() throws -> WALSnapshotTransaction {
guard let readerPool else {
@@ -950,7 +950,7 @@ extension DatabasePool {
purpose: "snapshot.\(databaseSnapshotCountMutex.increment())")
}
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
/// Creates a database snapshot that allows concurrent accesses to an
/// unchanging database content, as it exists at the moment the snapshot
/// is created.
+8 -5
View File
@@ -1,11 +1,14 @@
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
/// A database connection that allows concurrent accesses to an unchanging
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
+2 -2
View File
@@ -552,7 +552,7 @@ extension DatabaseWriter {
// This method is declared on DatabaseWriter instead of DatabaseReader,
// so that it is not available on DatabaseSnaphot. VACUUM INTO is not
// available inside the transaction that is kept open by DatabaseSnaphot.
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Creates a new database file at the specified path with a minimum
/// amount of disk space.
///
@@ -665,7 +665,7 @@ extension DatabaseWriter {
try await writeWithoutTransaction { try $0.execute(sql: "VACUUM") }
}
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Creates a new database file at the specified path with a minimum
/// amount of disk space.
///
+4
View File
@@ -1,4 +1,8 @@
#if os(Linux)
@preconcurrency import Dispatch
#else
import Dispatch
#endif
/// An actor that runs in a DispatchQueue.
///
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
/// A key that is used to decode a value in a row
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
#if canImport(string_h)
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
/// A type that can decode itself from the low-level C interface to
+3 -1
View File
@@ -1,5 +1,8 @@
#if canImport(CoreGraphics)
import CoreGraphics
#elseif !canImport(Darwin)
import Foundation
#endif
/// CGFloat adopts DatabaseValueConvertible
extension CGFloat: DatabaseValueConvertible {
@@ -15,4 +18,3 @@ extension CGFloat: DatabaseValueConvertible {
return CGFloat(double)
}
}
#endif
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
+7 -6
View File
@@ -1,15 +1,17 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
#if !os(Linux)
/// NSDate is stored in the database using the format
/// "yyyy-MM-dd HH:mm:ss.SSS", in the UTC time zone.
extension NSDate: DatabaseValueConvertible {
@@ -38,7 +40,6 @@ extension NSDate: DatabaseValueConvertible {
return cast(date)
}
}
#endif
/// Date is stored in the database using the format
/// "yyyy-MM-dd HH:mm:ss.SSS", in the UTC time zone.
+7 -6
View File
@@ -1,11 +1,13 @@
#if !os(Linux)
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
@@ -65,4 +67,3 @@ extension Decimal: StatementColumnConvertible {
@usableFromInline
let _posixLocale = Locale(identifier: "en_US_POSIX")
#endif
@@ -1,4 +1,3 @@
#if !os(Linux)
import Foundation
/// NSData is convertible to and from DatabaseValue.
@@ -24,4 +23,3 @@ extension NSData: DatabaseValueConvertible {
return cast(data)
}
}
#endif
+11 -3
View File
@@ -1,4 +1,4 @@
#if !os(Linux) && !os(Windows)
#if !os(Windows)
import Foundation
private let integerRoundingBehavior = NSDecimalNumberHandler(
@@ -81,10 +81,18 @@ extension NSNumber: DatabaseValueConvertible {
/// Otherwise, returns nil.
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Self? {
switch dbValue.storage {
case .int64(let int64) where self is NSDecimalNumber.Type:
let number = NSDecimalNumber(value: int64)
return number as? Self
case .int64(let int64):
return self.init(value: int64)
let number = NSNumber(value: int64)
return number as? Self
case .double(let double) where self is NSDecimalNumber.Type:
let number = NSDecimalNumber(value: double)
return number as? Self
case .double(let double):
return self.init(value: double)
let number = NSNumber(value: double)
return number as? Self
case let .string(string):
// Must match Decimal.fromDatabaseValue(_:)
guard let decimal = Decimal(string: string, locale: posixLocale) else { return nil }
@@ -1,4 +1,3 @@
#if !os(Linux)
import Foundation
/// NSString adopts DatabaseValueConvertible
@@ -24,4 +23,3 @@ extension NSString: DatabaseValueConvertible {
return self.init(string: string)
}
}
#endif
+6 -2
View File
@@ -1,12 +1,16 @@
import Foundation
#if !os(Linux) && !os(Windows)
#if !os(Windows)
/// NSURL stores its absoluteString in the database.
extension NSURL: DatabaseValueConvertible {
/// Returns a TEXT database value containing the absolute URL.
public var databaseValue: DatabaseValue {
absoluteString?.databaseValue ?? .null
#if !canImport(Darwin)
absoluteString.databaseValue
#else
absoluteString?.databaseValue ?? .null
#endif
}
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Self? {
+19 -9
View File
@@ -1,15 +1,18 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
#if !os(Linux) && !os(Windows)
#if !os(Windows)
/// NSUUID adopts DatabaseValueConvertible
extension NSUUID: DatabaseValueConvertible {
/// Returns a BLOB database value containing the uuid bytes.
@@ -33,10 +36,17 @@ extension NSUUID: DatabaseValueConvertible {
switch dbValue.storage {
case .blob(let data) where data.count == 16:
return data.withUnsafeBytes {
self.init(uuidBytes: $0.bindMemory(to: UInt8.self).baseAddress)
#if canImport(Darwin)
self.init(uuidBytes: $0.bindMemory(to: UInt8.self).baseAddress)
#else
guard let uuidBytes = $0.bindMemory(to: UInt8.self).baseAddress else {
return nil as Self?
}
return NSUUID(uuidBytes: uuidBytes) as? Self
#endif
}
case .string(let string):
return self.init(uuidString: string)
return NSUUID(uuidString: string) as? Self
default:
return nil
}
@@ -88,8 +98,8 @@ extension UUID: StatementColumnConvertible {
self.init(uuid: uuid.uuid)
case SQLITE_BLOB:
guard sqlite3_column_bytes(sqliteStatement, index) == 16,
let blob = sqlite3_column_blob(sqliteStatement, index) else
{
let blob = sqlite3_column_blob(sqliteStatement, index)
else {
return nil
}
self.init(uuid: blob.assumingMemoryBound(to: uuid_t.self).pointee)
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
extension Optional: StatementBinding where Wrapped: StatementBinding {
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
// MARK: - Value Types
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
extension Database {
+8 -17
View File
@@ -1,11 +1,14 @@
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
/// An instance of WALSnapshot records the state of a WAL mode database for some
@@ -16,18 +19,6 @@ import SQLite3
/// actual observation. This class has no other purpose, and is not intended to
/// become public.
///
/// It does not work with SQLCipher, because SQLCipher does not support
/// `SQLITE_ENABLE_SNAPSHOT` correctly: we have linker errors.
/// See <https://github.com/ericsink/SQLitePCL.raw/issues/452>.
///
/// With custom SQLite builds, it only works if `SQLITE_ENABLE_SNAPSHOT`
/// is defined.
///
/// With system SQLite, it works because the SDK exposes the C apis and
/// since XCode 14.
///
/// Yes, this is an awfully complex logic.
///
/// See <https://www.sqlite.org/c3ref/snapshot.html>.
final class WALSnapshot: @unchecked Sendable {
// @unchecked because sqlite3_snapshot has no threading requirements.
+1 -1
View File
@@ -1,4 +1,4 @@
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
/// A long-live read-only WAL transaction.
///
/// `WALSnapshotTransaction` **takes ownership** of its reader
+1 -1
View File
@@ -324,7 +324,7 @@ extension Database {
}
private func isShadowTable(_ tableName: String) throws -> Bool {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
// Maybe SQLCipher is too old: check actual version
if Database.sqliteLibVersionNumber >= 3037000 {
guard let table = try table(tableName) else {
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
/// A format that prints one line per database row, formatting values
+2 -2
View File
@@ -40,11 +40,11 @@ public struct FTS3 {
/// the `remove_diacritics=1` tokenizer argument.
case removeLegacy
#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Remove diacritics from Latin script characters. This option matches
/// the `remove_diacritics=2` tokenizer argument.
case remove
#elseif !GRDBCIPHER
#else
/// Remove diacritics from Latin script characters. This option matches
/// the `remove_diacritics=2` tokenizer argument.
@available(iOS 14, macOS 10.16, tvOS 14, *) // SQLite 3.27+
+2 -2
View File
@@ -95,10 +95,10 @@ public struct FTS3TokenizerDescriptor: Sendable {
break
case .keep:
arguments.append("remove_diacritics=0")
#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
case .remove:
arguments.append("remove_diacritics=2")
#elseif !GRDBCIPHER
#else
case .remove:
arguments.append("remove_diacritics=2")
#endif
+9 -6
View File
@@ -1,11 +1,14 @@
#if SQLITE_ENABLE_FTS5
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
@@ -60,12 +63,12 @@ public struct FTS5 {
/// Remove diacritics from Latin script characters. This
/// option matches the raw "remove_diacritics=1" tokenizer argument.
case removeLegacy
#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Remove diacritics from Latin script characters. This
/// option matches the raw "remove_diacritics=2" tokenizer argument,
/// available from SQLite 3.27.0
case remove
#elseif !GRDBCIPHER
#else
/// Remove diacritics from Latin script characters. This
/// option matches the raw "remove_diacritics=2" tokenizer argument,
/// available from SQLite 3.27.0
+7 -4
View File
@@ -1,11 +1,14 @@
#if SQLITE_ENABLE_FTS5
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
/// A type that implements a custom tokenizer for the ``FTS5`` full-text engine.
+7 -4
View File
@@ -1,11 +1,14 @@
#if SQLITE_ENABLE_FTS5
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
+2 -2
View File
@@ -182,10 +182,10 @@ public struct FTS5TokenizerDescriptor: Sendable {
break
case .keep:
components.append(contentsOf: ["remove_diacritics", "0"])
#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
case .remove:
components.append(contentsOf: ["remove_diacritics", "2"])
#elseif !GRDBCIPHER
#else
case .remove:
components.append(contentsOf: ["remove_diacritics", "2"])
#endif
+7 -4
View File
@@ -1,11 +1,14 @@
#if SQLITE_ENABLE_FTS5
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
+1 -1
View File
@@ -154,7 +154,7 @@ extension SQLSpecificExpressible {
}
}
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
extension SQLJSONExpressible {
/// The `->>` SQL operator.
///
+1 -1
View File
@@ -1,4 +1,4 @@
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
// MARK: - JSON
extension Database {
+156 -14
View File
@@ -18,6 +18,7 @@ import Foundation
/// ### Registering Migrations
///
/// - ``registerMigration(_:foreignKeyChecks:migrate:)``
/// - ``registerMigration(_:foreignKeyChecks:merging:migrate:)``
/// - ``ForeignKeyChecks``
///
/// ### Configuring a DatabaseMigrator
@@ -161,9 +162,8 @@ public struct DatabaseMigrator: Sendable {
/// Registers a migration.
///
/// The registered migration is appended to the list of migrations to run:
/// it will execute after previously registered migrations, and before
/// migrations that are registered later.
/// The registered migration is appended to the list of migrations. It
/// will execute after previously registered migrations.
///
/// For example:
///
@@ -214,6 +214,107 @@ public struct DatabaseMigrator: Sendable {
_ identifier: String,
foreignKeyChecks: ForeignKeyChecks = .deferred,
migrate: @escaping @Sendable (Database) throws -> Void)
{
registerMigration(identifier, foreignKeyChecks: foreignKeyChecks, merging: []) { db, ids in
precondition(ids.isEmpty)
try migrate(db)
}
}
/// Registers a merged migration.
///
/// Like migrations registered with ``registerMigration(_:foreignKeyChecks:migrate:)``,
/// the merged migration is appended to the list of migrations. It
/// will execute after previously registered migrations.
///
/// A merged migration merges and replaces a set of migrations defined
/// in a previous version of the application. For example, to merge the
/// migrations "v1", "v2" and "v3", redefine the "v3" migration so that
/// it merges "v1" and "v2", as in the example below.
///
/// The second argument of the `migrate` closure is the subset of merged
/// migrations that have already been applied when the merged
/// migration runs.
///
/// ```swift
/// // Old code
/// migrator.registerMigration("v1") { db in
/// // Apply schema version 1
/// }
/// migrator.registerMigration("v2") { db in
/// // Apply schema version 2
/// }
/// migrator.registerMigration("v3") { db in
/// // Apply schema version 3
/// }
///
/// // New code:
/// // - Migrations v1 and v2 are deleted.
/// // - Migration v3 is redefined and merges v1 and v2:
/// migrator.registerMigration("v3", merging: ["v1", "v2"]) { db, appliedIDs in
/// if !appliedIDs.contains("v1") {
/// // Apply schema version 1
/// }
/// if !appliedIDs.contains("v2") {
/// // Apply schema version 2
/// }
/// // Apply schema version 3
/// }
/// ```
///
/// In the above sample code, the merged migration is named like the
/// last one of the merged set. You can also give it a brand new name,
/// as in the alternative below. Notice the different logic in the
/// migration code.
///
/// **In all cases avoid naming the merged migration like the first
/// elements in the merged set** (`v1` or `v2` in our example).
///
/// ```swift
/// // Alternative new code:
/// // - Migrations v1, v2 and v3 are deleted.
/// // - The new migration v3-new merges v1, v2 and v3:
/// migrator.registerMigration("v3-new", merging: ["v1", "v2", "v3"]) { db, appliedIDs in
/// if !appliedIDs.contains("v1") {
/// // Apply schema version 1
/// }
/// if !appliedIDs.contains("v2") {
/// // Apply schema version 2
/// }
/// if !appliedIDs.contains("v3") {
/// // Apply schema version 3
/// }
/// }
/// ```
///
/// - parameters:
/// - identifier: The migration identifier.
/// - mergedIdentifiers: A set of previous migration identifiers
/// that are merged in this migration.
/// - foreignKeyChecks: This parameter is ignored if the database
/// ``Configuration`` has disabled foreign keys.
///
/// The default `.deferred` checks have the migration run with
/// disabled foreign keys, until foreign keys are checked right before
/// changes are committed on disk. These deferred checks are not
/// executed if the migrator is the result of
/// ``disablingDeferredForeignKeyChecks()``.
///
/// The `.immediate` checks have the migration run with foreign
/// keys enabled. Make sure you only use `.immediate` if the migration
/// does not perform schema changes described in
/// <https://www.sqlite.org/lang_altertable.html#making_other_kinds_of_table_schema_changes>
/// - migrate: A closure that performs database operations. The
/// first argument is a database connection. The second argument
/// is the set of previous migrations that has been applied when
/// the merged migration runs.
/// - precondition: No migration with the same identifier as already
/// been registered.
public mutating func registerMigration(
_ identifier: String,
foreignKeyChecks: ForeignKeyChecks = .deferred,
merging mergedIdentifiers: Set<String> = [],
migrate: @escaping @Sendable (_ db: Database, _ appliedIdentifiers: Set<String>) throws -> Void)
{
let migrationChecks: Migration.ForeignKeyChecks
switch foreignKeyChecks {
@@ -226,7 +327,18 @@ public struct DatabaseMigrator: Sendable {
case .immediate:
migrationChecks = .immediate
}
registerMigration(Migration(identifier: identifier, foreignKeyChecks: migrationChecks, migrate: migrate))
// Remove the migration identifier from the list of merged identifiers.
// Arguably, the semantics are ambiguous. And raising a fatal error
// is a high price when we can just fix the input.
var mergedIdentifiers = mergedIdentifiers
mergedIdentifiers.remove(identifier)
registerMigration(Migration(
identifier: identifier,
mergedIdentifiers: mergedIdentifiers,
foreignKeyChecks: migrationChecks,
migrate: migrate))
}
// MARK: - Applying Migrations
@@ -450,6 +562,16 @@ public struct DatabaseMigrator: Sendable {
// MARK: - Non public
private struct Execution {
enum Mode {
case run(mergedIdentifiers: Set<String>)
case deleteMergedIdentifiers
}
var migration: Migration
var mode: Mode
}
private mutating func registerMigration(_ migration: Migration) {
GRDBPrecondition(
!_migrations.map({ $0.identifier }).contains(migration.identifier),
@@ -457,8 +579,8 @@ public struct DatabaseMigrator: Sendable {
_migrations.append(migration)
}
/// Returns unapplied migration identifier,
private func unappliedMigrations(upTo targetIdentifier: String, appliedIdentifiers: [String]) -> [Migration] {
/// Returns unapplied migration executions
private func unappliedExecutions(upTo targetIdentifier: String, appliedIdentifiers: Set<String>) -> [Execution] {
var expectedMigrations: [Migration] = []
for migration in _migrations {
expectedMigrations.append(migration)
@@ -472,32 +594,52 @@ public struct DatabaseMigrator: Sendable {
expectedMigrations.last?.identifier == targetIdentifier,
"undefined migration: \(String(reflecting: targetIdentifier))")
return expectedMigrations.filter { !appliedIdentifiers.contains($0.identifier) }
return expectedMigrations.compactMap { migration in
if appliedIdentifiers.contains(migration.identifier) {
if migration.mergedIdentifiers.isDisjoint(with: appliedIdentifiers) {
// Nothing to do
return nil
} else {
// Migration is applied, but we have some merged identifiers to delete
return Execution(migration: migration, mode: .deleteMergedIdentifiers)
}
} else {
// Migration is not applied yet.
let appliedMergedIdentifiers = migration.mergedIdentifiers.intersection(appliedIdentifiers)
return Execution(migration: migration, mode: .run(mergedIdentifiers: appliedMergedIdentifiers))
}
}
}
private func runMigrations(_ db: Database, upTo targetIdentifier: String) throws {
try db.execute(sql: "CREATE TABLE IF NOT EXISTS grdb_migrations (identifier TEXT NOT NULL PRIMARY KEY)")
let appliedIdentifiers = try self.appliedMigrations(db)
// Subsequent migration must not be applied
let appliedMigrations = try self.appliedMigrations(db) // Only known ids
if let targetIndex = _migrations.firstIndex(where: { $0.identifier == targetIdentifier }),
let lastAppliedIdentifier = appliedIdentifiers.last,
let lastAppliedIndex = _migrations.firstIndex(where: { $0.identifier == lastAppliedIdentifier }),
let lastAppliedMigration = appliedMigrations.last,
let lastAppliedIndex = _migrations.firstIndex(where: { $0.identifier == lastAppliedMigration }),
targetIndex < lastAppliedIndex
{
fatalError("database is already migrated beyond migration \(String(reflecting: targetIdentifier))")
}
let unappliedMigrations = self.unappliedMigrations(
let appliedIdentifiers = try self.appliedIdentifiers(db) // All ids, even unknown ones
let unappliedExecutions = self.unappliedExecutions(
upTo: targetIdentifier,
appliedIdentifiers: appliedIdentifiers)
if unappliedMigrations.isEmpty {
if unappliedExecutions.isEmpty {
return
}
for migration in unappliedMigrations {
try migration.run(db)
for execution in unappliedExecutions {
switch execution.mode {
case .run(let mergedIdentifiers):
try execution.migration.run(db, mergedIdentifiers: mergedIdentifiers)
case .deleteMergedIdentifiers:
try execution.migration.deleteMergedIdentifiers(db)
}
}
}
+31 -18
View File
@@ -6,22 +6,27 @@ struct Migration: Sendable {
case disabled
}
typealias Migrate = @Sendable (_ db: Database, _ mergedIdentifiers: Set<String>) throws -> Void
let identifier: String
let mergedIdentifiers: Set<String>
var foreignKeyChecks: ForeignKeyChecks
// Private so that the guarantees of `run(_:)` are enforced.
private let migrate: @Sendable (Database) throws -> Void
private let migrate: Migrate
init(
identifier: String,
mergedIdentifiers: Set<String>,
foreignKeyChecks: ForeignKeyChecks,
migrate: @escaping @Sendable (Database) throws -> Void
migrate: @escaping Migrate
) {
self.identifier = identifier
self.mergedIdentifiers = mergedIdentifiers
self.foreignKeyChecks = foreignKeyChecks
self.migrate = migrate
}
func run(_ db: Database) throws {
func run(_ db: Database, mergedIdentifiers: Set<String>) throws {
// Migrations access the raw SQLite schema, without alteration due
// to the schemaSource. The goal is to ensure that migrations are
// immutable, immune from spooky actions at a distance.
@@ -29,33 +34,40 @@ struct Migration: Sendable {
if try Bool.fetchOne(db, sql: "PRAGMA foreign_keys") ?? false {
switch foreignKeyChecks {
case .deferred:
try runWithDeferredForeignKeysChecks(db)
try runWithDeferredForeignKeysChecks(db, mergedIdentifiers: mergedIdentifiers)
case .immediate:
try runWithImmediateForeignKeysChecks(db)
try runWithImmediateForeignKeysChecks(db, mergedIdentifiers: mergedIdentifiers)
case .disabled:
try runWithDisabledForeignKeysChecks(db)
try runWithDisabledForeignKeysChecks(db, mergedIdentifiers: mergedIdentifiers)
}
} else {
try runWithImmediateForeignKeysChecks(db)
try runWithImmediateForeignKeysChecks(db, mergedIdentifiers: mergedIdentifiers)
}
}
}
private func runWithImmediateForeignKeysChecks(_ db: Database) throws {
func deleteMergedIdentifiers(_ db: Database) throws {
if mergedIdentifiers.isEmpty == false {
try db.execute(literal: "DELETE FROM grdb_migrations WHERE identifier IN \(mergedIdentifiers)")
}
}
private func runWithImmediateForeignKeysChecks(_ db: Database, mergedIdentifiers: Set<String>) throws {
try db.inTransaction(.immediate) {
try migrate(db)
try insertAppliedIdentifier(db)
try migrate(db, mergedIdentifiers)
try updateAppliedIdentifier(db)
return .commit
}
}
private func runWithDisabledForeignKeysChecks(_ db: Database) throws {
private func runWithDisabledForeignKeysChecks(_ db: Database, mergedIdentifiers: Set<String>) throws {
try db.execute(sql: "PRAGMA foreign_keys = OFF")
try throwingFirstError(
execute: {
try db.inTransaction(.immediate) {
try migrate(db)
try insertAppliedIdentifier(db)
try migrate(db, mergedIdentifiers)
try updateAppliedIdentifier(db)
return .commit
}
},
@@ -64,7 +76,7 @@ struct Migration: Sendable {
})
}
private func runWithDeferredForeignKeysChecks(_ db: Database) throws {
private func runWithDeferredForeignKeysChecks(_ db: Database, mergedIdentifiers: Set<String>) throws {
// Support for database alterations described at
// https://www.sqlite.org/lang_altertable.html#otheralter
//
@@ -76,8 +88,8 @@ struct Migration: Sendable {
execute: {
// > 2. Start a transaction.
try db.inTransaction(.immediate) {
try migrate(db)
try insertAppliedIdentifier(db)
try migrate(db, mergedIdentifiers)
try updateAppliedIdentifier(db)
// > 10. If foreign key constraints were originally enabled
// > then run PRAGMA foreign_key_check to verify that the
@@ -96,7 +108,8 @@ struct Migration: Sendable {
})
}
private func insertAppliedIdentifier(_ db: Database) throws {
try db.execute(sql: "INSERT INTO grdb_migrations (identifier) VALUES (?)", arguments: [identifier])
private func updateAppliedIdentifier(_ db: Database) throws {
try deleteMergedIdentifiers(db)
try db.execute(literal: "INSERT INTO grdb_migrations (identifier) VALUES (\(identifier))")
}
}
@@ -635,16 +635,18 @@ extension QueryInterfaceRequest {
@discardableResult
public func deleteAll(_ db: Database) throws -> Int {
let statement = try SQLQueryGenerator(relation: relation).makeDeleteStatement(db)
let prevCount = db.totalChangesCount
try statement.execute()
return db.totalChangesCount - prevCount
var changesCount = 0
try db.countChanges(&changesCount, forTable: relation.source.tableName) {
try statement.execute()
}
return changesCount
}
}
// MARK: - Batch Delete and Fetch
extension QueryInterfaceRequest {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Returns a `DELETE RETURNING` prepared statement.
///
/// For example:
@@ -1136,9 +1138,11 @@ extension QueryInterfaceRequest {
// database not hit
return 0
}
let prevCount = db.totalChangesCount
try updateStatement.execute()
return db.totalChangesCount - prevCount
var changesCount = 0
try db.countChanges(&changesCount, forTable: relation.source.tableName) {
try updateStatement.execute()
}
return changesCount
}
/// Updates matching rows, and returns the number of updated rows.
@@ -1172,7 +1176,7 @@ extension QueryInterfaceRequest {
// MARK: - Batch Update and Fetch
extension QueryInterfaceRequest {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Returns an `UPDATE RETURNING` prepared statement.
///
/// For example:
+4 -4
View File
@@ -517,7 +517,7 @@ public struct SQLExpression: Sendable {
/// The `>>` bitwise right shift operator
static let rightShift = BinaryOperator(">>")
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// The `->` SQL operator
static let jsonExtractJSON = BinaryOperator("->", isJSONValue: true)
@@ -2121,7 +2121,7 @@ extension SQLExpression {
}
}
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Returns an expression suitable in JSON building contexts.
var jsonBuilderExpression: SQLExpression {
switch preferredJSONInterpretation {
@@ -2373,7 +2373,7 @@ extension SQLSpecificExpressible {
.desc(sqlExpression)
}
#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// An ordering term for ascending order (nulls last).
public var ascNullsLast: SQLOrdering {
.ascNullsLast(sqlExpression)
@@ -2383,7 +2383,7 @@ extension SQLSpecificExpressible {
public var descNullsFirst: SQLOrdering {
.descNullsFirst(sqlExpression)
}
#elseif !GRDBCIPHER
#else
/// An ordering term for ascending order (nulls last).
@available(iOS 14, macOS 10.16, tvOS 14, *) // SQLite 3.30+
public var ascNullsLast: SQLOrdering {
+5 -5
View File
@@ -10,7 +10,7 @@ public func abs(_ value: some SQLSpecificExpressible) -> SQLExpression {
.function("ABS", [value.sqlExpression])
}
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// The `AVG` SQL aggregate function.
///
/// For example:
@@ -163,7 +163,7 @@ public func max(
.simpleFunction("MAX", [value1.sqlExpression, value2.sqlExpression] + values.map(\.sqlExpression))
}
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// The `MAX` SQL aggregate function.
///
/// For example:
@@ -224,7 +224,7 @@ public func min(
.simpleFunction("MIN", [value1.sqlExpression, value2.sqlExpression] + values.map(\.sqlExpression))
}
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// The `MIN` SQL aggregate function.
///
/// For example:
@@ -269,7 +269,7 @@ public func min(_ value: some SQLSpecificExpressible) -> SQLExpression {
}
#endif
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// The `SUM` SQL aggregate function.
///
/// For example:
@@ -333,7 +333,7 @@ public func sum(_ value: some SQLSpecificExpressible) -> SQLExpression {
}
#endif
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// The `TOTAL` SQL aggregate function.
///
/// For example:
@@ -120,7 +120,7 @@ struct SQLTableGenerator {
var tableOptions: [String] = []
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
if options.contains(.strict) {
tableOptions.append("STRICT")
}
@@ -350,7 +350,7 @@ public final class ColumnDefinition {
return self
}
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Defines the column as a generated column.
///
/// For example:
@@ -79,7 +79,7 @@ public final class TableAlteration {
alterations.append(.addColumnLiteral(literal))
}
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Renames a column.
///
/// For example:
@@ -15,7 +15,7 @@ public struct TableOptions: OptionSet, Sendable {
/// Such tables can not be tracked with <doc:DatabaseObservation> tools.
public static let withoutRowID = TableOptions(rawValue: 1 << 2)
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Creates a [STRICT](https://www.sqlite.org/stricttables.html) table.
public static let strict = TableOptions(rawValue: 1 << 3)
#else
+8 -9
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import Foundation
@@ -519,20 +522,16 @@ private struct SingleValueRowDecoder<R: FetchableRecord>: SingleValueDecodingCon
func decode(_ type: Int16.Type) throws -> Int16 { try columnDecoder.decode(type) }
func decode(_ type: Int32.Type) throws -> Int32 { try columnDecoder.decode(type) }
func decode(_ type: Int64.Type) throws -> Int64 { try columnDecoder.decode(type) }
#if compiler(>=6)
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
func decode(_ type: Int128.Type) throws -> Int128 { try columnDecoder.decode(type) }
#endif
func decode(_ type: UInt.Type) throws -> UInt { try columnDecoder.decode(type) }
func decode(_ type: UInt8.Type) throws -> UInt8 { try columnDecoder.decode(type) }
func decode(_ type: UInt16.Type) throws -> UInt16 { try columnDecoder.decode(type) }
func decode(_ type: UInt32.Type) throws -> UInt32 { try columnDecoder.decode(type) }
func decode(_ type: UInt64.Type) throws -> UInt64 { try columnDecoder.decode(type) }
#if compiler(>=6)
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
func decode(_ type: UInt128.Type) throws -> UInt128 { try columnDecoder.decode(type) }
#endif
func decode<T>(_ type: T.Type) throws -> T where T: Decodable {
if let type = T.self as? any FetchableRecord.Type {
// Prefer FetchableRecord decoding over Decodable.
@@ -53,8 +53,10 @@ extension MutablePersistableRecord {
// Nil primary key
return false
}
let prevCount = db.totalChangesCount
try statement.execute()
return (db.totalChangesCount - prevCount) > 0
var changesCount = 0
try db.countChanges(&changesCount, forTable: type(of: self).databaseTableName) {
try statement.execute()
}
return changesCount > 0
}
}
@@ -90,7 +90,7 @@ extension MutablePersistableRecord {
// MARK: - Insert and Fetch
extension MutablePersistableRecord {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Executes an `INSERT RETURNING` statement, and returns a new record built
/// from the inserted row.
///
@@ -86,7 +86,7 @@ extension MutablePersistableRecord {
// MARK: - Save and Fetch
extension MutablePersistableRecord {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Executes an `INSERT RETURNING` or `UPDATE RETURNING` statement, and
/// returns a new record built from the saved row.
///
@@ -213,7 +213,7 @@ extension MutablePersistableRecord {
// MARK: - Update and Fetch
extension MutablePersistableRecord {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Executes an `UPDATE RETURNING` statement on all columns, and returns a
/// new record built from the updated row.
///
@@ -839,7 +839,7 @@ extension MutablePersistableRecord {
// MARK: - Internals
extension MutablePersistableRecord {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
@inlinable // allow specialization so that empty callbacks are removed
func updateChangesAndFetch<T>(
_ db: Database,
@@ -956,9 +956,10 @@ extension MutablePersistableRecord {
// Nil primary key
try dao.recordNotFound()
}
let prevCount = db.totalChangesCount
let returned = try fetch(statement)
let changesCount = db.totalChangesCount - prevCount
var changesCount = 0
let returned = try db.countChanges(&changesCount, forTable: type(of: self).databaseTableName) {
try fetch(statement)
}
if changesCount == 0 {
// No row was updated
try dao.recordNotFound()
@@ -1,7 +1,7 @@
// MARK: - Upsert
extension MutablePersistableRecord {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Executes an `INSERT ON CONFLICT DO UPDATE` statement.
///
/// The upsert behavior is triggered by a violation of any uniqueness
+1 -1
View File
@@ -55,7 +55,7 @@ extension PersistableRecord {
// MARK: - Insert and Fetch
extension PersistableRecord {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Executes an `INSERT RETURNING` statement, and returns a new record built
/// from the inserted row.
///
+1 -1
View File
@@ -38,7 +38,7 @@ extension PersistableRecord {
// MARK: - Save and Fetch
extension PersistableRecord {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Executes an `INSERT RETURNING` or `UPDATE RETURNING` statement, and
/// returns a new record built from the saved row.
///
+1 -1
View File
@@ -1,7 +1,7 @@
// MARK: - Upsert
extension PersistableRecord {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Executes an `INSERT ON CONFLICT DO UPDATE` statement.
///
/// The upsert behavior is triggered by a violation of any uniqueness
@@ -276,7 +276,7 @@ extension ValueConcurrentObserver {
}
}
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
extension ValueConcurrentObserver {
/// Synchronously starts the observation, and returns the initial value.
///
+25 -2
View File
@@ -1,11 +1,28 @@
// swift-tools-version:6.0
// swift-tools-version:6.1
// The swift-tools-version declares the minimum version of Swift required to build this package.
import Foundation
import PackageDescription
let darwinPlatforms: [Platform] = [
.iOS,
.macOS,
.macCatalyst,
.tvOS,
.visionOS,
.watchOS,
]
var swiftSettings: [SwiftSetting] = [
.define("SQLITE_ENABLE_FTS5"),
// Until Xcode has proper support for package traits, we must enable
// SQLITE_ENABLE_SNAPSHOT by default so that Xcode projects that build
// a Darwin app can depend on GRDB and profit from WAL snapshots.
// Package traits who want to disable snapshots must set SQLITE_DISABLE_SNAPSHOT.
// TODO: when Xcode support traits, remove all mentions of SQLITE_DISABLE_SNAPSHOT and update as below:
// .define("SQLITE_ENABLE_SNAPSHOT", .when(platforms: darwinPlatforms, traits: ["GRDBSQLite"])),
.define("SQLITE_ENABLE_SNAPSHOT"),
// Not all Linux distributions have support for WAL snapshots.
.define("SQLITE_DISABLE_SNAPSHOT", .when(platforms: [.linux])),
]
var cSettings: [CSetting] = []
var dependencies: [PackageDescription.Package.Dependency] = []
@@ -41,6 +58,10 @@ let package = Package(
.library(name: "GRDB", targets: ["GRDB"]),
.library(name: "GRDB-dynamic", type: .dynamic, targets: ["GRDB"]),
],
traits: [
"GRDBSQLite",
.default(enabledTraits: ["GRDBSQLite"]),
],
dependencies: dependencies,
targets: [
.systemLibrary(
@@ -48,7 +69,9 @@ let package = Package(
providers: [.apt(["libsqlite3-dev"])]),
.target(
name: "GRDB",
dependencies: ["GRDBSQLite"],
dependencies: [
.target(name: "GRDBSQLite", condition: .when(traits: ["GRDBSQLite"])),
],
path: "GRDB",
resources: [.copy("PrivacyInfo.xcprivacy")],
cSettings: cSettings,
+3 -3
View File
@@ -10,7 +10,7 @@
</p>
<p align="center">
<a href="https://developer.apple.com/swift/"><img alt="Swift 6" src="https://img.shields.io/badge/swift-6-orange.svg?style=flat"></a>
<a href="https://developer.apple.com/swift/"><img alt="Swift 6.1" src="https://img.shields.io/badge/swift-6.1-orange.svg?style=flat"></a>
<a href="https://github.com/groue/GRDB.swift/blob/master/LICENSE"><img alt="License" src="https://img.shields.io/github/license/groue/GRDB.swift.svg?maxAge=2592000"></a>
<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>
@@ -25,9 +25,9 @@
---
**Latest release**: September 23, 2025 • [version 7.7.0](https://github.com/groue/GRDB.swift/tree/v7.7.0) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 6 to GRDB 7](Documentation/GRDB7MigrationGuide.md)
**Latest release**: October 2, 2025 • [version 7.8.0](https://github.com/groue/GRDB.swift/tree/v7.8.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+ &bull; SQLite 3.20.0+ &bull; Swift 6+ / Xcode 16+
**Requirements**: iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 7.0+ &bull; SQLite 3.20.0+ &bull; Swift 6.1+ / Xcode 16.3+
**Contact**:
+1 -1
View File
@@ -13,4 +13,4 @@ OTHER_CFLAGS = -DUSING_BUILTIN_SQLITE -DGRDBCUSTOMSQLITE $(CUSTOM_SQLLIBRARY_CFL
GCC_PREPROCESSOR_DEFINITIONS = "GRDBCUSTOMSQLITE=1"
OTHER_SWIFT_FLAGS = -D USING_BUILTIN_SQLITE -D GRDBCUSTOMSQLITE $(CUSTOM_OTHER_SWIFT_FLAGS)
HEADER_SEARCH_PATHS = $(SRCROOT)/SQLiteCustom/src
SWIFT_VERSION = 6.0
SWIFT_VERSION = 6.1
+2 -1
View File
@@ -3,7 +3,8 @@ INFOPLIST_FILE = Support/Info.plist
PRODUCT_NAME = GRDB
PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.$(PRODUCT_NAME:rfc1034identifier)
MODULEMAP_FILE = $(SRCROOT)/Support/module.modulemap
SWIFT_VERSION = 6.0
SWIFT_VERSION = 6.1
OTHER_SWIFT_FLAGS = $(inherited) -D GRDBFRAMEWORK
// Slow compilation hunt:
// OTHER_SWIFT_FLAGS = $(inherited) -Xfrontend -warn-long-expression-type-checking=100 -Xfrontend -warn-long-function-bodies=100
+1 -1
View File
@@ -2,7 +2,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 13.0
MACOSX_DEPLOYMENT_TARGET = 10.15
TVOS_DEPLOYMENT_TARGET = 13.0
WATCHOS_DEPLOYMENT_TARGET = 7.0
OTHER_SWIFT_FLAGS = $(inherited) -D SQLITE_ENABLE_FTS5
OTHER_SWIFT_FLAGS = $(inherited) -D SQLITE_ENABLE_FTS5 -D SQLITE_ENABLE_SNAPSHOT
//// Compile with all opt-in APIs
//GCC_PREPROCESSOR_DEFINITIONS = $(inherited) GRDB_SQLITE_ENABLE_PREUPDATE_HOOK=1
+1
View File
@@ -2,4 +2,5 @@
// Tests still use the Swift 5 language mode.
SWIFT_UPCOMING_FEATURE_INFER_SENDABLE_FROM_CAPTURES = YES
OTHER_SWIFT_FLAGS = $(inherited) -D GRDBFRAMEWORK
OTHER_SWIFT_FLAGS = $(inherited) -enable-upcoming-feature GlobalActorIsolatedTypesUsability
+1 -1
View File
@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>7.7.0</string>
<string>7.8.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
@@ -40,7 +40,7 @@ class DatabaseReaderReadPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabaseQueue(path: $0)) }
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)) }
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)).makeSnapshot() }
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)).makeSnapshotPool() }
#endif
}
@@ -141,7 +141,7 @@ class DatabaseReaderReadPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0).makeSnapshot() }
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0).makeSnapshotPool() }
#endif
}
@@ -177,7 +177,7 @@ class DatabaseReaderReadPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabaseQueue(path: $0)) }
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)) }
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)).makeSnapshot() }
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)).makeSnapshotPool() }
#endif
}
@@ -213,7 +213,7 @@ class DatabaseReaderReadPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabaseQueue(path: $0)) }
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)) }
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)).makeSnapshot() }
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)).makeSnapshotPool() }
#endif
}
@@ -250,7 +250,7 @@ class DatabaseReaderReadPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabaseQueue(path: $0)) }
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)) }
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)).makeSnapshot() }
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)).makeSnapshotPool() }
#endif
}
@@ -274,7 +274,7 @@ class DatabaseReaderReadPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0).makeSnapshot() }
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0).makeSnapshotPool() }
#endif
}
@@ -122,7 +122,6 @@ class AssociationAggregateTests: GRDBTestCase {
}
}
#if compiler(>=6.1)
func testAggregateWithGroup_swift61() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.read { db in
@@ -139,7 +138,6 @@ class AssociationAggregateTests: GRDBTestCase {
""")
}
}
#endif
func testAnnotatedWithHasManyDefaultAverage() throws {
let dbQueue = try makeDatabaseQueue()
@@ -296,7 +294,6 @@ class AssociationAggregateTests: GRDBTestCase {
}
}
#if compiler(>=6.1)
func testAnnotatedWithHasManyDefaultMax_Swift61() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.read { db in
@@ -333,7 +330,6 @@ class AssociationAggregateTests: GRDBTestCase {
XCTAssertEqual(teamInfos[3].maxPlayerScore, 0)
}
}
#endif
func testAnnotatedWithHasManyDefaultMaxJoiningRequired() throws {
// It is important to have an explicit test for this technique because
@@ -53,14 +53,12 @@ private extension QueryInterfaceRequest<Player> {
.order { [teamAlias[Team.Columns.name], $0.name] }
}
#if compiler(>=6.1)
func orderedByTeamName_swift61() -> QueryInterfaceRequest<Player> {
let teamAlias = TableAlias<Team>()
return self
.joining(optional: PlayerWithOptionalTeam.team.aliased(teamAlias))
.order { [teamAlias.name, $0.name] }
}
#endif
}
/// Test support for Decodable records
@@ -190,7 +188,6 @@ class AssociationBelongsToDecodableRecordTests: GRDBTestCase {
XCTAssertEqual(records[0].team.name, "Reds")
}
#if compiler(>=6.1)
func testRequestRefining_swift61() throws {
let dbQueue = try makeDatabaseQueue()
let request = Player
@@ -212,5 +209,4 @@ class AssociationBelongsToDecodableRecordTests: GRDBTestCase {
XCTAssertEqual(records[0].team.id, 1)
XCTAssertEqual(records[0].team.name, "Reds")
}
#endif
}
@@ -119,7 +119,6 @@ class AssociationBelongsToSQLDerivationTests: GRDBTestCase {
JOIN "b" ON "b"."id" = "a"."bid"
""")
}
#if compiler(>=6.1)
do {
let aAlias = TableAlias<A>()
let request = A
@@ -135,7 +134,6 @@ class AssociationBelongsToSQLDerivationTests: GRDBTestCase {
JOIN "b" ON "b"."id" = "a"."bid"
""")
}
#endif
}
}
@@ -178,7 +176,6 @@ class AssociationBelongsToSQLDerivationTests: GRDBTestCase {
JOIN "b" ON ("b"."id" = "a"."bid") AND ("b"."id" IN ("a"."id", "b"."id", 42))
""")
}
#if compiler(>=6.1)
do {
let alias = TableAlias<A>()
let request = A
@@ -191,7 +188,6 @@ class AssociationBelongsToSQLDerivationTests: GRDBTestCase {
JOIN "b" ON ("b"."id" = "a"."bid") AND ("b"."id" IN ("a"."id", "b"."id", 42))
""")
}
#endif
do {
let request = A.including(required: A.b.filter(key: ["id": 1]))
try assertEqualSQL(db, request, """
@@ -237,7 +233,6 @@ class AssociationBelongsToSQLDerivationTests: GRDBTestCase {
WHERE "b"."name" IS NOT NULL
""")
}
#if compiler(>=6.1)
do {
let bAlias = TableAlias<B>()
let request = A
@@ -250,7 +245,6 @@ class AssociationBelongsToSQLDerivationTests: GRDBTestCase {
WHERE "b"."name" IS NOT NULL
""")
}
#endif
}
}
@@ -119,7 +119,6 @@ class AssociationHasOneSQLDerivationTests: GRDBTestCase {
JOIN "b" ON "b"."aid" = "a"."id"
""")
}
#if compiler(>=6.1)
do {
let aAlias = TableAlias<A>()
let request = A
@@ -135,7 +134,6 @@ class AssociationHasOneSQLDerivationTests: GRDBTestCase {
JOIN "b" ON "b"."aid" = "a"."id"
""")
}
#endif
}
}
@@ -211,7 +209,6 @@ class AssociationHasOneSQLDerivationTests: GRDBTestCase {
WHERE "b"."name" IS NOT NULL
""")
}
#if compiler(>=6.1)
do {
let bAlias = TableAlias<B>()
let request = A
@@ -224,7 +221,6 @@ class AssociationHasOneSQLDerivationTests: GRDBTestCase {
WHERE "b"."name" IS NOT NULL
""")
}
#endif
}
}
@@ -138,7 +138,6 @@ class AssociationHasOneThroughSQLDerivationTests: GRDBTestCase {
JOIN "c" ON "c"."id" = "b"."cId"
""")
}
#if compiler(>=6.1)
do {
let aAlias = TableAlias<A>()
let request = A
@@ -155,7 +154,6 @@ class AssociationHasOneThroughSQLDerivationTests: GRDBTestCase {
JOIN "c" ON "c"."id" = "b"."cId"
""")
}
#endif
}
}
@@ -238,7 +236,6 @@ class AssociationHasOneThroughSQLDerivationTests: GRDBTestCase {
WHERE "c"."name" IS NOT NULL
""")
}
#if compiler(>=6.1)
do {
let cAlias = TableAlias<C>()
let request = A
@@ -252,7 +249,6 @@ class AssociationHasOneThroughSQLDerivationTests: GRDBTestCase {
WHERE "c"."name" IS NOT NULL
""")
}
#endif
}
}
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import XCTest
@@ -130,7 +130,6 @@ class AssociationTableAliasTestsSQLTests : GRDBTestCase {
}
}
#if compiler(>=6.1)
func testTableAliasBasics_swift61() throws {
// A table reference qualifies all unqualified selectables, expressions, and orderings
@@ -208,7 +207,6 @@ class AssociationTableAliasTestsSQLTests : GRDBTestCase {
}
}
}
#endif
func testRecursiveRelationDepth1() throws {
// A.include(A.parent)
+6 -1
View File
@@ -1,7 +1,12 @@
import XCTest
import CoreGraphics
import GRDB
#if canImport(CoreGraphics)
import CoreGraphics
#elseif !canImport(Darwin)
import Foundation
#endif
class CGFloatTests: GRDBTestCase {
func testCGFLoat() throws {
@@ -101,7 +101,6 @@ class CommonTableExpressionTests: GRDBTestCase {
LEFT JOIN "cte" ON "t"."id" > "cte"."id"
""")
}
#if compiler(>=6.1)
do {
let cte = CommonTableExpression<T>(named: "cte", request: T.all())
let request = T.all()
@@ -114,7 +113,6 @@ class CommonTableExpressionTests: GRDBTestCase {
LEFT JOIN "cte" ON "t"."id" > "cte"."id"
""")
}
#endif
// Include SQL request as a CTE
do {
@@ -131,7 +129,6 @@ class CommonTableExpressionTests: GRDBTestCase {
JOIN "cte" ON "t"."id" = "cte"."id"
""")
}
#if compiler(>=6.1)
do {
let cte = CommonTableExpression(
named: "cte",
@@ -146,7 +143,6 @@ class CommonTableExpressionTests: GRDBTestCase {
JOIN "cte" ON "t"."id" = "cte"."id"
""")
}
#endif
// Include a filtered SQL request as a CTE
do {
@@ -180,7 +176,6 @@ class CommonTableExpressionTests: GRDBTestCase {
JOIN "cte" ON "t"."id" = "cte"."id"
""")
}
#if compiler(>=6.1)
do {
let cte = CommonTableExpression(
named: "cte",
@@ -196,7 +191,6 @@ class CommonTableExpressionTests: GRDBTestCase {
JOIN "cte" ON "t"."id" = "cte"."id"
""")
}
#endif
// Include SQL request as a CTE (custom column name)
do {
@@ -214,7 +208,6 @@ class CommonTableExpressionTests: GRDBTestCase {
JOIN "cte" ON "t"."id" = "cte"."id"
""")
}
#if compiler(>=6.1)
do {
let cte = CommonTableExpression(
named: "cte",
@@ -230,7 +223,6 @@ class CommonTableExpressionTests: GRDBTestCase {
JOIN "cte" ON "t"."id" = "cte"."id"
""")
}
#endif
// Include SQL request as a CTE (empty ON clause)
do {
@@ -261,7 +253,6 @@ class CommonTableExpressionTests: GRDBTestCase {
JOIN "cte" ON "t"."id" > "cte"."id"
""")
}
#if compiler(>=6.1)
do {
let cte = CommonTableExpression<T>(named: "cte", request: T.all())
let request = T.all()
@@ -274,7 +265,6 @@ class CommonTableExpressionTests: GRDBTestCase {
JOIN "cte" ON "t"."id" > "cte"."id"
""")
}
#endif
// Include filtered CTE
do {
@@ -336,7 +326,6 @@ class CommonTableExpressionTests: GRDBTestCase {
JOIN "cte" ON "t"."id" > "cte"."id"
""")
}
#if compiler(>=6.1)
do {
let cte = CommonTableExpression<T>(named: "cte", request: T.all())
let request = T.all()
@@ -350,7 +339,6 @@ class CommonTableExpressionTests: GRDBTestCase {
JOIN "cte" ON "t"."id" > "cte"."id"
""")
}
#endif
// Include one CTE twice with same key but different condition (last condition wins)
do {
@@ -366,7 +354,6 @@ class CommonTableExpressionTests: GRDBTestCase {
JOIN "cte" ON ("t"."id" + "cte"."id") = 1
""")
}
#if compiler(>=6.1)
do {
let cte = CommonTableExpression<T>(named: "cte", request: T.all())
let request = T.all()
@@ -380,7 +367,6 @@ class CommonTableExpressionTests: GRDBTestCase {
JOIN "cte" ON ("t"."id" + "cte"."id") = 1
""")
}
#endif
// Include one CTE twice with different keys
do {
@@ -397,7 +383,6 @@ class CommonTableExpressionTests: GRDBTestCase {
JOIN "cte" "cte2" ON "t"."id" < "cte2"."id"
""")
}
#if compiler(>=6.1)
do {
let cte = CommonTableExpression<T>(named: "cte", request: T.all())
let request = T.all()
@@ -412,7 +397,6 @@ class CommonTableExpressionTests: GRDBTestCase {
JOIN "cte" "cte2" ON "t"."id" < "cte2"."id"
""")
}
#endif
// Chain CTE includes
do {
+7 -4
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import XCTest
@@ -40,7 +40,7 @@ class DatabaseAbortedTransactionTests : GRDBTestCase {
try test(makeDatabaseQueue())
try test(makeDatabasePool())
try test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try test(makeDatabasePool().makeSnapshotPool())
#endif
}
@@ -85,7 +85,7 @@ class DatabaseAbortedTransactionTests : GRDBTestCase {
try test(makeDatabaseQueue())
try test(makeDatabasePool())
try test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try test(makeDatabasePool().makeSnapshotPool())
#endif
}
@@ -27,7 +27,7 @@ class DatabaseConfigurationTests: GRDBTestCase {
try pool.makeSnapshot().read { _ in }
XCTAssertEqual(connectionCountMutex.load(), 5)
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try pool.makeSnapshotPool().read { _ in }
XCTAssertEqual(connectionCountMutex.load(), 6)
#endif
@@ -74,7 +74,7 @@ class DatabaseConfigurationTests: GRDBTestCase {
XCTFail("Expected TestError")
} catch is TestError { }
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
do {
errorMutex.store(TestError())
_ = try pool.makeSnapshotPool()
+4
View File
@@ -216,6 +216,9 @@ class DatabaseErrorTests: GRDBTestCase {
}
func testNSErrorBridging() throws {
#if !canImport(Darwin)
throw XCTSkip("NSError bridging not available on non-Darwin platforms")
#else
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "parents") { $0.column("id", .integer).primaryKey() }
@@ -229,5 +232,6 @@ class DatabaseErrorTests: GRDBTestCase {
XCTAssertNotNil(error.localizedFailureReason)
}
}
#endif
}
}
+392
View File
@@ -10,6 +10,9 @@ class DatabaseMigratorTests : GRDBTestCase {
}
func testEmptyMigratorSync() throws {
#if !canImport(Combine)
throw XCTSkip("Combine not supported on this platform")
#else
func test(writer: some DatabaseWriter) throws {
let migrator = DatabaseMigrator()
try migrator.migrate(writer)
@@ -18,9 +21,13 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).run { try DatabaseQueue() }
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
#endif
}
func testEmptyMigratorAsync() throws {
#if !canImport(Combine)
throw XCTSkip("Combine not supported on this platform")
#else
func test(writer: some DatabaseWriter) throws {
let expectation = self.expectation(description: "")
let migrator = DatabaseMigrator()
@@ -38,9 +45,13 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).run { try DatabaseQueue() }
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
#endif
}
func testEmptyMigratorPublisher() throws {
#if !canImport(Combine)
throw XCTSkip("Combine not supported on this platform")
#else
func test(writer: some DatabaseWriter) throws {
let migrator = DatabaseMigrator()
let publisher = migrator.migratePublisher(writer)
@@ -51,9 +62,13 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).run { try DatabaseQueue() }
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
#endif
}
func testNonEmptyMigratorSync() throws {
#if !canImport(Combine)
throw XCTSkip("Combine not supported on this platform")
#else
func test(writer: some DatabaseWriter) throws {
var migrator = DatabaseMigrator()
migrator.registerMigration("createPersons") { db in
@@ -95,9 +110,13 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).run { try DatabaseQueue() }
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
#endif
}
func testNonEmptyMigratorAsync() throws {
#if !canImport(Combine)
throw XCTSkip("Combine not supported on this platform")
#else
func test(writer: some DatabaseWriter) throws {
var migrator = DatabaseMigrator()
migrator.registerMigration("createPersons") { db in
@@ -146,9 +165,13 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).run { try DatabaseQueue() }
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
#endif
}
func testNonEmptyMigratorPublisher() throws {
#if !canImport(Combine)
throw XCTSkip("Combine not supported on this platform")
#else
func test(writer: some DatabaseWriter) throws {
var migrator = DatabaseMigrator()
migrator.registerMigration("createPersons") { db in
@@ -198,9 +221,13 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).run { try DatabaseQueue() }
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
#endif
}
func testEmptyMigratorPublisherIsAsynchronous() throws {
#if !canImport(Combine)
throw XCTSkip("Combine not supported on this platform")
#else
func test(writer: some DatabaseWriter) throws {
let migrator = DatabaseMigrator()
let expectation = self.expectation(description: "")
@@ -220,9 +247,13 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).run { try DatabaseQueue() }
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
#endif
}
func testNonEmptyMigratorPublisherIsAsynchronous() throws {
#if !canImport(Combine)
throw XCTSkip("Combine not supported on this platform")
#else
func test(writer: some DatabaseWriter) throws {
var migrator = DatabaseMigrator()
migrator.registerMigration("first", migrate: { _ in })
@@ -243,9 +274,13 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).run { try DatabaseQueue() }
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
#endif
}
func testMigratorPublisherDefaultScheduler() throws {
#if !canImport(Combine)
throw XCTSkip("Combine not supported on this platform")
#else
func test<Writer: DatabaseWriter>(writer: Writer) {
var migrator = DatabaseMigrator()
migrator.registerMigration("first", migrate: { _ in })
@@ -268,9 +303,13 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).run { try DatabaseQueue() }
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
#endif
}
func testMigratorPublisherCustomScheduler() throws {
#if !canImport(Combine)
throw XCTSkip("Combine not supported on this platform")
#else
func test<Writer: DatabaseWriter>(writer: Writer) {
var migrator = DatabaseMigrator()
migrator.registerMigration("first", migrate: { _ in })
@@ -294,9 +333,13 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).run { try DatabaseQueue() }
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
#endif
}
func testMigrateUpTo() throws {
#if !canImport(Combine)
throw XCTSkip("Combine not supported on this platform")
#else
func test(writer: some DatabaseWriter) throws {
var migrator = DatabaseMigrator()
migrator.registerMigration("a") { db in
@@ -345,6 +388,7 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).run { try DatabaseQueue() }
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
#endif
}
func testMigrationFailureTriggersRollback() throws {
@@ -1166,4 +1210,352 @@ class DatabaseMigratorTests : GRDBTestCase {
}
try migrator.migrate(dbQueue)
}
func test_merged_migrations_named_like_the_last() throws {
// Original migrator
var oldMigrator = DatabaseMigrator()
oldMigrator.registerMigration("v1") { db in
try db.execute(sql: "CREATE TABLE t1(a)")
}
oldMigrator.registerMigration("v2") { db in
try db.execute(sql: "CREATE TABLE t2(a)")
}
oldMigrator.registerMigration("v3") { db in
try db.execute(sql: "CREATE TABLE t3(a)")
}
oldMigrator.registerMigration("v4") { db in
try db.execute(sql: "CREATE TABLE t4(a)")
}
oldMigrator.registerMigration("v5") { db in
try db.execute(sql: "CREATE TABLE t5(a)")
}
// New migrator merges v2, v3, and v4 into v4
var newMigrator = DatabaseMigrator()
newMigrator.registerMigration("v1") { db in
try db.execute(sql: "CREATE TABLE t1(a)")
}
newMigrator.registerMigration("v4", merging: ["v2", "v3"]) { db, appliedIDs in
if !appliedIDs.contains("v2") {
try db.execute(sql: "CREATE TABLE t2(a)")
}
if !appliedIDs.contains("v3") {
try db.execute(sql: "CREATE TABLE t3(a)")
}
try db.execute(sql: "CREATE TABLE t4(a)")
}
newMigrator.registerMigration("v5") { db in
try db.execute(sql: "CREATE TABLE t5(a)")
}
do {
let dbQueue = try makeDatabaseQueue()
try newMigrator.migrate(dbQueue)
try dbQueue.read { db in
try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4", "v5"])
try XCTAssertTrue(String
.fetchSet(db, sql: "SELECT name FROM sqlite_master")
.isSuperset(of: ["t1", "t2", "t3", "t4", "t5"]))
}
}
do {
let dbQueue = try makeDatabaseQueue()
try oldMigrator.migrate(dbQueue, upTo: "v1")
try newMigrator.migrate(dbQueue)
try dbQueue.read { db in
try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4", "v5"])
try XCTAssertTrue(String
.fetchSet(db, sql: "SELECT name FROM sqlite_master")
.isSuperset(of: ["t1", "t2", "t3", "t4", "t5"]))
}
}
do {
let dbQueue = try makeDatabaseQueue()
try oldMigrator.migrate(dbQueue, upTo: "v2")
try newMigrator.migrate(dbQueue)
try dbQueue.read { db in
try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4", "v5"])
try XCTAssertTrue(String
.fetchSet(db, sql: "SELECT name FROM sqlite_master")
.isSuperset(of: ["t1", "t2", "t3", "t4", "t5"]))
}
}
do {
let dbQueue = try makeDatabaseQueue()
try oldMigrator.migrate(dbQueue, upTo: "v3")
try newMigrator.migrate(dbQueue)
try dbQueue.read { db in
try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4", "v5"])
try XCTAssertTrue(String
.fetchSet(db, sql: "SELECT name FROM sqlite_master")
.isSuperset(of: ["t1", "t2", "t3", "t4", "t5"]))
}
}
do {
let dbQueue = try makeDatabaseQueue()
try oldMigrator.migrate(dbQueue, upTo: "v4")
try newMigrator.migrate(dbQueue)
try dbQueue.read { db in
try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4", "v5"])
try XCTAssertTrue(String
.fetchSet(db, sql: "SELECT name FROM sqlite_master")
.isSuperset(of: ["t1", "t2", "t3", "t4", "t5"]))
}
}
do {
let dbQueue = try makeDatabaseQueue()
try oldMigrator.migrate(dbQueue, upTo: "v5")
try newMigrator.migrate(dbQueue)
try dbQueue.read { db in
try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4", "v5"])
try XCTAssertTrue(String
.fetchSet(db, sql: "SELECT name FROM sqlite_master")
.isSuperset(of: ["t1", "t2", "t3", "t4", "t5"]))
}
}
}
func test_merged_migrations_named_like_the_last_that_includes_itself_in_the_list_of_merged_migrations() throws {
// Original migrator
var oldMigrator = DatabaseMigrator()
oldMigrator.registerMigration("v1") { db in
try db.execute(sql: "CREATE TABLE t1(a)")
}
oldMigrator.registerMigration("v2") { db in
try db.execute(sql: "CREATE TABLE t2(a)")
}
oldMigrator.registerMigration("v3") { db in
try db.execute(sql: "CREATE TABLE t3(a)")
}
oldMigrator.registerMigration("v4") { db in
try db.execute(sql: "CREATE TABLE t4(a)")
}
oldMigrator.registerMigration("v5") { db in
try db.execute(sql: "CREATE TABLE t5(a)")
}
// New migrator merges v2, v3, and v4 into v4
var newMigrator = DatabaseMigrator()
newMigrator.registerMigration("v1") { db in
try db.execute(sql: "CREATE TABLE t1(a)")
}
// SUT: the migration identifier is included in the list of merged identifiers.
newMigrator.registerMigration("v4", merging: ["v2", "v3", "v4"]) { db, appliedIDs in
if !appliedIDs.contains("v2") {
try db.execute(sql: "CREATE TABLE t2(a)")
}
if !appliedIDs.contains("v3") {
try db.execute(sql: "CREATE TABLE t3(a)")
}
try db.execute(sql: "CREATE TABLE t4(a)")
}
newMigrator.registerMigration("v5") { db in
try db.execute(sql: "CREATE TABLE t5(a)")
}
do {
let dbQueue = try makeDatabaseQueue()
try newMigrator.migrate(dbQueue)
try dbQueue.read { db in
try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4", "v5"])
try XCTAssertTrue(String
.fetchSet(db, sql: "SELECT name FROM sqlite_master")
.isSuperset(of: ["t1", "t2", "t3", "t4", "t5"]))
}
}
do {
let dbQueue = try makeDatabaseQueue()
try oldMigrator.migrate(dbQueue, upTo: "v1")
try newMigrator.migrate(dbQueue)
try dbQueue.read { db in
try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4", "v5"])
try XCTAssertTrue(String
.fetchSet(db, sql: "SELECT name FROM sqlite_master")
.isSuperset(of: ["t1", "t2", "t3", "t4", "t5"]))
}
}
do {
let dbQueue = try makeDatabaseQueue()
try oldMigrator.migrate(dbQueue, upTo: "v2")
try newMigrator.migrate(dbQueue)
try dbQueue.read { db in
try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4", "v5"])
try XCTAssertTrue(String
.fetchSet(db, sql: "SELECT name FROM sqlite_master")
.isSuperset(of: ["t1", "t2", "t3", "t4", "t5"]))
}
}
do {
let dbQueue = try makeDatabaseQueue()
try oldMigrator.migrate(dbQueue, upTo: "v3")
try newMigrator.migrate(dbQueue)
try dbQueue.read { db in
try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4", "v5"])
try XCTAssertTrue(String
.fetchSet(db, sql: "SELECT name FROM sqlite_master")
.isSuperset(of: ["t1", "t2", "t3", "t4", "t5"]))
}
}
do {
let dbQueue = try makeDatabaseQueue()
try oldMigrator.migrate(dbQueue, upTo: "v4")
try newMigrator.migrate(dbQueue)
try dbQueue.read { db in
try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4", "v5"])
try XCTAssertTrue(String
.fetchSet(db, sql: "SELECT name FROM sqlite_master")
.isSuperset(of: ["t1", "t2", "t3", "t4", "t5"]))
}
}
do {
let dbQueue = try makeDatabaseQueue()
try oldMigrator.migrate(dbQueue, upTo: "v5")
try newMigrator.migrate(dbQueue)
try dbQueue.read { db in
try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4", "v5"])
try XCTAssertTrue(String
.fetchSet(db, sql: "SELECT name FROM sqlite_master")
.isSuperset(of: ["t1", "t2", "t3", "t4", "t5"]))
}
}
}
func test_merged_migrations_with_a_new_name() throws {
// Original migrator
var oldMigrator = DatabaseMigrator()
oldMigrator.registerMigration("v1") { db in
try db.execute(sql: "CREATE TABLE t1(a)")
}
oldMigrator.registerMigration("v2") { db in
try db.execute(sql: "CREATE TABLE t2(a)")
}
oldMigrator.registerMigration("v3") { db in
try db.execute(sql: "CREATE TABLE t3(a)")
}
oldMigrator.registerMigration("v4") { db in
try db.execute(sql: "CREATE TABLE t4(a)")
}
oldMigrator.registerMigration("v5") { db in
try db.execute(sql: "CREATE TABLE t5(a)")
}
// New migrator merges v2, v3, and v4 into v4bis
var newMigrator = DatabaseMigrator()
newMigrator.registerMigration("v1") { db in
try db.execute(sql: "CREATE TABLE t1(a)")
}
newMigrator.registerMigration("v4bis", merging: ["v2", "v3", "v4"]) { db, appliedIDs in
if !appliedIDs.contains("v2") {
try db.execute(sql: "CREATE TABLE t2(a)")
}
if !appliedIDs.contains("v3") {
try db.execute(sql: "CREATE TABLE t3(a)")
}
if !appliedIDs.contains("v4") {
try db.execute(sql: "CREATE TABLE t4(a)")
}
}
newMigrator.registerMigration("v5") { db in
try db.execute(sql: "CREATE TABLE t5(a)")
}
do {
let dbQueue = try makeDatabaseQueue()
try newMigrator.migrate(dbQueue)
try dbQueue.read { db in
try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4bis", "v5"])
try XCTAssertTrue(String
.fetchSet(db, sql: "SELECT name FROM sqlite_master")
.isSuperset(of: ["t1", "t2", "t3", "t4", "t5"]))
}
}
do {
let dbQueue = try makeDatabaseQueue()
try oldMigrator.migrate(dbQueue, upTo: "v1")
try newMigrator.migrate(dbQueue)
try dbQueue.read { db in
try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4bis", "v5"])
try XCTAssertTrue(String
.fetchSet(db, sql: "SELECT name FROM sqlite_master")
.isSuperset(of: ["t1", "t2", "t3", "t4", "t5"]))
}
}
do {
let dbQueue = try makeDatabaseQueue()
try oldMigrator.migrate(dbQueue, upTo: "v2")
try newMigrator.migrate(dbQueue)
try dbQueue.read { db in
try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4bis", "v5"])
try XCTAssertTrue(String
.fetchSet(db, sql: "SELECT name FROM sqlite_master")
.isSuperset(of: ["t1", "t2", "t3", "t4", "t5"]))
}
}
do {
let dbQueue = try makeDatabaseQueue()
try oldMigrator.migrate(dbQueue, upTo: "v3")
try newMigrator.migrate(dbQueue)
try dbQueue.read { db in
try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4bis", "v5"])
try XCTAssertTrue(String
.fetchSet(db, sql: "SELECT name FROM sqlite_master")
.isSuperset(of: ["t1", "t2", "t3", "t4", "t5"]))
}
}
do {
let dbQueue = try makeDatabaseQueue()
try oldMigrator.migrate(dbQueue, upTo: "v4")
try newMigrator.migrate(dbQueue)
try dbQueue.read { db in
try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4bis", "v5"])
try XCTAssertTrue(String
.fetchSet(db, sql: "SELECT name FROM sqlite_master")
.isSuperset(of: ["t1", "t2", "t3", "t4", "t5"]))
}
}
do {
let dbQueue = try makeDatabaseQueue()
try oldMigrator.migrate(dbQueue, upTo: "v5")
try newMigrator.migrate(dbQueue)
try dbQueue.read { db in
try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4bis", "v5"])
try XCTAssertTrue(String
.fetchSet(db, sql: "SELECT name FROM sqlite_master")
.isSuperset(of: ["t1", "t2", "t3", "t4", "t5"]))
}
}
}
}
@@ -877,10 +877,12 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
XCTAssertEqual(db.configuration.label, nil)
XCTAssertEqual(db.description, "GRDB.DatabasePool.writer")
#if canImport(Darwin)
// This test CAN break in future releases: the dispatch queue labels
// are documented to be a debug-only tool.
let label = String(utf8String: __dispatch_queue_get_label(nil))
XCTAssertEqual(label, "GRDB.DatabasePool.writer")
#endif
}
let s1 = DispatchSemaphore(value: 0)
@@ -890,10 +892,12 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
XCTAssertEqual(db.configuration.label, nil)
XCTAssertEqual(db.description, "GRDB.DatabasePool.reader.1")
#if canImport(Darwin)
// This test CAN break in future releases: the dispatch queue labels
// are documented to be a debug-only tool.
let label = String(utf8String: __dispatch_queue_get_label(nil))
XCTAssertEqual(label, "GRDB.DatabasePool.reader.1")
#endif
_ = s1.signal()
_ = s2.wait(timeout: .distantFuture)
@@ -906,10 +910,12 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
XCTAssertEqual(db.configuration.label, nil)
XCTAssertEqual(db.description, "GRDB.DatabasePool.reader.2")
#if canImport(Darwin)
// This test CAN break in future releases: the dispatch queue labels
// are documented to be a debug-only tool.
let label = String(utf8String: __dispatch_queue_get_label(nil))
XCTAssertEqual(label, "GRDB.DatabasePool.reader.2")
#endif
}
}
let blocks = [block1, block2]
@@ -925,10 +931,12 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
XCTAssertEqual(db.configuration.label, "Toreador")
XCTAssertEqual(db.description, "Toreador.writer")
#if canImport(Darwin)
// This test CAN break in future releases: the dispatch queue labels
// are documented to be a debug-only tool.
let label = String(utf8String: __dispatch_queue_get_label(nil))
XCTAssertEqual(label, "Toreador.writer")
#endif
}
let s1 = DispatchSemaphore(value: 0)
@@ -938,10 +946,12 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
XCTAssertEqual(db.configuration.label, "Toreador")
XCTAssertEqual(db.description, "Toreador.reader.1")
#if canImport(Darwin)
// This test CAN break in future releases: the dispatch queue labels
// are documented to be a debug-only tool.
let label = String(utf8String: __dispatch_queue_get_label(nil))
XCTAssertEqual(label, "Toreador.reader.1")
#endif
_ = s1.signal()
_ = s2.wait(timeout: .distantFuture)
@@ -954,10 +964,12 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
XCTAssertEqual(db.configuration.label, "Toreador")
XCTAssertEqual(db.description, "Toreador.reader.2")
#if canImport(Darwin)
// This test CAN break in future releases: the dispatch queue labels
// are documented to be a debug-only tool.
let label = String(utf8String: __dispatch_queue_get_label(nil))
XCTAssertEqual(label, "Toreador.reader.2")
#endif
}
}
let blocks = [block1, block2]
@@ -1037,6 +1049,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
}
func testQoS() throws {
#if !canImport(Darwin)
throw XCTSkip("__dispatch_get_global_queue unavailable")
#else
func test(qos: DispatchQoS) throws {
// https://forums.swift.org/t/what-is-the-default-target-queue-for-a-serial-queue/18094/5
//
@@ -1072,6 +1087,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
try test(qos: .background)
try test(qos: .userInitiated)
#endif
}
// MARK: - AsyncConcurrentRead
@@ -1254,6 +1270,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
// MARK: - Concurrent opening
func testConcurrentOpening() throws {
#if !canImport(Darwin)
throw XCTSkip("NSFileCoordinator unavailable")
#else
for _ in 0..<50 {
let dbDirectoryName = "DatabasePoolConcurrencyTests-\(ProcessInfo.processInfo.globallyUniqueString)"
let directoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
@@ -1277,6 +1296,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
XCTAssert(poolError ?? coordinatorError == nil)
}
}
#endif
}
// MARK: - NSFileCoordinator sample code tests
@@ -1284,6 +1304,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
// Test for sample code in Documentation.docc/DatabaseSharing.md.
// This test passes if this method compiles
private func openSharedDatabase(at databaseURL: URL) throws -> DatabasePool {
#if !canImport(Darwin)
throw XCTSkip("NSFileCoordinator unavailable")
#else
let coordinator = NSFileCoordinator(filePresenter: nil)
var coordinatorError: NSError?
var dbPool: DatabasePool?
@@ -1299,6 +1322,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
throw error
}
return dbPool!
#endif
}
// Test for sample code in Documentation.docc/DatabaseSharing.md.
@@ -1313,6 +1337,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
// Test for sample code in Documentation.docc/DatabaseSharing.md.
// This test passes if this method compiles
private func openSharedReadOnlyDatabase(at databaseURL: URL) throws -> DatabasePool? {
#if !canImport(Darwin)
throw XCTSkip("NSFileCoordinator unavailable")
#else
let coordinator = NSFileCoordinator(filePresenter: nil)
var coordinatorError: NSError?
var dbPool: DatabasePool?
@@ -1328,6 +1355,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
throw error
}
return dbPool
#endif
}
// Test for sample code in Documentation.docc/DatabaseSharing.md.
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import XCTest
+11 -8
View File
@@ -1,10 +1,13 @@
// Import C SQLite functions
#if SWIFT_PACKAGE
import GRDBSQLite
#elseif GRDBCIPHER
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
#elseif GRDBFRAMEWORK // GRDB.xcodeproj or CocoaPods (standard subspec)
import SQLite3
#elseif GRDBCUSTOMSQLITE // GRDBCustom Framework
// #elseif SomeTrait
// import ...
#else // Default SPM trait must be the default. It impossible to detect from Xcode.
import GRDBSQLite
#endif
import XCTest
@@ -50,7 +53,7 @@ class DatabasePoolTests: GRDBTestCase {
XCTAssertTrue(fm.fileExists(atPath: dbPool.path + "-wal"))
XCTAssertTrue(fm.fileExists(atPath: dbPool.path + "-shm"))
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
// A non-empty wal file makes sure ValueObservation can use wal snapshots.
// See <https://github.com/groue/GRDB.swift/issues/1383>
let walURL = URL(fileURLWithPath: dbPool.path + "-wal")
@@ -74,7 +77,7 @@ class DatabasePoolTests: GRDBTestCase {
XCTAssertTrue(fm.fileExists(atPath: dbPool.path + "-wal"))
XCTAssertTrue(fm.fileExists(atPath: dbPool.path + "-shm"))
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
// A non-empty wal file makes sure ValueObservation can use wal snapshots.
// See <https://github.com/groue/GRDB.swift/issues/1383>
let walURL = URL(fileURLWithPath: dbPool.path + "-wal")
@@ -100,7 +103,7 @@ class DatabasePoolTests: GRDBTestCase {
XCTAssertTrue(fm.fileExists(atPath: dbPool.path + "-wal"))
XCTAssertTrue(fm.fileExists(atPath: dbPool.path + "-shm"))
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
// A non-empty wal file makes sure ValueObservation can use wal snapshots.
// See <https://github.com/groue/GRDB.swift/issues/1383>
let walURL = URL(fileURLWithPath: dbPool.path + "-wal")
@@ -123,7 +126,7 @@ class DatabasePoolTests: GRDBTestCase {
XCTAssertTrue(fm.fileExists(atPath: dbPool.path + "-wal"))
XCTAssertTrue(fm.fileExists(atPath: dbPool.path + "-shm"))
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
// A non-empty wal file makes sure ValueObservation can use wal snapshots.
// See <https://github.com/groue/GRDB.swift/issues/1383>
let walURL = URL(fileURLWithPath: dbPool.path + "-wal")
+8
View File
@@ -129,10 +129,12 @@ class DatabaseQueueTests: GRDBTestCase {
XCTAssertEqual(db.configuration.label, nil)
XCTAssertEqual(db.description, "GRDB.DatabaseQueue")
#if canImport(Darwin)
// This test CAN break in future releases: the dispatch queue labels
// are documented to be a debug-only tool.
let label = String(utf8String: __dispatch_queue_get_label(nil))
XCTAssertEqual(label, "GRDB.DatabaseQueue")
#endif
}
}
@@ -144,10 +146,12 @@ class DatabaseQueueTests: GRDBTestCase {
XCTAssertEqual(db.configuration.label, "Toreador")
XCTAssertEqual(db.description, "Toreador")
#if canImport(Darwin)
// This test CAN break in future releases: the dispatch queue labels
// are documented to be a debug-only tool.
let label = String(utf8String: __dispatch_queue_get_label(nil))
XCTAssertEqual(label, "Toreador")
#endif
}
}
@@ -221,6 +225,9 @@ class DatabaseQueueTests: GRDBTestCase {
}
func testQoS() throws {
#if !canImport(Darwin)
throw XCTSkip("__dispatch_get_global_queue not available on non-Darwin platforms")
#else
func test(qos: DispatchQoS) throws {
// https://forums.swift.org/t/what-is-the-default-target-queue-for-a-serial-queue/18094/5
//
@@ -256,6 +263,7 @@ class DatabaseQueueTests: GRDBTestCase {
try test(qos: .background)
try test(qos: .userInitiated)
#endif
}
// MARK: - SQLITE_BUSY prevention
+24 -24
View File
@@ -46,7 +46,7 @@ class DatabaseReaderTests : GRDBTestCase {
try test(setup(makeDatabaseQueue()))
try test(setup(makeDatabasePool()))
try test(setup(makeDatabasePool()).makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try test(setup(makeDatabasePool()).makeSnapshotPool())
#endif
}
@@ -68,7 +68,7 @@ class DatabaseReaderTests : GRDBTestCase {
try await test(setup(makeDatabaseQueue()))
try await test(setup(makeDatabasePool()))
try await test(setup(makeDatabasePool()).makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try await test(setup(makeDatabasePool()).makeSnapshotPool())
#endif
}
@@ -87,7 +87,7 @@ class DatabaseReaderTests : GRDBTestCase {
try test(makeDatabaseQueue())
try test(makeDatabasePool())
try test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try test(makeDatabasePool().makeSnapshotPool())
#endif
}
@@ -106,7 +106,7 @@ class DatabaseReaderTests : GRDBTestCase {
try await test(makeDatabaseQueue())
try await test(makeDatabasePool())
try await test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try await test(makeDatabasePool().makeSnapshotPool())
#endif
}
@@ -130,7 +130,7 @@ class DatabaseReaderTests : GRDBTestCase {
try test(setup(makeDatabaseQueue()))
try test(setup(makeDatabasePool()))
try test(setup(makeDatabasePool()).makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try test(setup(makeDatabasePool()).makeSnapshotPool())
#endif
}
@@ -152,7 +152,7 @@ class DatabaseReaderTests : GRDBTestCase {
try await test(setup(makeDatabaseQueue()))
try await test(setup(makeDatabasePool()))
try await test(setup(makeDatabasePool()).makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try await test(setup(makeDatabasePool()).makeSnapshotPool())
#endif
}
@@ -176,7 +176,7 @@ class DatabaseReaderTests : GRDBTestCase {
try test(setup(makeDatabaseQueue()))
try test(setup(makeDatabasePool()))
try test(setup(makeDatabasePool()).makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try test(setup(makeDatabasePool()).makeSnapshotPool())
#endif
}
@@ -196,7 +196,7 @@ class DatabaseReaderTests : GRDBTestCase {
try test(makeDatabaseQueue())
try test(makeDatabasePool())
try test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try test(makeDatabasePool().makeSnapshotPool())
#endif
}
@@ -243,7 +243,7 @@ class DatabaseReaderTests : GRDBTestCase {
try test(makeDatabaseQueue())
try test(makeDatabasePool())
try test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try test(makeDatabasePool().makeSnapshotPool())
#endif
}
@@ -272,7 +272,7 @@ class DatabaseReaderTests : GRDBTestCase {
try test(makeDatabaseQueue())
try test(makeDatabasePool())
try test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try test(makeDatabasePool().makeSnapshotPool())
#endif
}
@@ -292,7 +292,7 @@ class DatabaseReaderTests : GRDBTestCase {
try test(makeDatabaseQueue())
try test(makeDatabasePool())
try test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try test(makeDatabasePool().makeSnapshotPool())
#endif
}
@@ -312,7 +312,7 @@ class DatabaseReaderTests : GRDBTestCase {
try test(makeDatabaseQueue())
try test(makeDatabasePool())
try test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try test(makeDatabasePool().makeSnapshotPool())
#endif
}
@@ -339,7 +339,7 @@ class DatabaseReaderTests : GRDBTestCase {
try test(setup(makeDatabaseQueue(configuration: Configuration())))
try test(setup(makeDatabasePool(configuration: Configuration())))
try test(setup(makeDatabasePool(configuration: Configuration())).makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try test(setup(makeDatabasePool(configuration: Configuration())).makeSnapshotPool())
#endif
}
@@ -358,7 +358,7 @@ class DatabaseReaderTests : GRDBTestCase {
try await test(makeDatabaseQueue())
try await test(makeDatabasePool())
try await test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try await test(makeDatabasePool().makeSnapshotPool())
#endif
}
@@ -375,7 +375,7 @@ class DatabaseReaderTests : GRDBTestCase {
try await test(makeDatabaseQueue())
try await test(makeDatabasePool())
try await test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try await test(makeDatabasePool().makeSnapshotPool())
#endif
}
@@ -410,7 +410,7 @@ class DatabaseReaderTests : GRDBTestCase {
try await test(makeDatabaseQueue())
try await test(makeDatabasePool())
try await test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try await test(makeDatabasePool().makeSnapshotPool())
#endif
try await test(AnyDatabaseReader(makeDatabaseQueue()))
@@ -443,7 +443,7 @@ class DatabaseReaderTests : GRDBTestCase {
try await test(makeDatabaseQueue())
try await test(makeDatabasePool())
try await test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try await test(makeDatabasePool().makeSnapshotPool())
#endif
try await test(AnyDatabaseReader(makeDatabaseQueue()))
@@ -481,7 +481,7 @@ class DatabaseReaderTests : GRDBTestCase {
try await test(makeDatabaseQueue())
try await test(makeDatabasePool())
try await test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try await test(makeDatabasePool().makeSnapshotPool())
#endif
try await test(AnyDatabaseReader(makeDatabaseQueue()))
@@ -523,7 +523,7 @@ class DatabaseReaderTests : GRDBTestCase {
try await test(makeDatabaseQueue())
try await test(makeDatabasePool())
try await test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try await test(makeDatabasePool().makeSnapshotPool())
#endif
try await test(AnyDatabaseReader(makeDatabaseQueue()))
@@ -558,7 +558,7 @@ class DatabaseReaderTests : GRDBTestCase {
try await test(makeDatabaseQueue())
try await test(makeDatabasePool())
try await test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try await test(makeDatabasePool().makeSnapshotPool())
#endif
try await test(AnyDatabaseReader(makeDatabaseQueue()))
@@ -591,7 +591,7 @@ class DatabaseReaderTests : GRDBTestCase {
try await test(makeDatabaseQueue())
try await test(makeDatabasePool())
try await test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try await test(makeDatabasePool().makeSnapshotPool())
#endif
try await test(AnyDatabaseReader(makeDatabaseQueue()))
@@ -629,7 +629,7 @@ class DatabaseReaderTests : GRDBTestCase {
try await test(makeDatabaseQueue())
try await test(makeDatabasePool())
try await test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try await test(makeDatabasePool().makeSnapshotPool())
#endif
try await test(AnyDatabaseReader(makeDatabaseQueue()))
@@ -671,7 +671,7 @@ class DatabaseReaderTests : GRDBTestCase {
try await test(makeDatabaseQueue())
try await test(makeDatabasePool())
try await test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try await test(makeDatabasePool().makeSnapshotPool())
#endif
try await test(AnyDatabaseReader(makeDatabaseQueue()))
@@ -719,7 +719,7 @@ class DatabaseReaderTests : GRDBTestCase {
try await test(makeDatabaseQueue())
try await test(makeDatabasePool())
try await test(makeDatabasePool().makeSnapshot())
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
try await test(makeDatabasePool().makeSnapshotPool())
#endif
try await test(AnyDatabaseReader(makeDatabaseQueue()))
@@ -4,12 +4,14 @@ import GRDB
class DatabaseRegionObservationTests: GRDBTestCase {
// Test passes if it compiles.
// See <https://github.com/groue/GRDB.swift/issues/1541>
#if canImport(Combine)
func testAnyDatabaseWriter(writer: any DatabaseWriter) throws {
let observation = DatabaseRegionObservation(tracking: .fullDatabase)
_ = observation.start(in: writer, onError: { _ in }, onChange: { _ in })
_ = observation.publisher(in: writer)
}
#endif
func testDatabaseRegionObservation_FullDatabase() throws {
let dbQueue = try makeDatabaseQueue()
Loaded 100 of 127 files, more files were not shown because too many files have changed in this diff. Show more