mirror of
https://github.com/groue/GRDB.swift
synced 2026-12-06 05:28:44 +00:00
Compare commits
42
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dffc4bbe5d | ||
|
|
aa28797f67 | ||
|
|
fe59d44499 | ||
|
|
064eb9dea2 | ||
|
|
7bb5c636e7 | ||
|
|
080f9275cc | ||
|
|
aadc73cc11 | ||
|
|
2024f857a0 | ||
|
|
129e53d54e | ||
|
|
bc5dd31366 | ||
|
|
aa0079aeb8 | ||
|
|
74ef238376 | ||
|
|
9d7a487971 | ||
|
|
ac2f2e8643 | ||
|
|
e281149a2d | ||
|
|
3ee256e7e8 | ||
|
|
361599aacd | ||
|
|
64a024097d | ||
|
|
60ea10948b | ||
|
|
5dba64d545 | ||
|
|
2212a17950 | ||
|
|
24fa06d646 | ||
|
|
fd788900b6 | ||
|
|
b31be05ee3 | ||
|
|
a60810f28e | ||
|
|
c35095c6da | ||
|
|
f878d99733 | ||
|
|
48a17ce490 | ||
|
|
361a482b1e | ||
|
|
8cba324d6e | ||
|
|
17e1683b66 | ||
|
|
b1b83abd8b | ||
|
|
d06c9ed6b5 | ||
|
|
9a98ed6292 | ||
|
|
5cc85a98f3 | ||
|
|
edc1d646f0 | ||
|
|
ab09078842 | ||
|
|
267e1ea5a6 | ||
|
|
18497b68fd | ||
|
|
19e33e2e7d | ||
|
|
76e0815907 | ||
|
|
85ad232b0b |
No files matched your search
+24
-24
@@ -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 }}
|
||||
|
||||
@@ -2,4 +2,4 @@ version: 1
|
||||
builder:
|
||||
configs:
|
||||
- documentation_targets: [GRDB]
|
||||
swift_version: 6.0
|
||||
swift_version: 6.1
|
||||
+40
-1
@@ -7,6 +7,8 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
|
||||
|
||||
#### 7.x Releases
|
||||
|
||||
- `7.9.x` Releases - [7.9.0](#790)
|
||||
- `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)
|
||||
@@ -139,6 +141,43 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
|
||||
|
||||
---
|
||||
|
||||
## 7.9.0
|
||||
|
||||
Released December 13, 2025
|
||||
|
||||
- **Breaking Change**: Simplify the compiler checks for the availability of SQLite snapshots by [@groue](https://github.com/groue) in [#1826](https://github.com/groue/GRDB.swift/pull/1826)
|
||||
|
||||
This change aims at easing Linux and Android compatibility.
|
||||
|
||||
**The library requirements are raised to Swift 6.1+, Xcode 16.3+.**
|
||||
|
||||
- **Breaking Change**: Accept multiple SQLCipher libraries by [@groue](https://github.com/groue) in [#1819](https://github.com/groue/GRDB.swift/pull/1819)
|
||||
|
||||
This change aims at easing building GRDB against various SQLCipher flavors.
|
||||
|
||||
**The compiler flag that enables new GRDB APIs for SQLCipher is now `SQLITE_HAS_CODEC`.**
|
||||
|
||||
- **Fixed**: Fix cancellation of async tasks that use the FTS5 full-text engine by [@groue](https://github.com/groue) in [#1839](https://github.com/groue/GRDB.swift/pull/1839)
|
||||
|
||||
This workarounds an [SQLite bug](https://sqlite.org/forum/forumpost/95413eb410) that would trigger a GRDB crash, and improves the robustness of the library regarding database accesses cancellation and database interruption.
|
||||
|
||||
- **New**: Improve the ergonomics of `DatabaseMigrator.registerMigration(_:foreignKeyChecks:merging:migrate)`, introduced in [#1818](https://github.com/groue/GRDB.swift/pull/1818), by accepting that the name of the merged migration is included in the set of merged migrations:
|
||||
|
||||
```swift
|
||||
// Used to fail, now OK:
|
||||
migrator.registerMigration("v3", merging: ["v1", "v2", "v3"]) { ... }
|
||||
// ~~~~ ~~~~
|
||||
|
||||
// The above code is equivalent to:
|
||||
migrator.registerMigration("v3", merging: ["v1", "v2"]) { ... }
|
||||
```
|
||||
|
||||
## 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
|
||||
@@ -4363,7 +4402,7 @@ Released April 3, 2017
|
||||
|
||||
**Breaking Changes**
|
||||
|
||||
- SQLite C API is now available right from the GRBD module: you don't need any longer to import `SQLiteiPhoneOS` module et al (see documentation for [Raw SQLite Pointers](https://github.com/groue/GRDB.swift#raw-sqlite-pointers)).
|
||||
- SQLite C API is now available right from the GRDB module: you don't need any longer to import `SQLiteiPhoneOS` module et al (see documentation for [Raw SQLite Pointers](https://github.com/groue/GRDB.swift#raw-sqlite-pointers)).
|
||||
- The [manual installation procedure for WatchOS extensions](https://github.com/groue/GRDB.swift#installation) has changed.
|
||||
- [Carthage](https://github.com/Carthage/Carthage) is no longer supported. At the present time it is unable to support the various frameworks built by GRDB (system SQLite, SQLCipher, custom SQLite builds, etc.)
|
||||
|
||||
|
||||
@@ -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
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'GRDB.swift'
|
||||
s.version = '7.7.1'
|
||||
s.version = '7.9.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
|
||||
|
||||
|
||||
@@ -292,6 +292,7 @@
|
||||
56BB6EA91D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BB6EA81D3009B100A1CA52 /* SchedulingWatchdog.swift */; };
|
||||
56BCA2622E6C28F800E4F08D /* DatabaseSchemaSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BCA2612E6C28EF00E4F08D /* DatabaseSchemaSourceTests.swift */; };
|
||||
56BF2282241781C5003D86EB /* UtilsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF2281241781C5003D86EB /* UtilsTests.swift */; };
|
||||
56C7979B2EE99BD000AA265D /* Issue1838Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C7979A2EE99BD000AA265D /* Issue1838Tests.swift */; };
|
||||
56CC922C201DFFB900CB597E /* DropWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC922B201DFFB900CB597E /* DropWhileCursorTests.swift */; };
|
||||
56CC9243201E034D00CB597E /* PrefixWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC9242201E034D00CB597E /* PrefixWhileCursorTests.swift */; };
|
||||
56CC9246201E058100CB597E /* DropFirstCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC9245201E058000CB597E /* DropFirstCursorTests.swift */; };
|
||||
@@ -802,6 +803,7 @@
|
||||
56C3F7521CF9F12400F6A361 /* DatabaseSavepointTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseSavepointTests.swift; sourceTree = "<group>"; };
|
||||
56C48E731C9A9923005DF1D9 /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = "<group>"; };
|
||||
56C494401ED7255500CC72AF /* GRDBDeploymentTarget.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = GRDBDeploymentTarget.xcconfig; sourceTree = "<group>"; };
|
||||
56C7979A2EE99BD000AA265D /* Issue1838Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Issue1838Tests.swift; sourceTree = "<group>"; };
|
||||
56CC922B201DFFB900CB597E /* DropWhileCursorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropWhileCursorTests.swift; sourceTree = "<group>"; };
|
||||
56CC9242201E034D00CB597E /* PrefixWhileCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrefixWhileCursorTests.swift; sourceTree = "<group>"; };
|
||||
56CC9245201E058000CB597E /* DropFirstCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropFirstCursorTests.swift; sourceTree = "<group>"; };
|
||||
@@ -1448,6 +1450,7 @@
|
||||
56B964C21DA521450002DA19 /* FTS5TableBuilderTests.swift */,
|
||||
5698ACCA1DA62A2D0056AF8C /* FTS5TokenizerTests.swift */,
|
||||
56ED8A7E1DAB8D6800BD0ABC /* FTS5WrapperTokenizerTests.swift */,
|
||||
56C7979A2EE99BD000AA265D /* Issue1838Tests.swift */,
|
||||
);
|
||||
name = FTS;
|
||||
sourceTree = "<group>";
|
||||
@@ -2130,6 +2133,7 @@
|
||||
56D496C11D81373A008276D7 /* DatabaseQueueBackupTests.swift in Sources */,
|
||||
562393721DEE104400A6B01F /* MapCursorTests.swift in Sources */,
|
||||
56D496571D81303E008276D7 /* FoundationDateComponentsTests.swift in Sources */,
|
||||
56C7979B2EE99BD000AA265D /* Issue1838Tests.swift in Sources */,
|
||||
568C3F7A2A5AB2C300A2309D /* ForeignKeyDefinitionTests.swift in Sources */,
|
||||
56D496701D81309E008276D7 /* RecordPrimaryKeyRowIDTests.swift in Sources */,
|
||||
5622060C1E420EB3005860AC /* DatabaseQueueConcurrencyTests.swift in Sources */,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -510,6 +513,27 @@ extension Database {
|
||||
publicStatementArguments: configuration.publicStatementArguments)
|
||||
}
|
||||
|
||||
/// Always throws an error
|
||||
func statementCompilationDidFail(
|
||||
at statementStart: UnsafePointer<CChar>,
|
||||
withResultCode resultCode: CInt
|
||||
) throws -> Never {
|
||||
switch ResultCode(rawValue: resultCode) {
|
||||
case .SQLITE_INTERRUPT, .SQLITE_ABORT:
|
||||
// The only error that a user sees when a Task is cancelled
|
||||
// is CancellationError.
|
||||
try suspensionMutex.load().checkCancellation()
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
// Throw compilation failure
|
||||
throw DatabaseError(
|
||||
resultCode: resultCode,
|
||||
message: lastErrorMessage,
|
||||
sql: String(cString: statementStart))
|
||||
}
|
||||
|
||||
private func checkForAutocommitTransition() {
|
||||
if sqlite3_get_autocommit(sqliteConnection) == 0 {
|
||||
if autocommitState == .on {
|
||||
|
||||
@@ -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
|
||||
@@ -860,7 +863,16 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
|
||||
readOnlyDepth -= 1
|
||||
assert(readOnlyDepth >= 0, "unbalanced endReadOnly()")
|
||||
if readOnlyDepth == 0 {
|
||||
try internalCachedStatement(sql: "PRAGMA query_only = 0").execute()
|
||||
// We MUST ignore interruptions when we leave the read-only mode,
|
||||
// otherwise user could not write with this database
|
||||
// connection again.
|
||||
//
|
||||
// It's OK to ignore interruption, since interruption is
|
||||
// concurrent and we can pretend it occurred before or after
|
||||
// the PRAGMA.
|
||||
try ignoringInterruption {
|
||||
try internalCachedStatement(sql: "PRAGMA query_only = 0").execute()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1297,6 +1309,31 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
|
||||
return try value()
|
||||
}
|
||||
|
||||
/// Returns the result of `value`. If `value` throws an interruption
|
||||
/// error, it is retried a second time.
|
||||
func ignoringInterruption<T>(_ value: () throws -> T) rethrows -> T {
|
||||
do {
|
||||
return try value() // swiftlint:disable:next statement_position
|
||||
}
|
||||
catch is CancellationError,
|
||||
DatabaseError.SQLITE_INTERRUPT,
|
||||
DatabaseError.SQLITE_ABORT
|
||||
{
|
||||
// Maybe we were unlucky, and user has interrupted the database
|
||||
// during `value` execution.
|
||||
//
|
||||
// Another possible cause for this error is the FTS5 bug
|
||||
// described at <https://sqlite.org/forum/forumpost/137c7662b3>,
|
||||
// which leaves the database in a sticky interrupted state.
|
||||
// To workaround this bug, we must leave the interrupted state
|
||||
// before retrying:
|
||||
resetAllPreparedStatements()
|
||||
|
||||
// Retry
|
||||
return try value()
|
||||
}
|
||||
}
|
||||
|
||||
/// Support for `checkForSuspensionViolation(from:)`
|
||||
private func journalMode() throws -> String {
|
||||
if let journalMode = journalModeCache {
|
||||
@@ -1761,7 +1798,16 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
|
||||
// which rollback errors should be ignored, and which rollback errors
|
||||
// should be exposed to the library user.
|
||||
if isInsideTransaction {
|
||||
try execute(sql: "ROLLBACK TRANSACTION")
|
||||
// We MUST ignore interruptions during the rollback, otherwise
|
||||
// we could leave a transaction open, and trigger a fatal error in
|
||||
// `SerializedDatabase.preconditionNoUnsafeTransactionLeft`.
|
||||
//
|
||||
// It's OK to ignore interruption, since interruption is
|
||||
// concurrent and we can pretend it occurred before or after
|
||||
// the rollback.
|
||||
try ignoringInterruption {
|
||||
try execute(sql: "ROLLBACK TRANSACTION")
|
||||
}
|
||||
}
|
||||
assert(!isInsideTransaction)
|
||||
}
|
||||
@@ -1776,6 +1822,19 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
|
||||
assert(sqlite3_get_autocommit(sqliteConnection) != 0)
|
||||
}
|
||||
|
||||
/// Resets all prepared statements.
|
||||
///
|
||||
/// This method helps clearing the interrupted state, as a workaround
|
||||
/// for https://sqlite.org/forum/forumpost/137c7662b3, discovered
|
||||
/// in https://github.com/groue/GRDB.swift/issues/1838.
|
||||
func resetAllPreparedStatements() {
|
||||
var stmt: SQLiteStatement? = sqlite3_next_stmt(sqliteConnection, nil)
|
||||
while stmt != nil {
|
||||
sqlite3_reset(stmt)
|
||||
stmt = sqlite3_next_stmt(sqliteConnection, stmt)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Memory Management
|
||||
|
||||
/// Frees as much memory as possible.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -352,29 +352,35 @@ extension DatabasePool: DatabaseReader {
|
||||
}
|
||||
|
||||
public func read<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
guard let readerPool else {
|
||||
throw DatabaseError.connectionIsClosed()
|
||||
}
|
||||
|
||||
return try await readerPool.get { reader in
|
||||
try await reader.execute { db in
|
||||
defer {
|
||||
// Commit or rollback, but make sure we leave the read-only transaction
|
||||
// (commit may fail with a CancellationError).
|
||||
do {
|
||||
try db.commit()
|
||||
} catch {
|
||||
try? db.rollback()
|
||||
}
|
||||
assert(!db.isInsideTransaction)
|
||||
}
|
||||
// The block isolation comes from the DEFERRED transaction.
|
||||
try db.beginTransaction(.deferred)
|
||||
try db.clearSchemaCacheIfNeeded()
|
||||
return try value(db)
|
||||
}
|
||||
// Compiler does not see that value can be sent.
|
||||
return try await withoutActuallyEscaping(value) { value in
|
||||
typealias SendableClosure = @Sendable (Database) throws -> T
|
||||
let value = unsafeBitCast(value, to: SendableClosure.self)
|
||||
|
||||
return try await readerPool.get { reader in
|
||||
try await reader.execute { db in
|
||||
defer {
|
||||
// Commit or rollback, but make sure we leave the read-only transaction
|
||||
// (commit may fail with a CancellationError).
|
||||
do {
|
||||
try db.commit()
|
||||
} catch {
|
||||
try? db.rollback()
|
||||
}
|
||||
assert(!db.isInsideTransaction)
|
||||
}
|
||||
// The block isolation comes from the DEFERRED transaction.
|
||||
try db.beginTransaction(.deferred)
|
||||
try db.clearSchemaCacheIfNeeded()
|
||||
return try value(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,16 +438,22 @@ extension DatabasePool: DatabaseReader {
|
||||
}
|
||||
|
||||
public func unsafeRead<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
guard let readerPool else {
|
||||
throw DatabaseError.connectionIsClosed()
|
||||
}
|
||||
|
||||
return try await readerPool.get { reader in
|
||||
try await reader.execute { db in
|
||||
try db.clearSchemaCacheIfNeeded()
|
||||
return try value(db)
|
||||
// Compiler does not see that value can be sent.
|
||||
return try await withoutActuallyEscaping(value) { value in
|
||||
typealias SendableClosure = @Sendable (Database) throws -> T
|
||||
let value = unsafeBitCast(value, to: SendableClosure.self)
|
||||
|
||||
return try await readerPool.get { reader in
|
||||
try await reader.execute { db in
|
||||
try db.clearSchemaCacheIfNeeded()
|
||||
return try value(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -684,7 +696,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 {
|
||||
@@ -786,7 +798,7 @@ extension DatabasePool: DatabaseWriter {
|
||||
}
|
||||
|
||||
public func writeWithoutTransaction<T: Sendable>(
|
||||
_ updates: @Sendable (Database) throws -> T
|
||||
_ updates: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
try await writer.execute(updates)
|
||||
}
|
||||
@@ -802,32 +814,38 @@ extension DatabasePool: DatabaseWriter {
|
||||
}
|
||||
|
||||
public func barrierWriteWithoutTransaction<T: Sendable>(
|
||||
_ updates: @Sendable (Database) throws -> T
|
||||
_ updates: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
guard let readerPool else {
|
||||
throw DatabaseError.connectionIsClosed()
|
||||
}
|
||||
|
||||
// Pool.barrier does not support async calls (yet?).
|
||||
// So we perform cancellation checks just as in
|
||||
// the async version of SerializedDatabase.execute().
|
||||
let cancelMutex = Mutex<(@Sendable () -> Void)?>(nil)
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await readerPool.barrier {
|
||||
// Compiler does not see that updates can be sent.
|
||||
return try await withoutActuallyEscaping(updates) { updates in
|
||||
typealias SendableClosure = @Sendable (Database) throws -> T
|
||||
let updates = unsafeBitCast(updates, to: SendableClosure.self)
|
||||
|
||||
// Pool.barrier does not support async calls (yet?).
|
||||
// So we perform cancellation checks just as in
|
||||
// the async version of SerializedDatabase.execute().
|
||||
let cancelMutex = Mutex<(@Sendable () -> Void)?>(nil)
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try writer.sync { db in
|
||||
defer {
|
||||
cancelMutex.store(nil)
|
||||
db.uncancel()
|
||||
}
|
||||
cancelMutex.store(db.cancel)
|
||||
return try await readerPool.barrier {
|
||||
try Task.checkCancellation()
|
||||
return try updates(db)
|
||||
return try writer.sync { db in
|
||||
defer {
|
||||
cancelMutex.store(nil)
|
||||
db.uncancel()
|
||||
}
|
||||
cancelMutex.store(db.cancel)
|
||||
try Task.checkCancellation()
|
||||
return try updates(db)
|
||||
}
|
||||
}
|
||||
} onCancel: {
|
||||
cancelMutex.withLock { $0?() }
|
||||
}
|
||||
} onCancel: {
|
||||
cancelMutex.withLock { $0?() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -950,7 +968,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.
|
||||
|
||||
@@ -234,7 +234,7 @@ extension DatabaseQueue: DatabaseReader {
|
||||
}
|
||||
|
||||
public func read<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
try await writer.execute { db in
|
||||
try db.isolated(readOnly: true) {
|
||||
@@ -278,7 +278,7 @@ extension DatabaseQueue: DatabaseReader {
|
||||
}
|
||||
|
||||
public func unsafeRead<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
try await writer.execute(value)
|
||||
}
|
||||
@@ -397,7 +397,7 @@ extension DatabaseQueue: DatabaseWriter {
|
||||
}
|
||||
|
||||
public func writeWithoutTransaction<T: Sendable>(
|
||||
_ updates: @Sendable (Database) throws -> T
|
||||
_ updates: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
try await writer.execute(updates)
|
||||
}
|
||||
@@ -408,7 +408,7 @@ extension DatabaseQueue: DatabaseWriter {
|
||||
}
|
||||
|
||||
public func barrierWriteWithoutTransaction<T: Sendable>(
|
||||
_ updates: @Sendable (Database) throws -> T
|
||||
_ updates: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
try await writer.execute(updates)
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ public protocol DatabaseReader: AnyObject, Sendable {
|
||||
/// database access, or the error thrown by `value`, or
|
||||
/// `CancellationError` if the task is cancelled.
|
||||
func read<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: sending (Database) throws -> T
|
||||
) async throws -> T
|
||||
|
||||
/// Schedules read-only database operations for execution, and
|
||||
@@ -319,7 +319,7 @@ public protocol DatabaseReader: AnyObject, Sendable {
|
||||
/// database access, or the error thrown by `value`, or
|
||||
/// `CancellationError` if the task is cancelled.
|
||||
func unsafeRead<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: sending (Database) throws -> T
|
||||
) async throws -> T
|
||||
|
||||
/// Schedules database operations for execution, and returns immediately.
|
||||
@@ -652,7 +652,7 @@ extension AnyDatabaseReader: DatabaseReader {
|
||||
}
|
||||
|
||||
public func read<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
try await base.read(value)
|
||||
}
|
||||
@@ -669,7 +669,7 @@ extension AnyDatabaseReader: DatabaseReader {
|
||||
}
|
||||
|
||||
public func unsafeRead<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
try await base.unsafeRead(value)
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ extension DatabaseSnapshot: DatabaseSnapshotReader {
|
||||
}
|
||||
|
||||
public func read<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
try await reader.execute(value)
|
||||
}
|
||||
@@ -180,7 +180,7 @@ extension DatabaseSnapshot: DatabaseSnapshotReader {
|
||||
// `DatabaseSnapshotReader`, because of
|
||||
// <https://github.com/apple/swift/issues/74469>.
|
||||
public func unsafeRead<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
try await read(value)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -294,7 +297,7 @@ extension DatabaseSnapshotPool: DatabaseSnapshotReader {
|
||||
}
|
||||
|
||||
public func read<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
guard let readerPool else {
|
||||
throw DatabaseError.connectionIsClosed()
|
||||
@@ -342,7 +345,7 @@ extension DatabaseSnapshotPool: DatabaseSnapshotReader {
|
||||
// `DatabaseSnapshotReader`, because of
|
||||
// <https://github.com/apple/swift/issues/74469>.
|
||||
public func unsafeRead<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
try await read(value)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -130,7 +130,7 @@ public protocol DatabaseWriter: DatabaseReader {
|
||||
/// database access, or the error thrown by `updates`, or
|
||||
/// `CancellationError` if the task is cancelled.
|
||||
func writeWithoutTransaction<T: Sendable>(
|
||||
_ updates: @Sendable (Database) throws -> T
|
||||
_ updates: sending (Database) throws -> T
|
||||
) async throws -> T
|
||||
|
||||
/// Executes database operations, and returns their result after they have
|
||||
@@ -213,7 +213,7 @@ public protocol DatabaseWriter: DatabaseReader {
|
||||
/// database access, or the error thrown by `updates`, or
|
||||
/// `CancellationError` if the task is cancelled.
|
||||
func barrierWriteWithoutTransaction<T: Sendable>(
|
||||
_ updates: @Sendable (Database) throws -> T
|
||||
_ updates: sending (Database) throws -> T
|
||||
) async throws -> T
|
||||
|
||||
/// Schedules database operations for execution, and returns immediately.
|
||||
@@ -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.
|
||||
///
|
||||
@@ -640,7 +640,7 @@ extension DatabaseWriter {
|
||||
/// database access, or the error thrown by `updates`, or
|
||||
/// `CancellationError` if the task is cancelled.
|
||||
public func write<T: Sendable>(
|
||||
_ updates: @Sendable (Database) throws -> T
|
||||
_ updates: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
try await writeWithoutTransaction { db in
|
||||
var result: T?
|
||||
@@ -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.
|
||||
///
|
||||
@@ -885,7 +885,7 @@ extension AnyDatabaseWriter: DatabaseReader {
|
||||
}
|
||||
|
||||
public func read<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
try await base.read(value)
|
||||
}
|
||||
@@ -902,7 +902,7 @@ extension AnyDatabaseWriter: DatabaseReader {
|
||||
}
|
||||
|
||||
public func unsafeRead<T: Sendable>(
|
||||
_ value: @Sendable (Database) throws -> T
|
||||
_ value: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
try await base.unsafeRead(value)
|
||||
}
|
||||
@@ -936,7 +936,7 @@ extension AnyDatabaseWriter: DatabaseWriter {
|
||||
}
|
||||
|
||||
public func writeWithoutTransaction<T: Sendable>(
|
||||
_ updates: @Sendable (Database) throws -> T
|
||||
_ updates: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
try await base.writeWithoutTransaction(updates)
|
||||
}
|
||||
@@ -947,7 +947,7 @@ extension AnyDatabaseWriter: DatabaseWriter {
|
||||
}
|
||||
|
||||
public func barrierWriteWithoutTransaction<T: Sendable>(
|
||||
_ updates: @Sendable (Database) throws -> T
|
||||
_ updates: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
try await base.barrierWriteWithoutTransaction(updates)
|
||||
}
|
||||
|
||||
+7
-4
@@ -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
|
||||
|
||||
/// A key that is used to decode a value in a row
|
||||
|
||||
@@ -250,22 +250,29 @@ final class SerializedDatabase {
|
||||
|
||||
/// Asynchrously executes the block.
|
||||
func execute<T: Sendable>(
|
||||
_ block: @Sendable (Database) throws -> T
|
||||
_ block: sending (Database) throws -> T
|
||||
) async throws -> T {
|
||||
let cancelMutex = Mutex<(@Sendable () -> Void)?>(nil)
|
||||
return try await withTaskCancellationHandler {
|
||||
try await actor.execute {
|
||||
defer {
|
||||
cancelMutex.store(nil)
|
||||
db.uncancel()
|
||||
preconditionNoUnsafeTransactionLeft(db)
|
||||
|
||||
// Compiler does not see that block can be sent.
|
||||
return try await withoutActuallyEscaping(block) { block in
|
||||
typealias SendableClosure = @Sendable (Database) throws -> T
|
||||
let block = unsafeBitCast(block, to: SendableClosure.self)
|
||||
|
||||
return try await withTaskCancellationHandler {
|
||||
try await actor.execute {
|
||||
defer {
|
||||
cancelMutex.store(nil)
|
||||
db.uncancel()
|
||||
preconditionNoUnsafeTransactionLeft(db)
|
||||
}
|
||||
cancelMutex.store(db.cancel)
|
||||
try Task.checkCancellation()
|
||||
return try block(db)
|
||||
}
|
||||
cancelMutex.store(db.cancel)
|
||||
try Task.checkCancellation()
|
||||
return try block(db)
|
||||
} onCancel: {
|
||||
cancelMutex.withLock { $0?() }
|
||||
}
|
||||
} onCancel: {
|
||||
cancelMutex.withLock { $0?() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -147,10 +150,7 @@ public final class Statement {
|
||||
&sqliteStatement, statementEnd)
|
||||
|
||||
guard code == SQLITE_OK else {
|
||||
throw DatabaseError(
|
||||
resultCode: code,
|
||||
message: database.lastErrorMessage,
|
||||
sql: String(cString: statementStart))
|
||||
try database.statementCompilationDidFail(at: statementStart, withResultCode: code)
|
||||
}
|
||||
|
||||
guard let sqliteStatement else {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,11 +1,14 @@
|
||||
#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
|
||||
|
||||
@@ -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
|
||||
|
||||
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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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+
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -154,7 +154,7 @@ extension SQLSpecificExpressible {
|
||||
}
|
||||
}
|
||||
|
||||
#if GRDBCUSTOMSQLITE || GRDBCIPHER
|
||||
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
|
||||
extension SQLJSONExpressible {
|
||||
/// The `->>` SQL operator.
|
||||
///
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if GRDBCUSTOMSQLITE || GRDBCIPHER
|
||||
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
|
||||
// MARK: - JSON
|
||||
|
||||
extension Database {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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))")
|
||||
}
|
||||
}
|
||||
@@ -646,7 +646,7 @@ extension QueryInterfaceRequest {
|
||||
// MARK: - Batch Delete and Fetch
|
||||
|
||||
extension QueryInterfaceRequest {
|
||||
#if GRDBCUSTOMSQLITE || GRDBCIPHER
|
||||
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
|
||||
/// Returns a `DELETE RETURNING` prepared statement.
|
||||
///
|
||||
/// For example:
|
||||
@@ -1176,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:
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
///
|
||||
|
||||
@@ -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,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.
|
||||
///
|
||||
|
||||
@@ -287,6 +287,7 @@
|
||||
56C0539722ACEECD0029D27D /* ValueReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C0538C22ACEECD0029D27D /* ValueReducer.swift */; };
|
||||
56C0539B22ACEECD0029D27D /* Map.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C0538E22ACEECD0029D27D /* Map.swift */; };
|
||||
56C0539D22ACEECD0029D27D /* RemoveDuplicates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C0538F22ACEECD0029D27D /* RemoveDuplicates.swift */; };
|
||||
56C7979D2EE99BE900AA265D /* Issue1838Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C7979C2EE99BE900AA265D /* Issue1838Tests.swift */; };
|
||||
56C7A6AE1D2DFF6100EFB0C2 /* FoundationNSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* FoundationNSDateTests.swift */; };
|
||||
56C9EB9B2495324700FE5D55 /* grdb_config.h in Headers */ = {isa = PBXBuildFile; fileRef = 56C9EB9A2495324700FE5D55 /* grdb_config.h */; settings = {ATTRIBUTES = (Private, ); }; };
|
||||
56CC9234201E009000CB597E /* DropWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC9231201DFFF600CB597E /* DropWhileCursorTests.swift */; };
|
||||
@@ -814,6 +815,7 @@
|
||||
56C0538F22ACEECD0029D27D /* RemoveDuplicates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemoveDuplicates.swift; sourceTree = "<group>"; };
|
||||
56C3F7521CF9F12400F6A361 /* DatabaseSavepointTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseSavepointTests.swift; sourceTree = "<group>"; };
|
||||
56C494421ED726C500CC72AF /* GRDBDeploymentTarget.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = GRDBDeploymentTarget.xcconfig; path = SQLiteCustom/GRDBDeploymentTarget.xcconfig; sourceTree = "<group>"; };
|
||||
56C7979C2EE99BE900AA265D /* Issue1838Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Issue1838Tests.swift; sourceTree = "<group>"; };
|
||||
56C9EB9A2495324700FE5D55 /* grdb_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = grdb_config.h; path = SQLiteCustom/grdb_config.h; sourceTree = "<group>"; };
|
||||
56CC9231201DFFF600CB597E /* DropWhileCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropWhileCursorTests.swift; sourceTree = "<group>"; };
|
||||
56CC923A201E033400CB597E /* PrefixWhileCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrefixWhileCursorTests.swift; sourceTree = "<group>"; };
|
||||
@@ -1441,6 +1443,7 @@
|
||||
5698AC3E1DA2BEBB0056AF8C /* FTS */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
56C7979C2EE99BE900AA265D /* Issue1838Tests.swift */,
|
||||
5698AC3F1DA2BED90056AF8C /* FTS3PatternTests.swift */,
|
||||
5698AC481DA2D48A0056AF8C /* FTS3RecordTests.swift */,
|
||||
5698AC881DA389380056AF8C /* FTS3TableBuilderTests.swift */,
|
||||
@@ -2374,6 +2377,7 @@
|
||||
562205FE1E420EA2005860AC /* DatabasePoolConcurrencyTests.swift in Sources */,
|
||||
565EFAF11D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */,
|
||||
56DF0017228DDB8300D611F3 /* AssociationPrefetchingRowTests.swift in Sources */,
|
||||
56C7979D2EE99BE900AA265D /* Issue1838Tests.swift in Sources */,
|
||||
F3BA812E1CFB3064003DC1BA /* RecordPrimaryKeyMultipleTests.swift in Sources */,
|
||||
F3BA81021CFB3032003DC1BA /* CGFloatTests.swift in Sources */,
|
||||
5676FBAA22F5CEB9004717D9 /* ValueObservationRegionRecordingTests.swift in Sources */,
|
||||
|
||||
+38
-3
@@ -1,11 +1,20 @@
|
||||
// swift-tools-version:6.0
|
||||
// swift-tools-version:6.2
|
||||
// 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"),
|
||||
.define("SQLITE_ENABLE_SNAPSHOT"),
|
||||
]
|
||||
var cSettings: [CSetting] = []
|
||||
var dependencies: [PackageDescription.Package.Dependency] = []
|
||||
@@ -48,7 +57,9 @@ let package = Package(
|
||||
providers: [.apt(["libsqlite3-dev"])]),
|
||||
.target(
|
||||
name: "GRDB",
|
||||
dependencies: ["GRDBSQLite"],
|
||||
dependencies: [
|
||||
.target(name: "GRDBSQLite"),
|
||||
],
|
||||
path: "GRDB",
|
||||
resources: [.copy("PrivacyInfo.xcprivacy")],
|
||||
cSettings: cSettings,
|
||||
@@ -69,6 +80,9 @@ let package = Package(
|
||||
"Swift6Migration",
|
||||
"generatePerformanceReport.rb",
|
||||
"parsePerformanceTests.rb",
|
||||
"Swift6ApprochableConcurrencyGRDBTests",
|
||||
"Swift6DefaultGRDBTests",
|
||||
"Swift6MainActorIsolationGRDBTests",
|
||||
],
|
||||
resources: [
|
||||
.copy("GRDBTests/Betty.jpeg"),
|
||||
@@ -81,7 +95,28 @@ let package = Package(
|
||||
.swiftLanguageMode(.v5),
|
||||
.enableUpcomingFeature("InferSendableFromCaptures"),
|
||||
.enableUpcomingFeature("GlobalActorIsolatedTypesUsability"),
|
||||
])
|
||||
]),
|
||||
.testTarget(
|
||||
name: "Swift6ApprochableConcurrencyGRDBTests",
|
||||
dependencies: ["GRDB"],
|
||||
swiftSettings: [
|
||||
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
|
||||
.enableUpcomingFeature("InferIsolatedConformances")
|
||||
]
|
||||
),
|
||||
.testTarget(
|
||||
name: "Swift6DefaultGRDBTests",
|
||||
dependencies: ["GRDB"]
|
||||
),
|
||||
.testTarget(
|
||||
name: "Swift6MainActorIsolationGRDBTests",
|
||||
dependencies: ["GRDB"],
|
||||
swiftSettings: [
|
||||
.defaultIsolation(MainActor.self),
|
||||
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
|
||||
.enableUpcomingFeature("InferIsolatedConformances")
|
||||
]
|
||||
),
|
||||
],
|
||||
swiftLanguageModes: [.v6]
|
||||
)
|
||||
@@ -0,0 +1,105 @@
|
||||
// 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"),
|
||||
.define("SQLITE_ENABLE_SNAPSHOT"),
|
||||
]
|
||||
var cSettings: [CSetting] = []
|
||||
var dependencies: [PackageDescription.Package.Dependency] = []
|
||||
|
||||
// Don't rely on those environment variables. They are ONLY testing conveniences:
|
||||
// $ SQLITE_ENABLE_PREUPDATE_HOOK=1 make test_SPM
|
||||
if ProcessInfo.processInfo.environment["SQLITE_ENABLE_PREUPDATE_HOOK"] == "1" {
|
||||
swiftSettings.append(.define("SQLITE_ENABLE_PREUPDATE_HOOK"))
|
||||
cSettings.append(.define("GRDB_SQLITE_ENABLE_PREUPDATE_HOOK"))
|
||||
}
|
||||
|
||||
// The SPI_BUILDER environment variable enables documentation building
|
||||
// on <https://swiftpackageindex.com/groue/GRDB.swift>. See
|
||||
// <https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2122>
|
||||
// for more information.
|
||||
//
|
||||
// SPI_BUILDER also enables the `make docs-localhost` command.
|
||||
if ProcessInfo.processInfo.environment["SPI_BUILDER"] == "1" {
|
||||
dependencies.append(.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"))
|
||||
}
|
||||
|
||||
let package = Package(
|
||||
name: "GRDB",
|
||||
defaultLocalization: "en", // for tests
|
||||
platforms: [
|
||||
.iOS(.v13),
|
||||
.macOS(.v10_15),
|
||||
.tvOS(.v13),
|
||||
.watchOS(.v7),
|
||||
],
|
||||
products: [
|
||||
.library(name: "GRDBSQLite", targets: ["GRDBSQLite"]),
|
||||
.library(name: "GRDB", targets: ["GRDB"]),
|
||||
.library(name: "GRDB-dynamic", type: .dynamic, targets: ["GRDB"]),
|
||||
],
|
||||
dependencies: dependencies,
|
||||
targets: [
|
||||
.systemLibrary(
|
||||
name: "GRDBSQLite",
|
||||
providers: [.apt(["libsqlite3-dev"])]),
|
||||
.target(
|
||||
name: "GRDB",
|
||||
dependencies: [
|
||||
.target(name: "GRDBSQLite"),
|
||||
],
|
||||
path: "GRDB",
|
||||
resources: [.copy("PrivacyInfo.xcprivacy")],
|
||||
cSettings: cSettings,
|
||||
swiftSettings: swiftSettings),
|
||||
.testTarget(
|
||||
name: "GRDBTests",
|
||||
dependencies: ["GRDB"],
|
||||
path: "Tests",
|
||||
exclude: [
|
||||
"CocoaPods",
|
||||
"Crash",
|
||||
"CustomSQLite",
|
||||
"GRDBManualInstall",
|
||||
"GRDBTests/getThreadsCount.c",
|
||||
"Info.plist",
|
||||
"Performance",
|
||||
"SPM",
|
||||
"Swift6Migration",
|
||||
"generatePerformanceReport.rb",
|
||||
"parsePerformanceTests.rb",
|
||||
"Swift6ApprochableConcurrencyGRDBTests",
|
||||
"Swift6DefaultGRDBTests",
|
||||
"Swift6MainActorIsolationGRDBTests",
|
||||
],
|
||||
resources: [
|
||||
.copy("GRDBTests/Betty.jpeg"),
|
||||
.copy("GRDBTests/InflectionsTests.json"),
|
||||
.copy("GRDBTests/Issue1383.sqlite"),
|
||||
],
|
||||
cSettings: cSettings,
|
||||
swiftSettings: swiftSettings + [
|
||||
// Tests still use the Swift 5 language mode.
|
||||
.swiftLanguageMode(.v5),
|
||||
.enableUpcomingFeature("InferSendableFromCaptures"),
|
||||
.enableUpcomingFeature("GlobalActorIsolatedTypesUsability"),
|
||||
]),
|
||||
.testTarget(
|
||||
name: "Swift6DefaultGRDBTests",
|
||||
dependencies: ["GRDB"]
|
||||
),
|
||||
],
|
||||
swiftLanguageModes: [.v6]
|
||||
)
|
||||
@@ -10,24 +10,14 @@
|
||||
</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>
|
||||
|
||||
---
|
||||
**Latest release**: December 13, 2025 • [version 7.9.0](https://github.com/groue/GRDB.swift/tree/v7.9.0) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 6 to GRDB 7](Documentation/GRDB7MigrationGuide.md)
|
||||
|
||||
<a href="https://menial.co.uk/base/"><img alt="Base: The best SQLite database editor for macOS" src="https://raw.githubusercontent.com/groue/GRDB.swift/master/Sponsors/base.png"></a>
|
||||
|
||||
<p align="center">
|
||||
<strong>Thank you to <a href="https://menial.co.uk/base/">Base</a> for sponsoring GRDB</strong><br />Base is a small, powerful, comfortable SQLite editor for everyone on macOS.
|
||||
</p>
|
||||
|
||||
---
|
||||
|
||||
**Latest release**: September 29, 2025 • [version 7.7.1](https://github.com/groue/GRDB.swift/tree/v7.7.0) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 6 to GRDB 7](Documentation/GRDB7MigrationGuide.md)
|
||||
|
||||
**Requirements**: iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 7.0+ • SQLite 3.20.0+ • Swift 6+ / Xcode 16+
|
||||
**Requirements**: iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 7.0+ • SQLite 3.20.0+ • Swift 6.1+ / Xcode 16.3+
|
||||
|
||||
**Contact**:
|
||||
|
||||
|
||||
@@ -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
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 78 KiB |
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -15,7 +15,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>7.7.1</string>
|
||||
<string>7.9.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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -1166,4 +1166,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"]))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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()))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
|
||||
#if SQLITE_ENABLE_SNAPSHOT && !SQLITE_DISABLE_SNAPSHOT
|
||||
import XCTest
|
||||
import GRDB
|
||||
|
||||
|
||||
@@ -896,4 +896,41 @@ class DatabaseWriterTests : GRDBTestCase {
|
||||
try await test(makeDatabasePool())
|
||||
try await test(AnyDatabaseWriter(makeDatabaseQueue()))
|
||||
}
|
||||
|
||||
// Regression test for https://github.com/groue/GRDB.swift/pull/1838
|
||||
func test_cancellation_does_not_prevent_rollback() async throws {
|
||||
func test(_ dbWriter: some DatabaseWriter) async throws {
|
||||
// Numbers that have the test fail more or less reliably
|
||||
// (on my machine) unless the #1838 patch is applied.
|
||||
// When the test fails, we have a fatal error: A transaction has been left opened at the end of a database access.
|
||||
let repeatCount = 400
|
||||
let taskCount = 50
|
||||
for _ in 0..<repeatCount {
|
||||
try await withThrowingTaskGroup(of: Void.self) { group in
|
||||
for _ in 0..<taskCount{
|
||||
let task = Task {
|
||||
try await dbWriter.writeWithoutTransaction { db in
|
||||
try db.beginTransaction()
|
||||
try db.rollback()
|
||||
}
|
||||
}
|
||||
group.addTask {
|
||||
Task {
|
||||
// For the test to fail, we need to be lucky, here:
|
||||
// Cancellation must occur during the compilation
|
||||
// or the execution of the rollback statement.
|
||||
task.cancel()
|
||||
}
|
||||
// Ignore expected CancellationError
|
||||
try? await task.value
|
||||
}
|
||||
}
|
||||
try await group.waitForAll()
|
||||
}
|
||||
}
|
||||
}
|
||||
try await test(makeDatabaseQueue())
|
||||
try await test(makeDatabasePool())
|
||||
try await test(AnyDatabaseWriter(makeDatabaseQueue()))
|
||||
}
|
||||
}
|
||||
@@ -86,8 +86,11 @@ class FTS3TableBuilderTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
#if GRDBCUSTOMSQLITE
|
||||
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
|
||||
func testUnicode61TokenizerDiacriticsRemove() throws {
|
||||
guard Database.sqliteLibVersionNumber >= 3027000 else {
|
||||
throw XCTSkip("remove_diacritics=2 is not available")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(virtualTable: "documents", using: FTS3()) { t in
|
||||
@@ -96,10 +99,10 @@ class FTS3TableBuilderTests: GRDBTestCase {
|
||||
assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts3(tokenize=unicode61 \"remove_diacritics=2\")")
|
||||
}
|
||||
}
|
||||
#elseif !GRDBCIPHER
|
||||
#else
|
||||
func testUnicode61TokenizerDiacriticsRemove() throws {
|
||||
guard #available(iOS 14, macOS 10.16, tvOS 14, *) else {
|
||||
throw XCTSkip()
|
||||
throw XCTSkip("remove_diacritics=2 is not available")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
|
||||
@@ -95,8 +95,35 @@ class FTS3TokenizerTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
#if GRDBCUSTOMSQLITE
|
||||
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
|
||||
func testUnicode61TokenizerDiacriticsRemove() throws {
|
||||
guard Database.sqliteLibVersionNumber >= 3027000 else {
|
||||
throw XCTSkip("remove_diacritics=2 is not available")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(virtualTable: "documents", using: FTS3()) { t in
|
||||
t.tokenizer = .unicode61(diacritics: .remove)
|
||||
}
|
||||
|
||||
// simple match
|
||||
XCTAssertTrue(match(db, "abcDÉF", "abcDÉF"))
|
||||
|
||||
// English stemming
|
||||
XCTAssertFalse(match(db, "database", "databases"))
|
||||
|
||||
// diacritics in latin characters
|
||||
XCTAssertTrue(match(db, "eéÉ", "Èèe"))
|
||||
|
||||
// unicode case
|
||||
XCTAssertTrue(match(db, "jérôme", "JÉRÔME"))
|
||||
}
|
||||
}
|
||||
#else
|
||||
func testUnicode61TokenizerDiacriticsRemove() throws {
|
||||
guard #available(iOS 14, macOS 10.16, tvOS 14, *) else {
|
||||
throw XCTSkip("remove_diacritics=2 is not available")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(virtualTable: "documents", using: FTS3()) { t in
|
||||
|
||||
@@ -87,8 +87,24 @@ class FTS4TableBuilderTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
// TODO: why only custom SQLite build?
|
||||
#if GRDBCUSTOMSQLITE
|
||||
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
|
||||
func testUnicode61TokenizerDiacriticsRemove() throws {
|
||||
guard Database.sqliteLibVersionNumber >= 3027000 else {
|
||||
throw XCTSkip("remove_diacritics=2 is not available")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(virtualTable: "documents", using: FTS4()) { t in
|
||||
t.tokenizer = .unicode61(diacritics: .remove)
|
||||
}
|
||||
assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts4(tokenize=unicode61 \"remove_diacritics=2\")")
|
||||
}
|
||||
}
|
||||
#else
|
||||
func testUnicode61TokenizerDiacriticsRemove() throws {
|
||||
guard #available(iOS 14, macOS 10.16, tvOS 14, *) else {
|
||||
throw XCTSkip("remove_diacritics=2 is not available")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(virtualTable: "documents", using: FTS4()) { t in
|
||||
|
||||
Loaded 100 of 134 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user