diff --git a/.travis.yml b/.travis.yml index 5334c8f9c..d189df4f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,18 +28,122 @@ jobs: include: ########################################### - ## Test GRDB Xcode 11.4 + ## Test GRDB Xcode 11.6 - - name: "Test GRDB Xcode 11.4 - GRDBOSX" + - name: "Test GRDB Xcode 11.6 - GRDBOSX" gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode11.4 + osx_image: xcode11.6 script: make test_framework_GRDBOSX_maxSwift - - name: "Test GRDB Xcode 11.4 - GRDBWatchOS" + - name: "Test GRDB Xcode 11.6 - GRDBWatchOS" gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode11.4 + osx_image: xcode11.6 script: make test_framework_GRDBWatchOS + - name: "Test GRDB Xcode 11.6 - GRDBiOS iOS maxTarget" + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode11.6 + script: make test_framework_GRDBiOS_maxTarget_maxSwift + + - name: "Test GRDB Xcode 11.6 - GRDBiOS iOS minTarget" + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode11.6 + script: make test_framework_GRDBiOS_minTarget + + - name: "Test GRDB Xcode 11.6 - GRDBtvOS maxTarget" + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode11.6 + script: make test_framework_GRDBtvOS_maxTarget_maxSwift + + - name: "Test GRDB Xcode 11.6 - GRDBtvOS minTarget" + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode11.6 + script: make test_framework_GRDBtvOS_minTarget + + - name: "Test GRDB Xcode 11.6 - SPM" + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode11.6 + script: make test_SPM + + ########################################### + ## Test GRDBCustom Xcode 11.6 + + - name: "Test GRDBCustom Xcode 11.6 - GRDBOSX" + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode11.6 + script: make test_framework_GRDBCustomSQLiteOSX + + - name: "Test GRDBCustom Xcode 11.6 - GRDBiOS maxTarget" + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode11.6 + script: make test_framework_GRDBCustomSQLiteiOS_maxTarget_maxSwift + + - name: "Test GRDBCustom Xcode 11.6 - GRDBiOS minTarget" + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode11.6 + script: make test_framework_GRDBCustomSQLiteiOS_minTarget + + ########################################### + ## Test SQLCipher Xcode 11.6 + + - name: "Test SQLCipher Xcode 11.6 - SQLCipher 3" + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode11.6 + script: make test_framework_SQLCipher3 + + - name: "Test SQLCipher Xcode 11.6 - SQLCipher 4" + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode11.6 + script: make test_framework_SQLCipher4 + + ########################################### + ## Test Installation Xcode 11.6 + + # Manual Install + - name: "Test Installation Xcode 11.6 - Manual Install" + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode11.6 + script: make test_install_manual + + # CocoaPods Lint + - name: "Test Installation Xcode 11.6 - CocoaPods Lint" + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode11.6 + script: make test_CocoaPodsLint_GRDB + + # CocoaPods Install GRDB + - name: "Test Installation Xcode 11.6 - CocoaPods Framework" + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode11.6 + script: make test_install_GRDB_CocoaPods_framework + + # CocoaPods Install GRDB + - name: "Test Installation Xcode 11.6 - CocoaPods Static" + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode11.6 + script: make test_install_GRDB_CocoaPods_static + + # SPM Install + - name: "Test Installation Xcode 11.6 - SPM Package" + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode11.6 + script: make test_install_SPM_Package + + # SPM Install + - name: "Test Installation Xcode 11.6 - SPM Package in Xcode Project" + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode11.6 + script: make test_install_SPM_Project + + # Custom SQLite Install + - name: "Test Installation Xcode 11.6 - Custom SQLite" + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode11.6 + script: make test_install_customSQLite + + ########################################### + ## Test GRDB Xcode 11.4 + - name: "Test GRDB Xcode 11.4 - GRDBiOS iOS maxTarget" gemfile: .ci/gemfiles/Gemfile.travis osx_image: xcode11.4 @@ -49,94 +153,3 @@ jobs: gemfile: .ci/gemfiles/Gemfile.travis osx_image: xcode11.4 script: make test_framework_GRDBiOS_minTarget - - - name: "Test GRDB Xcode 11.4 - GRDBtvOS maxTarget" - gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode11.4 - script: make test_framework_GRDBtvOS_maxTarget_maxSwift - - - name: "Test GRDB Xcode 11.4 - GRDBtvOS minTarget" - gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode11.4 - script: make test_framework_GRDBtvOS_minTarget - - - name: "Test GRDB Xcode 11.4 - SPM" - gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode11.4 - script: make test_SPM - - ########################################### - ## Test GRDBCustom Xcode 11.4 - - - name: "Test GRDBCustom Xcode 11.4 - GRDBOSX" - gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode11.4 - script: make test_framework_GRDBCustomSQLiteOSX - - - name: "Test GRDBCustom Xcode 11.4 - GRDBiOS maxTarget" - gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode11.4 - script: make test_framework_GRDBCustomSQLiteiOS_maxTarget_maxSwift - - - name: "Test GRDBCustom Xcode 11.4 - GRDBiOS minTarget" - gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode11.4 - script: make test_framework_GRDBCustomSQLiteiOS_minTarget - - ########################################### - ## Test SQLCipher Xcode 11.4 - - - name: "Test SQLCipher Xcode 11.4 - SQLCipher 3" - gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode11.4 - script: make test_framework_SQLCipher3 - - - name: "Test SQLCipher Xcode 11.4 - SQLCipher 4" - gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode11.4 - script: make test_framework_SQLCipher4 - - ########################################### - ## Test Installation Xcode 11.4 - - # Manual Install - - name: "Test Installation Xcode 11.4 - Manual Install" - gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode11.4 - script: make test_install_manual - - # CocoaPods Lint - - name: "Test Installation Xcode 11.4 - CocoaPods Lint" - gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode11.4 - script: make test_CocoaPodsLint_GRDB - - # CocoaPods Install GRDB - - name: "Test Installation Xcode 11.4 - CocoaPods Framework" - gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode11.4 - script: make test_install_GRDB_CocoaPods_framework - - # CocoaPods Install GRDB - - name: "Test Installation Xcode 11.4 - CocoaPods Static" - gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode11.4 - script: make test_install_GRDB_CocoaPods_static - - # SPM Install - - name: "Test Installation Xcode 11.4 - SPM Package" - gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode11.4 - script: make test_install_SPM_Package - - # SPM Install - - name: "Test Installation Xcode 11.4 - SPM Package in Xcode Project" - gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode11.4 - script: make test_install_SPM_Project - - # Custom SQLite Install - - name: "Test Installation Xcode 11.4 - Custom SQLite" - gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode11.4 - script: make test_install_customSQLite diff --git a/CHANGELOG.md b/CHANGELOG.md index aacc01622..ce64bf565 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: #### 5.x Releases -- `5.0.0` Betas - [5.0.0-beta](#500-beta) | [5.0.0-beta.2](#500-beta2) | [5.0.0-beta.3](#500-beta3) | [5.0.0-beta.4](#500-beta4) | [5.0.0-beta.5](#500-beta5) | [5.0.0-beta.6](#500-beta6) | [5.0.0-beta.7](#500-beta7) | [5.0.0-beta.7](#500-beta8) +- `5.0.0` Betas - [5.0.0-beta](#500-beta) | [5.0.0-beta.2](#500-beta2) | [5.0.0-beta.3](#500-beta3) | [5.0.0-beta.4](#500-beta4) | [5.0.0-beta.5](#500-beta5) | [5.0.0-beta.6](#500-beta6) | [5.0.0-beta.7](#500-beta7) | [5.0.0-beta.8](#500-beta8) | [5.0.0-beta.9](#500-beta9) #### 4.x Releases @@ -75,6 +75,14 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: --> +## 5.0.0-beta.9 + +Released July 23, 2020 • [diff](https://github.com/groue/GRDB.swift/compare/v5.0.0-beta.8...v5.0.0-beta.9) + +- **New**: [#813](https://github.com/groue/GRDB.swift/pull/813): Expose SQLite 3.31.1 APIs to iOS, macOS, tvOS, watchOS +- **Fixed**: [#814](https://github.com/groue/GRDB.swift/pull/814): Fix regression with views + + ## 5.0.0-beta.8 Released July 19, 2020 • [diff](https://github.com/groue/GRDB.swift/compare/v5.0.0-beta.7...v5.0.0-beta.8) diff --git a/Documentation/FullTextSearch.md b/Documentation/FullTextSearch.md index 3ac780708..fcd577ebf 100644 --- a/Documentation/FullTextSearch.md +++ b/Documentation/FullTextSearch.md @@ -280,7 +280,7 @@ let pattern = FTS3Pattern(matchingAnyTokenIn: "") // nil let pattern = FTS3Pattern(matchingAnyTokenIn: "*") // nil ``` -FTS3Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Structs/StatementArguments.html): +FTS3Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Structs/StatementArguments.html): ```swift let documents = try Document.fetchAll(db, @@ -529,7 +529,7 @@ let pattern = FTS5Pattern(matchingAnyTokenIn: "") // nil let pattern = FTS5Pattern(matchingAnyTokenIn: "*") // nil ``` -FTS5Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Structs/StatementArguments.html): +FTS5Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Structs/StatementArguments.html): ```swift let documents = try Document.fetchAll(db, diff --git a/Documentation/Migrations.md b/Documentation/Migrations.md index 331fab06b..0c74aeff9 100644 --- a/Documentation/Migrations.md +++ b/Documentation/Migrations.md @@ -68,7 +68,7 @@ try dbQueue.read { db in } ``` -See the [DatabaseMigrator reference](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Structs/DatabaseMigrator.html) for more migrator methods. +See the [DatabaseMigrator reference](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Structs/DatabaseMigrator.html) for more migrator methods. ## The `eraseDatabaseOnSchemaChange` Option diff --git a/GRDB.swift.podspec b/GRDB.swift.podspec index 48ada8829..3a6711b7f 100644 --- a/GRDB.swift.podspec +++ b/GRDB.swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GRDB.swift' - s.version = '5.0.0-beta.8' + s.version = '5.0.0-beta.9' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'A toolkit for SQLite databases, with a focus on application development.' diff --git a/GRDB/Core/Cursor.swift b/GRDB/Core/Cursor.swift index 2c04634ad..b7e420dfb 100644 --- a/GRDB/Core/Cursor.swift +++ b/GRDB/Core/Cursor.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -// MARK: - Array, Sequence, Set extensions +// MARK: - Array, Sequence, Dictionary, Set extensions extension Array { /// Creates an array containing the elements of a cursor. @@ -25,6 +25,20 @@ extension Array { } } +extension Dictionary { + /// Creates a new dictionary whose keys are the groupings returned by the + /// given closure and whose values are arrays of the elements that returned + /// each key. + public init(grouping values: C, by keyForValue: (C.Element) throws -> Key) + throws where Value == [C.Element] + { + self.init() + while let value = try values.next() { + try self[keyForValue(value), default: []].append(value) + } + } +} + extension Sequence { /// Returns a cursor over the concatenated results of mapping transform diff --git a/GRDB/FTS/FTS3.swift b/GRDB/FTS/FTS3.swift index 1ebddf61e..536e2c9b5 100644 --- a/GRDB/FTS/FTS3.swift +++ b/GRDB/FTS/FTS3.swift @@ -21,6 +21,12 @@ public struct FTS3: VirtualTableModule { /// option matches the raw "remove_diacritics=2" tokenizer argument, /// available from SQLite 3.27.0 case remove + #elseif !GRDBCIPHER + /// Remove diacritics from Latin script characters. This + /// option matches the raw "remove_diacritics=2" tokenizer argument, + /// available from SQLite 3.27.0 + @available(OSX 10.16, iOS 14, tvOS 14, watchOS 7, *) + case remove #endif } diff --git a/GRDB/FTS/FTS3TokenizerDescriptor.swift b/GRDB/FTS/FTS3TokenizerDescriptor.swift index 0c9bd9bc4..2ce38af69 100644 --- a/GRDB/FTS/FTS3TokenizerDescriptor.swift +++ b/GRDB/FTS/FTS3TokenizerDescriptor.swift @@ -68,10 +68,13 @@ public struct FTS3TokenizerDescriptor { break case .keep: arguments.append("remove_diacritics=0") - #if GRDBCUSTOMSQLITE + #if GRDBCUSTOMSQLITE case .remove: arguments.append("remove_diacritics=2") - #endif + #elseif !GRDBCIPHER + case .remove: + arguments.append("remove_diacritics=2") + #endif } if !separators.isEmpty { // TODO: test "=" and "\"", "(" and ")" as separators, with diff --git a/GRDB/FTS/FTS5.swift b/GRDB/FTS/FTS5.swift index 06b243885..902eadcc1 100644 --- a/GRDB/FTS/FTS5.swift +++ b/GRDB/FTS/FTS5.swift @@ -26,6 +26,12 @@ public struct FTS5: VirtualTableModule { /// option matches the raw "remove_diacritics=2" tokenizer argument, /// available from SQLite 3.27.0 case remove + #elseif !GRDBCIPHER + /// Remove diacritics from Latin script characters. This + /// option matches the raw "remove_diacritics=2" tokenizer argument, + /// available from SQLite 3.27.0 + @available(OSX 10.16, iOS 14, tvOS 14, watchOS 7, *) + case remove #endif } diff --git a/GRDB/FTS/FTS5TokenizerDescriptor.swift b/GRDB/FTS/FTS5TokenizerDescriptor.swift index 04d571911..a54fd0496 100644 --- a/GRDB/FTS/FTS5TokenizerDescriptor.swift +++ b/GRDB/FTS/FTS5TokenizerDescriptor.swift @@ -144,10 +144,13 @@ public struct FTS5TokenizerDescriptor { break case .keep: components.append(contentsOf: ["remove_diacritics", "0"]) - #if GRDBCUSTOMSQLITE + #if GRDBCUSTOMSQLITE case .remove: components.append(contentsOf: ["remove_diacritics", "2"]) - #endif + #elseif !GRDBCIPHER + case .remove: + components.append(contentsOf: ["remove_diacritics", "2"]) + #endif } if !separators.isEmpty { // TODO: test "=" and "\"", "(" and ")" as separators, with diff --git a/GRDB/QueryInterface/SQL/SQLCollatedExpression.swift b/GRDB/QueryInterface/SQL/SQLCollatedExpression.swift index f571cc9ff..780538677 100644 --- a/GRDB/QueryInterface/SQL/SQLCollatedExpression.swift +++ b/GRDB/QueryInterface/SQL/SQLCollatedExpression.swift @@ -62,6 +62,32 @@ public struct SQLCollatedExpression { public var descNullsFirst: SQLOrderingTerm { _SQLOrdering.descNullsFirst(sqlExpression) } + #elseif !GRDBCIPHER + /// Returns an ordering suitable for QueryInterfaceRequest.order() + /// + /// let email: SQLCollatedExpression = Column("email").collating(.nocase) + /// + /// // SELECT * FROM player ORDER BY email COLLATE NOCASE ASC NULLS LAST + /// Player.order(email.ascNullsLast) + /// + /// See https://github.com/groue/GRDB.swift/#the-query-interface + @available(OSX 10.16, iOS 14, tvOS 14, watchOS 7, *) + public var ascNullsLast: SQLOrderingTerm { + _SQLOrdering.ascNullsLast(sqlExpression) + } + + /// Returns an ordering suitable for QueryInterfaceRequest.order() + /// + /// let email: SQLCollatedExpression = Column("email").collating(.nocase) + /// + /// // SELECT * FROM player ORDER BY email COLLATE NOCASE DESC NULLS FIRST + /// Player.order(email.descNullsFirst) + /// + /// See https://github.com/groue/GRDB.swift/#the-query-interface + @available(OSX 10.16, iOS 14, tvOS 14, watchOS 7, *) + public var descNullsFirst: SQLOrderingTerm { + _SQLOrdering.descNullsFirst(sqlExpression) + } #endif init(_ expression: SQLExpression, collationName: Database.CollationName) { diff --git a/GRDB/QueryInterface/SQL/SQLOrdering.swift b/GRDB/QueryInterface/SQL/SQLOrdering.swift index 54785a7d7..4e20e3f3b 100644 --- a/GRDB/QueryInterface/SQL/SQLOrdering.swift +++ b/GRDB/QueryInterface/SQL/SQLOrdering.swift @@ -24,10 +24,11 @@ public protocol SQLOrderingTerm: _SQLOrderingTerm { } public enum _SQLOrdering: SQLOrderingTerm, Refinable { case asc(SQLExpression) case desc(SQLExpression) - #if GRDBCUSTOMSQLITE + + // Only available from 3.30.0. This enum is not public, so those cases don't + // harm as long as we don't expose them through public APIs. case ascNullsLast(SQLExpression) case descNullsFirst(SQLExpression) - #endif var expression: SQLExpression { get { @@ -36,12 +37,10 @@ public enum _SQLOrdering: SQLOrderingTerm, Refinable { return expression case .desc(let expression): return expression - #if GRDBCUSTOMSQLITE case .ascNullsLast(let expression): return expression case .descNullsFirst(let expression): return expression - #endif } } set { @@ -50,12 +49,10 @@ public enum _SQLOrdering: SQLOrderingTerm, Refinable { self = .asc(newValue) case .desc: self = .desc(newValue) - #if GRDBCUSTOMSQLITE case .ascNullsLast: self = .ascNullsLast(newValue) case .descNullsFirst: self = .descNullsFirst(newValue) - #endif } } } @@ -67,12 +64,10 @@ public enum _SQLOrdering: SQLOrderingTerm, Refinable { return _SQLOrdering.desc(expression) case .desc(let expression): return _SQLOrdering.asc(expression) - #if GRDBCUSTOMSQLITE case .ascNullsLast(let expression): return _SQLOrdering.descNullsFirst(expression) case .descNullsFirst(let expression): return _SQLOrdering.ascNullsLast(expression) - #endif } } diff --git a/GRDB/QueryInterface/SQL/SQLRelation.swift b/GRDB/QueryInterface/SQL/SQLRelation.swift index c628df8d9..7fac40144 100644 --- a/GRDB/QueryInterface/SQL/SQLRelation.swift +++ b/GRDB/QueryInterface/SQL/SQLRelation.swift @@ -395,7 +395,7 @@ enum SQLSource { func qualified(with alias: TableAlias) -> SQLSource { switch self { - case let .table(tableName, sourceAlias): + case let .table(tableName: tableName, alias: sourceAlias): if let sourceAlias = sourceAlias { alias.becomeProxy(of: sourceAlias) return self diff --git a/GRDB/QueryInterface/SQL/SQLSpecificExpressible+QueryInterface.swift b/GRDB/QueryInterface/SQL/SQLSpecificExpressible+QueryInterface.swift index 12edf8b51..3f65b53fb 100644 --- a/GRDB/QueryInterface/SQL/SQLSpecificExpressible+QueryInterface.swift +++ b/GRDB/QueryInterface/SQL/SQLSpecificExpressible+QueryInterface.swift @@ -31,6 +31,22 @@ extension SQLSpecificExpressible { public var descNullsFirst: SQLOrderingTerm { _SQLOrdering.descNullsFirst(sqlExpression) } + #elseif !GRDBCIPHER + /// Returns a value that can be used as an argument to QueryInterfaceRequest.order() + /// + /// See https://github.com/groue/GRDB.swift/#the-query-interface + @available(OSX 10.16, iOS 14, tvOS 14, watchOS 7, *) + public var ascNullsLast: SQLOrderingTerm { + _SQLOrdering.ascNullsLast(sqlExpression) + } + + /// Returns a value that can be used as an argument to QueryInterfaceRequest.order() + /// + /// See https://github.com/groue/GRDB.swift/#the-query-interface + @available(OSX 10.16, iOS 14, tvOS 14, watchOS 7, *) + public var descNullsFirst: SQLOrderingTerm { + _SQLOrdering.descNullsFirst(sqlExpression) + } #endif } diff --git a/GRDB/QueryInterface/SQLGeneration/SQLGenerationContext.swift b/GRDB/QueryInterface/SQLGeneration/SQLGenerationContext.swift index 8643527d8..644d96cff 100644 --- a/GRDB/QueryInterface/SQLGeneration/SQLGenerationContext.swift +++ b/GRDB/QueryInterface/SQLGeneration/SQLGenerationContext.swift @@ -405,6 +405,7 @@ public class TableAlias: Hashable { /// } public var exists: SQLExpression { + // TODO: this fails with SQL views. Can we do something? _SQLExpressionQualifiedFastPrimaryKey(alias: self) != nil } diff --git a/GRDB/QueryInterface/SQLGeneration/SQLOrderingGenerator.swift b/GRDB/QueryInterface/SQLGeneration/SQLOrderingGenerator.swift index 11ab4c855..cf161f103 100644 --- a/GRDB/QueryInterface/SQLGeneration/SQLOrderingGenerator.swift +++ b/GRDB/QueryInterface/SQLGeneration/SQLOrderingGenerator.swift @@ -26,12 +26,10 @@ private struct SQLOrderingGenerator: _SQLOrderingTermVisitor { resultSQL = try expression.expressionSQL(context, wrappedInParenthesis: false) + " ASC" case .desc(let expression): resultSQL = try expression.expressionSQL(context, wrappedInParenthesis: false) + " DESC" - #if GRDBCUSTOMSQLITE case .ascNullsLast(let expression): resultSQL = try expression.expressionSQL(context, wrappedInParenthesis: false) + " ASC NULLS LAST" case .descNullsFirst(let expression): resultSQL = try expression.expressionSQL(context, wrappedInParenthesis: false) + " DESC NULLS FIRST" - #endif } } diff --git a/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift b/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift index 4a571b668..63d419bbe 100644 --- a/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift +++ b/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift @@ -175,9 +175,12 @@ struct SQLQueryGenerator: Refinable { // Can we intersect the region with rowIds? // // Give up unless request feeds from a single database table - guard case let .table(tableName: tableName, alias: alias) = relation.source else { - // TODO: try harder - return selectedRegion + guard + case let .table(tableName: tableName, alias: alias) = relation.source, + try db.tableExists(tableName) // skip views + else { + // TODO: try harder + return selectedRegion } // The filter knows better @@ -206,7 +209,10 @@ struct SQLQueryGenerator: Refinable { } // Do we filter on a unique key? - if case let .table(tableName, sourceAlias) = relation.source { + if + case let .table(tableName: tableName, alias: sourceAlias) = relation.source, + try db.tableExists(tableName) // skip views + { let identifyingColums = try filters .joined(operator: .and) .identifyingColums(db, for: sourceAlias) @@ -432,8 +438,11 @@ struct SQLQueryGenerator: Refinable { } // Grouping something which is not a table: assume non unique grouping. - guard case let .table(tableName: tableName, alias: alias) = relation.source else { - return .nonUnique + guard + case let .table(tableName: tableName, alias: alias) = relation.source, + try db.tableExists(tableName) // skip views + else { + return .nonUnique } var groupingColumns: Set = [] diff --git a/Makefile b/Makefile index c1ff3a999..f2c52f236 100644 --- a/Makefile +++ b/Makefile @@ -56,6 +56,13 @@ ifeq ($(XCODEVERSION),12.0) MIN_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 5s,OS=10.3.1" MAX_TVOS_DESTINATION = "platform=tvOS Simulator,name=Apple TV 4K,OS=14.0" MIN_TVOS_DESTINATION = "platform=tvOS Simulator,name=Apple TV,OS=10.2" +else ifeq ($(XCODEVERSION),11.6) + MAX_SWIFT_VERSION = 5.2 + MIN_SWIFT_VERSION = # MAX_SWIFT_VERSION is the minimum supported Swift version + MAX_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 11,OS=13.6" + MIN_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 5s,OS=10.3.1" + MAX_TVOS_DESTINATION = "platform=tvOS Simulator,name=Apple TV 4K,OS=13.4" + MIN_TVOS_DESTINATION = "platform=tvOS Simulator,name=Apple TV,OS=10.2" else ifeq ($(XCODEVERSION),11.5) MAX_SWIFT_VERSION = 5.2 MIN_SWIFT_VERSION = # MAX_SWIFT_VERSION is the minimum supported Swift version @@ -401,10 +408,10 @@ ifdef JAZZY --author 'Gwendal Roué' \ --author_url https://github.com/groue \ --github_url https://github.com/groue/GRDB.swift \ - --github-file-prefix https://github.com/groue/GRDB.swift/tree/v5.0.0-beta.8 \ - --module-version 5.0.0-beta.8 \ + --github-file-prefix https://github.com/groue/GRDB.swift/tree/v5.0.0-beta.9 \ + --module-version 5.0.0-beta.9 \ --module GRDB \ - --root-url http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/ \ + --root-url http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/ \ --output Documentation/Reference \ --xcodebuild-arguments -project,GRDB.xcodeproj,-scheme,GRDBiOS else diff --git a/README.md b/README.md index 8223603e3..993952f97 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,13 @@ --- -**Latest release**: July 19, 2020 • version 5.0.0-beta.8 • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 4 to GRDB 5](Documentation/GRDB5MigrationGuide.md) +**Latest release**: July 23, 2020 • version 5.0.0-beta.9 • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 4 to GRDB 5](Documentation/GRDB5MigrationGuide.md) **Requirements**: iOS 10.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+ • Swift 5.2+ / Xcode 11.4+ | Swift version | GRDB version | | ------------- | ----------------------------------------------------------- | -| **Swift 5.2** | **v5.0.0-beta.8**, [v4.14.0](https://github.com/groue/GRDB.swift/tree/v4.14.0)| +| **Swift 5.2** | **v5.0.0-beta.9**, [v4.14.0](https://github.com/groue/GRDB.swift/tree/v4.14.0)| | Swift 5.1 | [v4.14.0](https://github.com/groue/GRDB.swift/tree/v4.14.0) | | Swift 5 | [v4.14.0](https://github.com/groue/GRDB.swift/tree/v4.14.0) | | Swift 4.2 | [v4.14.0](https://github.com/groue/GRDB.swift/tree/v4.14.0) | @@ -278,7 +278,7 @@ Documentation #### Reference -- [GRDB Reference](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/index.html) (generated by [Jazzy](https://github.com/realm/jazzy)) +- [GRDB Reference](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/index.html) (generated by [Jazzy](https://github.com/realm/jazzy)) #### Getting Started @@ -480,7 +480,7 @@ let dbQueue = try DatabaseQueue( configuration: config) ``` -See [Configuration](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Structs/Configuration.html) for more details. +See [Configuration](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Structs/Configuration.html) for more details. ## Database Pools @@ -560,7 +560,7 @@ let dbPool = try DatabasePool( configuration: config) ``` -See [Configuration](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Structs/Configuration.html) for more details. +See [Configuration](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Structs/Configuration.html) for more details. Database pools are more memory-hungry than database queues. See [Memory Management](#memory-management) for more information. @@ -620,7 +620,7 @@ try dbQueue.write { db in } ``` -The `?` and colon-prefixed keys like `:score` in the SQL query are the **statements arguments**. You pass arguments with arrays or dictionaries, as in the example above. See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. +The `?` and colon-prefixed keys like `:score` in the SQL query are the **statements arguments**. You pass arguments with arrays or dictionaries, as in the example above. See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. You can also embed query arguments right into your SQL queries, with the `literal` argument label, as in the example below. See [SQL Interpolation] for more details. @@ -823,7 +823,7 @@ try dbQueue.read { db in - **Cursors are granted with direct access to SQLite,** unlike arrays and sets that have to take the time to copy database values. If you look after extra performance, you may prefer cursors. -- **Cursors adopt the [Cursor](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Protocols/Cursor.html) protocol, which looks a lot like standard [lazy sequences](https://developer.apple.com/reference/swift/lazysequenceprotocol) of Swift.** As such, cursors come with many convenience methods: `compactMap`, `contains`, `dropFirst`, `dropLast`, `drop(while:)`, `enumerated`, `filter`, `first`, `flatMap`, `forEach`, `joined`, `joined(separator:)`, `max`, `max(by:)`, `min`, `min(by:)`, `map`, `prefix`, `prefix(while:)`, `reduce`, `reduce(into:)`, `suffix`: +- **Cursors adopt the [Cursor](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Protocols/Cursor.html) protocol, which looks a lot like standard [lazy sequences](https://developer.apple.com/reference/swift/lazysequenceprotocol) of Swift.** As such, cursors come with many convenience methods: `compactMap`, `contains`, `dropFirst`, `dropLast`, `drop(while:)`, `enumerated`, `filter`, `first`, `flatMap`, `forEach`, `joined`, `joined(separator:)`, `max`, `max(by:)`, `min`, `min(by:)`, `map`, `prefix`, `prefix(while:)`, `reduce`, `reduce(into:)`, `suffix`: ```swift // Prints all Github links @@ -906,7 +906,7 @@ let rows = try Row.fetchAll(db, arguments: ["name": "Arthur"]) ``` -See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. +See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. Unlike row arrays that contain copies of the database rows, row cursors are close to the SQLite metal, and require a little care: @@ -1191,7 +1191,7 @@ GRDB ships with built-in support for the following value types: - Generally speaking, all types that adopt the [DatabaseValueConvertible](#custom-value-types) protocol. -Values can be used as [statement arguments](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Structs/StatementArguments.html): +Values can be used as [statement arguments](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Structs/StatementArguments.html): ```swift let url: URL = ... @@ -1598,7 +1598,7 @@ try dbQueue.inDatabase { db in // or dbPool.writeWithoutTransaction } ``` -Transactions can't be left opened unless you set the [allowsUnsafeTransactions](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Structs/Configuration.html) configuration flag: +Transactions can't be left opened unless you set the [allowsUnsafeTransactions](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Structs/Configuration.html) configuration flag: ```swift // fatal error: A transaction has been left opened at the end of a database access @@ -1712,7 +1712,7 @@ try dbQueue.write { db in } ``` -The `?` and colon-prefixed keys like `:name` in the SQL query are the statement arguments. You set them with arrays or dictionaries (arguments are actually of type [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Structs/StatementArguments.html), which happens to adopt the ExpressibleByArrayLiteral and ExpressibleByDictionaryLiteral protocols). +The `?` and colon-prefixed keys like `:name` in the SQL query are the statement arguments. You set them with arrays or dictionaries (arguments are actually of type [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Structs/StatementArguments.html), which happens to adopt the ExpressibleByArrayLiteral and ExpressibleByDictionaryLiteral protocols). ```swift updateStatement.arguments = ["name": "Arthur", "score": 1000] @@ -2476,7 +2476,7 @@ try Place.fetchSet(db, sql: "SELECT ...", arguments:...) // Set try Place.fetchOne(db, sql: "SELECT ...", arguments:...) // Place? ``` -See [fetching methods](#fetching-methods) for information about the `fetchCursor`, `fetchAll`, `fetchSet` and `fetchOne` methods. See [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Structs/StatementArguments.html) for more information about the query arguments. +See [fetching methods](#fetching-methods) for information about the `fetchCursor`, `fetchAll`, `fetchSet` and `fetchOne` methods. See [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Structs/StatementArguments.html) for more information about the query arguments. > :point_up: **Note**: for performance reasons, the same row argument to `init(row:)` is reused during the iteration of a fetch query. If you want to keep the row for later use, make sure to store a copy: `self.row = row.copy()`. @@ -2857,7 +2857,7 @@ protocol EncodableRecord { } ``` -See [DatabaseDateDecodingStrategy](https://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Enums/DatabaseDateDecodingStrategy.html), [DatabaseDateEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Enums/DatabaseDateEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Enums/DatabaseUUIDEncodingStrategy.html) to learn about all available strategies. +See [DatabaseDateDecodingStrategy](https://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Enums/DatabaseDateDecodingStrategy.html), [DatabaseDateEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Enums/DatabaseDateEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Enums/DatabaseUUIDEncodingStrategy.html) to learn about all available strategies. > :point_up: **Note**: there is no customization of uuid decoding, because UUID can already decode all its encoded variants (16-bytes blobs, and uuid strings). @@ -4255,7 +4255,7 @@ Player // SELECT * FROM player ``` -Raw SQL snippets are also accepted, with eventual [arguments](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Structs/StatementArguments.html): +Raw SQL snippets are also accepted, with eventual [arguments](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Structs/StatementArguments.html): ```swift // SELECT DATE(creationDate), COUNT(*) FROM player WHERE name = 'Arthur' GROUP BY date(creationDate) @@ -4911,7 +4911,7 @@ try Player.customRequest().fetchAll(db) // [Player] - The `adapted(_:)` method eases the consumption of complex rows with [row adapters](#row-adapters). See [Joined Queries Support](#joined-queries-support) for some sample code that uses this method. -- [AnyFetchRequest](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Structs/AnyFetchRequest.html): a type-erased request. +- [AnyFetchRequest](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Structs/AnyFetchRequest.html): a type-erased request. ## Joined Queries Support @@ -6071,7 +6071,7 @@ After `stopObservingDatabaseChangesUntilNextTransaction()`, the `databaseDidChan ### DatabaseRegion -**[DatabaseRegion](https://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Structs/DatabaseRegion.html) is a type that helps observing changes in the results of a database [request](#requests)**. +**[DatabaseRegion](https://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Structs/DatabaseRegion.html) is a type that helps observing changes in the results of a database [request](#requests)**. A request knows which database modifications can impact its results. It can communicate this information to [transaction observers](#transactionobserver-protocol) by the way of a DatabaseRegion. @@ -6081,7 +6081,7 @@ DatabaseRegion fuels, for example, [ValueObservation and DatabaseRegionObservati For example, if you observe the region of `Player.select(max(Column("score")))`, then you'll get be notified of all changes performed on the `score` column of the `player` table (updates, insertions and deletions), even if they do not modify the value of the maximum score. However, you will not get any notification for changes performed on other database tables, or updates to other columns of the player table. -For more details, see the [reference](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Structs/DatabaseRegion.html#/s:4GRDB14DatabaseRegionV10isModified2bySbAA0B5EventV_tF). +For more details, see the [reference](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Structs/DatabaseRegion.html#/s:4GRDB14DatabaseRegionV10isModified2bySbAA0B5EventV_tF). #### The DatabaseRegionConvertible Protocol @@ -7178,7 +7178,7 @@ try snapshot2.read { db in ### DatabaseWriter and DatabaseReader Protocols -Both DatabaseQueue and DatabasePool adopt the [DatabaseReader](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Protocols/DatabaseReader.html) and [DatabaseWriter](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Protocols/DatabaseWriter.html) protocols. DatabaseSnapshot adopts DatabaseReader only. +Both DatabaseQueue and DatabasePool adopt the [DatabaseReader](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Protocols/DatabaseReader.html) and [DatabaseWriter](http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Protocols/DatabaseWriter.html) protocols. DatabaseSnapshot adopts DatabaseReader only. These protocols provide a unified API that let you write generic code that targets all concurrency modes. They fuel, for example: @@ -7909,4 +7909,4 @@ This chapter has been superseded by [ValueObservation] and [DatabaseRegionObserv [Sharing a Database]: Documentation/SharingADatabase.md [FAQ]: #faq [Database Observation]: #database-changes-observation -[SQLRequest]: http://groue.github.io/GRDB.swift/docs/5.0.0-beta.8/Structs/SQLRequest.html +[SQLRequest]: http://groue.github.io/GRDB.swift/docs/5.0.0-beta.9/Structs/SQLRequest.html diff --git a/Support/Info.plist b/Support/Info.plist index deb05ed7a..9dd0315ef 100644 --- a/Support/Info.plist +++ b/Support/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 5.0.0-beta.8 + 5.0.0-beta.9 CFBundleSignature ???? CFBundleVersion diff --git a/Tests/GRDBTests/CursorTests.swift b/Tests/GRDBTests/CursorTests.swift index 96c102475..f2a8b6c3a 100644 --- a/Tests/GRDBTests/CursorTests.swift +++ b/Tests/GRDBTests/CursorTests.swift @@ -170,4 +170,22 @@ class CursorTests: GRDBTestCase { XCTAssertTrue(suffix == [1, 2, 3, 4, 5]) } } + + func testDictionaryGrouping() throws { + do { + let cursor = AnyCursor([]) + let dictionary = try Dictionary(grouping: cursor, by: { $0 % 2 }) + XCTAssertEqual(dictionary, [:]) + } + do { + let cursor = AnyCursor([1, 2, 3, 4, 5]) + let dictionary = try Dictionary(grouping: cursor, by: { $0 % 2 }) + XCTAssertEqual(dictionary, [0: [2, 4], 1: [1, 3, 5]]) + } + do { + let cursor = AnyCursor([5, 4, 3, 2, 1]) + let dictionary = try Dictionary(grouping: cursor, by: { $0 % 2 }) + XCTAssertEqual(dictionary, [0: [4, 2], 1: [5, 3, 1]]) + } + } } diff --git a/Tests/GRDBTests/FTS3TableBuilderTests.swift b/Tests/GRDBTests/FTS3TableBuilderTests.swift index 678f0f332..cd51aab51 100644 --- a/Tests/GRDBTests/FTS3TableBuilderTests.swift +++ b/Tests/GRDBTests/FTS3TableBuilderTests.swift @@ -74,6 +74,19 @@ class FTS3TableBuilderTests: GRDBTestCase { assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts3(tokenize=unicode61 \"remove_diacritics=2\")") } } + #elseif !GRDBCIPHER + func testUnicode61TokenizerDiacriticsRemove() throws { + guard #available(OSX 10.16, iOS 14, tvOS 14, watchOS 7, *) else { + throw XCTSkip() + } + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try db.create(virtualTable: "documents", using: FTS3()) { t in + t.tokenizer = .unicode61(diacritics: .remove) + } + assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts3(tokenize=unicode61 \"remove_diacritics=2\")") + } + } #endif func testUnicode61TokenizerSeparators() throws { diff --git a/Tests/GRDBTests/FTS5TableBuilderTests.swift b/Tests/GRDBTests/FTS5TableBuilderTests.swift index 600d79018..e03c0cf8d 100644 --- a/Tests/GRDBTests/FTS5TableBuilderTests.swift +++ b/Tests/GRDBTests/FTS5TableBuilderTests.swift @@ -128,6 +128,21 @@ class FTS5TableBuilderTests: GRDBTestCase { assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts5(content, tokenize='unicode61 remove_diacritics 2')") } } + #elseif !GRDBCIPHER + func testUnicode61TokenizerDiacriticsRemove() throws { + guard #available(OSX 10.16, iOS 14, tvOS 14, watchOS 7, *) else { + throw XCTSkip() + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try db.create(virtualTable: "documents", using: FTS5()) { t in + t.tokenizer = .unicode61(diacritics: .remove) + t.column("content") + } + assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts5(content, tokenize='unicode61 remove_diacritics 2')") + } + } #endif func testUnicode61TokenizerSeparators() throws { diff --git a/Tests/GRDBTests/QueryInterfaceRequestTests.swift b/Tests/GRDBTests/QueryInterfaceRequestTests.swift index ccb77d1ba..5fe2f446d 100644 --- a/Tests/GRDBTests/QueryInterfaceRequestTests.swift +++ b/Tests/GRDBTests/QueryInterfaceRequestTests.swift @@ -617,6 +617,21 @@ class QueryInterfaceRequestTests: GRDBTestCase { "SELECT * FROM \"readers\" WHERE 1 AND 0") } + // Regression test for https://github.com/groue/GRDB.swift/issues/812 + func testFilterOnView() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.execute(sql: "CREATE VIEW v AS SELECT * FROM readers") + struct ViewRecord: TableRecord, FetchableRecord, Decodable { + static let databaseTableName = "v" + } + _ = try ViewRecord.filter(Column("id") == 1).fetchOne(db) + XCTAssertEqual( + lastSQLQuery, + "SELECT * FROM \"v\" WHERE \"id\" = 1 LIMIT 1") + } + } + // MARK: - Group @@ -744,6 +759,15 @@ class QueryInterfaceRequestTests: GRDBTestCase { XCTAssertEqual( sql(dbQueue, tableRequest.order(Col.age.descNullsFirst)), "SELECT * FROM \"readers\" ORDER BY \"age\" DESC NULLS FIRST") + #elseif !GRDBCIPHER + if #available(OSX 10.16, iOS 14, tvOS 14, watchOS 7, *) { + XCTAssertEqual( + sql(dbQueue, tableRequest.order(Col.age.ascNullsLast)), + "SELECT * FROM \"readers\" ORDER BY \"age\" ASC NULLS LAST") + XCTAssertEqual( + sql(dbQueue, tableRequest.order(Col.age.descNullsFirst)), + "SELECT * FROM \"readers\" ORDER BY \"age\" DESC NULLS FIRST") + } #endif } @@ -765,6 +789,15 @@ class QueryInterfaceRequestTests: GRDBTestCase { XCTAssertEqual( sql(dbQueue, tableRequest.order(Col.name.collating(.nocase).descNullsFirst)), "SELECT * FROM \"readers\" ORDER BY \"name\" COLLATE NOCASE DESC NULLS FIRST") + #elseif !GRDBCIPHER + if #available(OSX 10.16, iOS 14, tvOS 14, watchOS 7, *) { + XCTAssertEqual( + sql(dbQueue, tableRequest.order(Col.name.collating(.nocase).ascNullsLast)), + "SELECT * FROM \"readers\" ORDER BY \"name\" COLLATE NOCASE ASC NULLS LAST") + XCTAssertEqual( + sql(dbQueue, tableRequest.order(Col.name.collating(.nocase).descNullsFirst)), + "SELECT * FROM \"readers\" ORDER BY \"name\" COLLATE NOCASE DESC NULLS FIRST") + } #endif } @@ -805,6 +838,15 @@ class QueryInterfaceRequestTests: GRDBTestCase { XCTAssertEqual( sql(dbQueue, tableRequest.order(Col.age.ascNullsLast).reversed()), "SELECT * FROM \"readers\" ORDER BY \"age\" DESC NULLS FIRST") + #elseif !GRDBCIPHER + if #available(OSX 10.16, iOS 14, tvOS 14, watchOS 7, *) { + XCTAssertEqual( + sql(dbQueue, tableRequest.order(Col.age.descNullsFirst).reversed()), + "SELECT * FROM \"readers\" ORDER BY \"age\" ASC NULLS LAST") + XCTAssertEqual( + sql(dbQueue, tableRequest.order(Col.age.ascNullsLast).reversed()), + "SELECT * FROM \"readers\" ORDER BY \"age\" DESC NULLS FIRST") + } #endif } @@ -826,6 +868,15 @@ class QueryInterfaceRequestTests: GRDBTestCase { XCTAssertEqual( sql(dbQueue, tableRequest.order(Col.name.collating(.nocase).descNullsFirst).reversed()), "SELECT * FROM \"readers\" ORDER BY \"name\" COLLATE NOCASE ASC NULLS LAST") + #elseif !GRDBCIPHER + if #available(OSX 10.16, iOS 14, tvOS 14, watchOS 7, *) { + XCTAssertEqual( + sql(dbQueue, tableRequest.order(Col.name.collating(.nocase).ascNullsLast).reversed()), + "SELECT * FROM \"readers\" ORDER BY \"name\" COLLATE NOCASE DESC NULLS FIRST") + XCTAssertEqual( + sql(dbQueue, tableRequest.order(Col.name.collating(.nocase).descNullsFirst).reversed()), + "SELECT * FROM \"readers\" ORDER BY \"name\" COLLATE NOCASE ASC NULLS LAST") + } #endif } diff --git a/Tests/GRDBTests/TableRecord+QueryInterfaceRequestTests.swift b/Tests/GRDBTests/TableRecord+QueryInterfaceRequestTests.swift index 9f2a4aee7..e17bfc22d 100644 --- a/Tests/GRDBTests/TableRecord+QueryInterfaceRequestTests.swift +++ b/Tests/GRDBTests/TableRecord+QueryInterfaceRequestTests.swift @@ -259,6 +259,15 @@ class TableRecordQueryInterfaceRequestTests: GRDBTestCase { XCTAssertEqual( sql(dbQueue, Reader.order(Col.age.descNullsFirst)), "SELECT * FROM \"readers\" ORDER BY \"age\" DESC NULLS FIRST") + #elseif !GRDBCIPHER + if #available(OSX 10.16, iOS 14, tvOS 14, watchOS 7, *) { + XCTAssertEqual( + sql(dbQueue, Reader.order(Col.age.ascNullsLast)), + "SELECT * FROM \"readers\" ORDER BY \"age\" ASC NULLS LAST") + XCTAssertEqual( + sql(dbQueue, Reader.order(Col.age.descNullsFirst)), + "SELECT * FROM \"readers\" ORDER BY \"age\" DESC NULLS FIRST") + } #endif }