diff --git a/.ci/gemfiles/Gemfile.travis b/.ci/gemfiles/Gemfile.travis index b9c52c2b5..135cd52f2 100644 --- a/.ci/gemfiles/Gemfile.travis +++ b/.ci/gemfiles/Gemfile.travis @@ -1,4 +1,5 @@ source 'https://rubygems.org' gem 'xcpretty' -gem 'xcpretty-travis-formatter' \ No newline at end of file +gem 'xcpretty-travis-formatter' +gem 'cocoapods', '~> 1.6' diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index c3adaa018..bb4be9723 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -18,7 +18,7 @@ Please fill out this template when filing an issue. ### Environment -**GRDB flavor(s):** (GRDB, GRDBCipher, GRDBCustom?) +**GRDB flavor(s):** (GRDB, SQLCipher, Custom SQLite build?) **GRDB version:** **Installation method:** (CocoaPods, SPM, manual?) **Xcode version:** diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index a9a667d0b..849c8590d 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -9,4 +9,4 @@ Please verify that your pull request checks those boxes: - [ ] This pull request is submitted against the `development` branch. - [ ] Inline documentation has been updated. - [ ] README.md or another dedicated guide has been updated. -- [ ] Changes are tested, for all flavors of GRDB, GRDBCipher, and GRDBCustomSQLite. +- [ ] Changes are tested. diff --git a/.gitignore b/.gitignore index 6682770f1..2d68688ac 100644 --- a/.gitignore +++ b/.gitignore @@ -101,9 +101,7 @@ SQLiteCustom/GRDBCustomSQLite-USER.h SQLiteCustom/GRDBCustomSQLite-USER.xcconfig # CocoaPods test -Podfile.lock Pods -Tests/CocoaPods/*/*.xcworkspace # SPM .build diff --git a/.gitmodules b/.gitmodules index 5a407f41b..70b679c61 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,9 +7,6 @@ [submodule "Tests/Performance/Realm"] path = Tests/Performance/Realm url = https://github.com/realm/realm-cocoa.git -[submodule "SQLCipher/src"] - path = SQLCipher/src - url = https://github.com/groue/sqlcipher.git [submodule "SQLiteCustom/src"] path = SQLiteCustom/src - url = https://github.com/swiftlyfalling/SQLiteLib + url = https://github.com/swiftlyfalling/SQLiteLib.git diff --git a/.swift-version b/.swift-version index 7d5c902e7..bf77d5496 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -4.1 +4.2 diff --git a/.travis.yml b/.travis.yml index da9eac35b..c87f1fece 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,16 @@ language: objective-c xcode_project: GRDB.xcodeproj +# Caches +cache: + - bundler + - cocoapods + +# Custom CocoaPods installation so that Podfile.lock is honored +install: + - bundle install + - bundle exec pod repo update + # Disable the default Travis-CI submodule logic # The various make commands ensure that the appropriate submodules are retrieved git: @@ -13,213 +23,312 @@ jobs: include: ########################################### - ## Test GRDB - - # Test GRDBOSX (Xcode 10) - - stage: Test GRDB + ## Test GRDB Xcode 10.2 + + - stage: Test GRDB Xcode 10.2 gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode10 + osx_image: xcode10.2 env: - - TID=GRDBOSX (Xcode 10, Swift 4.2, macOS) + - TID=GRDBOSX (Swift 5, macOS) script: make test_framework_GRDBOSX_maxSwift - - # Test GRDBOSX (Xcode 10) - - stage: Test GRDB + + - stage: Test GRDB Xcode 10.2 gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode10 + osx_image: xcode10.2 env: - - TID=GRDBOSX (Xcode 10, Swift 4.0, macOS) + - TID=GRDBOSX (Swift 4.2, macOS) script: make test_framework_GRDBOSX_minSwift - - # Test GRDBWatchOS (Xcode 10) - - stage: Test GRDB + + - stage: Test GRDB Xcode 10.2 gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode10 + osx_image: xcode10.2 env: - - TID=GRDBWatchOS (Xcode 10, watchOS) + - TID=GRDBWatchOS (watchOS) script: make test_framework_GRDBWatchOS - - # Test GRDBiOS (Xcode 10, iOS ) - - stage: Test GRDB + + - stage: Test GRDB Xcode 10.2 gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode10 + osx_image: xcode10.2 env: - - TID=GRDBiOS (Xcode 10, Swift 4.2, iOS ) + - TID=GRDBiOS (Swift 5, iOS ) script: make test_framework_GRDBiOS_maxTarget_maxSwift - - # Test GRDBiOS (Xcode 9.4, iOS ) - - stage: Test GRDB + + - stage: Test GRDB Xcode 10.2 gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode9.4 + osx_image: xcode10.2 env: - - TID=GRDBiOS (Xcode 9.4, iOS ) - script: make test_framework_GRDBiOS_maxTarget_maxSwift - - # Test GRDBiOS (Xcode 9.3, iOS )) - - stage: Test GRDB + - TID=GRDBiOS (Swift 4.2, iOS ) + script: make test_framework_GRDBiOS_maxTarget_minSwift + + - stage: Test GRDB Xcode 10.2 gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode9.3 + osx_image: xcode10.2 env: - - TID=GRDBiOS (Xcode 9.3, iOS ) + - TID=GRDBiOS (Swift 5, iOS ) script: make test_framework_GRDBiOS_minTarget - - # Test GRDB [SPM] (Xcode 10, macOS) - - stage: Test GRDB + + - stage: Test GRDB Xcode 10.2 gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode10 + osx_image: xcode10.2 env: - - TID=GRDB [SPM] (Xcode 10, macOS) + - TID=GRDB [SPM] (macOS) script: make test_SPM - + ########################################### - ## Test GRDB (Custom SQLite) - - # Test GRDBCustomSQLiteOSX (Xcode 10) - - stage: Test GRDB + Custom SQLite + ## Test GRDBCustom Xcode 10.2 + + - stage: Test GRDBCustom Xcode 10.2 gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode10 + osx_image: xcode10.2 env: - - TID=GRDBCustomSQLiteOSX (Xcode 10, macOS) + - TID=GRDBOSX (Swift 5, macOS) script: make test_framework_GRDBCustomSQLiteOSX - - # Test GRDBCustomSQLiteiOS (Xcode 10, iOS ) - - stage: Test GRDB + Custom SQLite + + - stage: Test GRDBCustom Xcode 10.2 gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode10 + osx_image: xcode10.2 env: - - TID=GRDBCustomSQLiteiOS (Xcode 10, Swift 4.2, iOS ) + - TID=GRDBiOS (Swift 5, iOS ) script: make test_framework_GRDBCustomSQLiteiOS_maxTarget_maxSwift - - # Test GRDBCustomSQLiteiOS (Xcode 10, iOS ) - - stage: Test GRDB + Custom SQLite + + - stage: Test GRDBCustom Xcode 10.2 gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode10 + osx_image: xcode10.2 env: - - TID=GRDBCustomSQLiteiOS (Xcode 10, Swift 4.0, iOS ) + - TID=GRDBiOS (Swift 4.2, iOS ) script: make test_framework_GRDBCustomSQLiteiOS_maxTarget_minSwift - - # Test GRDBCustomSQLiteiOS (Xcode 9.4, iOS ) - - stage: Test GRDB + Custom SQLite + + - stage: Test GRDBCustom Xcode 10.2 gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode9.4 + osx_image: xcode10.2 env: - - TID=GRDBCustomSQLiteiOS (Xcode 9.4, iOS ) - script: make test_framework_GRDBCustomSQLiteiOS_maxTarget - - # Test GRDBCustomSQLiteiOS (Xcode 9.3, iOS )) - - stage: Test GRDB + Custom SQLite - gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode9.3 - env: - - TID=GRDBCustomSQLiteiOS (Xcode 9.3, iOS ) + - TID=GRDBiOS (Swift 5, iOS ) script: make test_framework_GRDBCustomSQLiteiOS_minTarget - + ########################################### - ## Test GRDB (SQLCipher) - - # Test GRDBCipherOSX (Xcode 10) - - stage: Test GRDB + SQLCipher + ## Test SQLCipher Xcode 10.2 + + - stage: Test SQLCipher Xcode 10.2 gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode10 + osx_image: xcode10.2 env: - - TID=GRDBCipherOSX (Xcode 10, macOS) - script: make test_framework_GRDBCipherOSX - - # Test GRDBCipheriOS (Xcode 10, iOS ) - - stage: Test GRDB + SQLCipher + - TID=SQLCipher 3 + script: make test_framework_SQLCipher3 + + - stage: Test SQLCipher Xcode 10.2 gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode10 + osx_image: xcode10.2 env: - - TID=GRDBCipheriOS (Xcode 10, iOS ) - script: make test_framework_GRDBCipheriOS_maxTarget - - # Test GRDBCipheriOS (Xcode 9.4, iOS ) - - stage: Test GRDB + SQLCipher - gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode9.4 - env: - - TID=GRDBCipheriOS (Xcode 9.4, iOS ) - script: make test_framework_GRDBCipheriOS_maxTarget - - # Test GRDBCipheriOS (Xcode 9.3, iOS )) - - stage: Test GRDB + SQLCipher - gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode9.3 - env: - - TID=GRDBCipheriOS (Xcode 9.3, iOS ) - script: make test_framework_GRDBCipheriOS_minTarget - + - TID=SQLCipher 4 + script: make test_framework_SQLCipher4 + ########################################### - ## Test Installation Methods - - # Manual Install (Xcode 10) - - stage: Test Installation + ## Test Installation Xcode 10.2 + + # Manual Install + - stage: Test Installation Xcode 10.2 gemfile: .ci/gemfiles/Gemfile.travis - osx_image: xcode10 + osx_image: xcode10.2 env: - - TID=Manual Install (Xcode 10) + - TID=Manual Install script: make test_install_manual - - # Manual Install (GRDBCipher, Xcode 10) - - stage: Test Installation + + # CocoaPods Lint + - stage: Test Installation Xcode 10.2 + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode10.2 + env: + - TID=CocoaPods Lint + script: make test_CocoaPodsLint_GRDB + + # CocoaPods Install GRDB + - stage: Test Installation Xcode 10.2 + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode10.2 + env: + - TID=CocoaPods GRDB + script: make test_install_GRDB_CocoaPods + + # SPM Install + - stage: Test Installation Xcode 10.2 + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode10.2 + env: + - TID=SPM + script: make test_install_SPM + + ########################################### + ## Test GRDB Xcode 10.1 + + - stage: Test GRDB Xcode 10.1 + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode10.1 + env: + - TID=GRDBOSX (Swift 4.2, macOS) + script: make test_framework_GRDBOSX_maxSwift + + - stage: Test GRDB Xcode 10.1 + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode10.1 + env: + - TID=GRDBWatchOS (watchOS) + script: make test_framework_GRDBWatchOS + + - stage: Test GRDB Xcode 10.1 + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode10.1 + env: + - TID=GRDBiOS (Swift 4.2, iOS ) + script: make test_framework_GRDBiOS_maxTarget_maxSwift + + - stage: Test GRDB Xcode 10.1 + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode10.1 + env: + - TID=GRDBiOS (Swift 4.2, iOS ) + script: make test_framework_GRDBiOS_minTarget + + - stage: Test GRDB Xcode 10.1 + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode10.1 + env: + - TID=GRDB [SPM] (macOS) + script: make test_SPM + + # ########################################### + # ## Test GRDBCustom Xcode 10.1 + # + # - stage: Test GRDBCustom Xcode 10.1 + # gemfile: .ci/gemfiles/Gemfile.travis + # osx_image: xcode10.1 + # env: + # - TID=GRDBOSX (Swift 4.2, macOS) + # script: make test_framework_GRDBCustomSQLiteOSX + # + # - stage: Test GRDBCustom Xcode 10.1 + # gemfile: .ci/gemfiles/Gemfile.travis + # osx_image: xcode10.1 + # env: + # - TID=GRDBiOS (Swift 4.2, iOS ) + # script: make test_framework_GRDBCustomSQLiteiOS_maxTarget_maxSwift + # + # - stage: Test GRDBCustom Xcode 10.1 + # gemfile: .ci/gemfiles/Gemfile.travis + # osx_image: xcode10.1 + # env: + # - TID=GRDBiOS (Swift 4.2, iOS ) + # script: make test_framework_GRDBCustomSQLiteiOS_minTarget + + ########################################### + ## Test GRDB Xcode 10 + + - stage: Test GRDB Xcode 10 gemfile: .ci/gemfiles/Gemfile.travis osx_image: xcode10 env: - - TID=Manual Install (GRDBCipher, Xcode 10) - script: make test_install_GRDBCipher - - # CocoaPods Lint (Xcode 10) - - stage: Test Installation + - TID=GRDBOSX (Swift 4.2, macOS) + script: make test_framework_GRDBOSX_maxSwift + + - stage: Test GRDB Xcode 10 + gemfile: .ci/gemfiles/Gemfile.travis osx_image: xcode10 - install: - - gem install cocoapods --pre # >= 1.6.0.beta.1 for cocoapods lint env: - - TID=CocoaPods Lint GRDB.swift (Xcode 10) - script: make test_CocoaPodsLint_GRDB - - # CocoaPods Lint (Xcode 10) - - stage: Test Installation + - TID=GRDBWatchOS (watchOS) + script: make test_framework_GRDBWatchOS + + - stage: Test GRDB Xcode 10 + gemfile: .ci/gemfiles/Gemfile.travis osx_image: xcode10 - install: - - gem install cocoapods --pre # >= 1.6.0.beta.1 for cocoapods lint env: - - TID=CocoaPods Lint GRDBCipher (Xcode 10) - script: make test_CocoaPodsLint_GRDBCipher - - # CocoaPods Install (Xcode 10) - - stage: Test Installation + - TID=GRDBiOS (Swift 4.2, iOS ) + script: make test_framework_GRDBiOS_maxTarget_maxSwift + + - stage: Test GRDB Xcode 10 + gemfile: .ci/gemfiles/Gemfile.travis osx_image: xcode10 - install: - - gem install cocoapods --pre # >= 1.6.0.beta.1 for cocoapods lint env: - - TID=CocoaPods GRDB (Xcode 10) - script: make test_install_GRDB_CocoaPods - - # Disabled until we understand the reason for this failure: - # https://travis-ci.org/groue/GRDB.swift/jobs/503214543 - # - # # CocoaPods Install (Xcode 10) - # - stage: Test Installation + - TID=GRDBiOS (Swift 4.2, iOS ) + script: make test_framework_GRDBiOS_minTarget + + - stage: Test GRDB Xcode 10 + gemfile: .ci/gemfiles/Gemfile.travis + osx_image: xcode10 + env: + - TID=GRDB [SPM] (macOS) + script: make test_SPM + + # ########################################### + # ## Test GRDBCustom Xcode 10 + # + # - stage: Test GRDBCustom Xcode 10 + # gemfile: .ci/gemfiles/Gemfile.travis # osx_image: xcode10 - # install: - # - gem install cocoapods --pre # >= 1.6.0.beta.1 for cocoapods lint # env: - # - TID=CocoaPods GRDBCipher (Xcode 10) - # script: make test_install_GRDBCipher_CocoaPods - - # SPM Install (Xcode 10) - - stage: Test Installation - osx_image: xcode10 - env: - - TID=SPM (Xcode 10) - script: make test_install_SPM - - ## Carthage Build - - stage: Test Installation - osx_image: xcode10 - before_install: - - brew update - - brew outdated carthage || brew upgrade carthage - env: - - TID=Carthages - script: make test_CarthageBuild + # - TID=GRDBOSX (Swift 4.2, macOS) + # script: make test_framework_GRDBCustomSQLiteOSX + # + # - stage: Test GRDBCustom Xcode 10 + # gemfile: .ci/gemfiles/Gemfile.travis + # osx_image: xcode10 + # env: + # - TID=GRDBiOS (Swift 4.2, iOS ) + # script: make test_framework_GRDBCustomSQLiteiOS_maxTarget_maxSwift + # + # - stage: Test GRDBCustom Xcode 10 + # gemfile: .ci/gemfiles/Gemfile.travis + # osx_image: xcode10 + # env: + # - TID=GRDBiOS (Swift 4.2, iOS ) + # script: make test_framework_GRDBCustomSQLiteiOS_minTarget + # + # ########################################### + # ## Test SQLCipher Xcode 10 + # + # - stage: Test SQLCipher Xcode 10 + # gemfile: .ci/gemfiles/Gemfile.travis + # osx_image: xcode10 + # env: + # - TID=SQLCipher 3 + # script: make test_framework_SQLCipher3 + # + # - stage: Test SQLCipher Xcode 10 + # gemfile: .ci/gemfiles/Gemfile.travis + # osx_image: xcode10 + # env: + # - TID=SQLCipher 4 + # script: make test_framework_SQLCipher4 + # + # ########################################### + # ## Test Installation Xcode 10 + # + # # Manual Install + # - stage: Test Installation Xcode 10 + # gemfile: .ci/gemfiles/Gemfile.travis + # osx_image: xcode10 + # env: + # - TID=Manual Install + # script: make test_install_manual + # + # # CocoaPods Lint + # - stage: Test Installation Xcode 10 + # gemfile: .ci/gemfiles/Gemfile.travis + # osx_image: xcode10 + # env: + # - TID=CocoaPods Lint + # script: make test_CocoaPodsLint_GRDB + # + # # CocoaPods Install GRDB + # - stage: Test Installation Xcode 10 + # gemfile: .ci/gemfiles/Gemfile.travis + # osx_image: xcode10 + # env: + # - TID=CocoaPods GRDB + # script: make test_install_GRDB_CocoaPods + # + # # SPM Install + # - stage: Test Installation Xcode 10 + # gemfile: .ci/gemfiles/Gemfile.travis + # osx_image: xcode10 + # env: + # - TID=SPM + # script: make test_install_SPM diff --git a/CHANGELOG.md b/CHANGELOG.md index 0423ae96c..7b13c87ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,11 @@ Release Notes All notable changes to this project will be documented in this file. -GRDB adheres to [Semantic Versioning](https://semver.org/). +GRDB adheres to [Semantic Versioning](https://semver.org/), with one expection: APIs flagged [**:fire: EXPERIMENTAL**](README.md#what-are-experimental-features). Those are unstable, and may break between any two minor releases of the library. + +#### 4.x Releases + +- `4.0.x` Releases - [4.0.0](#400) #### 3.x Releases @@ -43,6 +47,498 @@ GRDB adheres to [Semantic Versioning](https://semver.org/). - [0.110.0](#01100), ... +## 4.0.0 + +Released May 23, 2019 • [diff](https://github.com/groue/GRDB.swift/compare/v3.7.0...v4.0.0) + +GRDB 4 is a release focused on **Swift 5**, and **enhancements on associations between record types**. + +It comes with new features, but also a few breaking changes. The [GRDB 4 Migration Guide](Documentation/GRDB3MigrationGuide.md) will help you upgrading your applications. + +### New + +- [#478](https://github.com/groue/GRDB.swift/pull/478): Swift 5: SQL interpolation +- [#484](https://github.com/groue/GRDB.swift/pull/484): SE-0193 Cross-module inlining and specialization +- [#486](https://github.com/groue/GRDB.swift/pull/486): Refactor PersistenceError.recordNotFound +- [#488](https://github.com/groue/GRDB.swift/pull/488): ValueObservation Cleanup +- [#490](https://github.com/groue/GRDB.swift/pull/490): Indirect Associations +- [#493](https://github.com/groue/GRDB.swift/pull/493): Bump SQLite to [3.27.2](https://www.sqlite.org/releaselog/3_27_2.html) +- [#499](https://github.com/groue/GRDB.swift/pull/499): Extract EncodableRecord from MutablePersistableRecord +- [#502](https://github.com/groue/GRDB.swift/pull/502): Rename Future to DatabaseFuture +- [#503](https://github.com/groue/GRDB.swift/pull/503): IFNULL support for association aggregates +- [#508](https://github.com/groue/GRDB.swift/pull/508) by [@michaelkirk-signal](https://github.com/michaelkirk-signal): Allow Database Connection Configuration +- [#510](https://github.com/groue/GRDB.swift/pull/510) by [@charlesmchen-signal](https://github.com/charlesmchen-signal): Expose DatabaseRegion(table:) initializer +- [#515](https://github.com/groue/GRDB.swift/pull/515) by [@alextrob](https://github.com/alextrob): Add "LIMIT 1" to `fetchOne` requests +- [#517](https://github.com/groue/GRDB.swift/pull/517): Support for SQLCipher 4 +- [#525](https://github.com/groue/GRDB.swift/pull/525): Eager Loading of HasMany associations + +### Fixed + +- [#511](https://github.com/groue/GRDB.swift/pull/511) by [@charlesmchen-signal](https://github.com/charlesmchen-signal): Fix DatabasePool.setupMemoryManagement() + +### Breaking Changes + +- Swift 4.0 and Swift 4.1 are no longer supported. Minimum Swift version is now Swift 4.2. +- iOS 8 is no longer supported. Minimum deployment target is now iOS 9.0. +- Deprecated APIs are no longer available. +- See the [Migration Guide](Documentation/GRDB3MigrationGuide.md) and the API diff below for other changes. + +### Documentation Diff + +- [SQL Interpolation](Documentation/SQLInterpolation.md): this new document describes the new SQL interpolation feature. +- The [Associations Guide](Documentation/AssociationsBasics.md) has been updated: + - [Required Protocols](Documentation/AssociationsBasics.md#required-protocols) describes which protocols your record types have to conform to in order to use Associations features. + - [The Types of Associations](Documentation/AssociationsBasics.md#the-types-of-associations) introduces the new HasManyThrough and HasOneThrough associations. + - [Convention for Database Table Names](Documentation/AssociationsBasics.md#convention-for-database-table-names) describes how GRDB inflects database table names into their singular or plural forms, depending on your usages of associations. + - [Joining And Prefetching Associated Records](Documentation/AssociationsBasics.md#joining-and-prefetching-associated-records) describes the new `including(all:)` method. + - [Fetching Values from Associations](Documentation/AssociationsBasics.md#fetching-values-from-associations) explains how to decode record types from associated requests, including requests built with the new `including(all:)` method. + - [Aggregate Operations](Documentation/AssociationsBasics.md#aggregate-operations) describes all the ways to transform association aggregates with logical, comparison and arithmetic operators. + +### API diff + +
+ Associations: indirect associations and eager loading of HasMany associations + +**New AssociationToOne and AssociationToMany protocols** + +```diff ++protocol AssociationToOne: Association { } ++protocol AssociationToMany: Association { } ++extension AssociationToMany { ++ var count: AssociationAggregate { get } ++ var isEmpty: AssociationAggregate { get } ++ func average(_ expression: SQLExpressible) -> AssociationAggregate ++ func max(_ expression: SQLExpressible) -> AssociationAggregate ++ func min(_ expression: SQLExpressible) -> AssociationAggregate ++ func sum(_ expression: SQLExpressible) -> AssociationAggregate ++} + ++extension BelongsToAssociation: AssociationToOne { } ++extension HasManyAssociation: AssociationToMany { } ++extension HasOneAssociation: AssociationToOne { } +``` + +**New HasManyThroughAssociation and HasOneThroughAssociation** + +```diff ++struct HasManyThroughAssociation: AssociationToMany { } ++extension HasManyThroughAssociation: TableRequest where Destination: TableRecord { } ++struct HasOneThroughAssociation: AssociationToOne { } ++extension HasOneThroughAssociation: TableRequest where Destination: TableRecord { } + + extension TableRecord { ++ static func hasMany(_ destination: Target.RowDecoder.Type, through pivot: Pivot, using target: Target, key: String? = nil) -> HasManyThroughAssociation where Pivot: Association, Target: Association, Pivot.OriginRowDecoder == Self, Pivot.RowDecoder == Target.OriginRowDecoder ++ static func hasOne(_ destination: Target.RowDecoder.Type, through pivot: Pivot, using target: Target, key: String? = nil) -> HasOneThroughAssociation where Pivot: AssociationToOne, Target: AssociationToOne, Pivot.OriginRowDecoder == Self, Pivot.RowDecoder == Target.OriginRowDecoder + } +``` + +**Eager loading of HasMany associations** + +```diff + extension TableRecord { ++ static func including(all association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == Self + } + + extension Association { ++ func including(all association: A) -> Self where A.OriginRowDecoder == RowDecoder + } + + extension QueryInterfaceRequest { ++ func including(all association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == RowDecoder + } +``` + +**Accessing eager loaded rows** + +```diff + class Row { ++ var prefetchedRows: Row.PrefetchedRowsView { get } ++ subscript(_ key: String) -> Collection where Collection: RangeReplaceableCollection, Collection.Element: FetchableRecord { get } ++ subscript(_ key: String) -> Set { get } + } + + extension Row { ++ struct PrefetchedRowsView: Equatable { ++ var isEmpty: Bool { get } ++ var keys: Set { get } ++ subscript(_ key: String) -> [Row]? { get } ++ } + } +``` + +
+ +
+ SQL Interpolation + +```diff ++extension SQLRequest: ExpressibleByStringInterpolation { ++ init(stringInterpolation sqlInterpolation: SQLInterpolation) ++} + ++struct SQLLiteral: ExpressibleByStringInterpolation { ++ var sql: String { get } ++ var arguments: StatementArguments { get } ++ init(stringInterpolation sqlInterpolation: SQLInterpolation) ++ init(sql: String, arguments: StatementArguments = StatementArguments()) ++ func mapSQL(_ transform: (String) throws -> String) rethrows -> SQLLiteral ++ mutating func append(sql: String, arguments: StatementArguments = StatementArguments()) ++ mutating func append(literal sqlLiteral: SQLLiteral) ++ static func + (lhs: SQLLiteral, rhs: SQLLiteral) -> SQLLiteral ++ static func += (lhs: inout SQLLiteral, rhs: SQLLiteral) ++} + ++extension Sequence where Element == SQLLiteral { ++ func joined(separator: String = "") -> SQLLiteral ++} + ++struct SQLInterpolation: StringInterpolationProtocol { ++ mutating func appendLiteral(_ sql: String) ++ mutating func appendInterpolation(sql: String, arguments: StatementArguments = StatementArguments()) ++ mutating func appendInterpolation(literal sqlLiteral: SQLLiteral) ++ mutating func appendInterpolation(_ table: T.Type) ++ mutating func appendInterpolation(tableOf record: T) ++ mutating func appendInterpolation(_ selection: SQLSelectable) ++ mutating func appendInterpolation(_ expressible: T?) ++ mutating func appendInterpolation(_ codingKey: CodingKey) ++ mutating func appendInterpolation(_ sequence: S) where S: Sequence, S.Element: SQLExpressible ++ mutating func appendInterpolation(_ ordering: SQLOrderingTerm) ++ mutating func appendInterpolation(_ request: SQLRequest) ++} +``` + +
+ +
+ Raw SQL breaking changes + +```diff + class Database { +- func makeSelectStatement(_ sql: String) throws -> SelectStatement +- func makeUpdateStatement(_ sql: String) throws -> UpdateStatement ++ func makeSelectStatement(sql: String) throws -> SelectStatement ++ func makeUpdateStatement(sql: String) throws -> UpdateStatement + +- func cachedSelectStatement(_ sql: String) throws -> SelectStatement +- func cachedUpdateStatement(_ sql: String) throws -> UpdateStatement ++ func cachedSelectStatement(sql: String) throws -> SelectStatement ++ func cachedUpdateStatement(sql: String) throws -> UpdateStatement + +- func execute(_ sql: String, arguments: StatementArguments? = nil) throws ++ func execute(sql: String, arguments: StatementArguments = StatementArguments()) throws + } + + class Row { +- static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RowCursor +- static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Row] +- static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Row? ++ static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> RowCursor ++ static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Row] ++ static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Row? + } + + extension FetchableRecord { +- static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RecordCursor +- static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] +- static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? ++ static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> RecordCursor ++ static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] ++ static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? + } + + extension DatabaseValueConvertible { +- static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DatabaseValueCursor +- static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] +- static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? ++ static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> DatabaseValueCursor ++ static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] ++ static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? + } + + extension Optional where Wrapped: DatabaseValueConvertible { +- static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor +- static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Wrapped?] ++ static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor ++ static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Wrapped?] + } + + extension TableRecord { +- static func select(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest ++ static func select(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest ++ static func select(literal sqlLiteral: SQLLiteral) -> QueryInterfaceRequest +- static func select(sql: String, arguments: StatementArguments? = nil, as type: RowDecoder.Type) -> QueryInterfaceRequest ++ static func select(sql: String, arguments: StatementArguments = StatementArguments(), as type: RowDecoder.Type) -> QueryInterfaceRequest ++ static func select(literal sqlLiteral: SQLLiteral, as type: RowDecoder.Type) -> QueryInterfaceRequest +- static func filter(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest ++ static func filter(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest ++ static func filter(literal sqlLiteral: SQLLiteral) -> QueryInterfaceRequest +- static func order(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest ++ static func order(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest ++ static func order(literal sqlLiteral: SQLLiteral) -> QueryInterfaceRequest + } + + final class FetchedRecordsController { +- func setRequest(sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws ++ func setRequest(sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws + } + + extension SelectionRequest { +- func select(sql: String, arguments: StatementArguments? = nil) -> Self ++ func select(sql: String, arguments: StatementArguments = StatementArguments()) -> Self ++ func select(literal sqlLiteral: SQLLiteral) -> Self + } + + extension FilteredRequest { +- func filter(sql: String, arguments: StatementArguments? = nil) -> Self ++ func filter(sql: String, arguments: StatementArguments = StatementArguments()) -> Self ++ func filter(literal sqlLiteral: SQLLiteral) -> Self + } + + extension AggregatingRequest { +- func group(sql: String, arguments: StatementArguments? = nil) -> Self ++ func group(sql: String, arguments: StatementArguments = StatementArguments()) -> Self ++ func group(literal sqlLiteral: SQLLiteral) -> Self +- func having(sql: String, arguments: StatementArguments? = nil) -> Self ++ func having(sql: String, arguments: StatementArguments = StatementArguments()) -> Self ++ func having(literal sqlLiteral: SQLLiteral) -> Self + } + + extension OrderedRequest { +- func order(sql: String, arguments: StatementArguments? = nil) -> Self ++ func order(sql: String, arguments: StatementArguments = StatementArguments()) -> Self ++ func order(literal sqlLiteral: SQLLiteral) -> Self + } + + struct SQLRequest : FetchRequest { +- init(_ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil, cached: Bool = false) ++ init(sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil, cached: Bool = false) ++ init(literal sqlLiteral: SQLLiteral, adapter: RowAdapter? = nil, cached: Bool = false) + } + + struct SQLExpressionLiteral { +- init(_ sql: String, arguments: StatementArguments? = nil) ++ init(sql: String, arguments: StatementArguments = StatementArguments()) ++ init(literal sqlLiteral: SQLLiteral) + } +``` + +
+ +
+ EncodableRecord + +```diff ++protocol EncodableRecord { ++ func encode(to container: inout PersistenceContainer) ++ static var databaseEncodingUserInfo: [CodingUserInfoKey: Any] { get } ++ static func databaseJSONEncoder(for column: String) -> JSONEncoder ++ static var databaseDateEncodingStrategy: DatabaseDateEncodingStrategy { get } ++ static var databaseUUIDEncodingStrategy: DatabaseUUIDEncodingStrategy { get } ++} ++ ++extension EncodableRecord where Self: Encodable { ++ func encode(to container: inout PersistenceContainer) ++} ++ ++extension EncodableRecord { ++ var databaseDictionary: [String: DatabaseValue] { get } ++ func databaseEquals(_ record: Self) -> Bool ++ func databaseChanges(from record: Record) -> [String: DatabaseValue] ++} + +-protocol MutablePersistableRecord: TableRecord { } ++protocol MutablePersistableRecord: EncodableRecord, TableRecord { } +``` + +
+ +
+ ValueObservation breaking changes + +```diff + enum ValueScheduling { +- case onQueue(DispatchQueue, startImmediately: Bool) ++ case async(onQueue: DispatchQueue, startImmediately: Bool) + } + + struct ValueObservation { +- var extent: Database.TransactionObservationExtent +- static func tracking(_ regions: DatabaseRegionConvertible..., reducer: Reducer) -> ValueObservation +- static func tracking(_ regions: DatabaseRegionConvertible..., fetchDistinct fetch: @escaping (Database) throws -> Value) -> ValueObservation>> where Value: Equatable + } +``` + +
+ +
+ Customizing pluralization and singularization + +```diff ++struct Inflections { ++ init() ++ func pluralize(_ string: String) -> String ++ func singularize(_ string: String) -> String + + // Configuration ++ mutating func plural(_ pattern: String, options: NSRegularExpression.Options = [.caseInsensitive], _ template: String) ++ mutating func singular(_ pattern: String, options: NSRegularExpression.Options = [.caseInsensitive], _ template: String) ++ mutating func uncountableWords(_ words: [String]) ++ mutating func irregularSuffix(_ singular: String, _ plural: String) ++} ++ ++extension Inflections { ++ static var `default`: Inflections { get set } ++} +``` + +
+ +
+ Full Text Search breaking changes: support for SQLite 3.27 + +```diff + struct FTS3 { ++ enum Diacritics { ++ case keep ++ case removeLegacy ++ #if GRDBCUSTOMSQLITE ++ case remove ++ #endif ++ } + } + + struct FTS3TokenizerDescriptor { +- static func unicode61(removeDiacritics: Bool = true, separators: Set = [], tokenCharacters: Set = []) -> FTS3TokenizerDescriptor ++ static func unicode61(diacritics: FTS3.Diacritics = .removeLegacy, separators: Set = [], tokenCharacters: Set = []) -> FTS3TokenizerDescriptor + } + + struct FTS5 { ++ enum Diacritics { ++ case keep ++ case removeLegacy ++ #if GRDBCUSTOMSQLITE ++ case remove ++ #endif ++ } + } + + struct FTS5TokenizerDescriptor { +- static func unicode61(removeDiacritics: Bool = true, separators: Set = [], tokenCharacters: Set = []) -> FTS5TokenizerDescriptor ++ static func unicode61(diacritics: FTS5.Diacritics = .removeLegacy, separators: Set = [], tokenCharacters: Set = []) -> FTS5TokenizerDescriptor + } +``` + +
+ +
+ SQLCipher breaking changes + +```diff + struct Configuration { +- var cipherPageSize: Int +- var kdfIterations: Int + } +``` + +
+ +
+ Miscellaneous additions + +**Column initializer from CodingKey** + +```diff + struct Column { ++ init(_ codingKey: CodingKey) + } +``` + +**Association aggregates: support for the IFNULL sql operator** + +```diff ++func ?? (lhs: AssociationAggregate, rhs: SQLExpressible) -> AssociationAggregate +``` + +**Remove all orderings from a request** + +```diff + protocol OrderedRequest { ++ func unordered() + } +``` + +**Annotate requests with any value, not only association aggregates** + +```diff + protocol SelectionRequest { ++ annotated(with selection: [SQLSelectable]) -> Self + } + + extension SelectionRequest { ++ func annotated(with selection: SQLSelectable...) -> Self + } + + extension TableRecord { ++ static func annotated(with selection: [SQLSelectable]) -> QueryInterfaceRequest ++ static func annotated(with selection: SQLSelectable...) -> QueryInterfaceRequest + } +``` + +**Build a DatabaseRegion from a table name** + +```diff + struct DatabaseRegion { ++ init(table: String) + } +``` + +
+ +
+ Miscellaneous breaking changes + +```diff + enum PersistenceError: Error { +- case recordNotFound(MutablePersistableRecord) ++ case recordNotFound(databaseTableName: String, key: [String: DatabaseValue]) + } + +- class Future { } ++ class DatabaseFuture { } + + protocol FetchRequest { +- func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) ++ func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) + } + + struct AnyFetchRequest : FetchRequest { +- init(_ prepare: @escaping (Database) throws -> (SelectStatement, RowAdapter?)) ++ init(_ prepare: @escaping (Database, _ singleResult: Bool) throws -> (SelectStatement, RowAdapter?)) + } + +-final class StatementCursor: Cursor { } +``` + +**Discarded deprecated methods** + +```diff + extension Cursor { +- func flatMap(_ transform: @escaping (Element) throws -> ElementOfResult?) -> MapCursor>, ElementOfResult> + } + + struct DatabaseValue { +- func losslessConvert(sql: String? = nil, arguments: StatementArguments? = nil) -> T where T : DatabaseValueConvertible +- func losslessConvert(sql: String? = nil, arguments: StatementArguments? = nil) -> T? where T : DatabaseValueConvertible + } + + protocol DatabaseWriter { +- func readFromCurrentState(_ block: @escaping (Database) -> Void) throws + } +``` + +
+ + ## 3.7.0 Released March 9, 2019 • [diff](https://github.com/groue/GRDB.swift/compare/v3.6.2...v3.7.20) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b7f3ab8b6..65b6b22c8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -86,7 +86,6 @@ The ideas, in alphabetical order: - [Linux] - [More SQL Generation] - [Reactive Database Observation] -- [Records: Splitting Database Encoding from Ability to Write in the Database] - [SQL Console in the Debugger] - [SQLCipher in a Shared App Container] - [Static Library] @@ -97,7 +96,7 @@ The ideas, in alphabetical order: :bowtie: Public API Challenge :muscle: Hard :fire: Experimental -Associations can be enhanced in several ways. See the "Known Issues" and "Future Directions" chapter of the [Associations Guide](Documentation/AssociationsBasics.md) +Associations can be enhanced in several ways. See the "Known Issues" chapter of the [Associations Guide](Documentation/AssociationsBasics.md) ### CloudKit @@ -303,19 +302,6 @@ We already have the [RxGRDB] companion library, which offers [RxSwift](https://g We need more choices of reactive engines. -### Records: Splitting Database Encoding from Ability to Write in the Database - -:baby: Starter Task :pencil: Documentation - -Record types that know how to encode themselves in the database (converting themselves into columns and database values) currently are granted with [persistence methods] which can write in the database. Those record types all adopt the [PersistableRecord] protocol. - -But encoding a record grants other features, such as [Record Comparison], or [Requesting Associated Records]. - -This is a problem: one should not have to grant a type with persistence methods, when one just needs read-only features. - -The fix is to split database encoding from persistence methods. See [#426](https://github.com/groue/GRDB.swift/issues/426) for more information. - - ### SQL Console in the Debugger :question: Unknown Difficulty :hammer: Tooling diff --git a/DemoApps/GRDBDemoiOS/GRDBDemoWatchOS Extension/Info.plist b/DemoApps/GRDBDemoiOS/GRDBDemoWatchOS Extension/Info.plist index 831251030..0881b8b30 100644 --- a/DemoApps/GRDBDemoiOS/GRDBDemoWatchOS Extension/Info.plist +++ b/DemoApps/GRDBDemoiOS/GRDBDemoWatchOS Extension/Info.plist @@ -25,7 +25,7 @@ NSExtensionAttributes WKAppBundleIdentifier - com.github.groue.GRDBDemoiOS.watchkitapp + com.github.groue.GRDBDemoiOS2.watchkitapp NSExtensionPointIdentifier com.apple.watchkit diff --git a/DemoApps/GRDBDemoiOS/GRDBDemoWatchOS/Info.plist b/DemoApps/GRDBDemoiOS/GRDBDemoWatchOS/Info.plist index 34395e2ee..0478fa15f 100644 --- a/DemoApps/GRDBDemoiOS/GRDBDemoWatchOS/Info.plist +++ b/DemoApps/GRDBDemoiOS/GRDBDemoWatchOS/Info.plist @@ -26,7 +26,7 @@ UIInterfaceOrientationPortraitUpsideDown WKCompanionAppBundleIdentifier - com.github.groue.GRDBDemoiOS + com.github.groue.GRDBDemoiOS2 WKWatchKitApp diff --git a/DemoApps/GRDBDemoiOS/GRDBDemoiOS.xcodeproj/project.pbxproj b/DemoApps/GRDBDemoiOS/GRDBDemoiOS.xcodeproj/project.pbxproj index ff910b77f..b2c8a4853 100644 --- a/DemoApps/GRDBDemoiOS/GRDBDemoiOS.xcodeproj/project.pbxproj +++ b/DemoApps/GRDBDemoiOS/GRDBDemoiOS.xcodeproj/project.pbxproj @@ -361,7 +361,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0830; - LastUpgradeCheck = 0930; + LastUpgradeCheck = 1020; ORGANIZATIONNAME = "Gwendal Roué"; TargetAttributes = { 568E5FBE1E926430002582E0 = { @@ -383,7 +383,7 @@ }; buildConfigurationList = 56B035FE1E8D9EBE003B6DA4 /* Build configuration list for PBXProject "GRDBDemoiOS" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, @@ -589,7 +589,7 @@ DEVELOPMENT_TEAM = AMD8W895CT; INFOPLIST_FILE = "GRDBDemoWatchOS Extension/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemoiOS.watchkitapp.watchkitextension; + PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemoiOS2.watchkitapp.watchkitextension; PRODUCT_NAME = "${TARGET_NAME}"; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -606,7 +606,7 @@ DEVELOPMENT_TEAM = AMD8W895CT; INFOPLIST_FILE = "GRDBDemoWatchOS Extension/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemoiOS.watchkitapp.watchkitextension; + PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemoiOS2.watchkitapp.watchkitextension; PRODUCT_NAME = "${TARGET_NAME}"; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -624,7 +624,7 @@ DEVELOPMENT_TEAM = AMD8W895CT; IBSC_MODULE = GRDBDemoWatchOS_Extension; INFOPLIST_FILE = GRDBDemoWatchOS/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemoiOS.watchkitapp; + PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemoiOS2.watchkitapp; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -642,7 +642,7 @@ DEVELOPMENT_TEAM = AMD8W895CT; IBSC_MODULE = GRDBDemoWatchOS_Extension; INFOPLIST_FILE = GRDBDemoWatchOS/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemoiOS.watchkitapp; + PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemoiOS2.watchkitapp; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -655,6 +655,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; @@ -713,6 +714,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; @@ -769,7 +771,7 @@ DEVELOPMENT_TEAM = AMD8W895CT; INFOPLIST_FILE = GRDBDemoiOS/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemoiOS; + PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemoiOS2; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -783,7 +785,7 @@ DEVELOPMENT_TEAM = AMD8W895CT; INFOPLIST_FILE = GRDBDemoiOS/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemoiOS; + PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemoiOS2; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; diff --git a/DemoApps/GRDBDemoiOS/GRDBDemoiOS.xcodeproj/xcshareddata/xcschemes/GRDBDemoWatchOS.xcscheme b/DemoApps/GRDBDemoiOS/GRDBDemoiOS.xcodeproj/xcshareddata/xcschemes/GRDBDemoWatchOS.xcscheme index 16013f9a2..e7450b0c6 100644 --- a/DemoApps/GRDBDemoiOS/GRDBDemoiOS.xcodeproj/xcshareddata/xcschemes/GRDBDemoWatchOS.xcscheme +++ b/DemoApps/GRDBDemoiOS/GRDBDemoiOS.xcodeproj/xcshareddata/xcschemes/GRDBDemoWatchOS.xcscheme @@ -1,6 +1,6 @@ QueryInterfaceRequest { - return Player.order(CodingKeys.name) + return Player.order(Columns.name) } static func orderedByScore() -> QueryInterfaceRequest { - return Player.order(CodingKeys.score.desc, CodingKeys.name) + return Player.order(Columns.score.desc, Columns.name) } } diff --git a/Documentation/AssociationsBasics.md b/Documentation/AssociationsBasics.md index 4ee3f1a4b..3d9cdaf16 100644 --- a/Documentation/AssociationsBasics.md +++ b/Documentation/AssociationsBasics.md @@ -2,10 +2,13 @@ GRDB Associations ================= - [Associations Benefits] +- [Required Protocols] - [The Types of Associations] - [BelongsTo] - - [HasOne] - [HasMany] + - [HasOne] + - [HasManyThrough] + - [HasOneThrough] - [Choosing Between BelongsTo and HasOne] - [Self Joins] - [Associations and the Database Schema] @@ -16,7 +19,7 @@ GRDB Associations - [Foreign Keys] - [Building Requests from Associations] - [Requesting Associated Records] - - [Joining Methods] + - [Joining And Prefetching Associated Records] - [Combining Associations] - [Filtering Associations] - [Sorting Associations] @@ -27,14 +30,15 @@ GRDB Associations - [The Structure of a Joined Request] - [Decoding a Joined Request with a Decodable Record] - [Decoding a Joined Request with FetchableRecord] + - [Debugging Request Decoding] - [Association Aggregates] - [Available Association Aggregates] - [Annotating a Request with Aggregates] - [Filtering a Request with Aggregates] + - [Aggregate Operations] - [Isolation of Multiple Aggregates] - [DerivableRequest Protocol] - [Known Issues] -- [Future Directions] ## Associations Benefits @@ -44,12 +48,12 @@ GRDB Associations Associations streamline common operations in your code, make them safer, and more efficient. For example, consider a library application that has two record types, author and book: ```swift -struct Author: TableRecord, FetchableRecord { +struct Author { var id: Int64 var name: String } -struct Book: TableRecord, FetchableRecord { +struct Book { var id: Int64 var authorId: Int64? var title: String @@ -119,22 +123,83 @@ let bookInfos = BookInfo.fetchAll(db, request) Before we dive in, please remember that associations can not generate all possible SQL queries that involve several tables. You may also *prefer* writing SQL, and this is just OK, because your SQL skills are welcome: see the [Joined Queries Support](../README.md#joined-queries-support) chapter. +## Required Protocols + +**Associations are available on types that adopt the necessary supporting protocols.** + +When your record type is a subclass of the [Record class], all necessary protocols are already setup and ready: you can skip this chapter. + +Generally speaking, associations use the [TableRecord], [FetchableRecord], and [EncodableRecord] protocols: + +- **[TableRecord]** is the protocol that lets you declare associations between record types: + + ```swift + extension Author: TableRecord { + static let books = hasMany(Book.self) + } + + extension Book: TableRecord { + static let author = belongsTo(Author.self) + } + ``` + +- **[FetchableRecord]** makes it possible to fetch records from the database: + + ```swift + extension Author: FetchableRecord { } + + // Who's prolific? + let authors = try dbQueue.read { db in + try Author + .having(Author.books.count >= 20) + .fetchAll(db) // [Author] + } + ``` + + FetchableRecord conformance can be derived from the standard Decodable protocol. See [Codable Records] for more information. + +- **[EncodableRecord]** makes it possible to fetch associated records with the `request(for:)` method: + + ```swift + extension Book: EncodableRecord { + // The request for the author of a book. + var author: QueryInterfaceRequest { + return request(for: Book.author) + } + } + + // Who wrote this book? + let book: Book = ... + let author = try dbQueue.read { db in + try book.author.fetchOne(db) // Author? + } + ``` + + A record type can conform to EncodableRecord via the [PersistableRecord] protocol. However, PersistableRecord also grants [persistence methods], the ones that are able to insert, update, and delete rows in the database. When you'd rather keep a record type read-only, and yet profit from associations, all you need is EncodableRecord. + + EncodableRecord conformance can be derived from the standard Encodable protocol. See [Codable Records] for more information. + + The Types of Associations ========================= -GRDB handles three types of associations: +GRDB handles five types of associations: - **BelongsTo** -- **HasOne** - **HasMany** +- **HasOne** +- **HasManyThrough** +- **HasOneThrough** An association declares a link from a record type to another, as in "one book **belongs to** its author". It instructs GRDB to use the foreign keys declared in the database as support for Swift methods. Each one of the three types of associations is appropriate for a particular database situation. - [BelongsTo] -- [HasOne] - [HasMany] +- [HasOne] +- [HasManyThrough] +- [HasOneThrough] - [Choosing Between BelongsTo and HasOne] - [Self Joins] @@ -143,14 +208,11 @@ Each one of the three types of associations is appropriate for a particular data The **BelongsTo** association sets up a one-to-one connection from a record type to another record type, such as each instance of the declaring record "belongs to" an instance of the other record. -For example, if your application includes authors and books, and each book is assigned its author, you'd declare the `Book.author` association as below, with its companion property: +For example, if your application includes authors and books, and each book is assigned its author, you'd declare the `Book.author` association as below: ```swift struct Book: TableRecord { static let author = belongsTo(Author.self) - var author: QueryInterfaceRequest { - return request(for: Book.author) - } ... } @@ -159,32 +221,45 @@ struct Author: TableRecord { } ``` -The `Book.author` association will help you build [association requests]. The property lets you fetch a book's author: - -```swift -let book: Book = ... -let author = try book.author.fetchOne(db) // Author? -``` - The **BelongsTo** association between a book and its author needs that the database table for books has a column that points to the table for authors: ![BelongsToSchema](https://cdn.rawgit.com/groue/GRDB.swift/master/Documentation/Images/Associations2/BelongsToSchema.svg) -See [Convention for the BelongsTo Association] for some sample code that defines the database schema for such an association. +See [Convention for the BelongsTo Association] for some sample code that defines the database schema for such an association, and [Building Requests from Associations] in order to learn how to use it. + + +## HasMany + +The **HasMany** association indicates a one-to-many connection between two record types, such as each instance of the declaring record "has many" instances of the other record. You'll often find this association on the other side of a **BelongsTo** association. + +For example, if your application includes authors and books, and each author is assigned zero or more books, you'd declare the `Author.books` association as below: + +```swift +struct Author: TableRecord { + static let books = hasMany(Book.self) +} + +struct Book: TableRecord { + ... +} +``` + +The **HasMany** association between an author and its books needs that the database table for books has a column that points to the table for authors: + +![HasManySchema](https://cdn.rawgit.com/groue/GRDB.swift/master/Documentation/Images/Associations2/HasManySchema.svg) + +See [Convention for the HasMany Association] for some sample code that defines the database schema for such an association, and [Building Requests from Associations] in order to learn how to use it. ## HasOne -The **HasOne** association also sets up a one-to-one connection from a record type to another record type, but with different semantics, and underlying database schema. It is usually used when an entity has been denormalized into two database tables. +The **HasOne** association, like BelongsTo, sets up a one-to-one connection from a record type to another record type, but with different semantics, and underlying database schema. It is usually used when an entity has been denormalized into two database tables. -For example, if your application has one database table for countries, and another for their demographic profiles, you'd declare the `Country.demographics` association as below, with its companion property: +For example, if your application has one database table for countries, and another for their demographic profiles, you'd declare the `Country.demographics` association as below: ```swift struct Country: TableRecord { - static let demographics = hasOne(Demographics.self) - var demographics: QueryInterfaceRequest { - return request(for: Country.demographics) - } + static let demographics = hasOne(Demographics.self, key: "demographics") ... } @@ -193,51 +268,110 @@ struct Demographics: TableRecord { } ``` -The `Country.demographics` association will help you build [association requests]. The property lets you fetch a country's demographic profile: - -```swift -let country: Country = ... -let demographics = try country.demographics.fetchOne(db) // Demographics? -``` - The **HasOne** association between a country and its demographics needs that the database table for demographics has a column that points to the table for countries: ![HasOneSchema](https://cdn.rawgit.com/groue/GRDB.swift/master/Documentation/Images/Associations2/HasOneSchema.svg) -See [Convention for the HasOne Association] for some sample code that defines the database schema for such an association. +Note that this demographics example of HasOne association uses an explicit `"demographics"` key, unlike the BelongsTo and HasMany associations above. This key is necessary when you use a plural name for a one-to-one association. See [Convention for Database Table Names] for more information. + +See [Convention for the HasOne Association] for some sample code that defines the database schema for such an association, and [Building Requests from Associations] in order to learn how to use it. -## HasMany +## HasManyThrough -The **HasMany** association indicates a one-to-many connection between two record types, such as each instance of the declaring record "has many" instances of the other record. You'll often find this association on the other side of a **BelongsTo** association. - -For example, if your application includes authors and books, and each author is assigned zero or more books, you'd declare the `Author.books` association as below, with its companion property: +The **HasManyThrough** association is often used to set up a many-to-many connection with another record. This association indicates that the declaring record can be matched with zero or more instances of another record by proceeding through a third record. For example, consider the practice of passport delivery. The relevant association declarations could look like this: ```swift -struct Author: TableRecord { - static let books = hasMany(Book.self) - var books: QueryInterfaceRequest { - return request(for: Author.books) - } +struct Country: TableRecord, EncodableRecord { + static let passports = hasMany(Passport.self) + static let citizens = hasMany(Citizen.self, through: passports, using: Passport.citizen) + ... } -struct Book: TableRecord { +struct Passport: TableRecord { + static let country = belongsTo(Country.self) + static let citizen = belongsTo(Citizen.self) +} + +struct Citizen: TableRecord, EncodableRecord { + static let passports = hasMany(Passport.self) + static let countries = hasMany(Country.self, through: passports, using: Passport.country) ... } ``` -The `Author.books` association will help you build [association requests]. The property lets you fetch an author's books: +![HasManyThroughSchema](https://cdn.rawgit.com/groue/GRDB.swift/master/Documentation/Images/Associations2/HasManyThroughSchema.svg) + +The **HasManyThrough** association is also useful for setting up "shortcuts" through nested associations. For example, if a document has many sections, and a section has many paragraphs, you may sometimes want to get a simple collection of all paragraphs in the document. You could set that up this way: ```swift -let author: Author = ... -let books = try author.books.fetchAll(db) // [Book] +struct Document: TableRecord { + static let sections = hasMany(Section.self) + static let paragraphs = hasMany(Paragraph.self, through: sections, using: Section.paragraphs) + ... +} + +struct Section: TableRecord { + static let paragraphs = hasMany(Paragraph.self) + ... +} + +struct Paragraph: TableRecord { + ... +} ``` -The **HasMany** association between an author and its books needs that the database table for books has a column that points to the table for authors: +As in the examples above, **HasManyThrough** association is always built from two other associations: the `through:` and `using:` arguments. Those associations can be any other association (BelongsTo, HasMany, HasManyThrough, etc). The above `Document.paragraphs` association can also be defined, in a much more explicit way, as below: -![HasManySchema](https://cdn.rawgit.com/groue/GRDB.swift/master/Documentation/Images/Associations2/HasManySchema.svg) +```swift +struct Document: TableRecord { + static let paragraphs = hasMany( + Paragraph.self, + through: Document.hasMany(Section.self), + using: Section.hasMany(Paragraph.self)) + ... +} +``` -See [Convention for the HasMany Association] for some sample code that defines the database schema for such an association. +See [Building Requests from Associations] in order to learn how to use the HasManyThrough association. + + +## HasOneThrough + +A **HasOneThrough** association sets up a one-to-one connection with another record. This association indicates that the declaring record can be matched with one instance of another record by proceeding through a third record. For example, if each book belongs to a library, and each library has one address, then one knows where the book should be returned to: + +```swift +struct Book: TableRecord, EncodableRecord { + static let library = belongsTo(Library.self) + static let returnAddress = hasOne(Address.self, through: library, using: library.address) + ... +} + +struct Library: TableRecord { + static let address = hasOne(Address.self) + ... +} + +struct Address: TableRecord { + ... +} +``` + +![HasOneThroughSchema](https://cdn.rawgit.com/groue/GRDB.swift/master/Documentation/Images/Associations2/HasOneThroughSchema.svg) + +As in the example above, **HasOneThrough** association is always built from two other associations: the `through:` and `using:` arguments. Those associations can be any other association to one (BelongsTo, HasOne, HasOneThrough). The above `Book.returnAddress` association can also be defined, in a much more explicit way, as below: + +```swift +struct Book: TableRecord { + static let returnAddress = hasOne( + Address.self, + through: Book.belongsTo(Library.self), + using: Library.hasOne(Address.self)) + ... +} +``` + +See [Building Requests from Associations] in order to learn how to use the HasOneThrough association. ## Choosing Between BelongsTo and HasOne @@ -251,12 +385,12 @@ A country **has one** demographic profile, a demographic profile **belongs to** ![HasOneSchema](https://cdn.rawgit.com/groue/GRDB.swift/master/Documentation/Images/Associations2/HasOneSchema.svg) ```swift -struct Country: TableRecord, FetchableRecord { +struct Country: TableRecord { static let demographics = hasOne(Demographics.self) ... } -struct Demographics: TableRecord, FetchableRecord { +struct Demographics: TableRecord { static let country = belongsTo(Country.self) ... } @@ -268,8 +402,9 @@ When designing your data model, you will sometimes find a record that should hav ```swift struct Employee { - static let subordinates = hasMany(Employee.self) - static let manager = belongsTo(Employee.self) + static let subordinates = hasMany(Employee.self, key: "subordinates") + static let manager = belongsTo(Employee.self, key: "manager") + ... } ``` @@ -289,6 +424,24 @@ migrator.registerMigration("Employees") { db in } ``` +Note that both sides of the self-join use a customized **[association key](#the-structure-of-a-joined-request)**. This helps consuming this association. For example: + +```swift +struct EmployeeInfo: FetchableRecord, Decodable { + var employee: Employee + var manager: Employee? + var subordinates: Set +} + +let request = Employee + .including(optional: Employee.manager) + .including(all: Employee.subordinates) + +let employeeInfos: [EmployeeInfo] = try EmployeeInfo.fetchAll(db, request) +``` + +See [Fetching Values from Associations] for more information. + Associations and the Database Schema ==================================== @@ -303,72 +456,64 @@ Those conventions help associations be convenient and, generally, "just work". W - [Convention for Database Table Names] - [Convention for the BelongsTo Association] -- [Convention for the HasOne Association] - [Convention for the HasMany Association] +- [Convention for the HasOne Association] - [Foreign Keys] ## Convention for Database Table Names -**Database table names should be singular and camel-cased.** +**Database table names should be written in English, singular, and camelCased.** Make them look like Swift identifiers: `book`, `author`, `postalAddress`. -This convention helps fetching values from associations. It is used, for example, in the sample code below, where we load all pairs of books along with their authors: +If the database schema does not follow this convention, and has, for example, database tables which are named with underscores (`postal_address`), you can still use associations. But you need to help row consumption by naming your associations with a customized key: ```swift -// The Author record -struct Author: FetchableRecord, TableRecord { +// Setup for table names that does not follow the expected convention + +struct PostalAddress: TableRecord { + // Customized table name + static let databaseTableName = "postal_address" } -// The Book record -struct Book: FetchableRecord, TableRecord { - static let author = belongsTo(Author.self) +extension Author { + // Customized association key + static let postalAddress = belongsTo(PostalAddress.self, key: "postalAddress") } - -// A pair made of a book and its author -struct BookInfo: FetchableRecord, Decodable { - let book: Book - let author: Author? -} - -let request = Book.including(optional: Book.author) -let bookInfos = BookInfo.fetchAll(db, request) ``` -This sample code only works if the database table for authors is called "author". The name "author" is the key that helps BookInfo initialize its `author` property. For your convenience, "author" is also the default value of the `Author.databaseTableName` property (see the [TableRecord] protocol). +GRDB will automatically **pluralize** or **singularize** names in order to help you easily associate records. -If the database schema does not follow this convention, and has, for example, database tables named with plural names (`authors` and `books`), you can still use associations. But you need to help row consumption by providing the required key: +For example, the Book and Author records will automatically feed properties named `books`, `author`, or `bookCount` in your decoded records, without any explicit configuration, as long as the names of the backing database tables are "book" and "author". -```swift -// Setup for customized table names +The GRDB pluralization mechanisms are very powerful, being capable of pluralizing and singularizing both regular and irregular words (it's directly inspired from the battle-tested [Ruby on Rails inflections](https://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-pluralize)). -struct Author: FetchableRecord, TableRecord { - // Customized table name - static let databaseTableName = "authors" -} +When using class names composed of two or more words, the table name should use the camelCase singular form: -struct Book: FetchableRecord, TableRecord { - // Customized table name - static let databaseTableName = "books" - - // Explicit association key - static let author = belongsTo(Author.self, key: "author") -} -``` +| RecordType | Table Name | Derived identifiers | +| ---------- | ---------- | ------------------- | +| Book | book | `book`, `books`, `bookCount` | +| LineItem | lineItem | `lineItem`, `lineItems`, `lineItemPriceSum` | +| Mouse | mouse | `mouse`, `mice`, `maxMouseSize` | +| Person | person | `person`, `people`, `personCount` | + +If your application relies on non-English names, GRDB may generate unexpected identifiers. If this happens, please [open an issue](http://github.com/groue/GRDB.swift/issues). See [The Structure of a Joined Request] for more information. ## Convention for the BelongsTo Association -**[BelongsTo] associations should be supported by an SQLite foreign key.** - -Foreign keys are the recommended way to declare relationships between database tables. Not only will SQLite guarantee the integrity of your data, but GRDB will be able to use those foreign keys to automatically configure your associations. +```swift +extension Book: TableRecord { + static let author = belongsTo(Author.self) +} +``` ![BelongsToSchema](https://cdn.rawgit.com/groue/GRDB.swift/master/Documentation/Images/Associations2/BelongsToSchema.svg) -The matching [migration] could look like: +Here is the recommended [migration] for the **[BelongsTo]** association: ```swift migrator.registerMigration("Books and Authors") { db in @@ -393,23 +538,23 @@ migrator.registerMigration("Books and Authors") { db in 4. Create an index on the `book.authorId` column in order to ease the selection of an author's books. 5. Create a foreign key from `book.authorId` column to `authors.id`, so that SQLite guarantees that no book refers to a missing author. The `onDelete: .cascade` option has SQLite automatically delete all of an author's books when that author is deleted. See [Foreign Key Actions] for more information. -The example above uses auto-incremented primary keys. But generally speaking, all primary keys are supported. +The example above uses auto-incremented primary keys. But generally speaking, all primary keys are supported, including composite primary keys that span several columns. Following this convention lets you write, for example: ```swift -struct Book: FetchableRecord, TableRecord { +struct Book: TableRecord { static let author = belongsTo(Author.self) } -struct Author: FetchableRecord, TableRecord { +struct Author: TableRecord { } ``` If the database schema does not follow this convention, and does not define foreign keys between tables, you can still use **BelongsTo** associations. But your help is needed to define the missing foreign key: ```swift -struct Book: FetchableRecord, TableRecord { +struct Book: TableRecord { static let author = belongsTo(Author.self, using: ForeignKey(...)) } ``` @@ -417,15 +562,76 @@ struct Book: FetchableRecord, TableRecord { See [Foreign Keys] for more information. +## Convention for the HasMany Association + +```swift +extension Author: TableRecord { + static let books = hasMany(Book.self) +} +``` + +![HasManySchema](https://cdn.rawgit.com/groue/GRDB.swift/master/Documentation/Images/Associations2/HasManySchema.svg) + +Here is the recommended [migration] for the **[HasMany]** association: + +```swift +migrator.registerMigration("Books and Authors") { db in + try db.create(table: "author") { t in + t.autoIncrementedPrimaryKey("id") // (1) + t.column("name", .text) + } + try db.create(table: "book") { t in + t.autoIncrementedPrimaryKey("id") + t.column("authorId", .integer) // (2) + .notNull() // (3) + .indexed() // (4) + .references("author", onDelete: .cascade) // (5) + t.column("title", .text) + } +} +``` + +1. The `author` table has a primary key. +2. The `book.authorId` column is used to link a book to the author it belongs to. +3. Make the `book.authorId` column not null if you want SQLite to guarantee that all books have an author. +4. Create an index on the `book.authorId` column in order to ease the selection of an author's books. +5. Create a foreign key from `book.authorId` column to `authors.id`, so that SQLite guarantees that no book refers to a missing author. The `onDelete: .cascade` option has SQLite automatically delete all of an author's books when that author is deleted. See [Foreign Key Actions] for more information. + +The example above uses auto-incremented primary keys. But generally speaking, all primary keys are supported, including composite primary keys that span several columns. + +Following this convention lets you write, for example: + +```swift +struct Book: TableRecord { +} + +struct Author: TableRecord { + static let books = hasMany(Book.self) +} +``` + +If the database schema does not follow this convention, and does not define foreign keys between tables, you can still use **HasMany** associations. But your help is needed to define the missing foreign key: + +```swift +struct Author: TableRecord { + static let books = hasMany(Book.self, using: ForeignKey(...)) +} +``` + +See [Foreign Keys] for more information. + + ## Convention for the HasOne Association -**[HasOne] associations should be supported by an SQLite foreign key.** - -Foreign keys are the recommended way to declare relationships between database tables. Not only will SQLite guarantee the integrity of your data, but GRDB will be able to use those foreign keys to automatically configure your associations. +```swift +extension Country: TableRecord { + static let demographics = hasOne(Demographics.self) +} +``` ![HasOneSchema](https://cdn.rawgit.com/groue/GRDB.swift/master/Documentation/Images/Associations2/HasOneSchema.svg) -The matching [migration] could look like: +Here is the recommended [migration] for the **[HasOne]** association: ```swift migrator.registerMigration("Countries") { db in @@ -451,23 +657,23 @@ migrator.registerMigration("Countries") { db in 4. Create a unique index on the `demographics.countryCode` column in order to guarantee the unicity of any country's profile. 5. Create a foreign key from `demographics.countryCode` column to `country.code`, so that SQLite guarantees that no profile refers to a missing country. The `onDelete: .cascade` option has SQLite automatically delete a profile when its country is deleted. See [Foreign Key Actions] for more information. -The example above uses a string primary key for the "country" table. But generally speaking, all primary keys are supported. +The example above uses a string primary key for the "country" table. But generally speaking, all primary keys are supported, including composite primary keys that span several columns. Following this convention lets you write, for example: ```swift -struct Country: FetchableRecord, TableRecord { +struct Country: TableRecord { static let demographics = hasOne(Demographics.self) } -struct Demographics: FetchableRecord, TableRecord { +struct Demographics: TableRecord { } ``` If the database schema does not follow this convention, and does not define foreign keys between tables, you can still use HasOne associations. But your help is needed to define the missing foreign key: ```swift -struct Country: FetchableRecord, TableRecord { +struct Country: TableRecord { static let demographics = hasOne(Demographics.self, using: ForeignKey(...)) } ``` @@ -475,63 +681,6 @@ struct Country: FetchableRecord, TableRecord { See [Foreign Keys] for more information. -## Convention for the HasMany Association - -**[HasMany] associations should be supported by an SQLite foreign key.** - -Foreign keys are the recommended way to declare relationships between database tables. Not only will SQLite guarantee the integrity of your data, but GRDB will be able to use those foreign keys to automatically configure your associations. - -![HasManySchema](https://cdn.rawgit.com/groue/GRDB.swift/master/Documentation/Images/Associations2/HasManySchema.svg) - -The matching [migration] could look like: - -```swift -migrator.registerMigration("Books and Authors") { db in - try db.create(table: "author") { t in - t.autoIncrementedPrimaryKey("id") // (1) - t.column("name", .text) - } - try db.create(table: "book") { t in - t.autoIncrementedPrimaryKey("id") - t.column("authorId", .integer) // (2) - .notNull() // (3) - .indexed() // (4) - .references("author", onDelete: .cascade) // (5) - t.column("title", .text) - } -} -``` - -1. The `author` table has a primary key. -2. The `book.authorId` column is used to link a book to the author it belongs to. -3. Make the `book.authorId` column not null if you want SQLite to guarantee that all books have an author. -4. Create an index on the `book.authorId` column in order to ease the selection of an author's books. -5. Create a foreign key from `book.authorId` column to `authors.id`, so that SQLite guarantees that no book refers to a missing author. The `onDelete: .cascade` option has SQLite automatically delete all of an author's books when that author is deleted. See [Foreign Key Actions] for more information. - -The example above uses auto-incremented primary keys. But generally speaking, all primary keys are supported. - -Following this convention lets you write, for example: - -```swift -struct Book: FetchableRecord, TableRecord { -} - -struct Author: FetchableRecord, TableRecord { - static let books = hasMany(Book.self) -} -``` - -If the database schema does not follow this convention, and does not define foreign keys between tables, you can still use **HasMany** associations. But your help is needed to define the missing foreign key: - -```swift -struct Author: FetchableRecord, TableRecord { - static let books = hasMany(Book.self, using: ForeignKey(...)) -} -``` - -See [Foreign Keys] for more information. - - ## Foreign Keys **Associations can automatically infer the foreign keys that define how two database tables are linked together.** @@ -609,12 +758,10 @@ Building Requests from Associations **Once you have defined associations, you can define fetch request that involve several record types.** -> :point_up: **Note**: Those requests are executed by SQLite as *SQL joined queries*. In all examples below, we'll show the SQL queries executed by our association-based requests. You can ignore them if you are not familiar with SQL. - Fetch requests do not visit the database until you fetch values from them. This will be covered in [Fetching Values from Associations]. But before you can fetch anything, you have to describe what you want to fetch. This is the topic of this chapter. - [Requesting Associated Records] -- [Joining Methods] +- [Joining And Prefetching Associated Records] - [Combining Associations] - [Filtering Associations] - [Sorting Associations] @@ -627,40 +774,42 @@ Fetch requests do not visit the database until you fetch values from them. This **You can use associations to build requests for associated records.** -For example, given a `Book.author` **[BelongsTo]** association, you can build a request for the author of a book. In the example below, we return this request from the `Book.author` property: +For example, given a `Book.author` **[BelongsTo]** association, you can build a request for the author of a book with the `request(for:)` method. In the example below, we return this request from the `Book.author` property: ```swift -struct Book: PersistableRecord { +struct Book: TableRecord, EncodableRecord { + /// The association from a book to is author static let author = belongsTo(Author.self) - /// The request for a book's author + /// The request for the author of a book var author: QueryInterfaceRequest { return request(for: Book.author) } } ``` -This request can fetch a book's author: +You can now fetch the author of a book: ```swift let book: Book = ... -let author = try book.author.fetchOne(db) // Author? +let author = try book.author.fetchOne(db) // Author? ``` -**[HasOne]** and **[HasMany]** associations can also build requests for associated records. For example: +All other associations, **[HasOne]**, **[HasMany]**, **[HasOneThrough]**, and **[HasManyThrough]**, can also build requests for associated records. For example: ```swift -struct Author: PersistableRecord { +struct Author: TableRecord, EncodableRecord { + /// The association from an author to its books static let books = hasMany(Book.self) - /// The request for an author's books + /// The request for the books of an author var books: QueryInterfaceRequest { return request(for: Author.books) } } let author: Author = ... -let books = try author.books.fetchAll(db) // [Book] +let books = try author.books.fetchAll(db) // [Book] ``` Requests for associated records can be filtered and ordered like all [query interface requests]: @@ -670,39 +819,44 @@ let novels = try author .books .filter(Column("kind") == BookKind.novel) .order(Column("publishDate").desc) - .fetchAll(db) + .fetchAll(db) // [Book] ``` -Those requests can also turn out useful when you want to track their changes with database observation tools like [RxGRDB](http://github.com/RxSwiftCommunity/RxGRDB): +Those requests can also turn out useful when you want to track their changes with [database observation tools] like [ValueObservation]: ```swift // Track changes in the author's books: let author: Author = ... -author.books.rx - .fetchAll(in: dbQueue) - .subscribe(onNext: { (books: [Book]) in +ValueObservation + .trackingAll(author.books) + .start(in: dbQueue) { (books: [Book]) in print("Author's book have changed") - }) + } ``` -## Joining Methods +## Joining And Prefetching Associated Records -**You build requests that involve several records with the four "joining methods":** +**You build requests that involve several records with the following "joining methods":** -- `including(optional: association)` -- `including(required: association)` - `joining(optional: association)` - `joining(required: association)` +- `including(optional: association)` +- `including(required: association)` +- `including(all: associationToMany)` Before we describe them in detail, let's see a few requests they can build: ```swift -/// All books with their respective authors +/// All authors with their respective books +let request = Author + .including(all: Author.books) + +/// All books with their respective author let request = Book .including(required: Book.author) -/// All books with their respective authors, sorted by title +/// All books with their respective author, sorted by title let request = Book .order(Column("title")) .including(required: Book.author) @@ -720,48 +874,70 @@ The pattern is always the same: you start from a base request, that you extend w If yes, use `including(...)`. Otherwise, use `joining(...)`. - For example, to load all books with their respective authors, you want authors to be fetched, and you use `including`: + For example, to load books with their respective author, you use `including(required:)`: ```swift - /// All books with their respective authors + // All books with their respective author let request = Book .including(required: Book.author) + + // This request can feed the following record: + struct BookInfo: FetchableRecord, Decodable { + var book: Book + var author: Author // the required associated author + } + let bookInfos: [BookInfo] = try BookInfo.fetchAll(db, request) + ``` + + And to load authors with their respective books, you use `including(all:)`: + + ```swift + // All authors with their respective books + let request = Author + .including(all: Author.books) + + // This request can feed the following record: + struct AuthorInfo: FetchableRecord, Decodable { + var author: Author + var books: [Book] // all associated books + } + let authorInfos: [AuthorInfo] = try AuthorInfo.fetchAll(db, request) ``` On the other side, to load all books written by a French author, you sure need to filter authors, but you don't need them to be present in the fetched results. You prefer `joining`: ```swift - /// All books written by a French author + // All books written by a French author let request = Book .joining(required: Book.author.filter(Column("countryCode") == "FR")) + + // This request feeds the Book record: + let books: [Book] = try request.fetchAll(db) ``` -2. Should the request allow missing associated records? +2. For to-one associations, should the request allow missing associated records? If yes, choose the `optional` variant. Otherwise, choose `required`. For example, to load all books with their respective authors, even if the book has no recorded author, you'd use `including(optional:)`: ```swift - /// All books with their respective (eventual) authors - /// (One Thousand and One Nights should be there) + // All books with their respective (eventual) authors let request = Book .including(optional: Book.author) + + // This request can feed the following record: + struct BookInfo: FetchableRecord, Decodable { + var book: Book + var author: Author? // the optional associated author + } + let bookInfos: [BookInfo] = try BookInfo.fetchAll(db, request) ``` You can remember to use `optional` when the fetched associated records should feed optional Swift values, of type `Author?`. Conversely, when the fetched results feed non-optional values of type `Author`, prefer `required`. Another way to describe the difference is that `required` filters the fetched results in order to discard missing associated records, when `optional` does not filter anything, and lets missing values pass through. - For example, consider this request: - - ```swift - let request = Book - .joining(optional: Book.author.filter(Column("countryCode") == "FR")) - ``` - - It fetches books that have a French author, but also those who don't :sweat_smile:. It's just another way to tell `Book.all()`. But we'll see below that such join can turn out useful. - Finally, readers who speak SQL may compare `optional` with left joins, and `required` with inner joins. @@ -779,6 +955,14 @@ You can join several associations in parallel: let request = Book .including(required: Book.author) .including(optional: Book.translator) + +// This request can feed the following record: +struct BookInfo: FetchableRecord, Decodable { + var book: Book + var author: Person + var translator: Person? +} +let bookInfos: [BookInfo] = try BookInfo.fetchAll(db, request) ``` The request above fetches all books, along with their author and eventual translator. @@ -793,11 +977,19 @@ You can chain associations in order to jump from a record to another: let request = Book .including(required: Book.author .including(optional: Person.country)) + +// This request can feed the following record: +struct BookInfo: FetchableRecord, Decodable { + var book: Book + var author: Author + var country: Country? +} +let bookInfos: [BookInfo] = try BookInfo.fetchAll(db, request) ``` The request above fetches all books, along with their author, and their author's country. -When you chain associations, you can avoid fetching intermediate values by replacing the `including` method with `joining`: +When you chain associations, you can avoid fetching intermediate tables by replacing the `including` method with `joining`. The request below fetches all books, along with their author's country, but does not include the intermediate authors in the fetched results: ```swift // SELECT book.*, country.* @@ -807,9 +999,31 @@ When you chain associations, you can avoid fetching intermediate values by repla let request = Book .joining(optional: Book.author .including(optional: Person.country)) + +// This request can feed the following record: +struct BookInfo: FetchableRecord, Decodable { + var book: Book + var country: Country? +} +let bookInfos: [BookInfo] = try BookInfo.fetchAll(db, request) ``` -The request above fetches all books, along with their author's country. +**[HasOneThrough]** and **[HasManyThrough]** associations provide a shortcut for those requests that skip intermediate tables: + +```swift +// SELECT book.*, country.* +// FROM book +// LEFT JOIN person ON person.id = book.authorId +// LEFT JOIN country ON country.code = person.countryCode +let request = Book.including(optional: Book.country) + +// This request can feed the following record: +struct BookInfo: FetchableRecord, Decodable { + var book: Book + var country: Country? +} +let bookInfos: [BookInfo] = try BookInfo.fetchAll(db, request) +``` > :warning: **Warning**: you can not currently chain a required association behind an optional association: > @@ -836,10 +1050,33 @@ The `filter(_:)`, `filter(key:)` and `filter(keys:)` methods, that you already k // AND person.countryCode = 'FR' let frenchAuthor = Book.author.filter(Column("countryCode") == "FR") let request = Book.joining(required: frenchAuthor) + +// This request feeds the Book record: +let books: [Book] = try request.fetchAll(db) ``` The request above fetches all books written by a French author. +The one below fetches all authors along with their novels and poems: + +```swift +let request = Author + .including(all: Author.book + .filter(Column("kind") == "novel") + .forKey("novels")) + .including(all: Author.book + .filter(Column("kind") == "poems") + .forKey("poems")) + +// This request can feed the following record: +struct AuthorInfo: FetchableRecord, Decodable { + var author: Author + var novels: [Book] + var poems: [Book] +} +let authorInfos: [AuthorInfo] = try AuthorInfo.fetchAll(db, request) +``` + **There are more filtering options:** - Filtering on conditions that involve several tables. @@ -907,41 +1144,7 @@ let restrictedAuthor = Book.author.select(Column("id"), Column("name")) let request = Book.including(required: restrictedAuthor) ``` -To specify the default selection for all inclusions of a given type, define the `databaseSelection` property: - -```swift -struct RestrictedAuthor: TableRecord { - static let databaseSelection: [SQLSelectable] = [Column("id"), Column("name")] -} - -struct ExtendedAuthor: TableRecord { - static let databaseSelection: [SQLSelectable] = [AllColumns(), Column.rowID] -} - -extension Book { - static let restrictedAuthor = belongsTo(RestrictedAuthor.self) - static let extendedAuthor = belongsTo(ExtendedAuthor.self) -} - -// SELECT book.*, author.id, author.name -// FROM book -// JOIN author ON author.id = book.authorId -let request = Book.including(required: Book.restrictedAuthor) - -// SELECT book.*, author.*, author.rowid -// FROM book -// JOIN author ON author.id = book.authorId -let request = Book.including(required: Book.extendedAuthor) -``` - -Modifying `databaseSelection` not only affects joined requests, but all requests built from the modified record. This is how records make sure they are always fed with the columns they need, no more, no less: - -```swift -// SELECT id, name FROM author -let request = RestrictedAuthor.all() -``` - -> :point_up: **Note**: make sure the `databaseSelection` property is explicitely declared as `[SQLSelectable]`. If it is not, the Swift compiler may infer a type which may silently miss the protocol requirement, resulting in sticky SELECT * requests. See [Columns Selected by a Request](../README.md#columns-selected-by-a-request) for further information. +To specify the default selection for all inclusions of a given type, see [Columns Selected by a Request](../README.md#columns-selected-by-a-request). ## Table Aliases @@ -1021,6 +1224,17 @@ let request = Book.aliased(bookAlias) > let books = Book.aliased(alias)... > let people = Person.aliased(alias)... > ``` +> +> :point_up: **Note**: you can't use the `including(all:)` method and use table aliases to filter the associated records on other records: +> +> ```swift +> // NOT IMPLEMENTED: loading all authors along with their posthumous books +> let authorAlias = TableAlias() +> let request = Author +> .aliased(authorAlias) +> .including(all: Author.books +> .filter(Column("publishDate") >= authorAlias[Column("deathDate")])) +> ``` ## Refining Association Requests @@ -1133,42 +1347,66 @@ When you join or include an association several times, with the same **[associat Fetching Values from Associations ================================= -We have seen in [Building Requests from Associations] how to define requests that involve several records by the mean of [Joining Methods]. +We have seen in [Joining And Prefetching Associated Records] how to define requests that involve several records. -If your application needs to display a list of books with information about their author, country, and cover image, you may build the following joined request: +To consume those requests, you will generally define a record type that matches the structure of the request. You'll make it adopt the [FetchableRecord] protocol, so that it can decode database rows. -```swift -// SELECT book.*, author.*, country.*, coverImage.* -// FROM book -// JOIN author ON author.id = book.authorId -// LEFT JOIN country ON country.code = author.countryCode -// LEFT JOIN coverImage ON coverImage.bookId = book.id -let request = Book - .including(required: Book.author - .including(optional: Author.country)) - .including(optional: Bool.coverImage) -``` +Often, you'll also make it adopt the standard Decodable protocol, because the compiler will generate the decoding code for you. -**Now is the time to tell how joined requests should be consumed.** +Each association included in the request can feed a property of the decoded record: -You will generally define a record type that matches the structure of the request. You'll make it adopt the [FetchableRecord] protocol, so that it can decode database rows. Often, you'll also make it adopt the standard Decodable protocol, because the compiler will generate the decoding code for you. +- `including(all:)` feeds an Array or Set property: -For example, the request above can be consumed into the following record: + ```swift + // All authors with their books + let request = Author.including(all: Author.books) + + struct AuthorInfo: FetchableRecord, Decodable { + var author: Author + var books: [Book] // all associated books + } + let authorInfos: [AuthorInfo] = try AuthorInfo.fetchAll(db, request) + ``` -```swift -struct BookInfo: FetchableRecord, Decodable { - var book: Book - var author: Author - var country: Country? - var coverImage: CoverImage? -} +- `including(optional:)` feeds an optional property: -let bookInfos = try BookInfo.fetchAll(db, request) // [BookInfo] -``` + ```swift + // All employees with their manager and subordinate + let request = Employee + .including(optional: Employee.manager) + .including(all: Employee.subordinates) + + struct EmployeeInfo: FetchableRecord, Decodable { + var employee: Employee + var manager: Employee? // the optional manager + var subordinates: Set + } + let employeeInfos: [EmployeeInfo] = try EmployeeInfo.fetchAll(db, request) + ``` + +- `including(required:)` feeds an non-optional property: + + ```swift + // All books with information about their author, country, and cover image: + let request = Book + .including(required: Book.author + .including(optional: Author.country)) + .including(optional: Book.coverImage) + + struct BookInfo: FetchableRecord, Decodable { + var book: Book + var author: Author // the required author + var country: Country? + var coverImage: CoverImage? + } + + let bookInfos: [BookInfo] = try BookInfo.fetchAll(db, request) + ``` - [The Structure of a Joined Request] - [Decoding a Joined Request with a Decodable Record] - [Decoding a Joined Request with FetchableRecord] +- [Debugging Request Decoding] - [Good Practices for Designing Record Types] - in this general guide about records, check out the "Compose Records" chapter. @@ -1182,25 +1420,14 @@ Below, author and cover image are both associated to book, and country is associ let request = Book .including(required: Book.author .including(optional: Author.country)) - .including(optional: Bool.coverImage) + .including(optional: Book.coverImage) ``` This request builds the following **tree of association keys**: ![TreeOfAssociationKeys](https://cdn.rawgit.com/groue/GRDB.swift/master/Documentation/Images/Associations2/TreeOfAssociationKeys.svg) -**Association keys** are strings. They are the names of the database tables of associated records (unless you specify otherwise, as we'll see below). - -Those keys are associated with slices in the fetched rows: - -![TreeOfAssociationKeysMapping](https://cdn.rawgit.com/groue/GRDB.swift/master/Documentation/Images/Associations2/TreeOfAssociationKeysMapping.svg) - -We'll see below how this tree of association keys and row slices can feed a Decodable record type. We'll then add some details by using FetchableRecord without Decodable support. - - -## Decoding a Joined Request with a Decodable Record - -When **association keys** match the property names of a Decodable record, you get free decoding of joined requests into this record: +Requests can feed record types whose property names match those association keys: ```swift struct BookInfo: FetchableRecord, Decodable { @@ -1210,25 +1437,65 @@ struct BookInfo: FetchableRecord, Decodable { var coverImage: CoverImage? } -let bookInfos = try BookInfo.fetchAll(db, request) // [BookInfo] +let bookInfos: [BookInfo] = try BookInfo.fetchAll(db, request) +``` + +By default, **association keys** are the names of the database tables of associated records. Keys are automatically [singularized or pluralized](#convention-for-database-table-names), depending of the cardinality of the included association: + +```swift +extension Author { + static let books = hasMany(Book.self) +} +Author.including(all: Author.books) // association key "books" + +extension Book { + static let author = belongsTo(Author.self) +} +Book.including(required: Book.author) // association key "author" +``` + +Keys can be customized when the association is defined: + +```swift +extension Employee { + static let manager = belongsTo(Employee.self, key: "manager") +} +Employee.including(optional: Employee.manager) // association key "manager" +``` + +Keys can also be customized with the `forKey` method: + +```swift +extension Author { + static let novels = books + .filter(Column("kind") == "novel") + .forKey("novels") +} +Author.including(all: Author.novels) // association key "novels" +``` + + +## Decoding a Joined Request with a Decodable Record + +When **association keys** match the property names of a Decodable record, you get free decoding of joined requests into this record: + +```swift +let request = Book + .including(required: Book.author + .including(optional: Author.country)) + .including(optional: Book.coverImage) + +struct BookInfo: FetchableRecord, Decodable { + var book: Book + var author: Author + var country: Country? + var coverImage: CoverImage? +} +let bookInfos: [BookInfo] = try BookInfo.fetchAll(db, request) ``` We see that a hierarchical tree has been flattened in the `BookInfo` record. -This flattening is made possible because the BookInfo initializer generated by the Decodable protocol matches **coding keys** with **association keys** by performing a breadth-first search in the tree of association keys. - -This deserves a little explanation: - -You known that the Decodable protocol feeds a value's properties by looking for **coding keys**. For example, the standard built-in JSONDecoder matches those coding keys with dictionary keys in a JSON object. The GRDB record decoder also matches coding keys, but with association keys: - -![TreeOfAssociationKeysMapping](https://cdn.rawgit.com/groue/GRDB.swift/master/Documentation/Images/Associations2/TreeOfAssociationKeysMapping.svg) - -Practically speaking, the BookInfo initializer first looks for the "book" coding key. This key is not found anywhere in the tree of association keys, so the book property is initialized from the row slice associated with the root of the tree, which contains book columns. - -The BookInfo initializer then looks for the "author", "country", and "coverImage" coding keys. All those are found in the tree of association keys, and each property is initialized from its matching row slice. - -The key lookup digs into the tree of association keys, and stops as soon as a key as been found, digging into deep tree levels only if the key was not found in higher levels (that's called a "breadth-first search"). This is how we can decode a hierarchical tree into a flat record. - But sometimes your decoded records will have better reflect the hierarchical structure of the request: @@ -1238,7 +1505,7 @@ Some requests are better decoded with a Decodable record that reflects the hiera ```swift let request = Book - .including(optional: Bool.coverImage) + .including(optional: Book.coverImage) .including(required: Book.author .including(optional: Person.country)) .including(optional: Book.translator @@ -1247,17 +1514,17 @@ let request = Book This requests for all books, with their cover images, and their authors and translators. Those people are themselves decorated with their respective nationalities. -We plan to decode this request into is the following record: +We plan to decode this request into is the following nested record: ```swift struct BookInfo: FetchableRecord, Decodable { - struct AuthorInfo: Decodable { - var author: Author + struct PersonInfo: Decodable { + var person: Person var country: Country? } var book: Book - var authorInfo: AuthorInfo - var translatorInfo: AuthorInfo? + var authorInfo: PersonInfo + var translatorInfo: PersonInfo? var coverImage: CoverImage? } ``` @@ -1270,7 +1537,7 @@ And who is the most able to know those coding keys? BookInfo itself, thanks to i extension BookInfo { static func all() -> QueryInterfaceRequest { return Book - .including(optional: Bool.coverImage) + .including(optional: Book.coverImage) .including(required: Book.author .forKey(CodingKeys.authorInfo) // (1) .including(optional: Person.country)) @@ -1288,84 +1555,18 @@ let bookInfos = try BookInfo.all().fetchAll(db, request) // [BookInfo] 2. The `asRequest(of:)` method turns the request into a request of BookInfo. See [Custom Requests] for more information. -### Debugging Joined Request Decoding - -When you have difficulties building a Decodable record that successfully decodes a joined request, we advise to temporarily decode raw database rows, and inspect them. - -```swift -let request = Book - .including(required: Book.author - .including(optional: Author.country)) - .including(optional: Bool.coverImage) - -let rows = try Row.fetchAll(db, request) -print(rows[0]) -// Prints: -// ▿ [id:1, authorId:2, title:"Moby-Dick"] -// unadapted: [id:1, authorId:2, title:"Moby-Dick", id:2, name:"Herman Melville", countryCode:"US", code:"US", name:"United States of America", id:NULL, imageId:NULL, path:NULL] -// - person: [id:2, name:"Herman Melville", countryCode:"US"] -// - country: [code:"US", name:"United States of America"] -// - coverImage: [id:NULL, imageId:NULL, path:NULL] -``` - -There are two important things to look into the row debugging description: - -- the **association keys**: "person", "country", and "coverImage" in our example -- associated rows that contain only null values (coverImage). - -The associated rows that contain only null values are easy to deal with: null rows loaded from optional associated records should be decoded into Swift optionals: - -```swift -struct BookInfo: FetchableRecord, Decodable { - var book: Book - var author: Author // .including(required: Book.author) - var country: Country? // .including(optional: Author.country) - var coverImage: CoverImage? // .including(optional: Bool.coverImage) -} -``` - -**Association keys** may not match the property names of your Decodable record. In this case, use the `forKey(_:)` method. - -This can be done at the request level: - -```swift -struct BookInfo: FetchableRecord, Decodable { - var book: Book - var author: Author // Expect "author" association key - var country: Country? - var coverImage: CoverImage? -} - -let request = Book - .including(required: Book.author - .forKey("author") // Change association key - .including(optional: Author.country)) - .including(optional: Bool.coverImage) -``` - -Association keys can also be defined right into the definition of the association: - -```swift -struct Book { - static let author = belongsTo(Person.self, key: "author") -} - -let request = Book - .including(required: Book.author // "author" association key - .including(optional: Author.country)) - .including(optional: Bool.coverImage) -``` - -The best choice is up to you and the structure of your application. See also [Decoding a Hierarchical Decodable Record] for further discussion about decoding keys. - - ## Decoding a Joined Request with FetchableRecord When [Dedocable](#decoding-a-joined-request-with-a-decodable-record) records provides convenient decoding of joined rows, you may want a little more control over row decoding. -The `init(row:)` initializer of the FetchableRecord protocol is what you look after: +The `init(row:)` initializer of the [FetchableRecord] protocol is what you look after: ```swift +let request = Book + .including(required: Book.author + .including(optional: Author.country)) + .including(optional: Book.coverImage) + struct BookInfo: FetchableRecord { var book: Book var author: Author @@ -1380,7 +1581,7 @@ struct BookInfo: FetchableRecord { } } -let bookInfos = try BookInfo.fetchAll(db, request) // [BookInfo] +let bookInfos: [BookInfo] = try BookInfo.fetchAll(db, request) ``` You are already familiar with row subscripts to decode [database values](../README.md#column-values): @@ -1389,7 +1590,7 @@ You are already familiar with row subscripts to decode [database values](../READ let name: String = row["name"] ``` -When you extract a record instead of a value from a row, GRDB perfoms a breadth-first search in the tree of **association keys** defined by the joined request. If the key is not found, or only associated with columns that all contain NULL values, an optional record is decoded as nil: +When you extract a record instead of a value from a row, GRDB looks up the tree of **association keys**. If the key is not found, or only associated with columns that all contain NULL values, an optional record is decoded as nil: ```swift let author: Author = row["author"] @@ -1398,30 +1599,117 @@ let country: Country? = row["country"] You can also perform custom navigation in the tree by using *row scopes*. See [Row Adapters] for more information. +When you use the `include(all:)` method, you can decode an Array or a Set of records: + +```swift +let request = Author.including(all: Author.books) + +struct AuthorInfo: FetchableRecord { + var author: Author + var books: [Book] + + init(row: Row) { + author = Author(row: row) + books = row["books"] + } +} + +let authorInfos: [AuthorInfo] = try AuthorInfo.fetchAll(db, request) +``` + + +## Debugging Request Decoding + +When you have difficulties building a Decodable record that successfully decodes a joined request, we advise to temporarily decode raw database rows, and inspect them. + +```swift +let request = Book + .including(required: Book.author + .including(optional: Author.country)) + .including(optional: Book.coverImage) + .including(all: Book.prizes) + +let rows = try Row.fetchAll(db, request) +print(rows[0].debugDescription) +// Prints: +// ▿ [id:1, authorId:2, title:"Moby-Dick"] +// unadapted: [id:1, authorId:2, title:"Moby-Dick", id:2, name:"Herman Melville", countryCode:"US", code:"US", name:"United States of America", id:NULL, imageId:NULL, path:NULL] +// - author: [id:2, name:"Herman Melville", countryCode:"US"] +// - country: [code:"US", name:"United States of America"] +// - coverImage: [id:NULL, imageId:NULL, path:NULL] +// + prizes: 3 rows +``` + +Watch in the row debugging description: + +- the **association keys**: "person", "country", "coverImage" and "prizes" in our example +- associated rows that contain only null values ("coverImage", above). + +The associated rows that contain only null values are easy to deal with: null rows loaded from optional associated records should be decoded into Swift optionals: + +```swift +struct BookInfo: FetchableRecord, Decodable { + var book: Book + var author: Author // .including(required: Book.author) + var country: Country? // .including(optional: Author.country) + var coverImage: CoverImage? // .including(optional: Book.coverImage) + var prizes: [Prize] // .including(all: Book.prizes) +} +``` + +When the **association keys** don't match your expectations, change them (see [The Structure of a Joined Request]): + +```swift +let request = Book + .including(optional: Book.author.forKey("writer")) // customized association key + +let rows = try Row.fetchAll(db, request) +print(rows[0].debugDescription) +// Prints: +// ▿ [id:1, authorId:2, title:"Moby-Dick"] +// unadapted: [id:1, authorId:2, title:"Moby-Dick", id:2, name:"Herman Melville"] +// - writer: [id:2, name:"Herman Melville", countryCode:"US"] +``` + ## Association Aggregates -It is possible to fetch aggregated values from a **[HasMany]** association: +It is possible to fetch aggregated values from **[HasMany]** and **[HasManyThrough]** associations: Counting associated records, fetching the minimum, maximum, average value of an associated record column, computing the sum of an associated record column, these are all aggregation operations. -When you need to compute aggregates **from a single record**, you use regular aggregating methods, detailed in the [Fetching Aggregated Values] chapter. For example: +When you need to compute aggregates **from a single record**, you use [regular aggregating methods] on [requests for associated records]. For example: ```swift +struct Author: TableRecord, EncodableRecord { + static let books = hasMany(Book.self) + var books: QueryInterfaceRequest { + return request(for: Author.books) + } +} + let author: Author = ... + +// The number of books by this author let bookCount = try author.books.fetchCount(db) // Int +// The year of the most recent book by this author let request = author.books.select(max(yearColumn)) let maxBookYear = try Int.fetchOne(db, request) // Int? ``` When you need to compute aggregates **from several record**, in a single shot, you'll use an **association aggregate**. Those are the topic of this chapter. -For example, you'll use the `isEmpty` aggregate when you want, say, to fetch all authors who wrote no book at all: +For example, you'll use the `isEmpty` aggregate when you want, say, to fetch all authors who wrote no book at all, or some books: ```swift -let lazyAuthors: [Author] = try Author.having(Author.books.isEmpty).fetchAll(db) -let productiveAuthors: [Author] = try Author.having(Author.books.isEmpty == false).fetchAll(db) +let lazyAuthors = try Author + .having(Author.books.isEmpty) + .fetchAll(db) // [Author] + +let productiveAuthors: [Author] = try Author + .having(Author.books.isEmpty == false) + .fetchAll(db) // [Author] ``` And you'll use the `count` aggregate in order to fetch all authors along with the number of books they wrote: @@ -1443,7 +1731,7 @@ for info in authorInfos { ### Available Association Aggregates -**HasMany** associations let you build the following association aggregates: +**[HasMany]** and **[HasManyThrough]** associations let you build the following association aggregates: - `books.count` - `books.isEmpty` @@ -1487,64 +1775,64 @@ for info in authorInfos { } ``` -As seen in the above example, some aggregated values are given a **default name**, such as "bookCount" or "maxBookYear". The default name is built from the aggregating method, the **[association key](#the-structure-of-a-joined-request)**, and the aggregated column name: +As seen in the above example, aggregated values are given a **default name**, such as "bookCount" or "maxBookYear", which directly feeds the decoded records. -| Method | Key | Column | Default name | -| --------- | --- | ------ | ------------- | -| `Author.books.isEmpty ` | `book` | - | - | -| `Author.books.count ` | `book` | - | `bookCount` | -| `Author.books.min(Column("year"))` | `book` | `year` | `minBookYear` | -| `Author.books.max(Column("year"))` | `book` | `year` | `maxBookYear` | -| `Author.books.average(Column("price"))` | `book` | `price` | `averageBookPrice` | -| `Author.books.sum(Column("awards")) ` | `book` | `awards` | `bookAwardsSum` | +The default name is built from the aggregating method, the **[association key](#the-structure-of-a-joined-request)**, and the aggregated column name: -You give a custom name to an aggregated value with the `aliased` method: +| Method | Association Key | Aggregated Column | Aggregate name | +| ------ | --------------- | ----------------- | -------------- | +| `Author.books.isEmpty`. | `books` | - | `hasNoBook` | +| `Author.books.count`. | `books` | - | `bookCount` | +| `Author.books.min(Column("year"))` | `books` | `year` | `minBookYear` | +| `Author.books.max(Column("year"))` | `books` | `year` | `maxBookYear` | +| `Author.books.average(Column("price"))` | `books` | `price` | `averageBookPrice` | +| `Author.books.sum(Column("awards"))` | `books` | `awards` | `bookAwardsSum` | + +Those default names are lost whenever an aggregate is modified (negated, added, multiplied, whatever). + +You can name or rename aggregates with the `aliased` method: ```swift struct AuthorInfo: Decodable, FetchableRecord { var author: Author var numberOfBooks: Int } +let numberOfBooks = Author.books.count.aliased("numberOfBooks") // <-- +let request = Author.annotated(with: numberOfBooks) +let authorInfos: [AuthorInfo] = try AuthorInfo.fetchAll(db, request) -// SELECT author.*, COUNT(DISTINCT book.rowid) AS numberOfBooks -// FROM author -// LEFT JOIN book ON book.authorId = author.id -// GROUP BY author.id -let request = Author.annotated(with: Author.books.count.aliased("numberOfBooks")) +struct AuthorInfo: Decodable, FetchableRecord { + var author: Author + var hasBooks: Bool +} +let hasBooks = (Author.books.isEmpty == false).aliased("hasBooks") // <-- +let request = Author.annotated(with: hasBooks) +let authorInfos: [AuthorInfo] = try AuthorInfo.fetchAll(db, request) + +struct AuthorInfo: Decodable, FetchableRecord { + var author: Author + var workCount: Int +} +let workCount = (Author.books.count + Author.paintings.count).aliased("workCount") // <-- +let request = Author.annotated(with: workCount) let authorInfos: [AuthorInfo] = try AuthorInfo.fetchAll(db, request) ``` -The `aliased` method also accept coding keys: +Coding keys are also accepted: ```swift struct AuthorInfo: Decodable, FetchableRecord { var author: Author var numberOfBooks: Int - static func fetchAll(_ db: Database) throws -> [AuthorInfo] { - let request = Author.annotated(with: Author.books.count.aliased(CodingKey.numberOfBooks)) - return try AuthorInfo.fetchAll(db, request) + static func all() -> QueryInterfaceRequest { + let numberOfBooks = Author.books.count.aliased(CodingKey.numberOfBooks) // <-- + return Author + .annotated(with: numberOfBooks) + .asRequest(of: AuthorInfo.self) } } -``` - -Custom names help consuming complex aggregates that have no name by default: - -```swift -struct AuthorInfo: Decodable, FetchableRecord { - var author: Author - var workCount: Int -} - -// SELECT author.*, -// (COUNT(DISTINCT book.rowid) + COUNT(DISTINCT painting.rowid)) AS workCount -// FROM author -// LEFT JOIN book ON book.authorId = author.id -// LEFT JOIN painting ON painting.authorId = author.id -// GROUP BY author.id -let aggregate = Author.books.count + Author.paintings.count -let request = Author.annotated(with: aggregate.aliased("workCount")) -let authorInfos: [AuthorInfo] = try AuthorInfo.fetchAll(db, request) +let authorInfos: [AuthorInfo] = try AuthorInfo.all().fetchAll(db) ``` @@ -1689,6 +1977,91 @@ The `having(_:)` method filters a request according to an aggregated value. You ``` +### Aggregate Operations + +Aggregates can be modified and combined with Swift operators: + +- Logical operators `&&`, `||` and `!` + +
+ SQL + + ```sql + SELECT author.* + FROM author + LEFT JOIN book ON book.authorId = author.id + LEFT JOIN painting ON painting.authorId = author.id + GROUP BY author.id + HAVING ((COUNT(DISTINCT book.rowid) = 0) AND (COUNT(DISTINCT painting.rowid) = 0)) + ``` + +
+ + ```swift + let condition = Author.books.isEmpty && Author.paintings.isEmpty + let request = Author.having(condition) + ``` + +- Comparison operators `<`, `<=`, `=`, `!=`, `>=`, `>` + +
+ SQL + + ```sql + SELECT author.* + FROM author + LEFT JOIN book ON book.authorId = author.id + GROUP BY author.id + HAVING MAX(book.year) >= 2010 + ``` + +
+ + ```swift + let request = Author.having(Author.books.max(Column("year")) >= 2010) + ``` + +- Arithmetic operators `+`, `-`, `*`, `/` + +
+ SQL + + ```sql + SELECT author.*, + (COUNT(DISTINCT book.rowid) + + COUNT(DISTINCT painting.rowid)) AS workCount + FROM author + LEFT JOIN book ON book.authorId = author.id + LEFT JOIN painting ON painting.authorId = author.id + GROUP BY author.id + ``` + +
+ + ```swift + let workCount = Author.books.count + Author.paintings.count) + let request = Author.annotated(with: workCount.aliased("workCount")) + ``` + +- IFNULL operator `??` + +
+ SQL + + ```sql + SELECT "team".*, IFNULL(MIN("player"."score"), 0) AS "minPlayerScore" + FROM "team" + LEFT JOIN "player" ON ("player"."teamId" = "team"."id") + GROUP BY "team"."id" + ``` + +
+ + ```swift + let request = Team.annotated(with: Team.players.min(Column("score")) ?? 0) + ``` + + ### Isolation of Multiple Aggregates When you compute multiple aggregates, make sure they use as many distinct **[association keys](#the-structure-of-a-joined-request)** as there are distinct populations of associated records. @@ -1713,7 +2086,7 @@ In the example below, we use compute two aggregates from the same association `A ```swift struct Author: TableRecord { - static let books = hasMany(Book.self) // association key "book" + static let books = hasMany(Book.self) // association key "books" } struct AuthorInfo: Decodable, FetchableRecord { @@ -1723,8 +2096,8 @@ In the example below, we use compute two aggregates from the same association `A } let request = Author.annotated(with: - Author.books.min(Column("year")), // association key "book" - Author.books.max(Column("year"))) // association key "book" + Author.books.min(Column("year")), // association key "books" + Author.books.max(Column("year"))) // association key "books" let authorInfos: [AuthorInfo] = try AuthorInfo.fetchAll(db, request) ``` @@ -1748,8 +2121,8 @@ In this other example, the `Author.books` and `Author.paintings` have the distin ```swift struct Author: TableRecord { - static let books = hasMany(Book.self) // association key "book" - static let paintings = hasMany(Painting.self) // association key "painting" + static let books = hasMany(Book.self) // association key "books" + static let paintings = hasMany(Painting.self) // association key "paintings" } struct AuthorInfo: Decodable, FetchableRecord { @@ -1757,8 +2130,8 @@ In this other example, the `Author.books` and `Author.paintings` have the distin var workCount: Int } - let aggregate = Author.books.count + // association key "book" - Author.paintings.count // association key "painting" + let aggregate = Author.books.count + // association key "books" + Author.paintings.count // association key "paintings" let request = Author.annotated(with: aggregate.aliased("workCount")) let authorInfos: [AuthorInfo] = try AuthorInfo.fetchAll(db, request) ``` @@ -1784,7 +2157,7 @@ But in the following example, we use the same association `Author.books` twice, ```swift struct Author: TableRecord { - static let books = hasMany(Book.self) // association key "book" + static let books = hasMany(Book.self) // association key "books" } struct AuthorInfo: Decodable, FetchableRecord { @@ -1795,11 +2168,11 @@ But in the following example, we use the same association `Author.books` twice, let novelCount = Author.books .filter(Column("kind") == "novel") - .forKey("novel") // association key "novel" + .forKey("novels") // association key "novels" .count let theatrePlayCount = Author.books .filter(Column("kind") == "theatrePlay") - .forKey("theatrePlay") // association key "theatrePlay" + .forKey("theatrePlays") // association key "theatrePlays" .count let request = Author.annotated(with: novelCount, theatrePlayCount) let authorInfos: [AuthorInfo] = try AuthorInfo.fetchAll(db, request) @@ -1824,11 +2197,11 @@ But in the following example, we use the same association `Author.books` twice, ```swift // WRONG: not counting distinct sets of associated books - let novelCount = Author.books // association key "book" + let novelCount = Author.books // association key "books" .filter(Column("kind") == "novel") .count .aliased("novelCount") - let theatrePlayCount = Author.books // association key "book" + let theatrePlayCount = Author.books // association key "books" .filter(Column("kind") == "theatrePlay") .count .aliased("theatrePlayCount") @@ -1874,30 +2247,49 @@ let request = Book.joining(required: Book.author ## Known Issues -**You can't chain a required association on an optional association:** +- **You can't chain a required association on an optional association:** -```swift -// NOT IMPLEMENTED -let request = Book - .joining(optional: Book.author - .including(required: Person.country)) -``` + ```swift + // NOT IMPLEMENTED + let request = Book + .joining(optional: Book.author + .including(required: Person.country)) + ``` -This code compiles, but you'll get a runtime fatal error "Not implemented: chaining a required association behind an optional association". Future versions of GRDB may allow such requests. + This code compiles, but you'll get a runtime fatal error "Not implemented: chaining a required association behind an optional association". Future versions of GRDB may allow such requests. +- **You can't use the `including(all:)` method and use table aliases to filter the associated records on other records:** -## Future Directions + ```swift + // NOT IMPLEMENTED: loading all authors along with their posthumous books + let authorAlias = TableAlias() + let request = Author + .aliased(authorAlias) + .including(all: Author.books + .filter(Column("publishDate") >= authorAlias[Column("deathDate")])) + ``` -The APIs that have been described above do not cover the whole topic of joined requests. Among the biggest omissions, there is: +- **You can't use the `including(all:)` method with a [HasMany] and a [HasManyThrough] associations that share the same base association in the same request**: -- One can not yet join two tables without a foreign key. One can not build the plain `SELECT * FROM a JOIN b`, for example. + ```swift + // NOT IMPLEMENTED + let request = Country + .including(all: Country.passports) + .including(all: Country.citizens) + ``` -- One can not yet express requests such as "all authors with all their books". + This code compiles, but you'll get a runtime fatal error "Not implemented: merging a direct association and an indirect one with including(all:)". Future versions of GRDB may allow such requests. -- There's no HasOneThrough and HasManyThrough association, which would allow to skip intermediate bridge records when building requests. + The workaround is to nest the most remote association: + + ```swift + // Workaround + let request = Country + .including(all: Country.passports + .including(required: Passport.citizen)) + ``` -Those features are not present yet because they hide several very tough challenges. Come [discuss](http://twitter.com/groue) for more information, or if you wish to help turning those features into reality. - +Come [discuss](http://twitter.com/groue) for more information, or if you wish to help turning those missing features into reality. --- @@ -1941,9 +2333,12 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. [Associations Benefits]: #associations-benefits +[Required Protocols]: #required-protocols [BelongsTo]: #belongsto -[HasOne]: #hasone [HasMany]: #hasmany +[HasOne]: #hasone +[HasManyThrough]: #hasmanythrough +[HasOneThrough]: #hasonethrough [Choosing Between BelongsTo and HasOne]: #choosing-between-belongsto-and-hasone [Self Joins]: #self-joins [The Types of Associations]: #the-types-of-associations @@ -1961,7 +2356,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. [Fetching Values from Associations]: #fetching-values-from-associations [Combining Associations]: #combining-associations [Requesting Associated Records]: #requesting-associated-records -[Joining Methods]: #joining-methods +[requests for associated records]: #requesting-associated-records +[Joining And Prefetching Associated Records]: #joining-and-prefetching-associated-records [Filtering Associations]: #filtering-associations [Sorting Associations]: #sorting-associations [Columns Selected by an Association]: #columns-selected-by-an-association @@ -1971,18 +2367,25 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. [Decoding a Joined Request with a Decodable Record]: #decoding-a-joined-request-with-a-decodable-record [Decoding a Hierarchical Decodable Record]: #decoding-a-hierarchical-decodable-record [Decoding a Joined Request with FetchableRecord]: #decoding-a-joined-request-with-fetchablerecord +[Debugging Request Decoding]: #debugging-request-decoding [Custom Requests]: ../README.md#custom-requests [Association Aggregates]: #association-aggregates [Available Association Aggregates]: #available-association-aggregates [Annotating a Request with Aggregates]: #annotating-a-request-with-aggregates [Filtering a Request with Aggregates]: #filtering-a-request-with-aggregates +[Aggregate Operations]: #aggregate-operations [Isolation of Multiple Aggregates]: #isolation-of-multiple-aggregates [DerivableRequest Protocol]: #derivablerequest-protocol [Known Issues]: #known-issues -[Future Directions]: #future-directions [Row Adapters]: ../README.md#row-adapters [query interface requests]: ../README.md#requests [TableRecord]: ../README.md#tablerecord-protocol -[association requests]: #building-requests-from-associations [Good Practices for Designing Record Types]: GoodPracticesForDesigningRecordTypes.md -[Fetching Aggregated Values]: ../README.md#fetching-aggregated-values +[regular aggregating methods]: ../README.md#fetching-aggregated-values +[Record class]: ../README.md#record-class +[EncodableRecord]: ../README.md#persistablerecord-protocol +[PersistableRecord]: ../README.md#persistablerecord-protocol +[Codable Records]: ../README.md#codable-records +[persistence methods]: ../README.md#persistence-methods +[database observation tools]: ../README.md#database-changes-observation +[ValueObservation]: ../README.md#valueobservation diff --git a/Documentation/CustomSQLiteBuilds.md b/Documentation/CustomSQLiteBuilds.md index 933453afa..54c41f382 100644 --- a/Documentation/CustomSQLiteBuilds.md +++ b/Documentation/CustomSQLiteBuilds.md @@ -3,7 +3,7 @@ Custom SQLite Builds By default, GRDB uses the version of SQLite that ships with the target operating system. -**You can build GRDB with a custom build of [SQLite 3.25.2](https://www.sqlite.org/changes.html).** +**You can build GRDB with a custom build of [SQLite 3.27.2](https://www.sqlite.org/changes.html).** A custom SQLite build can activate extra SQLite features, and extra GRDB features as well, such as support for the [FTS5 full-text search engine](../../../#full-text-search), and [SQLite Pre-Update Hooks](../../../#support-for-sqlite-pre-update-hooks). @@ -15,7 +15,7 @@ GRDB builds SQLite with [swiftlyfalling/SQLiteLib](https://github.com/swiftlyfal ```sh cd [GRDB directory] - git checkout v3.7.0 + git checkout v4.0.0 git submodule update --init SQLiteCustom/src ```` diff --git a/Documentation/FTS5Tokenizers.md b/Documentation/FTS5Tokenizers.md index c81a6a3c6..c7b42b3f4 100644 --- a/Documentation/FTS5Tokenizers.md +++ b/Documentation/FTS5Tokenizers.md @@ -81,7 +81,7 @@ try db.create(virtualTable: "documents", using: FTS5()) { t in The full-text table can be fed and queried in [a regular way](../../../#full-text-search): ```swift -try db.execute("INSERT INTO documents VALUES (?)", arguments: ["..."]) +try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["..."]) try Document(content: "...").insert(db) let pattern = FTS5Pattern(matchingAnyTokenIn:"...") diff --git a/Documentation/GRDB2MigrationGuide.md b/Documentation/GRDB2MigrationGuide.md index bdecc50be..2e708cd5c 100644 --- a/Documentation/GRDB2MigrationGuide.md +++ b/Documentation/GRDB2MigrationGuide.md @@ -172,43 +172,33 @@ extension Player { } ``` -When your record adopts the Codable protocol, you can use its [coding keys](https://developer.apple.com/documentation/foundation/archives_and_serialization/encoding_and_decoding_custom_types) as columns: +When your record adopts the Codable protocol, you can use its [coding keys](https://developer.apple.com/documentation/foundation/archives_and_serialization/encoding_and_decoding_custom_types) to safely define database columns: ```swift // GRDB 3 -struct Player: Codable, FetchableRecord, PersistableRecord { +struct Player: Codable { var id: Int64 var name: String var score: Int - - // Add ColumnExpression conformance - private enum CodingKeys: String, CodingKey, ColumnExpression { - case id, name, score - } } -extension Player { +extension Player: FetchableRecord, PersistableRecord { + enum Columns { + static let id = Column(CodingKeys.id.stringValue) + static let name = Column(CodingKeys.name.stringValue) + static let score = Column(CodingKeys.score.stringValue) + } + static func filter(name: String) -> QueryInterfaceRequest { - return filter(CodingKeys.name == name) + return filter(Columns.name == name) } static var maximumScore: QueryInterfaceRequest { - return select(max(CodingKeys.score), as: Int.self) + return select(max(Columns.score), as: Int.self) } } ``` -GRDB can apply additional optimizations on expressions that adopt ColumnExpression, so conform to this protocol whenever you define a custom column type: - -```swift -struct TypedColumn: ColumnExpression { - var name: String - var sqlType: String -} -let nameColumn = TypedColumn(name: "name", sqlType: "VARCHAR") -let arthur = try Player.filter(nameColumn == "Arthur").fetchOne(db) -``` - ## If You Use Database Queues diff --git a/Documentation/GRDB3MigrationGuide.md b/Documentation/GRDB3MigrationGuide.md new file mode 100644 index 000000000..5f8d1c3f1 --- /dev/null +++ b/Documentation/GRDB3MigrationGuide.md @@ -0,0 +1,183 @@ +Migrating From GRDB 3 to GRDB 4 +=============================== + +GRDB 4 comes with new features, but also a few breaking changes. This guide aims at helping you upgrading your applications. + +- [New requirements](#new-requirements) +- [Raw SQL](#raw-sql) +- [ValueObservation](#valueobservation) +- [Associations](#associations) +- [SQLCipher](#sqlcipher) +- [PersistenceError.recordNotFound](#persistenceerrorrecordnotfound) + + +### New requirements + +GRDB now requires Swift 4.2+ and Xcode 10+. Swift 4.0 and 4.1 are no longer supported. Xcode 9 is no longer supported. + +iOS 8 is no longer supported. The minimum iOS target is now iOS 9. + + +### Raw SQL + +Whenever your application uses raw SQL queries or snippets, you will now always have to use the `sql` argument label: + +```swift +// GRDB 3 +try db.execute("INSERT INTO player (name) VALUES (?)", arguments: ["Arthur"]) +let playerCount = try Int.fetchOne(db, "SELECT COUNT(*) FROM player") + +// GRDB 4 +try db.execute(sql: "INSERT INTO player (name) VALUES (?)", arguments: ["Arthur"]) +let playerCount = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM player") +``` + +This change was made necessary by the introduction of [SQL Interpolation]. + + +### ValueObservation + +[ValueObservation] has been refreshed in GRDB 4. + +To guarantee asynchronous notifications, and never ever block your main thread, use the `.async(onQueue:startImmediately:)` scheduling: + +```swift +// On main queue +var observation = ValueObservation.trackingAll(Player.all()) +observation.scheduling = .async(onQueue: .main, startImmediately: true) +let observer = try observation.start(in: dbQueue) { (players: [Player]) in + // On main queue + print("fresh players: \(players)")s +} +// <- here "fresh players" is not printed yet. +``` + +In GRDB 3, this scheduling used to be named `.queue(_: startImmediately:)`. + +The second breaking change is `ValueObservation.extent`, which was removed in GRDB 4. Now all observations last until the observer returned by the `start` method is deallocated. + + +### Associations + +GRDB 4 brought a few new [associations] features: + +- **Indirect associations** [HasOneThrough] and [HasManyThrough] let you define associations from a record to another through a third one. For example, they let you easily express many-to-many relations such as "a country has many citizens through its passports": + + ```swift + struct Country: TableRecord, EncodableRecord { + static let passports = hasMany(Passport.self) + // New! + static let citizens = hasMany(Citizen.self, through: passports, using: Passport.citizen) + var citizens: QueryInterfaceRequest { + return request(for: Country.citizens) + } + } + + struct Passport: TableRecord { + static let citizen = belongsTo(Citizen.self) + } + + struct Citizen: TableRecord { + } + + let country: Country = ... + let citizens: [Citizen] = try dbQueue.read { db in + try country.citizens.fetchAll(db) + } + ``` + + ![HasManyThroughSchema](https://cdn.rawgit.com/groue/GRDB.swift/master/Documentation/Images/Associations2/HasManyThroughSchema.svg) + +- **Eager loading of HasMany associations**: The new `including(all:)` method lets you load arrays or sets of associated records in a single request: + + ```swift + // All authors with their respective books + let request = Author.including(all: Author.books) + + // This request can feed the following record: + struct AuthorInfo: FetchableRecord, Decodable { + var author: Author + var books: [Book] // all associated books + } + let authorInfos: [AuthorInfo] = try AuthorInfo.fetchAll(db, request) + ``` + + See [Joining And Prefetching Associated Records] for more information. + +- **Automatic pluralization and singularization** of association identifiers. + + GRDB will automatically **pluralize** or **singularize** names in order to help you easily associate records. + + For example, the Book and Author records will automatically feed properties named `books`, `author`, or `bookCount` in your decoded records, without any explicit configuration, as long as the names of the backing database tables are "book" and "author". + + The GRDB pluralization mechanisms are very powerful, being capable of pluralizing and singularizing both regular and irregular words (it's directly inspired from the battle-tested [Ruby on Rails inflections](https://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-pluralize)). + + However, this change may have introduced some incompatibilities with GRDB 3 associations. Check [The Structure of a Joined Request] for more information. + + +### SQLCipher + +The integration of GRDB with SQLCipher has changed. + +1. With GRDB 3, it was possible to perform a manual installation, or to use CocoaPods and the GRDBCipher pod. + + With GRDB 4, CocoaPods is the only supported installation method. And the GRDBCipher pod is discontinued, replaced with GRDB.swift/SQLCipher: + + ```diff + -pod 'GRDBCipher' + +pod 'GRDB.swift/SQLCipher' + ``` + + In your Swift code, you no longer import the GRDBCipher module, but GRDB: + + ```diff + -import GRDBCipher + +import GRDB + ``` + +2. The default SQLCipher version which comes with GRDB 4 is now SQLCipher 4, which is incompatible with SQLCipher 3. SQLCipher 3 is still supported, though. See [Encryption] for more details. + +3. The `cipherPageSize` and `kdfIterations` configuration properties are discontinued. With GRDB 4, run sql pragmas in the `prepareDatabase` property of the configuration: + + ```swift + var configuration = Configuration() + configuration.passphrase = "secret" + configuration.prepareDatabase = { db in + try db.execute(sql: "PRAGMA cipher_page_size = 4096") + try db.execute(sql: "PRAGMA kdf_iter = 128000") + } + let dbQueue = try DatabaseQueue(path: "...", configuration: configuration) + ``` + + +### PersistenceError.recordNotFound + +PersistenceError.recordNotFound is thrown whenever a record update method does not find any database row to update. It was refactored in GRDB 4: + +```swift +public enum PersistenceError: Error { + case recordNotFound(databaseTableName: String, key: [String: DatabaseValue]) +} + +do { + try player.updateChanges { + $0.score += 1000 + } +} catch let error as PersistenceError.recordNotFound { + // Update failed because player does not exist in the database + print(error) + // prints "Key not found in table player: [id:42]" +} +``` + +[SQL Interpolation]: SQLInterpolation.md +[ValueObservation]: ../README.md#valueobservation +[Encryption]: ../README.md#encryption +[HasOneThrough]: AssociationsBasics.md#hasonethrough +[HasManyThrough]: AssociationsBasics.md#hasmanythrough +[PersistableRecord]: ../README.md#persistablerecord-protocol +[associations]: AssociationsBasics.md +[EncodableRecord]: ../README.md#persistablerecord-protocol +[The Structure of a Joined Request]: AssociationsBasics.md#the-structure-of-a-joined-request +[Joining And Prefetching Associated Records]: AssociationsBasics.md#joining-and-prefetching-associated-records + diff --git a/Documentation/ReleaseProcess.md b/Documentation/ReleaseProcess.md index 249d22130..3e07324af 100644 --- a/Documentation/ReleaseProcess.md +++ b/Documentation/ReleaseProcess.md @@ -17,14 +17,12 @@ To release a new GRDB version: - CHANGELOG.md - Documentation/CustomSQLiteBuilds.md - GRDB.swift.podspec - - GRDBCipher.podspec - README.md - Support/Info.plist - Commit and tag - Check tag authors: `git for-each-ref --format '%(refname) %(authorname)' refs/tags` - Push to the master branch - `pod trunk push --allow-warnings GRDB.swift.podspec` -- `pod trunk push --allow-warnings GRDBCipher.podspec` - `make doc`, and update index.html in the `gh-pages` branch - Update http://github.com/groue/WWDCCompanion - Update [performance comparison](https://github.com/groue/GRDB.swift/wiki/Performance): diff --git a/Documentation/SQLInterpolation.md b/Documentation/SQLInterpolation.md new file mode 100644 index 000000000..571a95e13 --- /dev/null +++ b/Documentation/SQLInterpolation.md @@ -0,0 +1,418 @@ +SQL Interpolation +================= + +Your SQL skills are [welcomed] throughout GRDB. Yet writing raw SQL presents commonplace challenges. For example, you want to make sure your queries don't break whenever the database schema changes as you ship new versions of your application. When you inject user values in the database, you have to use statement arguments, and it is easy to make a mistake in the process. + +The query below exemplifies this situation. It even contains a bug that is not quite easy to spot: + +```swift +try db.execute( + sql: """ + UPDATE student + SET firstName = ?, lastName = ?, department = ?, birthDate = ?, + registrationDate = ?, mainTeacherId = ? + WHERE id = ? + """, + arguments: [firstName, lastName, department, birthDate, + registrationDate, mainTeacherId]) + +``` + +SQL Interpolation is an answer to these troubles. It is available in Swift 5. + +- [Introduction] +- [SQLLiteral] +- [SQL Interpolation and Record Protocols] +- [SQL Interpolation Reference] + + +## Introduction + +**SQL Interpolation** lets you embed values in your SQL queries by wrapping them inside `\(` and `)`: + +```swift +let name: String = ... +let id: Int64 = ... +try db.execute(literal: "UPDATE player SET name = \(name) WHERE id = \(id)") +``` + +SQL interpolation looks and feel just like regular [String interpolation]: + +```swift +let name = "World" +print("Hello \(name)!") // prints "Hello World!" +``` + +The difference is that it generates valid SQL which does not suffer from syntax errors or [SQL injection]. For example, you do not need to validate input or process single quotes: + +```swift +// Executes `UPDATE player SET name = 'O''Brien' WHERE id = 42` +let name = "O'Brien" +let id = 42 +try db.execute(literal: "UPDATE player SET name = \(name) WHERE id = \(id)") +``` + +Under the hood, SQL interpolation generates a plain SQL string. It runs exactly as below: + +```swift +try db.execute(sql: "UPDATE player SET name = ? WHERE id = ?", arguments: [name, id]) +``` + +Plain SQL strings are indeed still available, and SQL interpolation only kicks in when you ask for it. There is a simple rule to remember: + +- For plain SQL strings, use the `sql` argument label: + + ```swift + try db.execute(sql: "UPDATE player SET name = ? WHERE id = ?", arguments: [name, id]) + ``` + +- For SQL interpolation, use the `literal` argument label: + + ```swift + try db.execute(literal: "UPDATE player SET name = \(name) WHERE id = \(id)") + ``` + + +## SQLLiteral + +**SQLLiteral** is the type that looks like a plain String, but profits from SQL interpolation: + +```swift +let query: SQLLiteral = "UPDATE player SET name = \(name) WHERE id = \(id)" +try db.execute(literal: query) +``` + +**SQLLiteral is not a Swift String.** You can not use the `execute(literal:)` method with a String argument: + +```swift +// Compiler error: +// Cannot convert value of type 'String' to expected argument type 'SQLLiteral' +let query = "UPDATE player SET name = \(name) WHERE id = \(id)" // a String +try db.execute(literal: query) +``` + +SQLLiteral can build your queries step by step, with regular operators and methods: + +```swift +// +, +=, append +var query: SQLLiteral = "UPDATE player " +query += "SET name = \(name) " +query.append(literal: "WHERE id = \(id)") + +// joined(), joined(separator:) +let components: [SQLLiteral] = [ + "UPDATE player", + "SET name = \(name)", + "WHERE id = \(id)" +] +let query = components.joined(separator: " ") +``` + +Extract the plain SQL string from a literal: + +```swift +let query: SQLLiteral = "UPDATE player SET name = \(name) WHERE id = \(id)" +print(query.sql) // prints "UPDATE player SET name = ? WHERE id = ?" +print(query.arguments) // prints ["O'Brien", 42] +``` + +Build a literal from a plain SQL string: + +```swift +let query = SQLLiteral( + sql: "UPDATE player SET name = ? WHERE id = ?", + arguments: [name, id]) +``` + +SQLLiteral can embed any [value], as we have seen above, but not only. Please keep on reading the next chapter, or jump directly to the [SQL Interpolation Reference]. + + +## SQL Interpolation and Record Protocols + +The [record protocols] extend your application types with database abilities. + +**A record type knows everything about the schema of its underlying database table**. With the [TableRecord] protocol, the `databaseTableName` property contains the table name. With the [Decodable] protocol, the [CodingKeys] enum contain the column names. And with [FetchableRecord], you can decode raw database rows. + +SQL Interpolation puts this knowledge to good use, so that you can build robust queries that consistently use correct table and column names: + +```swift +struct Player { + var id: Int64 + var name: String + var score: Int? +} + +extension Player: Decodable, FetchableRecord, TableRecord { + /// Deletes all player with no score + static func deleteAllWithoutScore(_ db: Database) throws { + try db.execute(literal: "DELETE FROM \(self) WHERE \(CodingKeys.score) IS NULL") + } + + /// The player with a given id + static func filter(id: Int64) -> SQLRequest { + return "SELECT * FROM \(self) WHERE \(CodingKeys.id) = \(id)" + } + + /// All players with the given ids + static func filter(ids: [Int64]) -> SQLRequest { + return "SELECT * FROM \(self) WHERE \(CodingKeys.id) IN \(ids)" + } + + /// The maximum score + static func maximumScore() -> SQLRequest { + return "SELECT MAX(\(CodingKeys.score)) FROM \(self)" + } + + /// All players whose score is the maximum score + static func leaders() -> SQLRequest { + return """ + SELECT * FROM \(self) + WHERE \(CodingKeys.score) = \(maximumScore()) + """ + } + + /// A complex request + static func complexRequest() -> SQLRequest { + let query: SQLLiteral = "SELECT * FROM \(self) " + query += "JOIN \(Team.self) ON ..." + query += "GROUP BY ..." + return SQLRequest(literal: query) + } +} +``` + +Let's breakdown each one of those methods. + +- `deleteAllWithoutScore(_:)` + + ```swift + extension Player: Decodable, FetchableRecord, TableRecord { + /// Deletes all player with no score + static func deleteAllWithoutScore(_ db: Database) throws { + try db.execute(literal: "DELETE FROM \(self) WHERE \(CodingKeys.score) IS NULL") + } + } + ``` + + Usage: + + ```swift + try dbQueue.write { db in + // DELETE FROM player WHERE score IS NULL + try Player.deleteAllWithoutScore(db) + } + ``` + + `DELETE FROM \(self) ...` embeds the Player type itself. Since Player adopts the [TableRecord] protocol, this embeds `Player.databaseTableName` in the SQL query. + + `... \(CodingKeys.score) IS NULL` embeds CodingKeys.score. This one has been synthesized by the Swift compiler because Player adopts the Decodable protocol. It embeds the column name in the SQL query. + +- `filter(id:)` + + ```swift + extension Player: Decodable, FetchableRecord, TableRecord { + /// The player with a given id + static func filter(id: Int64) -> SQLRequest { + return "SELECT * FROM \(self) WHERE \(CodingKeys.id) = \(id)" + } + } + ``` + + Usage: + + ```swift + let player = try dbQueue.read { db in + // SELECT * player WHERE id = 42 + try Player.filter(id: 42).fetchOne(db) // Player? + } + ``` + + The return type of this method is `SQLRequest`. It is one of the GRDB [request types]. And it profits from SQL interpolation: this is why this method can simply return an "SQL literal"". + + It embeds `\(self)` (the Player type which adopts the TableRecord protocol) and `\(CodingKeys.id)` (the coding key synthesized by the Decodable protocol), and `\(id)` (a [value]). + +- `filter(ids:)` + + ```swift + extension Player: Decodable, FetchableRecord, TableRecord { + /// All players with the given ids + static func filter(ids: [Int64]) -> SQLRequest { + return "SELECT * FROM \(self) WHERE \(CodingKeys.id) IN \(ids)" + } + } + ``` + + Usage: + + ```swift + let players = try dbQueue.read { db in + // SELECT * player WHERE id IN (1, 2, 3) + try Player.filter(ids: [1, 2, 3]).fetchAll(db) // [Player] + } + ``` + + It embeds `\(ids)`, an array of ids. All [value] sequences are supported (arrays, sets, etc.) Empty sequences are supported as well, with both `IN` and `NOT IN` SQL operators. + +- `maximumScore()` + + ```swift + extension Player: Decodable, FetchableRecord, TableRecord { + /// The maximum score + static func maximumScore() -> SQLRequest { + return "SELECT MAX(\(CodingKeys.score)) FROM \(self)" + } + } + ``` + + Usage: + + ```swift + let maximumScore = try dbQueue.read { db in + // SELECT MAX(score) FROM player + try Player.maximumScore().fetchOne(db) // Int? + } + ``` + + The result is `SQLRequest`, unlike previous requests of type `SQLRequest`. SQLRequest accepts any fetchable type (database [row], simple [value], or custom [record]). + +- `leaders()` + + ```swift + extension Player: Decodable, FetchableRecord, TableRecord { + /// All players whose score is the maximum score + static func leaders() -> SQLRequest { + return """ + SELECT * FROM \(self) + WHERE \(CodingKeys.score) = \(maximumScore()) + """ + } + } + ``` + + Usage: + + ```swift + let leaders = try dbQueue.read { db in + // SELECT * FROM player + // WHERE score = (SELECT MAX(score) FROM player) + try Player.leaders().fetchAll(db) // [Player] + } + ``` + + This request embeds `\(maximumScore())`, the `SQLRequest` returned by the `maximumScore` method. After values, coding keys, and types that adopt the TableRecord protocol, this ends our quick tour of things you can embed between `\(` and `)`. Check out the [SQL Interpolation Reference] for the full list of supported interpolations. + +- `complexRequest()` + + ```swift + extension Player: Decodable, FetchableRecord, TableRecord { + /// A complex request + static func complexRequest() -> SQLRequest { + let query: SQLLiteral = "SELECT * FROM \(self) " + query += "JOIN \(Team.self) ON ..." + query += "GROUP BY ..." + return SQLRequest(literal: query) + } + } + ``` + + This last request shows how to build an SQLRequest from an [SQLLiteral]. You will need SQLLiteral when the request can not be expressed in a single "SQL literal". + + + +## SQL Interpolation Reference + +This chapter lists all kinds of supported interpolations. + +- Types adopting the [TableRecord] protocol: + + ```swift + // SELECT * FROM player + extension Player: TableRecord { } + "SELECT * FROM \(Player.self)" + + // INSERT INTO player ... + let player: Player = ... + "INSERT INTO \(tableOf: player) ..." + ``` + +- [Expressions] and [values]: + + ```swift + // SELECT name FROM player + "SELECT \(Column("name")) FROM player" + + // SELECT (score + 100) AS points FROM player + let bonus = 100 + "SELECT \(Column("score") + bonus) AS points FROM player" + + // SELECT (score + 100) AS points FROM player + "SELECT (score + \(bonus)) AS points FROM player" + ``` + +- Coding keys: + + ```swift + // SELECT name FROM player + "SELECT \(CodingKeys.name) FROM player" + ``` + +- Sequences: + + ```swift + // SELECT * FROM player WHERE id IN (1, 2, 3) + let ids = [1, 2, 3] + "SELECT * FROM player WHERE id IN \(ids)" + ``` + +- Orderings: + + ```swift + // SELECT * FROM player ORDER BY name DESC + "SELECT * FROM player WHERE id IN \(Column("name").desc)" + ``` + +- SQLRequest: + + ```swift + // SELECT * FROM player WHERE score = (SELECT MAX(score) FROM player) + let subQuery: SQLRequest = "SELECT MAX(score) FROM player" + "SELECT * FROM player WHERE score = \(subQuery)" + ``` + +- SQLLiteral: + + ```swift + // SELECT * FROM player WHERE name = 'O''Brien' + let condition: SQLLiteral = "name = \("O'Brien")" + "SELECT * FROM player WHERE \(literal: condition)" + ``` + +- Plain SQL strings and eventual arguments: + + ```swift + // SELECT * FROM player + "SELECT * FROM \(sql: "player")" + + // SELECT * FROM player WHERE name = 'O''Brien' + "SELECT * FROM player WHERE \(sql: "name = ?", arguments: ["O'Brien"])" + ``` + +[Introduction]: #introduction +[SQLLiteral]: #sqlliteral +[SQL Interpolation and Record Protocols]: #sql-interpolation-and-record-protocols +[SQL Interpolation Reference]: #sql-interpolation-reference +[String interpolation]: https://docs.swift.org/swift-book/LanguageGuide/StringsAndCharacters.html#ID292 +[SQL injection]: ../README.md#avoiding-sql-injection +[record protocols]: ../README.md#record-protocols-overview +[FetchableRecord]: ../README.md#fetchablerecord-protocol +[TableRecord]: ../README.md#tablerecord-protocol +[Decodable]: ../README.md#codable-records +[CodingKeys]: https://developer.apple.com/documentation/foundation/archives_and_serialization/encoding_and_decoding_custom_types +[value]: ../README.md#values +[values]: ../README.md#values +[request types]: ../README.md#custom-requests +[row]: ../README.md#row-queries +[record]: ../README.md#records +[Expressions]: ../README.md#expressions +[welcomed]: ../README.md#sqlite-api +[SE-0228 Fix ExpressibleByStringInterpolation]: https://github.com/apple/swift-evolution/blob/master/proposals/0228-fix-expressiblebystringinterpolation.md diff --git a/Documentation/WhyAdoptGRDB.md b/Documentation/WhyAdoptGRDB.md index 4743be5bc..b96e9b6a7 100644 --- a/Documentation/WhyAdoptGRDB.md +++ b/Documentation/WhyAdoptGRDB.md @@ -69,7 +69,7 @@ By adopting the [FetchableRecord] protocol, places can be loaded from SQL reques ```swift extension Place: FetchableRecord { ... } -let places = try Place.fetchAll(db, "SELECT * FROM place") // [Place] +let places = try Place.fetchAll(db, sql: "SELECT * FROM place") // [Place] ``` Add the [TableRecord] protocol, and SQL requests are generated for you: @@ -177,9 +177,14 @@ For further information about GRDB concurrency, check its detailed [Concurrency SQL is a weird language. Born in the 70s, easy to [misuse](https://xkcd.com/327/), feared by some developers, despised by others, and yet wonderfully concise and powerful. -GRDB [query interface] and [associations] can generate SQL for you: +GRDB [records], [query interface] and [associations] can generate SQL for you: ```swift +// UPDATE player SET score = 950 WHERE id = 42 +try player.updateChanges { + $0.score += 10 +} + // SELECT * FROM player ORDER BY score DESC LIMIT 10 let bestPlayers: [Player] = try Player .order(scoreColumn.desc) @@ -202,19 +207,47 @@ let bookInfos: [BookInfo] = BookInfo.fetchAll(db, request) But you can always switch to SQL when you want to: ```swift -let bestPlayers: [Player] = try Player.fetchAll(db, """ +try db.execute( + sql: "UPDATE player SET score = ? WHERE id = ?", + arguments: [950, 42]) + +let bestPlayers: [Player] = try Player.fetchAll(db, sql: """ SELECT * FROM player ORDER BY score DESC LIMIT 10 """) -let maximumScore: Int? = try Int.fetchOne(db, """ +let maximumScore: Int? = try Int.fetchOne(db, sql: """ SELECT MAX(score) FROM player """) ``` +With Swift 5, you can profit from **SQL interpolation**. It lets you build SQL queries from natural looking strings, but without any risk of syntax error or [SQL injection](https://xkcd.com/327/): + +```swift +try db.execute(literal: "UPDATE player SET score = \(score) WHERE id = \(id)") + +extension Player { + static func filter(name: String) -> SQLRequest { + return "SELECT * FROM \(self) WHERE \(CodingKeys.name) = \(name)" + } +} + +let player = try Player.filter(name: "Arthur O'Brien").fetchOne(db) +``` + +Custom SQL requests as the one above are welcome in database observation tools like [ValueObservation] and [RxGRDB]: + +```swift +Player.filter(name: "Arthur O'Brien").rx + .fetchOne(in: dbQueue) + .subscribe(onNext: { (player: Player?) in + print("Player has changed") + }) +``` + Power users can also consume complex joined SQL queries into handy record values, by *adapting* raw database rows to the decoded records (see [Joined Queries Support](#../README.md#joined-queries-support)): ```swift -let bookInfos: [BookInfo] = SQLRequest(""" +let bookInfos: [BookInfo] = SQLRequest(sql: """ SELECT book.*, author.* FROM book LEFT JOIN author ON author.id = book.authorId @@ -232,7 +265,7 @@ let bookInfos: [BookInfo] = SQLRequest(""" In performance-critical sections, you may want to deal with raw database rows, and fetch [lazy cursors](../README.md#cursors) instead of arrays: ```swift -let rows = try Row.fetchCursor(db, "SELECT id, name, score FROM player") +let rows = try Row.fetchCursor(db, sql: "SELECT id, name, score FROM player") while let row = try rows.next() { let id: Int64 = row[0] let name: String = row[1] @@ -240,28 +273,6 @@ while let row = try rows.next() { } ``` -When you feel like your code clarity would be enhanced by hiding your custom SQL in a dedicated method, you can build [custom requests](../README.md#custom-requests): - -```swift -extension Player { - static func customRequest(...) -> SQLRequest { - return SQLRequest("SELECT ...", arguments: ...) - } -} - -let players = try Player.customRequest(...).fetchAll(db) -``` - -Those custom requests are welcome in database observation tools like [ValueObservation] and [RxGRDB]: - -```swift -Player.customRequest(...).rx - .fetchAll(in: dbQueue) - .subscribe(onNext: { players: [Player] in - print("Players have changed") - }) -``` - --- If this little tour of GRDB has convinced you, the real trip starts here: [GRDB]. @@ -294,3 +305,4 @@ Happy GRDB! :gift: [query interface]: ../README.md#the-query-interface [associations]: AssociationsBasics.md [Codable records]: ../README.md#codable-records +[records]: ../README.md#records diff --git a/GRDB.swift.podspec b/GRDB.swift.podspec index c591c964b..414d276c9 100644 --- a/GRDB.swift.podspec +++ b/GRDB.swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GRDB.swift' - s.version = '3.7.0' + s.version = '4.0.0' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'A toolkit for SQLite databases, with a focus on application development.' @@ -9,12 +9,26 @@ Pod::Spec.new do |s| s.source = { :git => 'https://github.com/groue/GRDB.swift.git', :tag => "v#{s.version}" } s.module_name = 'GRDB' - s.ios.deployment_target = '8.0' + s.ios.deployment_target = '9.0' s.osx.deployment_target = '10.9' s.watchos.deployment_target = '2.0' - - s.source_files = 'GRDB/**/*.swift', 'Support/*.h' s.module_map = 'Support/module.modulemap' - s.framework = 'Foundation' - s.library = 'sqlite3' + s.default_subspec = 'standard' + + s.subspec 'standard' do |ss| + ss.source_files = 'GRDB/**/*.swift', 'Support/*.h' + ss.framework = 'Foundation' + ss.library = 'sqlite3' + end + + s.subspec 'SQLCipher' do |ss| + ss.source_files = 'GRDB/**/*.swift', 'Support/*.h' + ss.framework = 'Foundation' + ss.dependency 'SQLCipher', '>= 3.4.0' + ss.xcconfig = { + 'OTHER_SWIFT_FLAGS' => '$(inherited) -D SQLITE_HAS_CODEC -D GRDBCIPHER -D SQLITE_ENABLE_FTS5', + 'OTHER_CFLAGS' => '$(inherited) -DSQLITE_HAS_CODEC -DGRDBCIPHER -DSQLITE_ENABLE_FTS5', + 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) SQLITE_HAS_CODEC=1 GRDBCIPHER=1 SQLITE_ENABLE_FTS5=1' + } + end end diff --git a/GRDB.xcodeproj/project.pbxproj b/GRDB.xcodeproj/project.pbxproj index e06acb792..a5bd51109 100755 --- a/GRDB.xcodeproj/project.pbxproj +++ b/GRDB.xcodeproj/project.pbxproj @@ -8,6 +8,14 @@ /* Begin PBXBuildFile section */ 31A778841C6A4E0600F507F6 /* FetchedRecordsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31A7787C1C6A4DD600F507F6 /* FetchedRecordsController.swift */; }; + 560432A0228F00C2009D3FE2 /* OrderedDictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56043299228F00C2009D3FE2 /* OrderedDictionaryTests.swift */; }; + 560432A1228F00C2009D3FE2 /* OrderedDictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56043299228F00C2009D3FE2 /* OrderedDictionaryTests.swift */; }; + 560432A3228F1668009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560432A2228F1667009D3FE2 /* AssociationPrefetchingObservationTests.swift */; }; + 560432A4228F1668009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560432A2228F1667009D3FE2 /* AssociationPrefetchingObservationTests.swift */; }; + 56057C552291B16A00A7CB10 /* AssociationHasManyRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56057C4E2291B16900A7CB10 /* AssociationHasManyRowScopeTests.swift */; }; + 56057C562291B16A00A7CB10 /* AssociationHasManyRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56057C4E2291B16900A7CB10 /* AssociationHasManyRowScopeTests.swift */; }; + 56057C622291C7C600A7CB10 /* AssociationHasManyThroughRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56057C612291C7C600A7CB10 /* AssociationHasManyThroughRowScopeTests.swift */; }; + 56057C632291C7C600A7CB10 /* AssociationHasManyThroughRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56057C612291C7C600A7CB10 /* AssociationHasManyThroughRowScopeTests.swift */; }; 5605F1591C672E4000235C62 /* CGFloat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1491C672E4000235C62 /* CGFloat.swift */; }; 5605F15A1C672E4000235C62 /* CGFloat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1491C672E4000235C62 /* CGFloat.swift */; }; 5605F15D1C672E4000235C62 /* DatabaseDateComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F14C1C672E4000235C62 /* DatabaseDateComponents.swift */; }; @@ -27,6 +35,8 @@ 5605F1881C69111300235C62 /* DatabaseRegionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1861C69111300235C62 /* DatabaseRegionTests.swift */; }; 5605F18D1C6B1A8700235C62 /* SQLCollatedExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */; }; 5605F18E1C6B1A8700235C62 /* SQLCollatedExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */; }; + 560714E3227DD0810091BB10 /* AssociationPrefetchingSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560714E2227DD0810091BB10 /* AssociationPrefetchingSQLTests.swift */; }; + 560714E4227DD0810091BB10 /* AssociationPrefetchingSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560714E2227DD0810091BB10 /* AssociationPrefetchingSQLTests.swift */; }; 56071A411DB54ED000CA6E47 /* FetchedRecordsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B15D0A1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift */; }; 5607EFD41BB827FD00605DE3 /* TransactionObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5607EFD21BB8254800605DE3 /* TransactionObserverTests.swift */; }; 560A37A41C8F625000949E71 /* DatabasePool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37A31C8F625000949E71 /* DatabasePool.swift */; }; @@ -70,10 +80,21 @@ 5613ED5621A95DD000DC7A68 /* ValueObservation+Count.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED5321A95DD000DC7A68 /* ValueObservation+Count.swift */; }; 5613EDA621A96A9300DC7A68 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613EDA521A96A9200DC7A68 /* ValueObservationCombineTests.swift */; }; 5613EDA721A96A9300DC7A68 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613EDA521A96A9200DC7A68 /* ValueObservationCombineTests.swift */; }; + 5615B261222AE1B400061C1C /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B25A222AE1B400061C1C /* AssociationHasOneThroughSQLDerivationTests.swift */; }; + 5615B262222AE1B400061C1C /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B25A222AE1B400061C1C /* AssociationHasOneThroughSQLDerivationTests.swift */; }; + 5615B26A222AFE8F00061C1C /* AssociationHasOneThroughRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B269222AFE8F00061C1C /* AssociationHasOneThroughRowScopeTests.swift */; }; + 5615B26B222AFE8F00061C1C /* AssociationHasOneThroughRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B269222AFE8F00061C1C /* AssociationHasOneThroughRowScopeTests.swift */; }; + 5615B275222B107900061C1C /* AssociationHasOneThroughFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B274222B107900061C1C /* AssociationHasOneThroughFetchableRecordTests.swift */; }; + 5615B276222B107900061C1C /* AssociationHasOneThroughFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B274222B107900061C1C /* AssociationHasOneThroughFetchableRecordTests.swift */; }; + 5615B288222B17C000061C1C /* AssociationHasOneThroughDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B287222B17BF00061C1C /* AssociationHasOneThroughDecodableRecordTests.swift */; }; + 5615B289222B17C000061C1C /* AssociationHasOneThroughDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B287222B17BF00061C1C /* AssociationHasOneThroughDecodableRecordTests.swift */; }; 561667051D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 561667001D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift */; }; 5616AAF1207CD45E00AC3664 /* RequestProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5616AAF0207CD45E00AC3664 /* RequestProtocols.swift */; }; 5616AAF2207CD45E00AC3664 /* RequestProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5616AAF0207CD45E00AC3664 /* RequestProtocols.swift */; }; 5616AAF3207CD45E00AC3664 /* RequestProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5616AAF0207CD45E00AC3664 /* RequestProtocols.swift */; }; + 5617294E223533F40006E219 /* EncodableRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56172947223533F40006E219 /* EncodableRecord.swift */; }; + 5617294F223533F40006E219 /* EncodableRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56172947223533F40006E219 /* EncodableRecord.swift */; }; + 56172950223533F40006E219 /* EncodableRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56172947223533F40006E219 /* EncodableRecord.swift */; }; 56176C591EACCCC7000F3F2B /* FTS5CustomTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD001DAA8ACA0056AF8C /* FTS5CustomTokenizerTests.swift */; }; 56176C5A1EACCCC7000F3F2B /* FTS5PatternTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964C01DA521450002DA19 /* FTS5PatternTests.swift */; }; 56176C5B1EACCCC7000F3F2B /* FTS5RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964C11DA521450002DA19 /* FTS5RecordTests.swift */; }; @@ -260,18 +281,15 @@ 5653EB0320944C7C00F46237 /* BelongsToAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAF820944C7B00F46237 /* BelongsToAssociation.swift */; }; 5653EB0420944C7C00F46237 /* BelongsToAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAF820944C7B00F46237 /* BelongsToAssociation.swift */; }; 5653EB0520944C7C00F46237 /* BelongsToAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAF820944C7B00F46237 /* BelongsToAssociation.swift */; }; - 5653EB0620944C7C00F46237 /* ForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAF920944C7B00F46237 /* ForeignKeyRequest.swift */; }; - 5653EB0720944C7C00F46237 /* ForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAF920944C7B00F46237 /* ForeignKeyRequest.swift */; }; - 5653EB0820944C7C00F46237 /* ForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAF920944C7B00F46237 /* ForeignKeyRequest.swift */; }; + 5653EB0620944C7C00F46237 /* SQLForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAF920944C7B00F46237 /* SQLForeignKeyRequest.swift */; }; + 5653EB0720944C7C00F46237 /* SQLForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAF920944C7B00F46237 /* SQLForeignKeyRequest.swift */; }; + 5653EB0820944C7C00F46237 /* SQLForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAF920944C7B00F46237 /* SQLForeignKeyRequest.swift */; }; 5653EB0920944C7C00F46237 /* Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFA20944C7B00F46237 /* Association.swift */; }; 5653EB0A20944C7C00F46237 /* Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFA20944C7B00F46237 /* Association.swift */; }; 5653EB0B20944C7C00F46237 /* Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFA20944C7B00F46237 /* Association.swift */; }; 5653EB0C20944C7C00F46237 /* HasManyAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFB20944C7B00F46237 /* HasManyAssociation.swift */; }; 5653EB0D20944C7C00F46237 /* HasManyAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFB20944C7B00F46237 /* HasManyAssociation.swift */; }; 5653EB0E20944C7C00F46237 /* HasManyAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFB20944C7B00F46237 /* HasManyAssociation.swift */; }; - 5653EB1820944C7C00F46237 /* ForeignKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFF20944C7C00F46237 /* ForeignKey.swift */; }; - 5653EB1920944C7C00F46237 /* ForeignKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFF20944C7C00F46237 /* ForeignKey.swift */; }; - 5653EB1A20944C7C00F46237 /* ForeignKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFF20944C7C00F46237 /* ForeignKey.swift */; }; 5653EB2120944C7C00F46237 /* HasOneAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB0220944C7C00F46237 /* HasOneAssociation.swift */; }; 5653EB2220944C7C00F46237 /* HasOneAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB0220944C7C00F46237 /* HasOneAssociation.swift */; }; 5653EB2320944C7C00F46237 /* HasOneAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB0220944C7C00F46237 /* HasOneAssociation.swift */; }; @@ -323,6 +341,23 @@ 565490E41D5AE252005622CB /* TableRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560D92461C672C4B00F4F92B /* TableRecord.swift */; }; 56553C101C3E906C00522B5C /* GRDBTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623E0901B4AFACC00B20B7F /* GRDBTestCase.swift */; }; 56553C131C3E906C00522B5C /* GRDB.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC3773F319C8CBB3004FCF85 /* GRDB.framework */; }; + 5656A7FF22946B34001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A7F822946B33001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */; }; + 5656A80022946B34001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A7F822946B33001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */; }; + 5656A81E2295B12F001FF3FF /* SQLAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A81D2295B12F001FF3FF /* SQLAssociation.swift */; }; + 5656A81F2295B12F001FF3FF /* SQLAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A81D2295B12F001FF3FF /* SQLAssociation.swift */; }; + 5656A8202295B12F001FF3FF /* SQLAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A81D2295B12F001FF3FF /* SQLAssociation.swift */; }; + 5656A8AD2295BFD7001FF3FF /* TableRecord+Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8A92295BFD5001FF3FF /* TableRecord+Association.swift */; }; + 5656A8AE2295BFD7001FF3FF /* TableRecord+Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8A92295BFD5001FF3FF /* TableRecord+Association.swift */; }; + 5656A8AF2295BFD7001FF3FF /* TableRecord+Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8A92295BFD5001FF3FF /* TableRecord+Association.swift */; }; + 5656A8B02295BFD7001FF3FF /* TableRecord+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8AA2295BFD6001FF3FF /* TableRecord+QueryInterfaceRequest.swift */; }; + 5656A8B12295BFD7001FF3FF /* TableRecord+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8AA2295BFD6001FF3FF /* TableRecord+QueryInterfaceRequest.swift */; }; + 5656A8B22295BFD7001FF3FF /* TableRecord+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8AA2295BFD6001FF3FF /* TableRecord+QueryInterfaceRequest.swift */; }; + 5656A8B32295BFD7001FF3FF /* Row+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8AB2295BFD6001FF3FF /* Row+QueryInterfaceRequest.swift */; }; + 5656A8B42295BFD7001FF3FF /* Row+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8AB2295BFD6001FF3FF /* Row+QueryInterfaceRequest.swift */; }; + 5656A8B52295BFD7001FF3FF /* Row+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8AB2295BFD6001FF3FF /* Row+QueryInterfaceRequest.swift */; }; + 5656A8B62295BFD7001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8AC2295BFD6001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift */; }; + 5656A8B72295BFD7001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8AC2295BFD6001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift */; }; + 5656A8B82295BFD7001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8AC2295BFD6001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift */; }; 5657AAB91D107001006283EF /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AAB81D107001006283EF /* NSData.swift */; }; 5657AABC1D107001006283EF /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AAB81D107001006283EF /* NSData.swift */; }; 5657AB0F1D10899D006283EF /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB0E1D10899D006283EF /* URL.swift */; }; @@ -415,9 +450,9 @@ 5674A6EB1F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E21F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift */; }; 5674A6EF1F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E21F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift */; }; 5674A6F01F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E21F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift */; }; - 5674A6F41F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F31F307F600095F066 /* PersistableRecord+Encodable.swift */; }; - 5674A6F81F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F31F307F600095F066 /* PersistableRecord+Encodable.swift */; }; - 5674A6F91F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F31F307F600095F066 /* PersistableRecord+Encodable.swift */; }; + 5674A6F41F307F600095F066 /* EncodableRecord+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F31F307F600095F066 /* EncodableRecord+Encodable.swift */; }; + 5674A6F81F307F600095F066 /* EncodableRecord+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F31F307F600095F066 /* EncodableRecord+Encodable.swift */; }; + 5674A6F91F307F600095F066 /* EncodableRecord+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F31F307F600095F066 /* EncodableRecord+Encodable.swift */; }; 5674A6FB1F307F600095F066 /* FetchableRecord+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F21F307F600095F066 /* FetchableRecord+Decodable.swift */; }; 5674A6FF1F307F600095F066 /* FetchableRecord+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F21F307F600095F066 /* FetchableRecord+Decodable.swift */; }; 5674A7001F307F600095F066 /* FetchableRecord+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F21F307F600095F066 /* FetchableRecord+Decodable.swift */; }; @@ -438,17 +473,19 @@ 567DAF221EAB61ED00FC0928 /* grdb_config.h in Headers */ = {isa = PBXBuildFile; fileRef = 567DAF141EAB61ED00FC0928 /* grdb_config.h */; settings = {ATTRIBUTES = (Private, ); }; }; 567DAF351EAB789800FC0928 /* DatabaseLogErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567DAF341EAB789800FC0928 /* DatabaseLogErrorTests.swift */; }; 567DAF391EAB789800FC0928 /* DatabaseLogErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567DAF341EAB789800FC0928 /* DatabaseLogErrorTests.swift */; }; + 567ECE4F2222E431009245CA /* GRDB-4.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567ECE4E2222E431009245CA /* GRDB-4.0.swift */; }; + 567ECE502222E431009245CA /* GRDB-4.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567ECE4E2222E431009245CA /* GRDB-4.0.swift */; }; + 567ECE512222E431009245CA /* GRDB-4.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567ECE4E2222E431009245CA /* GRDB-4.0.swift */; }; + 567F0B2D220F0E2E00D111FB /* SQLInterpolationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567F0B2C220F0E2E00D111FB /* SQLInterpolationTests.swift */; }; + 567F0B2E220F0E2E00D111FB /* SQLInterpolationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567F0B2C220F0E2E00D111FB /* SQLInterpolationTests.swift */; }; 567F45A81F888B2600030B59 /* TruncateOptimizationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567F45A71F888B2600030B59 /* TruncateOptimizationTests.swift */; }; 567F45AC1F888B2600030B59 /* TruncateOptimizationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567F45A71F888B2600030B59 /* TruncateOptimizationTests.swift */; }; 568068311EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 568068301EBBA26100EFB8AA /* SQLRequestTests.swift */; }; 568068351EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 568068301EBBA26100EFB8AA /* SQLRequestTests.swift */; }; 568735A21CEDE16C009B9116 /* Betty.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = 5687359E1CEDE16C009B9116 /* Betty.jpeg */; }; - 56873BEC1F2CB400004D24B4 /* Fixits-1.2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */; }; - 56873BEF1F2CB400004D24B4 /* Fixits-1.2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */; }; - 56873BF21F2CB400004D24B4 /* Fixits-1.2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */; }; - 568D131F2207213E00674B58 /* SQLSelectQueryGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 568D13182207213E00674B58 /* SQLSelectQueryGenerator.swift */; }; - 568D13202207213E00674B58 /* SQLSelectQueryGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 568D13182207213E00674B58 /* SQLSelectQueryGenerator.swift */; }; - 568D13212207213F00674B58 /* SQLSelectQueryGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 568D13182207213E00674B58 /* SQLSelectQueryGenerator.swift */; }; + 568D131F2207213E00674B58 /* SQLQueryGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 568D13182207213E00674B58 /* SQLQueryGenerator.swift */; }; + 568D13202207213E00674B58 /* SQLQueryGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 568D13182207213E00674B58 /* SQLQueryGenerator.swift */; }; + 568D13212207213F00674B58 /* SQLQueryGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 568D13182207213E00674B58 /* SQLQueryGenerator.swift */; }; 5690AFD82120589A001530EA /* InsertRecordCodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690AFD72120589A001530EA /* InsertRecordCodableTests.swift */; }; 5690AFD92120589A001530EA /* InsertRecordCodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690AFD72120589A001530EA /* InsertRecordCodableTests.swift */; }; 5690AFDB212058CB001530EA /* FetchRecordCodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690AFDA212058CB001530EA /* FetchRecordCodableTests.swift */; }; @@ -471,6 +508,13 @@ 5695312A1C908A5B00CF1A2B /* DatabasePoolSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531281C908A5B00CF1A2B /* DatabasePoolSchemaCacheTests.swift */; }; 569531351C919DF200CF1A2B /* DatabasePoolCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531331C919DF200CF1A2B /* DatabasePoolCollationTests.swift */; }; 569531381C919DF700CF1A2B /* DatabasePoolFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531361C919DF700CF1A2B /* DatabasePoolFunctionTests.swift */; }; + 5695961C222C456C002CB7C9 /* AssociationHasManyThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56959615222C456C002CB7C9 /* AssociationHasManyThroughSQLTests.swift */; }; + 5695961D222C456C002CB7C9 /* AssociationHasManyThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56959615222C456C002CB7C9 /* AssociationHasManyThroughSQLTests.swift */; }; + 56959629222C462D002CB7C9 /* HasManyThroughAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56959628222C462D002CB7C9 /* HasManyThroughAssociation.swift */; }; + 5695962A222C462D002CB7C9 /* HasManyThroughAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56959628222C462D002CB7C9 /* HasManyThroughAssociation.swift */; }; + 5695962B222C462D002CB7C9 /* HasManyThroughAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56959628222C462D002CB7C9 /* HasManyThroughAssociation.swift */; }; + 56959633222D056D002CB7C9 /* AssociationHasManySQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56959632222D056D002CB7C9 /* AssociationHasManySQLTests.swift */; }; + 56959634222D056D002CB7C9 /* AssociationHasManySQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56959632222D056D002CB7C9 /* AssociationHasManySQLTests.swift */; }; 5698AC031D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC021D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift */; }; 5698AC071D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC021D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift */; }; 5698AC371D9E5A590056AF8C /* FTS3Pattern.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC361D9E5A590056AF8C /* FTS3Pattern.swift */; }; @@ -506,10 +550,19 @@ 5698AD351DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */; }; 5698AD381DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */; }; 5698AD3B1DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */; }; - 569A98ED2039B6F3008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98EC2039B6F3008D7DBF /* Fixits-3.0.swift */; }; - 569A98EE2039B6F3008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98EC2039B6F3008D7DBF /* Fixits-3.0.swift */; }; - 569A98EF2039B6F3008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98EC2039B6F3008D7DBF /* Fixits-3.0.swift */; }; + 569BBA27228DE51800478429 /* AssociationPrefetchingFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569BBA20228DE51800478429 /* AssociationPrefetchingFetchableRecordTests.swift */; }; + 569BBA28228DE51800478429 /* AssociationPrefetchingFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569BBA20228DE51800478429 /* AssociationPrefetchingFetchableRecordTests.swift */; }; + 569BBA3622905FFA00478429 /* InflectionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569BBA3522905FFA00478429 /* InflectionsTests.swift */; }; + 569BBA3722905FFA00478429 /* InflectionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569BBA3522905FFA00478429 /* InflectionsTests.swift */; }; + 569BBA4622906A8200478429 /* InflectionsTests.json in Resources */ = {isa = PBXBuildFile; fileRef = 569BBA4522906A8200478429 /* InflectionsTests.json */; }; + 569BBA4722906A8200478429 /* InflectionsTests.json in Resources */ = {isa = PBXBuildFile; fileRef = 569BBA4522906A8200478429 /* InflectionsTests.json */; }; + 569BBA4E229170F800478429 /* Inflections+English.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569BBA482291707D00478429 /* Inflections+English.swift */; }; + 569BBA4F229170F900478429 /* Inflections+English.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569BBA482291707D00478429 /* Inflections+English.swift */; }; + 569BBA50229170FA00478429 /* Inflections+English.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569BBA482291707D00478429 /* Inflections+English.swift */; }; 569C1EB51CF07DDD0042627B /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */; }; + 569D6DDE220EF9E100A058A9 /* SQLInterpolation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569D6DDD220EF9E100A058A9 /* SQLInterpolation.swift */; }; + 569D6DDF220EF9E100A058A9 /* SQLInterpolation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569D6DDD220EF9E100A058A9 /* SQLInterpolation.swift */; }; + 569D6DE0220EF9E100A058A9 /* SQLInterpolation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569D6DDD220EF9E100A058A9 /* SQLInterpolation.swift */; }; 569EF0E2200D2D8400A9FA45 /* DatabaseRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569EF0E1200D2D8400A9FA45 /* DatabaseRegion.swift */; }; 569EF0E3200D2D8400A9FA45 /* DatabaseRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569EF0E1200D2D8400A9FA45 /* DatabaseRegion.swift */; }; 569EF0E4200D2D8400A9FA45 /* DatabaseRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569EF0E1200D2D8400A9FA45 /* DatabaseRegion.swift */; }; @@ -563,6 +616,11 @@ 56A8C2331D1914540096E9D4 /* UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A8C22F1D1914540096E9D4 /* UUID.swift */; }; 56A8C2471D1918F00096E9D4 /* FoundationNSUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A8C2361D1914790096E9D4 /* FoundationNSUUIDTests.swift */; }; 56A8C2481D1918F00096E9D4 /* FoundationUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A8C21E1D1914110096E9D4 /* FoundationUUIDTests.swift */; }; + 56AE64122229A53700AD1B0B /* HasOneThroughAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE64112229A53700AD1B0B /* HasOneThroughAssociation.swift */; }; + 56AE64132229A53700AD1B0B /* HasOneThroughAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE64112229A53700AD1B0B /* HasOneThroughAssociation.swift */; }; + 56AE64142229A53700AD1B0B /* HasOneThroughAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE64112229A53700AD1B0B /* HasOneThroughAssociation.swift */; }; + 56AE6424222AAC9500AD1B0B /* AssociationHasOneThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE6423222AAC9500AD1B0B /* AssociationHasOneThroughSQLTests.swift */; }; + 56AE6425222AAC9500AD1B0B /* AssociationHasOneThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE6423222AAC9500AD1B0B /* AssociationHasOneThroughSQLTests.swift */; }; 56AF746F1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AF746A1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift */; }; 56B021C91D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */; }; 56B021CD1D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */; }; @@ -573,6 +631,8 @@ 56B7F42A1BE14A1900E39BBF /* CGFloatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4291BE14A1900E39BBF /* CGFloatTests.swift */; }; 56B7F43A1BEB42D500E39BBF /* Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4391BEB42D500E39BBF /* Migration.swift */; }; 56B7F43B1BEB42D500E39BBF /* Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4391BEB42D500E39BBF /* Migration.swift */; }; + 56B86E79220FF4E000524C16 /* SQLLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B86E72220FF4E000524C16 /* SQLLiteralTests.swift */; }; + 56B86E7A220FF4E000524C16 /* SQLLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B86E72220FF4E000524C16 /* SQLLiteralTests.swift */; }; 56B9649D1DA51B4C0002DA19 /* FTS5.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B9649C1DA51B4C0002DA19 /* FTS5.swift */; }; 56B964A01DA51B4C0002DA19 /* FTS5.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B9649C1DA51B4C0002DA19 /* FTS5.swift */; }; 56B964A31DA51B4C0002DA19 /* FTS5.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B9649C1DA51B4C0002DA19 /* FTS5.swift */; }; @@ -584,15 +644,6 @@ 56B964BF1DA51D0A0002DA19 /* FTS5Pattern.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964B81DA51D0A0002DA19 /* FTS5Pattern.swift */; }; 56BB6EA91D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BB6EA81D3009B100A1CA52 /* SchedulingWatchdog.swift */; }; 56BB6EAC1D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BB6EA81D3009B100A1CA52 /* SchedulingWatchdog.swift */; }; - 56BF6D2F1DEF47DA006039A3 /* Fixits-0-84-0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2C1DEF47DA006039A3 /* Fixits-0-84-0.swift */; }; - 56BF6D321DEF47DA006039A3 /* Fixits-0-84-0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2C1DEF47DA006039A3 /* Fixits-0-84-0.swift */; }; - 56BF6D351DEF47DA006039A3 /* Fixits-0-84-0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2C1DEF47DA006039A3 /* Fixits-0-84-0.swift */; }; - 56BF6D361DEF47DA006039A3 /* Fixits-0-90-1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2D1DEF47DA006039A3 /* Fixits-0-90-1.swift */; }; - 56BF6D391DEF47DA006039A3 /* Fixits-0-90-1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2D1DEF47DA006039A3 /* Fixits-0-90-1.swift */; }; - 56BF6D3C1DEF47DA006039A3 /* Fixits-0-90-1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2D1DEF47DA006039A3 /* Fixits-0-90-1.swift */; }; - 56BF6D3D1DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2E1DEF47DA006039A3 /* Fixits-Swift2.swift */; }; - 56BF6D401DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2E1DEF47DA006039A3 /* Fixits-Swift2.swift */; }; - 56BF6D431DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2E1DEF47DA006039A3 /* Fixits-Swift2.swift */; }; 56C3F7561CF9F12400F6A361 /* DatabaseSavepointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C3F7521CF9F12400F6A361 /* DatabaseSavepointTests.swift */; }; 56CC922C201DFFB900CB597E /* DropWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC922B201DFFB900CB597E /* DropWhileCursorTests.swift */; }; 56CC922D201DFFB900CB597E /* DropWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC922B201DFFB900CB597E /* DropWhileCursorTests.swift */; }; @@ -611,9 +662,9 @@ 56CEB5011EAA2F4D00BFAF62 /* FTS4.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB4F91EAA2F4D00BFAF62 /* FTS4.swift */; }; 56CEB5041EAA2F4D00BFAF62 /* FTS4.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB4F91EAA2F4D00BFAF62 /* FTS4.swift */; }; 56CEB5071EAA2F4D00BFAF62 /* FTS4.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB4F91EAA2F4D00BFAF62 /* FTS4.swift */; }; - 56CEB5111EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */; }; - 56CEB5141EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */; }; - 56CEB5171EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */; }; + 56CEB5111EAA324B00BFAF62 /* FTS3+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterface.swift */; }; + 56CEB5141EAA324B00BFAF62 /* FTS3+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterface.swift */; }; + 56CEB5171EAA324B00BFAF62 /* FTS3+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterface.swift */; }; 56CEB5191EAA328900BFAF62 /* FTS5+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */; }; 56CEB51C1EAA328900BFAF62 /* FTS5+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */; }; 56CEB51F1EAA328900BFAF62 /* FTS5+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */; }; @@ -632,9 +683,6 @@ 56CEB5611EAA359A00BFAF62 /* SQLSelectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5441EAA359A00BFAF62 /* SQLSelectable.swift */; }; 56CEB5641EAA359A00BFAF62 /* SQLSelectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5441EAA359A00BFAF62 /* SQLSelectable.swift */; }; 56CEB5671EAA359A00BFAF62 /* SQLSelectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5441EAA359A00BFAF62 /* SQLSelectable.swift */; }; - 56D1215A1ED34978001347D2 /* Fixits-0.109.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D121591ED34978001347D2 /* Fixits-0.109.0.swift */; }; - 56D1215D1ED34978001347D2 /* Fixits-0.109.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D121591ED34978001347D2 /* Fixits-0.109.0.swift */; }; - 56D121601ED34978001347D2 /* Fixits-0.109.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D121591ED34978001347D2 /* Fixits-0.109.0.swift */; }; 56D3BE711F4EB1A00034C6D2 /* FetchRecordStructTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D3BE701F4EB1900034C6D2 /* FetchRecordStructTests.swift */; }; 56D3BE721F4EB1A00034C6D2 /* FetchRecordStructTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D3BE701F4EB1900034C6D2 /* FetchRecordStructTests.swift */; }; 56D496541D812F5B008276D7 /* SQLExpressionLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A4CDAF1D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift */; }; @@ -728,9 +776,9 @@ 56D91AA92205F2F100770D8D /* DatabasePromise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91AA82205F2F000770D8D /* DatabasePromise.swift */; }; 56D91AAA2205F2F100770D8D /* DatabasePromise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91AA82205F2F000770D8D /* DatabasePromise.swift */; }; 56D91AAB2205F2F100770D8D /* DatabasePromise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91AA82205F2F000770D8D /* DatabasePromise.swift */; }; - 56D91AB02205F8AC00770D8D /* SQLSelectQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91AAF2205F8AC00770D8D /* SQLSelectQuery.swift */; }; - 56D91AB12205F8AC00770D8D /* SQLSelectQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91AAF2205F8AC00770D8D /* SQLSelectQuery.swift */; }; - 56D91AB22205F8AC00770D8D /* SQLSelectQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91AAF2205F8AC00770D8D /* SQLSelectQuery.swift */; }; + 56D91AB02205F8AC00770D8D /* SQLQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91AAF2205F8AC00770D8D /* SQLQuery.swift */; }; + 56D91AB12205F8AC00770D8D /* SQLQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91AAF2205F8AC00770D8D /* SQLQuery.swift */; }; + 56D91AB22205F8AC00770D8D /* SQLQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91AAF2205F8AC00770D8D /* SQLQuery.swift */; }; 56DAA2D21DE99DAB006E10C8 /* DatabaseCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DAA2D11DE99DAB006E10C8 /* DatabaseCursorTests.swift */; }; 56DAA2D61DE99DAB006E10C8 /* DatabaseCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DAA2D11DE99DAB006E10C8 /* DatabaseCursorTests.swift */; }; 56DAA2DB1DE9C827006E10C8 /* Cursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DAA2DA1DE9C827006E10C8 /* Cursor.swift */; }; @@ -742,8 +790,10 @@ 56DE7B281C41302500861EB8 /* FetchNamedValuesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DE7B271C41302500861EB8 /* FetchNamedValuesTests.swift */; }; 56DE7B2A1C4130AF00861EB8 /* FetchPositionalValuesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DE7B291C4130AF00861EB8 /* FetchPositionalValuesTests.swift */; }; 56DE7B2C1C41311900861EB8 /* FetchRecordClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DE7B2B1C41311900861EB8 /* FetchRecordClassTests.swift */; }; - 56E06F061E859064008AE2A4 /* Fixits-0.102.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E06F051E859064008AE2A4 /* Fixits-0.102.0.swift */; }; - 56E06F181E85906E008AE2A4 /* Fixits-0.102.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E06F051E859064008AE2A4 /* Fixits-0.102.0.swift */; }; + 56DF001B228DDBA300D611F3 /* AssociationPrefetchingRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DF0019228DDBA200D611F3 /* AssociationPrefetchingRowTests.swift */; }; + 56DF001C228DDBA300D611F3 /* AssociationPrefetchingRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DF0019228DDBA200D611F3 /* AssociationPrefetchingRowTests.swift */; }; + 56DF001D228DDBA300D611F3 /* AssociationPrefetchingCodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DF001A228DDBA300D611F3 /* AssociationPrefetchingCodableRecordTests.swift */; }; + 56DF001E228DDBA300D611F3 /* AssociationPrefetchingCodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DF001A228DDBA300D611F3 /* AssociationPrefetchingCodableRecordTests.swift */; }; 56E5D7D41B4D3FEE00430942 /* GRDB.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 56E5D7CA1B4D3FED00430942 /* GRDB.framework */; }; 56E5D7FE1B4D422E00430942 /* GRDB.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC3773F319C8CBB3004FCF85 /* GRDB.framework */; }; 56E5D8041B4D424400430942 /* GRDBTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623E0901B4AFACC00B20B7F /* GRDBTestCase.swift */; }; @@ -752,6 +802,12 @@ 56E5D82D1B4D438800430942 /* GRDB-Bridging.h in Headers */ = {isa = PBXBuildFile; fileRef = DC2393C61ABE35F8003FF113 /* GRDB-Bridging.h */; settings = {ATTRIBUTES = (Public, ); }; }; 56E8CE0E1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E8CE0C1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift */; }; 56E8CE111BB4FE5B00828BEC /* StatementColumnConvertibleFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E8CE0F1BB4FE5B00828BEC /* StatementColumnConvertibleFetchTests.swift */; }; + 56E9FACB221046FD00C703A8 /* SQLInterpolation+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E9FACA221046FD00C703A8 /* SQLInterpolation+QueryInterface.swift */; }; + 56E9FACC221046FD00C703A8 /* SQLInterpolation+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E9FACA221046FD00C703A8 /* SQLInterpolation+QueryInterface.swift */; }; + 56E9FACD221046FD00C703A8 /* SQLInterpolation+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E9FACA221046FD00C703A8 /* SQLInterpolation+QueryInterface.swift */; }; + 56E9FAD8221053DD00C703A8 /* SQLLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E9FAD7221053DC00C703A8 /* SQLLiteral.swift */; }; + 56E9FAD9221053DD00C703A8 /* SQLLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E9FAD7221053DC00C703A8 /* SQLLiteral.swift */; }; + 56E9FADA221053DD00C703A8 /* SQLLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E9FAD7221053DC00C703A8 /* SQLLiteral.swift */; }; 56EA63C5209C7CE3009715B8 /* DerivableRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA63C4209C7CE3009715B8 /* DerivableRequestTests.swift */; }; 56EA63C6209C7CE3009715B8 /* DerivableRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA63C4209C7CE3009715B8 /* DerivableRequestTests.swift */; }; 56EA86951C91DFE7002BB4DF /* DatabaseReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA86931C91DFE7002BB4DF /* DatabaseReaderTests.swift */; }; @@ -761,13 +817,13 @@ 56F26C1C1CEE3F32007969C4 /* RowAdapterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565F03C11CE5D3AA00DE108F /* RowAdapterTests.swift */; }; 56F3E7491E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */; }; 56F3E74D1E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */; }; - 56F3E7631E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F3E7621E67F8C100BF0F01 /* Fixits-0.101.1.swift */; }; - 56F3E7661E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F3E7621E67F8C100BF0F01 /* Fixits-0.101.1.swift */; }; - 56F3E7691E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F3E7621E67F8C100BF0F01 /* Fixits-0.101.1.swift */; }; 56F5ABD91D814330001F60CB /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690C33F1D23E82A00E59934 /* Data.swift */; }; 56F5ABDA1D814330001F60CB /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AAB81D107001006283EF /* NSData.swift */; }; 56F5ABDC1D814330001F60CB /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB0E1D10899D006283EF /* URL.swift */; }; 56F5ABDD1D814330001F60CB /* UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A8C22F1D1914540096E9D4 /* UUID.swift */; }; + 56FBFED92210731A00945324 /* SQLRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FBFED82210731A00945324 /* SQLRequest.swift */; }; + 56FBFEDA2210731A00945324 /* SQLRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FBFED82210731A00945324 /* SQLRequest.swift */; }; + 56FBFEDB2210731A00945324 /* SQLRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FBFED82210731A00945324 /* SQLRequest.swift */; }; 56FC98781D969DEF00E3C842 /* SQLExpression+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FC98771D969DEF00E3C842 /* SQLExpression+QueryInterface.swift */; }; 56FC987B1D969DEF00E3C842 /* SQLExpression+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FC98771D969DEF00E3C842 /* SQLExpression+QueryInterface.swift */; }; 56FC987E1D969DEF00E3C842 /* SQLExpression+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FC98771D969DEF00E3C842 /* SQLExpression+QueryInterface.swift */; }; @@ -786,13 +842,6 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 560C97D11C0E22D300BF8471 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 56CA21FE1BB414FE009A04C5 /* SQLite.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = EE247B3B1C3F3ED000AE3E12; - remoteInfo = "SQLite Mac"; - }; 560C97D31C0E22D300BF8471 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = DC3773EA19C8CBB3004FCF85 /* Project object */; @@ -902,6 +951,10 @@ /* Begin PBXFileReference section */ 31A7787C1C6A4DD600F507F6 /* FetchedRecordsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedRecordsController.swift; sourceTree = ""; }; + 56043299228F00C2009D3FE2 /* OrderedDictionaryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OrderedDictionaryTests.swift; sourceTree = ""; }; + 560432A2228F1667009D3FE2 /* AssociationPrefetchingObservationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingObservationTests.swift; sourceTree = ""; }; + 56057C4E2291B16900A7CB10 /* AssociationHasManyRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManyRowScopeTests.swift; sourceTree = ""; }; + 56057C612291C7C600A7CB10 /* AssociationHasManyThroughRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManyThroughRowScopeTests.swift; sourceTree = ""; }; 5605F1491C672E4000235C62 /* CGFloat.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGFloat.swift; sourceTree = ""; }; 5605F14C1C672E4000235C62 /* DatabaseDateComponents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseDateComponents.swift; sourceTree = ""; }; 5605F14F1C672E4000235C62 /* Date.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = ""; }; @@ -912,6 +965,7 @@ 5605F1581C672E4000235C62 /* StandardLibrary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StandardLibrary.swift; sourceTree = ""; }; 5605F1861C69111300235C62 /* DatabaseRegionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegionTests.swift; sourceTree = ""; }; 5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLCollatedExpression.swift; sourceTree = ""; }; + 560714E2227DD0810091BB10 /* AssociationPrefetchingSQLTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingSQLTests.swift; sourceTree = ""; }; 5607EFD21BB8254800605DE3 /* TransactionObserverTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionObserverTests.swift; sourceTree = ""; }; 560A37A31C8F625000949E71 /* DatabasePool.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePool.swift; sourceTree = ""; }; 560A37A61C8FF6E500949E71 /* SerializedDatabase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SerializedDatabase.swift; sourceTree = ""; }; @@ -932,8 +986,13 @@ 5613ED4F21A95C6D00DC7A68 /* ValueObservation+DatabaseValueConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ValueObservation+DatabaseValueConvertible.swift"; sourceTree = ""; }; 5613ED5321A95DD000DC7A68 /* ValueObservation+Count.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ValueObservation+Count.swift"; sourceTree = ""; }; 5613EDA521A96A9200DC7A68 /* ValueObservationCombineTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationCombineTests.swift; sourceTree = ""; }; + 5615B25A222AE1B400061C1C /* AssociationHasOneThroughSQLDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughSQLDerivationTests.swift; sourceTree = ""; }; + 5615B269222AFE8F00061C1C /* AssociationHasOneThroughRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughRowScopeTests.swift; sourceTree = ""; }; + 5615B274222B107900061C1C /* AssociationHasOneThroughFetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughFetchableRecordTests.swift; sourceTree = ""; }; + 5615B287222B17BF00061C1C /* AssociationHasOneThroughDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughDecodableRecordTests.swift; sourceTree = ""; }; 561667001D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSDecimalNumberTests.swift; sourceTree = ""; }; 5616AAF0207CD45E00AC3664 /* RequestProtocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestProtocols.swift; sourceTree = ""; }; + 56172947223533F40006E219 /* EncodableRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EncodableRecord.swift; sourceTree = ""; }; 562393171DECC02000A6B01F /* RowFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFetchTests.swift; sourceTree = ""; }; 5623932F1DEDFC5700A6B01F /* AnyCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyCursorTests.swift; sourceTree = ""; }; 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnumeratedCursorTests.swift; sourceTree = ""; }; @@ -1007,15 +1066,20 @@ 5653EAD420944B4E00F46237 /* AssociationBelongsToDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToDecodableRecordTests.swift; sourceTree = ""; }; 5653EAD520944B4F00F46237 /* AssociationParallelSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelSQLTests.swift; sourceTree = ""; }; 5653EAF820944C7B00F46237 /* BelongsToAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BelongsToAssociation.swift; sourceTree = ""; }; - 5653EAF920944C7B00F46237 /* ForeignKeyRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForeignKeyRequest.swift; sourceTree = ""; }; + 5653EAF920944C7B00F46237 /* SQLForeignKeyRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLForeignKeyRequest.swift; sourceTree = ""; }; 5653EAFA20944C7B00F46237 /* Association.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Association.swift; sourceTree = ""; }; 5653EAFB20944C7B00F46237 /* HasManyAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HasManyAssociation.swift; sourceTree = ""; }; - 5653EAFF20944C7C00F46237 /* ForeignKey.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForeignKey.swift; sourceTree = ""; }; 5653EB0220944C7C00F46237 /* HasOneAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HasOneAssociation.swift; sourceTree = ""; }; 5653EB242094A14400F46237 /* QueryInterfaceRequest+Association.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "QueryInterfaceRequest+Association.swift"; sourceTree = ""; }; 5653EC0B2098738B00F46237 /* SQLGenerationContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLGenerationContext.swift; sourceTree = ""; }; 565490A01D5A4798005622CB /* GRDB.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = GRDB.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 56553C181C3E906C00522B5C /* GRDBOSXCrashTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBOSXCrashTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 5656A7F822946B33001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationQueryInterfaceRequestTests.swift; sourceTree = ""; }; + 5656A81D2295B12F001FF3FF /* SQLAssociation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SQLAssociation.swift; sourceTree = ""; }; + 5656A8A92295BFD5001FF3FF /* TableRecord+Association.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TableRecord+Association.swift"; sourceTree = ""; }; + 5656A8AA2295BFD6001FF3FF /* TableRecord+QueryInterfaceRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TableRecord+QueryInterfaceRequest.swift"; sourceTree = ""; }; + 5656A8AB2295BFD6001FF3FF /* Row+QueryInterfaceRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Row+QueryInterfaceRequest.swift"; sourceTree = ""; }; + 5656A8AC2295BFD6001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FetchableRecord+QueryInterfaceRequest.swift"; sourceTree = ""; }; 5657AAB81D107001006283EF /* NSData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSData.swift; sourceTree = ""; }; 5657AB0E1D10899D006283EF /* URL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URL.swift; sourceTree = ""; }; 5657AB2F1D108BA9006283EF /* FoundationDataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationDataTests.swift; sourceTree = ""; }; @@ -1064,7 +1128,7 @@ 5674A6E21F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DatabaseValueConvertible+Encodable.swift"; sourceTree = ""; }; 5674A6E31F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DatabaseValueConvertible+Decodable.swift"; sourceTree = ""; }; 5674A6F21F307F600095F066 /* FetchableRecord+Decodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FetchableRecord+Decodable.swift"; sourceTree = ""; }; - 5674A6F31F307F600095F066 /* PersistableRecord+Encodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PersistableRecord+Encodable.swift"; sourceTree = ""; }; + 5674A6F31F307F600095F066 /* EncodableRecord+Encodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "EncodableRecord+Encodable.swift"; sourceTree = ""; }; 5674A7021F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DatabaseValueConvertible+ReferenceConvertible.swift"; sourceTree = ""; }; 5674A70A1F3087700095F066 /* DatabaseValueConvertibleDecodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleDecodableTests.swift; sourceTree = ""; }; 5674A70B1F3087700095F066 /* DatabaseValueConvertibleEncodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleEncodableTests.swift; sourceTree = ""; }; @@ -1073,11 +1137,12 @@ 567A80521D41350C00C7DCEC /* IndexInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IndexInfoTests.swift; sourceTree = ""; }; 567DAF141EAB61ED00FC0928 /* grdb_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = grdb_config.h; sourceTree = ""; }; 567DAF341EAB789800FC0928 /* DatabaseLogErrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseLogErrorTests.swift; sourceTree = ""; }; + 567ECE4E2222E431009245CA /* GRDB-4.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "GRDB-4.0.swift"; sourceTree = ""; }; + 567F0B2C220F0E2E00D111FB /* SQLInterpolationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SQLInterpolationTests.swift; sourceTree = ""; }; 567F45A71F888B2600030B59 /* TruncateOptimizationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TruncateOptimizationTests.swift; sourceTree = ""; }; 568068301EBBA26100EFB8AA /* SQLRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLRequestTests.swift; sourceTree = ""; }; 5687359E1CEDE16C009B9116 /* Betty.jpeg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Betty.jpeg; sourceTree = ""; }; - 56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Fixits-1.2.swift"; sourceTree = ""; }; - 568D13182207213E00674B58 /* SQLSelectQueryGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLSelectQueryGenerator.swift; sourceTree = ""; }; + 568D13182207213E00674B58 /* SQLQueryGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLQueryGenerator.swift; sourceTree = ""; }; 5690AFD72120589A001530EA /* InsertRecordCodableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InsertRecordCodableTests.swift; sourceTree = ""; }; 5690AFDA212058CB001530EA /* FetchRecordCodableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchRecordCodableTests.swift; sourceTree = ""; }; 5690C3251D23E6D800E59934 /* FoundationDateComponentsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationDateComponentsTests.swift; sourceTree = ""; }; @@ -1096,6 +1161,9 @@ 569531281C908A5B00CF1A2B /* DatabasePoolSchemaCacheTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolSchemaCacheTests.swift; sourceTree = ""; }; 569531331C919DF200CF1A2B /* DatabasePoolCollationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolCollationTests.swift; sourceTree = ""; }; 569531361C919DF700CF1A2B /* DatabasePoolFunctionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolFunctionTests.swift; sourceTree = ""; }; + 56959615222C456C002CB7C9 /* AssociationHasManyThroughSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManyThroughSQLTests.swift; sourceTree = ""; }; + 56959628222C462D002CB7C9 /* HasManyThroughAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HasManyThroughAssociation.swift; sourceTree = ""; }; + 56959632222D056D002CB7C9 /* AssociationHasManySQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManySQLTests.swift; sourceTree = ""; }; 5698AC021D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceExtensibilityTests.swift; sourceTree = ""; }; 5698AC361D9E5A590056AF8C /* FTS3Pattern.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3Pattern.swift; sourceTree = ""; }; 5698AC3F1DA2BED90056AF8C /* FTS3PatternTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3PatternTests.swift; sourceTree = ""; }; @@ -1113,8 +1181,12 @@ 5698AD151DAAD16F0056AF8C /* FTS5Tokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5Tokenizer.swift; sourceTree = ""; }; 5698AD201DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5WrapperTokenizer.swift; sourceTree = ""; }; 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5CustomTokenizer.swift; sourceTree = ""; }; - 569A98EC2039B6F3008D7DBF /* Fixits-3.0.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Fixits-3.0.swift"; sourceTree = ""; }; + 569BBA20228DE51800478429 /* AssociationPrefetchingFetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingFetchableRecordTests.swift; sourceTree = ""; }; + 569BBA3522905FFA00478429 /* InflectionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InflectionsTests.swift; sourceTree = ""; }; + 569BBA4522906A8200478429 /* InflectionsTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = InflectionsTests.json; sourceTree = ""; }; + 569BBA482291707D00478429 /* Inflections+English.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Inflections+English.swift"; sourceTree = ""; }; 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SchedulingWatchdogTests.swift; sourceTree = ""; }; + 569D6DDD220EF9E100A058A9 /* SQLInterpolation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SQLInterpolation.swift; sourceTree = ""; }; 569EF0E1200D2D8400A9FA45 /* DatabaseRegion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseRegion.swift; sourceTree = ""; }; 56A238131B9C74A90082EB20 /* DatabaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseTests.swift; sourceTree = ""; }; 56A238141B9C74A90082EB20 /* DatabaseQueueInMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueInMemoryTests.swift; sourceTree = ""; }; @@ -1155,6 +1227,8 @@ 56A8C21E1D1914110096E9D4 /* FoundationUUIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationUUIDTests.swift; sourceTree = ""; }; 56A8C22F1D1914540096E9D4 /* UUID.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UUID.swift; sourceTree = ""; }; 56A8C2361D1914790096E9D4 /* FoundationNSUUIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSUUIDTests.swift; sourceTree = ""; }; + 56AE64112229A53700AD1B0B /* HasOneThroughAssociation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HasOneThroughAssociation.swift; sourceTree = ""; }; + 56AE6423222AAC9500AD1B0B /* AssociationHasOneThroughSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughSQLTests.swift; sourceTree = ""; }; 56AF746A1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleEscapingTests.swift; sourceTree = ""; }; 56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordPersistenceConflictPolicyTests.swift; sourceTree = ""; }; 56B14E7E1D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFromDictionaryLiteralTests.swift; sourceTree = ""; }; @@ -1162,8 +1236,9 @@ 56B6EF55208CB4E3002F0ACB /* ColumnExpressionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColumnExpressionTests.swift; sourceTree = ""; }; 56B7F4291BE14A1900E39BBF /* CGFloatTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGFloatTests.swift; sourceTree = ""; }; 56B7F4391BEB42D500E39BBF /* Migration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Migration.swift; sourceTree = ""; }; - 56B8C2401CA1758F00510325 /* Realm.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Realm.framework; path = "Realm/build/osx/swift-4.2.1/Realm.framework"; sourceTree = ""; }; - 56B8C2411CA1758F00510325 /* RealmSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RealmSwift.framework; path = "Realm/build/osx/swift-4.2.1/RealmSwift.framework"; sourceTree = ""; }; + 56B86E72220FF4E000524C16 /* SQLLiteralTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLLiteralTests.swift; sourceTree = ""; }; + 56B8C2401CA1758F00510325 /* Realm.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Realm.framework; path = "Realm/build/osx/swift-10.2.1/Realm.framework"; sourceTree = ""; }; + 56B8C2411CA1758F00510325 /* RealmSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RealmSwift.framework; path = "Realm/build/osx/swift-10.2.1/RealmSwift.framework"; sourceTree = ""; }; 56B8F49A1B4E2F3600C24296 /* GRDB.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = GRDB.xcconfig; sourceTree = ""; }; 56B9649C1DA51B4C0002DA19 /* FTS5.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5.swift; sourceTree = ""; }; 56B964B01DA51D010002DA19 /* FTS5TokenizerDescriptor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5TokenizerDescriptor.swift; sourceTree = ""; }; @@ -1186,9 +1261,6 @@ 56BB86211BA988F2001F9168 /* FMResultSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FMResultSet.h; sourceTree = ""; }; 56BB86221BA988F2001F9168 /* FMResultSet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FMResultSet.m; sourceTree = ""; }; 56BB862D1BA98933001F9168 /* GRDBPerformanceComparisonTests-Bridging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GRDBPerformanceComparisonTests-Bridging.h"; sourceTree = ""; }; - 56BF6D2C1DEF47DA006039A3 /* Fixits-0-84-0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0-84-0.swift"; sourceTree = ""; }; - 56BF6D2D1DEF47DA006039A3 /* Fixits-0-90-1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0-90-1.swift"; sourceTree = ""; }; - 56BF6D2E1DEF47DA006039A3 /* Fixits-Swift2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-Swift2.swift"; sourceTree = ""; }; 56C3F7521CF9F12400F6A361 /* DatabaseSavepointTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseSavepointTests.swift; sourceTree = ""; }; 56C48E731C9A9923005DF1D9 /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = ""; }; 56C494401ED7255500CC72AF /* GRDBDeploymentTarget.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = GRDBDeploymentTarget.xcconfig; sourceTree = ""; }; @@ -1201,21 +1273,20 @@ 56CEB4F01EAA2EFA00BFAF62 /* FetchableRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchableRecord.swift; sourceTree = ""; }; 56CEB4F81EAA2F4D00BFAF62 /* FTS3.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3.swift; sourceTree = ""; }; 56CEB4F91EAA2F4D00BFAF62 /* FTS4.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS4.swift; sourceTree = ""; }; - 56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FTS3+QueryInterfaceRequest.swift"; sourceTree = ""; }; + 56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FTS3+QueryInterface.swift"; sourceTree = ""; }; 56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FTS5+QueryInterface.swift"; sourceTree = ""; }; 56CEB5401EAA359A00BFAF62 /* Column.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Column.swift; sourceTree = ""; }; 56CEB5411EAA359A00BFAF62 /* SQLExpressible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLExpressible.swift; sourceTree = ""; }; 56CEB5421EAA359A00BFAF62 /* SQLExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLExpression.swift; sourceTree = ""; }; 56CEB5431EAA359A00BFAF62 /* SQLOrdering.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLOrdering.swift; sourceTree = ""; }; 56CEB5441EAA359A00BFAF62 /* SQLSelectable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLSelectable.swift; sourceTree = ""; }; - 56D121591ED34978001347D2 /* Fixits-0.109.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0.109.0.swift"; sourceTree = ""; }; 56D3BE701F4EB1900034C6D2 /* FetchRecordStructTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchRecordStructTests.swift; sourceTree = ""; }; 56D5075D1F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrimaryKeyInfoTests.swift; sourceTree = ""; }; 56D507821F6D7A4500AE1C5B /* InsertRecordStructTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsertRecordStructTests.swift; sourceTree = ""; }; 56D51CFF1EA789FA0074638A /* FetchableRecord+TableRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FetchableRecord+TableRecord.swift"; sourceTree = ""; }; 56D91AA12205E03700770D8D /* SQLRelation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLRelation.swift; sourceTree = ""; }; 56D91AA82205F2F000770D8D /* DatabasePromise.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePromise.swift; sourceTree = ""; }; - 56D91AAF2205F8AC00770D8D /* SQLSelectQuery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLSelectQuery.swift; sourceTree = ""; }; + 56D91AAF2205F8AC00770D8D /* SQLQuery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLQuery.swift; sourceTree = ""; }; 56DAA2D11DE99DAB006E10C8 /* DatabaseCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseCursorTests.swift; sourceTree = ""; }; 56DAA2DA1DE9C827006E10C8 /* Cursor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cursor.swift; sourceTree = ""; }; 56DE7B101C3D93ED00861EB8 /* StatementArgumentsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementArgumentsTests.swift; sourceTree = ""; }; @@ -1227,12 +1298,15 @@ 56DE7B2E1C42B23B00861EB8 /* PerformanceModel.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = PerformanceModel.xcdatamodel; sourceTree = ""; }; 56DE7B341C42B37E00861EB8 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; 56DE7B361C42BBBB00861EB8 /* PerformanceCoreDataTests.sqlite */ = {isa = PBXFileReference; lastKnownFileType = file; path = PerformanceCoreDataTests.sqlite; sourceTree = ""; }; - 56E06F051E859064008AE2A4 /* Fixits-0.102.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0.102.0.swift"; sourceTree = ""; }; + 56DF0019228DDBA200D611F3 /* AssociationPrefetchingRowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingRowTests.swift; sourceTree = ""; }; + 56DF001A228DDBA300D611F3 /* AssociationPrefetchingCodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingCodableRecordTests.swift; sourceTree = ""; }; 56E5D7CA1B4D3FED00430942 /* GRDB.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = GRDB.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 56E5D7D31B4D3FEE00430942 /* GRDBiOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBiOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 56E5D7F91B4D422D00430942 /* GRDBOSXTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBOSXTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 56E8CE0C1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleFetchTests.swift; sourceTree = ""; }; 56E8CE0F1BB4FE5B00828BEC /* StatementColumnConvertibleFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementColumnConvertibleFetchTests.swift; sourceTree = ""; }; + 56E9FACA221046FD00C703A8 /* SQLInterpolation+QueryInterface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SQLInterpolation+QueryInterface.swift"; sourceTree = ""; }; + 56E9FAD7221053DC00C703A8 /* SQLLiteral.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLLiteral.swift; sourceTree = ""; }; 56EA63C4209C7CE3009715B8 /* DerivableRequestTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DerivableRequestTests.swift; sourceTree = ""; }; 56EA86931C91DFE7002BB4DF /* DatabaseReaderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseReaderTests.swift; sourceTree = ""; }; 56EA869D1C932597002BB4DF /* DatabasePoolReadOnlyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolReadOnlyTests.swift; sourceTree = ""; }; @@ -1240,7 +1314,7 @@ 56ED8A7E1DAB8D6800BD0ABC /* FTS5WrapperTokenizerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5WrapperTokenizerTests.swift; sourceTree = ""; }; 56F0B98E1B6001C600A2F135 /* FoundationNSDateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSDateTests.swift; sourceTree = ""; }; 56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResultCodeTests.swift; sourceTree = ""; }; - 56F3E7621E67F8C100BF0F01 /* Fixits-0.101.1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0.101.1.swift"; sourceTree = ""; }; + 56FBFED82210731A00945324 /* SQLRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SQLRequest.swift; sourceTree = ""; }; 56FC98771D969DEF00E3C842 /* SQLExpression+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SQLExpression+QueryInterface.swift"; sourceTree = ""; }; 56FDECE11BB32DFD009AD709 /* RowFromStatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFromStatementTests.swift; sourceTree = ""; }; 56FEE7FA1F47253700D930EA /* TableRecordTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableRecordTests.swift; sourceTree = ""; }; @@ -1522,30 +1596,17 @@ 56300B6D1C53F592005A543B /* QueryInterface */ = { isa = PBXGroup; children = ( - 5653EAF720944BC900F46237 /* Association */, - 56CEB5401EAA359A00BFAF62 /* Column.swift */, - 56D91AA82205F2F000770D8D /* DatabasePromise.swift */, - 56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */, + 5656A8AC2295BFD6001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift */, + 56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterface.swift */, 56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */, - 56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */, - 5653EB242094A14400F46237 /* QueryInterfaceRequest+Association.swift */, - 5616AAF0207CD45E00AC3664 /* RequestProtocols.swift */, - 5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */, - 566475991D97D8A000FF74B8 /* SQLCollection.swift */, - 56CEB5411EAA359A00BFAF62 /* SQLExpressible.swift */, - 56CEB5421EAA359A00BFAF62 /* SQLExpression.swift */, - 56FC98771D969DEF00E3C842 /* SQLExpression+QueryInterface.swift */, - 5653EC0B2098738B00F46237 /* SQLGenerationContext.swift */, - 56CEB5431EAA359A00BFAF62 /* SQLOrdering.swift */, - 56D91AA12205E03700770D8D /* SQLRelation.swift */, - 56CEB5441EAA359A00BFAF62 /* SQLSelectable.swift */, - 566475A11D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift */, - 56D91AAF2205F8AC00770D8D /* SQLSelectQuery.swift */, - 568D13182207213E00674B58 /* SQLSelectQueryGenerator.swift */, - 566475B91D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift */, - 566475C91D981D5E00FF74B8 /* Support */, - 566AD8B11D5318F4002EC1A8 /* TableDefinition.swift */, - 5698AC771DA37DCB0056AF8C /* VirtualTableModule.swift */, + 5656A8182295B044001FF3FF /* Request */, + 5656A8AB2295BFD6001FF3FF /* Row+QueryInterfaceRequest.swift */, + 5656A8142295AF75001FF3FF /* Schema */, + 5656A8172295B00E001FF3FF /* SQL */, + 5656A8162295AFD6001FF3FF /* SQLGeneration */, + 56E9FACA221046FD00C703A8 /* SQLInterpolation+QueryInterface.swift */, + 5656A8A92295BFD5001FF3FF /* TableRecord+Association.swift */, + 5656A8AA2295BFD6001FF3FF /* TableRecord+QueryInterfaceRequest.swift */, ); path = QueryInterface; sourceTree = ""; @@ -1573,6 +1634,7 @@ 563B06C02185D29F00B38F35 /* ValueObservationExtentTests.swift */, 563B06C92185D2E500B38F35 /* ValueObservationFetchTests.swift */, 564CE4E821B2E06F00652B19 /* ValueObservationMapTests.swift */, + 5656A7F822946B33001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */, 563B06C22185D29F00B38F35 /* ValueObservationReadonlyTests.swift */, 563B071421862C4600B38F35 /* ValueObservationRecordTests.swift */, 563B06BC2185CCD300B38F35 /* ValueObservationReducerTests.swift */, @@ -1593,11 +1655,25 @@ 5653EAC920944B4D00F46237 /* AssociationBelongsToSQLTests.swift */, 5653EAC620944B4C00F46237 /* AssociationChainRowScopesTests.swift */, 5653EACF20944B4E00F46237 /* AssociationChainSQLTests.swift */, + 56057C4E2291B16900A7CB10 /* AssociationHasManyRowScopeTests.swift */, + 56959632222D056D002CB7C9 /* AssociationHasManySQLTests.swift */, + 56057C612291C7C600A7CB10 /* AssociationHasManyThroughRowScopeTests.swift */, + 56959615222C456C002CB7C9 /* AssociationHasManyThroughSQLTests.swift */, 5653EACA20944B4D00F46237 /* AssociationHasOneSQLDerivationTests.swift */, 5653EACC20944B4D00F46237 /* AssociationHasOneSQLTests.swift */, + 5615B287222B17BF00061C1C /* AssociationHasOneThroughDecodableRecordTests.swift */, + 5615B274222B107900061C1C /* AssociationHasOneThroughFetchableRecordTests.swift */, + 5615B269222AFE8F00061C1C /* AssociationHasOneThroughRowScopeTests.swift */, + 5615B25A222AE1B400061C1C /* AssociationHasOneThroughSQLDerivationTests.swift */, + 56AE6423222AAC9500AD1B0B /* AssociationHasOneThroughSQLTests.swift */, 5653EAD220944B4E00F46237 /* AssociationParallelDecodableRecordTests.swift */, 5653EACD20944B4D00F46237 /* AssociationParallelRowScopesTests.swift */, 5653EAD520944B4F00F46237 /* AssociationParallelSQLTests.swift */, + 56DF001A228DDBA300D611F3 /* AssociationPrefetchingCodableRecordTests.swift */, + 569BBA20228DE51800478429 /* AssociationPrefetchingFetchableRecordTests.swift */, + 560432A2228F1667009D3FE2 /* AssociationPrefetchingObservationTests.swift */, + 56DF0019228DDBA200D611F3 /* AssociationPrefetchingRowTests.swift */, + 560714E2227DD0810091BB10 /* AssociationPrefetchingSQLTests.swift */, 5653EAC820944B4D00F46237 /* AssociationRowScopeSearchTests.swift */, 5653EACB20944B4D00F46237 /* AssociationTableAliasTestsSQLTests.swift */, ); @@ -1610,18 +1686,72 @@ 5653EAFA20944C7B00F46237 /* Association.swift */, 563EF42C2161180D007DAACD /* AssociationAggregate.swift */, 5653EAF820944C7B00F46237 /* BelongsToAssociation.swift */, - 5653EAFF20944C7C00F46237 /* ForeignKey.swift */, - 5653EAF920944C7B00F46237 /* ForeignKeyRequest.swift */, 5653EAFB20944C7B00F46237 /* HasManyAssociation.swift */, + 56959628222C462D002CB7C9 /* HasManyThroughAssociation.swift */, 5653EB0220944C7C00F46237 /* HasOneAssociation.swift */, + 56AE64112229A53700AD1B0B /* HasOneThroughAssociation.swift */, ); path = Association; sourceTree = ""; }; + 5656A8142295AF75001FF3FF /* Schema */ = { + isa = PBXGroup; + children = ( + 566AD8B11D5318F4002EC1A8 /* TableDefinition.swift */, + 5698AC771DA37DCB0056AF8C /* VirtualTableModule.swift */, + ); + path = Schema; + sourceTree = ""; + }; + 5656A8162295AFD6001FF3FF /* SQLGeneration */ = { + isa = PBXGroup; + children = ( + 5653EC0B2098738B00F46237 /* SQLGenerationContext.swift */, + 568D13182207213E00674B58 /* SQLQueryGenerator.swift */, + ); + path = SQLGeneration; + sourceTree = ""; + }; + 5656A8172295B00E001FF3FF /* SQL */ = { + isa = PBXGroup; + children = ( + 56CEB5401EAA359A00BFAF62 /* Column.swift */, + 56D91AA82205F2F000770D8D /* DatabasePromise.swift */, + 5656A81D2295B12F001FF3FF /* SQLAssociation.swift */, + 5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */, + 566475991D97D8A000FF74B8 /* SQLCollection.swift */, + 56CEB5411EAA359A00BFAF62 /* SQLExpressible.swift */, + 56CEB5421EAA359A00BFAF62 /* SQLExpression.swift */, + 56FC98771D969DEF00E3C842 /* SQLExpression+QueryInterface.swift */, + 5653EAF920944C7B00F46237 /* SQLForeignKeyRequest.swift */, + 566475CA1D981D5E00FF74B8 /* SQLFunctions.swift */, + 566475CB1D981D5E00FF74B8 /* SQLOperators.swift */, + 56CEB5431EAA359A00BFAF62 /* SQLOrdering.swift */, + 56D91AAF2205F8AC00770D8D /* SQLQuery.swift */, + 56D91AA12205E03700770D8D /* SQLRelation.swift */, + 56CEB5441EAA359A00BFAF62 /* SQLSelectable.swift */, + 566475A11D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift */, + 566475B91D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift */, + ); + path = SQL; + sourceTree = ""; + }; + 5656A8182295B044001FF3FF /* Request */ = { + isa = PBXGroup; + children = ( + 5653EAF720944BC900F46237 /* Association */, + 56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */, + 5653EB242094A14400F46237 /* QueryInterfaceRequest+Association.swift */, + 5616AAF0207CD45E00AC3664 /* RequestProtocols.swift */, + ); + path = Request; + sourceTree = ""; + }; 5659F4861EA8D94E004A4992 /* Utils */ = { isa = PBXGroup; children = ( 563EF4492161F179007DAACD /* Inflections.swift */, + 569BBA482291707D00478429 /* Inflections+English.swift */, 563EF414215F87EB007DAACD /* OrderedDictionary.swift */, 5659F4971EA8D989004A4992 /* Pool.swift */, 5659F48F1EA8D964004A4992 /* ReadWriteBox.swift */, @@ -1631,15 +1761,6 @@ path = Utils; sourceTree = ""; }; - 566475C91D981D5E00FF74B8 /* Support */ = { - isa = PBXGroup; - children = ( - 566475CA1D981D5E00FF74B8 /* SQLFunctions.swift */, - 566475CB1D981D5E00FF74B8 /* SQLOperators.swift */, - ); - path = Support; - sourceTree = ""; - }; 5674A7251F30A8EF0095F066 /* FetchableRecord */ = { isa = PBXGroup; children = ( @@ -1711,6 +1832,9 @@ 5605F1861C69111300235C62 /* DatabaseRegionTests.swift */, 56AF746A1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift */, 56EB0AB11BCD787300A3DC55 /* DataMemoryTests.swift */, + 569BBA4522906A8200478429 /* InflectionsTests.json */, + 569BBA3522905FFA00478429 /* InflectionsTests.swift */, + 56043299228F00C2009D3FE2 /* OrderedDictionaryTests.swift */, 56FF45551D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift */, 56A4CDAF1D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift */, ); @@ -1748,6 +1872,8 @@ 56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */, 56A2381D1B9C74A90082EB20 /* Row */, 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */, + 567F0B2C220F0E2E00D111FB /* SQLInterpolationTests.swift */, + 56B86E72220FF4E000524C16 /* SQLLiteralTests.swift */, 568068301EBBA26100EFB8AA /* SQLRequestTests.swift */, 56A238201B9C74A90082EB20 /* Statement */, 56E8CE0F1BB4FE5B00828BEC /* StatementColumnConvertibleFetchTests.swift */, @@ -1841,6 +1967,9 @@ 567404871CEF84C8003ED5CC /* RowAdapter.swift */, 56BB6EA81D3009B100A1CA52 /* SchedulingWatchdog.swift */, 560A37A61C8FF6E500949E71 /* SerializedDatabase.swift */, + 569D6DDD220EF9E100A058A9 /* SQLInterpolation.swift */, + 56FBFED82210731A00945324 /* SQLRequest.swift */, + 56E9FAD7221053DC00C703A8 /* SQLLiteral.swift */, 56A238781B9C75030082EB20 /* Statement.swift */, 566B912A1FA4D0CC0012D5B0 /* StatementAuthorizer.swift */, 560D923F1C672C3E00F4F92B /* StatementColumnConvertible.swift */, @@ -1862,12 +1991,13 @@ 56A2389F1B9C753B0082EB20 /* Record */ = { isa = PBXGroup; children = ( + 56172947223533F40006E219 /* EncodableRecord.swift */, + 5674A6F31F307F600095F066 /* EncodableRecord+Encodable.swift */, 56CEB4F01EAA2EFA00BFAF62 /* FetchableRecord.swift */, 5674A6F21F307F600095F066 /* FetchableRecord+Decodable.swift */, 56D51CFF1EA789FA0074638A /* FetchableRecord+TableRecord.swift */, 31A7787C1C6A4DD600F507F6 /* FetchedRecordsController.swift */, 560D92441C672C4B00F4F92B /* PersistableRecord.swift */, - 5674A6F31F307F600095F066 /* PersistableRecord+Encodable.swift */, 56A238A11B9C753B0082EB20 /* Record.swift */, 560D92461C672C4B00F4F92B /* TableRecord.swift */, ); @@ -1923,21 +2053,6 @@ path = fmdb/src/fmdb; sourceTree = ""; }; - 56BF6D2B1DEF47DA006039A3 /* Legacy */ = { - isa = PBXGroup; - children = ( - 56BF6D2E1DEF47DA006039A3 /* Fixits-Swift2.swift */, - 56BF6D2C1DEF47DA006039A3 /* Fixits-0-84-0.swift */, - 56BF6D2D1DEF47DA006039A3 /* Fixits-0-90-1.swift */, - 56F3E7621E67F8C100BF0F01 /* Fixits-0.101.1.swift */, - 56E06F051E859064008AE2A4 /* Fixits-0.102.0.swift */, - 56D121591ED34978001347D2 /* Fixits-0.109.0.swift */, - 56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */, - 569A98EC2039B6F3008D7DBF /* Fixits-3.0.swift */, - ); - path = Legacy; - sourceTree = ""; - }; 56CA21FF1BB414FE009A04C5 /* Products */ = { isa = PBXGroup; children = ( @@ -1952,6 +2067,14 @@ name = Products; sourceTree = ""; }; + 56D7E449221595FE0052464B /* Fixit */ = { + isa = PBXGroup; + children = ( + 567ECE4E2222E431009245CA /* GRDB-4.0.swift */, + ); + path = Fixit; + sourceTree = ""; + }; 56DAA2C41DE99D8D006E10C8 /* Cursor */ = { isa = PBXGroup; children = ( @@ -2042,8 +2165,8 @@ isa = PBXGroup; children = ( 56A2386F1B9C75030082EB20 /* Core */, + 56D7E449221595FE0052464B /* Fixit */, 5698AC291D9E5A480056AF8C /* FTS */, - 56BF6D2B1DEF47DA006039A3 /* Legacy */, 56A238911B9C750B0082EB20 /* Migration */, 56300B6D1C53F592005A543B /* QueryInterface */, 56A2389F1B9C753B0082EB20 /* Record */, @@ -2116,7 +2239,6 @@ buildRules = ( ); dependencies = ( - 560C97D01C0E22D300BF8471 /* PBXTargetDependency */, 560C97D21C0E22D300BF8471 /* PBXTargetDependency */, ); name = GRDBOSXPerformanceTests; @@ -2276,11 +2398,11 @@ }; 56E5D7F81B4D422D00430942 = { CreatedOnToolsVersion = 7.0; - LastSwiftMigration = 0900; + LastSwiftMigration = 1020; }; DC3773F219C8CBB3004FCF85 = { CreatedOnToolsVersion = 6.1; - LastSwiftMigration = 0900; + LastSwiftMigration = 1020; }; }; }; @@ -2289,6 +2411,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -2411,6 +2534,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 569BBA4722906A8200478429 /* InflectionsTests.json in Resources */, 568735A21CEDE16C009B9116 /* Betty.jpeg in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -2419,6 +2543,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 569BBA4622906A8200478429 /* InflectionsTests.json in Resources */, 56D496C21D81374C008276D7 /* Betty.jpeg in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -2480,11 +2605,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 569A98EF2039B6F3008D7DBF /* Fixits-3.0.swift in Sources */, 5616AAF3207CD45E00AC3664 /* RequestProtocols.swift in Sources */, 56B964BF1DA51D0A0002DA19 /* FTS5Pattern.swift in Sources */, + 5656A8B82295BFD7001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift in Sources */, 56D51D061EA789FA0074638A /* FetchableRecord+TableRecord.swift in Sources */, 565490CE1D5AE252005622CB /* NSNull.swift in Sources */, + 5656A8202295B12F001FF3FF /* SQLAssociation.swift in Sources */, 565490E41D5AE252005622CB /* TableRecord.swift in Sources */, 564CE5AE21B8FAB400652B19 /* DatabaseRegionObservation.swift in Sources */, 565490CF1D5AE252005622CB /* NSNumber.swift in Sources */, @@ -2495,17 +2621,19 @@ 565490C11D5AE236005622CB /* FetchRequest.swift in Sources */, 5613ED4621A95B2C00DC7A68 /* ValueReducer.swift in Sources */, 5698AD1C1DAAD17F0056AF8C /* FTS5Tokenizer.swift in Sources */, - 56CEB5171EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */, - 56D91AB22205F8AC00770D8D /* SQLSelectQuery.swift in Sources */, + 56CEB5171EAA324B00BFAF62 /* FTS3+QueryInterface.swift in Sources */, + 5656A8B22295BFD7001FF3FF /* TableRecord+QueryInterfaceRequest.swift in Sources */, + 56D91AB22205F8AC00770D8D /* SQLQuery.swift in Sources */, 56B964B71DA51D010002DA19 /* FTS5TokenizerDescriptor.swift in Sources */, 5613ED5221A95C6D00DC7A68 /* ValueObservation+DatabaseValueConvertible.swift in Sources */, 5653EB0B20944C7C00F46237 /* Association.swift in Sources */, 564CE59F21B7A8B500652B19 /* ValueObservation+DistinctUntilChanged.swift in Sources */, 56F5ABDA1D814330001F60CB /* NSData.swift in Sources */, - 56D121601ED34978001347D2 /* Fixits-0.109.0.swift in Sources */, 564F9C341F07611900877A00 /* DatabaseFunction.swift in Sources */, 566475A81D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift in Sources */, 5659F4961EA8D964004A4992 /* ReadWriteBox.swift in Sources */, + 56172950223533F40006E219 /* EncodableRecord.swift in Sources */, + 56AE64142229A53700AD1B0B /* HasOneThroughAssociation.swift in Sources */, 5613ED3721A95A5C00DC7A68 /* ValueObservation+Map.swift in Sources */, 5659F48E1EA8D94E004A4992 /* Utils.swift in Sources */, 564CE43321AA901800652B19 /* ValueObserver.swift in Sources */, @@ -2515,6 +2643,7 @@ 563B06AD217EF0CC00B38F35 /* ValueObservation.swift in Sources */, 5674A6EF1F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */, 565490D81D5AE252005622CB /* DatabaseMigrator.swift in Sources */, + 5656A8AF2295BFD7001FF3FF /* TableRecord+Association.swift in Sources */, 56CEB5601EAA359A00BFAF62 /* SQLOrdering.swift in Sources */, 565490C21D5AE236005622CB /* Row.swift in Sources */, 565490C71D5AE236005622CB /* StatementColumnConvertible.swift in Sources */, @@ -2527,25 +2656,25 @@ 5613ED4A21A95C1200DC7A68 /* ValueObservation+Row.swift in Sources */, 565490D51D5AE252005622CB /* DatabaseValueConvertible+RawRepresentable.swift in Sources */, 565490C51D5AE236005622CB /* SerializedDatabase.swift in Sources */, - 56F3E7691E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */, 5698AC7E1DA37DCB0056AF8C /* VirtualTableModule.swift in Sources */, 564CE52221B3129A00652B19 /* ValueObservation+MapReducer.swift in Sources */, - 5653EB1A20944C7C00F46237 /* ForeignKey.swift in Sources */, 5698AC3D1D9E5A590056AF8C /* FTS3Pattern.swift in Sources */, 563EF45D2163309F007DAACD /* Inflections.swift in Sources */, + 569D6DE0220EF9E100A058A9 /* SQLInterpolation.swift in Sources */, + 567ECE512222E431009245CA /* GRDB-4.0.swift in Sources */, 565490BF1D5AE236005622CB /* DatabaseValueConvertible.swift in Sources */, 566B91191FA4C3F50012D5B0 /* DatabaseCollation.swift in Sources */, 5613ED4E21A95C4300DC7A68 /* ValueObservation+FetchableRecord.swift in Sources */, 5613ED5621A95DD000DC7A68 /* ValueObservation+Count.swift in Sources */, 56CEB5591EAA359A00BFAF62 /* SQLExpression.swift in Sources */, 5674A6FF1F307F600095F066 /* FetchableRecord+Decodable.swift in Sources */, - 56E06F181E85906E008AE2A4 /* Fixits-0.102.0.swift in Sources */, + 56E9FAD9221053DD00C703A8 /* SQLLiteral.swift in Sources */, 56B964A31DA51B4C0002DA19 /* FTS5.swift in Sources */, 56D91AAB2205F2F100770D8D /* DatabasePromise.swift in Sources */, 566475A01D97D8A000FF74B8 /* SQLCollection.swift in Sources */, 565490BB1D5AE236005622CB /* DatabaseReader.swift in Sources */, 5659F4A61EA8D997004A4992 /* Result.swift in Sources */, - 5674A6F81F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */, + 5674A6F81F307F600095F066 /* EncodableRecord+Encodable.swift in Sources */, 565490C31D5AE236005622CB /* RowAdapter.swift in Sources */, 5698AD3B1DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */, 5659F49E1EA8D989004A4992 /* Pool.swift in Sources */, @@ -2556,36 +2685,37 @@ 565490DF1D5AE252005622CB /* TableDefinition.swift in Sources */, 565490B71D5AE236005622CB /* Database.swift in Sources */, 5674A6E81F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */, - 56873BF21F2CB400004D24B4 /* Fixits-1.2.swift in Sources */, - 56BF6D431DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */, + 56E9FACD221046FD00C703A8 /* SQLInterpolation+QueryInterface.swift in Sources */, 5653EB2320944C7C00F46237 /* HasOneAssociation.swift in Sources */, 565490C01D5AE236005622CB /* DatabaseWriter.swift in Sources */, 565490C41D5AE236005622CB /* SchedulingWatchdog.swift in Sources */, 566B91311FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */, 56CEB54B1EAA359A00BFAF62 /* Column.swift in Sources */, 565490CC1D5AE252005622CB /* (null) in Sources */, - 56BF6D351DEF47DA006039A3 /* Fixits-0-84-0.swift in Sources */, 566B91291FA4CF810012D5B0 /* Database+Schema.swift in Sources */, 5671FC261DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift in Sources */, 5653EC142098738B00F46237 /* SQLGenerationContext.swift in Sources */, 56CEB5521EAA359A00BFAF62 /* SQLExpressible.swift in Sources */, - 568D13212207213F00674B58 /* SQLSelectQueryGenerator.swift in Sources */, + 568D13212207213F00674B58 /* SQLQueryGenerator.swift in Sources */, 565490DB1D5AE252005622CB /* SQLCollatedExpression.swift in Sources */, 5674A7071F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift in Sources */, 565490C61D5AE236005622CB /* Statement.swift in Sources */, 56CEB5071EAA2F4D00BFAF62 /* FTS4.swift in Sources */, 56CEB4F71EAA2EFA00BFAF62 /* FetchableRecord.swift in Sources */, + 56FBFEDB2210731A00945324 /* SQLRequest.swift in Sources */, 56F5ABD91D814330001F60CB /* Data.swift in Sources */, 565490D41D5AE252005622CB /* (null) in Sources */, 566475D21D981D5E00FF74B8 /* SQLFunctions.swift in Sources */, 565490B61D5AE236005622CB /* Configuration.swift in Sources */, 565490E11D5AE252005622CB /* PersistableRecord.swift in Sources */, 56FC987E1D969DEF00E3C842 /* SQLExpression+QueryInterface.swift in Sources */, + 569BBA50229170FA00478429 /* Inflections+English.swift in Sources */, 565490E01D5AE252005622CB /* FetchedRecordsController.swift in Sources */, 566B91391FA4D3810012D5B0 /* TransactionObserver.swift in Sources */, 565490C81D5AE252005622CB /* CGFloat.swift in Sources */, 56F5ABDC1D814330001F60CB /* URL.swift in Sources */, 569EF0E4200D2D8400A9FA45 /* DatabaseRegion.swift in Sources */, + 5695962B222C462D002CB7C9 /* HasManyThroughAssociation.swift in Sources */, 565490D31D5AE252005622CB /* (null) in Sources */, 566475D91D981D5E00FF74B8 /* SQLOperators.swift in Sources */, 566B910F1FA4C3970012D5B0 /* Database+Statements.swift in Sources */, @@ -2593,9 +2723,9 @@ 565490CB1D5AE252005622CB /* (null) in Sources */, 563EF417215F87EB007DAACD /* OrderedDictionary.swift in Sources */, 565490D61D5AE252005622CB /* StandardLibrary.swift in Sources */, + 5656A8B52295BFD7001FF3FF /* Row+QueryInterfaceRequest.swift in Sources */, 565490B81D5AE236005622CB /* DatabaseError.swift in Sources */, 564CE4D821B2DEB600652B19 /* ValueObservation+CompactMap.swift in Sources */, - 56BF6D3C1DEF47DA006039A3 /* Fixits-0-90-1.swift in Sources */, 56DAA2E11DE9C827006E10C8 /* Cursor.swift in Sources */, 5653EB0520944C7C00F46237 /* BelongsToAssociation.swift in Sources */, 5644DE6F20F8C32E001FFDDE /* DatabaseValueConversion.swift in Sources */, @@ -2603,7 +2733,7 @@ 563EF42F2161180D007DAACD /* AssociationAggregate.swift in Sources */, 565490BA1D5AE236005622CB /* DatabaseQueue.swift in Sources */, 565490CD1D5AE252005622CB /* Date.swift in Sources */, - 5653EB0820944C7C00F46237 /* ForeignKeyRequest.swift in Sources */, + 5653EB0820944C7C00F46237 /* SQLForeignKeyRequest.swift in Sources */, 565490BE1D5AE236005622CB /* DatabaseValue.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -2628,13 +2758,13 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 56BF6D401DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */, 5636E9BF1D22574100B9B05F /* FetchRequest.swift in Sources */, 563EF42E2161180D007DAACD /* AssociationAggregate.swift in Sources */, 56BB6EAC1D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */, 56300B791C53F592005A543B /* QueryInterfaceRequest.swift in Sources */, + 5656A8B12295BFD7001FF3FF /* TableRecord+QueryInterfaceRequest.swift in Sources */, 56CEB5561EAA359A00BFAF62 /* SQLExpression.swift in Sources */, - 5674A6F91F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */, + 5674A6F91F307F600095F066 /* EncodableRecord+Encodable.swift in Sources */, 5605F18E1C6B1A8700235C62 /* SQLCollatedExpression.swift in Sources */, 566475D61D981D5E00FF74B8 /* SQLOperators.swift in Sources */, 5698AD381DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */, @@ -2647,22 +2777,21 @@ 5605F1641C672E4000235C62 /* Date.swift in Sources */, 5613ED4921A95C1200DC7A68 /* ValueObservation+Row.swift in Sources */, 566B91361FA4D3810012D5B0 /* TransactionObserver.swift in Sources */, + 5656A8B42295BFD7001FF3FF /* Row+QueryInterfaceRequest.swift in Sources */, 564CE43221AA901800652B19 /* ValueObserver.swift in Sources */, 5605F1721C672E4000235C62 /* DatabaseValueConvertible+RawRepresentable.swift in Sources */, - 56CEB5141EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */, + 56CEB5141EAA324B00BFAF62 /* FTS3+QueryInterface.swift in Sources */, 566475CF1D981D5E00FF74B8 /* SQLFunctions.swift in Sources */, 5659F49B1EA8D989004A4992 /* Pool.swift in Sources */, 5653EB2220944C7C00F46237 /* HasOneAssociation.swift in Sources */, - 569A98EE2039B6F3008D7DBF /* Fixits-3.0.swift in Sources */, 56CEB51C1EAA328900BFAF62 /* FTS5+QueryInterface.swift in Sources */, 5698AC3A1D9E5A590056AF8C /* FTS3Pattern.swift in Sources */, 5664759D1D97D8A000FF74B8 /* SQLCollection.swift in Sources */, - 568D13202207213E00674B58 /* SQLSelectQueryGenerator.swift in Sources */, + 568D13202207213E00674B58 /* SQLQueryGenerator.swift in Sources */, 5674048A1CEF84C8003ED5CC /* RowAdapter.swift in Sources */, 563EF416215F87EB007DAACD /* OrderedDictionary.swift in Sources */, 563363C51C942C37000BE133 /* DatabaseWriter.swift in Sources */, 5698AD1B1DAAD17D0056AF8C /* FTS5Tokenizer.swift in Sources */, - 56F3E7661E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */, 5653EB0420944C7C00F46237 /* BelongsToAssociation.swift in Sources */, 56B964B41DA51D010002DA19 /* FTS5TokenizerDescriptor.swift in Sources */, 560A37A81C8FF6E500949E71 /* SerializedDatabase.swift in Sources */, @@ -2672,13 +2801,16 @@ 5605F16A1C672E4000235C62 /* NSString.swift in Sources */, 566B910C1FA4C3970012D5B0 /* Database+Statements.swift in Sources */, 56A8C2331D1914540096E9D4 /* UUID.swift in Sources */, - 56BF6D321DEF47DA006039A3 /* Fixits-0-84-0.swift in Sources */, 560D92411C672C3E00F4F92B /* DatabaseValueConvertible.swift in Sources */, 566475BD1D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift in Sources */, 56A238A51B9C753B0082EB20 /* Record.swift in Sources */, + 5656A8B72295BFD7001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift in Sources */, 5671FC231DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift in Sources */, 56D51D031EA789FA0074638A /* FetchableRecord+TableRecord.swift in Sources */, 560D924C1C672C4B00F4F92B /* TableRecord.swift in Sources */, + 569BBA4F229170F900478429 /* Inflections+English.swift in Sources */, + 5656A81F2295B12F001FF3FF /* SQLAssociation.swift in Sources */, + 5617294F223533F40006E219 /* EncodableRecord.swift in Sources */, 564CE52121B3129A00652B19 /* ValueObservation+MapReducer.swift in Sources */, 5653EC132098738B00F46237 /* SQLGenerationContext.swift in Sources */, 5657AB121D10899D006283EF /* URL.swift in Sources */, @@ -2688,9 +2820,10 @@ 56DAA2DE1DE9C827006E10C8 /* Cursor.swift in Sources */, 560A37A51C8F625000949E71 /* DatabasePool.swift in Sources */, 5674A7081F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift in Sources */, + 56AE64132229A53700AD1B0B /* HasOneThroughAssociation.swift in Sources */, 56A2388C1B9C75030082EB20 /* Statement.swift in Sources */, 5659F4931EA8D964004A4992 /* ReadWriteBox.swift in Sources */, - 56D91AB12205F8AC00770D8D /* SQLSelectQuery.swift in Sources */, + 56D91AB12205F8AC00770D8D /* SQLQuery.swift in Sources */, 56B7F43B1BEB42D500E39BBF /* Migration.swift in Sources */, 5690C3431D23E82A00E59934 /* Data.swift in Sources */, 5674A7001F307F600095F066 /* FetchableRecord+Decodable.swift in Sources */, @@ -2704,22 +2837,24 @@ 56CEB4F41EAA2EFA00BFAF62 /* FetchableRecord.swift in Sources */, 569531201C907A8C00CF1A2B /* DatabaseSchemaCache.swift in Sources */, 5605F15E1C672E4000235C62 /* DatabaseDateComponents.swift in Sources */, - 56BF6D391DEF47DA006039A3 /* Fixits-0-90-1.swift in Sources */, + 5695962A222C462D002CB7C9 /* HasManyThroughAssociation.swift in Sources */, 563363C11C942C04000BE133 /* DatabaseReader.swift in Sources */, - 5653EB1920944C7C00F46237 /* ForeignKey.swift in Sources */, 5659F4A31EA8D997004A4992 /* Result.swift in Sources */, 56B964BC1DA51D0A0002DA19 /* FTS5Pattern.swift in Sources */, 5605F1661C672E4000235C62 /* NSNull.swift in Sources */, + 5656A8AE2295BFD7001FF3FF /* TableRecord+Association.swift in Sources */, 569EF0E3200D2D8400A9FA45 /* DatabaseRegion.swift in Sources */, 56A238841B9C75030082EB20 /* DatabaseQueue.swift in Sources */, 563B06AC217EF0CC00B38F35 /* ValueObservation.swift in Sources */, 56D91AAA2205F2F100770D8D /* DatabasePromise.swift in Sources */, 5698AC7B1DA37DCB0056AF8C /* VirtualTableModule.swift in Sources */, + 569D6DDF220EF9E100A058A9 /* SQLInterpolation.swift in Sources */, 56A238821B9C75030082EB20 /* DatabaseError.swift in Sources */, - 56D1215D1ED34978001347D2 /* Fixits-0.109.0.swift in Sources */, 5653EB0D20944C7C00F46237 /* HasManyAssociation.swift in Sources */, + 567ECE502222E431009245CA /* GRDB-4.0.swift in Sources */, 566AD8B51D5318F4002EC1A8 /* TableDefinition.swift in Sources */, 5698AD241DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */, + 56FBFED92210731A00945324 /* SQLRequest.swift in Sources */, 5644DE6E20F8C32E001FFDDE /* DatabaseValueConversion.swift in Sources */, C96C0F2C2084A459006B2981 /* SQLiteDateParser.swift in Sources */, 5605F1681C672E4000235C62 /* NSNumber.swift in Sources */, @@ -2727,13 +2862,15 @@ 564CE5AD21B8FAB400652B19 /* DatabaseRegionObservation.swift in Sources */, 56CEB5041EAA2F4D00BFAF62 /* FTS4.swift in Sources */, 5605F1741C672E4000235C62 /* StandardLibrary.swift in Sources */, + 56E9FACC221046FD00C703A8 /* SQLInterpolation+QueryInterface.swift in Sources */, 560D92481C672C4B00F4F92B /* PersistableRecord.swift in Sources */, 5613ED4521A95B2C00DC7A68 /* ValueReducer.swift in Sources */, 5613ED5121A95C6D00DC7A68 /* ValueObservation+DatabaseValueConvertible.swift in Sources */, 560D92431C672C3E00F4F92B /* StatementColumnConvertible.swift in Sources */, 5613ED3621A95A5C00DC7A68 /* ValueObservation+Map.swift in Sources */, 566475A51D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift in Sources */, - 5653EB0720944C7C00F46237 /* ForeignKeyRequest.swift in Sources */, + 56E9FAD8221053DD00C703A8 /* SQLLiteral.swift in Sources */, + 5653EB0720944C7C00F46237 /* SQLForeignKeyRequest.swift in Sources */, 5657AABC1D107001006283EF /* NSData.swift in Sources */, 31A778841C6A4E0600F507F6 /* FetchedRecordsController.swift in Sources */, 5613ED4021A95A8B00DC7A68 /* ValueObservation+Combine.swift in Sources */, @@ -2742,7 +2879,6 @@ 566B91261FA4CF810012D5B0 /* Database+Schema.swift in Sources */, 566B912E1FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */, 56CEB5641EAA359A00BFAF62 /* SQLSelectable.swift in Sources */, - 56873BEF1F2CB400004D24B4 /* Fixits-1.2.swift in Sources */, 56D91AA32205E03700770D8D /* SQLRelation.swift in Sources */, 564F9C311F07611600877A00 /* DatabaseFunction.swift in Sources */, 564CE59E21B7A8B500652B19 /* ValueObservation+DistinctUntilChanged.swift in Sources */, @@ -2778,16 +2914,19 @@ 56A2384C1B9C74A90082EB20 /* UpdateStatementTests.swift in Sources */, 56A2384E1B9C74A90082EB20 /* DatabaseMigratorTests.swift in Sources */, 56CC9244201E034D00CB597E /* PrefixWhileCursorTests.swift in Sources */, + 560714E4227DD0810091BB10 /* AssociationPrefetchingSQLTests.swift in Sources */, 5657AB4A1D108BA9006283EF /* FoundationNSNullTests.swift in Sources */, 569531351C919DF200CF1A2B /* DatabasePoolCollationTests.swift in Sources */, 56A2385A1B9C74A90082EB20 /* RecordPrimaryKeySingleTests.swift in Sources */, 562756471E963AAC0035B653 /* DatabaseWriterTests.swift in Sources */, 569531381C919DF700CF1A2B /* DatabasePoolFunctionTests.swift in Sources */, 563B06F821861D8400B38F35 /* ValueObservationCountTests.swift in Sources */, + 56DF001C228DDBA300D611F3 /* AssociationPrefetchingRowTests.swift in Sources */, 56A238481B9C74A90082EB20 /* RowCopiedFromStatementTests.swift in Sources */, 56EA63C6209C7CE3009715B8 /* DerivableRequestTests.swift in Sources */, 5674A71A1F3087710095F066 /* DatabaseValueConvertibleDecodableTests.swift in Sources */, 5698AC071D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */, + 567F0B2E220F0E2E00D111FB /* SQLInterpolationTests.swift in Sources */, 56C3F7561CF9F12400F6A361 /* DatabaseSavepointTests.swift in Sources */, 56B021CD1D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */, 563B0706218627F800B38F35 /* ValueObservationRowTests.swift in Sources */, @@ -2801,10 +2940,14 @@ 56FDECE31BB32DFD009AD709 /* RowFromStatementTests.swift in Sources */, 56DE7B121C3D93ED00861EB8 /* StatementArgumentsTests.swift in Sources */, 56AF746F1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */, + 569BBA3722905FFA00478429 /* InflectionsTests.swift in Sources */, 5672DE6A1CDB751D0022BA81 /* DatabasePoolBackupTests.swift in Sources */, 5698AC4D1DA2D48A0056AF8C /* FTS3RecordTests.swift in Sources */, + 56057C632291C7C600A7CB10 /* AssociationHasManyThroughRowScopeTests.swift in Sources */, 56B15D0B1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift in Sources */, 56A238681B9C74A90082EB20 /* RecordInitializersTests.swift in Sources */, + 5656A80022946B34001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift in Sources */, + 5615B261222AE1B400061C1C /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */, 56CC9252201E093F00CB597E /* PrefixCursorTests.swift in Sources */, 563363B01C933FF8000BE133 /* MutablePersistableRecordTests.swift in Sources */, 5665FA152129C9D6004D8612 /* DatabaseDateDecodingStrategyTests.swift in Sources */, @@ -2815,12 +2958,14 @@ 56176C6B1EACCCC9000F3F2B /* FTS5CustomTokenizerTests.swift in Sources */, 56300B621C53C42C005A543B /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */, 56EA869F1C932597002BB4DF /* DatabasePoolReadOnlyTests.swift in Sources */, + 5615B288222B17C000061C1C /* AssociationHasOneThroughDecodableRecordTests.swift in Sources */, 567F45AC1F888B2600030B59 /* TruncateOptimizationTests.swift in Sources */, 5657AB621D108BA9006283EF /* FoundationNSURLTests.swift in Sources */, 5657AB6A1D108BA9006283EF /* FoundationURLTests.swift in Sources */, 563B06C42185D29F00B38F35 /* ValueObservationExtentTests.swift in Sources */, 564FCE5F20F7E11B00202B90 /* DatabaseValueConversionErrorTests.swift in Sources */, 5653EADF20944B4F00F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */, + 5695961D222C456C002CB7C9 /* AssociationHasManyThroughSQLTests.swift in Sources */, 56F3E74D1E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */, 56EB0AB31BCD787300A3DC55 /* DataMemoryTests.swift in Sources */, 56B6EF57208CB4E3002F0ACB /* ColumnExpressionTests.swift in Sources */, @@ -2829,8 +2974,10 @@ 56741EAC1E66A8B3003E422D /* FetchRequestTests.swift in Sources */, 5672DE5C1CDB72520022BA81 /* DatabaseQueueBackupTests.swift in Sources */, 56A2385E1B9C74A90082EB20 /* RecordCopyTests.swift in Sources */, + 56B86E7A220FF4E000524C16 /* SQLLiteralTests.swift in Sources */, 56176C6C1EACCCC9000F3F2B /* FTS5PatternTests.swift in Sources */, 563363B21C933FF8000BE133 /* PersistableRecordTests.swift in Sources */, + 5615B26B222AFE8F00061C1C /* AssociationHasOneThroughRowScopeTests.swift in Sources */, 56A238421B9C74A90082EB20 /* DatabaseValueConversionTests.swift in Sources */, 564E73E0203D50B9000C443C /* JoinSupportTests.swift in Sources */, 5674A7121F3087710095F066 /* DatabaseValueConvertibleEncodableTests.swift in Sources */, @@ -2849,9 +2996,11 @@ 5623935B1DEE013C00A6B01F /* FilterCursorTests.swift in Sources */, 5613EDA721A96A9300DC7A68 /* ValueObservationCombineTests.swift in Sources */, 5674A72D1F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */, + 560432A4228F1668009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */, 566A84412041914000E50BFD /* MutablePersistableRecordChangesTests.swift in Sources */, 56176C701EACCCC9000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */, 56FEE7FF1F47253700D930EA /* TableRecordTests.swift in Sources */, + 56057C562291B16A00A7CB10 /* AssociationHasManyRowScopeTests.swift in Sources */, 56A2386A1B9C74A90082EB20 /* RecordSubClassTests.swift in Sources */, 56A2383E1B9C74A90082EB20 /* DatabaseValueTests.swift in Sources */, 567156181CB142AA007DC145 /* DatabaseQueueReadOnlyTests.swift in Sources */, @@ -2859,6 +3008,7 @@ 56A8C2471D1918F00096E9D4 /* FoundationNSUUIDTests.swift in Sources */, 5698AC441DA2BED90056AF8C /* FTS3PatternTests.swift in Sources */, 5698ACBA1DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */, + 5615B276222B107900061C1C /* AssociationHasOneThroughFetchableRecordTests.swift in Sources */, 56176C6F1EACCCC9000F3F2B /* FTS5TokenizerTests.swift in Sources */, 565B0FF01BBC7D980098DE03 /* FetchableRecordTests.swift in Sources */, 5698AC9A1DA4B0430056AF8C /* FTS4RecordTests.swift in Sources */, @@ -2903,19 +3053,24 @@ 56703298212B5450007D270F /* DatabaseUUIDEncodingStrategyTests.swift in Sources */, 5623931C1DECC02000A6B01F /* RowFetchTests.swift in Sources */, 5653EAD720944B4F00F46237 /* AssociationChainRowScopesTests.swift in Sources */, + 569BBA28228DE51800478429 /* AssociationPrefetchingFetchableRecordTests.swift in Sources */, 562393641DEE06D300A6B01F /* CursorTests.swift in Sources */, 563B06C62185D29F00B38F35 /* ValueObservationSchedulingTests.swift in Sources */, 5657AB5A1D108BA9006283EF /* FoundationNSStringTests.swift in Sources */, + 560432A1228F00C2009D3FE2 /* OrderedDictionaryTests.swift in Sources */, 56300B6C1C53D3E8005A543B /* TableRecord+QueryInterfaceRequestTests.swift in Sources */, 5674A7231F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift in Sources */, 56F0B9921B6001C600A2F135 /* FoundationNSDateTests.swift in Sources */, 56A238381B9C74A90082EB20 /* DatabaseTests.swift in Sources */, 5653EAED20944B4F00F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */, 564CE4EA21B2E06F00652B19 /* ValueObservationMapTests.swift in Sources */, + 56959634222D056D002CB7C9 /* AssociationHasManySQLTests.swift in Sources */, 56300B5F1C53C38F005A543B /* QueryInterfaceRequestTests.swift in Sources */, + 56AE6425222AAC9500AD1B0B /* AssociationHasOneThroughSQLTests.swift in Sources */, 5634B10A1CF9B970005360B9 /* TransactionObserverSavepointsTests.swift in Sources */, 560C97C81BFD0B8400BF8471 /* DatabaseFunctionTests.swift in Sources */, 5653EAD920944B4F00F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */, + 56DF001E228DDBA300D611F3 /* AssociationPrefetchingCodableRecordTests.swift in Sources */, 56A2383A1B9C74A90082EB20 /* DatabaseQueueInMemoryTests.swift in Sources */, 56A5E40A1BA2BCF900707640 /* RecordWithColumnNameManglingTests.swift in Sources */, 5653EAF520944B4F00F46237 /* AssociationParallelSQLTests.swift in Sources */, @@ -2958,16 +3113,19 @@ 562206061E420EA4005860AC /* DatabasePoolBackupTests.swift in Sources */, 56D496B51D813413008276D7 /* DatabaseCollationTests.swift in Sources */, 56CC9243201E034D00CB597E /* PrefixWhileCursorTests.swift in Sources */, + 560714E3227DD0810091BB10 /* AssociationPrefetchingSQLTests.swift in Sources */, 56D496841D813147008276D7 /* SelectStatementTests.swift in Sources */, 56D496B11D8133BC008276D7 /* DatabaseQueueReadOnlyTests.swift in Sources */, 56D4968C1D81316E008276D7 /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */, 56D496981D81317B008276D7 /* DatabaseValueTests.swift in Sources */, 56D4966B1D81309E008276D7 /* MutablePersistableRecordDeleteTests.swift in Sources */, 563B06F721861D8400B38F35 /* ValueObservationCountTests.swift in Sources */, + 56DF001B228DDBA300D611F3 /* AssociationPrefetchingRowTests.swift in Sources */, 56D4965B1D81304E008276D7 /* FoundationNSDecimalNumberTests.swift in Sources */, 562756431E963AAC0035B653 /* DatabaseWriterTests.swift in Sources */, 56EA63C5209C7CE3009715B8 /* DerivableRequestTests.swift in Sources */, 56D496BF1D8135D4008276D7 /* TableDefinitionTests.swift in Sources */, + 567F0B2D220F0E2E00D111FB /* SQLInterpolationTests.swift in Sources */, 5674A7171F3087710095F066 /* DatabaseValueConvertibleDecodableTests.swift in Sources */, 56D496801D813131008276D7 /* StatementColumnConvertibleFetchTests.swift in Sources */, 563B0705218627F800B38F35 /* ValueObservationRowTests.swift in Sources */, @@ -2981,10 +3139,14 @@ 56DAA2D21DE99DAB006E10C8 /* DatabaseCursorTests.swift in Sources */, 56D496AE1D813345008276D7 /* DatabasePoolCollationTests.swift in Sources */, 5698AC491DA2D48A0056AF8C /* FTS3RecordTests.swift in Sources */, + 569BBA3622905FFA00478429 /* InflectionsTests.swift in Sources */, 56D496931D81316E008276D7 /* FetchableRecordTests.swift in Sources */, 56D496881D81316E008276D7 /* DatabaseValueConversionTests.swift in Sources */, + 56057C622291C7C600A7CB10 /* AssociationHasManyThroughRowScopeTests.swift in Sources */, 56D496BA1D813482008276D7 /* DatabaseQueueSchemaCacheTests.swift in Sources */, 56D496781D81309E008276D7 /* RecordSubClassTests.swift in Sources */, + 5656A7FF22946B34001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift in Sources */, + 5615B262222AE1B400061C1C /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */, 56D4965F1D81304E008276D7 /* FoundationNSURLTests.swift in Sources */, 562393301DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */, 5665FA142129C9D6004D8612 /* DatabaseDateDecodingStrategyTests.swift in Sources */, @@ -2995,12 +3157,14 @@ 5653EADC20944B4F00F46237 /* AssociationBelongsToSQLTests.swift in Sources */, 56D5075E1F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift in Sources */, 56176C591EACCCC7000F3F2B /* FTS5CustomTokenizerTests.swift in Sources */, + 5615B289222B17C000061C1C /* AssociationHasOneThroughDecodableRecordTests.swift in Sources */, 56D4968A1D81316E008276D7 /* DatabaseValueConvertibleSubclassTests.swift in Sources */, 56D496601D81304E008276D7 /* FoundationNSUUIDTests.swift in Sources */, 567F45A81F888B2600030B59 /* TruncateOptimizationTests.swift in Sources */, 563B06C32185D29F00B38F35 /* ValueObservationExtentTests.swift in Sources */, 56D4968D1D81316E008276D7 /* DatabaseFunctionTests.swift in Sources */, 564FCE5E20F7E11B00202B90 /* DatabaseValueConversionErrorTests.swift in Sources */, + 5695961C222C456C002CB7C9 /* AssociationHasManyThroughSQLTests.swift in Sources */, 5653EADE20944B4F00F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */, 56D496661D813086008276D7 /* QueryInterfaceRequestTests.swift in Sources */, 56F3E7491E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */, @@ -3009,8 +3173,10 @@ 5698ACD71DA925420056AF8C /* RowTestCase.swift in Sources */, 56176C7D1EACCD2D000F3F2B /* EncryptionTests.swift in Sources */, 56741EA81E66A8B3003E422D /* FetchRequestTests.swift in Sources */, + 56B86E79220FF4E000524C16 /* SQLLiteralTests.swift in Sources */, 56D496831D813147008276D7 /* DatabaseSavepointTests.swift in Sources */, 56D496871D81316E008276D7 /* DatabaseTimestampTests.swift in Sources */, + 5615B26A222AFE8F00061C1C /* AssociationHasOneThroughRowScopeTests.swift in Sources */, 56176C5A1EACCCC7000F3F2B /* FTS5PatternTests.swift in Sources */, 56D496581D81304E008276D7 /* FoundationDateTests.swift in Sources */, 562205F31E420E47005860AC /* DatabaseQueueReleaseMemoryTests.swift in Sources */, @@ -3029,9 +3195,11 @@ 56D496541D812F5B008276D7 /* SQLExpressionLiteralTests.swift in Sources */, 5613EDA621A96A9300DC7A68 /* ValueObservationCombineTests.swift in Sources */, 56D496961D81317B008276D7 /* PersistableRecordTests.swift in Sources */, + 560432A3228F1668009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */, 5698AC9E1DA4B0430056AF8C /* FTS4TableBuilderTests.swift in Sources */, 5674A72A1F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */, 566A84402041914000E50BFD /* MutablePersistableRecordChangesTests.swift in Sources */, + 56057C552291B16A00A7CB10 /* AssociationHasManyRowScopeTests.swift in Sources */, 56176C5E1EACCCC7000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */, 56FEE7FB1F47253700D930EA /* TableRecordTests.swift in Sources */, 56D496641D81304E008276D7 /* FoundationUUIDTests.swift in Sources */, @@ -3039,6 +3207,7 @@ 562206081E420EA4005860AC /* DatabasePoolReadOnlyTests.swift in Sources */, 5698ACCE1DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */, 56D496751D81309E008276D7 /* RecordEditedTests.swift in Sources */, + 5615B275222B107900061C1C /* AssociationHasOneThroughFetchableRecordTests.swift in Sources */, 56D4966F1D81309E008276D7 /* RecordPrimaryKeyNoneTests.swift in Sources */, 56D496621D81304E008276D7 /* StatementArguments+FoundationTests.swift in Sources */, 56176C5D1EACCCC7000F3F2B /* FTS5TokenizerTests.swift in Sources */, @@ -3083,19 +3252,24 @@ 56703297212B5450007D270F /* DatabaseUUIDEncodingStrategyTests.swift in Sources */, 56D496B41D8133F8008276D7 /* DatabaseTests.swift in Sources */, 56D496951D81317B008276D7 /* MutablePersistableRecordTests.swift in Sources */, + 569BBA27228DE51800478429 /* AssociationPrefetchingFetchableRecordTests.swift in Sources */, 5653EAD620944B4F00F46237 /* AssociationChainRowScopesTests.swift in Sources */, 563B06C52185D29F00B38F35 /* ValueObservationSchedulingTests.swift in Sources */, 5698AC801DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */, + 560432A0228F00C2009D3FE2 /* OrderedDictionaryTests.swift in Sources */, 56D496821D813131008276D7 /* TransactionObserverTests.swift in Sources */, 56D496941D81317B008276D7 /* SchedulingWatchdogTests.swift in Sources */, 5674A7201F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift in Sources */, 56D496551D812F83008276D7 /* FoundationDataTests.swift in Sources */, 56D4966A1D813086008276D7 /* TableRecord+QueryInterfaceRequestTests.swift in Sources */, 564CE4E921B2E06F00652B19 /* ValueObservationMapTests.swift in Sources */, + 56959633222D056D002CB7C9 /* AssociationHasManySQLTests.swift in Sources */, 5653EAEC20944B4F00F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */, + 56AE6424222AAC9500AD1B0B /* AssociationHasOneThroughSQLTests.swift in Sources */, 562206071E420EA4005860AC /* DatabasePoolConcurrencyTests.swift in Sources */, 5698ACB61DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */, 56D4965C1D81304E008276D7 /* FoundationNSNullTests.swift in Sources */, + 56DF001D228DDBA300D611F3 /* AssociationPrefetchingCodableRecordTests.swift in Sources */, 5653EAD820944B4F00F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */, 562205F11E420E47005860AC /* DatabasePoolReleaseMemoryTests.swift in Sources */, 5653EAF420944B4F00F46237 /* AssociationParallelSQLTests.swift in Sources */, @@ -3115,12 +3289,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 56873BEC1F2CB400004D24B4 /* Fixits-1.2.swift in Sources */, 563EF42D2161180D007DAACD /* AssociationAggregate.swift in Sources */, - 56D91AB02205F8AC00770D8D /* SQLSelectQuery.swift in Sources */, + 56D91AB02205F8AC00770D8D /* SQLQuery.swift in Sources */, 5613ED4C21A95C4300DC7A68 /* ValueObservation+FetchableRecord.swift in Sources */, - 56BF6D3D1DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */, 5616AAF1207CD45E00AC3664 /* RequestProtocols.swift in Sources */, + 5656A8B02295BFD7001FF3FF /* TableRecord+QueryInterfaceRequest.swift in Sources */, 5613ED4421A95B2C00DC7A68 /* ValueReducer.swift in Sources */, 5636E9BC1D22574100B9B05F /* FetchRequest.swift in Sources */, 56BB6EA91D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */, @@ -3129,17 +3302,17 @@ 566B91231FA4CF810012D5B0 /* Database+Schema.swift in Sources */, 5613ED3F21A95A8B00DC7A68 /* ValueObservation+Combine.swift in Sources */, 563B06AB217EF0CC00B38F35 /* ValueObservation.swift in Sources */, - 56CEB5111EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */, + 56CEB5111EAA324B00BFAF62 /* FTS3+QueryInterface.swift in Sources */, 5659F4901EA8D964004A4992 /* ReadWriteBox.swift in Sources */, 566A841A2041146100E50BFD /* DatabaseSnapshot.swift in Sources */, 569EF0E2200D2D8400A9FA45 /* DatabaseRegion.swift in Sources */, 56CEB4F11EAA2EFA00BFAF62 /* FetchableRecord.swift in Sources */, 56D91AA22205E03700770D8D /* SQLRelation.swift in Sources */, + 5656A8B32295BFD7001FF3FF /* Row+QueryInterfaceRequest.swift in Sources */, 56300B781C53F592005A543B /* QueryInterfaceRequest.swift in Sources */, 5605F18D1C6B1A8700235C62 /* SQLCollatedExpression.swift in Sources */, 5613ED5421A95DD000DC7A68 /* ValueObservation+Count.swift in Sources */, 566B91331FA4D3810012D5B0 /* TransactionObserver.swift in Sources */, - 56D1215A1ED34978001347D2 /* Fixits-0.109.0.swift in Sources */, 566475D31D981D5E00FF74B8 /* SQLOperators.swift in Sources */, 56CEB5611EAA359A00BFAF62 /* SQLSelectable.swift in Sources */, 56CEB4FA1EAA2F4D00BFAF62 /* FTS3.swift in Sources */, @@ -3159,15 +3332,17 @@ 564F9C2D1F075DD200877A00 /* DatabaseFunction.swift in Sources */, 564CE5AC21B8FAB400652B19 /* DatabaseRegionObservation.swift in Sources */, 5659F4981EA8D989004A4992 /* Pool.swift in Sources */, - 5674A6F41F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */, + 5674A6F41F307F600095F066 /* EncodableRecord+Encodable.swift in Sources */, 56CEB54C1EAA359A00BFAF62 /* SQLExpressible.swift in Sources */, 5664759A1D97D8A000FF74B8 /* SQLCollection.swift in Sources */, + 5656A8B62295BFD7001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift in Sources */, 567404881CEF84C8003ED5CC /* RowAdapter.swift in Sources */, - 56E06F061E859064008AE2A4 /* Fixits-0.102.0.swift in Sources */, 5653EB0320944C7C00F46237 /* BelongsToAssociation.swift in Sources */, 563363C41C942C37000BE133 /* DatabaseWriter.swift in Sources */, + 569BBA4E229170F800478429 /* Inflections+English.swift in Sources */, + 5656A81E2295B12F001FF3FF /* SQLAssociation.swift in Sources */, + 5617294E223533F40006E219 /* EncodableRecord.swift in Sources */, 5698AD181DAAD17A0056AF8C /* FTS5Tokenizer.swift in Sources */, - 56F3E7631E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */, 56B964B11DA51D010002DA19 /* FTS5TokenizerDescriptor.swift in Sources */, 560A37A71C8FF6E500949E71 /* SerializedDatabase.swift in Sources */, 5653EB252094A14400F46237 /* QueryInterfaceRequest+Association.swift in Sources */, @@ -3176,8 +3351,8 @@ 564CE4D621B2DEB600652B19 /* ValueObservation+CompactMap.swift in Sources */, 56A8C2301D1914540096E9D4 /* UUID.swift in Sources */, 56CEB5011EAA2F4D00BFAF62 /* FTS4.swift in Sources */, + 56AE64122229A53700AD1B0B /* HasOneThroughAssociation.swift in Sources */, 56CEB55A1EAA359A00BFAF62 /* SQLOrdering.swift in Sources */, - 56BF6D2F1DEF47DA006039A3 /* Fixits-0-84-0.swift in Sources */, 56A238811B9C75030082EB20 /* DatabaseError.swift in Sources */, 56D51D001EA789FA0074638A /* FetchableRecord+TableRecord.swift in Sources */, 566475BA1D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift in Sources */, @@ -3193,35 +3368,39 @@ 56DAA2DB1DE9C827006E10C8 /* Cursor.swift in Sources */, 5674A6EB1F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */, 56D91AA92205F2F100770D8D /* DatabasePromise.swift in Sources */, + 56959629222C462D002CB7C9 /* HasManyThroughAssociation.swift in Sources */, 560A37A41C8F625000949E71 /* DatabasePool.swift in Sources */, 56B7F43A1BEB42D500E39BBF /* Migration.swift in Sources */, 5613ED3521A95A5C00DC7A68 /* ValueObservation+Map.swift in Sources */, 566B912B1FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */, 56A2388B1B9C75030082EB20 /* Statement.swift in Sources */, + 5656A8AD2295BFD7001FF3FF /* TableRecord+Association.swift in Sources */, 5690C3401D23E82A00E59934 /* Data.swift in Sources */, 5659F4881EA8D94E004A4992 /* Utils.swift in Sources */, 56FC98781D969DEF00E3C842 /* SQLExpression+QueryInterface.swift in Sources */, 56A238931B9C750B0082EB20 /* DatabaseMigrator.swift in Sources */, 5695311F1C907A8C00CF1A2B /* DatabaseSchemaCache.swift in Sources */, - 568D131F2207213E00674B58 /* SQLSelectQueryGenerator.swift in Sources */, + 569D6DDE220EF9E100A058A9 /* SQLInterpolation.swift in Sources */, + 568D131F2207213E00674B58 /* SQLQueryGenerator.swift in Sources */, 5605F15D1C672E4000235C62 /* DatabaseDateComponents.swift in Sources */, - 56BF6D361DEF47DA006039A3 /* Fixits-0-90-1.swift in Sources */, + 567ECE4F2222E431009245CA /* GRDB-4.0.swift in Sources */, 56193E8E1CD8A3E200F95862 /* FetchedRecordsController.swift in Sources */, 56B964B91DA51D0A0002DA19 /* FTS5Pattern.swift in Sources */, + 56FBFEDA2210731A00945324 /* SQLRequest.swift in Sources */, 563363C01C942C04000BE133 /* DatabaseReader.swift in Sources */, 564CE43121AA901800652B19 /* ValueObserver.swift in Sources */, 5605F1651C672E4000235C62 /* NSNull.swift in Sources */, 56CEB5191EAA328900BFAF62 /* FTS5+QueryInterface.swift in Sources */, - 5653EB1820944C7C00F46237 /* ForeignKey.swift in Sources */, 5674A6FB1F307F600095F066 /* FetchableRecord+Decodable.swift in Sources */, - 5653EB0620944C7C00F46237 /* ForeignKeyRequest.swift in Sources */, + 5653EB0620944C7C00F46237 /* SQLForeignKeyRequest.swift in Sources */, + 56E9FACB221046FD00C703A8 /* SQLInterpolation+QueryInterface.swift in Sources */, 5698AC781DA37DCB0056AF8C /* VirtualTableModule.swift in Sources */, 56A2387D1B9C75030082EB20 /* Database.swift in Sources */, 566AD8B21D5318F4002EC1A8 /* TableDefinition.swift in Sources */, 5698AD211DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */, 56A238831B9C75030082EB20 /* DatabaseQueue.swift in Sources */, - 569A98ED2039B6F3008D7DBF /* Fixits-3.0.swift in Sources */, 5605F1671C672E4000235C62 /* NSNumber.swift in Sources */, + 56E9FADA221053DD00C703A8 /* SQLLiteral.swift in Sources */, C96C0F2B2084A442006B2981 /* SQLiteDateParser.swift in Sources */, 56A238871B9C75030082EB20 /* Row.swift in Sources */, 5653EB2120944C7C00F46237 /* HasOneAssociation.swift in Sources */, @@ -3242,11 +3421,6 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - 560C97D01C0E22D300BF8471 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = "SQLite Mac"; - targetProxy = 560C97D11C0E22D300BF8471 /* PBXContainerItemProxy */; - }; 560C97D21C0E22D300BF8471 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = DC3773F219C8CBB3004FCF85 /* GRDBOSX */; @@ -3324,7 +3498,7 @@ DEBUG_INFORMATION_FORMAT = dwarf; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", - "$(PROJECT_DIR)/Tests/Performance/Realm/build/osx/swift-4.2.1", + "$(PROJECT_DIR)/Tests/Performance/Realm/build/osx/swift-10.2.1", ); GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = Tests/Info.plist; @@ -3347,7 +3521,7 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", - "$(PROJECT_DIR)/Tests/Performance/Realm/build/osx/swift-4.2.1", + "$(PROJECT_DIR)/Tests/Performance/Realm/build/osx/swift-10.2.1", ); GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = Tests/Info.plist; @@ -3620,7 +3794,7 @@ MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -3667,7 +3841,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; MTL_ENABLE_DEBUG_INFO = NO; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; diff --git a/GRDB.xcodeproj/xcshareddata/xcschemes/GRDBOSX.xcscheme b/GRDB.xcodeproj/xcshareddata/xcschemes/GRDBOSX.xcscheme index 1b8d9e8ea..7ebe66f64 100644 --- a/GRDB.xcodeproj/xcshareddata/xcschemes/GRDBOSX.xcscheme +++ b/GRDB.xcodeproj/xcshareddata/xcschemes/GRDBOSX.xcscheme @@ -1,6 +1,6 @@ - - @@ -50,9 +47,6 @@ - - diff --git a/GRDB/Core/Configuration.swift b/GRDB/Core/Configuration.swift index 18934e3ff..0cb8a17e5 100644 --- a/GRDB/Core/Configuration.swift +++ b/GRDB/Core/Configuration.swift @@ -2,6 +2,8 @@ import Foundation import Dispatch #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -82,21 +84,22 @@ public struct Configuration { /// Default: nil public var passphrase: String? - /// The cipher_page_size setting for the encrypted database. - /// - /// See https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_page_size - /// - /// Default: 1024 - this corresponds to the default used by SQLCipher 3 - public var cipherPageSize: Int = 1024 - - /// The kdf_iter setting for the encrypted database. - /// - /// See https://www.zetetic.net/sqlcipher/sqlcipher-api/#kdf_iter - /// - /// Default: 64000 - this corresponds to the default used by SQLCipher 3 - public var kdfIterations: Int = 64000 #endif - + + /// If set, allows custom configuration to be run every time + /// a new connection is opened. + /// + /// This block is run after the Database's connection has opened, but + /// before that connection has been made available to any read/write + /// API's. + /// + /// For example: + /// + /// var config = Configuration() + /// config.prepareDatabase = { db in + /// try db.execute(sql: "PRAGMA kdf_iter = 10000") + /// } + public var prepareDatabase: ((Database) throws -> Void)? // MARK: - Transactions diff --git a/GRDB/Core/Cursor.swift b/GRDB/Core/Cursor.swift index cf26885f8..51ef3b303 100644 --- a/GRDB/Core/Cursor.swift +++ b/GRDB/Core/Cursor.swift @@ -14,8 +14,9 @@ extension Array { /// Creates an array containing the elements of a cursor. /// - /// let cursor = try String.fetchCursor(db, "SELECT 'foo' UNION ALL SELECT 'bar'") + /// let cursor = try String.fetchCursor(db, sql: "SELECT 'foo' UNION ALL SELECT 'bar'") /// let strings = try Array(cursor) // ["foo", "bar"] + @inlinable public init(_ cursor: C) throws where C.Element == Element { self.init() while let element = try cursor.next() { @@ -36,7 +37,7 @@ extension Sequence { extension Set { /// Creates a set containing the elements of a cursor. /// - /// let cursor = try String.fetchCursor(db, "SELECT 'foo' UNION ALL SELECT 'foo'") + /// let cursor = try String.fetchCursor(db, sql: "SELECT 'foo' UNION ALL SELECT 'foo'") /// let strings = try Set(cursor) // ["foo"] public init(_ cursor: C) throws where C.Element == Element { self.init() @@ -111,7 +112,7 @@ extension Cursor { /// Returns a cursor of pairs (n, x), where n represents a consecutive /// integer starting at zero, and x represents an element of the cursor. /// - /// let cursor = try String.fetchCursor(db, "SELECT 'foo' UNION ALL SELECT 'bar'") + /// let cursor = try String.fetchCursor(db, sql: "SELECT 'foo' UNION ALL SELECT 'bar'") /// let c = cursor.enumerated() /// while let (n, x) = c.next() { /// print("\(n): \(x)") @@ -144,11 +145,6 @@ extension Cursor { return map(transform).filter { $0 != nil }.map { $0! } } - @available(*, deprecated, renamed: "compactMap") - public func flatMap(_ transform: @escaping (Element) throws -> ElementOfResult?) -> MapCursor>, ElementOfResult> { - return compactMap(transform) - } - /// Returns a cursor that skips any initial elements that satisfy /// `predicate`. /// @@ -600,7 +596,7 @@ public final class DropWhileCursor : Cursor { /// To create an instance of `EnumeratedCursor`, call the `enumerated()` method /// on a cursor: /// -/// let cursor = try String.fetchCursor(db, "SELECT 'foo' UNION ALL SELECT 'bar'") +/// let cursor = try String.fetchCursor(db, sql: "SELECT 'foo' UNION ALL SELECT 'bar'") /// let c = cursor.enumerated() /// while let (n, x) = c.next() { /// print("\(n): \(x)") diff --git a/GRDB/Core/Database+Schema.swift b/GRDB/Core/Database+Schema.swift index fe07fd0ec..0155a214e 100644 --- a/GRDB/Core/Database+Schema.swift +++ b/GRDB/Core/Database+Schema.swift @@ -1,5 +1,7 @@ #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -171,13 +173,13 @@ extension Database { } let indexes = try Row - .fetchAll(self, "PRAGMA index_list(\(tableName.quotedDatabaseIdentifier))") + .fetchAll(self, sql: "PRAGMA index_list(\(tableName.quotedDatabaseIdentifier))") .map { row -> IndexInfo in // [seq:0 name:"index" unique:0 origin:"c" partial:0] let indexName: String = row[1] let unique: Bool = row[2] let columns = try Row - .fetchAll(self, "PRAGMA index_info(\(indexName.quotedDatabaseIdentifier))") + .fetchAll(self, sql: "PRAGMA index_info(\(indexName.quotedDatabaseIdentifier))") .map { row -> (Int, String) in // [seqno:0 cid:2 name:"column"] (row[0] as Int, row[2] as String) @@ -213,7 +215,7 @@ extension Database { var rawForeignKeys: [(destinationTable: String, mapping: [(origin: String, destination: String?, seq: Int)])] = [] var previousId: Int? = nil - for row in try Row.fetchAll(self, "PRAGMA foreign_key_list(\(tableName.quotedDatabaseIdentifier))") { + for row in try Row.fetchAll(self, sql: "PRAGMA foreign_key_list(\(tableName.quotedDatabaseIdentifier))") { // row = [id:0 seq:0 table:"parents" from:"parentId" to:"id" on_update:"..." on_delete:"..." match:"..."] let id: Int = row[0] let seq: Int = row[1] @@ -320,7 +322,7 @@ extension Database { } } let columns = try ColumnInfo - .fetchAll(self, "PRAGMA table_info(\(tableName.quotedDatabaseIdentifier))") + .fetchAll(self, sql: "PRAGMA table_info(\(tableName.quotedDatabaseIdentifier))") .sorted(by: { $0.cid < $1.cid }) guard columns.count > 0 else { throw DatabaseError(message: "no such table: \(tableName)") @@ -386,7 +388,7 @@ public struct ColumnInfo : FetchableRecord { /// /// For example: /// - /// try db.execute(""" + /// try db.execute(sql: """ /// CREATE TABLE player( /// id INTEGER PRIMARY KEY, /// name TEXT DEFAULT 'Anonymous', @@ -579,7 +581,7 @@ struct SchemaInfo: Equatable { private var objects: Set init(_ db: Database) throws { - objects = try Set(SchemaObject.fetchCursor(db, """ + objects = try Set(SchemaObject.fetchCursor(db, sql: """ SELECT type, name, tbl_name, sql, 0 AS isTemporary FROM sqlite_master \ UNION \ SELECT type, name, tbl_name, sql, 1 FROM sqlite_temp_master @@ -597,7 +599,7 @@ struct SchemaInfo: Equatable { /// Returns the canonical name of the object: /// - /// try db.execute("CREATE TABLE FooBar (...)") + /// try db.execute(sql: "CREATE TABLE FooBar (...)") /// try db.schema().canonicalName("foobar", ofType: .table) // "FooBar" func canonicalName(_ name: String, ofType type: SchemaObjectType) -> String? { let name = name.lowercased() @@ -610,16 +612,5 @@ struct SchemaInfo: Equatable { var tbl_name: String? var sql: String? var isTemporary: Bool - - #if !swift(>=4.2) - var hashValue: Int { - var hash = type.hashValue - hash ^= name.hashValue - hash ^= (tbl_name?.hashValue ?? 0) - hash ^= (sql?.hashValue ?? 0) - hash ^= isTemporary.hashValue - return hash - } - #endif } } diff --git a/GRDB/Core/Database+Statements.swift b/GRDB/Core/Database+Statements.swift index c77e6b2d0..1553dbf62 100644 --- a/GRDB/Core/Database+Statements.swift +++ b/GRDB/Core/Database+Statements.swift @@ -1,4 +1,11 @@ import Foundation +#if SWIFT_PACKAGE + import CSQLite +#elseif GRDBCIPHER + import SQLCipher +#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER + import SQLite3 +#endif extension Database { @@ -6,20 +13,20 @@ extension Database { /// Returns a new prepared statement that can be reused. /// - /// let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM player WHERE score > ?") + /// let statement = try db.makeSelectStatement(sql: "SELECT COUNT(*) FROM player WHERE score > ?") /// let moreThanTwentyCount = try Int.fetchOne(statement, arguments: [20])! /// let moreThanThirtyCount = try Int.fetchOne(statement, arguments: [30])! /// /// - parameter sql: An SQL query. /// - returns: A SelectStatement. /// - throws: A DatabaseError whenever SQLite could not parse the sql query. - public func makeSelectStatement(_ sql: String) throws -> SelectStatement { - return try makeSelectStatement(sql, prepFlags: 0) + public func makeSelectStatement(sql: String) throws -> SelectStatement { + return try makeSelectStatement(sql: sql, prepFlags: 0) } /// Returns a new prepared statement that can be reused. /// - /// let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM player WHERE score > ?", prepFlags: 0) + /// let statement = try db.makeSelectStatement(sql: "SELECT COUNT(*) FROM player WHERE score > ?", prepFlags: 0) /// let moreThanTwentyCount = try Int.fetchOne(statement, arguments: [20])! /// let moreThanThirtyCount = try Int.fetchOne(statement, arguments: [30])! /// @@ -28,13 +35,13 @@ extension Database { /// SQLite 3.20.0, see http://www.sqlite.org/c3ref/prepare.html) /// - returns: A SelectStatement. /// - throws: A DatabaseError whenever SQLite could not parse the sql query. - func makeSelectStatement(_ sql: String, prepFlags: Int32) throws -> SelectStatement { + func makeSelectStatement(sql: String, prepFlags: Int32) throws -> SelectStatement { return try SelectStatement.prepare(sql: sql, prepFlags: prepFlags, in: self) } /// Returns a prepared statement that can be reused. /// - /// let statement = try db.cachedSelectStatement("SELECT COUNT(*) FROM player WHERE score > ?") + /// let statement = try db.cachedSelectStatement(sql: "SELECT COUNT(*) FROM player WHERE score > ?") /// let moreThanTwentyCount = try Int.fetchOne(statement, arguments: [20])! /// let moreThanThirtyCount = try Int.fetchOne(statement, arguments: [30])! /// @@ -44,31 +51,31 @@ extension Database { /// - parameter sql: An SQL query. /// - returns: An UpdateStatement. /// - throws: A DatabaseError whenever SQLite could not parse the sql query. - public func cachedSelectStatement(_ sql: String) throws -> SelectStatement { + public func cachedSelectStatement(sql: String) throws -> SelectStatement { return try publicStatementCache.selectStatement(sql) } /// Returns a cached statement that does not conflict with user's cached statements. - func internalCachedSelectStatement(_ sql: String) throws -> SelectStatement { + func internalCachedSelectStatement(sql: String) throws -> SelectStatement { return try internalStatementCache.selectStatement(sql) } /// Returns a new prepared statement that can be reused. /// - /// let statement = try db.makeUpdateStatement("INSERT INTO player (name) VALUES (?)") + /// let statement = try db.makeUpdateStatement(sql: "INSERT INTO player (name) VALUES (?)") /// try statement.execute(arguments: ["Arthur"]) /// try statement.execute(arguments: ["Barbara"]) /// /// - parameter sql: An SQL query. /// - returns: An UpdateStatement. /// - throws: A DatabaseError whenever SQLite could not parse the sql query. - public func makeUpdateStatement(_ sql: String) throws -> UpdateStatement { - return try makeUpdateStatement(sql, prepFlags: 0) + public func makeUpdateStatement(sql: String) throws -> UpdateStatement { + return try makeUpdateStatement(sql: sql, prepFlags: 0) } /// Returns a new prepared statement that can be reused. /// - /// let statement = try db.makeUpdateStatement("INSERT INTO player (name) VALUES (?)", prepFlags: 0) + /// let statement = try db.makeUpdateStatement(sql: "INSERT INTO player (name) VALUES (?)", prepFlags: 0) /// try statement.execute(arguments: ["Arthur"]) /// try statement.execute(arguments: ["Barbara"]) /// @@ -77,13 +84,13 @@ extension Database { /// SQLite 3.20.0, see http://www.sqlite.org/c3ref/prepare.html) /// - returns: An UpdateStatement. /// - throws: A DatabaseError whenever SQLite could not parse the sql query. - func makeUpdateStatement(_ sql: String, prepFlags: Int32) throws -> UpdateStatement { + func makeUpdateStatement(sql: String, prepFlags: Int32) throws -> UpdateStatement { return try UpdateStatement.prepare(sql: sql, prepFlags: prepFlags, in: self) } /// Returns a prepared statement that can be reused. /// - /// let statement = try db.cachedUpdateStatement("INSERT INTO player (name) VALUES (?)") + /// let statement = try db.cachedUpdateStatement(sql: "INSERT INTO player (name) VALUES (?)") /// try statement.execute(arguments: ["Arthur"]) /// try statement.execute(arguments: ["Barbara"]) /// @@ -93,97 +100,121 @@ extension Database { /// - parameter sql: An SQL query. /// - returns: An UpdateStatement. /// - throws: A DatabaseError whenever SQLite could not parse the sql query. - public func cachedUpdateStatement(_ sql: String) throws -> UpdateStatement { + public func cachedUpdateStatement(sql: String) throws -> UpdateStatement { return try publicStatementCache.updateStatement(sql) } /// Returns a cached statement that does not conflict with user's cached statements. - func internalCachedUpdateStatement(_ sql: String) throws -> UpdateStatement { + func internalCachedUpdateStatement(sql: String) throws -> UpdateStatement { return try internalStatementCache.updateStatement(sql) } /// Executes one or several SQL statements, separated by semi-colons. /// /// try db.execute( - /// "INSERT INTO player (name) VALUES (:name)", + /// sql: "INSERT INTO player (name) VALUES (:name)", /// arguments: ["name": "Arthur"]) /// - /// try db.execute(""" + /// try db.execute(sql: """ /// INSERT INTO player (name) VALUES (?); /// INSERT INTO player (name) VALUES (?); /// INSERT INTO player (name) VALUES (?); - /// """, arguments; ['Arthur', 'Barbara', 'Craig']) + /// """, arguments: ["Arthur", "Barbara", "O'Brien"]) /// /// This method may throw a DatabaseError. /// /// - parameters: /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - throws: A DatabaseError whenever an SQLite error occurs. - public func execute(_ sql: String, arguments: StatementArguments? = nil) throws { + public func execute(sql: String, arguments: StatementArguments = StatementArguments()) throws { + try execute(literal: SQLLiteral(sql: sql, arguments: arguments)) + } + + /// Executes one or several SQL statements, separated by semi-colons. + /// + /// try db.execute(literal: SQLLiteral( + /// sql: "INSERT INTO player (name) VALUES (:name)", + /// arguments: ["name": "Arthur"])) + /// + /// try db.execute(literal: SQLLiteral(sql: """ + /// INSERT INTO player (name) VALUES (?); + /// INSERT INTO player (name) VALUES (?); + /// INSERT INTO player (name) VALUES (?); + /// """, arguments: ["Arthur", "Barbara", "O'Brien"])) + /// + /// With Swift 5, you can safely embed raw values in your SQL queries, + /// without any risk of syntax errors or SQL injection: + /// + /// try db.execute(literal: """ + /// INSERT INTO player (name) VALUES (\("Arthur")); + /// INSERT INTO player (name) VALUES (\("Barbara")); + /// INSERT INTO player (name) VALUES (\("O'Brien")); + /// """) + /// + /// This method may throw a DatabaseError. + /// + /// - parameter sqlLiteral: An SQLLiteral. + /// - throws: A DatabaseError whenever an SQLite error occurs. + public func execute(literal sqlLiteral: SQLLiteral) throws { // This method is like sqlite3_exec (https://www.sqlite.org/c3ref/exec.html) // It adds support for arguments, and the tricky part is to consume // arguments as statements are executed. // - // Here we build two functions: - // - consumeArguments returns arguments for a statement - // - validateRemainingArguments validates the remaining arguments, after - // all statements have been executed, in the same way - // as Statement.validate(arguments:) + // This job is performed by StatementArguments.extractBindings(forStatement:allowingRemainingValues:) + // + // And before we return, we'll check that all arguments were consumed. - var arguments = arguments ?? StatementArguments() + var arguments = sqlLiteral.arguments let initialValuesCount = arguments.values.count - let consumeArguments = { (statement: UpdateStatement) throws -> StatementArguments in - let bindings = try arguments.consume(statement, allowingRemainingValues: true) - return StatementArguments(bindings) - } - let validateRemainingArguments = { - if !arguments.values.isEmpty { - throw DatabaseError(resultCode: .SQLITE_MISUSE, message: "wrong number of statement arguments: \(initialValuesCount)") - } - } - // Iterate SQL statements - let sqlCodeUnits = sql.utf8CString - try sqlCodeUnits.withUnsafeBufferPointer { codeUnits in - let sqlStart = UnsafePointer(codeUnits.baseAddress)! - let sqlEnd = sqlStart + sqlCodeUnits.count + // Build a C string (SQLite wants that), and execute SQL statements one + // after the other. + try sqlLiteral.sql.utf8CString.withUnsafeBufferPointer { buffer in + guard let sqlStart = buffer.baseAddress else { return } + let sqlEnd = sqlStart + buffer.count // past \0 var statementStart = sqlStart - while statementStart < sqlEnd - 1 { + while statementStart < sqlEnd { var statementEnd: UnsafePointer? = nil + let nextStatement: UpdateStatement? + + // Compile do { - let statement: UpdateStatement - // Compile - do { - let statementCompilationAuthorizer = StatementCompilationAuthorizer() - authorizer = statementCompilationAuthorizer - defer { authorizer = nil } - - statement = try UpdateStatement( - database: self, - statementStart: statementStart, - statementEnd: &statementEnd, - prepFlags: 0, - authorizer: statementCompilationAuthorizer) - } + let statementCompilationAuthorizer = StatementCompilationAuthorizer() + authorizer = statementCompilationAuthorizer + defer { authorizer = nil } - // Execute - let arguments = try consumeArguments(statement) - statement.unsafeSetArguments(arguments) - try statement.execute() - - // Next - statementStart = statementEnd! - } catch is EmptyStatementError { - // End + nextStatement = try UpdateStatement( + database: self, + statementStart: statementStart, + statementEnd: &statementEnd, + prepFlags: 0, + authorizer: statementCompilationAuthorizer) + } + + guard let statement = nextStatement else { + // End of SQL string break } + + // Extract statement arguments + let bindings = try arguments.extractBindings(forStatement: statement, allowingRemainingValues: true) + // unsafe is OK because we just extracted the correct number of arguments + statement.unsafeSetArguments(StatementArguments(bindings)) + + // Execute + try statement.execute() + + // Next + statementStart = statementEnd! } } - // Force arguments validity: it is a programmer error to provide - // arguments that do not match the statement. - try! validateRemainingArguments() // throws if there are remaining arguments. + // Check that all arguments were consumed: it is a programmer error to + // provide arguments that do not match the statement. + if arguments.values.isEmpty == false { + throw DatabaseError(resultCode: .SQLITE_MISUSE, message: "wrong number of statement arguments: \(initialValuesCount)") + } } } @@ -248,12 +279,17 @@ struct StatementCache { // // However SQLITE_PREPARE_PERSISTENT was only introduced in // SQLite 3.20.0 http://www.sqlite.org/changes.html#version_3_20 - // - // TODO: use SQLITE_PREPARE_PERSISTENT if #available(iOS 12.0, OSX 10.14, watchOS 5.0, *) #if GRDBCUSTOMSQLITE || GRDBCIPHER - let statement = try db.makeSelectStatement(sql, prepFlags: SQLITE_PREPARE_PERSISTENT) + let statement = try db.makeSelectStatement(sql: sql, prepFlags: SQLITE_PREPARE_PERSISTENT) #else - let statement = try db.makeSelectStatement(sql) + let statement: SelectStatement + if #available(iOS 12.0, OSX 10.14, watchOS 5.0, *) { + // SQLite 3.24.0 or more + statement = try db.makeSelectStatement(sql: sql, prepFlags: SQLITE_PREPARE_PERSISTENT) + } else { + // SQLite 3.19.3 or less + statement = try db.makeSelectStatement(sql: sql) + } #endif selectStatements[sql] = statement return statement @@ -273,12 +309,17 @@ struct StatementCache { // // However SQLITE_PREPARE_PERSISTENT was only introduced in // SQLite 3.20.0 http://www.sqlite.org/changes.html#version_3_20 - // - // TODO: use SQLITE_PREPARE_PERSISTENT if #available(iOS 12.0, OSX 10.14, watchOS 5.0, *) #if GRDBCUSTOMSQLITE || GRDBCIPHER - let statement = try db.makeUpdateStatement(sql, prepFlags: SQLITE_PREPARE_PERSISTENT) + let statement = try db.makeUpdateStatement(sql: sql, prepFlags: SQLITE_PREPARE_PERSISTENT) #else - let statement = try db.makeUpdateStatement(sql) + let statement: UpdateStatement + if #available(iOS 12.0, OSX 10.14, watchOS 5.0, *) { + // SQLite 3.24.0 or more + statement = try db.makeUpdateStatement(sql: sql, prepFlags: SQLITE_PREPARE_PERSISTENT) + } else { + // SQLite 3.19.3 or less + statement = try db.makeUpdateStatement(sql: sql) + } #endif updateStatements[sql] = statement return statement @@ -290,14 +331,10 @@ struct StatementCache { } mutating func remove(_ statement: SelectStatement) { - if let index = selectStatements.index(where: { $0.1 === statement }) { - selectStatements.remove(at: index) - } + selectStatements.removeFirst { $0.value === statement } } mutating func remove(_ statement: UpdateStatement) { - if let index = updateStatements.index(where: { $0.1 === statement }) { - updateStatements.remove(at: index) - } + updateStatements.removeFirst { $0.value === statement } } } diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index 5319692c0..edf239aec 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -1,6 +1,8 @@ import Foundation #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -151,7 +153,7 @@ public final class Database { /// The list of compile options used when building SQLite static let sqliteCompileOptions: Set = DatabaseQueue().inDatabase { - try! Set(String.fetchCursor($0, "PRAGMA COMPILE_OPTIONS")) + try! Set(String.fetchCursor($0, sql: "PRAGMA COMPILE_OPTIONS")) } // MARK: - Private properties @@ -166,28 +168,9 @@ public final class Database { // MARK: - Initializer init(path: String, configuration: Configuration, schemaCache: DatabaseSchemaCache) throws { - let sqliteConnection = try Database.openConnection(path: path, flags: configuration.SQLiteOpenFlags) - do { - try Database.activateExtendedCodes(sqliteConnection) - #if SQLITE_HAS_CODEC - try Database.validateSQLCipher(sqliteConnection) - if let passphrase = configuration.passphrase { - try Database.set(passphrase: passphrase, forConnection: sqliteConnection) - try Database.set(cipherPageSize: configuration.cipherPageSize, forConnection: sqliteConnection) - try Database.set(kdfIterations: configuration.kdfIterations, forConnection: sqliteConnection) - } - #endif - try Database.validateDatabaseFormat(sqliteConnection) - } catch { - Database.closeConnection(sqliteConnection) - throw error - } - - self.sqliteConnection = sqliteConnection + self.sqliteConnection = try Database.openConnection(path: path, flags: configuration.SQLiteOpenFlags) self.configuration = configuration self.schemaCache = schemaCache - - configuration.SQLiteConnectionDidOpen?() } deinit { @@ -221,91 +204,6 @@ extension Database { } throw DatabaseError(resultCode: .SQLITE_INTERNAL) // WTF SQLite? } - - private static func activateExtendedCodes(_ sqliteConnection: SQLiteConnection) throws { - let code = sqlite3_extended_result_codes(sqliteConnection, 1) - guard code == SQLITE_OK else { - throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection))) - } - } - - #if SQLITE_HAS_CODEC - private static func validateSQLCipher(_ sqliteConnection: SQLiteConnection) throws { - // https://discuss.zetetic.net/t/important-advisory-sqlcipher-with-xcode-8-and-new-sdks/1688 - // - // > In order to avoid situations where SQLite might be used - // > improperly at runtime, we strongly recommend that - // > applications institute a runtime test to ensure that the - // > application is actually using SQLCipher on the active - // > connection. - var sqliteStatement: SQLiteStatement? = nil - let code = sqlite3_prepare_v2(sqliteConnection, "PRAGMA cipher_version", -1, &sqliteStatement, nil) - guard code == SQLITE_OK else { - throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection))) - } - defer { - sqlite3_finalize(sqliteStatement) - } - if sqlite3_step(sqliteStatement) != SQLITE_ROW || (sqlite3_column_text(sqliteStatement, 0) == nil) { - throw DatabaseError(resultCode: .SQLITE_MISUSE, message: """ - GRDB is not linked against SQLCipher. \ - Check https://discuss.zetetic.net/t/important-advisory-sqlcipher-with-xcode-8-and-new-sdks/1688 - """) - } - } - - private static func set(passphrase: String, forConnection sqliteConnection: SQLiteConnection) throws { - let data = passphrase.data(using: .utf8)! - let code = data.withUnsafeBytes { bytes in - sqlite3_key(sqliteConnection, bytes, Int32(data.count)) - } - guard code == SQLITE_OK else { - throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection))) - } - } - - private static func set(cipherPageSize: Int, forConnection sqliteConnection: SQLiteConnection) throws { - var sqliteStatement: SQLiteStatement? = nil - var code = sqlite3_prepare_v2(sqliteConnection, "PRAGMA cipher_page_size = \(cipherPageSize)", -1, &sqliteStatement, nil) - guard code == SQLITE_OK else { - throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection))) - } - defer { - sqlite3_finalize(sqliteStatement) - } - code = sqlite3_step(sqliteStatement) - if code != SQLITE_DONE { - throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection))) - } - } - - private static func set(kdfIterations: Int, forConnection sqliteConnection: SQLiteConnection) throws { - var sqliteStatement: SQLiteStatement? = nil - var code = sqlite3_prepare_v2(sqliteConnection, "PRAGMA kdf_iter = \(kdfIterations)", -1, &sqliteStatement, nil) - guard code == SQLITE_OK else { - throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection))) - } - defer { - sqlite3_finalize(sqliteStatement) - } - code = sqlite3_step(sqliteStatement) - if code != SQLITE_DONE { - throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection))) - } - } - #endif - - private static func validateDatabaseFormat(_ sqliteConnection: SQLiteConnection) throws { - // Users are surprised when they open a picture as a database and - // see no error (https://github.com/groue/GRDB.swift/issues/54). - // - // So let's fail early if file is not a database, or encrypted with - // another passphrase. - let code = sqlite3_exec(sqliteConnection, "SELECT * FROM sqlite_master LIMIT 1", nil, nil, nil) - guard code == SQLITE_OK else { - throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection))) - } - } } extension Database { @@ -321,6 +219,21 @@ extension Database { setupDefaultFunctions() setupDefaultCollations() observationBroker.installCommitAndRollbackHooks() + try activateExtendedCodes() + + #if SQLITE_HAS_CODEC + try validateSQLCipher() + if let passphrase = configuration.passphrase { + try setCipherPassphrase(passphrase) + } + #endif + + // Last step before we can start accessing the database. + // This is the opportunity to run SQLCipher configuration + // pragmas such as cipher_page_size, for example. + try configuration.prepareDatabase?(self) + try validateFormat() + configuration.SQLiteConnectionDidOpen?() } private func setupTrace() { @@ -375,11 +288,11 @@ extension Database { db.configuration.trace!(sql) return SQLITE_OK } - + private func setupForeignKeys() throws { // Foreign keys are disabled by default with SQLite3 if configuration.foreignKeysEnabled { - try execute("PRAGMA foreign_keys = ON") + try execute(sql: "PRAGMA foreign_keys = ON") } } @@ -411,7 +324,7 @@ extension Database { add(function: .lowercase) add(function: .uppercase) - if #available(iOS 9.0, OSX 10.11, watchOS 3.0, *) { + if #available(OSX 10.11, watchOS 3.0, *) { add(function: .localizedCapitalize) add(function: .localizedLowercase) add(function: .localizedUppercase) @@ -425,6 +338,56 @@ extension Database { add(collation: .localizedCompare) add(collation: .localizedStandardCompare) } + + private func activateExtendedCodes() throws { + let code = sqlite3_extended_result_codes(sqliteConnection, 1) + guard code == SQLITE_OK else { + throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection))) + } + } + + #if SQLITE_HAS_CODEC + private func validateSQLCipher() throws { + // https://discuss.zetetic.net/t/important-advisory-sqlcipher-with-xcode-8-and-new-sdks/1688 + // + // > In order to avoid situations where SQLite might be used + // > improperly at runtime, we strongly recommend that + // > applications institute a runtime test to ensure that the + // > application is actually using SQLCipher on the active + // > connection. + if try String.fetchOne(self, sql: "PRAGMA cipher_version") == nil { + throw DatabaseError(resultCode: .SQLITE_MISUSE, message: """ + GRDB is not linked against SQLCipher. \ + Check https://discuss.zetetic.net/t/important-advisory-sqlcipher-with-xcode-8-and-new-sdks/1688 + """) + } + } + + private func setCipherPassphrase(_ passphrase: String) throws { + let data = passphrase.data(using: .utf8)! + #if swift(>=5.0) + let code = data.withUnsafeBytes { + sqlite3_key(sqliteConnection, $0.baseAddress, Int32($0.count)) + } + #else + let code = data.withUnsafeBytes { + sqlite3_key(sqliteConnection, $0, Int32(data.count)) + } + #endif + guard code == SQLITE_OK else { + throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection))) + } + } + #endif + + private func validateFormat() throws { + // Users are surprised when they open a picture as a database and + // see no error (https://github.com/groue/GRDB.swift/issues/54). + // + // So let's fail early if file is not a database, or encrypted with + // another passphrase. + try makeSelectStatement(sql: "SELECT * FROM sqlite_master LIMIT 1").makeCursor().next() + } } extension Database { @@ -450,7 +413,7 @@ extension Database { #if GRDBCUSTOMSQLITE || GRDBCIPHER closeConnection_v2(sqliteConnection, sqlite3_close_v2) #else - if #available(iOS 8.2, OSX 10.10, OSXApplicationExtension 10.10, *) { + if #available(OSX 10.10, OSXApplicationExtension 10.10, *) { closeConnection_v2(sqliteConnection, sqlite3_close_v2) } else { closeConnection_v1(sqliteConnection) @@ -515,7 +478,7 @@ extension Database { /// return int + 1 /// } /// db.add(function: fn) - /// try Int.fetchOne(db, "SELECT succ(1)")! // 2 + /// try Int.fetchOne(db, sql: "SELECT succ(1)")! // 2 public func add(function: DatabaseFunction) { functions.update(with: function) function.install(in: self) @@ -538,7 +501,7 @@ extension Database { /// return (string1 as NSString).localizedStandardCompare(string2) /// } /// db.add(collation: collation) - /// try db.execute("CREATE TABLE files (name TEXT COLLATE localized_standard") + /// try db.execute(sql: "CREATE TABLE files (name TEXT COLLATE localized_standard") public func add(collation: DatabaseCollation) { collations.update(with: collation) let collationPointer = Unmanaged.passUnretained(collation).toOpaque() @@ -581,8 +544,8 @@ extension Database { // query_only pragma was added in SQLite 3.8.0 http://www.sqlite.org/changes.html#version_3_8_0 // It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS) // Assume those pragmas never fail - try! internalCachedUpdateStatement("PRAGMA query_only = 1").execute() - defer { try! internalCachedUpdateStatement("PRAGMA query_only = 0").execute() } + try! internalCachedUpdateStatement(sql: "PRAGMA query_only = 1").execute() + defer { try! internalCachedUpdateStatement(sql: "PRAGMA query_only = 0").execute() } return try block() } } @@ -595,7 +558,7 @@ extension Database { /// /// try dbQueue.inDatabase do { /// try db.inTransaction { - /// try db.execute("INSERT ...") + /// try db.execute(sql: "INSERT ...") /// return .commit /// } /// } @@ -655,7 +618,7 @@ extension Database { /// /// try dbQueue.inDatabase do { /// try db.inSavepoint { - /// try db.execute("INSERT ...") + /// try db.execute(sql: "INSERT ...") /// return .commit /// } /// } @@ -691,7 +654,7 @@ extension Database { // using unique savepoint names. User could still mess with them // with raw SQL queries, but let's assume that it is unlikely that // the user uses "grdb" as a savepoint name. - try execute("SAVEPOINT grdb") + try execute(sql: "SAVEPOINT grdb") // Now that savepoint has begun, we'll rollback in case of error. // But we'll throw the first caught error, so that user knows @@ -702,7 +665,7 @@ extension Database { let completion = try block() switch completion { case .commit: - try execute("RELEASE SAVEPOINT grdb") + try execute(sql: "RELEASE SAVEPOINT grdb") assert(!topLevelSavepoint || !isInsideTransaction) needsRollback = false case .rollback: @@ -721,8 +684,8 @@ extension Database { // Rollback, and release the savepoint. // Rollback alone is not enough to clear the savepoint from // the SQLite savepoint stack. - try execute("ROLLBACK TRANSACTION TO SAVEPOINT grdb") - try execute("RELEASE SAVEPOINT grdb") + try execute(sql: "ROLLBACK TRANSACTION TO SAVEPOINT grdb") + try execute(sql: "RELEASE SAVEPOINT grdb") } } catch { if firstError == nil { @@ -745,7 +708,7 @@ extension Database { /// - throws: The error thrown by the block. public func beginTransaction(_ kind: TransactionKind? = nil) throws { let kind = kind ?? configuration.defaultTransactionKind - try execute("BEGIN \(kind.rawValue) TRANSACTION") + try execute(sql: "BEGIN \(kind.rawValue) TRANSACTION") assert(isInsideTransaction) } @@ -795,7 +758,7 @@ extension Database { // UPDATE ... // Here the change is not visible by GRDB user try beginTransaction(.deferred) - try internalCachedSelectStatement("SELECT rootpage FROM sqlite_master LIMIT 1").makeCursor().next() + try internalCachedSelectStatement(sql: "SELECT rootpage FROM sqlite_master LIMIT 1").makeCursor().next() } /// Rollbacks a database transaction. @@ -841,14 +804,14 @@ extension Database { // should be exposed to the library user. SchedulingWatchdog.preconditionValidQueue(self) // guard sqlite3_get_autocommit if sqlite3_get_autocommit(sqliteConnection) == 0 { - try execute("ROLLBACK TRANSACTION") + try execute(sql: "ROLLBACK TRANSACTION") } assert(!isInsideTransaction) } /// Commits a database transaction. public func commit() throws { - try execute("COMMIT TRANSACTION") + try execute(sql: "COMMIT TRANSACTION") assert(!isInsideTransaction) } } @@ -924,9 +887,15 @@ extension Database { // > schema of the original db into the new one: // > https://discuss.zetetic.net/t/how-to-encrypt-a-plaintext-sqlite-database-to-use-sqlcipher-and-avoid-file-is-encrypted-or-is-not-a-database-errors/ let data = passphrase.data(using: .utf8)! - let code = data.withUnsafeBytes { bytes in - sqlite3_rekey(sqliteConnection, bytes, Int32(data.count)) + #if swift(>=5.0) + let code = data.withUnsafeBytes { + sqlite3_rekey(sqliteConnection, $0.baseAddress, Int32($0.count)) } + #else + let code = data.withUnsafeBytes { + sqlite3_rekey(sqliteConnection, $0, Int32(data.count)) + } + #endif guard code == SQLITE_OK else { throw DatabaseError(resultCode: code, message: lastErrorMessage) } diff --git a/GRDB/Core/DatabaseCollation.swift b/GRDB/Core/DatabaseCollation.swift index 84d862c78..530992caa 100644 --- a/GRDB/Core/DatabaseCollation.swift +++ b/GRDB/Core/DatabaseCollation.swift @@ -1,6 +1,8 @@ import Foundation #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -16,7 +18,7 @@ public final class DatabaseCollation { /// return (string1 as NSString).localizedStandardCompare(string2) /// } /// db.add(collation: collation) - /// try db.execute("CREATE TABLE file (name TEXT COLLATE localized_standard") + /// try db.execute(sql: "CREATE TABLE file (name TEXT COLLATE localized_standard") /// /// - parameters: /// - name: The function name. @@ -39,17 +41,10 @@ extension DatabaseCollation: Hashable { // implies hash equality) is thus non trivial. But it's not that // important, since this hashValue is only used when one adds // or removes a collation from a database connection. - #if swift(>=4.2) /// :nodoc: public func hash(into hasher: inout Hasher) { hasher.combine(0) } - #else - /// :nodoc: - public var hashValue: Int { - return 0 - } - #endif /// Two collations are equal if they share the same name (case insensitive) /// :nodoc: diff --git a/GRDB/Core/DatabaseError.swift b/GRDB/Core/DatabaseError.swift index 2299c70a7..d9121741d 100644 --- a/GRDB/Core/DatabaseError.swift +++ b/GRDB/Core/DatabaseError.swift @@ -1,6 +1,8 @@ import Foundation #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -147,7 +149,7 @@ extension ResultCode { #if GRDBCUSTOMSQLITE || GRDBCIPHER return String(cString: sqlite3_errstr(rawValue)) #else - if #available(iOS 8.2, OSX 10.10, OSXApplicationExtension 10.10, iOSApplicationExtension 8.2, *) { + if #available(OSX 10.10, OSXApplicationExtension 10.10, *) { return String(cString: sqlite3_errstr(rawValue)) } else { return nil diff --git a/GRDB/Core/DatabaseFunction.swift b/GRDB/Core/DatabaseFunction.swift index 12129f51c..0a9f4e036 100644 --- a/GRDB/Core/DatabaseFunction.swift +++ b/GRDB/Core/DatabaseFunction.swift @@ -1,5 +1,7 @@ #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -27,7 +29,7 @@ public final class DatabaseFunction: Hashable { /// return int + 1 /// } /// db.add(function: fn) - /// try Int.fetchOne(db, "SELECT succ(1)")! // 2 + /// try Int.fetchOne(db, sql: "SELECT succ(1)")! // 2 /// /// - parameters: /// - name: The function name. @@ -73,10 +75,10 @@ public final class DatabaseFunction: Hashable { /// let fn = DatabaseFunction("mysum", argumentCount: 1, aggregate: MySum.self) /// dbQueue.add(function: fn) /// try dbQueue.write { db in - /// try db.execute("CREATE TABLE test(i)") - /// try db.execute("INSERT INTO test(i) VALUES (1)") - /// try db.execute("INSERT INTO test(i) VALUES (2)") - /// try Int.fetchOne(db, "SELECT mysum(i) FROM test")! // 3 + /// try db.execute(sql: "CREATE TABLE test(i)") + /// try db.execute(sql: "INSERT INTO test(i) VALUES (1)") + /// try db.execute(sql: "INSERT INTO test(i) VALUES (2)") + /// try Int.fetchOne(db, sql: "SELECT mysum(i) FROM test")! // 3 /// } /// /// - parameters: @@ -262,7 +264,7 @@ public final class DatabaseFunction: Hashable { let stride = MemoryLayout>.stride let aggregateContextBufferP = UnsafeMutableRawBufferPointer(start: sqlite3_aggregate_context(sqliteContext, Int32(stride))!, count: stride) - if aggregateContextBufferP.contains(where: { $0 != 0 }) { + if aggregateContextBufferP.contains(where: { $0 != 0 }) { // TODO: This testt looks weird. Review. // Buffer contains non-null pointer: load aggregate context let aggregateContextP = aggregateContextBufferP.baseAddress!.assumingMemoryBound(to: Unmanaged.self) return aggregateContextP.pointee @@ -275,8 +277,8 @@ public final class DatabaseFunction: Hashable { // retain and store in SQLite's buffer let aggregateContextU = Unmanaged.passRetained(aggregateContext) - var aggregateContextP = aggregateContextU.toOpaque() - withUnsafeBytes(of: &aggregateContextP) { + let aggregateContextP = aggregateContextU.toOpaque() + withUnsafeBytes(of: aggregateContextP) { aggregateContextBufferP.copyMemory(from: $0) } return aggregateContextU @@ -294,9 +296,15 @@ public final class DatabaseFunction: Hashable { case .string(let string): sqlite3_result_text(sqliteContext, string, -1, SQLITE_TRANSIENT) case .blob(let data): - data.withUnsafeBytes { bytes in - sqlite3_result_blob(sqliteContext, bytes, Int32(data.count), SQLITE_TRANSIENT) + #if swift(>=5.0) + data.withUnsafeBytes { + sqlite3_result_blob(sqliteContext, $0.baseAddress, Int32($0.count), SQLITE_TRANSIENT) } + #else + data.withUnsafeBytes { + sqlite3_result_blob(sqliteContext, $0, Int32(data.count), SQLITE_TRANSIENT) + } + #endif } } @@ -313,17 +321,10 @@ public final class DatabaseFunction: Hashable { } extension DatabaseFunction { - #if swift(>=4.2) /// :nodoc: public func hash(into hasher: inout Hasher) { hasher.combine(identity) } - #else - /// :nodoc: - public var hashValue: Int { - return identity.hashValue - } - #endif /// Two functions are equal if they share the same name and arity. /// :nodoc: @@ -354,10 +355,10 @@ extension DatabaseFunction { /// let fn = DatabaseFunction("mysum", argumentCount: 1, aggregate: MySum.self) /// dbQueue.add(function: fn) /// try dbQueue.write { db in -/// try db.execute("CREATE TABLE test(i)") -/// try db.execute("INSERT INTO test(i) VALUES (1)") -/// try db.execute("INSERT INTO test(i) VALUES (2)") -/// try Int.fetchOne(db, "SELECT mysum(i) FROM test")! // 3 +/// try db.execute(sql: "CREATE TABLE test(i)") +/// try db.execute(sql: "INSERT INTO test(i) VALUES (1)") +/// try db.execute(sql: "INSERT INTO test(i) VALUES (2)") +/// try Int.fetchOne(db, sql: "SELECT mysum(i) FROM test")! // 3 /// } public protocol DatabaseAggregate { /// Creates an aggregate. diff --git a/GRDB/Core/DatabasePool.swift b/GRDB/Core/DatabasePool.swift index 241723b58..7a8bc4362 100644 --- a/GRDB/Core/DatabasePool.swift +++ b/GRDB/Core/DatabasePool.swift @@ -2,6 +2,8 @@ import Foundation import Dispatch #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -58,14 +60,14 @@ public final class DatabasePool: DatabaseWriter { // Activate WAL Mode unless readonly if !configuration.readonly { try writer.sync { db in - let journalMode = try String.fetchOne(db, "PRAGMA journal_mode = WAL") + let journalMode = try String.fetchOne(db, sql: "PRAGMA journal_mode = WAL") guard journalMode == "wal" else { throw DatabaseError(message: "could not activate WAL Mode at path: \(path)") } // https://www.sqlite.org/pragma.html#pragma_synchronous // > Many applications choose NORMAL when in WAL mode - try db.execute("PRAGMA synchronous = NORMAL") + try db.execute(sql: "PRAGMA synchronous = NORMAL") if !FileManager.default.fileExists(atPath: path + "-wal") { // Create the -wal file if it does not exist yet. This @@ -73,7 +75,7 @@ public final class DatabasePool: DatabaseWriter { // opens a pool to an existing non-WAL database, and // attempts to read from it. // See https://github.com/groue/GRDB.swift/issues/102 - try db.execute("CREATE TABLE grdb_issue_102 (id INTEGER PRIMARY KEY); DROP TABLE grdb_issue_102;") + try db.execute(sql: "CREATE TABLE grdb_issue_102 (id INTEGER PRIMARY KEY); DROP TABLE grdb_issue_102;") } } } @@ -177,13 +179,16 @@ extension DatabasePool { public func setupMemoryManagement(in application: UIApplication) { self.application = application let center = NotificationCenter.default - #if swift(>=4.2) - center.addObserver(self, selector: #selector(DatabasePool.applicationDidReceiveMemoryWarning(_:)), name: UIApplication.didReceiveMemoryWarningNotification, object: nil) - center.addObserver(self, selector: #selector(DatabasePool.applicationDidEnterBackground(_:)), name: UIApplication.didReceiveMemoryWarningNotification, object: nil) - #else - center.addObserver(self, selector: #selector(DatabasePool.applicationDidReceiveMemoryWarning(_:)), name: .UIApplicationDidReceiveMemoryWarning, object: nil) - center.addObserver(self, selector: #selector(DatabasePool.applicationDidEnterBackground(_:)), name: .UIApplicationDidEnterBackground, object: nil) - #endif + center.addObserver( + self, + selector: #selector(DatabasePool.applicationDidReceiveMemoryWarning(_:)), + name: UIApplication.didReceiveMemoryWarningNotification, + object: nil) + center.addObserver( + self, + selector: #selector(DatabasePool.applicationDidEnterBackground(_:)), + name: UIApplication.didEnterBackgroundNotification, + object: nil) } @objc private func applicationDidEnterBackground(_ notification: NSNotification) { @@ -192,12 +197,7 @@ extension DatabasePool { } let task: UIBackgroundTaskIdentifier = application.beginBackgroundTask(expirationHandler: nil) - #if swift(>=4.2) - let taskIsInvalid = task == UIBackgroundTaskIdentifier.invalid - #else - let taskIsInvalid = task == UIBackgroundTaskInvalid - #endif - if taskIsInvalid { + if task == .invalid { // Perform releaseMemory() synchronously. releaseMemory() } else { @@ -249,13 +249,13 @@ extension DatabasePool : DatabaseReader { /// try dbPool.read { db in /// // Those two values are guaranteed to be equal, even if the /// // `wine` table is modified between the two requests: - /// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")! - /// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")! + /// let count1 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")! + /// let count2 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")! /// } /// /// try dbPool.read { db in /// // Now this value may be different: - /// let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")! + /// let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")! /// } /// /// This method is *not* reentrant. @@ -290,15 +290,15 @@ extension DatabasePool : DatabaseReader { /// try dbPool.unsafeRead { db in /// // Those two values may be different because some other thread /// // may have inserted or deleted a wine between the two requests: - /// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")! - /// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")! + /// let count1 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")! + /// let count2 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")! /// } /// /// Cursor iteration is safe, though: /// /// try dbPool.unsafeRead { db in /// // No concurrent update can mess with this iteration: - /// let rows = try Row.fetchCursor(db, "SELECT ...") + /// let rows = try Row.fetchCursor(db, sql: "SELECT ...") /// while let row = try rows.next() { ... } /// } /// @@ -327,15 +327,15 @@ extension DatabasePool : DatabaseReader { /// try dbPool.unsafeReentrantRead { db in /// // Those two values may be different because some other thread /// // may have inserted or deleted a wine between the two requests: - /// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")! - /// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")! + /// let count1 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")! + /// let count2 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")! /// } /// /// Cursor iteration is safe, though: /// /// try dbPool.unsafeReentrantRead { db in /// // No concurrent update can mess with this iteration: - /// let rows = try Row.fetchCursor(db, "SELECT ...") + /// let rows = try Row.fetchCursor(db, sql: "SELECT ...") /// while let row = try rows.next() { ... } /// } /// @@ -359,80 +359,7 @@ extension DatabasePool : DatabaseReader { } } - /// This method is deprecated. Use concurrentRead instead. - /// - /// Asynchronously executes a read-only block in a protected dispatch queue, - /// wrapped in a deferred transaction. - /// - /// This method must be called from the writing dispatch queue, outside of a - /// transaction. You'll get a fatal error otherwise. - /// - /// The *block* argument is guaranteed to see the database in the last - /// committed state at the moment this method is called. Eventual concurrent - /// database updates are *not visible* inside the block. - /// - /// try dbPool.write { db in - /// try db.execute("DELETE FROM player") - /// try dbPool.readFromCurrentState { db in - /// // Guaranteed to be zero - /// try Int.fetchOne(db, "SELECT COUNT(*) FROM player")! - /// } - /// try db.execute("INSERT INTO player ...") - /// } - /// - /// This method blocks the current thread until the isolation guarantee has - /// been established, and before the block argument has run. - /// - /// - parameter block: A block that accesses the database. - /// - throws: The error thrown by the block, or any DatabaseError that would - /// happen while establishing the read access to the database. - @available(*, deprecated, message: "Use concurrentRead instead") - public func readFromCurrentState(_ block: @escaping (Database) -> Void) throws { - // Check that we're on the writer queue... - writer.execute { db in - // ... and that no transaction is opened. - GRDBPrecondition(!db.isInsideTransaction, """ - readFromCurrentState must not be called from inside a transaction. \ - If this error is raised from a DatabasePool.write block, use \ - DatabasePool.writeWithoutTransaction instead (and use \ - transactions when needed). - """) - } - - // The semaphore that blocks the writing dispatch queue until snapshot - // isolation has been established: - let semaphore = DispatchSemaphore(value: 0) - - var snapshotIsolationError: Error? = nil - let (reader, releaseReader) = try readerPool.get() - reader.async { db in - defer { - _ = try? db.commit() // Ignore commit error - releaseReader() - } - do { - try db.beginSnapshotIsolation() - } catch { - snapshotIsolationError = error - semaphore.signal() // Release the writer queue and rethrow error - return - } - semaphore.signal() // We can release the writer queue now that we are isolated for good - - // Reset the schema cache before running user code in snapshot isolation - db.schemaCache = SimpleDatabaseSchemaCache() - block(db) - } - - _ = semaphore.wait(timeout: .distantFuture) - - if let error = snapshotIsolationError { - // TODO: write a test for this - throw error - } - } - - public func concurrentRead(_ block: @escaping (Database) throws -> T) -> Future { + public func concurrentRead(_ block: @escaping (Database) throws -> T) -> DatabaseFuture { // Check that we're on the writer queue... writer.execute { db in // ... and that no transaction is opened. @@ -479,16 +406,16 @@ extension DatabasePool : DatabaseReader { futureSemaphore.signal() } } catch { - return Future { throw error } + return DatabaseFuture { throw error } } // Block the writer queue until snapshot isolation success or error _ = isolationSemaphore.wait(timeout: .distantFuture) - return Future { + return DatabaseFuture { // Block the future until results are fetched _ = futureSemaphore.wait(timeout: .distantFuture) - return try futureResult!.unwrap() + return try futureResult!.get() } } @@ -632,7 +559,7 @@ extension DatabasePool : DatabaseReader { /// } /// dbPool.add(function: fn) /// try dbPool.read { db in - /// try Int.fetchOne(db, "SELECT succ(1)") // 2 + /// try Int.fetchOne(db, sql: "SELECT succ(1)") // 2 /// } public func add(function: DatabaseFunction) { functions.update(with: function) @@ -654,7 +581,7 @@ extension DatabasePool : DatabaseReader { /// } /// dbPool.add(collation: collation) /// try dbPool.write { db in - /// try db.execute("CREATE TABLE file (name TEXT COLLATE LOCALIZED_STANDARD") + /// try db.execute(sql: "CREATE TABLE file (name TEXT COLLATE LOCALIZED_STANDARD") /// } public func add(collation: DatabaseCollation) { collations.update(with: collation) diff --git a/GRDB/Core/DatabaseQueue.swift b/GRDB/Core/DatabaseQueue.swift index 60df0bfe8..7d87f698a 100644 --- a/GRDB/Core/DatabaseQueue.swift +++ b/GRDB/Core/DatabaseQueue.swift @@ -94,13 +94,16 @@ extension DatabaseQueue { public func setupMemoryManagement(in application: UIApplication) { self.application = application let center = NotificationCenter.default - #if swift(>=4.2) - center.addObserver(self, selector: #selector(DatabaseQueue.applicationDidReceiveMemoryWarning(_:)), name: UIApplication.didReceiveMemoryWarningNotification, object: nil) - center.addObserver(self, selector: #selector(DatabaseQueue.applicationDidEnterBackground(_:)), name: UIApplication.didEnterBackgroundNotification, object: nil) - #else - center.addObserver(self, selector: #selector(DatabaseQueue.applicationDidReceiveMemoryWarning(_:)), name: .UIApplicationDidReceiveMemoryWarning, object: nil) - center.addObserver(self, selector: #selector(DatabaseQueue.applicationDidEnterBackground(_:)), name: .UIApplicationDidEnterBackground, object: nil) - #endif + center.addObserver( + self, + selector: #selector(DatabaseQueue.applicationDidReceiveMemoryWarning(_:)), + name: UIApplication.didReceiveMemoryWarningNotification, + object: nil) + center.addObserver( + self, + selector: #selector(DatabaseQueue.applicationDidEnterBackground(_:)), + name: UIApplication.didEnterBackgroundNotification, + object: nil) } @objc private func applicationDidEnterBackground(_ notification: NSNotification) { @@ -109,12 +112,7 @@ extension DatabaseQueue { } let task: UIBackgroundTaskIdentifier = application.beginBackgroundTask(expirationHandler: nil) - #if swift(>=4.2) - let taskIsInvalid = task == UIBackgroundTaskIdentifier.invalid - #else - let taskIsInvalid = task == UIBackgroundTaskInvalid - #endif - if taskIsInvalid { + if task == .invalid { // Perform releaseMemory() synchronously. releaseMemory() } else { @@ -203,30 +201,10 @@ extension DatabaseQueue { return try writer.reentrantSync(block) } - /// This method is deprecated. Use concurrentRead instead. - /// - /// Synchronously executes *block*. - /// - /// This method must be called from the protected database dispatch queue, - /// outside of a transaction. You'll get a fatal error otherwise. - /// - /// Starting SQLite 3.8.0 (iOS 8.2+, OSX 10.10+, custom SQLite builds and - /// SQLCipher), attempts to write in the database from this meethod throw a - /// DatabaseError of resultCode `SQLITE_READONLY`. - @available(*, deprecated, message: "Use concurrentRead instead") - public func readFromCurrentState(_ block: @escaping (Database) -> Void) { - // Check that we're on the correct queue... - writer.execute { db in - // ... and that no transaction is opened. - GRDBPrecondition(!db.isInsideTransaction, "readFromCurrentState must not be called from inside a transaction.") - db.readOnly { block(db) } - } - } - - public func concurrentRead(_ block: @escaping (Database) throws -> T) -> Future { + public func concurrentRead(_ block: @escaping (Database) throws -> T) -> DatabaseFuture { // DatabaseQueue can't perform parallel reads. // Perform a blocking read instead. - return Future(Result { + return DatabaseFuture(Result { // Check that we're on the writer queue... try writer.execute { db in // ... and that no transaction is opened. @@ -354,7 +332,7 @@ extension DatabaseQueue { /// } /// dbQueue.add(function: fn) /// try dbQueue.read { db in - /// try Int.fetchOne(db, "SELECT succ(1)") // 2 + /// try Int.fetchOne(db, sql: "SELECT succ(1)") // 2 /// } public func add(function: DatabaseFunction) { writer.sync { $0.add(function: function) } @@ -374,7 +352,7 @@ extension DatabaseQueue { /// } /// dbQueue.add(collation: collation) /// try dbQueue.write { db in - /// try db.execute("CREATE TABLE file (name TEXT COLLATE LOCALIZED_STANDARD") + /// try db.execute(sql: "CREATE TABLE file (name TEXT COLLATE LOCALIZED_STANDARD") /// } public func add(collation: DatabaseCollation) { writer.sync { $0.add(collation: collation) } diff --git a/GRDB/Core/DatabaseReader.swift b/GRDB/Core/DatabaseReader.swift index ee4ddd702..3f0a79b0f 100644 --- a/GRDB/Core/DatabaseReader.swift +++ b/GRDB/Core/DatabaseReader.swift @@ -1,5 +1,7 @@ #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -32,13 +34,13 @@ public protocol DatabaseReader : class { /// try reader.read { db in /// // Those two values are guaranteed to be equal, even if the /// // `wine` table is modified between the two requests: - /// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")! - /// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")! + /// let count1 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")! + /// let count2 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")! /// } /// /// try reader.read { db in /// // Now this value may be different: - /// let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")! + /// let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")! /// } /// /// Guarantee 2: Starting iOS 8.2, OSX 10.10, and with custom SQLite builds @@ -61,15 +63,15 @@ public protocol DatabaseReader : class { /// try reader.unsafeRead { db in /// // Those two values may be different because some other thread /// // may have inserted or deleted a wine between the two requests: - /// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")! - /// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")! + /// let count1 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")! + /// let count2 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")! /// } /// /// Cursor iterations are isolated, though: /// /// try reader.unsafeRead { db in /// // No concurrent update can mess with this iteration: - /// let rows = try Row.fetchCursor(db, "SELECT ...") + /// let rows = try Row.fetchCursor(db, sql: "SELECT ...") /// while let row = try rows.next() { ... } /// } /// @@ -92,15 +94,15 @@ public protocol DatabaseReader : class { /// try reader.unsafeReentrantRead { db in /// // Those two values may be different because some other thread /// // may have inserted or deleted a wine between the two requests: - /// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")! - /// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")! + /// let count1 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")! + /// let count2 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")! /// } /// /// Cursor iterations are isolated, though: /// /// try reader.unsafeReentrantRead { db in /// // No concurrent update can mess with this iteration: - /// let rows = try Row.fetchCursor(db, "SELECT ...") + /// let rows = try Row.fetchCursor(db, sql: "SELECT ...") /// while let row = try rows.next() { ... } /// } /// @@ -128,7 +130,7 @@ public protocol DatabaseReader : class { /// } /// reader.add(function: fn) /// try reader.read { db in - /// try Int.fetchOne(db, "SELECT succ(1)")! // 2 + /// try Int.fetchOne(db, sql: "SELECT succ(1)")! // 2 /// } func add(function: DatabaseFunction) @@ -144,7 +146,7 @@ public protocol DatabaseReader : class { /// return (string1 as NSString).localizedStandardCompare(string2) /// } /// reader.add(collation: collation) - /// try reader.execute("SELECT * FROM file ORDER BY name COLLATE localized_standard") + /// try reader.execute(sql: "SELECT * FROM file ORDER BY name COLLATE localized_standard") func add(collation: DatabaseCollation) /// Remove a collation. diff --git a/GRDB/Core/DatabaseRegion.swift b/GRDB/Core/DatabaseRegion.swift index 042bf335a..7df10aa59 100644 --- a/GRDB/Core/DatabaseRegion.swift +++ b/GRDB/Core/DatabaseRegion.swift @@ -3,8 +3,7 @@ /// `observes(eventsOfKind:)` and `databaseDidChange(with:)` methods. /// /// A database region is the union of any number of "table regions", which can -/// cover a full table, or the combination of columns and rows (identified by -/// their rowids): +/// cover a full table, or the combination of columns and rows: /// /// |Table1 | |Table2 | |Table3 | |Table4 | |Table5 | /// |-------| |-------| |-------| |-------| |-------| @@ -13,32 +12,23 @@ /// |x|x|x|x| |x| | | | | | | | | |x|x| |x| | | | | | /// |x|x|x|x| |x| | | | | | | | | | | | | | | | | | | /// -/// You don't create a database region directly. Instead, you use one of -/// those methods: +/// To create a database region, you use one of those methods: +/// +/// - `DatabaseRegion.fullDatabase`: the region that covers all database tables. +/// +/// - `DatabaseRegion()`: the empty region. +/// +/// - `DatabaseRegion(table:)`: the region that covers one database table. /// /// - `SelectStatement.databaseRegion`: /// -/// let statement = db.makeSelectStatement("SELECT name, score FROM player") -/// print(statement.databaseRegion) -/// // prints "player(name,score)" +/// let statement = try db.makeSelectStatement(sql: "SELECT name, score FROM player") +/// let region = statement.databaseRegion /// /// - `FetchRequest.databaseRegion(_:)` /// /// let request = Player.filter(key: 1) -/// try print(request.databaseRegion(db)) -/// // prints "player(*)[1]" -/// -/// Database regions returned by requests can be more precise than regions -/// returned by select statements. Especially, regions returned by statements -/// don't know about rowids: -/// -/// // A plain statement -/// let statement = db.makeSelectStatement("SELECT * FROM player WHERE id = 1") -/// statement.databaseRegion // "player(*)" -/// -/// // A query interface request that executes the same statement: -/// let request = Player.filter(key: 1) -/// try request.databaseRegion(db) // "player(*)[1]" +/// let region = try request.databaseRegion(db) public struct DatabaseRegion: CustomStringConvertible, Equatable { private let tableRegions: [String: TableRegion]? private init(tableRegions: [String: TableRegion]?) { @@ -58,13 +48,15 @@ public struct DatabaseRegion: CustomStringConvertible, Equatable { /// from all tables. public static let fullDatabase = DatabaseRegion(tableRegions: nil) - /// The empty database region + /// Creates an empty database region. public init() { self.init(tableRegions: [:]) } - /// A full table: (all columns in the table) × (all rows) - init(table: String) { + /// Creates a region that spans all rows and columns of a database table. + /// + /// - parameter table: A table name. + public init(table: String) { self.init(tableRegions: [table: TableRegion(columns: nil, rowIds: nil)]) } @@ -302,7 +294,6 @@ private struct TableRegion: Equatable { return TableRegion(columns: columnsUnion, rowIds: rowIdsUnion) } - @inline(__always) func contains(rowID: Int64) -> Bool { guard let rowIds = rowIds else { return true diff --git a/GRDB/Core/DatabaseSnapshot.swift b/GRDB/Core/DatabaseSnapshot.swift index 5ea57064c..fc7b28adc 100644 --- a/GRDB/Core/DatabaseSnapshot.swift +++ b/GRDB/Core/DatabaseSnapshot.swift @@ -28,7 +28,7 @@ public class DatabaseSnapshot : DatabaseReader { try serializedDatabase.sync { db in // Assert WAL mode - let journalMode = try String.fetchOne(db, "PRAGMA journal_mode") + let journalMode = try String.fetchOne(db, sql: "PRAGMA journal_mode") guard journalMode == "wal" else { throw DatabaseError(message: "WAL mode is not activated at path: \(path)") } @@ -116,7 +116,7 @@ extension DatabaseSnapshot { } } } - case let .onQueue(queue, startImmediately: startImmediately): + case let .async(onQueue: queue, startImmediately: startImmediately): if startImmediately { if let value = try unsafeReentrantRead(observation.initialValue) { queue.async { diff --git a/GRDB/Core/DatabaseValue.swift b/GRDB/Core/DatabaseValue.swift index 4a9b9adaf..d2b44f81e 100644 --- a/GRDB/Core/DatabaseValue.swift +++ b/GRDB/Core/DatabaseValue.swift @@ -1,6 +1,8 @@ import Foundation #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -149,7 +151,6 @@ public struct DatabaseValue: Hashable, CustomStringConvertible, DatabaseValueCon // Hashable extension DatabaseValue { - #if swift(>=4.2) /// :nodoc: public func hash(into hasher: inout Hasher) { switch storage { @@ -166,24 +167,6 @@ extension DatabaseValue { hasher.combine(data) } } - #else - /// :nodoc: - public var hashValue: Int { - switch storage { - case .null: - return 0 - case .int64(let int64): - // 1 == 1.0, hence 1 and 1.0 must have the same hash: - return Double(int64).hashValue - case .double(let double): - return double.hashValue - case .string(let string): - return string.hashValue - case .blob(let data): - return data.hashValue - } - } - #endif /// Returns whether two DatabaseValues are equal. /// @@ -222,57 +205,6 @@ extension DatabaseValue { } } -// MARK: - Lossless conversions - -extension DatabaseValue { - // TODO: deprecate and rename to DatabaseValue.decode(_:sql:arguments:) - /// Converts the database value to the type T. - /// - /// let dbValue = "foo".databaseValue - /// let string = dbValue.losslessConvert() as String // "foo" - /// - /// Conversion is successful if and only if T.fromDatabaseValue returns a - /// non-nil value. - /// - /// This method crashes with a fatal error when conversion fails. - /// - /// let dbValue = "foo".databaseValue - /// let int = dbValue.losslessConvert() as Int // fatalError - /// - /// - parameters: - /// - sql: Optional SQL statement that enhances the eventual - /// conversion error - /// - arguments: Optional statement arguments that enhances the eventual - /// conversion error - public func losslessConvert(sql: String? = nil, arguments: StatementArguments? = nil) -> T where T : DatabaseValueConvertible { - return T.decode(from: self, conversionContext: sql.map { ValueConversionContext(sql: $0, arguments: arguments) }) - } - - // TODO: deprecate and rename to DatabaseValue.decodeIfPresent(_:sql:arguments:) - /// Converts the database value to the type Optional. - /// - /// let dbValue = "foo".databaseValue - /// let string = dbValue.losslessConvert() as String? // "foo" - /// let null = DatabaseValue.null.losslessConvert() as String? // nil - /// - /// Conversion is successful if and only if T.fromDatabaseValue returns a - /// non-nil value. - /// - /// This method crashes with a fatal error when conversion fails. - /// - /// let dbValue = "foo".databaseValue - /// let int = dbValue.losslessConvert() as Int? // fatalError - /// - /// - parameters: - /// - sql: Optional SQL statement that enhances the eventual - /// conversion error - /// - arguments: Optional statement arguments that enhances the eventual - /// conversion error - public func losslessConvert(sql: String? = nil, arguments: StatementArguments? = nil) -> T? where T : DatabaseValueConvertible { - return T.decodeIfPresent(from: self, conversionContext: sql.map { ValueConversionContext(sql: $0, arguments: arguments) }) - } -} - // DatabaseValueConvertible extension DatabaseValue { /// Returns self @@ -305,12 +237,12 @@ extension DatabaseValue { return "NULL" } - if context.appendArguments([self]) { + if context.append(arguments: [self]) { return "?" } else { // Correctness above all: use SQLite to quote the value. // Assume that the Quote function always succeeds - return DatabaseQueue().inDatabase { try! String.fetchOne($0, "SELECT QUOTE(?)", arguments: [self])! } + return DatabaseQueue().inDatabase { try! String.fetchOne($0, sql: "SELECT QUOTE(?)", arguments: [self])! } } } @@ -345,12 +277,6 @@ extension DatabaseValue { public func qualifiedExpression(with alias: TableAlias) -> SQLExpression { return self } - - /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) - /// :nodoc: - public func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression { - return self - } } // CustomStringConvertible @@ -371,3 +297,45 @@ extension DatabaseValue { } } } + +/// Compares DatabaseValue like SQLite. +/// +/// See RxGRDB for tests. +/// +/// This comparison is not public because it does not handle text collations, +/// and may be dangerous when put in user hands. +/// +/// So far, the only goal of this sorting method so far is aesthetic, and +/// easier testing. +func < (lhs: DatabaseValue, rhs: DatabaseValue) -> Bool { + switch (lhs.storage, rhs.storage) { + case (.int64(let lhs), .int64(let rhs)): + return lhs < rhs + case (.double(let lhs), .double(let rhs)): + return lhs < rhs + case (.int64(let lhs), .double(let rhs)): + return Double(lhs) < rhs + case (.double(let lhs), .int64(let rhs)): + return lhs < Double(rhs) + case (.string(let lhs), .string(let rhs)): + return lhs.utf8.lexicographicallyPrecedes(rhs.utf8) + case (.blob(let lhs), .blob(let rhs)): + return lhs.lexicographicallyPrecedes(rhs, by: <) + case (.blob, _): + return false + case (_, .blob): + return true + case (.string, _): + return false + case (_, .string): + return true + case (.int64, _), (.double, _): + return false + case (_, .int64), (_, .double): + return true + case (.null, _): + return false + case (_, .null): + return true + } +} diff --git a/GRDB/Core/DatabaseValueConversion.swift b/GRDB/Core/DatabaseValueConversion.swift index 573342609..a752e34e5 100644 --- a/GRDB/Core/DatabaseValueConversion.swift +++ b/GRDB/Core/DatabaseValueConversion.swift @@ -1,5 +1,7 @@ #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -68,7 +70,7 @@ extension ValueConversionContext { arguments: statement.arguments, column: nil) } else if let sqliteStatement = row.sqliteStatement { - let sql = String(cString: sqlite3_sql(sqliteStatement)).trimmingCharacters(in: statementSeparatorCharacterSet) + let sql = String(cString: sqlite3_sql(sqliteStatement)).trimmingCharacters(in: .sqlStatementSeparators) self.init( row: row.copy(), sql: sql, @@ -82,14 +84,6 @@ extension ValueConversionContext { column: nil) } } - - init(sql: String, arguments: StatementArguments?) { - self.init( - row: nil, - sql: sql, - arguments: arguments, - column: nil) - } } /// The canonical conversion error message @@ -138,7 +132,16 @@ func fatalConversionError(to: T.Type, from dbValue: DatabaseValue?, conversio fatalError(conversionErrorMessage(to: T.self, from: dbValue, conversionContext: conversionContext), file: file, line: line) } -func fatalConversionError(to: T.Type, sqliteStatement: SQLiteStatement, index: Int32) -> Never { +@usableFromInline +func fatalConversionError(to: T.Type, from dbValue: DatabaseValue?, in row: Row, atColumn columnName: String, file: StaticString = #file, line: UInt = #line) -> Never { + fatalConversionError( + to: T.self, + from: dbValue, + conversionContext: ValueConversionContext(row).atColumn(columnName)) +} + +@usableFromInline +func fatalConversionError(to: T.Type, sqliteStatement: SQLiteStatement, index: Int32, file: StaticString = #file, line: UInt = #line) -> Never { let row = Row(sqliteStatement: sqliteStatement) fatalConversionError( to: T.self, @@ -146,11 +149,29 @@ func fatalConversionError(to: T.Type, sqliteStatement: SQLiteStatement, index conversionContext: ValueConversionContext(row).atColumn(Int(index))) } +@usableFromInline +func fatalConversionError(to: T.Type, from dbValue: DatabaseValue?, sqliteStatement: SQLiteStatement, index: Int32, file: StaticString = #file, line: UInt = #line) -> Never { + let row = Row(sqliteStatement: sqliteStatement) + fatalConversionError( + to: T.self, + from: dbValue, + conversionContext: ValueConversionContext(row).atColumn(Int(index))) +} + // MARK: - DatabaseValueConvertible /// Lossless conversions from database values and rows extension DatabaseValueConvertible { - @inline(__always) + @usableFromInline + static func decode(from sqliteStatement: SQLiteStatement, atUncheckedIndex index: Int32) -> Self { + let dbValue = DatabaseValue(sqliteStatement: sqliteStatement, index: index) + if let value = fromDatabaseValue(dbValue) { + return value + } else { + fatalConversionError(to: Self.self, from: dbValue, sqliteStatement: sqliteStatement, index: index) + } + } + static func decode(from dbValue: DatabaseValue, conversionContext: @autoclosure () -> ValueConversionContext?) -> Self { if let value = fromDatabaseValue(dbValue) { return value @@ -159,14 +180,25 @@ extension DatabaseValueConvertible { } } - @inline(__always) + @usableFromInline static func decode(from row: Row, atUncheckedIndex index: Int) -> Self { return decode( from: row.impl.databaseValue(atUncheckedIndex: index), conversionContext: ValueConversionContext(row).atColumn(index)) } - @inline(__always) + @usableFromInline + static func decodeIfPresent(from sqliteStatement: SQLiteStatement, atUncheckedIndex index: Int32) -> Self? { + let dbValue = DatabaseValue(sqliteStatement: sqliteStatement, index: index) + if let value = fromDatabaseValue(dbValue) { + return value + } else if dbValue.isNull { + return nil + } else { + fatalConversionError(to: Self.self, from: dbValue, sqliteStatement: sqliteStatement, index: index) + } + } + static func decodeIfPresent(from dbValue: DatabaseValue, conversionContext: @autoclosure () -> ValueConversionContext?) -> Self? { // Use fromDatabaseValue before checking for null: this allows DatabaseValue to convert NULL to .null. if let value = fromDatabaseValue(dbValue) { @@ -178,7 +210,7 @@ extension DatabaseValueConvertible { } } - @inline(__always) + @usableFromInline static func decodeIfPresent(from row: Row, atUncheckedIndex index: Int) -> Self? { return decodeIfPresent( from: row.impl.databaseValue(atUncheckedIndex: index), @@ -190,26 +222,23 @@ extension DatabaseValueConvertible { /// Lossless conversions from database values and rows extension DatabaseValueConvertible where Self: StatementColumnConvertible { - @inline(__always) - static func fastDecode(from sqliteStatement: SQLiteStatement, index: Int32) -> Self { + @inlinable + static func fastDecode(from sqliteStatement: SQLiteStatement, atUncheckedIndex index: Int32) -> Self { if sqlite3_column_type(sqliteStatement, index) == SQLITE_NULL { - fatalConversionError( - to: Self.self, - from: .null, - conversionContext: ValueConversionContext(Row(sqliteStatement: sqliteStatement)).atColumn(Int(index))) + fatalConversionError(to: Self.self, sqliteStatement: sqliteStatement, index: index) } return self.init(sqliteStatement: sqliteStatement, index: index) } - @inline(__always) + @inlinable static func fastDecode(from row: Row, atUncheckedIndex index: Int) -> Self { if let sqliteStatement = row.sqliteStatement { - return fastDecode(from: sqliteStatement, index: Int32(index)) + return fastDecode(from: sqliteStatement, atUncheckedIndex: Int32(index)) } - return row.impl.fastDecode(Self.self, atUncheckedIndex: index) + return row.fastDecode(Self.self, atUncheckedIndex: index) } - @inline(__always) + @inlinable static func fastDecodeIfPresent(from sqliteStatement: SQLiteStatement, atUncheckedIndex index: Int32) -> Self? { if sqlite3_column_type(sqliteStatement, index) == SQLITE_NULL { return nil @@ -217,11 +246,24 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { return self.init(sqliteStatement: sqliteStatement, index: index) } - @inline(__always) + @inlinable static func fastDecodeIfPresent(from row: Row, atUncheckedIndex index: Int) -> Self? { if let sqliteStatement = row.sqliteStatement { return fastDecodeIfPresent(from: sqliteStatement, atUncheckedIndex: Int32(index)) } - return row.impl.fastDecodeIfPresent(Self.self, atUncheckedIndex: index) + return row.fastDecodeIfPresent(Self.self, atUncheckedIndex: index) + } +} + +// Support for @inlinable decoding +extension Row { + @usableFromInline + func fastDecode(_ type: Value.Type, atUncheckedIndex index: Int) -> Value { + return impl.fastDecode(type, atUncheckedIndex: index) + } + + @usableFromInline + func fastDecodeIfPresent(_ type: Value.Type, atUncheckedIndex index: Int) -> Value? { + return impl.fastDecodeIfPresent(type, atUncheckedIndex: index) } } diff --git a/GRDB/Core/DatabaseValueConvertible.swift b/GRDB/Core/DatabaseValueConvertible.swift index e0590e6cf..3c0095e4b 100644 --- a/GRDB/Core/DatabaseValueConvertible.swift +++ b/GRDB/Core/DatabaseValueConvertible.swift @@ -1,5 +1,7 @@ #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -12,11 +14,11 @@ /// The protocol comes with built-in methods that allow to fetch cursors, /// arrays, or single values: /// -/// try String.fetchCursor(db, "SELECT name FROM ...", arguments:...) // Cursor of String -/// try String.fetchAll(db, "SELECT name FROM ...", arguments:...) // [String] -/// try String.fetchOne(db, "SELECT name FROM ...", arguments:...) // String? +/// try String.fetchCursor(db, sql: "SELECT name FROM ...", arguments:...) // Cursor of String +/// try String.fetchAll(db, sql: "SELECT name FROM ...", arguments:...) // [String] +/// try String.fetchOne(db, sql: "SELECT name FROM ...", arguments:...) // String? /// -/// let statement = try db.makeSelectStatement("SELECT name FROM ...") +/// let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") /// try String.fetchCursor(statement, arguments:...) // Cursor of String /// try String.fetchAll(statement, arguments:...) // [String] /// try String.fetchOne(statement, arguments:...) // String? @@ -42,58 +44,51 @@ extension DatabaseValueConvertible { /// For example: /// /// try dbQueue.read { db in -/// let urls: DatabaseValueCursor = try URL.fetchCursor(db, "SELECT url FROM link") +/// let urls: DatabaseValueCursor = try URL.fetchCursor(db, sql: "SELECT url FROM link") /// while let url = urls.next() { // URL /// print(url) /// } /// } public final class DatabaseValueCursor : Cursor { - private let statement: SelectStatement - private let sqliteStatement: SQLiteStatement - private let columnIndex: Int32 - private var done = false + @usableFromInline let _statement: SelectStatement + @usableFromInline let _sqliteStatement: SQLiteStatement + @usableFromInline let _columnIndex: Int32 + @usableFromInline var _done = false init(statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { - self.statement = statement - self.sqliteStatement = statement.sqliteStatement + _statement = statement + _sqliteStatement = statement.sqliteStatement if let adapter = adapter { // adapter may redefine the index of the leftmost column - self.columnIndex = try Int32(adapter.baseColumnIndex(atIndex: 0, layout: statement)) + _columnIndex = try Int32(adapter.baseColumnIndex(atIndex: 0, layout: statement)) } else { - self.columnIndex = 0 + _columnIndex = 0 } - statement.reset(withArguments: arguments) + _statement.reset(withArguments: arguments) } deinit { // Statement reset fails when sqlite3_step has previously failed. // Just ignore reset error. - try? statement.reset() + try? _statement.reset() } /// :nodoc: + @inlinable public func next() throws -> Value? { - if done { + if _done { // make sure this instance never yields a value again, even if the // statement is reset by another cursor. return nil } - switch sqlite3_step(sqliteStatement) { + switch sqlite3_step(_sqliteStatement) { case SQLITE_DONE: - done = true + _done = true return nil case SQLITE_ROW: - let dbValue = DatabaseValue(sqliteStatement: sqliteStatement, index: columnIndex) - return Value.decode( - from: dbValue, - conversionContext: ValueConversionContext(statement).atColumn(Int(columnIndex))) + return Value.decode(from: _sqliteStatement, atUncheckedIndex: _columnIndex) case let code: - statement.database.selectStatementDidFail(statement) - throw DatabaseError( - resultCode: code, - message: statement.database.lastErrorMessage, - sql: statement.sql, - arguments: statement.arguments) + try _statement.didFail(withResultCode: code) } } } @@ -102,58 +97,51 @@ public final class DatabaseValueCursor : Cursor /// For example: /// /// try dbQueue.read { db in -/// let urls: NullableDatabaseValueCursor = try Optional.fetchCursor(db, "SELECT url FROM link") +/// let urls: NullableDatabaseValueCursor = try Optional.fetchCursor(db, sql: "SELECT url FROM link") /// while let url = urls.next() { // URL? /// print(url) /// } /// } public final class NullableDatabaseValueCursor : Cursor { - private let statement: SelectStatement - private let sqliteStatement: SQLiteStatement - private let columnIndex: Int32 - private var done = false - + @usableFromInline let _statement: SelectStatement + @usableFromInline let _sqliteStatement: SQLiteStatement + @usableFromInline let _columnIndex: Int32 + @usableFromInline var _done = false + init(statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { - self.statement = statement - self.sqliteStatement = statement.sqliteStatement + _statement = statement + _sqliteStatement = statement.sqliteStatement if let adapter = adapter { // adapter may redefine the index of the leftmost column - self.columnIndex = try Int32(adapter.baseColumnIndex(atIndex: 0, layout: statement)) + _columnIndex = try Int32(adapter.baseColumnIndex(atIndex: 0, layout: statement)) } else { - self.columnIndex = 0 + _columnIndex = 0 } - statement.reset(withArguments: arguments) + _statement.reset(withArguments: arguments) } deinit { // Statement reset fails when sqlite3_step has previously failed. // Just ignore reset error. - try? statement.reset() + try? _statement.reset() } /// :nodoc: + @inlinable public func next() throws -> Value?? { - if done { + if _done { // make sure this instance never yields a value again, even if the // statement is reset by another cursor. return nil } - switch sqlite3_step(sqliteStatement) { + switch sqlite3_step(_sqliteStatement) { case SQLITE_DONE: - done = true + _done = true return nil case SQLITE_ROW: - let dbValue = DatabaseValue(sqliteStatement: sqliteStatement, index: columnIndex) - return Value.decodeIfPresent( - from: dbValue, - conversionContext: ValueConversionContext(statement).atColumn(Int(columnIndex))) + return Value.decodeIfPresent(from: _sqliteStatement, atUncheckedIndex: _columnIndex) case let code: - statement.database.selectStatementDidFail(statement) - throw DatabaseError( - resultCode: code, - message: statement.database.lastErrorMessage, - sql: statement.sql, - arguments: statement.arguments) + try _statement.didFail(withResultCode: code) } } } @@ -161,11 +149,11 @@ public final class NullableDatabaseValueCursor /// DatabaseValueConvertible comes with built-in methods that allow to fetch /// cursors, arrays, or single values: /// -/// try String.fetchCursor(db, "SELECT name FROM ...", arguments:...) // Cursor of String -/// try String.fetchAll(db, "SELECT name FROM ...", arguments:...) // [String] -/// try String.fetchOne(db, "SELECT name FROM ...", arguments:...) // String? +/// try String.fetchCursor(db, sql: "SELECT name FROM ...", arguments:...) // Cursor of String +/// try String.fetchAll(db, sql: "SELECT name FROM ...", arguments:...) // [String] +/// try String.fetchOne(db, sql: "SELECT name FROM ...", arguments:...) // String? /// -/// let statement = try db.makeSelectStatement("SELECT name FROM ...") +/// let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") /// try String.fetchCursor(statement, arguments:...) // Cursor of String /// try String.fetchAll(statement, arguments:...) // [String] /// try String.fetchOne(statement, arguments:...) // String @@ -177,7 +165,7 @@ extension DatabaseValueConvertible { /// Returns a cursor over values fetched from a prepared statement. /// - /// let statement = try db.makeSelectStatement("SELECT name FROM ...") + /// let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") /// let names = try String.fetchCursor(statement) // Cursor of String /// while let name = try names.next() { // String /// ... @@ -200,7 +188,7 @@ extension DatabaseValueConvertible { /// Returns an array of values fetched from a prepared statement. /// - /// let statement = try db.makeSelectStatement("SELECT name FROM ...") + /// let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") /// let names = try String.fetchAll(statement) // [String] /// /// - parameters: @@ -218,7 +206,7 @@ extension DatabaseValueConvertible { /// The result is nil if the query returns no row, or if no value can be /// extracted from the first row. /// - /// let statement = try db.makeSelectStatement("SELECT name FROM ...") + /// let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") /// let name = try String.fetchOne(statement) // String? /// /// - parameters: @@ -240,7 +228,7 @@ extension DatabaseValueConvertible { /// Returns a cursor over values fetched from an SQL query. /// - /// let names = try String.fetchCursor(db, "SELECT name FROM ...") // Cursor of String + /// let names = try String.fetchCursor(db, sql: "SELECT name FROM ...") // Cursor of String /// while let name = try name.next() { // String /// ... /// } @@ -253,27 +241,27 @@ extension DatabaseValueConvertible { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DatabaseValueCursor { - return try fetchCursor(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + public static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> DatabaseValueCursor { + return try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns an array of values fetched from an SQL query. /// - /// let names = try String.fetchAll(db, "SELECT name FROM ...") // [String] + /// let names = try String.fetchAll(db, sql: "SELECT name FROM ...") // [String] /// /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An array. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] { - return try fetchAll(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + public static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] { + return try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns a single value fetched from an SQL query. @@ -281,17 +269,17 @@ extension DatabaseValueConvertible { /// The result is nil if the query returns no row, or if no value can be /// extracted from the first row. /// - /// let name = try String.fetchOne(db, "SELECT name FROM ...") // String? + /// let name = try String.fetchOne(db, sql: "SELECT name FROM ...") // String? /// /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An optional value. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? { - return try fetchOne(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + public static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? { + return try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } @@ -318,7 +306,7 @@ extension DatabaseValueConvertible { /// - returns: A cursor over fetched values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. public static func fetchCursor(_ db: Database, _ request: R) throws -> DatabaseValueCursor { - let (statement, adapter) = try request.prepare(db) + let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchCursor(statement, adapter: adapter) } @@ -333,7 +321,7 @@ extension DatabaseValueConvertible { /// - returns: An array. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. public static func fetchAll(_ db: Database, _ request: R) throws -> [Self] { - let (statement, adapter) = try request.prepare(db) + let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchAll(statement, adapter: adapter) } @@ -351,7 +339,7 @@ extension DatabaseValueConvertible { /// - returns: An optional value. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. public static func fetchOne(_ db: Database, _ request: R) throws -> Self? { - let (statement, adapter) = try request.prepare(db) + let (statement, adapter) = try request.prepare(db, forSingleResult: true) return try fetchOne(statement, adapter: adapter) } } @@ -362,7 +350,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible { /// A cursor over fetched values. /// - /// let request: ... // Some TypedRequest that fetches String + /// let request: ... // Some FetchRequest that fetches String /// let strings = try request.fetchCursor(db) // Cursor of String /// while let string = try strings.next() { // String /// ... @@ -382,7 +370,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible { /// An array of fetched values. /// - /// let request: ... // Some TypedRequest that fetches String + /// let request: ... // Some FetchRequest that fetches String /// let strings = try request.fetchAll(db) // [String] /// /// - parameter db: A database connection. @@ -397,7 +385,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible { /// The result is nil if the request returns no row, or if no value can be /// extracted from the first row. /// - /// let request: ... // Some TypedRequest that fetches String + /// let request: ... // Some FetchRequest that fetches String /// let string = try request.fetchOne(db) // String? /// /// - parameter db: A database connection. @@ -411,10 +399,10 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible { /// Swift's Optional comes with built-in methods that allow to fetch cursors /// and arrays of optional DatabaseValueConvertible: /// -/// try Optional.fetchCursor(db, "SELECT name FROM ...", arguments:...) // Cursor of String? -/// try Optional.fetchAll(db, "SELECT name FROM ...", arguments:...) // [String?] +/// try Optional.fetchCursor(db, sql: "SELECT name FROM ...", arguments:...) // Cursor of String? +/// try Optional.fetchAll(db, sql: "SELECT name FROM ...", arguments:...) // [String?] /// -/// let statement = try db.makeSelectStatement("SELECT name FROM ...") +/// let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") /// try Optional.fetchCursor(statement, arguments:...) // Cursor of String? /// try Optional.fetchAll(statement, arguments:...) // [String?] /// @@ -425,7 +413,7 @@ extension Optional where Wrapped: DatabaseValueConvertible { /// Returns a cursor over optional values fetched from a prepared statement. /// - /// let statement = try db.makeSelectStatement("SELECT name FROM ...") + /// let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") /// let names = try Optional.fetchCursor(statement) // Cursor of String? /// while let name = try names.next() { // String? /// ... @@ -448,7 +436,7 @@ extension Optional where Wrapped: DatabaseValueConvertible { /// Returns an array of optional values fetched from a prepared statement. /// - /// let statement = try db.makeSelectStatement("SELECT name FROM ...") + /// let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") /// let names = try Optional.fetchAll(statement) // [String?] /// /// - parameters: @@ -468,7 +456,7 @@ extension Optional where Wrapped: DatabaseValueConvertible { /// Returns a cursor over optional values fetched from an SQL query. /// - /// let names = try Optional.fetchCursor(db, "SELECT name FROM ...") // Cursor of String? + /// let names = try Optional.fetchCursor(db, sql: "SELECT name FROM ...") // Cursor of String? /// while let name = try names.next() { // String? /// ... /// } @@ -481,27 +469,27 @@ extension Optional where Wrapped: DatabaseValueConvertible { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor { - return try fetchCursor(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + public static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor { + return try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns an array of optional values fetched from an SQL query. /// - /// let names = try String.fetchAll(db, "SELECT name FROM ...") // [String?] + /// let names = try String.fetchAll(db, sql: "SELECT name FROM ...") // [String?] /// /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - parameter arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An array of optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Wrapped?] { - return try fetchAll(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + public static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Wrapped?] { + return try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } @@ -528,7 +516,7 @@ extension Optional where Wrapped: DatabaseValueConvertible { /// - returns: A cursor over fetched optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. public static func fetchCursor(_ db: Database, _ request: R) throws -> NullableDatabaseValueCursor { - let (statement, adapter) = try request.prepare(db) + let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchCursor(statement, adapter: adapter) } @@ -543,7 +531,7 @@ extension Optional where Wrapped: DatabaseValueConvertible { /// - returns: An array of optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. public static func fetchAll(_ db: Database, _ request: R) throws -> [Wrapped?] { - let (statement, adapter) = try request.prepare(db) + let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchAll(statement, adapter: adapter) } } @@ -554,7 +542,7 @@ extension FetchRequest where RowDecoder: _OptionalProtocol, RowDecoder._Wrapped: /// A cursor over fetched optional values. /// - /// let request: ... // Some TypedRequest that fetches Optional + /// let request: ... // Some FetchRequest that fetches Optional /// let strings = try request.fetchCursor(db) // Cursor of String? /// while let string = try strings.next() { // String? /// ... @@ -574,7 +562,7 @@ extension FetchRequest where RowDecoder: _OptionalProtocol, RowDecoder._Wrapped: /// An array of fetched optional values. /// - /// let request: ... // Some TypedRequest that fetches Optional + /// let request: ... // Some FetchRequest that fetches Optional /// let strings = try request.fetchAll(db) // [String?] /// /// - parameter db: A database connection. diff --git a/GRDB/Core/DatabaseWriter.swift b/GRDB/Core/DatabaseWriter.swift index 5dbe867f5..c313ef2ba 100644 --- a/GRDB/Core/DatabaseWriter.swift +++ b/GRDB/Core/DatabaseWriter.swift @@ -62,31 +62,6 @@ public protocol DatabaseWriter : DatabaseReader { // MARK: - Reading from Database - /// This method is deprecated. Use concurrentRead instead. - /// - /// Synchronously or asynchronously executes a read-only block that takes a - /// database connection. - /// - /// This method must be called from a writing dispatch queue, outside of any - /// transaction. You'll get a fatal error otherwise. - /// - /// The *block* argument is guaranteed to see the database in the last - /// committed state at the moment this method is called. Eventual concurrent - /// database updates are *not visible* inside the block. - /// - /// For example: - /// - /// try writer.writeWithoutTransaction { db in - /// try db.execute("DELETE FROM player") - /// try writer.readFromCurrentState { db in - /// // Guaranteed to be zero - /// try Int.fetchOne(db, "SELECT COUNT(*) FROM player")! - /// } - /// try db.execute("INSERT INTO player ...") - /// } - @available(*, deprecated, message: "Use concurrentRead instead") - func readFromCurrentState(_ block: @escaping (Database) -> Void) throws - /// Concurrently executes a read-only block that takes a /// database connection. /// @@ -119,7 +94,7 @@ public protocol DatabaseWriter : DatabaseReader { /// // Guaranteed to be zero /// let count = try future.wait() /// } - func concurrentRead(_ block: @escaping (Database) throws -> T) -> Future + func concurrentRead(_ block: @escaping (Database) throws -> T) -> DatabaseFuture } extension DatabaseWriter { @@ -157,30 +132,30 @@ extension DatabaseWriter { // So we'll drop all database objects one after the other. try writeWithoutTransaction { db in // Prevent foreign keys from messing with drop table statements - let foreignKeysEnabled = try Bool.fetchOne(db, "PRAGMA foreign_keys")! + let foreignKeysEnabled = try Bool.fetchOne(db, sql: "PRAGMA foreign_keys")! if foreignKeysEnabled { - try db.execute("PRAGMA foreign_keys = OFF") + try db.execute(sql: "PRAGMA foreign_keys = OFF") } // Remove all database objects, one after the other do { try db.inTransaction { - while let row = try Row.fetchOne(db, "SELECT type, name FROM sqlite_master WHERE name NOT LIKE 'sqlite_%'") { + while let row = try Row.fetchOne(db, sql: "SELECT type, name FROM sqlite_master WHERE name NOT LIKE 'sqlite_%'") { let type: String = row["type"] let name: String = row["name"] - try db.execute("DROP \(type) \(name.quotedDatabaseIdentifier)") + try db.execute(sql: "DROP \(type) \(name.quotedDatabaseIdentifier)") } return .commit } // Restore foreign keys if needed if foreignKeysEnabled { - try db.execute("PRAGMA foreign_keys = ON") + try db.execute(sql: "PRAGMA foreign_keys = ON") } } catch { // Restore foreign keys if needed if foreignKeysEnabled { - try? db.execute("PRAGMA foreign_keys = ON") + try? db.execute(sql: "PRAGMA foreign_keys = ON") } throw error } @@ -197,7 +172,7 @@ extension DatabaseWriter { /// /// See https://www.sqlite.org/lang_vacuum.html for more information. public func vacuum() throws { - try writeWithoutTransaction { try $0.execute("VACUUM") } + try writeWithoutTransaction { try $0.execute(sql: "VACUUM") } } // MARK: - Value Observation @@ -235,7 +210,7 @@ extension DatabaseWriter { DispatchQueue.main.async { onChange(value) } } } - case let .onQueue(queue, startImmediately: startImmediately): + case let .async(onQueue: queue, startImmediately: startImmediately): if startImmediately { if let value = try reducer.initialValue(db, requiresWriteAccess: observation.requiresWriteAccess) { queue.async { onChange(value) } @@ -256,7 +231,7 @@ extension DatabaseWriter { notificationQueue: observation.notificationQueue, onError: onError, onChange: onChange) - db.add(transactionObserver: valueObserver, extent: observation.extent) + db.add(transactionObserver: valueObserver, extent: .observerLifetime) return valueObserver } @@ -281,13 +256,13 @@ extension ValueReducer { extension ValueObservation where Reducer: ValueReducer { /// Helper method for DatabaseWriter.add(observation:onError:onChange:) - fileprivate func fetchAfterChange(in writer: DatabaseWriter) -> (Database, Reducer) -> Future { + fileprivate func fetchAfterChange(in writer: DatabaseWriter) -> (Database, Reducer) -> DatabaseFuture { // The technique to return a future value after database has changed // depends on the requiresWriteAccess flag: if requiresWriteAccess { // Synchronous fetch return { (db, reducer) in - Future(Result { + DatabaseFuture(Result { var fetchedValue: Reducer.Fetched! try db.inTransaction { fetchedValue = try reducer.fetch(db) @@ -305,8 +280,20 @@ extension ValueObservation where Reducer: ValueReducer { } } -/// A future value. -public class Future { +/// A future database value, returned by the DatabaseWriter.concurrentRead(_:) +/// method. +/// +/// let futureCount: Future = try writer.writeWithoutTransaction { db in +/// try Player(...).insert() +/// +/// // Count players concurrently +/// return writer.concurrentRead { db in +/// return try Player.fetchCount() +/// } +/// } +/// +/// let count: Int = try futureCount.wait() +public class DatabaseFuture { private var consumed = false private let _wait: () throws -> Value @@ -315,7 +302,7 @@ public class Future { } init(_ result: Result) { - _wait = { try result.unwrap() } + _wait = result.get } /// Blocks the current thread until the value is available, and returns it. @@ -326,7 +313,7 @@ public class Future { public func wait() throws -> Value { // Not thread-safe and quick and dirty. // Goal is that users learn not to call this method twice. - GRDBPrecondition(consumed == false, "Future.wait() must be called only once") + GRDBPrecondition(consumed == false, "DatabaseFuture.wait() must be called only once") consumed = true return try _wait() } @@ -345,35 +332,29 @@ public final class AnyDatabaseWriter : DatabaseWriter { } // MARK: - Reading from Database - + /// :nodoc: public func read(_ block: (Database) throws -> T) throws -> T { return try base.read(block) } - + /// :nodoc: public func unsafeRead(_ block: (Database) throws -> T) throws -> T { return try base.unsafeRead(block) } - + /// :nodoc: public func unsafeReentrantRead(_ block: (Database) throws -> T) throws -> T { return try base.unsafeReentrantRead(block) } - - /// :nodoc: - @available(*, deprecated, message: "Use concurrentRead instead") - public func readFromCurrentState(_ block: @escaping (Database) -> Void) throws { - try base.readFromCurrentState(block) - } /// :nodoc: - public func concurrentRead(_ block: @escaping (Database) throws -> T) -> Future { + public func concurrentRead(_ block: @escaping (Database) throws -> T) -> DatabaseFuture { return base.concurrentRead(block) } - + // MARK: - Writing in Database - + /// :nodoc: public func write(_ block: (Database) throws -> T) throws -> T { return try base.write(block) @@ -383,7 +364,7 @@ public final class AnyDatabaseWriter : DatabaseWriter { public func writeWithoutTransaction(_ block: (Database) throws -> T) rethrows -> T { return try base.writeWithoutTransaction(block) } - + /// :nodoc: public func unsafeReentrantWrite(_ block: (Database) throws -> T) rethrows -> T { return try base.unsafeReentrantWrite(block) diff --git a/GRDB/Core/FetchRequest.swift b/GRDB/Core/FetchRequest.swift index ede50ec8e..70b3f2170 100644 --- a/GRDB/Core/FetchRequest.swift +++ b/GRDB/Core/FetchRequest.swift @@ -11,13 +11,16 @@ public protocol FetchRequest: DatabaseRegionConvertible { /// The type that tells how fetched database rows should be interpreted. associatedtype RowDecoder - + /// Returns a tuple that contains a prepared statement that is ready to be /// executed, and an eventual row adapter. /// /// - parameter db: A database connection. + /// - parameter singleResult: A hint that the query should return a single + /// result. Implementations can optionally use + /// this to optimize the prepared statement. /// - returns: A prepared statement and an eventual row adapter. - func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) + func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) /// Returns the number of rows fetched by the request. /// @@ -33,6 +36,7 @@ public protocol FetchRequest: DatabaseRegionConvertible { } extension FetchRequest { + /// Returns an adapted request. public func adapted(_ adapter: @escaping (Database) throws -> RowAdapter) -> AdaptedFetchRequest { return AdaptedFetchRequest(self, adapter) @@ -45,9 +49,9 @@ extension FetchRequest { /// /// - parameter db: A database connection. public func fetchCount(_ db: Database) throws -> Int { - let (statement, _) = try prepare(db) + let (statement, _) = try prepare(db, forSingleResult: false) let sql = "SELECT COUNT(*) FROM (\(statement.sql))" - return try Int.fetchOne(db, sql, arguments: statement.arguments)! + return try Int.fetchOne(db, sql: sql, arguments: statement.arguments)! } /// Returns the database region that the request looks into. @@ -57,7 +61,7 @@ extension FetchRequest { /// /// - parameter db: A database connection. public func databaseRegion(_ db: Database) throws -> DatabaseRegion { - let (statement, _) = try prepare(db) + let (statement, _) = try prepare(db, forSingleResult: false) return statement.databaseRegion } } @@ -79,8 +83,8 @@ public struct AdaptedFetchRequest : FetchRequest { } /// :nodoc: - public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) { - let (statement, baseAdapter) = try base.prepare(db) + public func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) { + let (statement, baseAdapter) = try base.prepare(db, forSingleResult: singleResult) if let baseAdapter = baseAdapter { return try (statement, ChainedAdapter(first: baseAdapter, second: adapter(db))) } else { @@ -108,7 +112,7 @@ public struct AdaptedFetchRequest : FetchRequest { public struct AnyFetchRequest : FetchRequest { public typealias RowDecoder = T - private let _prepare: (Database) throws -> (SelectStatement, RowAdapter?) + private let _prepare: (Database, _ singleResult: Bool) throws -> (SelectStatement, RowAdapter?) private let _fetchCount: (Database) throws -> Int private let _databaseRegion: (Database) throws -> DatabaseRegion @@ -121,26 +125,26 @@ public struct AnyFetchRequest : FetchRequest { /// Creates a request whose `prepare()` method wraps and forwards /// operations the argument closure. - public init(_ prepare: @escaping (Database) throws -> (SelectStatement, RowAdapter?)) { - _prepare = { db in - try prepare(db) + public init(_ prepare: @escaping (Database, _ singleResult: Bool) throws -> (SelectStatement, RowAdapter?)) { + _prepare = { db, singleResult in + try prepare(db, singleResult) } _fetchCount = { db in - let (statement, _) = try prepare(db) + let (statement, _) = try prepare(db, false) let sql = "SELECT COUNT(*) FROM (\(statement.sql))" - return try Int.fetchOne(db, sql, arguments: statement.arguments)! + return try Int.fetchOne(db, sql: sql, arguments: statement.arguments)! } _databaseRegion = { db in - let (statement, _) = try prepare(db) + let (statement, _) = try prepare(db, false) return statement.databaseRegion } } /// :nodoc: - public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) { - return try _prepare(db) + public func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) { + return try _prepare(db, singleResult) } /// :nodoc: @@ -153,98 +157,3 @@ public struct AnyFetchRequest : FetchRequest { return try _databaseRegion(db) } } - -// MARK: - SQLRequest - -/// A FetchRequest built from raw SQL. -public struct SQLRequest : FetchRequest { - public typealias RowDecoder = T - - public var sql: String - public var arguments: StatementArguments? - public var adapter: RowAdapter? - private let cache: Cache? - - /// Creates a request from an SQL string, optional arguments, and - /// optional row adapter. - /// - /// let request = SQLRequest("SELECT * FROM player") - /// let request = SQLRequest("SELECT * FROM player WHERE id = ?", arguments: [1]) - /// - /// - parameters: - /// - sql: An SQL query. - /// - arguments: Optional statement arguments. - /// - adapter: Optional RowAdapter. - /// - cached: Defaults to false. If true, the request reuses a cached - /// prepared statement. - /// - returns: A SQLRequest - public init(_ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil, cached: Bool = false) { - self.init(sql, arguments: arguments, adapter: adapter, fromCache: cached ? .public : nil) - } - - /// Creates an SQL request from any other fetch request. - /// - /// - parameters: - /// - db: A database connection. - /// - request: A request. - /// - cached: Defaults to false. If true, the request reuses a cached - /// prepared statement. - /// - returns: An SQLRequest - public init(_ db: Database, request: Request, cached: Bool = false) throws where Request.RowDecoder == RowDecoder { - let (statement, adapter) = try request.prepare(db) - self.init(statement.sql, arguments: statement.arguments, adapter: adapter, cached: cached) - } - - /// Creates an SQL request from an SQL string, optional arguments, and - /// optional row adapter. - /// - /// let request = SQLRequest("SELECT * FROM player") - /// let request = SQLRequest("SELECT * FROM player WHERE id = ?", arguments: [1]) - /// - /// - parameters: - /// - sql: An SQL query. - /// - arguments: Optional statement arguments. - /// - adapter: Optional RowAdapter. - /// - statementCacheName: Optional statement cache name. - /// - returns: A SQLRequest - init(_ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil, fromCache cache: Cache?) { - self.sql = sql - self.arguments = arguments - self.adapter = adapter - self.cache = cache - } - - /// A tuple that contains a prepared statement that is ready to be - /// executed, and an eventual row adapter. - /// - /// - parameter db: A database connection. - /// - /// :nodoc: - public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) { - let statement: SelectStatement - switch cache { - case .none: - statement = try db.makeSelectStatement(sql) - case .public?: - statement = try db.cachedSelectStatement(sql) - case .internal?: - statement = try db.internalCachedSelectStatement(sql) - } - if let arguments = arguments { - try statement.setArgumentsWithValidation(arguments) - } - return (statement, adapter) - } - - /// There are two statement caches: one for statements generated by the - /// user, and one for the statements generated by GRDB. Those are separated - /// so that GRDB has no opportunity to inadvertently modify the arguments of - /// user's cached statements. - enum Cache { - /// The public cache, for library user - case `public` - - /// The internal cache, for grdb - case `internal` - } -} diff --git a/GRDB/Core/Row.swift b/GRDB/Core/Row.swift index 3643918c1..c204fdeee 100644 --- a/GRDB/Core/Row.swift +++ b/GRDB/Core/Row.swift @@ -1,6 +1,8 @@ import Foundation #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -14,22 +16,37 @@ public final class Row : Equatable, Hashable, RandomAccessCollection, Expressibl /// Unless we are producing a row array, we use a single row when iterating /// a statement: /// - /// let rows = try Row.fetchCursor(db, "SELECT ...") - /// let players = try Player.fetchAll(db, "SELECT ...") + /// let rows = try Row.fetchCursor(db, sql: "SELECT ...") + /// let players = try Player.fetchAll(db, sql: "SELECT ...") /// /// This row keeps an unmanaged reference to the statement, and a handle to /// the sqlite statement, so that we avoid many retain/release invocations. /// /// The statementRef is released in deinit. let statementRef: Unmanaged? - let sqliteStatement: SQLiteStatement? + @usableFromInline let sqliteStatement: SQLiteStatement? var statement: SelectStatement? { return statementRef?.takeUnretainedValue() } /// The number of columns in the row. public let count: Int - + + /// A view on the prefetched associated rows. + /// + /// For example: + /// + /// let request = Author.including(all: Author.books) + /// let row = try Row.fetchOne(db, request)! + /// + /// print(row) + /// // Prints [id:1 name:"Herman Melville"] + /// + /// let bookRows = row.prefetchedRows["books"] + /// print(bookRows[0]) + /// // Prints [id:42 title:"Moby-Dick"] + public internal(set) var prefetchedRows: PrefetchedRowsView = PrefetchedRowsView() + // MARK: - Building rows /// Creates an empty row. @@ -140,7 +157,7 @@ extension Row { return index(ofColumn: columnName) != nil } - @inline(__always) + @usableFromInline func index(ofColumn name: String) -> Int? { return impl.index(ofColumn: name) } @@ -151,8 +168,8 @@ extension Row { // MARK: - Extracting Values /// Fatal errors if index is out of bounds - @inline(__always) - private func checkIndex(_ index: Int, file: StaticString = #file, line: UInt = #line) { + @inlinable + func _checkIndex(_ index: Int, file: StaticString = #file, line: UInt = #line) { GRDBPrecondition(index >= 0 && index < count, "row index out of range", file: file, line: line) } @@ -162,10 +179,10 @@ extension Row { /// /// For example: /// - /// let row = try Row.fetchOne(db, "SELECT 'foo', 1")! + /// let row = try Row.fetchOne(db, sql: "SELECT 'foo', 1")! /// row.containsNonNullValue // true /// - /// let row = try Row.fetchOne(db, "SELECT NULL, NULL")! + /// let row = try Row.fetchOne(db, sql: "SELECT NULL, NULL")! /// row.containsNonNullValue // false public var containsNonNullValue: Bool { for i in (0.. Bool { - checkIndex(index) + _checkIndex(index) return impl.hasNull(atUncheckedIndex: index) } @@ -198,7 +215,7 @@ extension Row { /// Indexes span from 0 for the leftmost column to (row.count - 1) for the /// righmost column. public subscript(_ index: Int) -> DatabaseValueConvertible? { - checkIndex(index) + _checkIndex(index) return impl.databaseValue(atUncheckedIndex: index).storage.value } @@ -210,8 +227,9 @@ extension Row { /// If the SQLite value is NULL, the result is nil. Otherwise the SQLite /// value is converted to the requested type `Value`. Should this conversion /// fail, a fatal error is raised. + @inlinable public subscript(_ index: Int) -> Value? { - checkIndex(index) + _checkIndex(index) return Value.decodeIfPresent(from: self, atUncheckedIndex: index) } @@ -227,8 +245,9 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see https://www.sqlite.org/datatype3.html). + @inlinable public subscript(_ index: Int) -> Value? { - checkIndex(index) + _checkIndex(index) return Value.fastDecodeIfPresent(from: self, atUncheckedIndex: index) } @@ -239,8 +258,9 @@ extension Row { /// /// This method crashes if the fetched SQLite value is NULL, or if the /// SQLite value can not be converted to `Value`. + @inlinable public subscript(_ index: Int) -> Value { - checkIndex(index) + _checkIndex(index) return Value.decode(from: self, atUncheckedIndex: index) } @@ -255,8 +275,9 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see https://www.sqlite.org/datatype3.html). + @inlinable public subscript(_ index: Int) -> Value { - checkIndex(index) + _checkIndex(index) return Value.fastDecode(from: self, atUncheckedIndex: index) } @@ -289,6 +310,7 @@ extension Row { /// If the column is missing or if the SQLite value is NULL, the result is /// nil. Otherwise the SQLite value is converted to the requested type /// `Value`. Should this conversion fail, a fatal error is raised. + @inlinable public subscript(_ columnName: String) -> Value? { guard let index = index(ofColumn: columnName) else { return nil @@ -308,6 +330,7 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see https://www.sqlite.org/datatype3.html). + @inlinable public subscript(_ columnName: String) -> Value? { guard let index = index(ofColumn: columnName) else { return nil @@ -324,13 +347,11 @@ extension Row { /// /// This method crashes if the fetched SQLite value is NULL, or if the /// SQLite value can not be converted to `Value`. + @inlinable public subscript(_ columnName: String) -> Value { guard let index = index(ofColumn: columnName) else { // No such column - fatalConversionError( - to: Value.self, - from: nil, - conversionContext: ValueConversionContext(self).atColumn(columnName)) + fatalConversionError(to: Value.self, from: nil, in: self, atColumn: columnName) } return Value.decode(from: self, atUncheckedIndex: index) } @@ -348,13 +369,11 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see https://www.sqlite.org/datatype3.html). + @inlinable public subscript(_ columnName: String) -> Value { guard let index = index(ofColumn: columnName) else { // No such column - fatalConversionError( - to: Value.self, - from: nil, - conversionContext: ValueConversionContext(self).atColumn(columnName)) + fatalConversionError(to: Value.self, from: nil, in: self, atColumn: columnName) } return Value.fastDecode(from: self, atUncheckedIndex: index) } @@ -366,7 +385,8 @@ extension Row { /// the same name, the leftmost column is considered. /// /// The result is nil if the row does not contain the column. - public subscript(_ column: ColumnExpression) -> DatabaseValueConvertible? { + @inlinable + public subscript(_ column: Column) -> DatabaseValueConvertible? { return self[column.name] } @@ -378,7 +398,8 @@ extension Row { /// If the column is missing or if the SQLite value is NULL, the result is /// nil. Otherwise the SQLite value is converted to the requested type /// `Value`. Should this conversion fail, a fatal error is raised. - public subscript(_ column: ColumnExpression) -> Value? { + @inlinable + public subscript(_ column: Column) -> Value? { return self[column.name] } @@ -394,7 +415,8 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see https://www.sqlite.org/datatype3.html). - public subscript(_ column: ColumnExpression) -> Value? { + @inlinable + public subscript(_ column: Column) -> Value? { return self[column.name] } @@ -407,7 +429,8 @@ extension Row { /// /// This method crashes if the fetched SQLite value is NULL, or if the /// SQLite value can not be converted to `Value`. - public subscript(_ column: ColumnExpression) -> Value { + @inlinable + public subscript(_ column: Column) -> Value { return self[column.name] } @@ -424,7 +447,8 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see https://www.sqlite.org/datatype3.html). - public subscript(_ column: ColumnExpression) -> Value { + @inlinable + public subscript(_ column: Column) -> Value { return self[column.name] } @@ -439,7 +463,7 @@ extension Row { /// The returned data does not owns its bytes: it must not be used longer /// than the row's lifetime. public func dataNoCopy(atIndex index: Int) -> Data? { - checkIndex(index) + _checkIndex(index) return impl.dataNoCopy(atUncheckedIndex: index) } @@ -472,7 +496,7 @@ extension Row { /// /// The returned data does not owns its bytes: it must not be used longer /// than the row's lifetime. - public func dataNoCopy(_ column: ColumnExpression) -> Data? { + public func dataNoCopy(_ column: Column) -> Data? { return dataNoCopy(named: column.name) } } @@ -494,26 +518,82 @@ extension Row { // MARK: - Extracting Records - /// Returns the record encoded in the given scope. + /// Returns the record associated with the given scope. /// - /// A fatal error is raised in the row was not fetched with a row adapter - /// that defines this scope. + /// For example: + /// + /// let request = Book.including(required: Book.author) + /// let row = try Row.fetchOne(db, request)! + /// + /// print(Book(row: row).title) + /// // Prints "Moby-Dick" + /// + /// let author: Author = row["author"] + /// print(author.name) + /// // Prints "Herman Melville" + /// + /// Associated records stored in nested associations are available, too: + /// + /// let request = Book.including(required: Book.author.including(required: Author.country)) + /// let row = try Row.fetchOne(db, request)! + /// + /// print(Book(row: row).title) + /// // Prints "Moby-Dick" + /// + /// let country: Country = row["country"] + /// print(country.name) + /// // Prints "United States" + /// + /// A fatal error is raised if the scope is not available, or contains only + /// null values. /// /// See https://github.com/groue/GRDB.swift/blob/master/README.md#joined-queries-support /// for more information. public subscript(_ scope: String) -> Record { guard let scopedRow = scopesTree[scope] else { // Programmer error - fatalError("no such scope: \(scope)") + let names = scopesTree.names + if names.isEmpty { + fatalError("missing scope `\(scope)` (row: \(self))") + } else { + fatalError("missing scope `\(scope)` (row: \(self), available scopes: \(names.sorted()))") + } + } + guard scopedRow.containsNonNullValue else { + // Programmer error + fatalError("scope `\(scope)` only contains null values (row: \(self))") } return Record(row: scopedRow) } - /// Returns the record encoded in the given scope, if and only if the scope - /// has been defined by a row adapter, and the scoped row contains a - /// non-null value. Otherwise, return nil. + /// Returns the eventual record associated with the given scope. /// - /// This subscript is designed to handle left joined records. + /// For example: + /// + /// let request = Book.including(optional: Book.author) + /// let row = try Row.fetchOne(db, request)! + /// + /// print(Book(row: row).title) + /// // Prints "Moby-Dick" + /// + /// let author: Author? = row["author"] + /// print(author.name) + /// // Prints "Herman Melville" + /// + /// Associated records stored in nested associations are available, too: + /// + /// let request = Book.including(optional: Book.author.including(optional: Author.country)) + /// let row = try Row.fetchOne(db, request)! + /// + /// print(Book(row: row).title) + /// // Prints "Moby-Dick" + /// + /// let country: Country? = row["country"] + /// print(country.name) + /// // Prints "United States" + /// + /// Nil is returned if the scope is not available, or contains only + /// null values. /// /// See https://github.com/groue/GRDB.swift/blob/master/README.md#joined-queries-support /// for more information. @@ -523,6 +603,72 @@ extension Row { } return Record(row: scopedRow) } + + /// Returns the records encoded in the given prefetched rows. + /// + /// For example: + /// + /// let request = Author.including(all: Author.books) + /// let row = try Row.fetchOne(db, request)! + /// + /// print(Author(row: row).name) + /// // Prints "Herman Melville" + /// + /// let books: [Book] = row["books"] + /// print(books[0].title) + /// // Prints "Moby-Dick" + public subscript(_ key: String) + -> Collection + where + Collection: RangeReplaceableCollection, + Collection.Element: FetchableRecord + { + guard let rows = prefetchedRows[key] else { + // Programmer error + let keys = prefetchedRows.keys + if keys.isEmpty { + fatalError("missing key for prefetched rows `\(key)` (row: \(self))") + } else { + fatalError("missing key for prefetched rows `\(key)` (row: \(self), available keys: \(keys.sorted()))") + } + } + var collection = Collection() + collection.reserveCapacity(rows.count) + for row in rows { + collection.append(Collection.Element(row: row)) + } + return collection + } + + /// Returns the set of records encoded in the given prefetched rows. + /// + /// For example: + /// + /// let request = Author.including(all: Author.books) + /// let row = try Row.fetchOne(db, request)! + /// + /// print(Author(row: row).name) + /// // Prints "Herman Melville" + /// + /// let books: Set = row["books"] + /// print(books.first!.title) + /// // Prints "Moby-Dick" + public subscript(_ key: String) -> Set { + guard let rows = prefetchedRows[key] else { + // Programmer error + let keys = prefetchedRows.keys + if keys.isEmpty { + fatalError("missing key for prefetched rows `\(key)` (row: \(self))") + } else { + fatalError("missing key for prefetched rows `\(key)` (row: \(self), available keys: \(keys.sorted()))") + } + } + var set = Set(minimumCapacity: rows.count) + for row in rows { + set.insert(Record(row: row)) + } + return set + } } extension Row { @@ -541,7 +687,7 @@ extension Row { /// /// // Fetch /// let sql = "SELECT 1 AS foo, 2 AS bar, 3 AS baz" - /// let row = try Row.fetchOne(db, sql, adapter: adapter)! + /// let row = try Row.fetchOne(db, sql: sql, adapter: adapter)! /// /// row.scopes.count // 2 /// row.scopes.names // ["foo", "bar"] @@ -550,7 +696,7 @@ extension Row { /// row.scopes["bar"] // [bar:2] /// row.scopes["baz"] // nil public var scopes: ScopesView { - return impl.scopes + return impl.scopes(prefetchedRows: prefetchedRows) } /// Returns a view on the scopes tree defined by row adapters. @@ -565,7 +711,7 @@ extension Row { /// /// // Fetch /// let sql = "SELECT 1 AS foo, 2 AS bar, 3 AS baz" - /// let row = try Row.fetchOne(db, sql, adapter: adapter)! + /// let row = try Row.fetchOne(db, sql: sql, adapter: adapter)! /// /// row.scopesTree.names // ["foo", "bar", "baz"] /// @@ -587,7 +733,16 @@ extension Row { /// // Success: /// XCTAssertEqual(row.unscoped, ["id": 1, "name": "foo"]) public var unscoped: Row { - return impl.unscopedRow(self) + var row = impl.unscopedRow(self) + + // Remove prefetchedRows + if row.prefetchedRows.isEmpty == false { + // Make sure we build another Row instance + row = Row(impl: row.copy().impl) + assert(row !== self) + assert(row.prefetchedRows.isEmpty) + } + return row } /// Return the raw row fetched from the database. @@ -599,21 +754,23 @@ extension Row { } } +// MARK: - RowCursor + /// A cursor of database rows. For example: /// /// try dbQueue.read { db in -/// let rows: RowCursor = try Row.fetchCursor(db, "SELECT * FROM player") +/// let rows: RowCursor = try Row.fetchCursor(db, sql: "SELECT * FROM player") /// } public final class RowCursor : Cursor { public let statement: SelectStatement - private let sqliteStatement: SQLiteStatement - private let row: Row // Reused for performance - private var done = false + @usableFromInline let _sqliteStatement: SQLiteStatement + @usableFromInline let _row: Row // Reused for performance + @usableFromInline var _done = false init(statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { self.statement = statement - self.row = try Row(statement: statement).adapted(with: adapter, layout: statement) - self.sqliteStatement = statement.sqliteStatement + self._row = try Row(statement: statement).adapted(with: adapter, layout: statement) + self._sqliteStatement = statement.sqliteStatement statement.reset(withArguments: arguments) } @@ -624,21 +781,21 @@ public final class RowCursor : Cursor { } /// :nodoc: + @inlinable public func next() throws -> Row? { - if done { + if _done { // make sure this instance never yields a value again, even if the // statement is reset by another cursor. return nil } - switch sqlite3_step(sqliteStatement) { + switch sqlite3_step(_sqliteStatement) { case SQLITE_DONE: - done = true + _done = true return nil case SQLITE_ROW: - return row + return _row case let code: - statement.database.selectStatementDidFail(statement) - throw DatabaseError(resultCode: code, message: statement.database.lastErrorMessage, sql: statement.sql, arguments: statement.arguments) + try statement.didFail(withResultCode: code) } } } @@ -649,7 +806,7 @@ extension Row { /// Returns a cursor over rows fetched from a prepared statement. /// - /// let statement = try db.makeSelectStatement("SELECT ...") + /// let statement = try db.makeSelectStatement(sql: "SELECT ...") /// let rows = try Row.fetchCursor(statement) // RowCursor /// while let row = try rows.next() { // Row /// let id: Int64 = row[0] @@ -682,7 +839,7 @@ extension Row { /// Returns an array of rows fetched from a prepared statement. /// - /// let statement = try db.makeSelectStatement("SELECT ...") + /// let statement = try db.makeSelectStatement(sql: "SELECT ...") /// let rows = try Row.fetchAll(statement) /// /// - parameters: @@ -698,7 +855,7 @@ extension Row { /// Returns a single row fetched from a prepared statement. /// - /// let statement = try db.makeSelectStatement("SELECT ...") + /// let statement = try db.makeSelectStatement(sql: "SELECT ...") /// let row = try Row.fetchOne(statement) /// /// - parameters: @@ -722,7 +879,7 @@ extension Row { /// Returns a cursor over rows fetched from an SQL query. /// - /// let rows = try Row.fetchCursor(db, "SELECT id, name FROM player") // RowCursor + /// let rows = try Row.fetchCursor(db, sql: "SELECT id, name FROM player") // RowCursor /// while let row = try rows.next() { // Row /// let id: Int64 = row[0] /// let name: String = row[1] @@ -744,42 +901,50 @@ extension Row { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched rows. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RowCursor { - return try fetchCursor(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + public static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> RowCursor { + return try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns an array of rows fetched from an SQL query. /// - /// let rows = try Row.fetchAll(db, "SELECT ...") + /// let rows = try Row.fetchAll(db, sql: "SELECT id, name FROM player") // [Row] + /// for row in rows { + /// let id: Int64 = row[0] + /// let name: String = row[1] + /// } /// /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An array of rows. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Row] { - return try fetchAll(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + public static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Row] { + return try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns a single row fetched from an SQL query. /// - /// let row = try Row.fetchOne(db, "SELECT ...") + /// let row = try Row.fetchOne(db, sql: "SELECT id, name FROM player") // Row? + /// if let row = row { + /// let id: Int64 = row[0] + /// let name: String = row[1] + /// } /// /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An optional row. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Row? { - return try fetchOne(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + public static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Row? { + return try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } @@ -815,7 +980,7 @@ extension Row { /// - returns: A cursor over fetched rows. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. public static func fetchCursor(_ db: Database, _ request: R) throws -> RowCursor { - let (statement, adapter) = try request.prepare(db) + let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchCursor(statement, adapter: adapter) } @@ -830,7 +995,7 @@ extension Row { /// - returns: An array of rows. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. public static func fetchAll(_ db: Database, _ request: R) throws -> [Row] { - let (statement, adapter) = try request.prepare(db) + let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchAll(statement, adapter: adapter) } @@ -845,18 +1010,18 @@ extension Row { /// - returns: An optional row. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. public static func fetchOne(_ db: Database, _ request: R) throws -> Row? { - let (statement, adapter) = try request.prepare(db) + let (statement, adapter) = try request.prepare(db, forSingleResult: true) return try fetchOne(statement, adapter: adapter) } } -extension FetchRequest where RowDecoder: Row { +extension FetchRequest where RowDecoder == Row { // MARK: Fetching Rows /// A cursor over fetched rows. /// - /// let request: ... // Some TypedRequest that fetches Row + /// let request: ... // Some FetchRequest that fetches Row /// let rows = try request.fetchCursor(db) // RowCursor /// while let row = try rows.next() { // Row /// let id: Int64 = row[0] @@ -885,7 +1050,7 @@ extension FetchRequest where RowDecoder: Row { /// An array of fetched rows. /// - /// let request: ... // Some TypedRequest that fetches Row + /// let request: ... // Some FetchRequest that fetches Row /// let rows = try request.fetchAll(db) /// /// - parameter db: A database connection. @@ -897,11 +1062,11 @@ extension FetchRequest where RowDecoder: Row { /// The first fetched row. /// - /// let request: ... // Some TypedRequest that fetches Row + /// let request: ... // Some FetchRequest that fetches Row /// let row = try request.fetchOne(db) /// /// - parameter db: A database connection. - /// - returns: A,n optional rows. + /// - returns: An optional row. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. public func fetchOne(_ db: Database) throws -> Row? { return try Row.fetchOne(db, self) @@ -943,7 +1108,7 @@ extension Row { /// Accesses the (ColumnName, DatabaseValue) pair at given index. public subscript(position: RowIndex) -> (String, DatabaseValue) { let index = position.index - checkIndex(index) + _checkIndex(index) return ( impl.columnName(atUncheckedIndex: index), impl.databaseValue(atUncheckedIndex: index)) @@ -988,13 +1153,16 @@ extension Row { } } + guard lhs.prefetchedRows == rhs.prefetchedRows else { + return false + } + return true } } // Hashable extension Row { - #if swift(>=4.2) /// :nodoc: public func hash(into hasher: inout Hasher) { hasher.combine(count) @@ -1003,13 +1171,6 @@ extension Row { hasher.combine(dbValue) } } - #else - /// :nodoc: - public var hashValue: Int { - return columnNames.reduce(0) { (acc, column) in acc ^ column.hashValue } ^ - databaseValues.reduce(0) { (acc, dbValue) in acc ^ dbValue.hashValue } - } - #endif } // CustomStringConvertible & CustomDebugStringConvertible @@ -1027,7 +1188,7 @@ extension Row { } private func debugDescription(level: Int) -> String { - if level == 0 && self == self.unadapted { + if level == 0 && self == self.unadapted && prefetchedRows.prefetches.isEmpty { return description } let prefix = repeatElement(" ", count: level + 1).joined(separator: "") @@ -1044,6 +1205,19 @@ extension Row { for (name, scopedRow) in scopes.sorted(by: { $0.name < $1.name }) { str += "\n" + prefix + "- " + name + ": " + scopedRow.debugDescription(level: level + 1) } + for key in prefetchedRows.keys.sorted() { + let rows = prefetchedRows[key]! + let prefetchedRowsDescription: String + switch rows.count { + case 0: + prefetchedRowsDescription = "0 row" + case 1: + prefetchedRowsDescription = "1 row" + case let count: + prefetchedRowsDescription = "\(count) rows" + } + str += "\n" + prefix + "+ " + key + ": \(prefetchedRowsDescription)" + } return str } @@ -1101,7 +1275,7 @@ extension Row { /// /// // Fetch /// let sql = "SELECT 1 AS foo, 2 AS bar, 3 AS baz" - /// let row = try Row.fetchOne(db, sql, adapter: adapter)! + /// let row = try Row.fetchOne(db, sql: sql, adapter: adapter)! /// /// row.scopes.count // 2 /// row.scopes.names // ["foo", "bar"] @@ -1113,6 +1287,7 @@ extension Row { public typealias Index = Dictionary.Index private let row: Row private let scopes: [String: LayoutedRowAdapter] + private let prefetchedRows: Row.PrefetchedRowsView /// The scopes defined on this row. public var names: Dictionary.Keys { @@ -1120,12 +1295,13 @@ extension Row { } init() { - self.init(row: Row(), scopes: [:]) + self.init(row: Row(), scopes: [:], prefetchedRows: Row.PrefetchedRowsView()) } - init(row: Row, scopes: [String: LayoutedRowAdapter]) { + init(row: Row, scopes: [String: LayoutedRowAdapter], prefetchedRows: Row.PrefetchedRowsView) { self.row = row self.scopes = scopes + self.prefetchedRows = prefetchedRows } /// :nodoc: @@ -1146,16 +1322,24 @@ extension Row { /// :nodoc: public subscript(position: Index) -> (name: String, row: Row) { let (name, adapter) = scopes[position] - return (name: name, row: Row(base: row, adapter: adapter)) + let adaptedRow = Row(base: row, adapter: adapter) + if let prefetch = prefetchedRows.prefetches[name] { + // Let the adapted row access its own prefetched rows. + // Use case: + // + // let request = A.including(required: A.b.including(all: B.c)) + // let row = try Row.fetchOne(db, request)! + // row.prefetchedRows["cs"] // Some array + // row.scopes["b"]!.prefetchedRows["cs"] // The same array + adaptedRow.prefetchedRows = Row.PrefetchedRowsView(prefetches: prefetch.prefetches) + } + return (name: name, row: adaptedRow) } /// Returns the row associated with the given scope, or nil if the /// scope is not defined. public subscript(_ name: String) -> Row? { - guard let adapter = scopes[name] else { - return nil - } - return Row(base: row, adapter: adapter) + return scopes.index(forKey: name).map { self[$0].row } } } } @@ -1176,7 +1360,7 @@ extension Row { /// /// // Fetch /// let sql = "SELECT 1 AS foo, 2 AS bar, 3 AS baz" - /// let row = try Row.fetchOne(db, sql, adapter: adapter)! + /// let row = try Row.fetchOne(db, sql: sql, adapter: adapter)! /// /// row.scopesTree.names // ["foo", "bar", "baz"] /// @@ -1196,9 +1380,33 @@ extension Row { return names } - /// Returns the row associated with the given scope, by performing a - /// breadth-first search in this row's scopes and the scopes of its - /// scoped rows, recursively. + /// Returns the row associated with the given scope. + /// + /// For example: + /// + /// let request = Book.including(required: Book.author) + /// let row = try Row.fetchOne(db, request)! + /// + /// print(row) + /// // Prints [id:42 title:"Moby-Dick"] + /// + /// let authorRow = row.scopesTree["author"] + /// print(authorRow) + /// // Prints [id:1 name:"Herman Melville"] + /// + /// Associated rows stored in nested associations are available, too: + /// + /// let request = Book.including(required: Book.author.including(required: Author.country)) + /// let row = try Row.fetchOne(db, request)! + /// + /// print(row) + /// // Prints [id:42 title:"Moby-Dick"] + /// + /// let countryRow = row.scopesTree["country"] + /// print(countryRow) + /// // Prints [code:"US" name:"United States"] + /// + /// Nil is returned if the scope is not available. public subscript(_ name: String) -> Row? { var fifo = Array(scopes) while !fifo.isEmpty { @@ -1213,13 +1421,117 @@ extension Row { } } +// MARK: - Row.PrefetchedRowsView + +extension Row { + fileprivate struct Prefetch: Equatable { + // Nil for intermediate associations + var rows: [Row]? + // OrderedDictionary so that breadth-first search gives a consistent result + // (we preserve the ordering of associations in the request) + var prefetches: OrderedDictionary + } + + /// A view on the prefetched associated rows. + /// + /// For example: + /// + /// let request = Author.including(all: Author.books) + /// let row = try Row.fetchOne(db, request)! + /// + /// print(row) + /// // Prints [id:1 name:"Herman Melville"] + /// + /// let bookRows = row.prefetchedRows["books"] + /// print(bookRows[0]) + /// // Prints [id:42 title:"Moby-Dick"] + public struct PrefetchedRowsView: Equatable { + // OrderedDictionary so that breadth-first search gives a consistent result + // (we preserve the ordering of associations in the request) + fileprivate var prefetches: OrderedDictionary = [:] + + /// True if there is no prefetched associated rows. + public var isEmpty: Bool { + return prefetches.isEmpty + } + + /// The keys for available prefetched rows + /// + /// For example: + /// + /// let request = Author.including(all: Author.books) + /// let row = try Row.fetchOne(db, request)! + /// + /// print(row.prefetchedRows.keys) + /// // Prints ["books"] + public var keys: Set { + var result: Set = [] + var fifo = Array(prefetches) + while !fifo.isEmpty { + let (prefetchKey, prefetch) = fifo.removeFirst() + if prefetch.rows != nil { + result.insert(prefetchKey) + } + fifo.append(contentsOf: prefetch.prefetches) + } + return result + } + + /// Returns the prefetched rows associated with the given key. + /// + /// For example: + /// + /// let request = Author.including(all: Author.books) + /// let row = try Row.fetchOne(db, request)! + /// + /// print(row) + /// // Prints [id:1 name:"Herman Melville"] + /// + /// let bookRows = row.prefetchedRows["books"] + /// print(bookRows[0]) + /// // Prints [id:42 title:"Moby-Dick"] + /// + /// Prefetched rows stored in nested "to-one" associations are + /// available, too. + /// + /// Nil is returned if the key is not available. + public subscript(_ key: String) -> [Row]? { + var fifo = Array(prefetches) + while !fifo.isEmpty { + let (prefetchKey, prefetch) = fifo.removeFirst() + if prefetchKey == key { + return prefetch.rows + } + fifo.append(contentsOf: prefetch.prefetches) + } + return nil + } + + mutating func setRows(_ rows: [Row], forKeyPath keyPath: [String]) { + prefetches.setRows(rows, forKeyPath: keyPath) + } + } +} + +extension OrderedDictionary where Key == String, Value == Row.Prefetch { + fileprivate mutating func setRows(_ rows: [Row], forKeyPath keyPath: [String]) { + var keyPath = keyPath + let key = keyPath.removeFirst() + if keyPath.isEmpty { + self[key, default: Row.Prefetch(rows: nil, prefetches: [:])].rows = rows + } else { + self[key, default: Row.Prefetch(rows: nil, prefetches: [:])].prefetches.setRows(rows, forKeyPath: keyPath) + } + } +} + // MARK: - RowImpl // The protocol for Row underlying implementation protocol RowImpl { var count: Int { get } var isFetched: Bool { get } - var scopes: Row.ScopesView { get } + func scopes(prefetchedRows: Row.PrefetchedRowsView) -> Row.ScopesView func columnName(atUncheckedIndex index: Int) -> String func hasNull(atUncheckedIndex index:Int) -> Bool func databaseValue(atUncheckedIndex index: Int) -> DatabaseValue @@ -1252,7 +1564,7 @@ extension RowImpl { return row } - var scopes: Row.ScopesView { + func scopes(prefetchedRows: Row.PrefetchedRowsView) -> Row.ScopesView { // unless customized, assume unuscoped row (see AdaptedRowImpl for customization) return Row.ScopesView() } @@ -1317,7 +1629,7 @@ private struct ArrayRowImpl : RowImpl { func index(ofColumn name: String) -> Int? { let lowercaseName = name.lowercased() - return columns.index { (column, _) in column.lowercased() == lowercaseName } + return columns.firstIndex { (column, _) in column.lowercased() == lowercaseName } } func copiedRow(_ row: Row) -> Row { @@ -1356,7 +1668,7 @@ private struct StatementCopyRowImpl : RowImpl { func index(ofColumn name: String) -> Int? { let lowercaseName = name.lowercased() - return columnNames.index { $0.lowercased() == lowercaseName } + return columnNames.firstIndex { $0.lowercased() == lowercaseName } } func copiedRow(_ row: Row) -> Row { @@ -1415,7 +1727,7 @@ private struct StatementRowImpl : RowImpl { _ type: Value.Type, atUncheckedIndex index: Int) -> Value { - return Value.fastDecode(from: sqliteStatement, index: Int32(index)) + return Value.fastDecode(from: sqliteStatement, atUncheckedIndex: Int32(index)) } func fastDecodeIfPresent( diff --git a/GRDB/Core/RowAdapter.swift b/GRDB/Core/RowAdapter.swift index fea2549ed..b9ab95c8c 100644 --- a/GRDB/Core/RowAdapter.swift +++ b/GRDB/Core/RowAdapter.swift @@ -13,7 +13,7 @@ import Foundation /// "b": adapters[1], /// "c": adapters[2], /// "d": adapters[3]]) -/// let row = try Row.fetchOne(db, sql, adapter: adapter) +/// let row = try Row.fetchOne(db, sql: sql, adapter: adapter) /// row.scopes["a"] // [1] /// row.scopes["b"] // [2, 3, 4] /// row.scopes["c"] // [5, 6] @@ -78,7 +78,7 @@ public struct LayoutedColumnMapping { /// } /// /// // [foo:"foo" bar: "bar"] - /// try Row.fetchOne(db, "SELECT NULL, 'foo', 'bar'", adapter: FooBarAdapter()) + /// try Row.fetchOne(db, sql: "SELECT NULL, 'foo', 'bar'", adapter: FooBarAdapter()) public init(layoutColumns: S) where S.Iterator.Element == (Int, String) { self.layoutColumns = Array(layoutColumns) self.lowercaseColumnIndexes = Dictionary( @@ -201,7 +201,7 @@ extension SelectStatement : RowLayout { /// let sql = "SELECT 1 AS foo, 2 AS bar, 3 AS baz" /// /// // [baz:3] -/// try Row.fetchOne(db, sql, adapter: adapter) +/// try Row.fetchOne(db, sql: sql, adapter: adapter) public protocol RowAdapter { /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) @@ -224,7 +224,7 @@ public protocol RowAdapter { /// } /// /// // [foo:1] - /// try Row.fetchOne(db, "SELECT 1, 2, 3", adapter: FirstColumnAdapter()) + /// try Row.fetchOne(db, sql: "SELECT 1, 2, 3", adapter: FirstColumnAdapter()) func layoutedAdapter(from layout: RowLayout) throws -> LayoutedRowAdapter } @@ -269,7 +269,7 @@ public struct EmptyRowAdapter: RowAdapter { /// let sql = "SELECT 'foo' AS foo, 'bar' AS bar, 'baz' AS baz" /// /// // [foo:"bar"] -/// try Row.fetchOne(db, sql, adapter: adapter) +/// try Row.fetchOne(db, sql: sql, adapter: adapter) public struct ColumnMapping : RowAdapter { /// A dictionary from mapped column names to column names in a base row. let mapping: [String: String] @@ -303,7 +303,7 @@ public struct ColumnMapping : RowAdapter { /// let sql = "SELECT 1 AS foo, 2 AS bar, 3 AS baz" /// /// // [baz:3] -/// try Row.fetchOne(db, sql, adapter: adapter) +/// try Row.fetchOne(db, sql: sql, adapter: adapter) public struct SuffixRowAdapter : RowAdapter { /// The suffix index let index: Int @@ -330,7 +330,7 @@ public struct SuffixRowAdapter : RowAdapter { /// let sql = "SELECT 1 AS foo, 2 AS bar, 3 AS baz, 4 as qux" /// /// // [bar:2 baz:3] -/// try Row.fetchOne(db, sql, adapter: adapter) +/// try Row.fetchOne(db, sql: sql, adapter: adapter) public struct RangeRowAdapter : RowAdapter { /// The range let range: CountableRange @@ -367,7 +367,7 @@ public struct RangeRowAdapter : RowAdapter { /// /// // Fetch /// let sql = "SELECT 'foo' AS foo, 'bar' AS bar" -/// let row = try Row.fetchOne(db, sql, adapter: adapter)! +/// let row = try Row.fetchOne(db, sql: sql, adapter: adapter)! /// /// // Scoped rows: /// if let fooRow = row.scopes["foo"] { @@ -389,7 +389,7 @@ public struct ScopeAdapter : RowAdapter { /// For example: /// /// let adapter = ScopeAdapter(["suffix": SuffixRowAdapter(fromIndex: 1)]) - /// let row = try Row.fetchOne(db, "SELECT 1, 2, 3", adapter: adapter)! + /// let row = try Row.fetchOne(db, sql: "SELECT 1, 2, 3", adapter: adapter)! /// row // [1, 2, 3] /// row.scopes["suffix"] // [2, 3] /// @@ -406,7 +406,7 @@ public struct ScopeAdapter : RowAdapter { /// /// let baseAdapter = RangeRowAdapter(0..<1) /// let adapter = ScopeAdapter(base: baseAdapter, scopes: ["suffix": SuffixRowAdapter(fromIndex: 1)]) - /// let row = try Row.fetchOne(db, "SELECT 1, 2, 3", adapter: adapter)! + /// let row = try Row.fetchOne(db, sql: "SELECT 1, 2, 3", adapter: adapter)! /// row // [1] /// row.scopes["initial"] // [2, 3] /// @@ -487,8 +487,8 @@ struct AdaptedRowImpl : RowImpl { return base.isFetched } - var scopes: Row.ScopesView { - return Row.ScopesView(row: base, scopes: adapter.scopes) + func scopes(prefetchedRows: Row.PrefetchedRowsView) -> Row.ScopesView { + return Row.ScopesView(row: base, scopes: adapter.scopes, prefetchedRows: prefetchedRows) } func hasNull(atUncheckedIndex index: Int) -> Bool { diff --git a/GRDB/Core/SQLInterpolation.swift b/GRDB/Core/SQLInterpolation.swift new file mode 100644 index 000000000..49bc2b3b0 --- /dev/null +++ b/GRDB/Core/SQLInterpolation.swift @@ -0,0 +1,33 @@ +#if swift(>=5.0) +/// :nodoc: +public struct SQLInterpolation: StringInterpolationProtocol { + var context = SQLGenerationContext.literalGenerationContext(withArguments: true) + var sql: String + var arguments: StatementArguments { + get { return context.arguments! } + set { context.arguments = newValue } + } + + public init(literalCapacity: Int, interpolationCount: Int) { + sql = "" + sql.reserveCapacity(literalCapacity + interpolationCount) + } + + /// "SELECT * FROM player" + public mutating func appendLiteral(_ sql: String) { + self.sql += sql + } + + /// "SELECT * FROM \(sql: "player")" + public mutating func appendInterpolation(sql: String, arguments: StatementArguments = StatementArguments()) { + self.sql += sql + self.arguments += arguments + } + + /// "SELECT * FROM player WHERE \(literal: condition)" + public mutating func appendInterpolation(literal sqlLiteral: SQLLiteral) { + sql += sqlLiteral.sql + arguments += sqlLiteral.arguments + } +} +#endif diff --git a/GRDB/Core/SQLLiteral.swift b/GRDB/Core/SQLLiteral.swift new file mode 100644 index 000000000..e95e58b88 --- /dev/null +++ b/GRDB/Core/SQLLiteral.swift @@ -0,0 +1,145 @@ +/// SQLLiteral is a type which support [SQL Interpolation](https://github.com/groue/GRDB.swift/blob/master/Documentation/SQLInterpolation.md). +/// +/// For example: +/// +/// try dbQueue.write { db in +/// let name: String = ... +/// let id: Int64 = ... +/// let query: SQLLiteral = "UPDATE player SET name = \(name) WHERE id = \(id)" +/// try db.execute(literal: query) +/// } +public struct SQLLiteral { + private(set) public var sql: String + private(set) public var arguments: StatementArguments + + /// Creates an SQLLiteral from a plain SQL string, and eventual arguments. + /// + /// For example: + /// + /// let query = SQLLiteral( + /// sql: "UPDATE player SET name = ? WHERE id = ?", + /// arguments: [name, id]) + public init(sql: String, arguments: StatementArguments = StatementArguments()) { + self.sql = sql + self.arguments = arguments + } + + /// Returns a literal whose SQL is transformed by the given closure. + public func mapSQL(_ transform: (String) throws -> String) rethrows -> SQLLiteral { + var result = self + result.sql = try transform(sql) + return result + } +} + +extension SQLLiteral { + /// Returns the SQLLiteral produced by the concatenation of two literals. + /// + /// let name = "O'Brien" + /// let selection: SQLLiteral = "SELECT * FROM player " + /// let condition: SQLLiteral = "WHERE name = \(name)" + /// let query = selection + condition + public static func + (lhs: SQLLiteral, rhs: SQLLiteral) -> SQLLiteral { + var result = lhs + result += rhs + return result + } + + /// Appends an SQLLiteral to the receiver. + /// + /// let name = "O'Brien" + /// var query: SQLLiteral = "SELECT * FROM player " + /// query += "WHERE name = \(name)" + public static func += (lhs: inout SQLLiteral, rhs: SQLLiteral) { + lhs.sql += rhs.sql + lhs.arguments += rhs.arguments + } + + /// Appends an SQLLiteral to the receiver. + /// + /// let name = "O'Brien" + /// var query: SQLLiteral = "SELECT * FROM player " + /// query.append(literal: "WHERE name = \(name)") + public mutating func append(literal sqlLiteral: SQLLiteral) { + self += sqlLiteral + } + + /// Appends a plain SQL string to the receiver, and eventual arguments. + /// + /// let name = "O'Brien" + /// var query: SQLLiteral = "SELECT * FROM player " + /// query.append(sql: "WHERE name = ?", arguments: [name]) + public mutating func append(sql: String, arguments: StatementArguments = StatementArguments()) { + self += SQLLiteral(sql: sql, arguments: arguments) + } +} + +extension Sequence where Element == SQLLiteral { + /// Returns the concatenated SQLLiteral of this sequence of literals, + /// inserting the given separator between each element. + /// + /// let components: [SQLLiteral] = [ + /// "UPDATE player", + /// "SET name = \(name)", + /// "WHERE id = \(id)" + /// ] + /// let query = components.joined(separator: " ") + public func joined(separator: String = "") -> SQLLiteral { + var sql = "" + var arguments = StatementArguments() + var first = true + for literal in self { + if first { + first = false + } else { + sql += separator + } + sql += literal.sql + arguments += literal.arguments + } + return SQLLiteral(sql: sql, arguments: arguments) + } +} + +extension Collection where Element == SQLLiteral { + /// Returns the concatenated SQLLiteral of this collection of literals, + /// inserting the given separator between each element. + /// + /// let components: [SQLLiteral] = [ + /// "UPDATE player", + /// "SET name = \(name)", + /// "WHERE id = \(id)" + /// ] + /// let query = components.joined(separator: " ") + public func joined(separator: String = "") -> SQLLiteral { + let sql = map { $0.sql }.joined(separator: separator) + let arguments = reduce(into: StatementArguments()) { $0 += $1.arguments } + return SQLLiteral(sql: sql, arguments: arguments) + } +} + +// MARK: - ExpressibleByStringInterpolation + +#if swift(>=5.0) +extension SQLLiteral: ExpressibleByStringInterpolation { + /// :nodoc + public init(unicodeScalarLiteral: String) { + self.init(sql: unicodeScalarLiteral, arguments: []) + } + + /// :nodoc: + public init(extendedGraphemeClusterLiteral: String) { + self.init(sql: extendedGraphemeClusterLiteral, arguments: []) + } + + /// :nodoc: + public init(stringLiteral: String) { + self.init(sql: stringLiteral, arguments: []) + } + + /// :nodoc: + public init(stringInterpolation sqlInterpolation: SQLInterpolation) { + self.init(sql: sqlInterpolation.sql, arguments: sqlInterpolation.arguments) + } +} +#endif diff --git a/GRDB/Core/SQLRequest.swift b/GRDB/Core/SQLRequest.swift new file mode 100644 index 000000000..46efea693 --- /dev/null +++ b/GRDB/Core/SQLRequest.swift @@ -0,0 +1,168 @@ +/// A FetchRequest built from raw SQL. +public struct SQLRequest : FetchRequest { + /// There are two statement caches: one "public" for statements generated by + /// the user, and one "internal" for the statements generated by GRDB. Those + /// are separated so that GRDB has no opportunity to inadvertently modify + /// the arguments of user's cached statements. + enum Cache { + /// The public cache, for library user + case `public` + + /// The internal cache, for GRDB + case `internal` + } + + public typealias RowDecoder = T + + /// The raw SQL query + /// + /// let id = 42 + /// let request: SQLRequest = "SELECT * FROM player WHERE id = \(id)" + /// request.sql // "SELECT * FROM player WHERE id = ?" + public var sql: String { return sqlLiteral.sql } + + /// The request argument + /// + /// let id = 42 + /// let request: SQLRequest = "SELECT * FROM player WHERE id = \(id)" + /// request.arguments // [42] + public var arguments: StatementArguments { return sqlLiteral.arguments } + + /// The request adapter + public var adapter: RowAdapter? + + private var sqlLiteral: SQLLiteral + private let cache: Cache? + + /// Creates a request from an SQL string, optional arguments, and + /// optional row adapter. + /// + /// let request = SQLRequest(sql: """ + /// SELECT name FROM player + /// """) + /// let request = SQLRequest(sql: """ + /// SELECT * FROM player WHERE id = ? + /// """, arguments: [1]) + /// + /// - parameters: + /// - sql: An SQL query. + /// - arguments: Statement arguments. + /// - adapter: Optional RowAdapter. + /// - cached: Defaults to false. If true, the request reuses a cached + /// prepared statement. + /// - returns: A SQLRequest + public init(sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil, cached: Bool = false) { + self.init(literal: SQLLiteral(sql: sql, arguments: arguments), adapter: adapter, fromCache: cached ? .public : nil) + } + + /// Creates a request from an SQLLiteral, and optional row adapter. + /// + /// let request = SQLRequest(literal: SQLLiteral(sql: """ + /// SELECT name FROM player + /// """)) + /// let request = SQLRequest(literal: SQLLiteral(sql: """ + /// SELECT * FROM player WHERE name = ? + /// """, arguments: ["O'Brien"])) + /// + /// With Swift 5, you can safely embed raw values in your SQL queries, + /// without any risk of syntax errors or SQL injection: + /// + /// let request = SQLRequest(literal: """ + /// SELECT * FROM player WHERE name = \("O'brien") + /// """) + /// + /// - parameters: + /// - sqlLiteral: An SQLLiteral. + /// - adapter: Optional RowAdapter. + /// - cached: Defaults to false. If true, the request reuses a cached + /// prepared statement. + /// - returns: A SQLRequest + public init(literal sqlLiteral: SQLLiteral, adapter: RowAdapter? = nil, cached: Bool = false) { + self.init(literal: sqlLiteral, adapter: adapter, fromCache: cached ? .public : nil) + } + + /// Creates an SQL request from any other fetch request. + /// + /// - parameters: + /// - db: A database connection. + /// - request: A request. + /// - cached: Defaults to false. If true, the request reuses a cached + /// prepared statement. + /// - returns: An SQLRequest + public init(_ db: Database, request: Request, cached: Bool = false) throws where Request.RowDecoder == RowDecoder { + let (statement, adapter) = try request.prepare(db, forSingleResult: false) + self.init(literal: SQLLiteral(sql: statement.sql, arguments: statement.arguments), adapter: adapter, cached: cached) + } + + /// Creates a request from an SQLLiteral, and optional row adapter. + /// + /// let request = SQLRequest(literal: SQLLiteral(sql: """ + /// SELECT name FROM player + /// """)) + /// let request = SQLRequest(literal: SQLLiteral(sql: """ + /// SELECT * FROM player WHERE name = ? + /// """, arguments: ["O'Brien"])) + /// + /// With Swift 5, you can safely embed raw values in your SQL queries, + /// without any risk of syntax errors or SQL injection: + /// + /// let request = SQLRequest(literal: """ + /// SELECT * FROM player WHERE name = \("O'brien") + /// """) + /// + /// - parameters: + /// - sqlLiteral: An SQLLiteral. + /// - adapter: Optional RowAdapter. + /// - cache: The eventual cache + /// - returns: A SQLRequest + init(literal sqlLiteral: SQLLiteral, adapter: RowAdapter? = nil, fromCache cache: Cache?) { + self.sqlLiteral = sqlLiteral + self.adapter = adapter + self.cache = cache + } + + /// A tuple that contains a prepared statement that is ready to be + /// executed, and an eventual row adapter. + /// + /// - parameter db: A database connection. + /// - parameter singleResult: SQLRequest disregards this hint. + /// + /// :nodoc: + public func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) { + let statement: SelectStatement + switch cache { + case .none: + statement = try db.makeSelectStatement(sql: sqlLiteral.sql) + case .public?: + statement = try db.cachedSelectStatement(sql: sqlLiteral.sql) + case .internal?: + statement = try db.internalCachedSelectStatement(sql: sqlLiteral.sql) + } + try statement.setArgumentsWithValidation(sqlLiteral.arguments) + return (statement, adapter) + } +} + +#if swift(>=5.0) +extension SQLRequest: ExpressibleByStringInterpolation { + /// :nodoc + public init(unicodeScalarLiteral: String) { + self.init(sql: unicodeScalarLiteral) + } + + /// :nodoc: + public init(extendedGraphemeClusterLiteral: String) { + self.init(sql: extendedGraphemeClusterLiteral) + } + + /// :nodoc: + public init(stringLiteral: String) { + self.init(sql: stringLiteral) + } + + /// :nodoc: + public init(stringInterpolation sqlInterpolation: SQLInterpolation) { + self.init(literal: SQLLiteral(stringInterpolation: sqlInterpolation)) + } +} +#endif diff --git a/GRDB/Core/SchedulingWatchdog.swift b/GRDB/Core/SchedulingWatchdog.swift index 165abfb05..93318631b 100644 --- a/GRDB/Core/SchedulingWatchdog.swift +++ b/GRDB/Core/SchedulingWatchdog.swift @@ -44,7 +44,7 @@ final class SchedulingWatchdog { } static func preconditionValidQueue(_ db: Database, _ message: @autoclosure() -> String = "Database was not used on the correct thread.", file: StaticString = #file, line: UInt = #line) { - GRDBPrecondition(current?.allows(db) ?? false, message, file: file, line: line) + GRDBPrecondition(current?.allows(db) ?? false, message(), file: file, line: line) } static var current: SchedulingWatchdog? { diff --git a/GRDB/Core/SerializedDatabase.swift b/GRDB/Core/SerializedDatabase.swift index 2a804e965..7fabe2ee2 100644 --- a/GRDB/Core/SerializedDatabase.swift +++ b/GRDB/Core/SerializedDatabase.swift @@ -42,7 +42,12 @@ final class SerializedDatabase { self.queue = configuration.makeDispatchQueue(defaultLabel: defaultLabel, purpose: purpose) SchedulingWatchdog.allowDatabase(db, onQueue: queue) try queue.sync { - try db.setup() + do { + try db.setup() + } catch { + db.close() + throw error + } } } @@ -189,11 +194,11 @@ final class SerializedDatabase { /// Fatal error if current dispatch queue is not valid. func preconditionValidQueue(_ message: @autoclosure() -> String = "Database was not used on the correct thread.", file: StaticString = #file, line: UInt = #line) { - SchedulingWatchdog.preconditionValidQueue(db, message, file: file, line: line) + SchedulingWatchdog.preconditionValidQueue(db, message(), file: file, line: line) } /// Fatal error if a transaction has been left opened. private func preconditionNoUnsafeTransactionLeft(_ db: Database, _ message: @autoclosure() -> String = "A transaction has been left opened at the end of a database access", file: StaticString = #file, line: UInt = #line) { - GRDBPrecondition(configuration.allowsUnsafeTransactions || !db.isInsideTransaction, message, file: file, line: line) + GRDBPrecondition(configuration.allowsUnsafeTransactions || !db.isInsideTransaction, message(), file: file, line: line) } } diff --git a/GRDB/Core/Statement.swift b/GRDB/Core/Statement.swift index 0d4bb6ccd..73a76d472 100644 --- a/GRDB/Core/Statement.swift +++ b/GRDB/Core/Statement.swift @@ -1,6 +1,8 @@ import Foundation #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -8,11 +10,9 @@ import Foundation /// A raw SQLite statement, suitable for the SQLite C API. public typealias SQLiteStatement = OpaquePointer -/// Statements are separated by semicolons and white spaces -let statementSeparatorCharacterSet = CharacterSet(charactersIn: ";").union(.whitespacesAndNewlines) - -/// An error emitted when one tries to compile an empty statement. -struct EmptyStatementError : Error { +extension CharacterSet { + /// Statements are separated by semicolons and white spaces + static let sqlStatementSeparators = CharacterSet(charactersIn: ";").union(.whitespacesAndNewlines) } /// A statement represents an SQL query. @@ -28,12 +28,13 @@ public class Statement { public var sql: String { // trim white space and semicolumn for homogeneous output return String(cString: sqlite3_sql(sqliteStatement)) - .trimmingCharacters(in: statementSeparatorCharacterSet) + .trimmingCharacters(in: .sqlStatementSeparators) } unowned let database: Database - /// Creates a prepared statement. + /// Creates a prepared statement. Returns nil if the compiled string is + /// blank or empty. /// /// - parameter database: A database connection. /// - parameter statementStart: A pointer to a UTF-8 encoded C string @@ -42,23 +43,27 @@ public class Statement { /// statement in the C string. /// - parameter prepFlags: Flags for sqlite3_prepare_v3 (available from /// SQLite 3.20.0, see http://www.sqlite.org/c3ref/prepare.html) - /// - throws: DatabaseError in case of compilation error, and - /// EmptyStatementError if the compiled string is blank or empty. - init( + /// - throws: DatabaseError in case of compilation error. + required init?( database: Database, statementStart: UnsafePointer, statementEnd: UnsafeMutablePointer?>, - prepFlags: Int32) throws + prepFlags: Int32, + authorizer: StatementCompilationAuthorizer) throws { SchedulingWatchdog.preconditionValidQueue(database) var sqliteStatement: SQLiteStatement? = nil // sqlite3_prepare_v3 was introduced in SQLite 3.20.0 http://www.sqlite.org/changes.html#version_3_20 #if GRDBCUSTOMSQLITE || GRDBCIPHER - let code = sqlite3_prepare_v3(database.sqliteConnection, statementStart, -1, UInt32(bitPattern: prepFlags), &sqliteStatement, statementEnd) + let code = sqlite3_prepare_v3(database.sqliteConnection, statementStart, -1, UInt32(bitPattern: prepFlags), &sqliteStatement, statementEnd) #else - // TODO: use sqlite3_prepare_v3 if #available(iOS 12.0, OSX 10.14, watchOS 5.0, *) - let code = sqlite3_prepare_v2(database.sqliteConnection, statementStart, -1, &sqliteStatement, statementEnd) + let code: Int32 + if #available(iOS 12.0, OSX 10.14, watchOS 5.0, *) { + code = sqlite3_prepare_v3(database.sqliteConnection, statementStart, -1, UInt32(bitPattern: prepFlags), &sqliteStatement, statementEnd) + } else { + code = sqlite3_prepare_v2(database.sqliteConnection, statementStart, -1, &sqliteStatement, statementEnd) + } #endif guard code == SQLITE_OK else { @@ -66,13 +71,7 @@ public class Statement { } guard let statement = sqliteStatement else { - // I wish we could simply return nil, and make this initializer failable. - // - // Unfortunately, there is a Swift bug with failable+throwing initializers: - // https://bugs.swift.org/browse/SR-6067 - // - // We thus use sentinel error for empty statements. - throw EmptyStatementError() + return nil } self.database = database @@ -95,7 +94,7 @@ public class Statement { // MARK: Arguments var argumentsNeedValidation = true - var _arguments: StatementArguments = [] + var _arguments = StatementArguments() lazy var sqliteArgumentCount: Int = { Int(sqlite3_bind_parameter_count(self.sqliteStatement)) @@ -125,7 +124,7 @@ public class Statement { /// statement arguments. public func validate(arguments: StatementArguments) throws { var arguments = arguments - _ = try arguments.consume(self, allowingRemainingValues: false) + _ = try arguments.extractBindings(forStatement: self, allowingRemainingValues: false) } /// Set arguments without any validation. Trades safety for performance. @@ -152,7 +151,7 @@ public class Statement { // Validate _arguments = arguments var arguments = arguments - let bindings = try arguments.consume(self, allowingRemainingValues: false) + let bindings = try arguments.extractBindings(forStatement: self, allowingRemainingValues: false) argumentsNeedValidation = false // Apply @@ -176,9 +175,15 @@ public class Statement { case .string(let string): code = sqlite3_bind_text(sqliteStatement, index, string, -1, SQLITE_TRANSIENT) case .blob(let data): - code = data.withUnsafeBytes { bytes in - sqlite3_bind_blob(sqliteStatement, index, bytes, Int32(data.count), SQLITE_TRANSIENT) + #if swift(>=5.0) + code = data.withUnsafeBytes { + sqlite3_bind_blob(sqliteStatement, index, $0.baseAddress, Int32($0.count), SQLITE_TRANSIENT) } + #else + code = data.withUnsafeBytes { + sqlite3_bind_blob(sqliteStatement, index, $0, Int32(data.count), SQLITE_TRANSIENT) + } + #endif } // It looks like sqlite3_bind_xxx() functions do not access the file system. @@ -210,48 +215,30 @@ public class Statement { } } -// MARK: - AuthorizedStatement +// MARK: - Statement Preparation -/// A common protocol for UpdateStatement and SelectStatement -protocol AuthorizedStatement { - // This initializer should be a required initializer of Statement. - // - // But Swift requires this required initializer to be public: - // https://bugs.swift.org/browse/SR-2347 - // - // We work around SR-2347 with this internal protocol. - // - // TODO: hasn't this bug been fixed in Swift 4.2? https://github.com/apple/swift/blob/master/CHANGELOG.md#swift-42 - init( - database: Database, - statementStart: UnsafePointer, - statementEnd: UnsafeMutablePointer?>, - prepFlags: Int32, - authorizer: StatementCompilationAuthorizer) throws -} - -extension AuthorizedStatement { - // Static function instead of an initializer because initializer doesn't - // compile due to the "capturing of an uninitialized self" in - // `sqlCodeUnits.withUnsafeBufferPointer`. +/// A common protocol for UpdateStatement and SelectStatement, only used as +/// support for SelectStatement.prepare(...) and UpdateStatement.prepare(...). +protocol StatementProtocol { } +extension Statement: StatementProtocol { } +extension StatementProtocol where Self: Statement { + // Static method instead of an initializer because initializer can't run + // inside `sqlCodeUnits.withUnsafeBufferPointer`. static func prepare(sql: String, prepFlags: Int32, in database: Database) throws -> Self { let authorizer = StatementCompilationAuthorizer() database.authorizer = authorizer defer { database.authorizer = nil } - let sqlCodeUnits = sql.utf8CString - return try sqlCodeUnits.withUnsafeBufferPointer { codeUnits in - let statementStart = UnsafePointer(codeUnits.baseAddress)! + return try sql.utf8CString.withUnsafeBufferPointer { buffer in + let statementStart = buffer.baseAddress! var statementEnd: UnsafePointer? = nil - let statement: Self - do { - statement = try self.init( - database: database, - statementStart: statementStart, - statementEnd: &statementEnd, - prepFlags: prepFlags, - authorizer: authorizer) - } catch is EmptyStatementError { + guard let statement = try self.init( + database: database, + statementStart: statementStart, + statementEnd: &statementEnd, + prepFlags: prepFlags, + authorizer: authorizer) else + { throw DatabaseError( resultCode: .SQLITE_ERROR, message: "empty statement", @@ -259,18 +246,11 @@ extension AuthorizedStatement { arguments: nil) } - let remainingData = Data( - bytesNoCopy: UnsafeMutableRawPointer(mutating: statementEnd!), - count: statementStart + sqlCodeUnits.count - statementEnd! - 1, - deallocator: .none) - - let remainingSQL = String(data: remainingData, encoding: .utf8)! - .trimmingCharacters(in: statementSeparatorCharacterSet) - + let remainingSQL = String(cString: statementEnd!).trimmingCharacters(in: .sqlStatementSeparators) guard remainingSQL.isEmpty else { throw DatabaseError( resultCode: .SQLITE_MISUSE, - message: "Multiple statements found. To execute multiple statements, use Database.execute() instead.", + message: "Multiple statements found. To execute multiple statements, use Database.execute(sql:) instead.", sql: sql, arguments: nil) } @@ -287,15 +267,16 @@ extension AuthorizedStatement { /// You create SelectStatement with the Database.makeSelectStatement() method: /// /// try dbQueue.read { db in -/// let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM player WHERE score > ?") +/// let statement = try db.makeSelectStatement(sql: "SELECT COUNT(*) FROM player WHERE score > ?") /// let moreThanTwentyCount = try Int.fetchOne(statement, arguments: [20])! /// let moreThanThirtyCount = try Int.fetchOne(statement, arguments: [30])! /// } public final class SelectStatement : Statement { /// The database region that the statement looks into. - public private(set) var databaseRegion: DatabaseRegion + public private(set) var databaseRegion = DatabaseRegion() - /// Creates a prepared statement. + /// Creates a prepared statement. Returns nil if the compiled string is + /// blank or empty. /// /// - parameter database: A database connection. /// - parameter statementStart: A pointer to a UTF-8 encoded C string @@ -305,21 +286,20 @@ public final class SelectStatement : Statement { /// - parameter prepFlags: Flags for sqlite3_prepare_v3 (available from /// SQLite 3.20.0, see http://www.sqlite.org/c3ref/prepare.html) /// - authorizer: A StatementCompilationAuthorizer - /// - throws: DatabaseError in case of compilation error, and - /// EmptyStatementError if the compiled string is blank or empty. - init( + /// - throws: DatabaseError in case of compilation error. + required init?( database: Database, statementStart: UnsafePointer, statementEnd: UnsafeMutablePointer?>, prepFlags: Int32, authorizer: StatementCompilationAuthorizer) throws { - self.databaseRegion = DatabaseRegion() try super.init( database: database, statementStart: statementStart, statementEnd: statementEnd, - prepFlags: prepFlags) + prepFlags: prepFlags, + authorizer: authorizer) GRDBPrecondition(authorizer.invalidatesDatabaseSchemaCache == false, "Invalid statement type for query \(String(reflecting: sql)): use UpdateStatement instead.") GRDBPrecondition(authorizer.transactionEffect == nil, "Invalid statement type for query \(String(reflecting: sql)): use UpdateStatement instead.") @@ -351,9 +331,9 @@ public final class SelectStatement : Statement { return columnIndexes[name.lowercased()] } - /// Creates a cursor over the statement. This cursor does not produce any - /// value, and is only intended to give access to the sqlite3_step() - /// low-level function. + /// Creates a cursor over the statement which does not produce any + /// value. Each call to the next() cursor method calls the sqlite3_step() + /// C function. func makeCursor(arguments: StatementArguments? = nil) -> StatementCursor { return StatementCursor(statement: self, arguments: arguments) } @@ -363,53 +343,64 @@ public final class SelectStatement : Statement { prepare(withArguments: arguments) try! reset() } + + /// Utility function for cursors + @usableFromInline + func didFail(withResultCode resultCode: Int32) throws -> Never { + database.selectStatementDidFail(self) + throw DatabaseError( + resultCode: resultCode, + message: database.lastErrorMessage, + sql: sql, + arguments: arguments) + + } } -// Hide AuthorizedStatement from Jazzy -extension SelectStatement: AuthorizedStatement { } - -// TODO: remove public qualifier, or expose SelectStatement.makeCursor() /// A cursor that iterates a database statement without producing any value. +/// Each call to the next() cursor method calls the sqlite3_step() C function. +/// /// For example: /// /// try dbQueue.read { db in -/// let statement = db.makeSelectStatement("SELECT * FROM player") -/// let cursor: StatementCursor = statement.makeCursor() +/// let statement = db.makeSelectStatement(sql: "SELECT performSideEffect()") +/// let cursor = statement.makeCursor() +/// try cursor.next() /// } -public final class StatementCursor: Cursor { - public let statement: SelectStatement - private let sqliteStatement: SQLiteStatement - private var done = false +final class StatementCursor: Cursor { + let _statement: SelectStatement + let _sqliteStatement: SQLiteStatement + var _done = false - // Use SelectStatement.cursor() instead - fileprivate init(statement: SelectStatement, arguments: StatementArguments? = nil) { - self.statement = statement - self.sqliteStatement = statement.sqliteStatement - statement.reset(withArguments: arguments) + // Use SelectStatement.makeCursor() instead + init(statement: SelectStatement, arguments: StatementArguments? = nil) { + _statement = statement + _sqliteStatement = statement.sqliteStatement + _statement.reset(withArguments: arguments) } deinit { // Statement reset fails when sqlite3_step has previously failed. // Just ignore reset error. - try? statement.reset() + try? _statement.reset() } /// :nodoc: - public func next() throws -> Void? { - if done { + @inlinable + func next() throws -> Void? { + if _done { // make sure this instance never yields a value again, even if the // statement is reset by another cursor. return nil } - switch sqlite3_step(sqliteStatement) { + switch sqlite3_step(_sqliteStatement) { case SQLITE_DONE: - done = true + _done = true return nil case SQLITE_ROW: return .some(()) case let code: - statement.database.selectStatementDidFail(statement) - throw DatabaseError(resultCode: code, message: statement.database.lastErrorMessage, sql: statement.sql, arguments: statement.arguments) + try _statement.didFail(withResultCode: code) } } } @@ -422,7 +413,7 @@ public final class StatementCursor: Cursor { /// You create UpdateStatement with the Database.makeUpdateStatement() method: /// /// try dbQueue.inTransaction { db in -/// let statement = try db.makeUpdateStatement("INSERT INTO player (name) VALUES (?)") +/// let statement = try db.makeUpdateStatement(sql: "INSERT INTO player (name) VALUES (?)") /// try statement.execute(arguments: ["Arthur"]) /// try statement.execute(arguments: ["Barbara"]) /// return .commit @@ -439,12 +430,13 @@ public final class UpdateStatement : Statement { /// If true, the database schema cache gets invalidated after this statement /// is executed. - private(set) var invalidatesDatabaseSchemaCache: Bool + private(set) var invalidatesDatabaseSchemaCache: Bool = false private(set) var transactionEffect: TransactionEffect? - private(set) var databaseEventKinds: [DatabaseEventKind] + private(set) var databaseEventKinds: [DatabaseEventKind] = [] - /// Creates a prepared statement. + /// Creates a prepared statement. Returns nil if the compiled string is + /// blank or empty. /// /// - parameter database: A database connection. /// - parameter statementStart: A pointer to a UTF-8 encoded C string @@ -454,22 +446,20 @@ public final class UpdateStatement : Statement { /// - parameter prepFlags: Flags for sqlite3_prepare_v3 (available from /// SQLite 3.20.0, see http://www.sqlite.org/c3ref/prepare.html) /// - authorizer: A StatementCompilationAuthorizer - /// - throws: DatabaseError in case of compilation error, and - /// EmptyStatementError if the compiled string is blank or empty. - init( + /// - throws: DatabaseError in case of compilation error. + required init?( database: Database, statementStart: UnsafePointer, statementEnd: UnsafeMutablePointer?>, prepFlags: Int32, authorizer: StatementCompilationAuthorizer) throws { - self.invalidatesDatabaseSchemaCache = false - self.databaseEventKinds = [] try super.init( database: database, statementStart: statementStart, statementEnd: statementEnd, - prepFlags: prepFlags) + prepFlags: prepFlags, + authorizer: authorizer) self.invalidatesDatabaseSchemaCache = authorizer.invalidatesDatabaseSchemaCache self.transactionEffect = authorizer.transactionEffect self.databaseEventKinds = authorizer.databaseEventKinds @@ -477,7 +467,7 @@ public final class UpdateStatement : Statement { /// Executes the SQL query. /// - /// - parameter arguments: Statement arguments. + /// - parameter arguments: Optional statement arguments. /// - throws: A DatabaseError whenever an SQLite error occurs. public func execute(arguments: StatementArguments? = nil) throws { SchedulingWatchdog.preconditionValidQueue(database) @@ -491,17 +481,17 @@ public final class UpdateStatement : Statement { // The statement did return a row, and the user ignores the // content of this row: // - // try db.execute("SELECT ...") + // try db.execute(sql: "SELECT ...") // // That's OK: maybe the selected rows perform side effects. // For example: // - // try db.execute("SELECT sqlcipher_export(...)") + // try db.execute(sql: "SELECT sqlcipher_export(...)") // // Or maybe the user doesn't know that the executed statement // return rows (https://github.com/groue/GRDB.swift/issues/15); // - // try db.execute("PRAGMA journal_mode=WAL") + // try db.execute(sql: "PRAGMA journal_mode=WAL") // // It is thus important that we consume *all* rows. continue @@ -518,10 +508,6 @@ public final class UpdateStatement : Statement { } } -// Hide AuthorizedStatement from Jazzy -extension UpdateStatement: AuthorizedStatement { } - - // MARK: - StatementArguments /// StatementArguments provide values to argument placeholders in raw @@ -542,12 +528,12 @@ extension UpdateStatement: AuthorizedStatement { } /// To fill question marks placeholders, feed StatementArguments with an array: /// /// db.execute( -/// "INSERT ... (?, ?)", +/// sql: "INSERT ... (?, ?)", /// arguments: StatementArguments(["Arthur", 41])) /// /// // Array literals are automatically converted: /// db.execute( -/// "INSERT ... (?, ?)", +/// sql: "INSERT ... (?, ?)", /// arguments: ["Arthur", 41]) /// /// ## Named Arguments @@ -555,12 +541,12 @@ extension UpdateStatement: AuthorizedStatement { } /// To fill named arguments, feed StatementArguments with a dictionary: /// /// db.execute( -/// "INSERT ... (:name, :score)", +/// sql: "INSERT ... (:name, :score)", /// arguments: StatementArguments(["name": "Arthur", "score": 41])) /// /// // Dictionary literals are automatically converted: /// db.execute( -/// "INSERT ... (:name, :score)", +/// sql: "INSERT ... (:name, :score)", /// arguments: ["name": "Arthur", "score": 41]) /// /// ## Concatenating Arguments @@ -570,7 +556,7 @@ extension UpdateStatement: AuthorizedStatement { } /// /// var arguments: StatementArguments = ["Arthur"] /// arguments += [41] -/// db.execute("INSERT ... (?, ?)", arguments: arguments) +/// db.execute(sql: "INSERT ... (?, ?)", arguments: arguments) /// /// `+` and `+=` operators consider that overriding named arguments is a /// programmer error: @@ -593,7 +579,7 @@ extension UpdateStatement: AuthorizedStatement { } /// /// let sql = "SELECT ?2 AS two, :foo AS foo, ?1 AS one, :foo AS foo2, :bar AS bar" /// var arguments: StatementArguments = [1, 2, "bar"] + ["foo": "foo"] -/// let row = try Row.fetchOne(db, sql, arguments: arguments)! +/// let row = try Row.fetchOne(db, sql: sql, arguments: arguments)! /// print(row) /// // Prints [two:2 foo:"foo" one:1 foo2:"foo" bar:"bar"] /// @@ -615,7 +601,7 @@ public struct StatementArguments: CustomStringConvertible, Equatable, Expressibl // MARK: Empty Arguments /// Creates empty StatementArguments. - init() { + public init() { } // MARK: Positional Arguments @@ -623,7 +609,7 @@ public struct StatementArguments: CustomStringConvertible, Equatable, Expressibl /// Creates statement arguments from a sequence of optional values. /// /// let values: [DatabaseValueConvertible?] = ["foo", 1, nil] - /// db.execute("INSERT ... (?,?,?)", arguments: StatementArguments(values)) + /// db.execute(sql: "INSERT ... (?,?,?)", arguments: StatementArguments(values)) /// /// - parameter sequence: A sequence of DatabaseValueConvertible values. /// - returns: A StatementArguments. @@ -634,7 +620,7 @@ public struct StatementArguments: CustomStringConvertible, Equatable, Expressibl /// Creates statement arguments from a sequence of optional values. /// /// let values: [String] = ["foo", "bar"] - /// db.execute("INSERT ... (?,?)", arguments: StatementArguments(values)) + /// db.execute(sql: "INSERT ... (?,?)", arguments: StatementArguments(values)) /// /// - parameter sequence: A sequence of DatabaseValueConvertible values. /// - returns: A StatementArguments. @@ -665,7 +651,7 @@ public struct StatementArguments: CustomStringConvertible, Equatable, Expressibl /// such as a dictionary. /// /// let values: [String: DatabaseValueConvertible?] = ["firstName": nil, "lastName": "Miller"] - /// db.execute("INSERT ... (:firstName, :lastName)", arguments: StatementArguments(values)) + /// db.execute(sql: "INSERT ... (:firstName, :lastName)", arguments: StatementArguments(values)) /// /// - parameter sequence: A sequence of (key, value) pairs /// - returns: A StatementArguments. @@ -677,7 +663,7 @@ public struct StatementArguments: CustomStringConvertible, Equatable, Expressibl /// as a dictionary. /// /// let values: [String: DatabaseValueConvertible?] = ["firstName": nil, "lastName": "Miller"] - /// db.execute("INSERT ... (:firstName, :lastName)", arguments: StatementArguments(values)) + /// db.execute(sql: "INSERT ... (:firstName, :lastName)", arguments: StatementArguments(values)) /// /// - parameter sequence: A sequence of (key, value) pairs /// - returns: A StatementArguments. @@ -863,7 +849,7 @@ public struct StatementArguments: CustomStringConvertible, Equatable, Expressibl // MARK: Not Public - mutating func consume(_ statement: Statement, allowingRemainingValues: Bool) throws -> [DatabaseValue] { + mutating func extractBindings(forStatement statement: Statement, allowingRemainingValues: Bool) throws -> [DatabaseValue] { let initialValuesCount = values.count let bindings = try statement.sqliteArgumentNames.map { argumentName -> DatabaseValue in if let argumentName = argumentName { @@ -893,7 +879,10 @@ public struct StatementArguments: CustomStringConvertible, Equatable, Expressibl extension StatementArguments { /// Returns a StatementArguments from an array literal: /// - /// db.selectRows("SELECT ...", arguments: ["Arthur", 41]) + /// let arguments: StatementArguments = ["Arthur", 41] + /// try db.execute( + /// sql: "INSERT INTO player (name, score) VALUES (?, ?)" + /// arguments: arguments) public init(arrayLiteral elements: DatabaseValueConvertible?...) { self.init(elements) } @@ -903,7 +892,10 @@ extension StatementArguments { extension StatementArguments { /// Returns a StatementArguments from a dictionary literal: /// - /// db.selectRows("SELECT ...", arguments: ["name": "Arthur", "score": 41]) + /// let arguments: StatementArguments = ["name": "Arthur", "score": 41] + /// try db.execute( + /// sql: "INSERT INTO player (name, score) VALUES (:name, :score)" + /// arguments: arguments) public init(dictionaryLiteral elements: (String, DatabaseValueConvertible?)...) { self.init(elements) } diff --git a/GRDB/Core/StatementAuthorizer.swift b/GRDB/Core/StatementAuthorizer.swift index 0c9957878..e94bfa4a5 100644 --- a/GRDB/Core/StatementAuthorizer.swift +++ b/GRDB/Core/StatementAuthorizer.swift @@ -3,6 +3,8 @@ #endif #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif diff --git a/GRDB/Core/StatementColumnConvertible.swift b/GRDB/Core/StatementColumnConvertible.swift index 65650e0e3..f0a03fac6 100644 --- a/GRDB/Core/StatementColumnConvertible.swift +++ b/GRDB/Core/StatementColumnConvertible.swift @@ -1,5 +1,7 @@ #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -13,11 +15,11 @@ /// DatabaseValueConvertible. GRDB will then automatically apply the /// optimization whenever direct access to SQLite is possible: /// -/// let rows = Row.fetchCursor(db, "SELECT ...") +/// let rows = Row.fetchCursor(db, sql: "SELECT ...") /// while let row = try rows.next() { /// let int: Int = row[0] // there /// } -/// let ints = Int.fetchAll(db, "SELECT ...") // there +/// let ints = Int.fetchAll(db, sql: "SELECT ...") // there /// struct Player { /// init(row: Row) { /// name = row["name"] // there @@ -54,114 +56,108 @@ public protocol StatementColumnConvertible { /// For example: /// /// try dbQueue.read { db in -/// let names: ColumnCursor = try String.fetchCursor(db, "SELECT name FROM player") +/// let names: ColumnCursor = try String.fetchCursor(db, sql: "SELECT name FROM player") /// while let name = names.next() { // String /// print(name) /// } /// } public final class FastDatabaseValueCursor : Cursor { - private let statement: SelectStatement - private let sqliteStatement: SQLiteStatement - private let columnIndex: Int32 - private var done = false + @usableFromInline let _statement: SelectStatement + @usableFromInline let _columnIndex: Int32 + @usableFromInline let _sqliteStatement: SQLiteStatement + @usableFromInline var _done = false init(statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { - self.statement = statement - self.sqliteStatement = statement.sqliteStatement + _statement = statement + _sqliteStatement = statement.sqliteStatement if let adapter = adapter { // adapter may redefine the index of the leftmost column - self.columnIndex = try Int32(adapter.baseColumnIndex(atIndex: 0, layout: statement)) + _columnIndex = try Int32(adapter.baseColumnIndex(atIndex: 0, layout: statement)) } else { - self.columnIndex = 0 + _columnIndex = 0 } - statement.reset(withArguments: arguments) + _statement.reset(withArguments: arguments) } deinit { // Statement reset fails when sqlite3_step has previously failed. // Just ignore reset error. - try? statement.reset() + try? _statement.reset() } /// :nodoc: + @inlinable public func next() throws -> Value? { - if done { + if _done { // make sure this instance never yields a value again, even if the // statement is reset by another cursor. return nil } - switch sqlite3_step(sqliteStatement) { + switch sqlite3_step(_sqliteStatement) { case SQLITE_DONE: - done = true + _done = true return nil case SQLITE_ROW: - return Value.fastDecode(from: sqliteStatement, index: columnIndex) + return Value.fastDecode(from: _sqliteStatement, atUncheckedIndex: _columnIndex) case let code: - statement.database.selectStatementDidFail(statement) - throw DatabaseError(resultCode: code, message: statement.database.lastErrorMessage, sql: statement.sql, arguments: statement.arguments) + try _statement.didFail(withResultCode: code) } } } -@available(*, deprecated, renamed: "FastDatabaseValueCursor") -public typealias ColumnCursor = FastDatabaseValueCursor - /// A cursor of optional database values extracted from a single column. /// For example: /// /// try dbQueue.read { db in -/// let emails: NullableColumnCursor = try Optional.fetchCursor(db, "SELECT email FROM player") +/// let emails: NullableColumnCursor = try Optional.fetchCursor(db, sql: "SELECT email FROM player") /// while let email = emails.next() { // String? /// print(email ?? "") /// } /// } public final class FastNullableDatabaseValueCursor : Cursor { - private let statement: SelectStatement - private let sqliteStatement: SQLiteStatement - private let columnIndex: Int32 - private var done = false - + @usableFromInline let _statement: SelectStatement + @usableFromInline let _columnIndex: Int32 + @usableFromInline let _sqliteStatement: SQLiteStatement + @usableFromInline var _done = false + init(statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { - self.statement = statement - self.sqliteStatement = statement.sqliteStatement + _statement = statement + _sqliteStatement = statement.sqliteStatement if let adapter = adapter { // adapter may redefine the index of the leftmost column - self.columnIndex = try Int32(adapter.baseColumnIndex(atIndex: 0, layout: statement)) + _columnIndex = try Int32(adapter.baseColumnIndex(atIndex: 0, layout: statement)) } else { - self.columnIndex = 0 + _columnIndex = 0 } - statement.reset(withArguments: arguments) + _statement.reset(withArguments: arguments) } deinit { // Statement reset fails when sqlite3_step has previously failed. // Just ignore reset error. - try? statement.reset() + try? _statement.reset() } /// :nodoc: + @inlinable public func next() throws -> Value?? { - if done { + if _done { // make sure this instance never yields a value again, even if the // statement is reset by another cursor. return nil } - switch sqlite3_step(sqliteStatement) { + switch sqlite3_step(_sqliteStatement) { case SQLITE_DONE: - done = true + _done = true return nil case SQLITE_ROW: - return Value.fastDecodeIfPresent(from: sqliteStatement, atUncheckedIndex: columnIndex) + return Value.fastDecodeIfPresent(from: _sqliteStatement, atUncheckedIndex: _columnIndex) case let code: - statement.database.selectStatementDidFail(statement) - throw DatabaseError(resultCode: code, message: statement.database.lastErrorMessage, sql: statement.sql, arguments: statement.arguments) + try _statement.didFail(withResultCode: code) } } } -@available(*, deprecated, renamed: "FastNullableDatabaseValueCursor") -public typealias NullableColumnCursor = FastNullableDatabaseValueCursor - /// Types that adopt both DatabaseValueConvertible and /// StatementColumnConvertible can be efficiently initialized from /// database values. @@ -174,7 +170,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// Returns a cursor over values fetched from a prepared statement. /// - /// let statement = try db.makeSelectStatement("SELECT name FROM ...") + /// let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") /// let names = try String.fetchCursor(statement) // Cursor of String /// while let name = try names.next() { // String /// ... @@ -197,7 +193,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// Returns an array of values fetched from a prepared statement. /// - /// let statement = try db.makeSelectStatement("SELECT name FROM ...") + /// let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") /// let names = try String.fetchAll(statement) // [String] /// /// - parameters: @@ -212,7 +208,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// Returns a single value fetched from a prepared statement. /// - /// let statement = try db.makeSelectStatement("SELECT name FROM ...") + /// let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") /// let name = try String.fetchOne(statement) // String? /// /// - parameters: @@ -234,7 +230,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// Returns a cursor over values fetched from an SQL query. /// - /// let names = try String.fetchCursor(db, "SELECT name FROM ...") // Cursor of String + /// let names = try String.fetchCursor(db, sql: "SELECT name FROM ...") // Cursor of String /// while let name = try names.next() { // String /// ... /// } @@ -247,42 +243,42 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> FastDatabaseValueCursor { - return try fetchCursor(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + public static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> FastDatabaseValueCursor { + return try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns an array of values fetched from an SQL query. /// - /// let names = try String.fetchAll(db, "SELECT name FROM ...") // [String] + /// let names = try String.fetchAll(db, sql: "SELECT name FROM ...") // [String] /// /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An array of values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] { - return try fetchAll(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + public static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] { + return try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns a single value fetched from an SQL query. /// - /// let name = try String.fetchOne(db, "SELECT name FROM ...") // String? + /// let name = try String.fetchOne(db, sql: "SELECT name FROM ...") // String? /// /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An optional value. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? { - return try fetchOne(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + public static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? { + return try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } @@ -309,7 +305,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// - returns: A cursor over fetched values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. public static func fetchCursor(_ db: Database, _ request: R) throws -> FastDatabaseValueCursor { - let (statement, adapter) = try request.prepare(db) + let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchCursor(statement, adapter: adapter) } @@ -324,7 +320,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// - returns: An array of values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. public static func fetchAll(_ db: Database, _ request: R) throws -> [Self] { - let (statement, adapter) = try request.prepare(db) + let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchAll(statement, adapter: adapter) } @@ -339,7 +335,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// - returns: An optional value. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. public static func fetchOne(_ db: Database, _ request: R) throws -> Self? { - let (statement, adapter) = try request.prepare(db) + let (statement, adapter) = try request.prepare(db, forSingleResult: true) return try fetchOne(statement, adapter: adapter) } } @@ -350,7 +346,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible & StatementCol /// A cursor over fetched values. /// - /// let request: ... // Some TypedRequest that fetches String + /// let request: ... // Some FetchRequest that fetches String /// let strings = try request.fetchCursor(db) // Cursor of String /// while let string = try strings.next() { // String /// ... @@ -370,7 +366,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible & StatementCol /// An array of fetched values. /// - /// let request: ... // Some TypedRequest that fetches String + /// let request: ... // Some FetchRequest that fetches String /// let strings = try request.fetchAll(db) // [String] /// /// - parameter db: A database connection. @@ -385,7 +381,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible & StatementCol /// The result is nil if the request returns no row, or if no value can be /// extracted from the first row. /// - /// let request: ... // Some TypedRequest that fetches String + /// let request: ... // Some FetchRequest that fetches String /// let string = try request.fetchOne(db) // String? /// /// - parameter db: A database connection. @@ -399,10 +395,10 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible & StatementCol /// Swift's Optional comes with built-in methods that allow to fetch cursors /// and arrays of optional DatabaseValueConvertible: /// -/// try Optional.fetchCursor(db, "SELECT name FROM ...", arguments:...) // Cursor of String? -/// try Optional.fetchAll(db, "SELECT name FROM ...", arguments:...) // [String?] +/// try Optional.fetchCursor(db, sql: "SELECT name FROM ...", arguments:...) // Cursor of String? +/// try Optional.fetchAll(db, sql: "SELECT name FROM ...", arguments:...) // [String?] /// -/// let statement = try db.makeSelectStatement("SELECT name FROM ...") +/// let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") /// try Optional.fetchCursor(statement, arguments:...) // Cursor of String? /// try Optional.fetchAll(statement, arguments:...) // [String?] /// @@ -413,7 +409,7 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv /// Returns a cursor over optional values fetched from a prepared statement. /// - /// let statement = try db.makeSelectStatement("SELECT name FROM ...") + /// let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") /// let names = try Optional.fetchCursor(statement) // Cursor of String? /// while let name = try names.next() { // String? /// ... @@ -436,7 +432,7 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv /// Returns an array of optional values fetched from a prepared statement. /// - /// let statement = try db.makeSelectStatement("SELECT name FROM ...") + /// let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") /// let names = try Optional.fetchAll(statement) // [String?] /// /// - parameters: @@ -456,7 +452,7 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv /// Returns a cursor over optional values fetched from an SQL query. /// - /// let names = try Optional.fetchCursor(db, "SELECT name FROM ...") // Cursor of String? + /// let names = try Optional.fetchCursor(db, sql: "SELECT name FROM ...") // Cursor of String? /// while let name = try names.next() { // String? /// ... /// } @@ -469,27 +465,27 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> FastNullableDatabaseValueCursor { - return try fetchCursor(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + public static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> FastNullableDatabaseValueCursor { + return try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns an array of optional values fetched from an SQL query. /// - /// let names = try String.fetchAll(db, "SELECT name FROM ...") // [String?] + /// let names = try String.fetchAll(db, sql: "SELECT name FROM ...") // [String?] /// /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - parameter arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An array of optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Wrapped?] { - return try fetchAll(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + public static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Wrapped?] { + return try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } @@ -516,7 +512,7 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv /// - returns: A cursor over fetched optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. public static func fetchCursor(_ db: Database, _ request: R) throws -> FastNullableDatabaseValueCursor { - let (statement, adapter) = try request.prepare(db) + let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchCursor(statement, adapter: adapter) } @@ -531,7 +527,7 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv /// - returns: An array of optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. public static func fetchAll(_ db: Database, _ request: R) throws -> [Wrapped?] { - let (statement, adapter) = try request.prepare(db) + let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchAll(statement, adapter: adapter) } } @@ -542,7 +538,7 @@ extension FetchRequest where RowDecoder: _OptionalProtocol, RowDecoder._Wrapped: /// A cursor over fetched optional values. /// - /// let request: ... // Some TypedRequest that fetches Optional + /// let request: ... // Some FetchRequest that fetches Optional /// let strings = try request.fetchCursor(db) // Cursor of String? /// while let string = try strings.next() { // String? /// ... @@ -562,7 +558,7 @@ extension FetchRequest where RowDecoder: _OptionalProtocol, RowDecoder._Wrapped: /// An array of fetched optional values. /// - /// let request: ... // Some TypedRequest that fetches Optional + /// let request: ... // Some FetchRequest that fetches Optional /// let strings = try request.fetchAll(db) // [String?] /// /// - parameter db: A database connection. diff --git a/GRDB/Core/Support/Foundation/Data.swift b/GRDB/Core/Support/Foundation/Data.swift index ece9321ed..8c4202bdc 100644 --- a/GRDB/Core/Support/Foundation/Data.swift +++ b/GRDB/Core/Support/Foundation/Data.swift @@ -1,12 +1,15 @@ import Foundation #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif /// Data is convertible to and from DatabaseValue. extension Data : DatabaseValueConvertible, StatementColumnConvertible { + @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { if let bytes = sqlite3_column_blob(sqliteStatement, index) { let count = Int(sqlite3_column_bytes(sqliteStatement, index)) diff --git a/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift b/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift index 8c8b0776a..f84be4909 100644 --- a/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift +++ b/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift @@ -1,6 +1,8 @@ import Foundation #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif diff --git a/GRDB/Core/Support/Foundation/DatabaseValueConvertible+ReferenceConvertible.swift b/GRDB/Core/Support/Foundation/DatabaseValueConvertible+ReferenceConvertible.swift index c5c8c6a52..d5fedd5ad 100644 --- a/GRDB/Core/Support/Foundation/DatabaseValueConvertible+ReferenceConvertible.swift +++ b/GRDB/Core/Support/Foundation/DatabaseValueConvertible+ReferenceConvertible.swift @@ -26,14 +26,14 @@ extension DatabaseValueConvertible where Self: ReferenceConvertible, Self.Refere } } -public extension DatabaseValueConvertible where Self: Decodable & ReferenceConvertible, Self.ReferenceType: DatabaseValueConvertible { +extension DatabaseValueConvertible where Self: Decodable & ReferenceConvertible, Self.ReferenceType: DatabaseValueConvertible { public static func fromDatabaseValue(_ databaseValue: DatabaseValue) -> Self? { // Preserve custom database decoding return ReferenceType.fromDatabaseValue(databaseValue).flatMap { cast($0) } } } -public extension DatabaseValueConvertible where Self: Encodable & ReferenceConvertible, Self.ReferenceType: DatabaseValueConvertible { +extension DatabaseValueConvertible where Self: Encodable & ReferenceConvertible, Self.ReferenceType: DatabaseValueConvertible { public var databaseValue: DatabaseValue { // Preserve custom database encoding return (self as! ReferenceType).databaseValue diff --git a/GRDB/Core/Support/Foundation/Date.swift b/GRDB/Core/Support/Foundation/Date.swift index ea9faa6d4..4742c84ed 100644 --- a/GRDB/Core/Support/Foundation/Date.swift +++ b/GRDB/Core/Support/Foundation/Date.swift @@ -1,6 +1,8 @@ import Foundation #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -63,7 +65,8 @@ extension Date : DatabaseValueConvertible { return nil } - private init?(databaseDateComponents: DatabaseDateComponents) { + @usableFromInline + init?(databaseDateComponents: DatabaseDateComponents) { guard databaseDateComponents.format.hasYMDComponents else { // Refuse to turn hours without any date information into Date: return nil @@ -122,6 +125,7 @@ extension Date: StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. + @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { switch sqlite3_column_type(sqliteStatement, index) { case SQLITE_INTEGER, SQLITE_FLOAT: diff --git a/GRDB/Core/Support/Foundation/SQLiteDateParser.swift b/GRDB/Core/Support/Foundation/SQLiteDateParser.swift index ba2f83814..cd42663c0 100644 --- a/GRDB/Core/Support/Foundation/SQLiteDateParser.swift +++ b/GRDB/Core/Support/Foundation/SQLiteDateParser.swift @@ -23,16 +23,20 @@ class SQLiteDateParser { func components(cString: UnsafePointer, length: Int) -> DatabaseDateComponents? { assert(strlen(cString) == length) + // "HH:MM" is the shortest valid string guard length >= 5 else { return nil } - if cString.advanced(by: 4).pointee == 45 /* '-' */ { + // "YYYY-..." -> datetime + if cString[4] == UInt8(ascii: "-") { return datetimeComponents(cString: cString, length: length) } - if cString.advanced(by: 2).pointee == 58 /* ':' */ { + // "HH-:..." -> time + if cString[2] == UInt8(ascii: ":") { return timeComponents(cString: cString, length: length) } + // Invalid return nil } diff --git a/GRDB/Core/Support/Foundation/UUID.swift b/GRDB/Core/Support/Foundation/UUID.swift index 13bb3bca6..8ed8d68b0 100644 --- a/GRDB/Core/Support/Foundation/UUID.swift +++ b/GRDB/Core/Support/Foundation/UUID.swift @@ -1,6 +1,8 @@ import Foundation #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -19,19 +21,15 @@ extension NSUUID: DatabaseValueConvertible { public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Self? { switch dbValue.storage { case .blob(let data) where data.count == 16: - // The code below works in debug configuration, but crashes in - // release configuration (Xcode 9.4.1) - -// return data.withUnsafeBytes { -// self.init(uuidBytes: $0) -// } - - // Workaround (involves a useless copy) - let buffer = UnsafeMutableBufferPointer.allocate(capacity: 16) - _ = data.copyBytes(to: buffer) - let uuid = self.init(uuidBytes: UnsafePointer(buffer.baseAddress!)) - buffer.deallocate() - return uuid + #if swift(>=5.0) + return data.withUnsafeBytes { + self.init(uuidBytes: $0.bindMemory(to: UInt8.self).baseAddress) + } + #else + return data.withUnsafeBytes { + self.init(uuidBytes: $0) + } + #endif case .string(let string): return self.init(uuidString: string) default: @@ -44,8 +42,7 @@ extension NSUUID: DatabaseValueConvertible { /// UUID adopts DatabaseValueConvertible extension UUID: DatabaseValueConvertible { public var databaseValue: DatabaseValue { - var uuid_t = uuid - return withUnsafeBytes(of: &uuid_t) { + return withUnsafeBytes(of: uuid) { Data(bytes: $0.baseAddress!, count: $0.count).databaseValue } } @@ -53,9 +50,15 @@ extension UUID: DatabaseValueConvertible { public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> UUID? { switch dbValue.storage { case .blob(let data) where data.count == 16: + #if swift(>=5.0) + return data.withUnsafeBytes { + UUID(uuid: $0.bindMemory(to: uuid_t.self).first!) + } + #else return data.withUnsafeBytes { UUID(uuid: $0.pointee) } + #endif case .string(let string): return UUID(uuidString: string) default: @@ -65,6 +68,7 @@ extension UUID: DatabaseValueConvertible { } extension UUID: StatementColumnConvertible { + @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { switch sqlite3_column_type(sqliteStatement, index) { case SQLITE_TEXT: diff --git a/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Decodable.swift b/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Decodable.swift index afb22a49e..f04cfd071 100644 --- a/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Decodable.swift +++ b/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Decodable.swift @@ -178,13 +178,13 @@ private struct DatabaseValueDecoder: Decoder { } } -public extension DatabaseValueConvertible where Self: Decodable { +extension DatabaseValueConvertible where Self: Decodable { public static func fromDatabaseValue(_ databaseValue: DatabaseValue) -> Self? { return try? self.init(from: DatabaseValueDecoder(dbValue: databaseValue, codingPath: [])) } } -public extension DatabaseValueConvertible where Self: Decodable & RawRepresentable, Self.RawValue: DatabaseValueConvertible { +extension DatabaseValueConvertible where Self: Decodable & RawRepresentable, Self.RawValue: DatabaseValueConvertible { public static func fromDatabaseValue(_ databaseValue: DatabaseValue) -> Self? { // Preserve custom database decoding return RawValue.fromDatabaseValue(databaseValue).flatMap { self.init(rawValue: $0) } diff --git a/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Encodable.swift b/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Encodable.swift index c7bf480eb..8aa705b32 100644 --- a/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Encodable.swift +++ b/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Encodable.swift @@ -89,7 +89,7 @@ private struct DatabaseValueEncoder : Encoder { } } -public extension DatabaseValueConvertible where Self: Encodable { +extension DatabaseValueConvertible where Self: Encodable { public var databaseValue: DatabaseValue { var dbValue: DatabaseValue! = nil let encoder = DatabaseValueEncoder(encode: { dbValue = $0 }) @@ -98,7 +98,7 @@ public extension DatabaseValueConvertible where Self: Encodable { } } -public extension DatabaseValueConvertible where Self: Encodable & RawRepresentable, Self.RawValue: DatabaseValueConvertible { +extension DatabaseValueConvertible where Self: Encodable & RawRepresentable, Self.RawValue: DatabaseValueConvertible { public var databaseValue: DatabaseValue { // Preserve custom database encoding return rawValue.databaseValue diff --git a/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift b/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift index e3438aacd..79a3d581c 100644 --- a/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift +++ b/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift @@ -1,5 +1,7 @@ #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -14,6 +16,7 @@ extension Bool: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. + @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { self = sqlite3_column_int64(sqliteStatement, index) != 0 } @@ -100,6 +103,7 @@ extension Int: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. + @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) if let v = Int(exactly: int64) { @@ -128,6 +132,7 @@ extension Int8: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. + @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) if let v = Int8(exactly: int64) { @@ -156,6 +161,7 @@ extension Int16: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. + @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) if let v = Int16(exactly: int64) { @@ -184,6 +190,7 @@ extension Int32: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. + @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) if let v = Int32(exactly: int64) { @@ -212,6 +219,7 @@ extension Int64: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. + @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { self = sqlite3_column_int64(sqliteStatement, index) } @@ -244,6 +252,7 @@ extension UInt: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. + @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) if let v = UInt(exactly: int64) { @@ -272,6 +281,7 @@ extension UInt8: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. + @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) if let v = UInt8(exactly: int64) { @@ -300,6 +310,7 @@ extension UInt16: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. + @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) if let v = UInt16(exactly: int64) { @@ -328,6 +339,7 @@ extension UInt32: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. + @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) if let v = UInt32(exactly: int64) { @@ -356,6 +368,7 @@ extension UInt64: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. + @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) if let v = UInt64(exactly: int64) { @@ -384,6 +397,7 @@ extension Double: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. + @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { self = sqlite3_column_double(sqliteStatement, index) } @@ -414,6 +428,7 @@ extension Float: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. + @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { self = Float(sqlite3_column_double(sqliteStatement, index)) } @@ -444,6 +459,7 @@ extension String: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. + @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { self = String(cString: sqlite3_column_text(sqliteStatement, index)!) } @@ -543,7 +559,7 @@ extension DatabaseFunction { /// let nameColumn = Column("name") /// let request = Player.select(nameColumn.localizedCapitalized) /// let names = try String.fetchAll(dbQueue, request) // [String] - @available(iOS 9.0, OSX 10.11, watchOS 3.0, *) + @available(OSX 10.11, watchOS 3.0, *) public static let localizedCapitalize = DatabaseFunction("swiftLocalizedCapitalizedString", argumentCount: 1, pure: true) { dbValues in guard let string = String.fromDatabaseValue(dbValues[0]) else { return nil @@ -563,7 +579,7 @@ extension DatabaseFunction { /// let nameColumn = Column("name") /// let request = Player.select(nameColumn.localizedLowercased) /// let names = try String.fetchAll(dbQueue, request) // [String] - @available(iOS 9.0, OSX 10.11, watchOS 3.0, *) + @available(OSX 10.11, watchOS 3.0, *) public static let localizedLowercase = DatabaseFunction("swiftLocalizedLowercaseString", argumentCount: 1, pure: true) { dbValues in guard let string = String.fromDatabaseValue(dbValues[0]) else { return nil @@ -583,7 +599,7 @@ extension DatabaseFunction { /// let nameColumn = Column("name") /// let request = Player.select(nameColumn.localizedUppercased) /// let names = try String.fetchAll(dbQueue, request) // [String] - @available(iOS 9.0, OSX 10.11, watchOS 3.0, *) + @available(OSX 10.11, watchOS 3.0, *) public static let localizedUppercase = DatabaseFunction("swiftLocalizedUppercaseString", argumentCount: 1, pure: true) { dbValues in guard let string = String.fromDatabaseValue(dbValues[0]) else { return nil @@ -616,11 +632,11 @@ extension DatabaseCollation { /// You can use it when creating database tables: /// /// let collationName = DatabaseCollation.caseInsensitiveCompare.name - /// dbQueue.execute( - /// "CREATE TABLE players (" + - /// "name TEXT COLLATE \(collationName)" + - /// ")" - /// ) + /// dbQueue.execute(sql: """ + /// CREATE TABLE players ( + /// name TEXT COLLATE \(collationName) + /// ) + /// """) public static let unicodeCompare = DatabaseCollation("swiftCompare") { (lhs, rhs) in return (lhs < rhs) ? .orderedAscending : ((lhs == rhs) ? .orderedSame : .orderedDescending) } @@ -634,11 +650,11 @@ extension DatabaseCollation { /// You can use it when creating database tables: /// /// let collationName = DatabaseCollation.caseInsensitiveCompare.name - /// dbQueue.execute( - /// "CREATE TABLE players (" + - /// "name TEXT COLLATE \(collationName)" + - /// ")" - /// ) + /// dbQueue.execute(sql: """ + /// CREATE TABLE players ( + /// name TEXT COLLATE \(collationName) + /// ) + /// """) public static let caseInsensitiveCompare = DatabaseCollation("swiftCaseInsensitiveCompare") { (lhs, rhs) in return lhs.caseInsensitiveCompare(rhs) } @@ -652,11 +668,11 @@ extension DatabaseCollation { /// You can use it when creating database tables: /// /// let collationName = DatabaseCollation.localizedCaseInsensitiveCompare.name - /// dbQueue.execute( - /// "CREATE TABLE players (" + - /// "name TEXT COLLATE \(collationName)" + - /// ")" - /// ) + /// dbQueue.execute(sql: """ + /// CREATE TABLE players ( + /// name TEXT COLLATE \(collationName) + /// ) + /// """) public static let localizedCaseInsensitiveCompare = DatabaseCollation("swiftLocalizedCaseInsensitiveCompare") { (lhs, rhs) in return lhs.localizedCaseInsensitiveCompare(rhs) } @@ -670,11 +686,11 @@ extension DatabaseCollation { /// You can use it when creating database tables: /// /// let collationName = DatabaseCollation.localizedCompare.name - /// dbQueue.execute( - /// "CREATE TABLE players (" + - /// "name TEXT COLLATE \(collationName)" + - /// ")" - /// ) + /// dbQueue.execute(sql: """ + /// CREATE TABLE players ( + /// name TEXT COLLATE \(collationName) + /// ) + /// """) public static let localizedCompare = DatabaseCollation("swiftLocalizedCompare") { (lhs, rhs) in return lhs.localizedCompare(rhs) } @@ -688,11 +704,11 @@ extension DatabaseCollation { /// You can use it when creating database tables: /// /// let collationName = DatabaseCollation.localizedStandardCompare.name - /// dbQueue.execute( - /// "CREATE TABLE players (" + - /// "name TEXT COLLATE \(collationName)" + - /// ")" - /// ) + /// dbQueue.execute(sql: """ + /// CREATE TABLE players ( + /// name TEXT COLLATE \(collationName) + /// ) + /// """) public static let localizedStandardCompare = DatabaseCollation("swiftLocalizedStandardCompare") { (lhs, rhs) in return lhs.localizedStandardCompare(rhs) } diff --git a/GRDB/Core/TransactionObserver.swift b/GRDB/Core/TransactionObserver.swift index 0b50b9f80..096a246e8 100644 --- a/GRDB/Core/TransactionObserver.swift +++ b/GRDB/Core/TransactionObserver.swift @@ -1,5 +1,7 @@ #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -95,11 +97,11 @@ extension Database { /// let observer = MyObserver() /// dbQueue.add(transactionObserver: observer) /// dbQueue.inDatabase { db in -/// try db.execute("BEGIN TRANSACTION") +/// try db.execute(sql: "BEGIN TRANSACTION") /// /// Then a statement is executed: /// -/// try db.execute("INSERT INTO document ...") +/// try db.execute(sql: "INSERT INTO document ...") /// /// The observation process starts when the statement is *compiled*: /// sqlite3_set_authorizer tells that the statement performs insertion into the @@ -117,7 +119,7 @@ extension Database { /// /// Now a savepoint is started: /// -/// try db.execute("SAVEPOINT foo") +/// try db.execute(sql: "SAVEPOINT foo") /// /// Statement compilation has sqlite3_set_authorizer tell that this statement /// begins a "foo" savepoint. @@ -128,7 +130,7 @@ extension Database { /// /// Then another statement is executed: /// -/// try db.execute("INSERT INTO document ...") +/// try db.execute(sql: "INSERT INTO document ...") /// /// This time, when the statement is *executed* and SQLite tells that a row has /// been inserted, the broker buffers the change event instead of immediately @@ -138,7 +140,7 @@ extension Database { /// /// The savepoint is released: /// -/// try db.execute("RELEASE SAVEPOINT foo") +/// try db.execute(sql: "RELEASE SAVEPOINT foo") /// /// Statement compilation has sqlite3_set_authorizer tell that this statement /// releases the "foo" savepoint. @@ -149,7 +151,7 @@ extension Database { /// /// Finally the transaction is committed: /// -/// try db.execute("COMMIT") +/// try db.execute(sql: "COMMIT") /// /// During the statement *execution*, SQlite tells the broker that the /// transaction is about to be committed through sqlite3_commit_hook. The broker @@ -440,8 +442,8 @@ class DatabaseObservationBroker { // SQLite, no transaction at all has started, and sqlite3_commit_hook // was not triggered: // - // try db.execute("BEGIN DEFERRED TRANSACTION") - // try db.execute("COMMIT") // <- no sqlite3_commit_hook callback invocation + // try db.execute(sql: "BEGIN DEFERRED TRANSACTION") + // try db.execute(sql: "COMMIT") // <- no sqlite3_commit_hook callback invocation // // Should we tell transaction observers of this transaction, or not? // The code says that a transaction was open, but SQLite says the @@ -517,7 +519,7 @@ class DatabaseObservationBroker { // // But we have to deal with a particular case: // - // let journalMode = String.fetchOne(db, "PRAGMA journal_mode = wal") + // let journalMode = String.fetchOne(db, sql: "PRAGMA journal_mode = wal") // // It runs a SelectStatement, not an UpdateStatement. But this not why // this case is particular. What is unexpected is that it triggers diff --git a/GRDB/FTS/FTS3.swift b/GRDB/FTS/FTS3.swift index 5098d5967..4bf3abfca 100644 --- a/GRDB/FTS/FTS3.swift +++ b/GRDB/FTS/FTS3.swift @@ -5,6 +5,25 @@ /// t.column("content") /// } public struct FTS3 : VirtualTableModule { + /// Options for Latin script characters. Matches the raw "remove_diacritics" + /// tokenizer argument. + /// + /// See https://www.sqlite.org/fts3.html + public enum Diacritics { + /// Do not remove diacritics from Latin script characters. This + /// option matches the raw "remove_diacritics=0" tokenizer argument. + case keep + /// Remove diacritics from Latin script characters. This + /// option matches the raw "remove_diacritics=1" tokenizer argument. + case removeLegacy + #if GRDBCUSTOMSQLITE + /// Remove diacritics from Latin script characters. This + /// option matches the raw "remove_diacritics=2" tokenizer argument, + /// available from SQLite 3.27.0 + case remove + #endif + } + /// Creates a FTS3 module suitable for the Database /// `create(virtualTable:using:)` method. /// diff --git a/GRDB/FTS/FTS3Pattern.swift b/GRDB/FTS/FTS3Pattern.swift index 2a2ef31ee..69c43d0e1 100644 --- a/GRDB/FTS/FTS3Pattern.swift +++ b/GRDB/FTS/FTS3Pattern.swift @@ -19,8 +19,8 @@ public struct FTS3Pattern { // that pattern. do { try DatabaseQueue().inDatabase { db in - try db.execute("CREATE VIRTUAL TABLE documents USING fts3()") - try db.execute("SELECT * FROM documents WHERE content MATCH ?", arguments: [rawPattern]) + try db.execute(sql: "CREATE VIRTUAL TABLE documents USING fts3()") + try db.execute(sql: "SELECT * FROM documents WHERE content MATCH ?", arguments: [rawPattern]) } } catch let error as DatabaseError { // Remove private SQL & arguments from the thrown error @@ -78,7 +78,7 @@ public struct FTS3Pattern { /// FTS3Pattern(matchingAnyTokenIn: "foo bar") // foo OR bar /// /// - parameter string: The string to turn into an FTS3 pattern - @available(iOS 8.2, OSX 10.10, *) + @available(OSX 10.10, *) public init?(matchingAnyTokenIn string: String) { let tokens = FTS3TokenizerDescriptor.simple.tokenize(string) guard !tokens.isEmpty else { return nil } @@ -92,7 +92,7 @@ public struct FTS3Pattern { /// FTS3Pattern(matchingAllTokensIn: "foo bar") // foo bar /// /// - parameter string: The string to turn into an FTS3 pattern - @available(iOS 8.2, OSX 10.10, *) + @available(OSX 10.10, *) public init?(matchingAllTokensIn string: String) { let tokens = FTS3TokenizerDescriptor.simple.tokenize(string) guard !tokens.isEmpty else { return nil } @@ -106,7 +106,7 @@ public struct FTS3Pattern { /// FTS3Pattern(matchingPhrase: "foo bar") // "foo bar" /// /// - parameter string: The string to turn into an FTS3 pattern - @available(iOS 8.2, OSX 10.10, *) + @available(OSX 10.10, *) public init?(matchingPhrase string: String) { let tokens = FTS3TokenizerDescriptor.simple.tokenize(string) guard !tokens.isEmpty else { return nil } diff --git a/GRDB/FTS/FTS3TokenizerDescriptor.swift b/GRDB/FTS/FTS3TokenizerDescriptor.swift index 24ce4fff9..44f667d0f 100644 --- a/GRDB/FTS/FTS3TokenizerDescriptor.swift +++ b/GRDB/FTS/FTS3TokenizerDescriptor.swift @@ -40,16 +40,16 @@ public struct FTS3TokenizerDescriptor { /// } /// /// - parameters: - /// - removeDiacritics: If true (the default), then SQLite will strip - /// diacritics from latin characters. + /// - diacritics: By default SQLite will strip diacritics from + /// latin characters. /// - separators: Unless empty (the default), SQLite will consider these /// characters as token separators. /// - tokenCharacters: Unless empty (the default), SQLite will consider /// these characters as token characters. /// /// See https://www.sqlite.org/fts3.html#tokenizer - public static func unicode61(removeDiacritics: Bool = true, separators: Set = [], tokenCharacters: Set = []) -> FTS3TokenizerDescriptor { - return _unicode61(removeDiacritics: removeDiacritics, separators: separators, tokenCharacters: tokenCharacters) + public static func unicode61(diacritics: FTS3.Diacritics = .removeLegacy, separators: Set = [], tokenCharacters: Set = []) -> FTS3TokenizerDescriptor { + return _unicode61(diacritics: diacritics, separators: separators, tokenCharacters: tokenCharacters) } #else /// The "unicode61" tokenizer. @@ -59,26 +59,33 @@ public struct FTS3TokenizerDescriptor { /// } /// /// - parameters: - /// - removeDiacritics: If true (the default), then SQLite will strip - /// diacritics from latin characters. + /// - diacritics: By default SQLite will strip diacritics from + /// latin characters. /// - separators: Unless empty (the default), SQLite will consider these /// characters as token separators. /// - tokenCharacters: Unless empty (the default), SQLite will consider /// these characters as token characters. /// /// See https://www.sqlite.org/fts3.html#tokenizer - @available(iOS 8.2, OSX 10.10, *) - public static func unicode61(removeDiacritics: Bool = true, separators: Set = [], tokenCharacters: Set = []) -> FTS3TokenizerDescriptor { + @available(OSX 10.10, *) + public static func unicode61(diacritics: FTS3.Diacritics = .removeLegacy, separators: Set = [], tokenCharacters: Set = []) -> FTS3TokenizerDescriptor { // query_only pragma was added in SQLite 3.8.0 http://www.sqlite.org/changes.html#version_3_8_0 // It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS) - return _unicode61(removeDiacritics: removeDiacritics, separators: separators, tokenCharacters: tokenCharacters) + return _unicode61(diacritics: diacritics, separators: separators, tokenCharacters: tokenCharacters) } #endif - private static func _unicode61(removeDiacritics: Bool = true, separators: Set = [], tokenCharacters: Set = []) -> FTS3TokenizerDescriptor { + private static func _unicode61(diacritics: FTS3.Diacritics, separators: Set = [], tokenCharacters: Set = []) -> FTS3TokenizerDescriptor { var arguments: [String] = [] - if !removeDiacritics { + switch diacritics { + case .removeLegacy: + break + case .keep: arguments.append("remove_diacritics=0") + #if GRDBCUSTOMSQLITE + case .remove: + arguments.append("remove_diacritics=2") + #endif } if !separators.isEmpty { // TODO: test "=" and "\"", "(" and ")" as separators, with both FTS3Pattern(matchingAnyTokenIn:tokenizer:) and Database.create(virtualTable:using:) @@ -96,7 +103,7 @@ public struct FTS3TokenizerDescriptor { return _tokenize(string) } #else - @available(iOS 8.2, OSX 10.10, *) + @available(OSX 10.10, *) func tokenize(_ string: String) -> [String] { return _tokenize(string) } @@ -116,8 +123,8 @@ public struct FTS3TokenizerDescriptor { } let tokenizerSQL = tokenizerChunks.joined(separator: ", ") // Assume fts3tokenize virtual table in an in-memory database always succeeds - try! db.execute("CREATE VIRTUAL TABLE tokens USING fts3tokenize(\(tokenizerSQL))") - return try! String.fetchAll(db, "SELECT token FROM tokens WHERE input = ? ORDER BY position", arguments: [string]) + try! db.execute(sql: "CREATE VIRTUAL TABLE tokens USING fts3tokenize(\(tokenizerSQL))") + return try! String.fetchAll(db, sql: "SELECT token FROM tokens WHERE input = ? ORDER BY position", arguments: [string]) } } } diff --git a/GRDB/FTS/FTS4.swift b/GRDB/FTS/FTS4.swift index fded83706..56dc6e0f8 100644 --- a/GRDB/FTS/FTS4.swift +++ b/GRDB/FTS/FTS4.swift @@ -110,7 +110,7 @@ public struct FTS4 : VirtualTableModule { let oldRowID = "old.\(rowIDColumn.quotedDatabaseIdentifier)" - try db.execute(""" + try db.execute(sql: """ CREATE TRIGGER \("__\(tableName)_bu".quotedDatabaseIdentifier) BEFORE UPDATE ON \(content) BEGIN DELETE FROM \(ftsTable) WHERE docid=\(oldRowID); END; @@ -127,7 +127,7 @@ public struct FTS4 : VirtualTableModule { // https://www.sqlite.org/fts3.html#*fts4rebuidcmd - try db.execute("INSERT INTO \(ftsTable)(\(ftsTable)) VALUES('rebuild')") + try db.execute(sql: "INSERT INTO \(ftsTable)(\(ftsTable)) VALUES('rebuild')") } } } @@ -288,7 +288,7 @@ public final class FTS4ColumnDefinition { /// See https://www.sqlite.org/fts3.html#the_notindexed_option /// /// - returns: Self so that you can further refine the column definition. - @available(iOS 8.2, OSX 10.10, *) + @available(OSX 10.10, *) @discardableResult public func notIndexed() -> Self { // notindexed FTS4 option was added in SQLite 3.8.0 http://www.sqlite.org/changes.html#version_3_8_0 @@ -318,7 +318,7 @@ public final class FTS4ColumnDefinition { extension Database { /// Deletes the synchronization triggers for a synchronized FTS4 table public func dropFTS4SynchronizationTriggers(forTable tableName: String) throws { - try execute(""" + try execute(sql: """ DROP TRIGGER IF EXISTS \("__\(tableName)_bu".quotedDatabaseIdentifier); DROP TRIGGER IF EXISTS \("__\(tableName)_bd".quotedDatabaseIdentifier); DROP TRIGGER IF EXISTS \("__\(tableName)_au".quotedDatabaseIdentifier); diff --git a/GRDB/FTS/FTS5.swift b/GRDB/FTS/FTS5.swift index fc974b19b..d78c52a7c 100644 --- a/GRDB/FTS/FTS5.swift +++ b/GRDB/FTS/FTS5.swift @@ -1,5 +1,42 @@ #if SQLITE_ENABLE_FTS5 - /// FTS5 lets you define "fts5" virtual tables. +#if SWIFT_PACKAGE + import CSQLite +#elseif GRDBCIPHER + import SQLCipher +#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER + import SQLite3 +#endif + +/// FTS5 lets you define "fts5" virtual tables. +/// +/// // CREATE VIRTUAL TABLE document USING fts5(content) +/// try db.create(virtualTable: "document", using: FTS5()) { t in +/// t.column("content") +/// } +/// +/// See https://www.sqlite.org/fts5.html +public struct FTS5 : VirtualTableModule { + /// Options for Latin script characters. Matches the raw "remove_diacritics" + /// tokenizer argument. + /// + /// See https://www.sqlite.org/fts5.html + public enum Diacritics { + /// Do not remove diacritics from Latin script characters. This + /// option matches the raw "remove_diacritics=0" tokenizer argument. + case keep + /// Remove diacritics from Latin script characters. This + /// option matches the raw "remove_diacritics=1" tokenizer argument. + case removeLegacy + #if GRDBCUSTOMSQLITE + /// Remove diacritics from Latin script characters. This + /// option matches the raw "remove_diacritics=2" tokenizer argument, + /// available from SQLite 3.27.0 + case remove + #endif + } + + /// Creates a FTS5 module suitable for the Database + /// `create(virtualTable:using:)` method. /// /// // CREATE VIRTUAL TABLE document USING fts5(content) /// try db.create(virtualTable: "document", using: FTS5()) { t in @@ -7,391 +44,364 @@ /// } /// /// See https://www.sqlite.org/fts5.html - public struct FTS5 : VirtualTableModule { + public init() { + } + + // MARK: - VirtualTableModule Adoption + + /// The virtual table module name + public let moduleName = "fts5" + + /// Don't use this method. + public func makeTableDefinition() -> FTS5TableDefinition { + return FTS5TableDefinition() + } + + /// Don't use this method. + public func moduleArguments(for definition: FTS5TableDefinition, in db: Database) throws -> [String] { + var arguments: [String] = [] - /// Creates a FTS5 module suitable for the Database - /// `create(virtualTable:using:)` method. - /// - /// // CREATE VIRTUAL TABLE document USING fts5(content) - /// try db.create(virtualTable: "document", using: FTS5()) { t in - /// t.column("content") - /// } - /// - /// See https://www.sqlite.org/fts5.html - public init() { + if definition.columns.isEmpty { + // Programmer error + fatalError("FTS5 virtual table requires at least one column.") } - // MARK: - VirtualTableModule Adoption - - /// The virtual table module name - public let moduleName = "fts5" - - /// Don't use this method. - public func makeTableDefinition() -> FTS5TableDefinition { - return FTS5TableDefinition() - } - - /// Don't use this method. - public func moduleArguments(for definition: FTS5TableDefinition, in db: Database) throws -> [String] { - var arguments: [String] = [] - - if definition.columns.isEmpty { - // Programmer error - fatalError("FTS5 virtual table requires at least one column.") - } - - for column in definition.columns { - if column.isIndexed { - arguments.append("\(column.name)") - } else { - arguments.append("\(column.name) UNINDEXED") - } - } - - if let tokenizer = definition.tokenizer { - arguments.append("tokenize=\(tokenizer.components.joined(separator: " ").sqlExpression.sql)") - } - - switch definition.contentMode { - case .raw(let content, let contentRowID): - if let content = content { - arguments.append("content=\(content.sqlExpression.sql)") - } - if let contentRowID = contentRowID { - arguments.append("content_rowid=\(contentRowID.sqlExpression.sql)") - } - case .synchronized(let contentTable): - arguments.append("content=\(contentTable.sqlExpression.sql)") - if let rowIDColumn = try db.primaryKey(contentTable).rowIDColumn { - arguments.append("content_rowid=\(rowIDColumn.sqlExpression.sql)") - } - } - - - if let prefixes = definition.prefixes { - arguments.append("prefix=\(prefixes.sorted().map { "\($0)" }.joined(separator: " ").sqlExpression.sql)") - } - - if let columnSize = definition.columnSize { - arguments.append("columnSize=\(columnSize)") - } - - if let detail = definition.detail { - arguments.append("detail=\(detail)") - } - - return arguments - } - - /// Reserved; part of the VirtualTableModule protocol. - /// - /// See Database.create(virtualTable:using:) - public func database(_ db: Database, didCreate tableName: String, using definition: FTS5TableDefinition) throws { - switch definition.contentMode { - case .raw: - break - case .synchronized(let contentTable): - // https://sqlite.org/fts5.html#external_content_tables - - let rowIDColumn = try db.primaryKey(contentTable).rowIDColumn ?? Column.rowID.name - let ftsTable = tableName.quotedDatabaseIdentifier - let content = contentTable.quotedDatabaseIdentifier - let indexedColumns = definition.columns.map { $0.name } - - let ftsColumns = (["rowid"] + indexedColumns) - .map { $0.quotedDatabaseIdentifier } - .joined(separator: ", ") - - let newContentColumns = ([rowIDColumn] + indexedColumns) - .map { "new.\($0.quotedDatabaseIdentifier)" } - .joined(separator: ", ") - - let oldContentColumns = ([rowIDColumn] + indexedColumns) - .map { "old.\($0.quotedDatabaseIdentifier)" } - .joined(separator: ", ") - - try db.execute(""" - CREATE TRIGGER \("__\(tableName)_ai".quotedDatabaseIdentifier) AFTER INSERT ON \(content) BEGIN - INSERT INTO \(ftsTable)(\(ftsColumns)) VALUES (\(newContentColumns)); - END; - CREATE TRIGGER \("__\(tableName)_ad".quotedDatabaseIdentifier) AFTER DELETE ON \(content) BEGIN - INSERT INTO \(ftsTable)(\(ftsTable), \(ftsColumns)) VALUES('delete', \(oldContentColumns)); - END; - CREATE TRIGGER \("__\(tableName)_au".quotedDatabaseIdentifier) AFTER UPDATE ON \(content) BEGIN - INSERT INTO \(ftsTable)(\(ftsTable), \(ftsColumns)) VALUES('delete', \(oldContentColumns)); - INSERT INTO \(ftsTable)(\(ftsColumns)) VALUES (\(newContentColumns)); - END; - """) - - // https://sqlite.org/fts5.html#the_rebuild_command - - try db.execute("INSERT INTO \(ftsTable)(\(ftsTable)) VALUES('rebuild')") + for column in definition.columns { + if column.isIndexed { + arguments.append("\(column.name)") + } else { + arguments.append("\(column.name) UNINDEXED") } } - static func api(_ db: Database) -> UnsafePointer { - // Access to FTS5 is one of the rare SQLite api which was broken in - // SQLite 3.20.0+, for security reasons: - // - // Starting SQLite 3.20.0+, we need to use the new sqlite3_bind_pointer api. - // The previous way to access FTS5 does not work any longer. - // - // So let's see which SQLite version we are linked against: - - #if GRDBCUSTOMSQLITE || GRDBCIPHER - // GRDB is linked against SQLCipher or a custom SQLite build: SQLite 3.20.0 or more. - return api_v2(db, sqlite3_prepare_v3, sqlite3_bind_pointer) - #else - // GRDB is linked against the system SQLite. - // - // Do we use SQLite 3.19.3 (iOS 11.4), or SQLite 3.24.0 (iOS 12.0)? - // We need to check for available(iOS 12.0, OSX 10.14, watchOS 5.0, *). - // - // This test requires the Swift 4.2 compiler. - // - // It does not need the Swift 4.2 language, though: the Swift 4.2 - // compiler running in Swift 4.0 compatibility mode is OK. - // - // On top of that, we want to preserve compatibility with Xcode 9.3+. - // - // So let's check exactly which compiler version we are using. - // - // Fortunately, this horribly complex check has been solved - // by @hartbit: see https://forums.swift.org/t/compiler-version-directive/11952 - // and https://github.com/hartbit/swift-evolution/blob/compiler-directive/proposals/XXXX-compiler-version-directive.md - #if swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0)) - if #available(iOS 12.0, OSX 10.14, watchOS 5.0, *) { - // SQLite 3.24.0 or more - // setup: Xcode 10.0, SWIFT_VERSION = 4.0, iOS 12 - // setup: Xcode 10.0, SWIFT_VERSION = 4.2, iOS 12 - return api_v2(db, sqlite3_prepare_v3, sqlite3_bind_pointer) - } else { - // SQLite 3.19.3 or less - // setup: Xcode 10.0, SWIFT_VERSION = 4.0, iOS 11 - // setup: Xcode 10.0, SWIFT_VERSION = 4.2, iOS 11 - return api_v1(db) - } - #else - // SQLite 3.19.3 or less - // setup: Xcode 9.4.1, iOS 11 - return api_v1(db) - #endif - #endif + if let tokenizer = definition.tokenizer { + arguments.append("tokenize=\(tokenizer.components.joined(separator: " ").sqlExpression.quotedSQL())") } - private static func api_v1(_ db: Database) -> UnsafePointer { - guard let data = try! Data.fetchOne(db, "SELECT fts5()") else { - fatalError("FTS5 is not available") + switch definition.contentMode { + case .raw(let content, let contentRowID): + if let content = content { + arguments.append("content=\(content.sqlExpression.quotedSQL())") + } + if let contentRowID = contentRowID { + arguments.append("content_rowid=\(contentRowID.sqlExpression.quotedSQL())") + } + case .synchronized(let contentTable): + arguments.append("content=\(contentTable.sqlExpression.quotedSQL())") + if let rowIDColumn = try db.primaryKey(contentTable).rowIDColumn { + arguments.append("content_rowid=\(rowIDColumn.sqlExpression.quotedSQL())") } - return data.withUnsafeBytes { $0.pointee } } - // Technique given by Jordan Rose: - // https://forums.swift.org/t/c-interoperability-combinations-of-library-and-os-versions/14029/4 - private static func api_v2( - _ db: Database, - _ sqlite3_prepare_v3: @convention(c) (OpaquePointer?, UnsafePointer?, Int32, UInt32, UnsafeMutablePointer?, UnsafeMutablePointer?>?) -> Int32, - _ sqlite3_bind_pointer: @convention(c) (OpaquePointer?, Int32, UnsafeMutableRawPointer?, UnsafePointer?, (@convention(c) (UnsafeMutableRawPointer?) -> Void)?) -> Int32) - -> UnsafePointer - { - let sqliteConnection = db.sqliteConnection - var statement: SQLiteStatement? = nil - var api: UnsafePointer? = nil - let type: StaticString = "fts5_api_ptr" + + if let prefixes = definition.prefixes { + arguments.append("prefix=\(prefixes.sorted().map { "\($0)" }.joined(separator: " ").sqlExpression.quotedSQL())") + } + + if let columnSize = definition.columnSize { + arguments.append("columnSize=\(columnSize)") + } + + if let detail = definition.detail { + arguments.append("detail=\(detail)") + } + + return arguments + } + + /// Reserved; part of the VirtualTableModule protocol. + /// + /// See Database.create(virtualTable:using:) + public func database(_ db: Database, didCreate tableName: String, using definition: FTS5TableDefinition) throws { + switch definition.contentMode { + case .raw: + break + case .synchronized(let contentTable): + // https://sqlite.org/fts5.html#external_content_tables - let code = sqlite3_prepare_v3(db.sqliteConnection, "SELECT fts5(?)", -1, 0, &statement, nil) - guard code == SQLITE_OK else { - fatalError("FTS5 is not available") - } - defer { sqlite3_finalize(statement) } - type.utf8Start.withMemoryRebound(to: Int8.self, capacity: type.utf8CodeUnitCount) { typePointer in - _ = sqlite3_bind_pointer(statement, 1, &api, typePointer, nil) - } - sqlite3_step(statement) - guard let result = api else { - fatalError("FTS5 is not available") - } - return result + let rowIDColumn = try db.primaryKey(contentTable).rowIDColumn ?? Column.rowID.name + let ftsTable = tableName.quotedDatabaseIdentifier + let content = contentTable.quotedDatabaseIdentifier + let indexedColumns = definition.columns.map { $0.name } + + let ftsColumns = (["rowid"] + indexedColumns) + .map { $0.quotedDatabaseIdentifier } + .joined(separator: ", ") + + let newContentColumns = ([rowIDColumn] + indexedColumns) + .map { "new.\($0.quotedDatabaseIdentifier)" } + .joined(separator: ", ") + + let oldContentColumns = ([rowIDColumn] + indexedColumns) + .map { "old.\($0.quotedDatabaseIdentifier)" } + .joined(separator: ", ") + + try db.execute(sql: """ + CREATE TRIGGER \("__\(tableName)_ai".quotedDatabaseIdentifier) AFTER INSERT ON \(content) BEGIN + INSERT INTO \(ftsTable)(\(ftsColumns)) VALUES (\(newContentColumns)); + END; + CREATE TRIGGER \("__\(tableName)_ad".quotedDatabaseIdentifier) AFTER DELETE ON \(content) BEGIN + INSERT INTO \(ftsTable)(\(ftsTable), \(ftsColumns)) VALUES('delete', \(oldContentColumns)); + END; + CREATE TRIGGER \("__\(tableName)_au".quotedDatabaseIdentifier) AFTER UPDATE ON \(content) BEGIN + INSERT INTO \(ftsTable)(\(ftsTable), \(ftsColumns)) VALUES('delete', \(oldContentColumns)); + INSERT INTO \(ftsTable)(\(ftsColumns)) VALUES (\(newContentColumns)); + END; + """) + + // https://sqlite.org/fts5.html#the_rebuild_command + + try db.execute(sql: "INSERT INTO \(ftsTable)(\(ftsTable)) VALUES('rebuild')") } } - /// The FTS5TableDefinition class lets you define columns of a FTS5 virtual table. + static func api(_ db: Database) -> UnsafePointer { + // Access to FTS5 is one of the rare SQLite api which was broken in + // SQLite 3.20.0+, for security reasons: + // + // Starting SQLite 3.20.0+, we need to use the new sqlite3_bind_pointer api. + // The previous way to access FTS5 does not work any longer. + // + // So let's see which SQLite version we are linked against: + + #if GRDBCUSTOMSQLITE || GRDBCIPHER + // GRDB is linked against SQLCipher or a custom SQLite build: SQLite 3.20.0 or more. + return api_v2(db, sqlite3_prepare_v3, sqlite3_bind_pointer) + #else + // GRDB is linked against the system SQLite. + // + // Do we use SQLite 3.19.3 (iOS 11.4), or SQLite 3.24.0 (iOS 12.0)? + if #available(iOS 12.0, OSX 10.14, watchOS 5.0, *) { + // SQLite 3.24.0 or more + return api_v2(db, sqlite3_prepare_v3, sqlite3_bind_pointer) + } else { + // SQLite 3.19.3 or less + return api_v1(db) + } + #endif + } + + private static func api_v1(_ db: Database) -> UnsafePointer { + guard let data = try! Data.fetchOne(db, sql: "SELECT fts5()") else { + fatalError("FTS5 is not available") + } + #if swift(>=5.0) + return data.withUnsafeBytes { + $0.bindMemory(to: UnsafePointer.self).first! + } + #else + return data.withUnsafeBytes { + $0.pointee + } + #endif + } + + // Technique given by Jordan Rose: + // https://forums.swift.org/t/c-interoperability-combinations-of-library-and-os-versions/14029/4 + private static func api_v2( + _ db: Database, + _ sqlite3_prepare_v3: @convention(c) (OpaquePointer?, UnsafePointer?, Int32, UInt32, UnsafeMutablePointer?, UnsafeMutablePointer?>?) -> Int32, + _ sqlite3_bind_pointer: @convention(c) (OpaquePointer?, Int32, UnsafeMutableRawPointer?, UnsafePointer?, (@convention(c) (UnsafeMutableRawPointer?) -> Void)?) -> Int32) + -> UnsafePointer + { + let sqliteConnection = db.sqliteConnection + var statement: SQLiteStatement? = nil + var api: UnsafePointer? = nil + let type: StaticString = "fts5_api_ptr" + + let code = sqlite3_prepare_v3(db.sqliteConnection, "SELECT fts5(?)", -1, 0, &statement, nil) + guard code == SQLITE_OK else { + fatalError("FTS5 is not available") + } + defer { sqlite3_finalize(statement) } + type.utf8Start.withMemoryRebound(to: Int8.self, capacity: type.utf8CodeUnitCount) { typePointer in + _ = sqlite3_bind_pointer(statement, 1, &api, typePointer, nil) + } + sqlite3_step(statement) + guard let result = api else { + fatalError("FTS5 is not available") + } + return result + } +} + +/// The FTS5TableDefinition class lets you define columns of a FTS5 virtual table. +/// +/// You don't create instances of this class. Instead, you use the Database +/// `create(virtualTable:using:)` method: +/// +/// try db.create(virtualTable: "document", using: FTS5()) { t in // t is FTS5TableDefinition +/// t.column("content") +/// } +/// +/// See https://www.sqlite.org/fts5.html +public final class FTS5TableDefinition { + enum ContentMode { + case raw(content: String?, contentRowID: String?) + case synchronized(contentTable: String) + } + + fileprivate var columns: [FTS5ColumnDefinition] = [] + fileprivate var contentMode: ContentMode = .raw(content: nil, contentRowID: nil) + + /// The virtual table tokenizer /// - /// You don't create instances of this class. Instead, you use the Database - /// `create(virtualTable:using:)` method: + /// try db.create(virtualTable: "document", using: FTS5()) { t in + /// t.tokenizer = .porter() + /// } /// - /// try db.create(virtualTable: "document", using: FTS5()) { t in // t is FTS5TableDefinition + /// See https://www.sqlite.org/fts5.html#fts5_table_creation_and_initialization + public var tokenizer: FTS5TokenizerDescriptor? + + /// The FTS5 `content` option + /// + /// When you want the full-text table to be synchronized with the + /// content of an external table, prefer the `synchronize(withTable:)` + /// method. + /// + /// Setting this property invalidates any synchronization previously + /// established with the `synchronize(withTable:)` method. + /// + /// See https://www.sqlite.org/fts5.html#external_content_and_contentless_tables + public var content: String? { + get { + switch contentMode { + case .raw(let content, _): + return content + case .synchronized(let contentTable): + return contentTable + } + } + set { + switch contentMode { + case .raw(_, let contentRowID): + contentMode = .raw(content: newValue, contentRowID: contentRowID) + case .synchronized: + contentMode = .raw(content: newValue, contentRowID: nil) + } + } + } + + /// The FTS5 `content_rowid` option + /// + /// When you want the full-text table to be synchronized with the + /// content of an external table, prefer the `synchronize(withTable:)` + /// method. + /// + /// Setting this property invalidates any synchronization previously + /// established with the `synchronize(withTable:)` method. + /// + /// See https://sqlite.org/fts5.html#external_content_tables + public var contentRowID: String? { + get { + switch contentMode { + case .raw(_, let contentRowID): + return contentRowID + case .synchronized: + return nil + } + } + set { + switch contentMode { + case .raw(let content, _): + contentMode = .raw(content: content, contentRowID: newValue) + case .synchronized: + contentMode = .raw(content: nil, contentRowID: newValue) + } + } + } + + /// Support for the FTS5 `prefix` option + /// + /// See https://www.sqlite.org/fts5.html#prefix_indexes + public var prefixes: Set? + + /// Support for the FTS5 `columnsize` option + /// + /// https://www.sqlite.org/fts5.html#the_columnsize_option + public var columnSize: Int? + + /// Support for the FTS5 `detail` option + /// + /// https://www.sqlite.org/fts5.html#the_detail_option + public var detail: String? + + /// Appends a table column. + /// + /// try db.create(virtualTable: "document", using: FTS5()) { t in /// t.column("content") /// } /// - /// See https://www.sqlite.org/fts5.html - public final class FTS5TableDefinition { - enum ContentMode { - case raw(content: String?, contentRowID: String?) - case synchronized(contentTable: String) - } - - fileprivate var columns: [FTS5ColumnDefinition] = [] - fileprivate var contentMode: ContentMode = .raw(content: nil, contentRowID: nil) - - /// The virtual table tokenizer - /// - /// try db.create(virtualTable: "document", using: FTS5()) { t in - /// t.tokenizer = .porter() - /// } - /// - /// See https://www.sqlite.org/fts5.html#fts5_table_creation_and_initialization - public var tokenizer: FTS5TokenizerDescriptor? - - /// The FTS5 `content` option - /// - /// When you want the full-text table to be synchronized with the - /// content of an external table, prefer the `synchronize(withTable:)` - /// method. - /// - /// Setting this property invalidates any synchronization previously - /// established with the `synchronize(withTable:)` method. - /// - /// See https://www.sqlite.org/fts5.html#external_content_and_contentless_tables - public var content: String? { - get { - switch contentMode { - case .raw(let content, _): - return content - case .synchronized(let contentTable): - return contentTable - } - } - set { - switch contentMode { - case .raw(_, let contentRowID): - contentMode = .raw(content: newValue, contentRowID: contentRowID) - case .synchronized: - contentMode = .raw(content: newValue, contentRowID: nil) - } - } - } - - /// The FTS5 `content_rowid` option - /// - /// When you want the full-text table to be synchronized with the - /// content of an external table, prefer the `synchronize(withTable:)` - /// method. - /// - /// Setting this property invalidates any synchronization previously - /// established with the `synchronize(withTable:)` method. - /// - /// See https://sqlite.org/fts5.html#external_content_tables - public var contentRowID: String? { - get { - switch contentMode { - case .raw(_, let contentRowID): - return contentRowID - case .synchronized: - return nil - } - } - set { - switch contentMode { - case .raw(let content, _): - contentMode = .raw(content: content, contentRowID: newValue) - case .synchronized: - contentMode = .raw(content: nil, contentRowID: newValue) - } - } - } - - /// Support for the FTS5 `prefix` option - /// - /// See https://www.sqlite.org/fts5.html#prefix_indexes - public var prefixes: Set? - - /// Support for the FTS5 `columnsize` option - /// - /// https://www.sqlite.org/fts5.html#the_columnsize_option - public var columnSize: Int? - - /// Support for the FTS5 `detail` option - /// - /// https://www.sqlite.org/fts5.html#the_detail_option - public var detail: String? - - /// Appends a table column. - /// - /// try db.create(virtualTable: "document", using: FTS5()) { t in - /// t.column("content") - /// } - /// - /// - parameter name: the column name. - @discardableResult - public func column(_ name: String) -> FTS5ColumnDefinition { - let column = FTS5ColumnDefinition(name: name) - columns.append(column) - return column - } - - /// Synchronizes the full-text table with the content of an external - /// table. - /// - /// The full-text table is initially populated with the existing - /// content in the external table. SQL triggers make sure that the - /// full-text table is kept up to date with the external table. - /// - /// See https://sqlite.org/fts5.html#external_content_tables - public func synchronize(withTable tableName: String) { - contentMode = .synchronized(contentTable: tableName) - } + /// - parameter name: the column name. + @discardableResult + public func column(_ name: String) -> FTS5ColumnDefinition { + let column = FTS5ColumnDefinition(name: name) + columns.append(column) + return column } - /// The FTS5ColumnDefinition class lets you refine a column of an FTS5 - /// virtual table. + /// Synchronizes the full-text table with the content of an external + /// table. /// - /// You get instances of this class when you create an FTS5 table: + /// The full-text table is initially populated with the existing + /// content in the external table. SQL triggers make sure that the + /// full-text table is kept up to date with the external table. + /// + /// See https://sqlite.org/fts5.html#external_content_tables + public func synchronize(withTable tableName: String) { + contentMode = .synchronized(contentTable: tableName) + } +} + +/// The FTS5ColumnDefinition class lets you refine a column of an FTS5 +/// virtual table. +/// +/// You get instances of this class when you create an FTS5 table: +/// +/// try db.create(virtualTable: "document", using: FTS5()) { t in +/// t.column("content") // FTS5ColumnDefinition +/// } +/// +/// See https://www.sqlite.org/fts5.html +public final class FTS5ColumnDefinition { + fileprivate let name: String + fileprivate var isIndexed: Bool + + init(name: String) { + self.name = name + self.isIndexed = true + } + + /// Excludes the column from the full-text index. /// /// try db.create(virtualTable: "document", using: FTS5()) { t in - /// t.column("content") // FTS5ColumnDefinition + /// t.column("a") + /// t.column("b").notIndexed() /// } /// - /// See https://www.sqlite.org/fts5.html - public final class FTS5ColumnDefinition { - fileprivate let name: String - fileprivate var isIndexed: Bool - - init(name: String) { - self.name = name - self.isIndexed = true - } - - /// Excludes the column from the full-text index. - /// - /// try db.create(virtualTable: "document", using: FTS5()) { t in - /// t.column("a") - /// t.column("b").notIndexed() - /// } - /// - /// See https://www.sqlite.org/fts5.html#the_unindexed_column_option - /// - /// - returns: Self so that you can further refine the column definition. - @discardableResult - public func notIndexed() -> Self { - self.isIndexed = false - return self - } - } - - extension Column { - /// The FTS5 rank column - public static let rank = Column("rank") + /// See https://www.sqlite.org/fts5.html#the_unindexed_column_option + /// + /// - returns: Self so that you can further refine the column definition. + @discardableResult + public func notIndexed() -> Self { + self.isIndexed = false + return self } +} - extension Database { - /// Deletes the synchronization triggers for a synchronized FTS5 table - public func dropFTS5SynchronizationTriggers(forTable tableName: String) throws { - try execute(""" - DROP TRIGGER IF EXISTS \("__\(tableName)_ai".quotedDatabaseIdentifier); - DROP TRIGGER IF EXISTS \("__\(tableName)_ad".quotedDatabaseIdentifier); - DROP TRIGGER IF EXISTS \("__\(tableName)_au".quotedDatabaseIdentifier); - """) - } +extension Column { + /// The FTS5 rank column + public static let rank = Column("rank") +} + +extension Database { + /// Deletes the synchronization triggers for a synchronized FTS5 table + public func dropFTS5SynchronizationTriggers(forTable tableName: String) throws { + try execute(sql: """ + DROP TRIGGER IF EXISTS \("__\(tableName)_ai".quotedDatabaseIdentifier); + DROP TRIGGER IF EXISTS \("__\(tableName)_ad".quotedDatabaseIdentifier); + DROP TRIGGER IF EXISTS \("__\(tableName)_au".quotedDatabaseIdentifier); + """) } +} #endif diff --git a/GRDB/FTS/FTS5CustomTokenizer.swift b/GRDB/FTS/FTS5CustomTokenizer.swift index b7834e225..9d3a54570 100644 --- a/GRDB/FTS/FTS5CustomTokenizer.swift +++ b/GRDB/FTS/FTS5CustomTokenizer.swift @@ -1,153 +1,161 @@ #if SQLITE_ENABLE_FTS5 - /// The protocol for custom FTS5 tokenizers. - public protocol FTS5CustomTokenizer : FTS5Tokenizer { - /// The name of the tokenizer; should uniquely identify your custom - /// tokenizer. - static var name: String { get } - - /// Creates a custom tokenizer. - /// - /// The arguments parameter is an array of String built from the CREATE - /// VIRTUAL TABLE statement. In the example below, the arguments will - /// be `["arg1", "arg2"]`. - /// - /// CREATE VIRTUAL TABLE document USING fts5( - /// tokenize='custom arg1 arg2' - /// ) - /// - /// - parameter db: A Database connection - /// - parameter arguments: An array of string arguments - init(db: Database, arguments: [String]) throws - } - - extension FTS5CustomTokenizer { - - /// Creates an FTS5 tokenizer descriptor. - /// - /// class MyTokenizer : FTS5CustomTokenizer { ... } - /// - /// db.create(virtualTable: "book", using: FTS5()) { t in - /// let tokenizer = MyTokenizer.tokenizerDescriptor(arguments: ["unicode61", "remove_diacritics", "0"]) - /// t.tokenizer = tokenizer - /// } - public static func tokenizerDescriptor(arguments: [String] = []) -> FTS5TokenizerDescriptor { - return FTS5TokenizerDescriptor(components: [name] + arguments) - } - - } - - extension Database { - - // MARK: - FTS5 - - private class FTS5TokenizerConstructor { - let db: Database - let constructor: (Database, [String], UnsafeMutablePointer?) -> Int32 - - init(db: Database, constructor: @escaping (Database, [String], UnsafeMutablePointer?) -> Int32) { - self.db = db - self.constructor = constructor - } - } - - /// Add a custom FTS5 tokenizer. - /// - /// class MyTokenizer : FTS5CustomTokenizer { ... } - /// db.add(tokenizer: MyTokenizer.self) - public func add(tokenizer: Tokenizer.Type) { - let api = FTS5.api(self) - - // Swift won't let the @convention(c) xCreate() function below create - // an instance of the generic Tokenizer type. - // - // We thus hide the generic Tokenizer type inside a neutral type: - // FTS5TokenizerConstructor - let constructor = FTS5TokenizerConstructor( - db: self, - constructor: { (db, arguments, tokenizerHandle) in - guard let tokenizerHandle = tokenizerHandle else { - return SQLITE_ERROR - } - do { - let tokenizer = try Tokenizer(db: db, arguments: arguments) - - // Tokenizer must remain alive until xDeleteTokenizer() - // is called, as the xDelete member of xTokenizer - let tokenizerPointer = OpaquePointer(Unmanaged.passRetained(tokenizer).toOpaque()) - - tokenizerHandle.pointee = tokenizerPointer - return SQLITE_OK - } catch let error as DatabaseError { - return error.extendedResultCode.rawValue - } catch { - return SQLITE_ERROR - } - }) - - // Constructor must remain alive until deleteConstructor() is - // called, as the last argument of the xCreateTokenizer() function. - let constructorPointer = Unmanaged.passRetained(constructor).toOpaque() - - func deleteConstructor(constructorPointer: UnsafeMutableRawPointer?) { - guard let constructorPointer = constructorPointer else { return } - Unmanaged.fromOpaque(constructorPointer).release() - } - - func xCreateTokenizer(constructorPointer: UnsafeMutableRawPointer?, azArg: UnsafeMutablePointer?>?, nArg: Int32, tokenizerHandle: UnsafeMutablePointer?) -> Int32 { - guard let constructorPointer = constructorPointer else { - return SQLITE_ERROR - } - let constructor = Unmanaged.fromOpaque(constructorPointer).takeUnretainedValue() - var arguments: [String] = [] - if let azArg = azArg { - for i in 0...fromOpaque(UnsafeMutableRawPointer(tokenizerPointer)).release() - } - - func xTokenize(tokenizerPointer: OpaquePointer?, context: UnsafeMutableRawPointer?, flags: Int32, pText: UnsafePointer?, nText: Int32, tokenCallback: (@convention(c) (UnsafeMutableRawPointer?, Int32, UnsafePointer?, Int32, Int32, Int32) -> Int32)?) -> Int32 { - guard let tokenizerPointer = tokenizerPointer else { - return SQLITE_ERROR - } - let object = Unmanaged.fromOpaque(UnsafeMutableRawPointer(tokenizerPointer)).takeUnretainedValue() - guard let tokenizer = object as? FTS5Tokenizer else { - return SQLITE_ERROR - } - return tokenizer.tokenize(context: context, tokenization: FTS5Tokenization(rawValue: flags), pText: pText, nText: nText, tokenCallback: tokenCallback!) - } - - var xTokenizer = fts5_tokenizer(xCreate: xCreateTokenizer, xDelete: xDeleteTokenizer, xTokenize: xTokenize) - let code = withUnsafeMutablePointer(to: &xTokenizer) { xTokenizerPointer in - api.pointee.xCreateTokenizer(UnsafeMutablePointer(mutating: api), Tokenizer.name, constructorPointer, xTokenizerPointer, deleteConstructor) - } - guard code == SQLITE_OK else { - // Assume a GRDB bug: there is no point throwing any error. - fatalError(DatabaseError(resultCode: code, message: lastErrorMessage).description) - } - } - } - - extension DatabaseQueue { - - // MARK: - Custom FTS5 Tokenizers - - /// Add a custom FTS5 tokenizer. - /// - /// class MyTokenizer : FTS5CustomTokenizer { ... } - /// dbQueue.add(tokenizer: MyTokenizer.self) - public func add(tokenizer: Tokenizer.Type) { - inDatabase { db in - db.add(tokenizer: Tokenizer.self) - } - } - } +#if SWIFT_PACKAGE + import CSQLite +#elseif GRDBCIPHER + import SQLCipher +#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER + import SQLite3 +#endif + +/// The protocol for custom FTS5 tokenizers. +public protocol FTS5CustomTokenizer : FTS5Tokenizer { + /// The name of the tokenizer; should uniquely identify your custom + /// tokenizer. + static var name: String { get } + + /// Creates a custom tokenizer. + /// + /// The arguments parameter is an array of String built from the CREATE + /// VIRTUAL TABLE statement. In the example below, the arguments will + /// be `["arg1", "arg2"]`. + /// + /// CREATE VIRTUAL TABLE document USING fts5( + /// tokenize='custom arg1 arg2' + /// ) + /// + /// - parameter db: A Database connection + /// - parameter arguments: An array of string arguments + init(db: Database, arguments: [String]) throws +} + +extension FTS5CustomTokenizer { + + /// Creates an FTS5 tokenizer descriptor. + /// + /// class MyTokenizer : FTS5CustomTokenizer { ... } + /// + /// db.create(virtualTable: "book", using: FTS5()) { t in + /// let tokenizer = MyTokenizer.tokenizerDescriptor(arguments: ["unicode61", "remove_diacritics", "0"]) + /// t.tokenizer = tokenizer + /// } + public static func tokenizerDescriptor(arguments: [String] = []) -> FTS5TokenizerDescriptor { + return FTS5TokenizerDescriptor(components: [name] + arguments) + } + +} + +extension Database { + + // MARK: - FTS5 + + private class FTS5TokenizerConstructor { + let db: Database + let constructor: (Database, [String], UnsafeMutablePointer?) -> Int32 + + init(db: Database, constructor: @escaping (Database, [String], UnsafeMutablePointer?) -> Int32) { + self.db = db + self.constructor = constructor + } + } + + /// Add a custom FTS5 tokenizer. + /// + /// class MyTokenizer : FTS5CustomTokenizer { ... } + /// db.add(tokenizer: MyTokenizer.self) + public func add(tokenizer: Tokenizer.Type) { + let api = FTS5.api(self) + + // Swift won't let the @convention(c) xCreate() function below create + // an instance of the generic Tokenizer type. + // + // We thus hide the generic Tokenizer type inside a neutral type: + // FTS5TokenizerConstructor + let constructor = FTS5TokenizerConstructor( + db: self, + constructor: { (db, arguments, tokenizerHandle) in + guard let tokenizerHandle = tokenizerHandle else { + return SQLITE_ERROR + } + do { + let tokenizer = try Tokenizer(db: db, arguments: arguments) + + // Tokenizer must remain alive until xDeleteTokenizer() + // is called, as the xDelete member of xTokenizer + let tokenizerPointer = OpaquePointer(Unmanaged.passRetained(tokenizer).toOpaque()) + + tokenizerHandle.pointee = tokenizerPointer + return SQLITE_OK + } catch let error as DatabaseError { + return error.extendedResultCode.rawValue + } catch { + return SQLITE_ERROR + } + }) + + // Constructor must remain alive until deleteConstructor() is + // called, as the last argument of the xCreateTokenizer() function. + let constructorPointer = Unmanaged.passRetained(constructor).toOpaque() + + func deleteConstructor(constructorPointer: UnsafeMutableRawPointer?) { + guard let constructorPointer = constructorPointer else { return } + Unmanaged.fromOpaque(constructorPointer).release() + } + + func xCreateTokenizer(constructorPointer: UnsafeMutableRawPointer?, azArg: UnsafeMutablePointer?>?, nArg: Int32, tokenizerHandle: UnsafeMutablePointer?) -> Int32 { + guard let constructorPointer = constructorPointer else { + return SQLITE_ERROR + } + let constructor = Unmanaged.fromOpaque(constructorPointer).takeUnretainedValue() + var arguments: [String] = [] + if let azArg = azArg { + for i in 0...fromOpaque(UnsafeMutableRawPointer(tokenizerPointer)).release() + } + + func xTokenize(tokenizerPointer: OpaquePointer?, context: UnsafeMutableRawPointer?, flags: Int32, pText: UnsafePointer?, nText: Int32, tokenCallback: (@convention(c) (UnsafeMutableRawPointer?, Int32, UnsafePointer?, Int32, Int32, Int32) -> Int32)?) -> Int32 { + guard let tokenizerPointer = tokenizerPointer else { + return SQLITE_ERROR + } + let object = Unmanaged.fromOpaque(UnsafeMutableRawPointer(tokenizerPointer)).takeUnretainedValue() + guard let tokenizer = object as? FTS5Tokenizer else { + return SQLITE_ERROR + } + return tokenizer.tokenize(context: context, tokenization: FTS5Tokenization(rawValue: flags), pText: pText, nText: nText, tokenCallback: tokenCallback!) + } + + var xTokenizer = fts5_tokenizer(xCreate: xCreateTokenizer, xDelete: xDeleteTokenizer, xTokenize: xTokenize) + let code = withUnsafeMutablePointer(to: &xTokenizer) { xTokenizerPointer in + api.pointee.xCreateTokenizer(UnsafeMutablePointer(mutating: api), Tokenizer.name, constructorPointer, xTokenizerPointer, deleteConstructor) + } + guard code == SQLITE_OK else { + // Assume a GRDB bug: there is no point throwing any error. + fatalError(DatabaseError(resultCode: code, message: lastErrorMessage).description) + } + } +} + +extension DatabaseQueue { + + // MARK: - Custom FTS5 Tokenizers + + /// Add a custom FTS5 tokenizer. + /// + /// class MyTokenizer : FTS5CustomTokenizer { ... } + /// dbQueue.add(tokenizer: MyTokenizer.self) + public func add(tokenizer: Tokenizer.Type) { + inDatabase { db in + db.add(tokenizer: Tokenizer.self) + } + } +} #endif diff --git a/GRDB/FTS/FTS5Pattern.swift b/GRDB/FTS/FTS5Pattern.swift index d5601d1e0..c67558f10 100644 --- a/GRDB/FTS/FTS5Pattern.swift +++ b/GRDB/FTS/FTS5Pattern.swift @@ -1,121 +1,121 @@ #if SQLITE_ENABLE_FTS5 - /// A full text pattern that can query FTS5 virtual tables. - public struct FTS5Pattern { - - /// The raw pattern string. Guaranteed to be a valid FTS5 pattern. - public let rawPattern: String - - /// Creates a pattern that matches any token found in the input string; - /// returns nil if no pattern could be built. - /// - /// FTS5Pattern(matchingAnyTokenIn: "") // nil - /// FTS5Pattern(matchingAnyTokenIn: "foo bar") // foo OR bar - /// - /// - parameter string: The string to turn into an FTS5 pattern - public init?(matchingAnyTokenIn string: String) { - guard let tokens = try? DatabaseQueue().inDatabase({ db in try db.makeTokenizer(.ascii()).nonSynonymTokens(in: string, for: .query) }) else { return nil } - guard !tokens.isEmpty else { return nil } - try? self.init(rawPattern: tokens.joined(separator: " OR ")) - } - - /// Creates a pattern that matches all tokens found in the input string; - /// returns nil if no pattern could be built. - /// - /// FTS5Pattern(matchingAllTokensIn: "") // nil - /// FTS5Pattern(matchingAllTokensIn: "foo bar") // foo bar - /// - /// - parameter string: The string to turn into an FTS5 pattern - public init?(matchingAllTokensIn string: String) { - guard let tokens = try? DatabaseQueue().inDatabase({ db in try db.makeTokenizer(.ascii()).nonSynonymTokens(in: string, for: .query) }) else { return nil } - guard !tokens.isEmpty else { return nil } - try? self.init(rawPattern: tokens.joined(separator: " ")) - } - - /// Creates a pattern that matches a contiguous string; returns nil if no - /// pattern could be built. - /// - /// FTS5Pattern(matchingPhrase: "") // nil - /// FTS5Pattern(matchingPhrase: "foo bar") // "foo bar" - /// - /// - parameter string: The string to turn into an FTS5 pattern - public init?(matchingPhrase string: String) { - guard let tokens = try? DatabaseQueue().inDatabase({ db in try db.makeTokenizer(.ascii()).nonSynonymTokens(in: string, for: .query) }) else { return nil } - guard !tokens.isEmpty else { return nil } - try? self.init(rawPattern: "\"" + tokens.joined(separator: " ") + "\"") - } - - /// Creates a pattern that matches a contiguous string prefix; returns - /// nil if no pattern could be built. - /// - /// FTS5Pattern(matchingPrefixPhrase: "") // nil - /// FTS5Pattern(matchingPrefixPhrase: "foo bar") // ^"foo bar" - /// - /// - parameter string: The string to turn into an FTS5 pattern - public init?(matchingPrefixPhrase string: String) { - guard let tokens = try? DatabaseQueue().inDatabase({ db in try db.makeTokenizer(.ascii()).nonSynonymTokens(in: string, for: .query) }) else { return nil } - guard !tokens.isEmpty else { return nil } - try? self.init(rawPattern: "^\"" + tokens.joined(separator: " ") + "\"") - } - - init(rawPattern: String, allowedColumns: [String] = []) throws { - // Correctness above all: use SQLite to validate the pattern. - // - // Invalid patterns have SQLite return an error on the first - // call to sqlite3_step() on a statement that matches against - // that pattern. - do { - try DatabaseQueue().inDatabase { db in - try db.create(virtualTable: "document", using: FTS5()) { t in - if allowedColumns.isEmpty { - t.column("__grdb__") - } else { - for column in allowedColumns { - t.column(column) - } +/// A full text pattern that can query FTS5 virtual tables. +public struct FTS5Pattern { + + /// The raw pattern string. Guaranteed to be a valid FTS5 pattern. + public let rawPattern: String + + /// Creates a pattern that matches any token found in the input string; + /// returns nil if no pattern could be built. + /// + /// FTS5Pattern(matchingAnyTokenIn: "") // nil + /// FTS5Pattern(matchingAnyTokenIn: "foo bar") // foo OR bar + /// + /// - parameter string: The string to turn into an FTS5 pattern + public init?(matchingAnyTokenIn string: String) { + guard let tokens = try? DatabaseQueue().inDatabase({ db in try db.makeTokenizer(.ascii()).nonSynonymTokens(in: string, for: .query) }) else { return nil } + guard !tokens.isEmpty else { return nil } + try? self.init(rawPattern: tokens.joined(separator: " OR ")) + } + + /// Creates a pattern that matches all tokens found in the input string; + /// returns nil if no pattern could be built. + /// + /// FTS5Pattern(matchingAllTokensIn: "") // nil + /// FTS5Pattern(matchingAllTokensIn: "foo bar") // foo bar + /// + /// - parameter string: The string to turn into an FTS5 pattern + public init?(matchingAllTokensIn string: String) { + guard let tokens = try? DatabaseQueue().inDatabase({ db in try db.makeTokenizer(.ascii()).nonSynonymTokens(in: string, for: .query) }) else { return nil } + guard !tokens.isEmpty else { return nil } + try? self.init(rawPattern: tokens.joined(separator: " ")) + } + + /// Creates a pattern that matches a contiguous string; returns nil if no + /// pattern could be built. + /// + /// FTS5Pattern(matchingPhrase: "") // nil + /// FTS5Pattern(matchingPhrase: "foo bar") // "foo bar" + /// + /// - parameter string: The string to turn into an FTS5 pattern + public init?(matchingPhrase string: String) { + guard let tokens = try? DatabaseQueue().inDatabase({ db in try db.makeTokenizer(.ascii()).nonSynonymTokens(in: string, for: .query) }) else { return nil } + guard !tokens.isEmpty else { return nil } + try? self.init(rawPattern: "\"" + tokens.joined(separator: " ") + "\"") + } + + /// Creates a pattern that matches a contiguous string prefix; returns + /// nil if no pattern could be built. + /// + /// FTS5Pattern(matchingPrefixPhrase: "") // nil + /// FTS5Pattern(matchingPrefixPhrase: "foo bar") // ^"foo bar" + /// + /// - parameter string: The string to turn into an FTS5 pattern + public init?(matchingPrefixPhrase string: String) { + guard let tokens = try? DatabaseQueue().inDatabase({ db in try db.makeTokenizer(.ascii()).nonSynonymTokens(in: string, for: .query) }) else { return nil } + guard !tokens.isEmpty else { return nil } + try? self.init(rawPattern: "^\"" + tokens.joined(separator: " ") + "\"") + } + + init(rawPattern: String, allowedColumns: [String] = []) throws { + // Correctness above all: use SQLite to validate the pattern. + // + // Invalid patterns have SQLite return an error on the first + // call to sqlite3_step() on a statement that matches against + // that pattern. + do { + try DatabaseQueue().inDatabase { db in + try db.create(virtualTable: "document", using: FTS5()) { t in + if allowedColumns.isEmpty { + t.column("__grdb__") + } else { + for column in allowedColumns { + t.column(column) } } - try db.makeSelectStatement("SELECT * FROM document WHERE document MATCH ?") - .makeCursor(arguments: [rawPattern]) - .next() // error on next() for invalid patterns } - } catch let error as DatabaseError { - // Remove private SQL & arguments from the thrown error - throw DatabaseError(resultCode: error.extendedResultCode, message: error.message, sql: nil, arguments: nil) + try db.makeSelectStatement(sql: "SELECT * FROM document WHERE document MATCH ?") + .makeCursor(arguments: [rawPattern]) + .next() // error on next() for invalid patterns } - - // Pattern is valid - self.rawPattern = rawPattern + } catch let error as DatabaseError { + // Remove private SQL & arguments from the thrown error + throw DatabaseError(resultCode: error.extendedResultCode, message: error.message, sql: nil, arguments: nil) } + + // Pattern is valid + self.rawPattern = rawPattern } +} - extension Database { - - // MARK: - FTS5 - - /// Creates a pattern from a raw pattern string; throws DatabaseError on - /// invalid syntax. - /// - /// The pattern syntax is documented at https://www.sqlite.org/fts5.html#full_text_query_syntax - /// - /// try db.makeFTS5Pattern(rawPattern: "and", forTable: "document") // OK - /// try db.makeFTS5Pattern(rawPattern: "AND", forTable: "document") // malformed MATCH expression: [AND] - public func makeFTS5Pattern(rawPattern: String, forTable table: String) throws -> FTS5Pattern { - return try FTS5Pattern(rawPattern: rawPattern, allowedColumns: columns(in: table).map { $0.name }) - } +extension Database { + + // MARK: - FTS5 + + /// Creates a pattern from a raw pattern string; throws DatabaseError on + /// invalid syntax. + /// + /// The pattern syntax is documented at https://www.sqlite.org/fts5.html#full_text_query_syntax + /// + /// try db.makeFTS5Pattern(rawPattern: "and", forTable: "document") // OK + /// try db.makeFTS5Pattern(rawPattern: "AND", forTable: "document") // malformed MATCH expression: [AND] + public func makeFTS5Pattern(rawPattern: String, forTable table: String) throws -> FTS5Pattern { + return try FTS5Pattern(rawPattern: rawPattern, allowedColumns: columns(in: table).map { $0.name }) } +} - extension FTS5Pattern : DatabaseValueConvertible { - /// Returns a value that can be stored in the database. - public var databaseValue: DatabaseValue { - return rawPattern.databaseValue - } - - /// Returns an FTS5Pattern initialized from *dbValue*, if it - /// contains a suitable value. - public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> FTS5Pattern? { - return String - .fromDatabaseValue(dbValue) - .flatMap { try? FTS5Pattern(rawPattern: $0) } - } +extension FTS5Pattern : DatabaseValueConvertible { + /// Returns a value that can be stored in the database. + public var databaseValue: DatabaseValue { + return rawPattern.databaseValue } + + /// Returns an FTS5Pattern initialized from *dbValue*, if it + /// contains a suitable value. + public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> FTS5Pattern? { + return String + .fromDatabaseValue(dbValue) + .flatMap { try? FTS5Pattern(rawPattern: $0) } + } +} #endif diff --git a/GRDB/FTS/FTS5Tokenizer.swift b/GRDB/FTS/FTS5Tokenizer.swift index 20efcdad3..d5dd44de2 100644 --- a/GRDB/FTS/FTS5Tokenizer.swift +++ b/GRDB/FTS/FTS5Tokenizer.swift @@ -1,214 +1,222 @@ #if SQLITE_ENABLE_FTS5 - /// A low-level SQLite function that lets FTS5Tokenizer notify tokens. - /// - /// See FTS5Tokenizer.tokenize(context:flags:pText:nText:tokenCallback:) - public typealias FTS5TokenCallback = @convention(c) (_ context: UnsafeMutableRawPointer?, _ flags: Int32, _ pToken: UnsafePointer?, _ nToken: Int32, _ iStart: Int32, _ iEnd: Int32) -> Int32 - - /// The reason why FTS5 is requesting tokenization. - /// - /// See https://www.sqlite.org/fts5.html#custom_tokenizers - public struct FTS5Tokenization : OptionSet { - public let rawValue: Int32 - - public init(rawValue: Int32) { - self.rawValue = rawValue - } - - /// FTS5_TOKENIZE_QUERY - public static let query = FTS5Tokenization(rawValue: FTS5_TOKENIZE_QUERY) - - /// FTS5_TOKENIZE_PREFIX - public static let prefix = FTS5Tokenization(rawValue: FTS5_TOKENIZE_PREFIX) - - /// FTS5_TOKENIZE_DOCUMENT - public static let document = FTS5Tokenization(rawValue: FTS5_TOKENIZE_DOCUMENT) - - /// FTS5_TOKENIZE_AUX - public static let aux = FTS5Tokenization(rawValue: FTS5_TOKENIZE_AUX) - } - - /// The protocol for FTS5 tokenizers - public protocol FTS5Tokenizer : class { - /// Tokenizes the text described by `pText` and `nText`, and - /// notifies found tokens to the `tokenCallback` function. - /// - /// It matches the `xTokenize` function documented at https://www.sqlite.org/fts5.html#custom_tokenizers - /// - /// - parameters: - /// - context: An opaque pointer that is the first argument to - /// the `tokenCallback` function - /// - tokenization: The reason why FTS5 is requesting tokenization. - /// - pText: The tokenized text bytes. May or may not be - /// nul-terminated. - /// - nText: The number of bytes in the tokenized text. - /// - tokenCallback: The function to call for each found token. - /// It matches the `xToken` callback at https://www.sqlite.org/fts5.html#custom_tokenizers - func tokenize(context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, pText: UnsafePointer?, nText: Int32, tokenCallback: @escaping FTS5TokenCallback) -> Int32 - } - - private class TokenizeContext { - var tokens: [(String, FTS5TokenFlags)] = [] - } - - extension FTS5Tokenizer { - - /// Tokenizes the string argument into an array of - /// (String, FTS5TokenFlags) pairs. - /// - /// let tokenizer = try db.makeTokenizer(.ascii()) - /// try tokenizer.tokenize("foo bar", for: .document) // [("foo", flags), ("bar", flags)] - /// - /// - parameter string: The string to tokenize - /// - parameter tokenization: The reason why tokenization is requested: - /// - .document: Tokenize like a document being inserted into an FTS table. - /// - .query: Tokenize like the search pattern of the MATCH operator. - /// - parameter tokenizer: A FTS5TokenizerDescriptor such as .ascii() - func tokenize(_ string: String, for tokenization: FTS5Tokenization) throws -> [(String, FTS5TokenFlags)] { - return try ContiguousArray(string.utf8).withUnsafeBufferPointer { buffer -> [(String, FTS5TokenFlags)] in - guard let addr = buffer.baseAddress else { - return [] - } - let pText = UnsafeMutableRawPointer(mutating: addr).assumingMemoryBound(to: Int8.self) - let nText = Int32(buffer.count) - - var context = TokenizeContext() - try withUnsafeMutablePointer(to: &context) { contextPointer in - let code = tokenize(context: UnsafeMutableRawPointer(contextPointer), tokenization: tokenization, pText: pText, nText: nText, tokenCallback: { (contextPointer, flags, pToken, nToken, iStart, iEnd) -> Int32 in - guard let contextPointer = contextPointer else { return SQLITE_ERROR } - - // Extract token - guard let token = pToken.flatMap({ String(data: Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: $0), count: Int(nToken), deallocator: .none), encoding: .utf8) }) else { - return SQLITE_OK - } - - let context = contextPointer.assumingMemoryBound(to: TokenizeContext.self).pointee - context.tokens.append((token, FTS5TokenFlags(rawValue: flags))) - - return SQLITE_OK - }) - if (code != SQLITE_OK) { - throw DatabaseError(resultCode: code) - } - } - return context.tokens - } - } - - func nonSynonymTokens(in string: String, for tokenization: FTS5Tokenization) throws -> [String] { - var tokens: [String] = [] - for (token, flags) in try tokenize(string, for: tokenization) { - if !flags.contains(.colocated) { - tokens.append(token) - } - } - return tokens - } - } - - extension Database { - - // MARK: - FTS5 +#if SWIFT_PACKAGE + import CSQLite +#elseif GRDBCIPHER + import SQLCipher +#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER + import SQLite3 +#endif - /// Private type that makes a pre-registered FTS5 tokenizer available - /// through the FTS5Tokenizer protocol. - private final class FTS5RegisteredTokenizer : FTS5Tokenizer { - let xTokenizer: fts5_tokenizer - let tokenizerPointer: OpaquePointer +/// A low-level SQLite function that lets FTS5Tokenizer notify tokens. +/// +/// See FTS5Tokenizer.tokenize(context:flags:pText:nText:tokenCallback:) +public typealias FTS5TokenCallback = @convention(c) (_ context: UnsafeMutableRawPointer?, _ flags: Int32, _ pToken: UnsafePointer?, _ nToken: Int32, _ iStart: Int32, _ iEnd: Int32) -> Int32 + +/// The reason why FTS5 is requesting tokenization. +/// +/// See https://www.sqlite.org/fts5.html#custom_tokenizers +public struct FTS5Tokenization : OptionSet { + public let rawValue: Int32 + + public init(rawValue: Int32) { + self.rawValue = rawValue + } + + /// FTS5_TOKENIZE_QUERY + public static let query = FTS5Tokenization(rawValue: FTS5_TOKENIZE_QUERY) + + /// FTS5_TOKENIZE_PREFIX + public static let prefix = FTS5Tokenization(rawValue: FTS5_TOKENIZE_PREFIX) + + /// FTS5_TOKENIZE_DOCUMENT + public static let document = FTS5Tokenization(rawValue: FTS5_TOKENIZE_DOCUMENT) + + /// FTS5_TOKENIZE_AUX + public static let aux = FTS5Tokenization(rawValue: FTS5_TOKENIZE_AUX) +} + +/// The protocol for FTS5 tokenizers +public protocol FTS5Tokenizer : class { + /// Tokenizes the text described by `pText` and `nText`, and + /// notifies found tokens to the `tokenCallback` function. + /// + /// It matches the `xTokenize` function documented at https://www.sqlite.org/fts5.html#custom_tokenizers + /// + /// - parameters: + /// - context: An opaque pointer that is the first argument to + /// the `tokenCallback` function + /// - tokenization: The reason why FTS5 is requesting tokenization. + /// - pText: The tokenized text bytes. May or may not be + /// nul-terminated. + /// - nText: The number of bytes in the tokenized text. + /// - tokenCallback: The function to call for each found token. + /// It matches the `xToken` callback at https://www.sqlite.org/fts5.html#custom_tokenizers + func tokenize(context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, pText: UnsafePointer?, nText: Int32, tokenCallback: @escaping FTS5TokenCallback) -> Int32 +} + +private class TokenizeContext { + var tokens: [(String, FTS5TokenFlags)] = [] +} + +extension FTS5Tokenizer { + + /// Tokenizes the string argument into an array of + /// (String, FTS5TokenFlags) pairs. + /// + /// let tokenizer = try db.makeTokenizer(.ascii()) + /// try tokenizer.tokenize("foo bar", for: .document) // [("foo", flags), ("bar", flags)] + /// + /// - parameter string: The string to tokenize + /// - parameter tokenization: The reason why tokenization is requested: + /// - .document: Tokenize like a document being inserted into an FTS table. + /// - .query: Tokenize like the search pattern of the MATCH operator. + /// - parameter tokenizer: A FTS5TokenizerDescriptor such as .ascii() + func tokenize(_ string: String, for tokenization: FTS5Tokenization) throws -> [(String, FTS5TokenFlags)] { + return try ContiguousArray(string.utf8).withUnsafeBufferPointer { buffer -> [(String, FTS5TokenFlags)] in + guard let addr = buffer.baseAddress else { + return [] + } + let pText = UnsafeMutableRawPointer(mutating: addr).assumingMemoryBound(to: Int8.self) + let nText = Int32(buffer.count) - init(xTokenizer: fts5_tokenizer, contextPointer: UnsafeMutableRawPointer?, arguments: [String]) throws { - guard let xCreate = xTokenizer.xCreate else { - throw DatabaseError(resultCode: .SQLITE_ERROR, message: "nil fts5_tokenizer.xCreate") - } - - self.xTokenizer = xTokenizer - - var tokenizerPointer: OpaquePointer? = nil - let code: Int32 - if let argument = arguments.first { - // Turn [String] into ContiguousArray> - // (for an alternative implementation see https://oleb.net/blog/2016/10/swift-array-of-c-strings/) - func convertArguments(_ array: inout ContiguousArray>, _ car: String, _ cdr: [String], _ body: (ContiguousArray>) -> Result) -> Result { - return car.withCString { cString in - if let car = cdr.first { - array.append(cString) - return convertArguments(&array, car, Array(cdr.suffix(from: 1)), body) - } else { - return body(array) - } - } + var context = TokenizeContext() + try withUnsafeMutablePointer(to: &context) { contextPointer in + let code = tokenize(context: UnsafeMutableRawPointer(contextPointer), tokenization: tokenization, pText: pText, nText: nText, tokenCallback: { (contextPointer, flags, pToken, nToken, iStart, iEnd) -> Int32 in + guard let contextPointer = contextPointer else { return SQLITE_ERROR } + + // Extract token + guard let token = pToken.flatMap({ String(data: Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: $0), count: Int(nToken), deallocator: .none), encoding: .utf8) }) else { + return SQLITE_OK } - var cStrings = ContiguousArray>() - code = convertArguments(&cStrings, argument, Array(arguments.suffix(from: 1))) { cStrings in - cStrings.withUnsafeBufferPointer { azArg in - xCreate(contextPointer, UnsafeMutablePointer(OpaquePointer(azArg.baseAddress!)), Int32(cStrings.count), &tokenizerPointer) - } - } - } else { - code = xCreate(contextPointer, nil, 0, &tokenizerPointer) - } - - guard code == SQLITE_OK else { - throw DatabaseError(resultCode: code, message: "failed fts5_tokenizer.xCreate") - } - - if let tokenizerPointer = tokenizerPointer { - self.tokenizerPointer = tokenizerPointer - } else { - throw DatabaseError(resultCode: code, message: "nil tokenizer") + + let context = contextPointer.assumingMemoryBound(to: TokenizeContext.self).pointee + context.tokens.append((token, FTS5TokenFlags(rawValue: flags))) + + return SQLITE_OK + }) + if (code != SQLITE_OK) { + throw DatabaseError(resultCode: code) } } - - deinit { - if let delete = xTokenizer.xDelete { - delete(tokenizerPointer) - } - } - - func tokenize(context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, pText: UnsafePointer?, nText: Int32, tokenCallback: @escaping FTS5TokenCallback) -> Int32 { - guard let xTokenize = xTokenizer.xTokenize else { - return SQLITE_ERROR - } - return xTokenize(tokenizerPointer, context, tokenization.rawValue, pText, nText, tokenCallback) + return context.tokens + } + } + + func nonSynonymTokens(in string: String, for tokenization: FTS5Tokenization) throws -> [String] { + var tokens: [String] = [] + for (token, flags) in try tokenize(string, for: tokenization) { + if !flags.contains(.colocated) { + tokens.append(token) } } + return tokens + } +} + +extension Database { + + // MARK: - FTS5 + + /// Private type that makes a pre-registered FTS5 tokenizer available + /// through the FTS5Tokenizer protocol. + private final class FTS5RegisteredTokenizer : FTS5Tokenizer { + let xTokenizer: fts5_tokenizer + let tokenizerPointer: OpaquePointer - /// Creates an FTS5 tokenizer, given its descriptor. - /// - /// let unicode61 = try db.makeTokenizer(.unicode61()) - /// - /// It is a programmer error to use the tokenizer outside of a protected - /// database queue, or after the database has been closed. - /// - /// Use this method when you implement a custom wrapper tokenizer: - /// - /// final class MyTokenizer : FTS5WrapperTokenizer { - /// var wrappedTokenizer: FTS5Tokenizer - /// - /// init(db: Database, arguments: [String]) throws { - /// wrappedTokenizer = try db.makeTokenizer(.unicode61()) - /// } - /// } - public func makeTokenizer(_ descriptor: FTS5TokenizerDescriptor) throws -> FTS5Tokenizer { - let api = FTS5.api(self) + init(xTokenizer: fts5_tokenizer, contextPointer: UnsafeMutableRawPointer?, arguments: [String]) throws { + guard let xCreate = xTokenizer.xCreate else { + throw DatabaseError(resultCode: .SQLITE_ERROR, message: "nil fts5_tokenizer.xCreate") + } - let xTokenizerPointer: UnsafeMutablePointer = .allocate(capacity: 1) - defer { xTokenizerPointer.deallocate() } + self.xTokenizer = xTokenizer - let contextHandle: UnsafeMutablePointer = .allocate(capacity: 1) - defer { contextHandle.deallocate() } - - let code = api.pointee.xFindTokenizer!( - UnsafeMutablePointer(mutating: api), - descriptor.name, - contextHandle, - xTokenizerPointer) + var tokenizerPointer: OpaquePointer? = nil + let code: Int32 + if let argument = arguments.first { + // Turn [String] into ContiguousArray> + // (for an alternative implementation see https://oleb.net/blog/2016/10/swift-array-of-c-strings/) + func convertArguments(_ array: inout ContiguousArray>, _ car: String, _ cdr: [String], _ body: (ContiguousArray>) -> Result) -> Result { + return car.withCString { cString in + if let car = cdr.first { + array.append(cString) + return convertArguments(&array, car, Array(cdr.suffix(from: 1)), body) + } else { + return body(array) + } + } + } + var cStrings = ContiguousArray>() + code = convertArguments(&cStrings, argument, Array(arguments.suffix(from: 1))) { cStrings in + cStrings.withUnsafeBufferPointer { azArg in + xCreate(contextPointer, UnsafeMutablePointer(OpaquePointer(azArg.baseAddress!)), Int32(cStrings.count), &tokenizerPointer) + } + } + } else { + code = xCreate(contextPointer, nil, 0, &tokenizerPointer) + } guard code == SQLITE_OK else { - throw DatabaseError(resultCode: code) + throw DatabaseError(resultCode: code, message: "failed fts5_tokenizer.xCreate") } - let contextPointer = contextHandle.pointee - return try FTS5RegisteredTokenizer(xTokenizer: xTokenizerPointer.pointee, contextPointer: contextPointer, arguments: descriptor.arguments) + if let tokenizerPointer = tokenizerPointer { + self.tokenizerPointer = tokenizerPointer + } else { + throw DatabaseError(resultCode: code, message: "nil tokenizer") + } + } + + deinit { + if let delete = xTokenizer.xDelete { + delete(tokenizerPointer) + } + } + + func tokenize(context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, pText: UnsafePointer?, nText: Int32, tokenCallback: @escaping FTS5TokenCallback) -> Int32 { + guard let xTokenize = xTokenizer.xTokenize else { + return SQLITE_ERROR + } + return xTokenize(tokenizerPointer, context, tokenization.rawValue, pText, nText, tokenCallback) } } + + /// Creates an FTS5 tokenizer, given its descriptor. + /// + /// let unicode61 = try db.makeTokenizer(.unicode61()) + /// + /// It is a programmer error to use the tokenizer outside of a protected + /// database queue, or after the database has been closed. + /// + /// Use this method when you implement a custom wrapper tokenizer: + /// + /// final class MyTokenizer : FTS5WrapperTokenizer { + /// var wrappedTokenizer: FTS5Tokenizer + /// + /// init(db: Database, arguments: [String]) throws { + /// wrappedTokenizer = try db.makeTokenizer(.unicode61()) + /// } + /// } + public func makeTokenizer(_ descriptor: FTS5TokenizerDescriptor) throws -> FTS5Tokenizer { + let api = FTS5.api(self) + + let xTokenizerPointer: UnsafeMutablePointer = .allocate(capacity: 1) + defer { xTokenizerPointer.deallocate() } + + let contextHandle: UnsafeMutablePointer = .allocate(capacity: 1) + defer { contextHandle.deallocate() } + + let code = api.pointee.xFindTokenizer!( + UnsafeMutablePointer(mutating: api), + descriptor.name, + contextHandle, + xTokenizerPointer) + + guard code == SQLITE_OK else { + throw DatabaseError(resultCode: code) + } + + let contextPointer = contextHandle.pointee + return try FTS5RegisteredTokenizer(xTokenizer: xTokenizerPointer.pointee, contextPointer: contextPointer, arguments: descriptor.arguments) + } +} #endif diff --git a/GRDB/FTS/FTS5TokenizerDescriptor.swift b/GRDB/FTS/FTS5TokenizerDescriptor.swift index 95c0e0431..618392e84 100644 --- a/GRDB/FTS/FTS5TokenizerDescriptor.swift +++ b/GRDB/FTS/FTS5TokenizerDescriptor.swift @@ -1,117 +1,138 @@ #if SQLITE_ENABLE_FTS5 - /// An FTS5 tokenizer, suitable for FTS5 table definitions: +/// An FTS5 tokenizer, suitable for FTS5 table definitions: +/// +/// db.create(virtualTable: "book", using: FTS5()) { t in +/// t.tokenizer = .unicode61() // FTS5TokenizerDescriptor +/// } +/// +/// See https://www.sqlite.org/fts5.html#tokenizers +public struct FTS5TokenizerDescriptor { + /// The tokenizer components + /// + /// // ["unicode61"] + /// FTS5TokenizerDescriptor.unicode61().components + /// + /// // ["unicode61", "remove_diacritics", "0"] + /// FTS5TokenizerDescriptor.unicode61(removeDiacritics: false)).components + public let components: [String] + + /// The tokenizer name + /// + /// // "unicode61" + /// FTS5TokenizerDescriptor.unicode61().name + /// + /// // "unicode61" + /// FTS5TokenizerDescriptor.unicode61(removeDiacritics: false)).name + var name: String { + return components[0] + } + + var arguments: [String] { + return Array(components.suffix(from: 1)) + } + + /// Creates an FTS5 tokenizer descriptor. /// /// db.create(virtualTable: "book", using: FTS5()) { t in - /// t.tokenizer = .unicode61() // FTS5TokenizerDescriptor + /// let tokenizer = FTS5TokenizerDescriptor(components: ["porter", "unicode61", "remove_diacritics", "0"]) + /// t.tokenizer = tokenizer /// } /// - /// See https://www.sqlite.org/fts5.html#tokenizers - public struct FTS5TokenizerDescriptor { - /// The tokenizer components - /// - /// // ["unicode61"] - /// FTS5TokenizerDescriptor.unicode61().components - /// - /// // ["unicode61", "remove_diacritics", "0"] - /// FTS5TokenizerDescriptor.unicode61(removeDiacritics: false)).components - public let components: [String] - - /// The tokenizer name - /// - /// // "unicode61" - /// FTS5TokenizerDescriptor.unicode61().name - /// - /// // "unicode61" - /// FTS5TokenizerDescriptor.unicode61(removeDiacritics: false)).name - var name: String { - return components[0] - } - - var arguments: [String] { - return Array(components.suffix(from: 1)) - } - - /// Creates an FTS5 tokenizer descriptor. - /// - /// db.create(virtualTable: "book", using: FTS5()) { t in - /// let tokenizer = FTS5TokenizerDescriptor(components: ["porter", "unicode61", "remove_diacritics", "0"]) - /// t.tokenizer = tokenizer - /// } - /// - /// - precondition: Components is not empty - public init(components: [String]) { - GRDBPrecondition(!components.isEmpty, "FTS5TokenizerDescriptor requires at least one component") - assert(!components.isEmpty) - self.components = components - } - - /// The "ascii" tokenizer - /// - /// db.create(virtualTable: "book", using: FTS5()) { t in - /// t.tokenizer = .ascii() - /// } - /// - /// - parameters: - /// - separators: Unless empty (the default), SQLite will consider - /// these characters as token separators. - /// - /// See https://www.sqlite.org/fts5.html#ascii_tokenizer - public static func ascii(separators: Set = []) -> FTS5TokenizerDescriptor { - if separators.isEmpty { - return FTS5TokenizerDescriptor(components: ["ascii"]) - } else { - return FTS5TokenizerDescriptor(components: ["ascii", "separators", separators.map { String($0) }.joined(separator: "").sqlExpression.sql]) - } - } - - /// The "porter" tokenizer - /// - /// db.create(virtualTable: "book", using: FTS5()) { t in - /// t.tokenizer = .porter() - /// } - /// - /// - parameters: - /// - base: An eventual wrapping tokenizer which replaces the - // default unicode61() base tokenizer. - /// - /// See https://www.sqlite.org/fts5.html#porter_tokenizer - public static func porter(wrapping base: FTS5TokenizerDescriptor? = nil) -> FTS5TokenizerDescriptor { - if let base = base { - return FTS5TokenizerDescriptor(components: ["porter"] + base.components) - } else { - return FTS5TokenizerDescriptor(components: ["porter"]) - } - } - - /// An "unicode61" tokenizer - /// - /// db.create(virtualTable: "book", using: FTS5()) { t in - /// t.tokenizer = .unicode61() - /// } - /// - /// - parameters: - /// - removeDiacritics: If true (the default), then SQLite will - /// strip diacritics from latin characters. - /// - separators: Unless empty (the default), SQLite will consider - /// these characters as token separators. - /// - tokenCharacters: Unless empty (the default), SQLite will - /// consider these characters as token characters. - /// - /// See https://www.sqlite.org/fts5.html#unicode61_tokenizer - public static func unicode61(removeDiacritics: Bool = true, separators: Set = [], tokenCharacters: Set = []) -> FTS5TokenizerDescriptor { - var components: [String] = ["unicode61"] - if !removeDiacritics { - components.append(contentsOf: ["remove_diacritics", "0"]) - } - if !separators.isEmpty { - // TODO: test "=" and "\"", "(" and ")" as separators, with both FTS3Pattern(matchingAnyTokenIn:tokenizer:) and Database.create(virtualTable:using:) - components.append(contentsOf: ["separators", separators.sorted().map { String($0) }.joined(separator: "").sqlExpression.sql]) - } - if !tokenCharacters.isEmpty { - // TODO: test "=" and "\"", "(" and ")" as tokenCharacters, with both FTS3Pattern(matchingAnyTokenIn:tokenizer:) and Database.create(virtualTable:using:) - components.append(contentsOf: ["tokenchars", tokenCharacters.sorted().map { String($0) }.joined(separator: "").sqlExpression.sql]) - } - return FTS5TokenizerDescriptor(components: components) + /// - precondition: Components is not empty + public init(components: [String]) { + GRDBPrecondition(!components.isEmpty, "FTS5TokenizerDescriptor requires at least one component") + assert(!components.isEmpty) + self.components = components + } + + /// The "ascii" tokenizer + /// + /// db.create(virtualTable: "book", using: FTS5()) { t in + /// t.tokenizer = .ascii() + /// } + /// + /// - parameters: + /// - separators: Unless empty (the default), SQLite will consider + /// these characters as token separators. + /// + /// See https://www.sqlite.org/fts5.html#ascii_tokenizer + public static func ascii(separators: Set = []) -> FTS5TokenizerDescriptor { + if separators.isEmpty { + return FTS5TokenizerDescriptor(components: ["ascii"]) + } else { + return FTS5TokenizerDescriptor(components: ["ascii", "separators", separators.map { String($0) }.joined(separator: "").sqlExpression.quotedSQL()]) } } + + /// The "porter" tokenizer + /// + /// db.create(virtualTable: "book", using: FTS5()) { t in + /// t.tokenizer = .porter() + /// } + /// + /// - parameters: + /// - base: An eventual wrapping tokenizer which replaces the + // default unicode61() base tokenizer. + /// + /// See https://www.sqlite.org/fts5.html#porter_tokenizer + public static func porter(wrapping base: FTS5TokenizerDescriptor? = nil) -> FTS5TokenizerDescriptor { + if let base = base { + return FTS5TokenizerDescriptor(components: ["porter"] + base.components) + } else { + return FTS5TokenizerDescriptor(components: ["porter"]) + } + } + + /// An "unicode61" tokenizer + /// + /// db.create(virtualTable: "book", using: FTS5()) { t in + /// t.tokenizer = .unicode61() + /// } + /// + /// - parameters: + /// - diacritics: By default SQLite will strip diacritics from + /// latin characters. + /// - separators: Unless empty (the default), SQLite will consider + /// these characters as token separators. + /// - tokenCharacters: Unless empty (the default), SQLite will + /// consider these characters as token characters. + /// + /// See https://www.sqlite.org/fts5.html#unicode61_tokenizer + public static func unicode61(diacritics: FTS5.Diacritics = .removeLegacy, separators: Set = [], tokenCharacters: Set = []) -> FTS5TokenizerDescriptor { + var components: [String] = ["unicode61"] + switch diacritics { + case .removeLegacy: + break + case .keep: + components.append(contentsOf: ["remove_diacritics", "0"]) + #if GRDBCUSTOMSQLITE + case .remove: + components.append(contentsOf: ["remove_diacritics", "2"]) + #endif + } + if !separators.isEmpty { + // TODO: test "=" and "\"", "(" and ")" as separators, with both FTS3Pattern(matchingAnyTokenIn:tokenizer:) and Database.create(virtualTable:using:) + components.append(contentsOf: [ + "separators", + separators + .sorted() + .map { String($0) } + .joined(separator: "") + .sqlExpression + .quotedSQL()]) + } + if !tokenCharacters.isEmpty { + // TODO: test "=" and "\"", "(" and ")" as tokenCharacters, with both FTS3Pattern(matchingAnyTokenIn:tokenizer:) and Database.create(virtualTable:using:) + components.append(contentsOf: [ + "tokenchars", + tokenCharacters + .sorted() + .map { String($0) } + .joined(separator: "") + .sqlExpression + .quotedSQL()]) + } + return FTS5TokenizerDescriptor(components: components) + } +} #endif diff --git a/GRDB/FTS/FTS5WrapperTokenizer.swift b/GRDB/FTS/FTS5WrapperTokenizer.swift index 65b683f54..a217176cb 100644 --- a/GRDB/FTS/FTS5WrapperTokenizer.swift +++ b/GRDB/FTS/FTS5WrapperTokenizer.swift @@ -1,141 +1,149 @@ #if SQLITE_ENABLE_FTS5 - /// Flags that tell SQLite how to register a token. - /// - /// See https://www.sqlite.org/fts5.html#custom_tokenizers - public struct FTS5TokenFlags : OptionSet { - public let rawValue: Int32 - - public init(rawValue: Int32) { - self.rawValue = rawValue - } - - /// FTS5_TOKEN_COLOCATED - public static let colocated = FTS5TokenFlags(rawValue: FTS5_TOKEN_COLOCATED) +#if SWIFT_PACKAGE + import CSQLite +#elseif GRDBCIPHER + import SQLCipher +#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER + import SQLite3 +#endif + +/// Flags that tell SQLite how to register a token. +/// +/// See https://www.sqlite.org/fts5.html#custom_tokenizers +public struct FTS5TokenFlags : OptionSet { + public let rawValue: Int32 + + public init(rawValue: Int32) { + self.rawValue = rawValue } - /// A function that lets FTS5WrapperTokenizer notify tokens. - /// - /// See FTS5WrapperTokenizer.accept(token:flags:tokenCallback:) - public typealias FTS5WrapperTokenCallback = (_ token: String, _ flags: FTS5TokenFlags) throws -> () + /// FTS5_TOKEN_COLOCATED + public static let colocated = FTS5TokenFlags(rawValue: FTS5_TOKEN_COLOCATED) +} + +/// A function that lets FTS5WrapperTokenizer notify tokens. +/// +/// See FTS5WrapperTokenizer.accept(token:flags:tokenCallback:) +public typealias FTS5WrapperTokenCallback = (_ token: String, _ flags: FTS5TokenFlags) throws -> () + +/// The protocol for custom FTS5 tokenizers that wrap another tokenizer. +/// +/// Types that adopt FTS5WrapperTokenizer don't have to implement the +/// low-level FTS5Tokenizer.tokenize(context:flags:pText:nText:tokenCallback:). +/// +/// Instead, they process regular Swift strings. +/// +/// Here is the implementation for a trivial tokenizer that wraps the +/// built-in ascii tokenizer without any custom processing: +/// +/// class TrivialAsciiTokenizer : FTS5WrapperTokenizer { +/// static let name = "trivial" +/// let wrappedTokenizer: FTS5Tokenizer +/// +/// init(db: Database, arguments: [String]) throws { +/// wrappedTokenizer = try db.makeTokenizer(.ascii()) +/// } +/// +/// func accept(token: String, flags: FTS5TokenFlags, for tokenization: FTS5Tokenization, tokenCallback: FTS5WrapperTokenCallback) throws { +/// try tokenCallback(token, flags) +/// } +/// } +public protocol FTS5WrapperTokenizer : FTS5CustomTokenizer { + /// The wrapped tokenizer + var wrappedTokenizer: FTS5Tokenizer { get } - /// The protocol for custom FTS5 tokenizers that wrap another tokenizer. + /// Given a token produced by the wrapped tokenizer, notifies customized + /// tokens to the `tokenCallback` function. /// - /// Types that adopt FTS5WrapperTokenizer don't have to implement the - /// low-level FTS5Tokenizer.tokenize(context:flags:pText:nText:tokenCallback:). + /// For example: /// - /// Instead, they process regular Swift strings. - /// - /// Here is the implementation for a trivial tokenizer that wraps the - /// built-in ascii tokenizer without any custom processing: - /// - /// class TrivialAsciiTokenizer : FTS5WrapperTokenizer { - /// static let name = "trivial" - /// let wrappedTokenizer: FTS5Tokenizer - /// - /// init(db: Database, arguments: [String]) throws { - /// wrappedTokenizer = try db.makeTokenizer(.ascii()) - /// } - /// - /// func accept(token: String, flags: FTS5TokenFlags, for tokenization: FTS5Tokenization, tokenCallback: FTS5WrapperTokenCallback) throws { - /// try tokenCallback(token, flags) - /// } + /// func accept(token: String, flags: FTS5TokenFlags, for tokenization: FTS5Tokenization, tokenCallback: FTS5WrapperTokenCallback) throws { + /// // pass through: + /// try tokenCallback(token, flags) /// } - public protocol FTS5WrapperTokenizer : FTS5CustomTokenizer { - /// The wrapped tokenizer - var wrappedTokenizer: FTS5Tokenizer { get } - - /// Given a token produced by the wrapped tokenizer, notifies customized - /// tokens to the `tokenCallback` function. - /// - /// For example: - /// - /// func accept(token: String, flags: FTS5TokenFlags, for tokenization: FTS5Tokenization, tokenCallback: FTS5WrapperTokenCallback) throws { - /// // pass through: - /// try tokenCallback(token, flags) - /// } - /// - /// When implementing the accept method, there are a two rules - /// to observe: - /// - /// 1. Errors thrown by the tokenCallback function must not be caught. - /// - /// 2. The input `flags` should be given unmodified to the tokenCallback - /// function, unless you union it with the .colocated flag when the - /// tokenizer produces synonyms (see - /// https://www.sqlite.org/fts5.html#synonym_support). - /// - /// - parameters: - /// - token: A token produced by the wrapped tokenizer - /// - flags: Flags that tell SQLite how to register a token. - /// - tokenization: The reason why FTS5 is requesting tokenization. - /// - tokenCallback: The function to call for each customized token. - func accept(token: String, flags: FTS5TokenFlags, for tokenization: FTS5Tokenization, tokenCallback: FTS5WrapperTokenCallback) throws - } - - private struct FTS5WrapperContext { - let tokenizer: FTS5WrapperTokenizer - let context: UnsafeMutableRawPointer? - let tokenization: FTS5Tokenization - let tokenCallback: FTS5TokenCallback - } - - extension FTS5WrapperTokenizer { - /// Default implementation - public func tokenize(context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, pText: UnsafePointer?, nText: Int32, tokenCallback: @escaping FTS5TokenCallback) -> Int32 { - // `tokenCallback` is @convention(c). This requires a little setup - // in order to transfer context. - var customContext = FTS5WrapperContext( - tokenizer: self, - context: context, - tokenization: tokenization, - tokenCallback: tokenCallback) - return withUnsafeMutablePointer(to: &customContext) { customContextPointer in - // Invoke wrappedTokenizer - return wrappedTokenizer.tokenize(context: customContextPointer, tokenization: tokenization, pText: pText, nText: nText) { (customContextPointer, tokenFlags, pToken, nToken, iStart, iEnd) in - - // Extract token produced by wrapped tokenizer - guard let token = pToken.flatMap({ String(data: Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: $0), count: Int(nToken), deallocator: .none), encoding: .utf8) }) else { - return 0 // SQLITE_OK - } - - // Extract context - let customContext = customContextPointer!.assumingMemoryBound(to: FTS5WrapperContext.self).pointee - let tokenizer = customContext.tokenizer - let context = customContext.context - let tokenization = customContext.tokenization - let tokenCallback = customContext.tokenCallback - - // Process token produced by wrapped tokenizer - do { - try tokenizer.accept( - token: token, - flags: FTS5TokenFlags(rawValue: tokenFlags), - for: tokenization, - tokenCallback: { (token, flags) in - // Turn token into bytes - return try ContiguousArray(token.utf8).withUnsafeBufferPointer { buffer in - guard let addr = buffer.baseAddress else { - return - } - let pToken = UnsafeMutableRawPointer(mutating: addr).assumingMemoryBound(to: Int8.self) - let nToken = Int32(buffer.count) - - // Inject token bytes into SQLite - let code = tokenCallback(context, flags.rawValue, pToken, nToken, iStart, iEnd) - guard code == SQLITE_OK else { - throw DatabaseError(resultCode: code, message: "token callback failed") - } + /// + /// When implementing the accept method, there are a two rules + /// to observe: + /// + /// 1. Errors thrown by the tokenCallback function must not be caught. + /// + /// 2. The input `flags` should be given unmodified to the tokenCallback + /// function, unless you union it with the .colocated flag when the + /// tokenizer produces synonyms (see + /// https://www.sqlite.org/fts5.html#synonym_support). + /// + /// - parameters: + /// - token: A token produced by the wrapped tokenizer + /// - flags: Flags that tell SQLite how to register a token. + /// - tokenization: The reason why FTS5 is requesting tokenization. + /// - tokenCallback: The function to call for each customized token. + func accept(token: String, flags: FTS5TokenFlags, for tokenization: FTS5Tokenization, tokenCallback: FTS5WrapperTokenCallback) throws +} + +private struct FTS5WrapperContext { + let tokenizer: FTS5WrapperTokenizer + let context: UnsafeMutableRawPointer? + let tokenization: FTS5Tokenization + let tokenCallback: FTS5TokenCallback +} + +extension FTS5WrapperTokenizer { + /// Default implementation + public func tokenize(context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, pText: UnsafePointer?, nText: Int32, tokenCallback: @escaping FTS5TokenCallback) -> Int32 { + // `tokenCallback` is @convention(c). This requires a little setup + // in order to transfer context. + var customContext = FTS5WrapperContext( + tokenizer: self, + context: context, + tokenization: tokenization, + tokenCallback: tokenCallback) + return withUnsafeMutablePointer(to: &customContext) { customContextPointer in + // Invoke wrappedTokenizer + return wrappedTokenizer.tokenize(context: customContextPointer, tokenization: tokenization, pText: pText, nText: nText) { (customContextPointer, tokenFlags, pToken, nToken, iStart, iEnd) in + + // Extract token produced by wrapped tokenizer + guard let token = pToken.flatMap({ String(data: Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: $0), count: Int(nToken), deallocator: .none), encoding: .utf8) }) else { + return 0 // SQLITE_OK + } + + // Extract context + let customContext = customContextPointer!.assumingMemoryBound(to: FTS5WrapperContext.self).pointee + let tokenizer = customContext.tokenizer + let context = customContext.context + let tokenization = customContext.tokenization + let tokenCallback = customContext.tokenCallback + + // Process token produced by wrapped tokenizer + do { + try tokenizer.accept( + token: token, + flags: FTS5TokenFlags(rawValue: tokenFlags), + for: tokenization, + tokenCallback: { (token, flags) in + // Turn token into bytes + return try ContiguousArray(token.utf8).withUnsafeBufferPointer { buffer in + guard let addr = buffer.baseAddress else { + return } - }) - - return SQLITE_OK - } catch let error as DatabaseError { - return error.extendedResultCode.rawValue - } catch { - return SQLITE_ERROR - } + let pToken = UnsafeMutableRawPointer(mutating: addr).assumingMemoryBound(to: Int8.self) + let nToken = Int32(buffer.count) + + // Inject token bytes into SQLite + let code = tokenCallback(context, flags.rawValue, pToken, nToken, iStart, iEnd) + guard code == SQLITE_OK else { + throw DatabaseError(resultCode: code, message: "token callback failed") + } + } + }) + + return SQLITE_OK + } catch let error as DatabaseError { + return error.extendedResultCode.rawValue + } catch { + return SQLITE_ERROR } } } } +} #endif diff --git a/GRDB/Fixit/GRDB-4.0.swift b/GRDB/Fixit/GRDB-4.0.swift new file mode 100644 index 000000000..048ed5de7 --- /dev/null +++ b/GRDB/Fixit/GRDB-4.0.swift @@ -0,0 +1,157 @@ +import Dispatch + +// Fixits for changes introduced by GRDB 4.0.0 + +extension Cursor { + @available(*, unavailable, renamed: "compactMap") + public func flatMap(_ transform: @escaping (Element) throws -> ElementOfResult?) -> MapCursor>, ElementOfResult> { preconditionFailure() } +} + +extension DatabaseWriter { + @available(*, unavailable, message: "Use concurrentRead instead") + public func readFromCurrentState(_ block: @escaping (Database) -> Void) throws { preconditionFailure() } +} + +extension ValueObservation { + @available(*, unavailable, message: "Provide the reducer in a (Database) -> Reducer closure") + public static func tracking(_ regions: DatabaseRegionConvertible..., reducer: Reducer) -> ValueObservation { preconditionFailure() } + + @available(*, unavailable, message: "Use distinctUntilChanged() instead") + public static func tracking(_ regions: DatabaseRegionConvertible..., fetchDistinct fetch: @escaping (Database) throws -> Value) -> ValueObservation>> where Value: Equatable { preconditionFailure() } +} + +@available(*, unavailable, renamed: "FastDatabaseValueCursor") +public typealias ColumnCursor = FastDatabaseValueCursor + +@available(*, unavailable, renamed: "FastNullableDatabaseValueCursor") +public typealias NullableColumnCursor = FastNullableDatabaseValueCursor + +extension Database { + @available(*, unavailable, renamed: "execute(sql:arguments:)") + public func execute(_ sql: String, arguments: StatementArguments? = nil) throws { preconditionFailure() } + + @available(*, unavailable, renamed: "makeSelectStatement(sql:)") + public func makeSelectStatement(_ sql: String) throws -> SelectStatement { preconditionFailure() } + + @available(*, unavailable, renamed: "cachedSelectStatement(sql:)") + public func cachedSelectStatement(_ sql: String) throws -> SelectStatement { preconditionFailure() } + + @available(*, unavailable, renamed: "makeUpdateStatement(sql:)") + public func makeUpdateStatement(_ sql: String) throws -> UpdateStatement { preconditionFailure() } + + @available(*, unavailable, renamed: "cachedUpdateStatement(sql:)") + public func cachedUpdateStatement(_ sql: String) throws -> UpdateStatement { preconditionFailure() } +} + +extension DatabaseValueConvertible { + @available(*, unavailable, renamed: "fetchCursor(_:sql:arguments:adapter:)") + public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DatabaseValueCursor { preconditionFailure() } + + @available(*, unavailable, renamed: "fetchAll(_:sql:arguments:adapter:)") + public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] { preconditionFailure() } + + @available(*, unavailable, renamed: "fetchOne(_:sql:arguments:adapter:)") + public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? { preconditionFailure() } +} + +extension Optional where Wrapped: DatabaseValueConvertible { + @available(*, unavailable, renamed: "fetchCursor(_:sql:arguments:adapter:)") + public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor { preconditionFailure() } + + @available(*, unavailable, renamed: "fetchAll(_:sql:arguments:adapter:)") + public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Wrapped?] { preconditionFailure() } +} + +extension Row { + @available(*, unavailable, renamed: "fetchCursor(_:sql:arguments:adapter:)") + public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RowCursor { preconditionFailure() } + + @available(*, unavailable, renamed: "fetchAll(_:sql:arguments:adapter:)") + public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Row] { preconditionFailure() } + + @available(*, unavailable, renamed: "fetchOne(_:sql:arguments:adapter:)") + public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Row? { preconditionFailure() } +} + +extension DatabaseValueConvertible where Self: StatementColumnConvertible { + @available(*, unavailable, renamed: "fetchCursor(_:sql:arguments:adapter:)") + public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> FastDatabaseValueCursor { preconditionFailure() } +} + +extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConvertible { + @available(*, unavailable, renamed: "fetchCursor(_:sql:arguments:adapter:)") + public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> FastNullableDatabaseValueCursor { preconditionFailure() } +} + +extension FetchableRecord { + @available(*, unavailable, renamed: "fetchCursor(_:sql:arguments:adapter:)") + public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RecordCursor { preconditionFailure() } + + @available(*, unavailable, renamed: "fetchAll(_:sql:arguments:adapter:)") + public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] { preconditionFailure() } + + @available(*, unavailable, renamed: "fetchOne(_:sql:arguments:adapter:)") + public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? { preconditionFailure() } +} + +extension SQLRequest { + @available(*, unavailable, renamed: "init(sql:arguments:adapter:cached:)") + public init(_ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil, cached: Bool = false) { preconditionFailure() } +} + +extension SQLExpressionLiteral { + @available(*, unavailable, renamed: "init(sql:arguments:)") + public init(_ sql: String, arguments: StatementArguments? = nil) { preconditionFailure() } +} + +extension SQLExpression { + @available(*, unavailable, message: "Use sqlLiteral property instead") + public var literal: SQLExpressionLiteral { preconditionFailure() } +} + +extension FTS3TokenizerDescriptor { + @available(*, unavailable, renamed: "unicode61(diacritics:separators:tokenCharacters:)") + public static func unicode61(removeDiacritics: Bool, separators: Set = [], tokenCharacters: Set = []) -> FTS3TokenizerDescriptor { preconditionFailure() } +} + +#if SQLITE_ENABLE_FTS5 +extension FTS5TokenizerDescriptor { + @available(*, unavailable, renamed: "unicode61(diacritics:separators:tokenCharacters:)") + public static func unicode61(removeDiacritics: Bool = true, separators: Set = [], tokenCharacters: Set = []) -> FTS5TokenizerDescriptor { preconditionFailure() } +} +#endif + +extension DatabaseValue { + @available(*, unavailable) + public func losslessConvert(sql: String? = nil, arguments: StatementArguments? = nil) -> T where T: DatabaseValueConvertible { preconditionFailure() } + + @available(*, unavailable) + public func losslessConvert(sql: String? = nil, arguments: StatementArguments? = nil) -> T? where T: DatabaseValueConvertible { preconditionFailure() } +} + +extension ValueScheduling { + @available(*, unavailable, renamed: "async(onQueue:startImmediately:)") + public static func onQueue(_ queue: DispatchQueue, startImmediately: Bool) -> ValueScheduling { preconditionFailure() } +} + +extension ValueObservation { + @available(*, unavailable, message: "Observation extent is controlled by the lifetime of observers returned by the start() method.") + public var extent: Database.TransactionObservationExtent { + get { preconditionFailure() } + set { preconditionFailure() } + } +} + +extension Configuration { + @available(*, unavailable, message: "Run the PRAGMA cipher_page_size in Configuration.prepareDatabase instead.") + public var cipherPageSize: Int { + get { preconditionFailure() } + set { preconditionFailure() } + } + + @available(*, unavailable, message: "Run the PRAGMA kdf_iter in Configuration.prepareDatabase instead.") + public var kdfIterations: Int { + get { preconditionFailure() } + set { preconditionFailure() } + } +} diff --git a/GRDB/Legacy/Fixits-0-84-0.swift b/GRDB/Legacy/Fixits-0-84-0.swift deleted file mode 100644 index 09caa9164..000000000 --- a/GRDB/Legacy/Fixits-0-84-0.swift +++ /dev/null @@ -1,19 +0,0 @@ -import Foundation - -@available(*, unavailable, renamed:"Database.ForeignKeyAction") -public typealias SQLForeignKeyAction = Database.ForeignKeyAction - -@available(*, unavailable, renamed:"Database.ColumnType") -public typealias SQLColumnType = Database.ColumnType - -@available(*, unavailable, renamed:"Database.ConflictResolution") -public typealias SQLConflictResolution = Database.ConflictResolution - -@available(*, unavailable, renamed:"Database.CollationName") -public typealias SQLCollation = Database.CollationName - -@available(*, unavailable, renamed:"SQLSpecificExpressible") -public typealias _SpecificSQLExpressible = SQLSpecificExpressible - -@available(*, unavailable, renamed:"SQLExpression") -public typealias _SQLExpression = SQLExpression diff --git a/GRDB/Legacy/Fixits-0-90-1.swift b/GRDB/Legacy/Fixits-0-90-1.swift deleted file mode 100644 index cb886e4de..000000000 --- a/GRDB/Legacy/Fixits-0-90-1.swift +++ /dev/null @@ -1,55 +0,0 @@ -extension Row { - @available(*, unavailable, renamed:"fetchCursor") - public static func fetch(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Any { preconditionFailure() } - @available(*, unavailable, renamed:"fetchCursor") - public static func fetch(_ db: Database, _ request: Request) -> Any { preconditionFailure() } - @available(*, unavailable, renamed:"fetchCursor") - public static func fetch(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Any { preconditionFailure() } -} - -extension DatabaseValueConvertible { - @available(*, unavailable, renamed:"fetchCursor") - public static func fetch(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Any { preconditionFailure() } - @available(*, unavailable, renamed:"fetchCursor") - public static func fetch(_ db: Database, _ request: Request) -> Any { preconditionFailure() } - @available(*, unavailable, renamed:"fetchCursor") - public static func fetch(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Any { preconditionFailure() } -} - -extension Optional where Wrapped: DatabaseValueConvertible { - @available(*, unavailable, renamed:"fetchCursor") - public static func fetch(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Any { preconditionFailure() } - @available(*, unavailable, renamed:"fetchCursor") - public static func fetch(_ db: Database, _ request: Request) -> Any { preconditionFailure() } - @available(*, unavailable, renamed:"fetchCursor") - public static func fetch(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Any { preconditionFailure() } -} - -extension QueryInterfaceRequest { - @available(*, unavailable, renamed:"fetchCursor") - public func fetch(_ db: Database) -> Any { preconditionFailure() } -} - -extension FetchableRecord { - @available(*, unavailable, renamed:"fetchCursor") - public static func fetch(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Any { preconditionFailure() } - @available(*, unavailable, renamed:"fetchCursor") - public static func fetch(_ db: Database, _ request: Request) -> Any { preconditionFailure() } - @available(*, unavailable, renamed:"fetchCursor") - public static func fetch(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Any { preconditionFailure() } -} - -extension FetchableRecord where Self: TableRecord { - @available(*, unavailable, renamed:"fetchCursor") - public static func fetch(_ db: Database) -> Any { preconditionFailure() } - @available(*, unavailable, renamed:"fetchCursor") - public static func fetch(_ db: Database, keys: Sequence) -> Any where Sequence.Iterator.Element: DatabaseValueConvertible { preconditionFailure() } - @available(*, unavailable, renamed:"fetchCursor") - public static func fetch(_ db: Database, keys: [[String: DatabaseValueConvertible?]]) -> Any { preconditionFailure() } -} - -@available(*, unavailable, message:"DatabaseSequence has been replaced by Cursor.") -public struct DatabaseSequence { } - -@available(*, unavailable, message:"DatabaseIterator has been replaced by Cursor.") -public struct DatabaseIterator { } diff --git a/GRDB/Legacy/Fixits-0.101.1.swift b/GRDB/Legacy/Fixits-0.101.1.swift deleted file mode 100644 index 78c6071fe..000000000 --- a/GRDB/Legacy/Fixits-0.101.1.swift +++ /dev/null @@ -1,4 +0,0 @@ -extension DatabaseError { - @available(*, unavailable, renamed:"resultCode") - public var code: Int32 { return 0 } -} diff --git a/GRDB/Legacy/Fixits-0.102.0.swift b/GRDB/Legacy/Fixits-0.102.0.swift deleted file mode 100644 index 379703bb6..000000000 --- a/GRDB/Legacy/Fixits-0.102.0.swift +++ /dev/null @@ -1,9 +0,0 @@ -extension Database { - @available(*, unavailable, renamed:"inTransaction") - public func writeInTransaction(_ kind: Database.TransactionKind? = nil, _ block: (Database) throws -> Database.TransactionCompletion) throws { } -} - -extension DatabaseValue { - @available(*, unavailable, message:"DatabaseSequence has been replaced by Cursor.") - public func value() -> Any { preconditionFailure() } -} diff --git a/GRDB/Legacy/Fixits-0.109.0.swift b/GRDB/Legacy/Fixits-0.109.0.swift deleted file mode 100644 index 1b9dcc727..000000000 --- a/GRDB/Legacy/Fixits-0.109.0.swift +++ /dev/null @@ -1,4 +0,0 @@ -extension FetchRequest { - @available(*, unavailable, message:"Use QueryInterfaceRequest.asRequest(of:), or AnyFetchRequest") - public func bound(to type: T.Type) -> AnyFetchRequest { preconditionFailure() } -} diff --git a/GRDB/Legacy/Fixits-1.2.swift b/GRDB/Legacy/Fixits-1.2.swift deleted file mode 100644 index 97857d01d..000000000 --- a/GRDB/Legacy/Fixits-1.2.swift +++ /dev/null @@ -1,28 +0,0 @@ -extension Row { - @available(*, unavailable, message:"use subscript instead: row[index]") - public func value(atIndex index: Int) -> DatabaseValueConvertible? { preconditionFailure() } - - @available(*, unavailable, message:"use subscript instead: row[index]") - public func value(atIndex index: Int) -> Value? { preconditionFailure() } - - @available(*, unavailable, message:"use subscript instead: row[index]") - public func value(atIndex index: Int) -> Value { preconditionFailure() } - - @available(*, unavailable, message:"use subscript instead: row[column]") - public func value(named name: String) -> DatabaseValueConvertible? { preconditionFailure() } - - @available(*, unavailable, message:"use subscript instead: row[column]") - public func value(named name: String) -> Value? { preconditionFailure() } - - @available(*, unavailable, message:"use subscript instead: row[column]") - public func value(named name: String) -> Value { preconditionFailure() } - - @available(*, unavailable, message:"use subscript instead: row[column]") - public func value(_ column: Column) -> DatabaseValueConvertible? { preconditionFailure() } - - @available(*, unavailable, message:"use subscript instead: row[column]") - public func value(_ column: Column) -> Value? { preconditionFailure() } - - @available(*, unavailable, message:"use subscript instead: row[column]") - public func value(_ column: Column) -> Value { preconditionFailure() } -} diff --git a/GRDB/Legacy/Fixits-3.0.swift b/GRDB/Legacy/Fixits-3.0.swift deleted file mode 100644 index 6ec160f41..000000000 --- a/GRDB/Legacy/Fixits-3.0.swift +++ /dev/null @@ -1,85 +0,0 @@ -/// :nodoc: -@available(*, unavailable, renamed:"FetchRequest") -public typealias Request = FetchRequest - -/// :nodoc: -@available(*, unavailable, renamed:"FetchableRecord") -public typealias RowConvertible = FetchableRecord - -/// :nodoc: -@available(*, unavailable, renamed:"TableRecord") -public typealias TableMapping = TableRecord - -/// :nodoc: -@available(*, unavailable, renamed:"MutablePersistableRecord") -public typealias MutablePersistable = MutablePersistableRecord - -/// :nodoc: -@available(*, unavailable, renamed:"PersistableRecord") -public typealias Persistable = PersistableRecord - -/// :nodoc: -@available(*, unavailable, renamed:"TableAlias") -public typealias SQLTableQualifier = TableAlias - -extension Database { - /// :nodoc: - @available(*, unavailable, message: "Use db.columns(in: tableName).count instead") - public func columnCount(in tableName: String) throws -> Int { preconditionFailure() } -} - -extension SelectStatement { - /// :nodoc: - @available(*, unavailable, renamed:"DatabaseRegion") - public typealias SelectionInfo = DatabaseRegion - - /// :nodoc: - @available(*, unavailable, renamed:"databaseRegion") - public var selectionInfo: DatabaseRegion { preconditionFailure() } - - /// :nodoc: - @available(*, unavailable, renamed:"databaseRegion") - public var fetchedRegion: DatabaseRegion { preconditionFailure() } -} - -extension DatabaseEventKind { - /// :nodoc: - @available(*, unavailable, message: "Use DatabaseRegion.isModified(byEventsOfKind:) instead") - public func impacts(_ region: DatabaseRegion) -> Bool { preconditionFailure() } -} - -extension Record { - /// :nodoc: - @available(*, unavailable, renamed: "hasDatabaseChanges") - public var hasPersistentChangedValues: Bool { preconditionFailure() } - - /// :nodoc: - @available(*, unavailable, renamed: "databaseChanges") - public var persistentChangedValues: [String: DatabaseValue?] { preconditionFailure() } -} - -@available(*, unavailable, message: "Use changes methods defined on the MutablePersistableRecord protocol: databaseEquals(_:), databaseChanges(from:), updateChanges(from:)") -public final class RecordBox: Record { } - -extension MutablePersistableRecord { - /// :nodoc: - @available(*, unavailable, renamed: "databaseEquals") - public func databaseEqual(_ record: Self) -> Bool { preconditionFailure() } -} - -extension Row { - /// :nodoc: - @available(*, unavailable, message: "Use row.scopes.names instead") - var scopeNames: Set { preconditionFailure() } - - /// :nodoc: - @available(*, unavailable, message: "Use row.scopes[name] instead") - public func scoped(on name: String) -> Row? { preconditionFailure() } -} - -extension FetchRequest { - - /// :nodoc: - @available(*, unavailable, renamed:"databaseRegion(_:)") - public func fetchedRegion(_ db: Database) throws -> DatabaseRegion { preconditionFailure() } -} diff --git a/GRDB/Legacy/Fixits-Swift2.swift b/GRDB/Legacy/Fixits-Swift2.swift deleted file mode 100644 index 2dc4fc9ff..000000000 --- a/GRDB/Legacy/Fixits-Swift2.swift +++ /dev/null @@ -1,210 +0,0 @@ -// -// Fixits-Swift2.swift -// GRDB -// -// Created by Swiftlyfalling. -// -// Provides automatic renaming Fix-Its for many of the Swift 2.x -> Swift 3 GRDB API changes. -// Consult the CHANGELOG.md and documentation for details on all of the changes. -// - -import Foundation -#if os(iOS) - import UIKit -#endif - -// Database Connections - -@available(*, unavailable, renamed:"Database.BusyMode") -public typealias BusyMode = Database.BusyMode - -@available(*, unavailable, renamed:"Database.CheckpointMode") -public typealias CheckpointMode = Database.CheckpointMode - -@available(*, unavailable, renamed:"Database.TransactionKind") -public typealias TransactionKind = Database.TransactionKind - -@available(*, unavailable, renamed:"Database.TransactionCompletion") -public typealias TransactionCompletion = Database.TransactionCompletion - -@available(*, unavailable, renamed:"Database.BusyCallback") -public typealias BusyCallback = Database.BusyCallback - -extension DatabasePool { -#if os(iOS) - @available(*, unavailable, renamed:"setupMemoryManagement(in:)") - public func setupMemoryManagement(application: UIApplication) { } -#endif -#if SQLITE_HAS_CODEC - @available(*, unavailable, renamed:"change(passphrase:)") - public func changePassphrase(_ passphrase: String) throws { } -#endif -} - -extension DatabaseQueue { -#if os(iOS) - @available(*, unavailable, renamed:"setupMemoryManagement(in:)") - public func setupMemoryManagement(application: UIApplication) { } -#endif -#if SQLITE_HAS_CODEC - @available(*, unavailable, renamed:"change(passphrase:)") - public func changePassphrase(_ passphrase: String) throws { } -#endif -} - -// SQL Functions - -extension Database { - @available(*, unavailable, renamed:"add(function:)") - public func addFunction(_ function: DatabaseFunction) { } - - @available(*, unavailable, renamed:"remove(function:)") - public func removeFunction(_ function: DatabaseFunction) { } -} - -extension DatabasePool { - @available(*, unavailable, renamed:"add(function:)") - public func addFunction(_ function: DatabaseFunction) { } - - @available(*, unavailable, renamed:"remove(function:)") - public func removeFunction(_ function: DatabaseFunction) { } -} - -extension DatabaseQueue { - @available(*, unavailable, renamed:"add(function:)") - public func addFunction(_ function: DatabaseFunction) { } - - @available(*, unavailable, renamed:"remove(function:)") - public func removeFunction(_ function: DatabaseFunction) { } -} - -extension DatabaseReader { - @available(*, unavailable, renamed:"add(function:)") - public func addFunction(_ function: DatabaseFunction) { } - - @available(*, unavailable, renamed:"remove(function:)") - public func removeFunction(_ function: DatabaseFunction) { } -} - -extension DatabaseFunction { - @available(*, unavailable, renamed:"capitalize") - public static let capitalizedString = capitalize - - @available(*, unavailable, renamed:"lowercase") - public static let lowercaseString = lowercase - - @available(*, unavailable, renamed:"uppercase") - public static let uppercaseString = uppercase -} - -@available(iOS 9.0, OSX 10.11, watchOS 3.0, *) -extension DatabaseFunction { - @available(*, unavailable, renamed:"localizedCapitalize") - public static let localizedCapitalizedString = localizedCapitalize - - @available(*, unavailable, renamed:"localizedLowercase") - public static let localizedLowercaseString = localizedLowercase - - @available(*, unavailable, renamed:"localizedUppercase") - public static let localizedUppercaseString = localizedUppercase -} - -// SQL Collations - -extension Database { - @available(*, unavailable, renamed:"add(collation:)") - public func addCollation(_ collation: DatabaseCollation) { } - - @available(*, unavailable, renamed:"remove(collation:)") - public func removeCollation(_ collation: DatabaseCollation) { } -} - -extension DatabasePool { - @available(*, unavailable, renamed:"add(collation:)") - public func addCollation(_ collation: DatabaseCollation) { } - - @available(*, unavailable, renamed:"remove(collation:)") - public func removeCollation(_ collation: DatabaseCollation) { } -} - -extension DatabaseQueue { - @available(*, unavailable, renamed:"add(collation:)") - public func addCollation(_ collation: DatabaseCollation) { } - - @available(*, unavailable, renamed:"remove(collation:)") - public func removeCollation(_ collation: DatabaseCollation) { } -} - -extension DatabaseReader { - @available(*, unavailable, renamed:"add(collation:)") - public func addCollation(_ collation: DatabaseCollation) { } - - @available(*, unavailable, renamed:"remove(collation:)") - public func removeCollation(_ collation: DatabaseCollation) { } -} - -// Prepared Statements - -extension Database { - @available(*, unavailable, renamed:"makeSelectStatement(_:)") - func selectStatement(_ sql: String) throws -> SelectStatement { preconditionFailure() } - - @available(*, unavailable, renamed:"makeUpdateStatement(_:)") - func updateStatement(_ sql: String) throws -> UpdateStatement { preconditionFailure() } -} - -extension Statement { - @available(*, unavailable, renamed:"validate(arguments:)") - public func validateArguments(_ arguments: StatementArguments) throws { } -} - -// Transaction Observers - -extension Database { - @available(*, unavailable, message:"Use add(transactionObserver:) instead. Database events filtering is now performed by transaction observers themselves.") - public func addTransactionObserver(_ transactionObserver: TransactionObserver, forDatabaseEvents filter: ((DatabaseEventKind) -> Bool)? = nil) { } - - @available(*, unavailable, renamed:"remove(transactionObserver:)") - public func removeTransactionObserver(_ transactionObserver: TransactionObserver) { } -} - -extension DatabaseWriter { - @available(*, unavailable, message:"Use add(transactionObserver:) instead. Database events filtering is now performed by transaction observers themselves.") - public func addTransactionObserver(_ transactionObserver: TransactionObserver, forDatabaseEvents filter: ((DatabaseEventKind) -> Bool)? = nil) { } - - @available(*, unavailable, renamed:"remove(transactionObserver:)") - public func removeTransactionObserver(_ transactionObserver: TransactionObserver) { } -} - -@available(*, unavailable, renamed:"TransactionObserver") -public typealias TransactionObserverType = TransactionObserver - -// Query Interface - -@available(*, unavailable, renamed:"Column") -public typealias SQLColumn = Column - -/// :nodoc: -extension SQLSpecificExpressible { - @available(*, unavailable, renamed:"capitalized") - public var capitalizedString: SQLExpression { get { return capitalized } } - - @available(*, unavailable, renamed:"lowercased") - public var lowercaseString: SQLExpression { get { return lowercased } } - - @available(*, unavailable, renamed:"uppercased") - public var uppercaseString: SQLExpression { get { return uppercased } } -} - -/// :nodoc: -@available(iOS 9.0, OSX 10.11, watchOS 3.0, *) -extension SQLSpecificExpressible { - @available(*, unavailable, renamed:"localizedCapitalized") - public var localizedCapitalizedString: SQLExpression { get { return localizedCapitalized } } - - @available(*, unavailable, renamed:"localizedLowercased") - public var localizedLowercaseString: SQLExpression { get { return localizedLowercased } } - - @available(*, unavailable, renamed:"localizedUppercased") - public var localizedUppercaseString: SQLExpression { get { return localizedUppercased } } -} diff --git a/GRDB/Migration/DatabaseMigrator.swift b/GRDB/Migration/DatabaseMigrator.swift index c993fe241..b8d18d176 100644 --- a/GRDB/Migration/DatabaseMigrator.swift +++ b/GRDB/Migration/DatabaseMigrator.swift @@ -100,7 +100,7 @@ public struct DatabaseMigrator { /// t.autoIncrementedPrimaryKey("id") /// t.column("name", .text).notNull() /// } - /// try db.execute("INSERT INTO new_player SELECT * FROM player") + /// try db.execute(sql: "INSERT INTO new_player SELECT * FROM player") /// try db.drop(table: "player") /// try db.rename(table: "new_player", to: "player") /// } @@ -119,7 +119,7 @@ public struct DatabaseMigrator { registerMigration(Migration(identifier: identifier, disabledForeignKeyChecks: true, migrate: migrate)) } #else - @available(iOS 8.2, OSX 10.10, *) + @available(OSX 10.10, *) /// Registers an advanced migration, as described at https://www.sqlite.org/lang_altertable.html#otheralter /// /// // Add a NOT NULL constraint on players.name: @@ -128,7 +128,7 @@ public struct DatabaseMigrator { /// t.autoIncrementedPrimaryKey("id") /// t.column("name", .text).notNull() /// } - /// try db.execute("INSERT INTO new_player SELECT * FROM player") + /// try db.execute(sql: "INSERT INTO new_player SELECT * FROM player") /// try db.drop(table: "player") /// try db.rename(table: "new_player", to: "player") /// } @@ -237,11 +237,11 @@ public struct DatabaseMigrator { } private func setupMigrations(_ db: Database) throws { - try db.execute("CREATE TABLE IF NOT EXISTS grdb_migrations (identifier TEXT NOT NULL PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE IF NOT EXISTS grdb_migrations (identifier TEXT NOT NULL PRIMARY KEY)") } private func appliedIdentifiers(_ db: Database) throws -> Set { - return try Set(String.fetchAll(db, "SELECT identifier FROM grdb_migrations")) + return try Set(String.fetchAll(db, sql: "SELECT identifier FROM grdb_migrations")) } private func runMigrations(_ db: Database, upTo targetIdentifier: String) throws { diff --git a/GRDB/Migration/Migration.swift b/GRDB/Migration/Migration.swift index 8b54d9da3..17d60de28 100644 --- a/GRDB/Migration/Migration.swift +++ b/GRDB/Migration/Migration.swift @@ -17,7 +17,7 @@ struct Migration { self.migrate = migrate } - @available(iOS 8.2, OSX 10.10, *) + @available(OSX 10.10, *) // PRAGMA foreign_key_check was introduced in SQLite 3.7.16 http://www.sqlite.org/changes.html#version_3_7_16 // It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS) init(identifier: String, disabledForeignKeyChecks: Bool, migrate: @escaping (Database) throws -> Void) { @@ -28,7 +28,7 @@ struct Migration { #endif func run(_ db: Database) throws { - if try disabledForeignKeyChecks && (Bool.fetchOne(db, "PRAGMA foreign_keys") ?? false) { + if try disabledForeignKeyChecks && (Bool.fetchOne(db, sql: "PRAGMA foreign_keys") ?? false) { try runWithDisabledForeignKeys(db) } else { try runWithoutDisabledForeignKeys(db) @@ -50,7 +50,7 @@ struct Migration { // // > 1. If foreign key constraints are enabled, disable them using // > PRAGMA foreign_keys=OFF. - try db.execute("PRAGMA foreign_keys = OFF") + try db.execute(sql: "PRAGMA foreign_keys = OFF") // > 2. Start a transaction. try db.inTransaction(.immediate) { @@ -60,7 +60,7 @@ struct Migration { // > 10. If foreign key constraints were originally enabled then run PRAGMA // > foreign_key_check to verify that the schema change did not break any foreign key // > constraints. - if try Row.fetchOne(db, "PRAGMA foreign_key_check") != nil { + if try Row.fetchOne(db, sql: "PRAGMA foreign_key_check") != nil { // https://www.sqlite.org/pragma.html#pragma_foreign_key_check // // PRAGMA foreign_key_check does not return an error, @@ -76,10 +76,10 @@ struct Migration { } // > 12. If foreign keys constraints were originally enabled, reenable them now. - try db.execute("PRAGMA foreign_keys = ON") + try db.execute(sql: "PRAGMA foreign_keys = ON") } private func insertAppliedIdentifier(_ db: Database) throws { - try db.execute("INSERT INTO grdb_migrations (identifier) VALUES (?)", arguments: [identifier]) + try db.execute(sql: "INSERT INTO grdb_migrations (identifier) VALUES (?)", arguments: [identifier]) } } diff --git a/GRDB/QueryInterface/Association/Association.swift b/GRDB/QueryInterface/Association/Association.swift deleted file mode 100644 index d38f4cdcb..000000000 --- a/GRDB/QueryInterface/Association/Association.swift +++ /dev/null @@ -1,408 +0,0 @@ -/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) -/// -/// The base protocol for all associations that define a connection between two -/// record types. -public protocol Association: DerivableRequest { - // OriginRowDecoder and RowDecoder provide type safety: - // - // Book.including(required: Book.author) // compiles - // Fruit.including(required: Book.author) // does not compile - - /// The record type at the origin of the association. - /// - /// In the `belongsTo` association below, it is Book: - /// - /// struct Book: TableRecord { - /// // BelongsToAssociation - /// static let author = belongsTo(Author.self) - /// } - associatedtype OriginRowDecoder - - /// The associated record type. - /// - /// In the `belongsTo` association below, it is Author: - /// - /// struct Book: TableRecord { - /// // BelongsToAssociation - /// static let author = belongsTo(Author.self) - /// } - associatedtype RowDecoder - - // Association is a protocol, not a struct. - // This is because we want associations to be richly typed. - // Yet, we don't want to pollute user code with implementation details of - // associations. So let's hide all this stuff behind the _impl property: - - /// :nodoc: - associatedtype Impl: AssociationImpl - - /// :nodoc: - var _impl: Impl { get } - - /// :nodoc: - init(_impl: Impl) -} - -extension Association { - private func mapImpl(_ transform: (Impl) throws -> Impl) rethrows -> Self { - return try Self.init(_impl: transform(_impl)) - } - - private func mapRelation(_ transform: (SQLRelation) -> SQLRelation) -> Self { - return mapImpl { $0.mapRelation(transform) } - } -} - -extension Association { - - /// The association key defines how rows fetched from this association - /// should be consumed. - /// - /// For example: - /// - /// struct Player: TableRecord { - /// // The default key of this association is the name of the - /// // database table for teams, let's say "team": - /// static let team = belongsTo(Team.self) - /// } - /// print(Player.team.key) // Prints "team" - /// - /// // Consume rows: - /// let request = Player.including(required: Player.team) - /// for row in Row.fetchAll(db, request) { - /// let team: Team = row["team"] // the association key - /// } - /// - /// The key can be redefined with the `forKey` method: - /// - /// let request = Player.including(required: Player.team.forKey("custom")) - /// for row in Row.fetchAll(db, request) { - /// let team: Team = row["custom"] - /// } - var key: String { - return _impl.key - } - - /// Creates an association which selects *selection*. - /// - /// struct Player: TableRecord { - /// static let team = belongsTo(Team.self) - /// } - /// - /// // SELECT player.*, team.color - /// // FROM player - /// // JOIN team ON team.id = player.teamId - /// let association = Player.team.select([Column("color")]) - /// var request = Player.including(required: association) - /// - /// Any previous selection is replaced: - /// - /// // SELECT player.*, team.color - /// // FROM player - /// // JOIN team ON team.id = player.teamId - /// let association = Player.team - /// .select([Column("id")]) - /// .select([Column("color")]) - /// var request = Player.including(required: association) - public func select(_ selection: [SQLSelectable]) -> Self { - return mapRelation { $0.select(selection) } - } - - /// Creates an association with the provided *predicate promise* added to - /// the eventual set of already applied predicates. - /// - /// struct Player: TableRecord { - /// static let team = belongsTo(Team.self) - /// } - /// - /// // SELECT player.*, team.* - /// // FROM player - /// // JOIN team ON team.id = player.teamId AND 1 - /// let association = Player.team.filter { db in true } - /// var request = Player.including(required: association) - public func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> Self { - return mapRelation { $0.filter(predicate) } - } - - /// Creates an association with the provided *orderings promise*. - /// - /// struct Player: TableRecord { - /// static let team = belongsTo(Team.self) - /// } - /// - /// // SELECT player.*, team.* - /// // FROM player - /// // JOIN team ON team.id = player.teamId - /// // ORDER BY team.name - /// let association = Player.team.order { _ in [Column("name")] } - /// var request = Player.including(required: association) - /// - /// Any previous ordering is replaced: - /// - /// // SELECT player.*, team.* - /// // FROM player - /// // JOIN team ON team.id = player.teamId - /// // ORDER BY team.name - /// let association = Player.team - /// .order{ _ in [Column("color")] } - /// .reversed() - /// .order{ _ in [Column("name")] } - /// var request = Player.including(required: association) - public func order(_ orderings: @escaping (Database) throws -> [SQLOrderingTerm]) -> Self { - return mapRelation { $0.order(orderings) } - } - - /// Creates an association that reverses applied orderings. - /// - /// struct Player: TableRecord { - /// static let team = belongsTo(Team.self) - /// } - /// - /// // SELECT player.*, team.* - /// // FROM player - /// // JOIN team ON team.id = player.teamId - /// // ORDER BY team.name DESC - /// let association = Player.team.order(Column("name")).reversed() - /// var request = Player.including(required: association) - /// - /// If no ordering was applied, the returned association is identical. - /// - /// // SELECT player.*, team.* - /// // FROM player - /// // JOIN team ON team.id = player.teamId - /// let association = Player.team.reversed() - /// var request = Player.including(required: association) - public func reversed() -> Self { - return mapRelation { $0.reversed() } - } - - /// Creates an association with the given key. - /// - /// This new key impacts how rows fetched from the resulting association - /// should be consumed: - /// - /// struct Player: TableRecord { - /// static let team = belongsTo(Team.self) - /// } - /// - /// // Consume rows: - /// let request = Player.including(required: Player.team.forKey("custom")) - /// for row in Row.fetchAll(db, request) { - /// let team: Team = row["custom"] - /// } - public func forKey(_ key: String) -> Self { - return mapImpl { $0.forKey(key) } - } - - /// Creates an association with the given key. - /// - /// This new key helps Decodable records decode rows fetched from the - /// resulting association: - /// - /// struct Player: TableRecord { - /// static let team = belongsTo(Team.self) - /// } - /// - /// struct PlayerInfo: FetchableRecord, Decodable { - /// let player: Player - /// let team: Team - /// - /// static func all() -> QueryInterfaceRequest { - /// return Player - /// .including(required: Player.team.forKey(CodingKeys.team)) - /// .asRequest(of: PlayerInfo.self) - /// } - /// } - /// - /// let playerInfos = PlayerInfo.all().fetchAll(db) - /// print(playerInfos.first?.team) - public func forKey(_ codingKey: CodingKey) -> Self { - return forKey(codingKey.stringValue) - } - - /// Creates an association that allows you to define expressions that target - /// a specific database table. - /// - /// In the example below, the "team.color = 'red'" condition in the where - /// clause could be not achieved without table aliases. - /// - /// struct Player: TableRecord { - /// static let team = belongsTo(Team.self) - /// } - /// - /// // SELECT player.*, team.* - /// // JOIN team ON ... - /// // WHERE team.color = 'red' - /// let teamAlias = TableAlias() - /// let request = Player - /// .including(required: Player.team.aliased(teamAlias)) - /// .filter(teamAlias[Column("color")] == "red") - /// - /// When you give a name to a table alias, you can reliably inject sql - /// snippets in your requests: - /// - /// // SELECT player.*, custom.* - /// // JOIN team custom ON ... - /// // WHERE custom.color = 'red' - /// let teamAlias = TableAlias(name: "custom") - /// let request = Player - /// .including(required: Player.team.aliased(teamAlias)) - /// .filter(sql: "custom.color = ?", arguments: ["red"]) - public func aliased(_ alias: TableAlias) -> Self { - return mapRelation { $0.qualified(with: alias) } - } -} - -extension Association { - /// Creates an association that includes another one. The columns of the - /// associated record are selected. The returned association does not - /// require that the associated database table contains a matching row. - public func including(optional association: A) -> Self where A.OriginRowDecoder == RowDecoder { - return mapRelation { association._impl.joinedRelation($0, joinOperator: .optional) } - } - - /// Creates an association that includes another one. The columns of the - /// associated record are selected. The returned association requires - /// that the associated database table contains a matching row. - public func including(required association: A) -> Self where A.OriginRowDecoder == RowDecoder { - return mapRelation { association._impl.joinedRelation($0, joinOperator: .required) } - } - - /// Creates an association that joins another one. The columns of the - /// associated record are not selected. The returned association does not - /// require that the associated database table contains a matching row. - public func joining(optional association: A) -> Self where A.OriginRowDecoder == RowDecoder { - return mapRelation { association.select([])._impl.joinedRelation($0, joinOperator: .optional) } - } - - /// Creates an association that joins another one. The columns of the - /// associated record are not selected. The returned association requires - /// that the associated database table contains a matching row. - public func joining(required association: A) -> Self where A.OriginRowDecoder == RowDecoder { - return mapRelation { association.select([])._impl.joinedRelation($0, joinOperator: .required) } - } -} - -extension Association where OriginRowDecoder: MutablePersistableRecord { - /// Support for MutablePersistableRecord.request(for:). - /// - /// For example: - /// - /// struct Team: { - /// static let players = hasMany(Player.self) - /// var players: QueryInterfaceRequest { - /// return request(for: Team.players) - /// } - /// } - /// - /// let team: Team = ... - /// let players = try team.players.fetchAll(db) // [Player] - func request(from record: OriginRowDecoder) -> QueryInterfaceRequest { - // Goal: turn `JOIN association ON association.recordId = record.id` - // into a regular request `SELECT * FROM association WHERE association.recordId = 123` - - // We need table aliases to build the joining condition - let associationAlias = TableAlias() - let recordAlias = TableAlias() - - // Turn the association query into a query interface request: - // JOIN association -> SELECT FROM association - return QueryInterfaceRequest(query: SQLSelectQuery(relation: _impl.relation)) - - // Turn the JOIN condition into a regular WHERE condition - .filter { db in - // Build a join condition: `association.recordId = record.id` - // We still need to replace `record.id` with the actual record id. - let joinExpression = try self._impl.joinCondition.sqlExpression(db, leftAlias: recordAlias, rightAlias: associationAlias) - - // Serialize record: ["id": 123, ...] - // We do it as late as possible, when request is about to be - // executed, in order to support long-lived reference types. - let container = PersistenceContainer(record) - - // Replace `record.id` with 123 - return joinExpression.resolvedExpression(inContext: [recordAlias: container]) - } - - // We just added a condition qualified with associationAlias. Don't - // risk introducing conflicting aliases that would prevent the user - // from setting a custom alias name: force the same alias for the - // whole request. - .aliased(associationAlias) - } -} - -// MARK: - AssociationImpl - -/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) -/// -/// The protocol for implementation details of associations. -/// -/// :nodoc: -public /* TODO: internal */ protocol AssociationImpl { - /// The association key - var key: String { get } - - /// Creates an association with the given key. - func forKey(_ key: String) -> Self - - /// Returns an association whose relation is transformed by the - /// given closure. - /// - /// This method provides fundamental support for association derivation: - /// - /// // Invokes Book.author.mapRelation { $0.filter(...) } - /// Book.author.filter(...) - func mapRelation(_ transform: (SQLRelation) -> SQLRelation) -> Self - - /// Returns a relation joined with self. - /// - /// This method provides fundamental support for joining methods. - func joinedRelation(_ relation: SQLRelation, joinOperator: JoinOperator) -> SQLRelation - - // TODO: remove relation & joinCondition properties. - // - // They assume that an association is implemented as a direct join to an - // associated table. This is limiting: has-one-through and has-many-through - // associations can't be implemented in such context. - // - // Their impact is limited yet. Those propertise are currently only used by - // Association.request(from:). When this method gets a new implementation - // that does not need a direct join to an associated table, we'll be able to - // remove those properties. - var relation: SQLRelation { get } - var joinCondition: JoinCondition { get } -} - -// MARK: - - -/// The AssociationImpl shared by BelongsTo, HasOne, and HasMany, which is -/// implemented as a simple join. -/// -/// :nodoc: -public /* TODO: internal */ struct JoinAssociationImpl: AssociationImpl { - public var key: String - public /* TODO: internal */ let joinCondition: JoinCondition - public /* TODO: internal */ var relation: SQLRelation - - public func forKey(_ key: String) -> JoinAssociationImpl { - var assoc = self - assoc.key = key - return assoc - } - - public func mapRelation(_ transform: (SQLRelation) -> SQLRelation) -> JoinAssociationImpl { - var assoc = self - assoc.relation = transform(relation) - return assoc - } - - public func joinedRelation(_ relation: SQLRelation, joinOperator: JoinOperator) -> SQLRelation { - let join = SQLJoin( - joinOperator: joinOperator, - joinCondition: joinCondition, - relation: self.relation) - return relation.appendingJoin(join, forKey: key) - } -} - diff --git a/GRDB/QueryInterface/Association/BelongsToAssociation.swift b/GRDB/QueryInterface/Association/BelongsToAssociation.swift deleted file mode 100644 index 32c9f390a..000000000 --- a/GRDB/QueryInterface/Association/BelongsToAssociation.swift +++ /dev/null @@ -1,161 +0,0 @@ -/// The BelongsTo association sets up a one-to-one connection from a record -/// type to another record type, such as each instance of the declaring record -/// "belongs to" an instance of the other record. -/// -/// For example, if your application includes authors and books, and each book -/// is assigned its author, you'd declare the association this way: -/// -/// struct Author: TableRecord { ... } -/// struct Book: TableRecord { -/// static let author = belongsTo(Author.self) -/// ... -/// } -/// -/// A BelongsTo associations should be supported by an SQLite foreign key. -/// -/// Foreign keys are the recommended way to declare relationships between -/// database tables because not only will SQLite guarantee the integrity of your -/// data, but GRDB will be able to use those foreign keys to automatically -/// configure your association. -/// -/// You define the foreign key when you create database tables. For example: -/// -/// try db.create(table: "author") { t in -/// t.autoIncrementedPrimaryKey("id") // (1) -/// t.column("name", .text) -/// } -/// try db.create(table: "book") { t in -/// t.autoIncrementedPrimaryKey("id") -/// t.column("authorId", .integer) // (2) -/// .notNull() // (3) -/// .indexed() // (4) -/// .references("author", onDelete: .cascade) // (5) -/// t.column("title", .text) -/// } -/// -/// 1. The author table has a primary key. -/// 2. The book.authorId column is used to link a book to the author it -/// belongs to. -/// 3. Make the book.authorId column not null if you want SQLite to guarantee -/// that all books have an author. -/// 4. Create an index on the book.authorId column in order to ease the -/// selection of an author's books. -/// 5. Create a foreign key from book.authorId column to authors.id, so that -/// SQLite guarantees that no book refers to a missing author. The -/// `onDelete: .cascade` option has SQLite automatically delete all of an -/// author's books when that author is deleted. -/// See https://sqlite.org/foreignkeys.html#fk_actions for more information. -/// -/// The example above uses auto-incremented primary keys. But generally -/// speaking, all primary keys are supported. -/// -/// If the database schema does not define foreign keys between tables, you can -/// still use BelongsTo associations. But your help is needed to define the -/// missing foreign key: -/// -/// struct Book: FetchableRecord, TableRecord { -/// static let author = belongsTo(Author.self, using: ForeignKey(...)) -/// } -/// -/// See ForeignKey for more information. -public struct BelongsToAssociation: Association { - /// :nodoc: - public typealias OriginRowDecoder = Origin - - /// :nodoc: - public typealias RowDecoder = Destination - - /// :nodoc: - public var _impl: JoinAssociationImpl - - /// :nodoc: - public init(_impl: JoinAssociationImpl) { - self._impl = _impl - } -} - -// Allow BelongsToAssociation(...).filter(key: ...) -extension BelongsToAssociation: TableRequest where Destination: TableRecord { - /// :nodoc: - public var databaseTableName: String { return Destination.databaseTableName } -} - -extension TableRecord { - /// Creates a "Belongs To" association between Self and the - /// destination type. - /// - /// struct Author: TableRecord { ... } - /// struct Book: TableRecord { - /// static let author = belongsTo(Author.self) - /// } - /// - /// The association will let you define requests that load both the source - /// and the destination type: - /// - /// // A request for all books with their authors: - /// let request = Book.including(optional: Book.author) - /// - /// To consume those requests, define a type that adopts both the - /// FetchableRecord and Decodable protocols: - /// - /// struct BookInfo: FetchableRecord, Decodable { - /// var book: Book - /// var author: Author? - /// } - /// - /// let bookInfos = try dbQueue.read { db in - /// return try BookInfo.fetchAll(db, request) - /// } - /// for bookInfo in bookInfos { - /// print("\(bookInfo.book.title) by \(bookInfo.author.name)") - /// } - /// - /// It is recommended that you define, alongside the association, a property - /// with the same name: - /// - /// struct Book: TableRecord { - /// static let author = belongsTo(Author.self) - /// var author: QueryInterfaceRequest { - /// return request(for: Book.author) - /// } - /// } - /// - /// This property will let you navigate from the source type to the - /// destination type: - /// - /// try dbQueue.read { db in - /// let book: Book = ... - /// let author = try book.author.fetchOne(db) // Author? - /// } - /// - /// - parameters: - /// - destination: The record type at the other side of the association. - /// - key: An eventual decoding key for the association. By default, it - /// is `destination.databaseTableName`. - /// - foreignKey: An eventual foreign key. You need to provide an - /// explicit foreign key when GRDB can't infer one from the database - /// schema. This happens when the schema does not define any foreign - /// key to the destination table, or when the schema defines several - /// foreign keys to the destination table. - public static func belongsTo( - _ destination: Destination.Type, - key: String? = nil, - using foreignKey: ForeignKey? = nil) - -> BelongsToAssociation - where Destination: TableRecord - { - let foreignKeyRequest = ForeignKeyRequest( - originTable: databaseTableName, - destinationTable: Destination.databaseTableName, - foreignKey: foreignKey) - - let joinCondition = JoinCondition( - foreignKeyRequest: foreignKeyRequest, - originIsLeft: true) - - return BelongsToAssociation(_impl: JoinAssociationImpl( - key: key ?? Destination.databaseTableName, - joinCondition: joinCondition, - relation: Destination.all().relation)) - } -} diff --git a/GRDB/QueryInterface/Association/ForeignKey.swift b/GRDB/QueryInterface/Association/ForeignKey.swift deleted file mode 100644 index 5b4312762..000000000 --- a/GRDB/QueryInterface/Association/ForeignKey.swift +++ /dev/null @@ -1,108 +0,0 @@ -/// A ForeignKey helps building associations when GRDB can't infer a foreign -/// key from the database schema. -/// -/// Sometimes the database schema does not define any foreign key between two -/// tables. And sometimes, there are several foreign keys from a table -/// to another: -/// -/// | Table book | | Table person | -/// | ------------ | | ------------ | -/// | id | +-->• id | -/// | authorId •---+ | name | -/// | translatorId •---+ -/// | title | -/// -/// When this happens, associations can't be automatically inferred from the -/// database schema. GRDB will complain with a fatal error such as "Ambiguous -/// foreign key from book to person", or "Could not infer foreign key from book -/// to person". -/// -/// Your help is needed. You have to instruct GRDB which foreign key to use: -/// -/// struct Book: TableRecord { -/// // Define foreign keys -/// static let authorForeignKey = ForeignKey(["authorId"])) -/// static let translatorForeignKey = ForeignKey(["translatorId"])) -/// -/// // Use foreign keys to define associations: -/// static let author = belongsTo(Person.self, using: authorForeignKey) -/// static let translator = belongsTo(Person.self, using: translatorForeignKey) -/// } -/// -/// Foreign keys are always defined from the table that contains the columns at -/// the origin of the foreign key. Person's symmetric HasMany associations reuse -/// Book's foreign keys: -/// -/// struct Person: TableRecord { -/// static let writtenBooks = hasMany(Book.self, using: Book.authorForeignKey) -/// static let translatedBooks = hasMany(Book.self, using: Book.translatorForeignKey) -/// } -/// -/// Foreign keys can also be defined from query interface columns: -/// -/// struct Book: TableRecord { -/// enum Columns: String, ColumnExpression { -/// case id, title, authorId, translatorId -/// } -/// -/// static let authorForeignKey = ForeignKey([Columns.authorId])) -/// static let translatorForeignKey = ForeignKey([Columns.translatorId])) -/// } -/// -/// When the destination table of a foreign key does not define any primary key, -/// you need to provide the full definition of a foreign key: -/// -/// struct Book: TableRecord { -/// static let authorForeignKey = ForeignKey(["authorId"], to: ["id"])) -/// static let author = belongsTo(Person.self, using: authorForeignKey) -/// } -public struct ForeignKey { - var originColumns: [String] - var destinationColumns: [String]? - - /// Creates a ForeignKey intended to define a record association. - /// - /// struct Book: TableRecord { - /// // Define foreign keys - /// static let authorForeignKey = ForeignKey(["authorId"])) - /// static let translatorForeignKey = ForeignKey(["translatorId"])) - /// - /// // Use foreign keys to define associations: - /// static let author = belongsTo(Person.self, using: authorForeignKey) - /// static let translator = belongsTo(Person.self, using: translatorForeignKey) - /// } - /// - /// - parameter originColumns: The columns at the origin of the foreign key. - /// - parameter destinationColumns: The columns at the destination of the - /// foreign key. When nil (the default), GRDB automatically uses the - /// primary key. - public init(_ originColumns: [String], to destinationColumns: [String]? = nil) { - self.originColumns = originColumns - self.destinationColumns = destinationColumns - } - - /// Creates a ForeignKey intended to define a record association. - /// - /// struct Book: TableRecord { - /// // Define columns - /// enum Columns: String, ColumnExpression { - /// case id, title, authorId, translatorId - /// } - /// - /// // Define foreign keys - /// static let authorForeignKey = ForeignKey([Columns.authorId])) - /// static let translatorForeignKey = ForeignKey([Columns.translatorId])) - /// - /// // Use foreign keys to define associations: - /// static let author = belongsTo(Person.self, using: authorForeignKey) - /// static let translator = belongsTo(Person.self, using: translatorForeignKey) - /// } - /// - /// - parameter originColumns: The columns at the origin of the foreign key. - /// - parameter destinationColumns: The columns at the destination of the - /// foreign key. When nil (the default), GRDB automatically uses the - /// primary key. - public init(_ originColumns: [ColumnExpression], to destinationColumns: [ColumnExpression]? = nil) { - self.init(originColumns.map { $0.name }, to: destinationColumns?.map { $0.name }) - } -} diff --git a/GRDB/QueryInterface/Association/HasManyAssociation.swift b/GRDB/QueryInterface/Association/HasManyAssociation.swift deleted file mode 100644 index 5f0994e07..000000000 --- a/GRDB/QueryInterface/Association/HasManyAssociation.swift +++ /dev/null @@ -1,250 +0,0 @@ -/// The HasMany association indicates a one-to-many connection between two -/// record types, such as each instance of the declaring record "has many" -/// instances of the other record. -/// -/// For example, if your application includes authors and books, and each author -/// is assigned zero or more books, you'd declare the association this way: -/// -/// struct Book: TableRecord { ... } -/// struct Author: TableRecord { -/// static let books = hasMany(Book.self) -/// ... -/// } -/// -/// HasMany associations should be supported by an SQLite foreign key. -/// -/// Foreign keys are the recommended way to declare relationships between -/// database tables because not only will SQLite guarantee the integrity of your -/// data, but GRDB will be able to use those foreign keys to automatically -/// configure your association. -/// -/// You define the foreign key when you create database tables. For example: -/// -/// try db.create(table: "author") { t in -/// t.autoIncrementedPrimaryKey("id") // (1) -/// t.column("name", .text) -/// } -/// try db.create(table: "book") { t in -/// t.autoIncrementedPrimaryKey("id") -/// t.column("authorId", .integer) // (2) -/// .notNull() // (3) -/// .indexed() // (4) -/// .references("author", onDelete: .cascade) // (5) -/// t.column("title", .text) -/// } -/// -/// 1. The author table has a primary key. -/// 2. The book.authorId column is used to link a book to the author it -/// belongs to. -/// 3. Make the book.authorId column not null if you want SQLite to guarantee -/// that all books have an author. -/// 4. Create an index on the book.authorId column in order to ease the -/// selection of an author's books. -/// 5. Create a foreign key from book.authorId column to authors.id, so that -/// SQLite guarantees that no book refers to a missing author. The -/// `onDelete: .cascade` option has SQLite automatically delete all of an -/// author's books when that author is deleted. -/// See https://sqlite.org/foreignkeys.html#fk_actions for more information. -/// -/// The example above uses auto-incremented primary keys. But generally -/// speaking, all primary keys are supported. -/// -/// If the database schema does not define foreign keys between tables, you can -/// still use HasMany associations. But your help is needed to define the -/// missing foreign key: -/// -/// struct Author: TableRecord { -/// static let books = hasMany(Book.self, using: ForeignKey(...)) -/// } -/// -/// See ForeignKey for more information. -public struct HasManyAssociation: Association { - /// :nodoc: - public typealias OriginRowDecoder = Origin - - /// :nodoc: - public typealias RowDecoder = Destination - - /// :nodoc: - public var _impl: JoinAssociationImpl - - /// :nodoc: - public init(_impl: JoinAssociationImpl) { - self._impl = _impl - } -} - -// Allow HasManyAssociation(...).filter(key: ...) -extension HasManyAssociation: TableRequest where Destination: TableRecord { - /// :nodoc: - public var databaseTableName: String { return Destination.databaseTableName } -} - -extension HasManyAssociation where Origin: TableRecord, Destination: TableRecord { - private func makeAggregate(_ expression: SQLExpression) -> AssociationAggregate { - return AssociationAggregate { request in - let tableAlias = TableAlias() - let request = request - .joining(optional: self.aliased(tableAlias)) - .groupByPrimaryKey() - let expression = tableAlias[expression] - return (request: request, expression: expression) - } - } - - /// The number of associated records. - /// - /// For example: - /// - /// Team.annotated(with: Team.players.count()) - public var count: AssociationAggregate { - return makeAggregate(SQLExpressionCountDistinct(Column.rowID)).aliased("\(key)Count") - } - - /// An aggregate that is true if there exists no associated records. - /// - /// For example: - /// - /// Team.having(Team.players.isEmpty()) - /// Team.having(!Team.players.isEmpty()) - /// Team.having(Team.players.isEmpty() == false) - public var isEmpty: AssociationAggregate { - return makeAggregate(SQLExpressionIsEmpty(SQLExpressionCountDistinct(Column.rowID))) - } - - /// The average value of the given expression in associated records. - /// - /// For example: - /// - /// Team.annotated(with: Team.players.average(Column("score"))) - public func average(_ expression: SQLExpressible) -> AssociationAggregate { - let aggregate = makeAggregate(SQLExpressionFunction(.avg, arguments: expression)) - if let column = expression as? ColumnExpression { - return aggregate.aliased("average\(key.uppercasingFirstCharacter)\(column.name.uppercasingFirstCharacter)") - } else { - return aggregate - } - } - - /// The maximum value of the given expression in associated records. - /// - /// For example: - /// - /// Team.annotated(with: Team.players.max(Column("score"))) - public func max(_ expression: SQLExpressible) -> AssociationAggregate { - let aggregate = makeAggregate(SQLExpressionFunction(.max, arguments: expression)) - if let column = expression as? ColumnExpression { - return aggregate.aliased("max\(key.uppercasingFirstCharacter)\(column.name.uppercasingFirstCharacter)") - } else { - return aggregate - } - } - - /// The minimum value of the given expression in associated records. - /// - /// For example: - /// - /// Team.annotated(with: Team.players.min(Column("score"))) - public func min(_ expression: SQLExpressible) -> AssociationAggregate { - let aggregate = makeAggregate(SQLExpressionFunction(.min, arguments: expression)) - if let column = expression as? ColumnExpression { - return aggregate.aliased("min\(key.uppercasingFirstCharacter)\(column.name.uppercasingFirstCharacter)") - } else { - return aggregate - } - } - - /// The sum of the given expression in associated records. - /// - /// For example: - /// - /// Team.annotated(with: Team.players.min(Column("score"))) - public func sum(_ expression: SQLExpressible) -> AssociationAggregate { - let aggregate = makeAggregate(SQLExpressionFunction(.sum, arguments: expression)) - if let column = expression as? ColumnExpression { - return aggregate.aliased("\(key)\(column.name.uppercasingFirstCharacter)Sum") - } else { - return aggregate - } - } -} - -extension TableRecord { - /// Creates a "Has many" association between Self and the - /// destination type. - /// - /// struct Book: TableRecord { ... } - /// struct Author: TableRecord { - /// static let books = hasMany(Book.self) - /// } - /// - /// The association will let you define requests that load both the source - /// and the destination type: - /// - /// // A request for all (author, book) pairs: - /// let request = Author.including(required: Author.books) - /// - /// To consume those requests, define a type that adopts both the - /// FetchableRecord and Decodable protocols: - /// - /// struct Authorship: FetchableRecord, Decodable { - /// var author: Author - /// var book: Book - /// } - /// - /// let authorships = try dbQueue.read { db in - /// return try Authorship.fetchAll(db, request) - /// } - /// for authorship in authorships { - /// print("\(authorship.author.name) wrote \(authorship.book.title)") - /// } - /// - /// It is recommended that you define, alongside the association, a property - /// with the same name: - /// - /// struct Author: TableRecord { - /// static let books = hasMany(Book.self) - /// var books: QueryInterfaceRequest { - /// return request(for: Author.books) - /// } - /// } - /// - /// This property will let you navigate from the source type to the - /// destination type: - /// - /// try dbQueue.read { db in - /// let author: Author = ... - /// let books = try author.books.fetchAll(db) // [Book] - /// } - /// - /// - parameters: - /// - destination: The record type at the other side of the association. - /// - key: An eventual decoding key for the association. By default, it - /// is `destination.databaseTableName`. - /// - foreignKey: An eventual foreign key. You need to provide an - /// explicit foreign key when GRDB can't infer one from the database - /// schema. This happens when the schema does not define any foreign - /// key from the destination table, or when the schema defines several - /// foreign keys from the destination table. - public static func hasMany( - _ destination: Destination.Type, - key: String? = nil, - using foreignKey: ForeignKey? = nil) - -> HasManyAssociation - where Destination: TableRecord - { - let foreignKeyRequest = ForeignKeyRequest( - originTable: Destination.databaseTableName, - destinationTable: databaseTableName, - foreignKey: foreignKey) - - let joinCondition = JoinCondition( - foreignKeyRequest: foreignKeyRequest, - originIsLeft: false) - - return HasManyAssociation(_impl: JoinAssociationImpl( - key: key ?? Destination.databaseTableName, - joinCondition: joinCondition, - relation: Destination.all().relation)) - } -} diff --git a/GRDB/QueryInterface/Association/HasOneAssociation.swift b/GRDB/QueryInterface/Association/HasOneAssociation.swift deleted file mode 100644 index 61779de5f..000000000 --- a/GRDB/QueryInterface/Association/HasOneAssociation.swift +++ /dev/null @@ -1,163 +0,0 @@ -/// The HasOne association indicates a one-to-one connection between two -/// record types, such as each instance of the declaring record "has one" -/// instances of the other record. -/// -/// For example, if your application has one database table for countries, and -/// another for their demographic profiles, you'd declare the association -/// this way: -/// -/// struct Demographics: TableRecord { ... } -/// struct Country: TableRecord { -/// static let demographics = hasOne(Demographics.self) -/// ... -/// } -/// -/// HasOne associations should be supported by an SQLite foreign key. -/// -/// Foreign keys are the recommended way to declare relationships between -/// database tables because not only will SQLite guarantee the integrity of your -/// data, but GRDB will be able to use those foreign keys to automatically -/// configure your association. -/// -/// You define the foreign key when you create database tables. For example: -/// -/// try db.create(table: "country") { t in -/// t.column("code", .text).primaryKey() // (1) -/// t.column("name", .text) -/// } -/// try db.create(table: "demographics") { t in -/// t.autoIncrementedPrimaryKey("id") -/// t.column("countryCode", .text) // (2) -/// .notNull() // (3) -/// .unique() // (4) -/// .references("country", onDelete: .cascade) // (5) -/// t.column("population", .integer) -/// t.column("density", .double) -/// } -/// -/// 1. The country table has a primary key. -/// 2. The demographics.countryCode column is used to link a demographic -/// profile to the country it belongs to. -/// 3. Make the demographics.countryCode column not null if you want SQLite to -/// guarantee that all profiles are linked to a country. -/// 4. Create a unique index on the demographics.countryCode column in order to -/// guarantee the unicity of any country's profile. -/// 5. Create a foreign key from demographics.countryCode column to -/// country.code, so that SQLite guarantees that no profile refers to a -/// missing country. The `onDelete: .cascade` option has SQLite automatically -/// delete a profile when its country is deleted. -/// See https://sqlite.org/foreignkeys.html#fk_actions for more information. -/// -/// The example above uses a string primary for the country table. But generally -/// speaking, all primary keys are supported. -/// -/// If the database schema does not follow this convention, and does not define -/// foreign keys between tables, you can still use HasOne associations. But -/// your help is needed to define the missing foreign key: -/// -/// struct Country: FetchableRecord, TableRecord { -/// static let demographics = hasOne(Demographics.self, using: ForeignKey(...)) -/// } -/// -/// See ForeignKey for more information. -public struct HasOneAssociation: Association { - /// :nodoc: - public typealias OriginRowDecoder = Origin - - /// :nodoc: - public typealias RowDecoder = Destination - - /// :nodoc: - public var _impl: JoinAssociationImpl - - /// :nodoc: - public init(_impl: JoinAssociationImpl) { - self._impl = _impl - } -} - -// Allow HasOneAssociation(...).filter(key: ...) -extension HasOneAssociation: TableRequest where Destination: TableRecord { - /// :nodoc: - public var databaseTableName: String { return Destination.databaseTableName } -} - -extension TableRecord { - /// Creates a "Has one" association between Self and the - /// destination type. - /// - /// struct Demographics: TableRecord { ... } - /// struct Country: TableRecord { - /// static let demographics = hasOne(Demographics.self) - /// } - /// - /// The association will let you define requests that load both the source - /// and the destination type: - /// - /// // A request for all countries with their demographic profile: - /// let request = Country.including(optional: Country.demographics) - /// - /// To consume those requests, define a type that adopts both the - /// FetchableRecord and Decodable protocols: - /// - /// struct CountryInfo: FetchableRecord, Decodable { - /// var country: Country - /// var demographics: Demographics? - /// } - /// - /// let countryInfos = try dbQueue.read { db in - /// return try CountryInfo.fetchAll(db, request) - /// } - /// for countryInfo in countryInfos { - /// print("\(countryInfo.country.name) has \(countryInfo.demographics.population) citizens") - /// } - /// - /// It is recommended that you define, alongside the association, a property - /// with the same name: - /// - /// struct Country: TableRecord { - /// static let demographics = hasOne(Demographics.self) - /// var demographics: QueryInterfaceRequest { - /// return request(for: Country.demographics) - /// } - /// } - /// - /// This property will let you navigate from the source type to the - /// destination type: - /// - /// try dbQueue.read { db in - /// let country: Country = ... - /// let demographics = try country.demographics.fetchOne(db) // Demographics? - /// } - /// - /// - parameters: - /// - destination: The record type at the other side of the association. - /// - key: An eventual decoding key for the association. By default, it - /// is `destination.databaseTableName`. - /// - foreignKey: An eventual foreign key. You need to provide an - /// explicit foreign key when GRDB can't infer one from the database - /// schema. This happens when the schema does not define any foreign - /// key from the destination table, or when the schema defines several - /// foreign keys from the destination table. - public static func hasOne( - _ destination: Destination.Type, - key: String? = nil, - using foreignKey: ForeignKey? = nil) - -> HasOneAssociation - where Destination: TableRecord - { - let foreignKeyRequest = ForeignKeyRequest( - originTable: Destination.databaseTableName, - destinationTable: databaseTableName, - foreignKey: foreignKey) - - let joinCondition = JoinCondition( - foreignKeyRequest: foreignKeyRequest, - originIsLeft: false) - - return HasOneAssociation(_impl: JoinAssociationImpl( - key: key ?? Destination.databaseTableName, - joinCondition: joinCondition, - relation: Destination.all().relation)) - } -} diff --git a/GRDB/QueryInterface/FTS3+QueryInterfaceRequest.swift b/GRDB/QueryInterface/FTS3+QueryInterface.swift similarity index 100% rename from GRDB/QueryInterface/FTS3+QueryInterfaceRequest.swift rename to GRDB/QueryInterface/FTS3+QueryInterface.swift diff --git a/GRDB/QueryInterface/FetchableRecord+QueryInterfaceRequest.swift b/GRDB/QueryInterface/FetchableRecord+QueryInterfaceRequest.swift new file mode 100644 index 000000000..c600e87f1 --- /dev/null +++ b/GRDB/QueryInterface/FetchableRecord+QueryInterfaceRequest.swift @@ -0,0 +1,120 @@ +extension QueryInterfaceRequest where RowDecoder: FetchableRecord { + /// A cursor over fetched records. + /// + /// let request: QueryInterfaceRequest = ... + /// let players = try request.fetchCursor(db) // Cursor of Player + /// while let player = try players.next() { // Player + /// ... + /// } + /// + /// If the database is modified during the cursor iteration, the remaining + /// elements are undefined. + /// + /// The cursor must be iterated in a protected dispath queue. + /// + /// - parameter db: A database connection. + /// - returns: A cursor over fetched records. + /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. + public func fetchCursor(_ db: Database) throws -> RecordCursor { + return try RowDecoder.fetchCursor(db, self) + } + + /// An array of fetched records. + /// + /// let request: QueryInterfaceRequest = ... + /// let players = try request.fetchAll(db) // [Player] + /// + /// - parameter db: A database connection. + /// - returns: An array of records. + /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. + public func fetchAll(_ db: Database) throws -> [RowDecoder] { + return try RowDecoder.fetchAll(db, self) + } + + /// The first fetched record. + /// + /// let request: QueryInterfaceRequest = ... + /// let player = try request.fetchOne(db) // Player? + /// + /// - parameter db: A database connection. + /// - returns: An optional record. + /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. + public func fetchOne(_ db: Database) throws -> RowDecoder? { + return try RowDecoder.fetchOne(db, self) + } +} + +extension FetchableRecord { + + // MARK: Fetching From QueryInterfaceRequest + + /// Returns a cursor over records fetched from a fetch request. + /// + /// let request = try Player.all() + /// let players = try Player.fetchCursor(db, request) // Cursor of Player + /// while let player = try players.next() { // Player + /// ... + /// } + /// + /// If the database is modified during the cursor iteration, the remaining + /// elements are undefined. + /// + /// The cursor must be iterated in a protected dispath queue. + /// + /// - parameters: + /// - db: A database connection. + /// - sql: a FetchRequest. + /// - returns: A cursor over fetched records. + /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. + public static func fetchCursor(_ db: Database, _ request: QueryInterfaceRequest) throws -> RecordCursor { + precondition(request.prefetchedAssociations.isEmpty, "Not implemented: fetchCursor with prefetched associations") + let (statement, adapter) = try request.prepare(db, forSingleResult: false) + return try fetchCursor(statement, adapter: adapter) + } + + /// Returns an array of records fetched from a query interface request. + /// + /// let request = try Player.all() + /// let players = try Player.fetchAll(db, request) // [Player] + /// + /// - parameters: + /// - db: A database connection. + /// - sql: a FetchRequest. + /// - returns: An array of records. + /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. + public static func fetchAll(_ db: Database, _ request: QueryInterfaceRequest) throws -> [Self] { + let (statement, adapter) = try request.prepare(db, forSingleResult: false) + let associations = request.prefetchedAssociations + if associations.isEmpty { + return try fetchAll(statement, adapter: adapter) + } else { + let rows = try Row.fetchAll(statement, adapter: adapter) + try Row.prefetch(db, associations: associations, in: rows) + return rows.map(Self.init(row:)) + } + } + + /// Returns a single record fetched from a query interface request. + /// + /// let request = try Player.filter(key: 1) + /// let player = try Player.fetchOne(db, request) // Player? + /// + /// - parameters: + /// - db: A database connection. + /// - sql: a FetchRequest. + /// - returns: An optional record. + /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. + public static func fetchOne(_ db: Database, _ request: QueryInterfaceRequest) throws -> Self? { + let (statement, adapter) = try request.prepare(db, forSingleResult: true) + let associations = request.prefetchedAssociations + if associations.isEmpty { + return try fetchOne(statement, adapter: adapter) + } else { + guard let row = try Row.fetchOne(statement, adapter: adapter) else { + return nil + } + try Row.prefetch(db, associations: associations, in: [row]) + return Self.init(row: row) + } + } +} diff --git a/GRDB/QueryInterface/QueryInterfaceRequest+Association.swift b/GRDB/QueryInterface/QueryInterfaceRequest+Association.swift deleted file mode 100644 index d381f4af1..000000000 --- a/GRDB/QueryInterface/QueryInterfaceRequest+Association.swift +++ /dev/null @@ -1,164 +0,0 @@ -extension QueryInterfaceRequest where RowDecoder: TableRecord { - // MARK: - Associations - - /// Creates a request that includes an association. The columns of the - /// associated record are selected. The returned association does not - /// require that the associated database table contains a matching row. - public func including(optional association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == RowDecoder { - return mapQuery { $0.mapRelation { association._impl.joinedRelation($0, joinOperator: .optional) } } - } - - /// Creates a request that includes an association. The columns of the - /// associated record are selected. The returned association requires - /// that the associated database table contains a matching row. - public func including(required association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == RowDecoder { - return mapQuery { $0.mapRelation { association._impl.joinedRelation($0, joinOperator: .required) } } - } - - /// Creates a request that includes an association. The columns of the - /// associated record are not selected. The returned association does not - /// require that the associated database table contains a matching row. - public func joining(optional association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == RowDecoder { - return mapQuery { $0.mapRelation { association.select([])._impl.joinedRelation($0, joinOperator: .optional) } } - } - - /// Creates a request that includes an association. The columns of the - /// associated record are not selected. The returned association requires - /// that the associated database table contains a matching row. - public func joining(required association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == RowDecoder { - return mapQuery { $0.mapRelation { association.select([])._impl.joinedRelation($0, joinOperator: .required) } } - } - - // MARK: - Association Aggregates - - private func annotated(with aggregate: AssociationAggregate) -> QueryInterfaceRequest { - let (request, expression) = aggregate.prepare(self) - if let alias = aggregate.alias { - return request.annotated(with: [expression.aliased(alias)]) - } else { - return request.annotated(with: [expression]) - } - } - - /// Creates a request which appends *aggregates* to the current selection. - /// - /// // SELECT player.*, COUNT(DISTINCT book.rowid) AS bookCount - /// // FROM player LEFT JOIN book ... - /// var request = Player.all() - /// request = request.annotated(with: Player.books.count) - public func annotated(with aggregates: AssociationAggregate...) -> QueryInterfaceRequest { - return annotated(with: aggregates) - } - - /// Creates a request which appends *aggregates* to the current selection. - /// - /// // SELECT player.*, COUNT(DISTINCT book.rowid) AS bookCount - /// // FROM player LEFT JOIN book ... - /// var request = Player.all() - /// request = request.annotated(with: [Player.books.count]) - public func annotated(with aggregates: [AssociationAggregate]) -> QueryInterfaceRequest { - return aggregates.reduce(self) { request, aggregate in - request.annotated(with: aggregate) - } - } - - /// Creates a request which appends the provided aggregate *predicate* to - /// the eventual set of already applied predicates. - /// - /// // SELECT player.* - /// // FROM player LEFT JOIN book ... - /// // HAVING COUNT(DISTINCT book.rowid) = 0 - /// var request = Player.all() - /// request = request.having(Player.books.isEmpty) - public func having(_ predicate: AssociationAggregate) -> QueryInterfaceRequest { - let (request, expression) = predicate.prepare(self) - return request.having(expression) - } -} - -extension MutablePersistableRecord { - /// Creates a request that fetches the associated record(s). - /// - /// For example: - /// - /// struct Team: { - /// static let players = hasMany(Player.self) - /// var players: QueryInterfaceRequest { - /// return request(for: Team.players) - /// } - /// } - /// - /// let team: Team = ... - /// let players = try team.players.fetchAll(db) // [Player] - public func request(for association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == Self { - return association.request(from: self) - } -} - -extension TableRecord { - - // MARK: - Associations - - /// Creates a request that includes an association. The columns of the - /// associated record are selected. The returned association does not - /// require that the associated database table contains a matching row. - public static func including(optional association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == Self { - return all().including(optional: association) - } - - /// Creates a request that includes an association. The columns of the - /// associated record are selected. The returned association requires - /// that the associated database table contains a matching row. - public static func including(required association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == Self { - return all().including(required: association) - } - - /// Creates a request that includes an association. The columns of the - /// associated record are not selected. The returned association does not - /// require that the associated database table contains a matching row. - public static func joining(optional association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == Self { - return all().joining(optional: association) - } - - /// Creates a request that includes an association. The columns of the - /// associated record are not selected. The returned association requires - /// that the associated database table contains a matching row. - public static func joining(required association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == Self { - return all().joining(required: association) - } - - // MARK: - Association Aggregates - - /// Creates a request with *aggregates* appended to the selection. - /// - /// // SELECT player.*, COUNT(DISTINCT book.rowid) AS bookCount - /// // FROM player LEFT JOIN book ... - /// var request = Player.annotated(with: Player.books.count) - public static func annotated(with aggregates: AssociationAggregate...) -> QueryInterfaceRequest { - return all().annotated(with: aggregates) - } - - /// Creates a request with *aggregates* appended to the selection. - /// - /// // SELECT player.*, COUNT(DISTINCT book.rowid) AS bookCount - /// // FROM player LEFT JOIN book ... - /// var request = Player.annotated(with: [Player.books.count]) - public static func annotated(with aggregates: [AssociationAggregate]) -> QueryInterfaceRequest { - return all().annotated(with: aggregates) - } - - /// Creates a request with the provided aggregate *predicate*. - /// - /// // SELECT player.* - /// // FROM player LEFT JOIN book ... - /// // HAVING COUNT(DISTINCT book.rowid) = 0 - /// var request = Player.all() - /// request = request.having(Player.books.isEmpty) - /// - /// The selection defaults to all columns. This default can be changed for - /// all requests by the `TableRecord.databaseSelection` property, or - /// for individual requests with the `TableRecord.select` method. - public static func having(_ predicate: AssociationAggregate) -> QueryInterfaceRequest { - return all().having(predicate) - } -} diff --git a/GRDB/QueryInterface/Request/Association/Association.swift b/GRDB/QueryInterface/Request/Association/Association.swift new file mode 100644 index 000000000..2ff915f14 --- /dev/null +++ b/GRDB/QueryInterface/Request/Association/Association.swift @@ -0,0 +1,514 @@ +import Foundation + +/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) +/// +/// The base protocol for all associations that define a connection between two +/// record types. +public protocol Association: DerivableRequest { + // OriginRowDecoder and RowDecoder provide type safety: + // + // Book.including(required: Book.author) // compiles + // Fruit.including(required: Book.author) // does not compile + + /// The record type at the origin of the association. + /// + /// In the `belongsTo` association below, it is Book: + /// + /// struct Book: TableRecord { + /// // BelongsToAssociation + /// static let author = belongsTo(Author.self) + /// } + associatedtype OriginRowDecoder + + /// The associated record type. + /// + /// In the `belongsTo` association below, it is Author: + /// + /// struct Book: TableRecord { + /// // BelongsToAssociation + /// static let author = belongsTo(Author.self) + /// } + associatedtype RowDecoder + + /// :nodoc: + var sqlAssociation: SQLAssociation { get } + + /// Creates an association with the given key. + /// + /// This new key impacts how rows fetched from the resulting association + /// should be consumed: + /// + /// struct Player: TableRecord { + /// static let team = belongsTo(Team.self) + /// } + /// + /// // Consume rows: + /// let request = Player.including(required: Player.team.forKey("custom")) + /// for row in Row.fetchAll(db, request) { + /// let team: Team = row["custom"] + /// } + func forKey(_ key: String) -> Self + + /// :nodoc: + init(sqlAssociation: SQLAssociation) +} + +extension Association { + private func mapDestinationRelation(_ transform: (SQLRelation) -> SQLRelation) -> Self { + return Self.init(sqlAssociation: sqlAssociation.mapDestinationRelation(transform)) + } +} + +extension Association { + + /// The association key defines how rows fetched from this association + /// should be consumed. + /// + /// For example: + /// + /// struct Player: TableRecord { + /// // The default key of this association is the name of the + /// // database table for teams, let's say "team": + /// static let team = belongsTo(Team.self) + /// } + /// print(Player.team.key) // Prints "team" + /// + /// // Consume rows: + /// let request = Player.including(required: Player.team) + /// for row in Row.fetchAll(db, request) { + /// let team: Team = row["team"] // the association key + /// } + /// + /// The key can be redefined with the `forKey` method: + /// + /// let request = Player.including(required: Player.team.forKey("custom")) + /// for row in Row.fetchAll(db, request) { + /// let team: Team = row["custom"] + /// } + var key: SQLAssociationKey { + return sqlAssociation.destination.key + } + + /// Creates an association which selects *selection*. + /// + /// struct Player: TableRecord { + /// static let team = belongsTo(Team.self) + /// } + /// + /// // SELECT player.*, team.color + /// // FROM player + /// // JOIN team ON team.id = player.teamId + /// let association = Player.team.select([Column("color")]) + /// var request = Player.including(required: association) + /// + /// Any previous selection is replaced: + /// + /// // SELECT player.*, team.color + /// // FROM player + /// // JOIN team ON team.id = player.teamId + /// let association = Player.team + /// .select([Column("id")]) + /// .select([Column("color")]) + /// var request = Player.including(required: association) + public func select(_ selection: [SQLSelectable]) -> Self { + return mapDestinationRelation { $0.select(selection) } + } + + /// Creates an association which appends *selection*. + /// + /// struct Player: TableRecord { + /// static let team = belongsTo(Team.self) + /// } + /// + /// // SELECT player.*, team.color, team.name + /// // FROM player + /// // JOIN team ON team.id = player.teamId + /// let association = Player.team + /// .select([Column("color")]) + /// .annotated(with: [Column("name")]) + /// var request = Player.including(required: association) + public func annotated(with selection: [SQLSelectable]) -> Self { + return mapDestinationRelation { $0.annotated(with: selection) } + } + + /// Creates an association with the provided *predicate promise* added to + /// the eventual set of already applied predicates. + /// + /// struct Player: TableRecord { + /// static let team = belongsTo(Team.self) + /// } + /// + /// // SELECT player.*, team.* + /// // FROM player + /// // JOIN team ON team.id = player.teamId AND 1 + /// let association = Player.team.filter { db in true } + /// var request = Player.including(required: association) + public func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> Self { + return mapDestinationRelation { $0.filter(predicate) } + } + + /// Creates an association with the provided *orderings promise*. + /// + /// struct Player: TableRecord { + /// static let team = belongsTo(Team.self) + /// } + /// + /// // SELECT player.*, team.* + /// // FROM player + /// // JOIN team ON team.id = player.teamId + /// // ORDER BY team.name + /// let association = Player.team.order { _ in [Column("name")] } + /// var request = Player.including(required: association) + /// + /// Any previous ordering is replaced: + /// + /// // SELECT player.*, team.* + /// // FROM player + /// // JOIN team ON team.id = player.teamId + /// // ORDER BY team.name + /// let association = Player.team + /// .order{ _ in [Column("color")] } + /// .reversed() + /// .order{ _ in [Column("name")] } + /// var request = Player.including(required: association) + public func order(_ orderings: @escaping (Database) throws -> [SQLOrderingTerm]) -> Self { + return mapDestinationRelation { $0.order(orderings) } + } + + /// Creates an association that reverses applied orderings. + /// + /// struct Player: TableRecord { + /// static let team = belongsTo(Team.self) + /// } + /// + /// // SELECT player.*, team.* + /// // FROM player + /// // JOIN team ON team.id = player.teamId + /// // ORDER BY team.name DESC + /// let association = Player.team.order(Column("name")).reversed() + /// var request = Player.including(required: association) + /// + /// If no ordering was applied, the returned association is identical. + /// + /// // SELECT player.*, team.* + /// // FROM player + /// // JOIN team ON team.id = player.teamId + /// let association = Player.team.reversed() + /// var request = Player.including(required: association) + public func reversed() -> Self { + return mapDestinationRelation { $0.reversed() } + } + + /// Creates an association without any ordering. + /// + /// struct Player: TableRecord { + /// static let team = belongsTo(Team.self) + /// } + /// + /// // SELECT player.*, team.* + /// // FROM player + /// // JOIN team ON team.id = player.teamId + /// let association = Player.team.order(Column("name")).unordered() + /// var request = Player.including(required: association) + public func unordered() -> Self { + return mapDestinationRelation { $0.unordered() } + } + + /// Creates an association with the given key. + /// + /// This new key helps Decodable records decode rows fetched from the + /// resulting association: + /// + /// struct Player: TableRecord { + /// static let team = belongsTo(Team.self) + /// } + /// + /// struct PlayerInfo: FetchableRecord, Decodable { + /// let player: Player + /// let team: Team + /// + /// static func all() -> QueryInterfaceRequest { + /// return Player + /// .including(required: Player.team.forKey(CodingKeys.team)) + /// .asRequest(of: PlayerInfo.self) + /// } + /// } + /// + /// let playerInfos = PlayerInfo.all().fetchAll(db) + /// print(playerInfos.first?.team) + public func forKey(_ codingKey: CodingKey) -> Self { + return forKey(codingKey.stringValue) + } + + /// Creates an association that allows you to define expressions that target + /// a specific database table. + /// + /// In the example below, the "team.color = 'red'" condition in the where + /// clause could be not achieved without table aliases. + /// + /// struct Player: TableRecord { + /// static let team = belongsTo(Team.self) + /// } + /// + /// // SELECT player.*, team.* + /// // JOIN team ON ... + /// // WHERE team.color = 'red' + /// let teamAlias = TableAlias() + /// let request = Player + /// .including(required: Player.team.aliased(teamAlias)) + /// .filter(teamAlias[Column("color")] == "red") + /// + /// When you give a name to a table alias, you can reliably inject sql + /// snippets in your requests: + /// + /// // SELECT player.*, custom.* + /// // JOIN team custom ON ... + /// // WHERE custom.color = 'red' + /// let teamAlias = TableAlias(name: "custom") + /// let request = Player + /// .including(required: Player.team.aliased(teamAlias)) + /// .filter(sql: "custom.color = ?", arguments: ["red"]) + public func aliased(_ alias: TableAlias) -> Self { + return mapDestinationRelation { $0.qualified(with: alias) } + } +} + +extension Association { + /// Creates an association that prefetches another one. + public func including(all association: A) -> Self where A.OriginRowDecoder == RowDecoder { + return mapDestinationRelation { + $0.including(all: association.sqlAssociation) + } + } + + /// Creates an association that includes another one. The columns of the + /// associated record are selected. The returned association does not + /// require that the associated database table contains a matching row. + public func including(optional association: A) -> Self where A.OriginRowDecoder == RowDecoder { + return mapDestinationRelation { + $0.including(optional: association.sqlAssociation) + } + } + + /// Creates an association that includes another one. The columns of the + /// associated record are selected. The returned association requires + /// that the associated database table contains a matching row. + public func including(required association: A) -> Self where A.OriginRowDecoder == RowDecoder { + return mapDestinationRelation { + $0.including(required: association.sqlAssociation) + } + } + + /// Creates an association that joins another one. The columns of the + /// associated record are not selected. The returned association does not + /// require that the associated database table contains a matching row. + public func joining(optional association: A) -> Self where A.OriginRowDecoder == RowDecoder { + return mapDestinationRelation { + $0.joining(optional: association.sqlAssociation) + } + } + + /// Creates an association that joins another one. The columns of the + /// associated record are not selected. The returned association requires + /// that the associated database table contains a matching row. + public func joining(required association: A) -> Self where A.OriginRowDecoder == RowDecoder { + return mapDestinationRelation { + $0.joining(required: association.sqlAssociation) + } + } +} + +// Allow association.filter(key: ...) +extension Association where Self: TableRequest, RowDecoder: TableRecord { + /// :nodoc: + public var databaseTableName: String { return RowDecoder.databaseTableName } +} + +// MARK: - AssociationToOne + +/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) +/// +/// The base protocol for all associations that define a one-to-one connection. +public protocol AssociationToOne: Association { } + +extension AssociationToOne { + public func forKey(_ key: String) -> Self { + let associationKey = SQLAssociationKey.fixedSingular(key) + return Self.init(sqlAssociation: sqlAssociation.forDestinationKey(associationKey)) + } +} + +// MARK: - AssociationToMany + +/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) +/// +/// The base protocol for all associations that define a one-to-many connection. +public protocol AssociationToMany: Association { } + +extension AssociationToMany { + public func forKey(_ key: String) -> Self { + let associationKey = SQLAssociationKey.fixedPlural(key) + return Self.init(sqlAssociation: sqlAssociation.forDestinationKey(associationKey)) + } +} + +extension AssociationToMany where OriginRowDecoder: TableRecord { + private func makeAggregate(_ expression: SQLExpression) -> AssociationAggregate { + return AssociationAggregate { request in + let tableAlias = TableAlias() + let request = request + .joining(optional: self.aliased(tableAlias)) + .groupByPrimaryKey() + let expression = tableAlias[expression] + return (request: request, expression: expression) + } + } + + /// The number of associated records. + /// + /// It has a default name, which is "[key]Count", where key is the key of + /// the association. For example: + /// + /// For example: + /// + /// struct TeamInfo: FetchableRecord, Decodable { + /// var team: Team + /// var playerCount: Int + /// } + /// let request = Team.annotated(with: Team.players.count()) + /// let infos: [TeamInfo] = try TeamInfo.fetchAll(db, request) + /// + /// let teams: [Team] = try Team.having(Team.players.count() > 10).fetchAll(db) + public var count: AssociationAggregate { + return makeAggregate(SQLExpressionCountDistinct(Column.rowID)) + .aliased("\(key.singularizedName)Count") + } + + /// Creates an aggregate that is true if there exists no associated records. + /// + /// It has a default name, which is "hasNo[Key]", where key is the key of + /// the association. For example: + /// + /// struct TeamInfo: FetchableRecord, Decodable { + /// var team: Team + /// var hasNoPlayer: Bool + /// } + /// let request = Team.annotated(with: Team.players.isEmpty()) + /// let infos: [TeamInfo] = try TeamInfo.fetchAll(db, request) + /// + /// let teams: [Team] = try Team.having(Team.players.isEmpty()).fetchAll(db) + /// let teams: [Team] = try Team.having(!Team.players.isEmpty()) + /// let teams: [Team] = try Team.having(Team.players.isEmpty() == false) + public var isEmpty: AssociationAggregate { + return makeAggregate(SQLExpressionIsEmpty(SQLExpressionCountDistinct(Column.rowID))) + .aliased("hasNo\(key.singularizedName.uppercasingFirstCharacter)") + } + + /// Creates an aggregate which evaluate to the average value of the given + /// expression in associated records. + /// + /// When the averaged expression is a column, the aggregate has a default + /// name which is "average[Key][Column]", where key is the key of the + /// association. For example: + /// + /// For example: + /// + /// struct TeamInfo: FetchableRecord, Decodable { + /// var team: Team + /// var averagePlayerScore: Double + /// } + /// let request = Team.annotated(with: Team.players.average(Column("score"))) + /// let infos: [TeamInfo] = try TeamInfo.fetchAll(db, request) + /// + /// let teams: [Team] = try Team.having(Team.players.average(Column("score")) > 100).fetchAll(db) + public func average(_ expression: SQLExpressible) -> AssociationAggregate { + let aggregate = makeAggregate(SQLExpressionFunction(.avg, arguments: expression)) + if let column = expression as? ColumnExpression { + let name = key.singularizedName + return aggregate.aliased("average\(name.uppercasingFirstCharacter)\(column.name.uppercasingFirstCharacter)") + } else { + return aggregate + } + } + + /// Creates an aggregate which evaluate to the maximum value of the given + /// expression in associated records. + /// + /// When the maximized expression is a column, the aggregate has a default + /// name which is "maximum[Key][Column]", where key is the key of the + /// association. For example: + /// + /// For example: + /// + /// struct TeamInfo: FetchableRecord, Decodable { + /// var team: Team + /// var maxPlayerScore: Double + /// } + /// let request = Team.annotated(with: Team.players.max(Column("score"))) + /// let infos: [TeamInfo] = try TeamInfo.fetchAll(db, request) + /// + /// let teams: [Team] = try Team.having(Team.players.max(Column("score")) < 100).fetchAll(db) + public func max(_ expression: SQLExpressible) -> AssociationAggregate { + let aggregate = makeAggregate(SQLExpressionFunction(.max, arguments: expression)) + if let column = expression as? ColumnExpression { + let name = key.singularizedName + return aggregate.aliased("max\(name.uppercasingFirstCharacter)\(column.name.uppercasingFirstCharacter)") + } else { + return aggregate + } + } + + /// Creates an aggregate which evaluate to the minimum value of the given + /// expression in associated records. + /// + /// When the minimized expression is a column, the aggregate has a default + /// name which is "minimum[Key][Column]", where key is the key of the + /// association. For example: + /// + /// For example: + /// + /// struct TeamInfo: FetchableRecord, Decodable { + /// var team: Team + /// var minPlayerScore: Double + /// } + /// let request = Team.annotated(with: Team.players.min(Column("score"))) + /// let infos: [TeamInfo] = try TeamInfo.fetchAll(db, request) + /// + /// let teams: [Team] = try Team.having(Team.players.min(Column("score")) > 100).fetchAll(db) + public func min(_ expression: SQLExpressible) -> AssociationAggregate { + let aggregate = makeAggregate(SQLExpressionFunction(.min, arguments: expression)) + if let column = expression as? ColumnExpression { + let name = key.singularizedName + return aggregate.aliased("min\(name.uppercasingFirstCharacter)\(column.name.uppercasingFirstCharacter)") + } else { + return aggregate + } + } + + /// Creates an aggregate which evaluate to the sum of the given expression + /// in associated records. + /// + /// When the summed expression is a column, the aggregate has a default + /// name which is "[key][Column]Sum", where key is the key of the + /// association. For example: + /// + /// For example: + /// + /// struct TeamInfo: FetchableRecord, Decodable { + /// var team: Team + /// var playerScoreSum: Double + /// } + /// let request = Team.annotated(with: Team.players.sum(Column("score"))) + /// let infos: [TeamInfo] = try TeamInfo.fetchAll(db, request) + /// + /// let teams: [Team] = try Team.having(Team.players.sum(Column("score")) > 100).fetchAll(db) + public func sum(_ expression: SQLExpressible) -> AssociationAggregate { + let aggregate = makeAggregate(SQLExpressionFunction(.sum, arguments: expression)) + if let column = expression as? ColumnExpression { + let name = key.singularizedName + return aggregate.aliased("\(name)\(column.name.uppercasingFirstCharacter)Sum") + } else { + return aggregate + } + } +} diff --git a/GRDB/QueryInterface/Association/AssociationAggregate.swift b/GRDB/QueryInterface/Request/Association/AssociationAggregate.swift similarity index 88% rename from GRDB/QueryInterface/Association/AssociationAggregate.swift rename to GRDB/QueryInterface/Request/Association/AssociationAggregate.swift index 7206b0ce2..cf67dd5bb 100644 --- a/GRDB/QueryInterface/Association/AssociationAggregate.swift +++ b/GRDB/QueryInterface/Request/Association/AssociationAggregate.swift @@ -108,7 +108,7 @@ extension AssociationAggregate { /// /// For example: /// -/// let request = Author.having(!Author.books.isEmpty) +/// Author.having(!Author.books.isEmpty) public prefix func ! (aggregate: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = aggregate.prepare(request) @@ -120,7 +120,7 @@ public prefix func ! (aggregate: AssociationAggregate) - /// /// For example: /// -/// let request = Author.having(Author.books.isEmpty && Author.paintings.isEmpty) +/// Author.having(Author.books.isEmpty && Author.paintings.isEmpty) public func && (lhs: AssociationAggregate, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (lRequest, lExpression) = lhs.prepare(request) @@ -129,7 +129,7 @@ public func && (lhs: AssociationAggregate, rhs: Associat } } -// TODO: test & document +// TODO: test /// :nodoc: public func && (lhs: AssociationAggregate, rhs: SQLExpressible) -> AssociationAggregate { return AssociationAggregate { request in @@ -138,7 +138,7 @@ public func && (lhs: AssociationAggregate, rhs: SQLExpre } } -// TODO: test & document +// TODO: test /// :nodoc: public func && (lhs: SQLExpressible, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in @@ -152,7 +152,7 @@ public func && (lhs: SQLExpressible, rhs: AssociationAggregate(lhs: AssociationAggregate, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (lRequest, lExpression) = lhs.prepare(request) @@ -161,7 +161,7 @@ public func || (lhs: AssociationAggregate, rhs: Associat } } -// TODO: test & document +// TODO: test /// :nodoc: public func || (lhs: AssociationAggregate, rhs: SQLExpressible) -> AssociationAggregate { return AssociationAggregate { request in @@ -170,7 +170,7 @@ public func || (lhs: AssociationAggregate, rhs: SQLExpre } } -// TODO: test & document +// TODO: test /// :nodoc: public func || (lhs: SQLExpressible, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in @@ -185,7 +185,7 @@ public func || (lhs: SQLExpressible, rhs: AssociationAggregate(lhs: AssociationAggregate, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (lRequest, lExpression) = lhs.prepare(request) @@ -198,7 +198,7 @@ public func == (lhs: AssociationAggregate, rhs: Associat /// /// For example: /// -/// let request = Author.having(Author.books.count == 3) +/// Author.having(Author.books.count == 3) public func == (lhs: AssociationAggregate, rhs: SQLExpressible) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = lhs.prepare(request) @@ -210,7 +210,7 @@ public func == (lhs: AssociationAggregate, rhs: SQLExpre /// /// For example: /// -/// let request = Author.having(3 == Author.books.count) +/// Author.having(3 == Author.books.count) public func == (lhs: SQLExpressible, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = rhs.prepare(request) @@ -222,7 +222,7 @@ public func == (lhs: SQLExpressible, rhs: AssociationAggregate(lhs: AssociationAggregate, rhs: Bool) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = lhs.prepare(request) @@ -234,7 +234,7 @@ public func == (lhs: AssociationAggregate, rhs: Bool) -> /// /// For example: /// -/// let request = Author.having(false == Author.books.isEmpty) +/// Author.having(false == Author.books.isEmpty) public func == (lhs: Bool, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = rhs.prepare(request) @@ -246,7 +246,7 @@ public func == (lhs: Bool, rhs: AssociationAggregate) -> /// /// For example: /// -/// let request = Author.having(Author.books.count != Author.paintings.count) +/// Author.having(Author.books.count != Author.paintings.count) public func != (lhs: AssociationAggregate, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (lRequest, lExpression) = lhs.prepare(request) @@ -259,7 +259,7 @@ public func != (lhs: AssociationAggregate, rhs: Associat /// /// For example: /// -/// let request = Author.having(Author.books.count != 3) +/// Author.having(Author.books.count != 3) public func != (lhs: AssociationAggregate, rhs: SQLExpressible) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = lhs.prepare(request) @@ -271,7 +271,7 @@ public func != (lhs: AssociationAggregate, rhs: SQLExpre /// /// For example: /// -/// let request = Author.having(3 != Author.books.count) +/// Author.having(3 != Author.books.count) public func != (lhs: SQLExpressible, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = rhs.prepare(request) @@ -283,7 +283,7 @@ public func != (lhs: SQLExpressible, rhs: AssociationAggregate(lhs: AssociationAggregate, rhs: Bool) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = lhs.prepare(request) @@ -295,7 +295,7 @@ public func != (lhs: AssociationAggregate, rhs: Bool) -> /// /// For example: /// -/// let request = Author.having(true != Author.books.isEmpty) +/// Author.having(true != Author.books.isEmpty) public func != (lhs: Bool, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = rhs.prepare(request) @@ -307,7 +307,7 @@ public func != (lhs: Bool, rhs: AssociationAggregate) -> /// /// For example: /// -/// let request = Author.having(Author.books.count === Author.paintings.count) +/// Author.having(Author.books.count === Author.paintings.count) public func === (lhs: AssociationAggregate, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (lRequest, lExpression) = lhs.prepare(request) @@ -320,7 +320,7 @@ public func === (lhs: AssociationAggregate, rhs: Associa /// /// For example: /// -/// let request = Author.having(Author.books.count === 3) +/// Author.having(Author.books.count === 3) public func === (lhs: AssociationAggregate, rhs: SQLExpressible) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = lhs.prepare(request) @@ -332,7 +332,7 @@ public func === (lhs: AssociationAggregate, rhs: SQLExpr /// /// For example: /// -/// let request = Author.having(3 === Author.books.count) +/// Author.having(3 === Author.books.count) public func === (lhs: SQLExpressible, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = rhs.prepare(request) @@ -344,7 +344,7 @@ public func === (lhs: SQLExpressible, rhs: AssociationAggregate(lhs: AssociationAggregate, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (lRequest, lExpression) = lhs.prepare(request) @@ -357,7 +357,7 @@ public func !== (lhs: AssociationAggregate, rhs: Associa /// /// For example: /// -/// let request = Author.having(Author.books.count !== 3) +/// Author.having(Author.books.count !== 3) public func !== (lhs: AssociationAggregate, rhs: SQLExpressible) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = lhs.prepare(request) @@ -369,7 +369,7 @@ public func !== (lhs: AssociationAggregate, rhs: SQLExpr /// /// For example: /// -/// let request = Author.having(3 !== Author.books.count) +/// Author.having(3 !== Author.books.count) public func !== (lhs: SQLExpressible, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = rhs.prepare(request) @@ -383,7 +383,7 @@ public func !== (lhs: SQLExpressible, rhs: AssociationAggregate(lhs: AssociationAggregate, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (lRequest, lExpression) = lhs.prepare(request) @@ -396,7 +396,7 @@ public func <= (lhs: AssociationAggregate, rhs: Associat /// /// For example: /// -/// let request = Author.having(Author.books.count <= 3) +/// Author.having(Author.books.count <= 3) public func <= (lhs: AssociationAggregate, rhs: SQLExpressible) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = lhs.prepare(request) @@ -408,7 +408,7 @@ public func <= (lhs: AssociationAggregate, rhs: SQLExpre /// /// For example: /// -/// let request = Author.having(3 <= Author.books.count) +/// Author.having(3 <= Author.books.count) public func <= (lhs: SQLExpressible, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = rhs.prepare(request) @@ -420,7 +420,7 @@ public func <= (lhs: SQLExpressible, rhs: AssociationAggregate(lhs: AssociationAggregate, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (lRequest, lExpression) = lhs.prepare(request) @@ -433,7 +433,7 @@ public func < (lhs: AssociationAggregate, rhs: Associati /// /// For example: /// -/// let request = Author.having(Author.books.count < 3) +/// Author.having(Author.books.count < 3) public func < (lhs: AssociationAggregate, rhs: SQLExpressible) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = lhs.prepare(request) @@ -445,7 +445,7 @@ public func < (lhs: AssociationAggregate, rhs: SQLExpres /// /// For example: /// -/// let request = Author.having(3 < Author.books.count) +/// Author.having(3 < Author.books.count) public func < (lhs: SQLExpressible, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = rhs.prepare(request) @@ -457,7 +457,7 @@ public func < (lhs: SQLExpressible, rhs: AssociationAggregate Author.paintings.count) +/// Author.having(Author.books.count > Author.paintings.count) public func > (lhs: AssociationAggregate, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (lRequest, lExpression) = lhs.prepare(request) @@ -470,7 +470,7 @@ public func > (lhs: AssociationAggregate, rhs: Associati /// /// For example: /// -/// let request = Author.having(Author.books.count > 3) +/// Author.having(Author.books.count > 3) public func > (lhs: AssociationAggregate, rhs: SQLExpressible) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = lhs.prepare(request) @@ -482,7 +482,7 @@ public func > (lhs: AssociationAggregate, rhs: SQLExpres /// /// For example: /// -/// let request = Author.having(3 > Author.books.count) +/// Author.having(3 > Author.books.count) public func > (lhs: SQLExpressible, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = rhs.prepare(request) @@ -494,7 +494,7 @@ public func > (lhs: SQLExpressible, rhs: AssociationAggregate= Author.paintings.count) +/// Author.having(Author.books.count >= Author.paintings.count) public func >= (lhs: AssociationAggregate, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (lRequest, lExpression) = lhs.prepare(request) @@ -507,7 +507,7 @@ public func >= (lhs: AssociationAggregate, rhs: Associat /// /// For example: /// -/// let request = Author.having(Author.books.count >= 3) +/// Author.having(Author.books.count >= 3) public func >= (lhs: AssociationAggregate, rhs: SQLExpressible) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = lhs.prepare(request) @@ -519,7 +519,7 @@ public func >= (lhs: AssociationAggregate, rhs: SQLExpre /// /// For example: /// -/// let request = Author.having(3 >= Author.books.count) +/// Author.having(3 >= Author.books.count) public func >= (lhs: SQLExpressible, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = rhs.prepare(request) @@ -533,7 +533,7 @@ public func >= (lhs: SQLExpressible, rhs: AssociationAggregate(aggregate: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = aggregate.prepare(request) @@ -545,7 +545,7 @@ public prefix func - (aggregate: AssociationAggregate) - /// /// For example: /// -/// let request = Author.annotated(with: Author.books.count + Author.paintings.count) +/// Author.annotated(with: Author.books.count + Author.paintings.count) public func + (lhs: AssociationAggregate, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (lRequest, lExpression) = lhs.prepare(request) @@ -558,7 +558,7 @@ public func + (lhs: AssociationAggregate, rhs: Associati /// /// For example: /// -/// let request = Author.annotated(with: Author.books.count + 1) +/// Author.annotated(with: Author.books.count + 1) public func + (lhs: AssociationAggregate, rhs: SQLExpressible) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = lhs.prepare(request) @@ -570,7 +570,7 @@ public func + (lhs: AssociationAggregate, rhs: SQLExpres /// /// For example: /// -/// let request = Author.annotated(with: 1 + Author.books.count) +/// Author.annotated(with: 1 + Author.books.count) public func + (lhs: SQLExpressible, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = rhs.prepare(request) @@ -582,7 +582,7 @@ public func + (lhs: SQLExpressible, rhs: AssociationAggregate(lhs: AssociationAggregate, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (lRequest, lExpression) = lhs.prepare(request) @@ -595,7 +595,7 @@ public func - (lhs: AssociationAggregate, rhs: Associati /// /// For example: /// -/// let request = Author.annotated(with: Author.books.count - 1) +/// Author.annotated(with: Author.books.count - 1) public func - (lhs: AssociationAggregate, rhs: SQLExpressible) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = lhs.prepare(request) @@ -607,7 +607,7 @@ public func - (lhs: AssociationAggregate, rhs: SQLExpres /// /// For example: /// -/// let request = Author.annotated(with: 1 - Author.books.count) +/// Author.annotated(with: 1 - Author.books.count) public func - (lhs: SQLExpressible, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = rhs.prepare(request) @@ -619,7 +619,7 @@ public func - (lhs: SQLExpressible, rhs: AssociationAggregate(lhs: AssociationAggregate, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (lRequest, lExpression) = lhs.prepare(request) @@ -632,7 +632,7 @@ public func * (lhs: AssociationAggregate, rhs: Associati /// /// For example: /// -/// let request = Author.annotated(with: Author.books.count * 2) +/// Author.annotated(with: Author.books.count * 2) public func * (lhs: AssociationAggregate, rhs: SQLExpressible) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = lhs.prepare(request) @@ -644,7 +644,7 @@ public func * (lhs: AssociationAggregate, rhs: SQLExpres /// /// For example: /// -/// let request = Author.annotated(with: 2 * Author.books.count) +/// Author.annotated(with: 2 * Author.books.count) public func * (lhs: SQLExpressible, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = rhs.prepare(request) @@ -656,7 +656,7 @@ public func * (lhs: SQLExpressible, rhs: AssociationAggregate(lhs: AssociationAggregate, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (lRequest, lExpression) = lhs.prepare(request) @@ -669,7 +669,7 @@ public func / (lhs: AssociationAggregate, rhs: Associati /// /// For example: /// -/// let request = Author.annotated(with: Author.books.count / 2) +/// Author.annotated(with: Author.books.count / 2) public func / (lhs: AssociationAggregate, rhs: SQLExpressible) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = lhs.prepare(request) @@ -681,7 +681,7 @@ public func / (lhs: AssociationAggregate, rhs: SQLExpres /// /// For example: /// -/// let request = Author.annotated(with: 2 / Author.books.count) +/// Author.annotated(with: 2 / Author.books.count) public func / (lhs: SQLExpressible, rhs: AssociationAggregate) -> AssociationAggregate { return AssociationAggregate { request in let (request, expression) = rhs.prepare(request) @@ -689,7 +689,21 @@ public func / (lhs: SQLExpressible, rhs: AssociationAggregate(lhs: AssociationAggregate, rhs: SQLExpressible) -> AssociationAggregate { + var aggregate = AssociationAggregate { request in + let (request, expression) = lhs.prepare(request) + return (request: request, expression: expression ?? rhs) + } + + // Preserve alias + aggregate.alias = lhs.alias + return aggregate +} + // TODO: add support for ABS(aggregate) // TODO: add support for LENGTH(aggregate) -// TODO: add support for IFNULL(aggregate, ...) -// TODO: add support for IFNULL(..., aggregate) diff --git a/GRDB/QueryInterface/Request/Association/BelongsToAssociation.swift b/GRDB/QueryInterface/Request/Association/BelongsToAssociation.swift new file mode 100644 index 000000000..1f459622f --- /dev/null +++ b/GRDB/QueryInterface/Request/Association/BelongsToAssociation.swift @@ -0,0 +1,78 @@ +/// The BelongsTo association sets up a one-to-one connection from a record +/// type to another record type, such as each instance of the declaring record +/// "belongs to" an instance of the other record. +/// +/// For example, if your application includes authors and books, and each book +/// is assigned its author, you'd declare the association this way: +/// +/// struct Author: TableRecord { ... } +/// struct Book: TableRecord { +/// static let author = belongsTo(Author.self) +/// ... +/// } +/// +/// A BelongsTo associations should be supported by an SQLite foreign key. +/// +/// Foreign keys are the recommended way to declare relationships between +/// database tables because not only will SQLite guarantee the integrity of your +/// data, but GRDB will be able to use those foreign keys to automatically +/// configure your association. +/// +/// You define the foreign key when you create database tables. For example: +/// +/// try db.create(table: "author") { t in +/// t.autoIncrementedPrimaryKey("id") // (1) +/// t.column("name", .text) +/// } +/// try db.create(table: "book") { t in +/// t.autoIncrementedPrimaryKey("id") +/// t.column("authorId", .integer) // (2) +/// .notNull() // (3) +/// .indexed() // (4) +/// .references("author", onDelete: .cascade) // (5) +/// t.column("title", .text) +/// } +/// +/// 1. The author table has a primary key. +/// 2. The book.authorId column is used to link a book to the author it +/// belongs to. +/// 3. Make the book.authorId column not null if you want SQLite to guarantee +/// that all books have an author. +/// 4. Create an index on the book.authorId column in order to ease the +/// selection of an author's books. +/// 5. Create a foreign key from book.authorId column to authors.id, so that +/// SQLite guarantees that no book refers to a missing author. The +/// `onDelete: .cascade` option has SQLite automatically delete all of an +/// author's books when that author is deleted. +/// See https://sqlite.org/foreignkeys.html#fk_actions for more information. +/// +/// The example above uses auto-incremented primary keys. But generally +/// speaking, all primary keys are supported. +/// +/// If the database schema does not define foreign keys between tables, you can +/// still use BelongsTo associations. But your help is needed to define the +/// missing foreign key: +/// +/// struct Book: FetchableRecord, TableRecord { +/// static let author = belongsTo(Author.self, using: ForeignKey(...)) +/// } +/// +/// See ForeignKey for more information. +public struct BelongsToAssociation: AssociationToOne { + /// :nodoc: + public typealias OriginRowDecoder = Origin + + /// :nodoc: + public typealias RowDecoder = Destination + + /// :nodoc: + public var sqlAssociation: SQLAssociation + + /// :nodoc: + public init(sqlAssociation: SQLAssociation) { + self.sqlAssociation = sqlAssociation + } +} + +// Allow BelongsToAssociation(...).filter(key: ...) +extension BelongsToAssociation: TableRequest where Destination: TableRecord { } diff --git a/GRDB/QueryInterface/Request/Association/HasManyAssociation.swift b/GRDB/QueryInterface/Request/Association/HasManyAssociation.swift new file mode 100644 index 000000000..d02586fde --- /dev/null +++ b/GRDB/QueryInterface/Request/Association/HasManyAssociation.swift @@ -0,0 +1,78 @@ +/// The HasMany association indicates a one-to-many connection between two +/// record types, such as each instance of the declaring record "has many" +/// instances of the other record. +/// +/// For example, if your application includes authors and books, and each author +/// is assigned zero or more books, you'd declare the association this way: +/// +/// struct Book: TableRecord { ... } +/// struct Author: TableRecord { +/// static let books = hasMany(Book.self) +/// ... +/// } +/// +/// HasMany associations should be supported by an SQLite foreign key. +/// +/// Foreign keys are the recommended way to declare relationships between +/// database tables because not only will SQLite guarantee the integrity of your +/// data, but GRDB will be able to use those foreign keys to automatically +/// configure your association. +/// +/// You define the foreign key when you create database tables. For example: +/// +/// try db.create(table: "author") { t in +/// t.autoIncrementedPrimaryKey("id") // (1) +/// t.column("name", .text) +/// } +/// try db.create(table: "book") { t in +/// t.autoIncrementedPrimaryKey("id") +/// t.column("authorId", .integer) // (2) +/// .notNull() // (3) +/// .indexed() // (4) +/// .references("author", onDelete: .cascade) // (5) +/// t.column("title", .text) +/// } +/// +/// 1. The author table has a primary key. +/// 2. The book.authorId column is used to link a book to the author it +/// belongs to. +/// 3. Make the book.authorId column not null if you want SQLite to guarantee +/// that all books have an author. +/// 4. Create an index on the book.authorId column in order to ease the +/// selection of an author's books. +/// 5. Create a foreign key from book.authorId column to authors.id, so that +/// SQLite guarantees that no book refers to a missing author. The +/// `onDelete: .cascade` option has SQLite automatically delete all of an +/// author's books when that author is deleted. +/// See https://sqlite.org/foreignkeys.html#fk_actions for more information. +/// +/// The example above uses auto-incremented primary keys. But generally +/// speaking, all primary keys are supported. +/// +/// If the database schema does not define foreign keys between tables, you can +/// still use HasMany associations. But your help is needed to define the +/// missing foreign key: +/// +/// struct Author: TableRecord { +/// static let books = hasMany(Book.self, using: ForeignKey(...)) +/// } +/// +/// See ForeignKey for more information. +public struct HasManyAssociation: AssociationToMany { + /// :nodoc: + public typealias OriginRowDecoder = Origin + + /// :nodoc: + public typealias RowDecoder = Destination + + /// :nodoc: + public var sqlAssociation: SQLAssociation + + /// :nodoc: + public init(sqlAssociation: SQLAssociation) { + self.sqlAssociation = sqlAssociation + } +} + +// Allow HasManyAssociation(...).filter(key: ...) +extension HasManyAssociation: TableRequest where Destination: TableRecord { } diff --git a/GRDB/QueryInterface/Request/Association/HasManyThroughAssociation.swift b/GRDB/QueryInterface/Request/Association/HasManyThroughAssociation.swift new file mode 100644 index 000000000..e4e5cb3cc --- /dev/null +++ b/GRDB/QueryInterface/Request/Association/HasManyThroughAssociation.swift @@ -0,0 +1,61 @@ +/// The **HasManyThrough** association is often used to set up a many-to-many +/// connection with another record. This association indicates that the +/// declaring record can be matched with zero or more instances of another +/// record by proceeding through a third record. +/// +/// For example, consider the practice of passport delivery. One coutry +/// "has many" citizens "through" its passports: +/// +/// struct Country: TableRecord { +/// static let passports = hasMany(Passport.self) +/// static let citizens = hasMany(Citizen.self, through: passports, using: Passport.citizen) +/// ... +/// } +/// +/// struct Passport: TableRecord { +/// static let citizen = belongsTo(Citizen.self) +/// ... +/// } +/// +/// struct Citizen: TableRecord { ... } +/// +/// The **HasManyThrough** association is also useful for setting up +/// "shortcuts" through nested HasMany associations. For example, if a document +/// has many sections, and a section has many paragraphs, you may sometimes want +/// to get a simple collection of all paragraphs in the document. You could set +/// that up this way: +/// +/// struct Document: TableRecord { +/// static let sections = hasMany(Section.self) +/// static let paragraphs = hasMany(Paragraph.self, through: sections, using: Section.paragraphs) +/// } +/// +/// struct Section: TableRecord { +/// static let paragraphs = hasMany(Paragraph.self) +/// } +/// +/// struct Paragraph: TableRecord { +/// } +/// +/// As in the examples above, **HasManyThrough** association is always built from +/// two other associations: the `through:` and `using:` arguments. Those +/// associations can be any other association (BelongsTo, HasMany, +/// HasManyThrough, etc). +public struct HasManyThroughAssociation: AssociationToMany { + /// :nodoc: + public typealias OriginRowDecoder = Origin + + /// :nodoc: + public typealias RowDecoder = Destination + + /// :nodoc: + public var sqlAssociation: SQLAssociation + + /// :nodoc: + public init(sqlAssociation: SQLAssociation) { + self.sqlAssociation = sqlAssociation + } +} + +// Allow HasManyThroughAssociation(...).filter(key: ...) +extension HasManyThroughAssociation: TableRequest where Destination: TableRecord { } diff --git a/GRDB/QueryInterface/Request/Association/HasOneAssociation.swift b/GRDB/QueryInterface/Request/Association/HasOneAssociation.swift new file mode 100644 index 000000000..6b1f49f7c --- /dev/null +++ b/GRDB/QueryInterface/Request/Association/HasOneAssociation.swift @@ -0,0 +1,80 @@ +/// The HasOne association indicates a one-to-one connection between two +/// record types, such as each instance of the declaring record "has one" +/// instances of the other record. +/// +/// For example, if your application has one database table for countries, and +/// another for their demographic profiles, you'd declare the association +/// this way: +/// +/// struct Demographics: TableRecord { ... } +/// struct Country: TableRecord { +/// static let demographics = hasOne(Demographics.self) +/// ... +/// } +/// +/// HasOne associations should be supported by an SQLite foreign key. +/// +/// Foreign keys are the recommended way to declare relationships between +/// database tables because not only will SQLite guarantee the integrity of your +/// data, but GRDB will be able to use those foreign keys to automatically +/// configure your association. +/// +/// You define the foreign key when you create database tables. For example: +/// +/// try db.create(table: "country") { t in +/// t.column("code", .text).primaryKey() // (1) +/// t.column("name", .text) +/// } +/// try db.create(table: "demographics") { t in +/// t.autoIncrementedPrimaryKey("id") +/// t.column("countryCode", .text) // (2) +/// .notNull() // (3) +/// .unique() // (4) +/// .references("country", onDelete: .cascade) // (5) +/// t.column("population", .integer) +/// t.column("density", .double) +/// } +/// +/// 1. The country table has a primary key. +/// 2. The demographics.countryCode column is used to link a demographic +/// profile to the country it belongs to. +/// 3. Make the demographics.countryCode column not null if you want SQLite to +/// guarantee that all profiles are linked to a country. +/// 4. Create a unique index on the demographics.countryCode column in order to +/// guarantee the unicity of any country's profile. +/// 5. Create a foreign key from demographics.countryCode column to +/// country.code, so that SQLite guarantees that no profile refers to a +/// missing country. The `onDelete: .cascade` option has SQLite automatically +/// delete a profile when its country is deleted. +/// See https://sqlite.org/foreignkeys.html#fk_actions for more information. +/// +/// The example above uses a string primary for the country table. But generally +/// speaking, all primary keys are supported. +/// +/// If the database schema does not follow this convention, and does not define +/// foreign keys between tables, you can still use HasOne associations. But +/// your help is needed to define the missing foreign key: +/// +/// struct Country: FetchableRecord, TableRecord { +/// static let demographics = hasOne(Demographics.self, using: ForeignKey(...)) +/// } +/// +/// See ForeignKey for more information. +public struct HasOneAssociation: AssociationToOne { + /// :nodoc: + public typealias OriginRowDecoder = Origin + + /// :nodoc: + public typealias RowDecoder = Destination + + /// :nodoc: + public var sqlAssociation: SQLAssociation + + /// :nodoc: + public init(sqlAssociation: SQLAssociation) { + self.sqlAssociation = sqlAssociation + } +} + +// Allow HasOneAssociation(...).filter(key: ...) +extension HasOneAssociation: TableRequest where Destination: TableRecord { } diff --git a/GRDB/QueryInterface/Request/Association/HasOneThroughAssociation.swift b/GRDB/QueryInterface/Request/Association/HasOneThroughAssociation.swift new file mode 100644 index 000000000..be25e3173 --- /dev/null +++ b/GRDB/QueryInterface/Request/Association/HasOneThroughAssociation.swift @@ -0,0 +1,41 @@ +/// A **HasOneThrough** association sets up a one-to-one connection with +/// another record. This association indicates that the declaring record can be +/// matched with one instance of another record by proceeding through a third +/// record. For example, if each book belongs to a library, and each library has +/// one address, then one knows where the book should be returned to: +/// +/// struct Book: TableRecord { +/// static let library = belongsTo(Library.self) +/// static let returnAddress = hasOne(Address.self, through: library, using: library.address) +/// ... +/// } +/// +/// struct Library: TableRecord { +/// static let address = hasOne(Address.self) +/// ... +/// } +/// +/// struct Address: TableRecord { ... } +/// +/// As in the example above, **HasOneThrough** association is always built from +/// two other associations: the `through:` and `using:` arguments. Those +/// associations can be any other association to one (BelongsTo, HasOne, +/// HasOneThrough). +public struct HasOneThroughAssociation: AssociationToOne { + /// :nodoc: + public typealias OriginRowDecoder = Origin + + /// :nodoc: + public typealias RowDecoder = Destination + + /// :nodoc: + public var sqlAssociation: SQLAssociation + + /// :nodoc: + public init(sqlAssociation: SQLAssociation) { + self.sqlAssociation = sqlAssociation + } +} + +// Allow HasOneThroughAssociation(...).filter(key: ...) +extension HasOneThroughAssociation: TableRequest where Destination: TableRecord { } diff --git a/GRDB/QueryInterface/Request/QueryInterfaceRequest+Association.swift b/GRDB/QueryInterface/Request/QueryInterfaceRequest+Association.swift new file mode 100644 index 000000000..8ef57e1d9 --- /dev/null +++ b/GRDB/QueryInterface/Request/QueryInterfaceRequest+Association.swift @@ -0,0 +1,102 @@ +extension QueryInterfaceRequest where RowDecoder: TableRecord { + // MARK: - Associations + + /// Creates a request that prefetches an association. + public func including(all association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == RowDecoder { + return mapQuery { + $0.mapRelation { + $0.including(all: association.sqlAssociation) + } + } + } + + /// Creates a request that includes an association. The columns of the + /// associated record are selected. The returned request does not + /// require that the associated database table contains a matching row. + public func including(optional association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == RowDecoder { + return mapQuery { + $0.mapRelation { + $0.including(optional: association.sqlAssociation) + } + } + } + + /// Creates a request that includes an association. The columns of the + /// associated record are selected. The returned request requires + /// that the associated database table contains a matching row. + public func including(required association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == RowDecoder { + return mapQuery { + $0.mapRelation { + $0.including(required: association.sqlAssociation) + } + } + } + + /// Creates a request that joins an association. The columns of the + /// associated record are not selected. The returned request does not + /// require that the associated database table contains a matching row. + public func joining(optional association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == RowDecoder { + return mapQuery { + $0.mapRelation { + $0.joining(optional: association.sqlAssociation) + } + } + } + + /// Creates a request that joins an association. The columns of the + /// associated record are not selected. The returned request requires + /// that the associated database table contains a matching row. + public func joining(required association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == RowDecoder { + return mapQuery { + $0.mapRelation { + $0.joining(required: association.sqlAssociation) + } + } + } + + // MARK: - Association Aggregates + + private func annotated(with aggregate: AssociationAggregate) -> QueryInterfaceRequest { + let (request, expression) = aggregate.prepare(self) + if let alias = aggregate.alias { + return request.annotated(with: [expression.aliased(alias)]) + } else { + return request.annotated(with: [expression]) + } + } + + /// Creates a request which appends *aggregates* to the current selection. + /// + /// // SELECT player.*, COUNT(DISTINCT book.rowid) AS bookCount + /// // FROM player LEFT JOIN book ... + /// var request = Player.all() + /// request = request.annotated(with: Player.books.count) + public func annotated(with aggregates: AssociationAggregate...) -> QueryInterfaceRequest { + return annotated(with: aggregates) + } + + /// Creates a request which appends *aggregates* to the current selection. + /// + /// // SELECT player.*, COUNT(DISTINCT book.rowid) AS bookCount + /// // FROM player LEFT JOIN book ... + /// var request = Player.all() + /// request = request.annotated(with: [Player.books.count]) + public func annotated(with aggregates: [AssociationAggregate]) -> QueryInterfaceRequest { + return aggregates.reduce(self) { request, aggregate in + request.annotated(with: aggregate) + } + } + + /// Creates a request which appends the provided aggregate *predicate* to + /// the eventual set of already applied predicates. + /// + /// // SELECT player.* + /// // FROM player LEFT JOIN book ... + /// // HAVING COUNT(DISTINCT book.rowid) = 0 + /// var request = Player.all() + /// request = request.having(Player.books.isEmpty) + public func having(_ predicate: AssociationAggregate) -> QueryInterfaceRequest { + let (request, expression) = predicate.prepare(self) + return request.having(expression) + } +} diff --git a/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift b/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift new file mode 100644 index 000000000..39f4a2679 --- /dev/null +++ b/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift @@ -0,0 +1,424 @@ +// QueryInterfaceRequest is the type of requests generated by TableRecord: +// +// struct Player: TableRecord { ... } +// let playerRequest = Player.all() // QueryInterfaceRequest +// +// It wraps an SQLQuery, and has an attached type. +// +// The attached type helps decoding raw database values: +// +// try dbQueue.read { db in +// try playerRequest.fetchAll(db) // [Player] +// } +// +// The attached type also helps the compiler validate associated requests: +// +// playerRequest.including(required: Player.team) // OK +// fruitRequest.including(required: Player.team) // Does not compile + +/// QueryInterfaceRequest is a request that generates SQL for you. +/// +/// For example: +/// +/// try dbQueue.read { db in +/// let request = Player +/// .filter(Column("score") > 1000) +/// .order(Column("name")) +/// let players = try request.fetchAll(db) // [Player] +/// } +/// +/// See https://github.com/groue/GRDB.swift#the-query-interface +public struct QueryInterfaceRequest { + var query: SQLQuery + + init(query: SQLQuery) { + self.query = query + } + + init(relation: SQLRelation) { + self.init(query: SQLQuery(relation: relation)) + } + + var prefetchedAssociations: [SQLAssociation] { + return query.relation.prefetchedAssociations + } +} + +extension QueryInterfaceRequest : FetchRequest { + public typealias RowDecoder = T + + /// Returns a tuple that contains a prepared statement that is ready to be + /// executed, and an eventual row adapter. + /// + /// - parameter db: A database connection. + /// - parameter singleResult: A hint as to whether the query should be optimized for a single result. + /// - returns: A prepared statement and an eventual row adapter. + /// :nodoc: + public func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) { + var query = self.query + + // Optimize query by setting a limit of 1 when appropriate + if singleResult && !query.expectsSingleResult { + query.limit = SQLLimit(limit: 1, offset: query.limit?.offset) + } + + return try SQLQueryGenerator(query).prepare(db) + } + + /// Returns the number of rows fetched by the request. + /// + /// - parameter db: A database connection. + /// :nodoc: + public func fetchCount(_ db: Database) throws -> Int { + return try query.fetchCount(db) + } + + /// Returns the database region that the request looks into. + /// + /// - parameter db: A database connection. + /// :nodoc: + public func databaseRegion(_ db: Database) throws -> DatabaseRegion { + var region = try SQLQueryGenerator(query).databaseRegion(db) + + // Iterate all prefetched associations + var fifo = query.relation.prefetchedAssociations + while !fifo.isEmpty { + let association = fifo.removeFirst() + + // Build the query for prefetched rows. + // CAUTION: Keep this code in sync with Row.prefetch(_:associations:in:) + let pivotMappings = try association.pivot.condition.columnMappings(db) + let pivotColumns = pivotMappings.map { $0.right } + let pivotAlias = TableAlias() + let prefetchedRelation = association + .mapPivotRelation { $0.qualified(with: pivotAlias) } + .destinationRelation(fromOriginRows: { _ in [] /* no origin row */ }) + .annotated(with: pivotColumns.map { pivotAlias[Column($0)].aliased("grdb_\($0)") }) + let prefetchedQuery = SQLQuery(relation: prefetchedRelation) + + // Union region + try region.formUnion(SQLQueryGenerator(prefetchedQuery).databaseRegion(db)) + + // Append nested prefetched associations (support for + // A.including(all: A.bs.including(all: B.cs)) + fifo.append(contentsOf: prefetchedRelation.prefetchedAssociations) + } + + return region + } +} + +extension QueryInterfaceRequest : DerivableRequest, AggregatingRequest { + + // MARK: Request Derivation + + /// Creates a request which selects *selection*. + /// + /// // SELECT id, email FROM player + /// var request = Player.all() + /// request = request.select([Column("id"), Column("email")]) + /// + /// Any previous selection is replaced: + /// + /// // SELECT email FROM player + /// request + /// .select([Column("id")]) + /// .select([Column("email")]) + public func select(_ selection: [SQLSelectable]) -> QueryInterfaceRequest { + return mapQuery { $0.select(selection) } + } + + /// Creates a request which selects *selection*, and fetches values of + /// type *type*. + /// + /// try dbQueue.read { db in + /// // SELECT max(score) FROM player + /// let request = Player.all().select([max(Column("score"))], as: Int.self) + /// let maxScore: Int? = try request.fetchOne(db) + /// } + public func select(_ selection: [SQLSelectable], as type: RowDecoder.Type) -> QueryInterfaceRequest { + return mapQuery { $0.select(selection) }.asRequest(of: RowDecoder.self) + } + + /// Creates a request which selects *selection*, and fetches values of + /// type *type*. + /// + /// try dbQueue.read { db in + /// // SELECT max(score) FROM player + /// let request = Player.all().select(max(Column("score")), as: Int.self) + /// let maxScore: Int? = try request.fetchOne(db) + /// } + public func select(_ selection: SQLSelectable..., as type: RowDecoder.Type) -> QueryInterfaceRequest { + return select(selection, as: type) + } + + /// Creates a request which selects *sql*, and fetches values of + /// type *type*. + /// + /// try dbQueue.read { db in + /// // SELECT max(score) FROM player + /// let request = Player.all().select(sql: "max(score)", as: Int.self) + /// let maxScore: Int? = try request.fetchOne(db) + /// } + public func select(sql: String, arguments: StatementArguments = StatementArguments(), as type: RowDecoder.Type) -> QueryInterfaceRequest { + return select(literal: SQLLiteral(sql: sql, arguments: arguments), as: type) + } + + /// Creates a request which selects an SQL *literal*, and fetches values of + /// type *type*. + /// + /// try dbQueue.read { db in + /// // SELECT IFNULL(name, 'Anonymous') FROM player WHERE id = 42 + /// let request = Player. + /// .filter(primaryKey: 42) + /// .select( + /// SQLLiteral( + /// sql: "IFNULL(name, ?)", + /// arguments: ["Anonymous"]), + /// as: String.self) + /// let name: String? = try request.fetchOne(db) + /// } + /// + /// With Swift 5, you can safely embed raw values in your SQL queries, + /// without any risk of syntax errors or SQL injection: + /// + /// try dbQueue.read { db in + /// // SELECT IFNULL(name, 'Anonymous') FROM player WHERE id = 42 + /// let request = Player. + /// .filter(primaryKey: 42) + /// .select( + /// literal: "IFNULL(name, \("Anonymous"))", + /// as: String.self) + /// let name: String? = try request.fetchOne(db) + /// } + public func select(literal sqlLiteral: SQLLiteral, as type: RowDecoder.Type) -> QueryInterfaceRequest { + return select(SQLSelectionLiteral(literal: sqlLiteral), as: type) + } + + /// Creates a request which appends *selection*. + /// + /// // SELECT id, email, name FROM player + /// var request = Player.all() + /// request = request + /// .select([Column("id"), Column("email")]) + /// .annotated(with: [Column("name")]) + public func annotated(with selection: [SQLSelectable]) -> QueryInterfaceRequest { + // TODO: test consumption of + // + // let author = TableAlias() + // let request = Book + // .annotated(with: [author[Column("name")]]) + // .joining(requireed: Book.author) + // + // The problem is the "author.name" column. Can we consume it as "name"? + // From raw rows? From copied rows? + return mapQuery { $0.annotated(with: selection) } + } + + /// Creates a request which returns distinct rows. + /// + /// // SELECT DISTINCT * FROM player + /// var request = Player.all() + /// request = request.distinct() + /// + /// // SELECT DISTINCT name FROM player + /// var request = Player.select(Column("name")) + /// request = request.distinct() + public func distinct() -> QueryInterfaceRequest { + return mapQuery { $0.distinct() } + } + + /// Creates a request with the provided *predicate promise* added to the + /// eventual set of already applied predicates. + /// + /// // SELECT * FROM player WHERE 1 + /// var request = Player.all() + /// request = request.filter { db in true } + public func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> QueryInterfaceRequest { + return mapQuery { $0.filter(predicate) } + } + + /// Creates a request which expects a single result. + /// + /// It is unlikely you need to call this method. Its net effect is that + /// QueryInterfaceRequest does not use any `LIMIT 1` sql clause when you + /// call a `fetchOne` method. + /// + /// :nodoc: + public func expectingSingleResult() -> QueryInterfaceRequest { + return mapQuery { $0.expectingSingleResult() } + } + + /// Creates a request grouped according to *expressions promise*. + public func group(_ expressions: @escaping (Database) throws -> [SQLExpressible]) -> QueryInterfaceRequest { + return mapQuery { $0.group(expressions) } + } + + /// Creates a request with the provided *predicate* added to the + /// eventual set of already applied predicates. + public func having(_ predicate: SQLExpressible) -> QueryInterfaceRequest { + return mapQuery { $0.having(predicate) } + } + + /// Creates a request with the provided *orderings promise*. + /// + /// // SELECT * FROM player ORDER BY name + /// var request = Player.all() + /// request = request.order { _ in [Column("name")] } + /// + /// Any previous ordering is replaced: + /// + /// // SELECT * FROM player ORDER BY name + /// request + /// .order{ _ in [Column("email")] } + /// .reversed() + /// .order{ _ in [Column("name")] } + public func order(_ orderings: @escaping (Database) throws -> [SQLOrderingTerm]) -> QueryInterfaceRequest { + return mapQuery { $0.order(orderings) } + } + + /// Creates a request that reverses applied orderings. + /// + /// // SELECT * FROM player ORDER BY name DESC + /// var request = Player.all().order(Column("name")) + /// request = request.reversed() + /// + /// If no ordering was applied, the returned request is identical. + /// + /// // SELECT * FROM player + /// var request = Player.all() + /// request = request.reversed() + public func reversed() -> QueryInterfaceRequest { + return mapQuery { $0.reversed() } + } + + /// Creates a request without any ordering. + /// + /// // SELECT * FROM player + /// var request = Player.all().order(Column("name")) + /// request = request.unordered() + public func unordered() -> QueryInterfaceRequest { + return mapQuery { $0.unordered() } + } + + /// Creates a request which fetches *limit* rows, starting at *offset*. + /// + /// // SELECT * FROM player LIMIT 1 + /// var request = Player.all() + /// request = request.limit(1) + /// + /// Any previous limit is replaced. + public func limit(_ limit: Int, offset: Int? = nil) -> QueryInterfaceRequest { + return mapQuery { $0.limit(limit, offset: offset) } + } + + /// Creates a request that allows you to define expressions that target + /// a specific database table. + /// + /// In the example below, the "team.avgScore < player.score" condition in + /// the ON clause could be not achieved without table aliases. + /// + /// struct Player: TableRecord { + /// static let team = belongsTo(Team.self) + /// } + /// + /// // SELECT player.*, team.* + /// // JOIN team ON ... AND team.avgScore < player.score + /// let playerAlias = TableAlias() + /// let request = Player + /// .all() + /// .aliased(playerAlias) + /// .including(required: Player.team.filter(Column("avgScore") < playerAlias[Column("score")]) + public func aliased(_ alias: TableAlias) -> QueryInterfaceRequest { + return mapQuery { $0.qualified(with: alias) } + } + + /// Creates a request bound to type Target. + /// + /// The returned request can fetch if the type Target is fetchable (Row, + /// value, record). + /// + /// // Int? + /// let maxScore = try Player + /// .select(max(scoreColumn)) + /// .asRequest(of: Int.self) // <-- + /// .fetchOne(db) + /// + /// - parameter type: The fetched type Target + /// - returns: A typed request bound to type Target. + public func asRequest(of type: RowDecoder.Type) -> QueryInterfaceRequest { + return QueryInterfaceRequest(query: query) + } + + /// Returns a request whose query is transformed by the given closure. + func mapQuery(_ transform: (SQLQuery) -> SQLQuery) -> QueryInterfaceRequest { + var request = self + request.query = transform(query) + return request + } +} + +extension QueryInterfaceRequest { + /// Turns a request into a SQLRelation. + /// + /// This method helps initializing associations: + /// + /// struct Book: TableRecord { + /// // invokes Author.all().relation + /// static let author = belongsTo(Author.self) + /// } + var relation: SQLRelation { + let query = self.query + + // Prevent information loss + GRDBPrecondition(!query.isDistinct, "Not implemented: join distinct queries") + GRDBPrecondition(query.groupPromise == nil, "Can't join aggregated queries") + GRDBPrecondition(query.havingExpression == nil, "Can't join aggregated queries") + GRDBPrecondition(query.limit == nil, "Can't join limited queries") + + return query.relation + } +} + +extension QueryInterfaceRequest: TableRequest { + /// :nodoc: + public var databaseTableName: String { + switch query.relation.source { + case .table(tableName: let tableName, alias: _): + // Use case: + // + // let request = Player.all() + // request.filter(key: ...) + // request.filter(keys: ...) + // request.orderByPrimaryKey() + return tableName + case .query: + // The only current use case for SQLSource.query is the + // "trivial count query" (see SQLQuery.countQuery): + // + // // SELECT COUNT(*) FROM (SELECT * FROM player LIMIT 10) + // let request = Player.limit(10) + // let count = try request.fetchCount(db) + // + // This query is currently never wrapped in a QueryInterfaceRequest + // So this fatal error can not currently happen. + fatalError("Request is not based on a database table") + } + } +} + +extension QueryInterfaceRequest where T: MutablePersistableRecord { + + // MARK: Deleting + + /// Deletes matching rows; returns the number of deleted rows. + /// + /// - parameter db: A database connection. + /// - returns: The number of deleted rows + /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. + @discardableResult + public func deleteAll(_ db: Database) throws -> Int { + try SQLQueryGenerator(query).makeDeleteStatement(db).execute() + return db.changesCount + } +} diff --git a/GRDB/QueryInterface/RequestProtocols.swift b/GRDB/QueryInterface/Request/RequestProtocols.swift similarity index 68% rename from GRDB/QueryInterface/RequestProtocols.swift rename to GRDB/QueryInterface/Request/RequestProtocols.swift index 3f7480db5..44f69017a 100644 --- a/GRDB/QueryInterface/RequestProtocols.swift +++ b/GRDB/QueryInterface/Request/RequestProtocols.swift @@ -19,6 +19,15 @@ public protocol SelectionRequest { /// .select([Column("id")]) /// .select([Column("email")]) func select(_ selection: [SQLSelectable]) -> Self + + /// Creates a request which appends *selection*. + /// + /// // SELECT id, email, name FROM player + /// var request = Player.all() + /// request = request + /// .select([Column("id"), Column("email")]) + /// .annotated(with: [Column("name")]) + func annotated(with selection: [SQLSelectable]) -> Self } /// :nodoc: @@ -51,8 +60,49 @@ extension SelectionRequest { /// request /// .select(sql: "id") /// .select(sql: "email") - public func select(sql: String, arguments: StatementArguments? = nil) -> Self { - return select(SQLSelectionLiteral(sql, arguments: arguments)) + public func select(sql: String, arguments: StatementArguments = StatementArguments()) -> Self { + return select(literal: SQLLiteral(sql: sql, arguments: arguments)) + } + + /// Creates a request which selects an SQL *literal*. + /// + /// // SELECT id, email, score + 1000 FROM player + /// let bonus = 1000 + /// var request = Player.all() + /// request = request.select(literal: SQLLiteral(sql: """ + /// id, email, score + ? + /// """, arguments: [bonus])) + /// + /// With Swift 5, you can safely embed raw values in your SQL queries, + /// without any risk of syntax errors or SQL injection: + /// + /// // SELECT id, email, score + 1000 FROM player + /// let bonus = 1000 + /// var request = Player.all() + /// request = request.select(literal: """ + /// id, email, score + \(bonus) + /// """) + /// + /// Any previous selection is replaced: + /// + /// // SELECT email FROM player + /// request + /// .select(...) + /// .select(literal: SQLLiteral(sql: "email")) + public func select(literal sqlLiteral: SQLLiteral) -> Self { + // NOT TESTED + return select(SQLSelectionLiteral(literal: sqlLiteral)) + } + + /// Creates a request which appends *selection*. + /// + /// // SELECT id, email, name FROM player + /// var request = Player.all() + /// request = request + /// .select([Column("id"), Column("email")]) + /// .annotated(with: Column("name")) + public func annotated(with selection: SQLSelectable...) -> Self { + return annotated(with: selection) } } @@ -71,10 +121,23 @@ public protocol FilteredRequest { /// var request = Player.all() /// request = request.filter { db in true } func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> Self + + /// Creates a request which expects a single result. + /// + /// Requests expecting a single result may ignore the second parameter of + /// the `FetchRequest.prepare(_:forSingleResult:)` method, in order to + /// produce sharply tailored SQL. + /// + /// This method has a default implementation which returns self. + func expectingSingleResult() -> Self } /// :nodoc: extension FilteredRequest { + public func expectingSingleResult() -> Self { + return self + } + /// Creates a request with the provided *predicate* added to the /// eventual set of already applied predicates. /// @@ -91,10 +154,29 @@ extension FilteredRequest { /// // SELECT * FROM player WHERE email = 'arthur@example.com' /// var request = Player.all() /// request = request.filter(sql: "email = ?", arguments: ["arthur@example.com"]) - public func filter(sql: String, arguments: StatementArguments? = nil) -> Self { - return filter(SQLExpressionLiteral(sql, arguments: arguments)) + public func filter(sql: String, arguments: StatementArguments = StatementArguments()) -> Self { + return filter(literal: SQLLiteral(sql: sql, arguments: arguments)) } + /// Creates a request with the provided *predicate* added to the + /// eventual set of already applied predicates. + /// + /// // SELECT * FROM player WHERE email = 'arthur@example.com' + /// var request = Player.all() + /// request = request.filter(literal: SQLLiteral(sql: """ + /// email = ? + /// """, arguments: ["arthur@example.com"]) + /// + /// With Swift 5, you can safely embed raw values in your SQL queries, + /// without any risk of syntax errors or SQL injection: + /// + /// var request = Player.all() + /// request = request.filter(literal: "name = \("O'Brien")") + public func filter(literal sqlLiteral: SQLLiteral) -> Self { + // NOT TESTED + return filter(SQLExpressionLiteral(literal: sqlLiteral)) + } + /// Creates a request that matches nothing. /// /// // SELECT * FROM player WHERE 0 @@ -149,24 +231,24 @@ extension TableRequest where Self: FilteredRequest { /// Creates a request with the provided primary key *predicate*. public func filter(keys: Sequence) -> Self where Sequence.Element: DatabaseValueConvertible { + var request = self let keys = Array(keys) - let makePredicate: (Column) -> SQLExpression switch keys.count { case 0: return none() case 1: - makePredicate = { $0 == keys[0] } + request = request.expectingSingleResult() default: - makePredicate = { keys.contains($0) } + break } - + let databaseTableName = self.databaseTableName - return filter { db in + return request.filter { db in let primaryKey = try db.primaryKey(databaseTableName) GRDBPrecondition( primaryKey.columns.count == 1, "Requesting by key requires a single-column primary key in the table \(databaseTableName)") - return makePredicate(Column(primaryKey.columns[0])) + return keys.contains(Column(primaryKey.columns[0])) } } @@ -186,12 +268,18 @@ extension TableRequest where Self: FilteredRequest { /// When executed, this request raises a fatal error if there is no unique /// index on the key columns. public func filter(keys: [[String: DatabaseValueConvertible?]]) -> Self { - guard !keys.isEmpty else { + var request = self + switch keys.count { + case 0: return none() + case 1: + request = request.expectingSingleResult() + default: + break } let databaseTableName = self.databaseTableName - return filter { db in + return request.filter { db in try keys .map { key in // Prevent filter(keys: [["foo": 1, "bar": 2]]) where @@ -205,8 +293,8 @@ extension TableRequest where Self: FilteredRequest { return key // Preserve ordering of columns in the unique index .sorted { (kv1, kv2) in - let index1 = lowercaseColumns.index(of: kv1.key.lowercased())! - let index2 = lowercaseColumns.index(of: kv2.key.lowercased())! + let index1 = lowercaseColumns.firstIndex(of: kv1.key.lowercased())! + let index2 = lowercaseColumns.firstIndex(of: kv2.key.lowercased())! return index1 < index2 } .map { (column, value) in Column(column) == value } @@ -268,24 +356,35 @@ extension AggregatingRequest { } /// Creates a request with a new grouping. - public func group(sql: String, arguments: StatementArguments? = nil) -> Self { + public func group(sql: String, arguments: StatementArguments = StatementArguments()) -> Self { + return group(literal: SQLLiteral(sql: sql, arguments: arguments)) + } + + /// Creates a request with a new grouping. + public func group(literal sqlLiteral: SQLLiteral) -> Self { + // NOT TESTED // This "expression" is not a real expression. We support raw sql which // actually contains several expressions: // // request = Player.group(sql: "teamId, level") // - // This is why we use the "unsafe" flag, so that the SQLExpressionLiteral - // does not output its safe wrapping parenthesis, and generates - // invalid SQL. - var expression = SQLExpressionLiteral(sql, arguments: arguments) - expression.unsafeRaw = true - return group(expression) + // This is why we use the "unsafeLiteral" initializer, so that the + // SQLExpressionLiteral does not wrap input in parentheses, and + // generates invalid SQL `GROUP BY (teamId, level)`. + return group(SQLExpressionLiteral(unsafeLiteral: sqlLiteral)) } - + /// Creates a request with the provided *sql* added to the /// eventual set of already applied predicates. - public func having(sql: String, arguments: StatementArguments? = nil) -> Self { - return having(SQLExpressionLiteral(sql, arguments: arguments)) + public func having(sql: String, arguments: StatementArguments = StatementArguments()) -> Self { + return having(literal: SQLLiteral(sql: sql, arguments: arguments)) + } + + /// Creates a request with the provided *sql* added to the + /// eventual set of already applied predicates. + public func having(literal sqlLiteral: SQLLiteral) -> Self { + // NOT TESTED + return having(SQLExpressionLiteral(literal: sqlLiteral)) } } @@ -324,6 +423,13 @@ public protocol OrderedRequest { /// var request = Player.all() /// request = request.reversed() func reversed() -> Self + + /// Creates a request without any ordering. + /// + /// // SELECT * FROM player + /// var request = Player.all().order(Column("name")) + /// request = request.unordered() + func unordered() -> Self } /// :nodoc: @@ -362,7 +468,7 @@ extension OrderedRequest { return order { _ in orderings } } - /// Creates a request with the provided *sql* used for sorting. + /// Creates a request sorted according to *sql*. /// /// // SELECT * FROM player ORDER BY name /// var request = Player.all() @@ -374,18 +480,33 @@ extension OrderedRequest { /// request /// .order(sql: "email") /// .order(sql: "name") - public func order(sql: String, arguments: StatementArguments? = nil) -> Self { + public func order(sql: String, arguments: StatementArguments = StatementArguments()) -> Self { + return order(literal: SQLLiteral(sql: sql, arguments: arguments)) + } + + /// Creates a request sorted according to an SQL *literal*. + /// + /// // SELECT * FROM player ORDER BY name + /// var request = Player.all() + /// request = request.order(sql: "name") + /// + /// Any previous ordering is replaced: + /// + /// // SELECT * FROM player ORDER BY name + /// request + /// .order(sql: "email") + /// .order(sql: "name") + public func order(literal sqlLiteral: SQLLiteral) -> Self { + // NOT TESTED // This "expression" is not a real expression. We support raw sql which // actually contains several expressions: // // request = Player.order(sql: "teamId, level") // - // This is why we use the "unsafe" flag, so that the SQLExpressionLiteral - // does not output its safe wrapping parenthesis, and generates - // invalid SQL. - var expression = SQLExpressionLiteral(sql, arguments: arguments) - expression.unsafeRaw = true - return order([expression]) + // This is why we use the "unsafeLiteral" initializer, so that the + // SQLExpressionLiteral does not wrap input in parentheses, and + // generates invalid SQL `ORDER BY (teamId, level)`. + return order(SQLExpressionLiteral(unsafeLiteral: sqlLiteral)) } } diff --git a/GRDB/QueryInterface/Row+QueryInterfaceRequest.swift b/GRDB/QueryInterface/Row+QueryInterfaceRequest.swift new file mode 100644 index 000000000..4efd97c5e --- /dev/null +++ b/GRDB/QueryInterface/Row+QueryInterfaceRequest.swift @@ -0,0 +1,219 @@ +extension QueryInterfaceRequest where RowDecoder == Row { + + // MARK: Fetching Rows + + /// A cursor over fetched rows. + /// + /// let request: QueryInterfaceRequest = ... + /// let rows = try request.fetchCursor(db) // RowCursor + /// while let row = try rows.next() { // Row + /// let id: Int64 = row[0] + /// let name: String = row[1] + /// } + /// + /// Fetched rows are reused during the cursor iteration: don't turn a row + /// cursor into an array with `Array(rows)` or `rows.filter { ... }` since + /// you would not get the distinct rows you expect. Use `Row.fetchAll(...)` + /// instead. + /// + /// For the same reason, make sure you make a copy whenever you extract a + /// row for later use: `row.copy()`. + /// + /// If the database is modified during the cursor iteration, the remaining + /// elements are undefined. + /// + /// The cursor must be iterated in a protected dispath queue. + /// + /// - parameter db: A database connection. + /// - returns: A cursor over fetched rows. + /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. + public func fetchCursor(_ db: Database) throws -> RowCursor { + return try Row.fetchCursor(db, self) + } + + /// An array of fetched rows. + /// + /// let request: QueryInterfaceRequest = ... + /// let rows = try request.fetchAll(db) + /// + /// - parameter db: A database connection. + /// - returns: An array of fetched rows. + /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. + public func fetchAll(_ db: Database) throws -> [Row] { + return try Row.fetchAll(db, self) + } + + /// The first fetched row. + /// + /// let request: QueryInterfaceRequest = ... + /// let row = try request.fetchOne(db) + /// + /// - parameter db: A database connection. + /// - returns: An optional row. + /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. + public func fetchOne(_ db: Database) throws -> Row? { + return try Row.fetchOne(db, self) + } +} + +extension Row { + + // MARK: - Fetching From QueryInterfaceRequest + + /// Returns a cursor over rows fetched from a fetch request. + /// + /// let request = Player.all() + /// let rows = try Row.fetchCursor(db, request) // RowCursor + /// while let row = try rows.next() { // Row + /// let id: Int64 = row["id"] + /// let name: String = row["name"] + /// } + /// + /// Fetched rows are reused during the cursor iteration: don't turn a row + /// cursor into an array with `Array(rows)` or `rows.filter { ... }` since + /// you would not get the distinct rows you expect. Use `Row.fetchAll(...)` + /// instead. + /// + /// For the same reason, make sure you make a copy whenever you extract a + /// row for later use: `row.copy()`. + /// + /// If the database is modified during the cursor iteration, the remaining + /// elements are undefined. + /// + /// The cursor must be iterated in a protected dispath queue. + /// + /// - parameters: + /// - db: A database connection. + /// - request: A FetchRequest. + /// - returns: A cursor over fetched rows. + /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. + public static func fetchCursor(_ db: Database, _ request: QueryInterfaceRequest) throws -> RowCursor { + precondition(request.prefetchedAssociations.isEmpty, "Not implemented: fetchCursor with prefetched associations") + let (statement, adapter) = try request.prepare(db, forSingleResult: false) + return try fetchCursor(statement, adapter: adapter) + } + + /// Returns an array of rows fetched from a fetch request. + /// + /// let request = Player.all() + /// let rows = try Row.fetchAll(db, request) + /// + /// - parameters: + /// - db: A database connection. + /// - request: A FetchRequest. + /// - returns: An array of rows. + /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. + public static func fetchAll(_ db: Database, _ request: QueryInterfaceRequest) throws -> [Row] { + let (statement, adapter) = try request.prepare(db, forSingleResult: false) + let rows = try fetchAll(statement, adapter: adapter) + + let associations = request.prefetchedAssociations + if associations.isEmpty == false { + try prefetch(db, associations: associations, in: rows) + } + return rows + } + + /// Returns a single row fetched from a fetch request. + /// + /// let request = Player.filter(key: 1) + /// let row = try Row.fetchOne(db, request) + /// + /// - parameters: + /// - db: A database connection. + /// - request: A FetchRequest. + /// - returns: An optional row. + /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. + public static func fetchOne(_ db: Database, _ request: QueryInterfaceRequest) throws -> Row? { + let (statement, adapter) = try request.prepare(db, forSingleResult: true) + guard let row = try fetchOne(statement, adapter: adapter) else { + return nil + } + + let associations = request.prefetchedAssociations + if associations.isEmpty == false { + try prefetch(db, associations: associations, in: [row]) + } + return row + } + + /// Append rows from prefetched associations into the argument rows. + static func prefetch(_ db: Database, associations: [SQLAssociation], in rows: [Row]) throws { + guard let firstRow = rows.first else { + return + } + + // CAUTION: Keep this code in sync with QueryInterfaceRequest.databaseRegion(_:) + for association in associations { + let pivotMappings = try association.pivot.condition.columnMappings(db) + + let prefetchedRows: [[DatabaseValue] : [Row]] + do { + // Annotate prefetched rows with pivot columns, so that we can + // group them. + // + // Those pivot columns are necessary when we prefetch + // indirect associations: + // + // // SELECT country.*, passport.citizenId AS grdb_citizenId + // // -- ^ the necessary pivot column + // // FROM country + // // JOIN passport ON passport.countryCode = country.code + // // AND passport.citizenId IN (1, 2, 3) + // Citizen.including(all: Citizen.countries) + // + // Those pivot columns are redundant when we prefetch direct + // associations (maybe we'll remove this redundancy later): + // + // // SELECT *, authorId AS grdb_authorId + // // -- ^ the redundant pivot column + // // FROM book + // // WHERE authorId IN (1, 2, 3) + // Author.including(all: Author.books) + let pivotColumns = pivotMappings.map { $0.right } + let pivotAlias = TableAlias() + let prefetchedRelation = association + .mapPivotRelation { $0.qualified(with: pivotAlias) } + .destinationRelation(fromOriginRows: { _ in rows }) + .annotated(with: pivotColumns.map { pivotAlias[Column($0)].aliased("grdb_\($0)") }) + prefetchedRows = try QueryInterfaceRequest(relation: prefetchedRelation) + .fetchAll(db) + .grouped(byDatabaseValuesOnColumns: pivotColumns.map { "grdb_\($0)" }) + // TODO: can we remove those grdb_ columns now that grouping has been done? + } + + let groupingIndexes = firstRow.indexes(ofColumns: pivotMappings.map { $0.left }) + for row in rows { + let groupingKey = groupingIndexes.map { row.impl.databaseValue(atUncheckedIndex: $0) } + let prefetchedRows = prefetchedRows[groupingKey, default: []] + row.prefetchedRows.setRows(prefetchedRows, forKeyPath: association.keyPath) + } + } + } +} + +extension Array where Element == Row { + /// - precondition: Columns all exist in all rows. All rows have the same + /// columnns, in the same order. + fileprivate func grouped(byDatabaseValuesOnColumns columns: [String]) -> [[DatabaseValue]: [Row]] { + guard let firstRow = first else { + return [:] + } + let indexes = firstRow.indexes(ofColumns: columns) + return Dictionary(grouping: self, by: { row in + indexes.map { row.impl.databaseValue(atUncheckedIndex: $0) } + }) + } +} + +extension Row { + /// - precondition: Columns all exist in the row. + fileprivate func indexes(ofColumns columns: [String]) -> [Int] { + return columns.map { column -> Int in + guard let index = index(ofColumn: column) else { + fatalError("Column \(column) is not selected") + } + return index + } + } +} diff --git a/GRDB/QueryInterface/Column.swift b/GRDB/QueryInterface/SQL/Column.swift similarity index 83% rename from GRDB/QueryInterface/Column.swift rename to GRDB/QueryInterface/SQL/Column.swift index e66ca6ba4..ef13a06d6 100644 --- a/GRDB/QueryInterface/Column.swift +++ b/GRDB/QueryInterface/SQL/Column.swift @@ -36,12 +36,6 @@ extension ColumnExpression { public func qualifiedExpression(with alias: TableAlias) -> SQLExpression { return QualifiedColumn(name, alias: alias) } - - /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) - /// :nodoc: - public func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression { - return self - } } /// A column in a database table. @@ -61,6 +55,11 @@ public struct Column: ColumnExpression { public init(_ name: String) { self.name = name } + + /// Creates a column given a CodingKey. + public init(_ codingKey: CodingKey) { + self.name = codingKey.stringValue + } } /// A qualified column in the database, as in `SELECT t.a FROM t` @@ -85,22 +84,12 @@ struct QualifiedColumn: ColumnExpression { // Never requalify return self } - - func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression { - guard - let container = context[alias], - let value = container.value(forCaseInsensitiveColumn: name) else - { - return self - } - return value - } } /// Support for column enums: /// /// struct Player { -/// enum Columns: ColumnExpression { +/// enum Columns: String, ColumnExpression { /// case id, name, score /// } /// } diff --git a/GRDB/QueryInterface/DatabasePromise.swift b/GRDB/QueryInterface/SQL/DatabasePromise.swift similarity index 95% rename from GRDB/QueryInterface/DatabasePromise.swift rename to GRDB/QueryInterface/SQL/DatabasePromise.swift index 8eaad2644..d3194fc8f 100644 --- a/GRDB/QueryInterface/DatabasePromise.swift +++ b/GRDB/QueryInterface/SQL/DatabasePromise.swift @@ -42,7 +42,6 @@ struct DatabasePromise { } } - // TODO: write human-readable documentation for this classic monadic operation func flatMap(_ transform: @escaping (T) -> DatabasePromise) -> DatabasePromise { return DatabasePromise { db in try transform(self.resolve(db)).resolve(db) diff --git a/GRDB/QueryInterface/SQL/SQLAssociation.swift b/GRDB/QueryInterface/SQL/SQLAssociation.swift new file mode 100644 index 000000000..a918fcea5 --- /dev/null +++ b/GRDB/QueryInterface/SQL/SQLAssociation.swift @@ -0,0 +1,353 @@ +// MARK: - SQLAssociation + +/// An SQL association is a non-empty chain of steps which starts at the +/// "pivot" and ends on the "destination": +/// +/// // SELECT origin.*, destination.* +/// // FROM origin +/// // JOIN pivot ON ... +/// // JOIN ... +/// // JOIN ... +/// // JOIN destination ON ... +/// Origin.including(required: association) +/// +/// For direct associations such as BelongTo or HasMany, the chain contains a +/// single element, the "destination", without intermediate step: +/// +/// // "Origin" belongsTo "destination": +/// // SELECT origin.*, destination.* +/// // FROM origin +/// // JOIN destination ON destination.originId = origin.id +/// let association = Origin.belongsTo(Destination.self) +/// Origin.including(required: association) +/// +/// Indirect associations such as HasManyThrough have one or several +/// intermediate steps: +/// +/// // "Origin" has many "destination" through "pivot": +/// // SELECT origin.*, destination.* +/// // FROM origin +/// // JOIN pivot ON pivot.originId = origin.id +/// // JOIN destination ON destination.id = pivot.destinationId +/// let association = Origin.hasMany( +/// Destination.self, +/// through: Origin.hasMany(Pivot.self), +/// via: Pivot.belongsTo(Destination.self)) +/// Origin.including(required: association) +/// +/// // "Origin" has many "destination" through "pivot1" and "pivot2": +/// // SELECT origin.*, destination.* +/// // FROM origin +/// // JOIN pivot1 ON pivot1.originId = origin.id +/// // JOIN pivot2 ON pivot2.pivot1Id = pivot1.id +/// // JOIN destination ON destination.id = pivot.destinationId +/// let association = Origin.hasMany( +/// Destination.self, +/// through: Origin.hasMany(Pivot1.self), +/// via: Pivot1.hasMany( +/// Destination.self, +/// through: Pivot1.hasMany(Pivot2.self), +/// via: Pivot2.belongsTo(Destination.self))) +/// Origin.including(required: association) +/// +/// :nodoc: +public /* TODO: internal */ struct SQLAssociation { + // All steps, from pivot to destination. Never empty. + private(set) var steps: [SQLAssociationStep] + var keyPath: [String] { + return steps.map { $0.key.name(for: $0.cardinality) } + } + + var destination: SQLAssociationStep { + get { return steps[steps.count - 1] } + set { steps[steps.count - 1] = newValue } + } + + var pivot: SQLAssociationStep { + get { return steps[0] } + set { steps[0] = newValue } + } + + init(steps: [SQLAssociationStep]) { + assert(!steps.isEmpty) + self.steps = steps + } + + init( + key: SQLAssociationKey, + condition: SQLAssociationCondition, + relation: SQLRelation, + cardinality: SQLAssociationCardinality) + { + let step = SQLAssociationStep( + key: key, + condition: condition, + relation: relation, + cardinality: cardinality) + self.init(steps: [step]) + } + + /// Changes the destination key + func forDestinationKey(_ key: SQLAssociationKey) -> SQLAssociation { + var result = self + result.destination.key = key + return result + } + + /// Transforms the destination relation + func mapDestinationRelation(_ transform: (SQLRelation) -> SQLRelation) -> SQLAssociation { + var result = self + result.destination = result.destination.mapRelation(transform) + return result + } + + /// Transforms the pivot relation + func mapPivotRelation(_ transform: (SQLRelation) -> SQLRelation) -> SQLAssociation { + var result = self + result.pivot = result.pivot.mapRelation(transform) + return result + } + + /// Returns a new association + func through(_ other: SQLAssociation) -> SQLAssociation { + return SQLAssociation(steps: other.steps + steps) + } + + /// Given an origin alias and rows, returns the destination of the + /// association as a relation. + /// + /// This method provides support for association methods such + /// as `request(for:)`: + /// + /// struct Destination: TableRecord { } + /// struct Origin: TableRecord, EncodableRecord { + /// static let destinations = hasMany(Destination.self) + /// var destinations: QueryInterface { + /// return request(for: Origin.destinations) + /// } + /// } + /// + /// // SELECT destination.* + /// // FROM destination + /// // WHERE destination.originId = 1 + /// let origin = Origin(id: 1) + /// let destinations = origin.destinations.fetchAll(db) + /// + /// At low-level, this gives: + /// + /// let origin = Origin(id: 1) + /// let originAlias = TableAlias(tableName: Origin.databaseTableName) + /// let sqlAssociation = Origin.destination.sqlAssociation + /// let destinationRelation = sqlAssociation.destinationRelation( + /// from: originAlias, + /// rows: { db in try [Row(PersistenceContainer(db, origin))] }) + /// let query = SQLQuery(relation: destinationRelation) + /// let generator = SQLQueryGenerator(query) + /// let statement, _ = try generator.prepare(db) + /// print(statement.sql) + /// // SELECT destination.* + /// // FROM destination + /// // WHERE destination.originId = 1 + /// + /// This method works for simple direct associations such as BelongsTo or + /// HasMany in the above examples, but also for indirect associations such + /// as HasManyThrough, which have any number of pivot relations between the + /// origin and the destination. + func destinationRelation(fromOriginRows originRows: @escaping (Database) throws -> [Row]) -> SQLRelation { + // Filter the pivot + let pivot = self.pivot + let pivotAlias = TableAlias() + let filteredPivotRelation = pivot.relation + .qualified(with: pivotAlias) + .filter({ db in + // `pivot.originId = 123` or `pivot.originId IN (1, 2, 3)` + try pivot.condition.filteringExpression(db, leftRows: originRows(db), rightAlias: pivotAlias) + }) + + if steps.count == 1 { + // This is a direct join from origin to destination, without + // intermediate step. + // + // SELECT destination.* + // FROM destination + // WHERE destination.originId = 1 + // + // let association = Origin.hasMany(Destination.self) + // Origin(id: 1).request(for: association) + return filteredPivotRelation + } + + // This is an indirect join from origin to destination, through + // some intermediate steps: + // + // SELECT destination.* + // FROM destination + // JOIN pivot ON (pivot.destinationId = destination.id) AND (pivot.originId = 1) + // + // let association = Origin.hasMany( + // Destination.self, + // through: Origin.hasMany(Pivot.self), + // via: Pivot.belongsTo(Destination.self)) + // Origin(id: 1).request(for: association) + let reversedSteps = zip(steps, steps.dropFirst()) + .map { (step, nextStep) -> SQLAssociationStep in + // Intermediate steps are not included in the selection, and + // don't have any child. + let relation = step.relation.select([]).deletingChildren() + return SQLAssociationStep( + key: step.key, + condition: nextStep.condition.reversed, + relation: relation, + cardinality: step.cardinality) + } + .reversed() + + var reversedAssociation = SQLAssociation(steps: Array(reversedSteps)) + // Replace pivot with the filtered one (not included in the selection, + // without children). + reversedAssociation = reversedAssociation.mapDestinationRelation { _ in + filteredPivotRelation.select([]).deletingChildren() + } + return destination.relation.appending(reversedAssociation, kind: .oneRequired) + } +} + +struct SQLAssociationStep { + var key: SQLAssociationKey + var condition: SQLAssociationCondition + var relation: SQLRelation + var cardinality: SQLAssociationCardinality + + func mapRelation(_ transform: (SQLRelation) -> SQLRelation) -> SQLAssociationStep { + return SQLAssociationStep( + key: key, + condition: condition, + relation: transform(relation), + cardinality: cardinality) + } +} + +enum SQLAssociationCardinality { + case toOne + case toMany +} + +// MARK: - SQLAssociationKey + +/// Associations are meant to be consumed, most often into Decodable records. +/// +/// Those records have singular or plural property names, and we want +/// associations to be able to fill those singular or plural names +/// automatically, so that the user does not have to perform explicit +/// decoding configuration. +/// +/// Those plural or singular names are not decided when the association is +/// defined. For example, the Author.books association, which looks plural, may +/// actually generate "book" or "books" depending on the context: +/// +/// struct Author: TableRecord { +/// static let books = hasMany(Book.self) +/// } +/// struct Book: TableRecord { +/// } +/// +/// // "books" +/// struct AuthorInfo: FetchableRecord, Decodable { +/// var author: Author +/// var books: [Book] +/// } +/// let request = Author.including(all: Author.books) +/// let authorInfos = try AuthorInfo.fetchAll(db, request) +/// +/// "book" +/// struct AuthorInfo: FetchableRecord, Decodable { +/// var author: Author +/// var book: Book +/// } +/// let request = Author.including(required: Author.books) +/// let authorInfos = try AuthorInfo.fetchAll(db, request) +/// +/// "bookCount" +/// struct AuthorInfo: FetchableRecord, Decodable { +/// var author: Author +/// var bookCount: Int +/// } +/// let request = Author.annotated(with: Author.books.count) +/// let authorInfos = try AuthorInfo.fetchAll(db, request) +/// +/// The SQLAssociationKey type aims at providing the necessary support for +/// those various inflections. +enum SQLAssociationKey { + /// A key that is inflected in singular and plural contexts. + /// + /// For example: + /// + /// struct Author: TableRecord { + /// static let databaseTableName = "authors" + /// } + /// struct Book: TableRecord { + /// let author = belongsTo(Author.self) + /// } + /// + /// let request = Book.including(required: Book.author) + /// let row = try Row.fetchOne(db, request)! + /// row.scopes["author"] // singularized "authors" table name + case inflected(String) + + /// A key that is inflected in plural contexts, but stricly honors + /// user-provided name in singular contexts. + /// + /// For example: + /// + /// struct Country: TableRecord { + /// let demographics = hasOne(Demographics.self, key: "demographics") + /// } + /// + /// let request = Country.including(required: Country.demographics) + /// let row = try Row.fetchOne(db, request)! + /// row.scopes["demographics"] // not singularized + case fixedSingular(String) + + /// A key that is inflected in singular contexts, but stricly honors + /// user-provided name in plural contexts. + /// See .inflected and .fixedSingular for some context. + case fixedPlural(String) + + /// A key that is never inflected. + case fixed(String) + + func name(for cardinality: SQLAssociationCardinality) -> String { + switch cardinality { + case .toOne: + return singularizedName + case .toMany: + return pluralizedName + } + } + + var pluralizedName: String { + switch self { + case .inflected(let name): + return name.pluralized + case .fixedSingular(let name): + return name.pluralized + case .fixedPlural(let name): + return name + case .fixed(let name): + return name + } + } + + var singularizedName: String { + switch self { + case .inflected(let name): + return name.singularized + case .fixedSingular(let name): + return name + case .fixedPlural(let name): + return name.singularized + case .fixed(let name): + return name + } + } +} diff --git a/GRDB/QueryInterface/SQLCollatedExpression.swift b/GRDB/QueryInterface/SQL/SQLCollatedExpression.swift similarity index 100% rename from GRDB/QueryInterface/SQLCollatedExpression.swift rename to GRDB/QueryInterface/SQL/SQLCollatedExpression.swift diff --git a/GRDB/QueryInterface/SQLCollection.swift b/GRDB/QueryInterface/SQL/SQLCollection.swift similarity index 82% rename from GRDB/QueryInterface/SQLCollection.swift rename to GRDB/QueryInterface/SQL/SQLCollection.swift index 1c6700336..8bc5f6831 100644 --- a/GRDB/QueryInterface/SQLCollection.swift +++ b/GRDB/QueryInterface/SQL/SQLCollection.swift @@ -49,10 +49,15 @@ struct SQLExpressionsArray : SQLCollection { } func contains(_ value: SQLExpressible) -> SQLExpression { - if expressions.isEmpty { + guard let expression = expressions.first else { + // [].contains(Column("name")) => 0 return false.databaseValue - } else { - return SQLExpressionContains(value, self) } + if expressions.count == 1 { + // ["foo"].contains(Column("name")) => name = 'foo' + return value == expression + } + // ["foo", "bar"].contains(Column("name")) => name IN ('foo', 'bar') + return SQLExpressionContains(value, self) } } diff --git a/GRDB/QueryInterface/SQLExpressible.swift b/GRDB/QueryInterface/SQL/SQLExpressible.swift similarity index 100% rename from GRDB/QueryInterface/SQLExpressible.swift rename to GRDB/QueryInterface/SQL/SQLExpressible.swift diff --git a/GRDB/QueryInterface/SQLExpression+QueryInterface.swift b/GRDB/QueryInterface/SQL/SQLExpression+QueryInterface.swift similarity index 80% rename from GRDB/QueryInterface/SQLExpression+QueryInterface.swift rename to GRDB/QueryInterface/SQL/SQLExpression+QueryInterface.swift index 0a65e8ac8..3d1c0deb8 100644 --- a/GRDB/QueryInterface/SQLExpression+QueryInterface.swift +++ b/GRDB/QueryInterface/SQL/SQLExpression+QueryInterface.swift @@ -1,22 +1,21 @@ // MARK: - SQLExpression extension SQLExpression { - /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) /// - /// Converts an expression to an SQLExpressionLiteral + /// Converts an expression to an SQLLiteral /// /// :nodoc: - public var literal: SQLExpressionLiteral { + public var sqlLiteral: SQLLiteral { var context = SQLGenerationContext.literalGenerationContext(withArguments: true) let sql = expressionSQL(&context) - return SQLExpressionLiteral(sql, arguments: context.arguments) + return SQLLiteral(sql: sql, arguments: context.arguments!) } /// The expression as a quoted SQL literal (not public in order to avoid abuses) /// - /// "foo'bar".databaseValue.sql // "'foo''bar'"" - var sql: String { + /// "foo'bar".databaseValue.quotedSQL() // "'foo''bar'"" + func quotedSQL() -> String { var context = SQLGenerationContext.literalGenerationContext(withArguments: false) return expressionSQL(&context) } @@ -28,57 +27,61 @@ extension SQLExpression { /// /// SQLExpressionLiteral is an expression built from a raw SQL snippet. /// -/// SQLExpressionLiteral("1 + 2") +/// SQLExpressionLiteral(sql: "1 + 2") /// /// The SQL literal may contain `?` and colon-prefixed arguments: /// -/// SQLExpressionLiteral("? + ?", arguments: [1, 2]) -/// SQLExpressionLiteral(":one + :two", arguments: ["one": 1, "two": 2]) +/// SQLExpressionLiteral(sql: "? + ?", arguments: [1, 2]) +/// SQLExpressionLiteral(sql: ":one + :two", arguments: ["one": 1, "two": 2]) public struct SQLExpressionLiteral : SQLExpression { - /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) - /// - /// The SQL literal - public let sql: String + private let sqlLiteral: SQLLiteral - /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) - /// - /// Eventual arguments that feed the `?` and colon-prefixed arguments in the - /// SQL literal - public let arguments: StatementArguments? - - /// If safe, an SQLExpressionLiteral("foo") wraps itself in parenthesis, - /// and outputs "(foo)" in SQL queries. This avoids any bug due to operator - /// precedence. When unsafe, the expression literal does not wrap itself - /// in parenthesis and outputs its raw sql. - var unsafeRaw: Bool = false + public var sql: String { return sqlLiteral.sql } + public var arguments: StatementArguments { return sqlLiteral.arguments } /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) /// /// Creates an SQL literal expression. /// - /// SQLExpressionLiteral("1 + 2") - /// SQLExpressionLiteral("? + ?", arguments: [1, 2]) - /// SQLExpressionLiteral(":one + :two", arguments: ["one": 1, "two": 2]) - public init(_ sql: String, arguments: StatementArguments? = nil) { - self.sql = sql - self.arguments = arguments + /// SQLExpressionLiteral(sql: "1 + 2") + /// SQLExpressionLiteral(sql: "? + ?", arguments: [1, 2]) + /// SQLExpressionLiteral(sql: ":one + :two", arguments: ["one": 1, "two": 2]) + public init(sql: String, arguments: StatementArguments = StatementArguments()) { + self.init(literal: SQLLiteral(sql: sql, arguments: arguments)) } + /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) + /// + /// Creates an SQL literal expression. + /// + /// SQLExpressionLiteral(literal: SQLLiteral(sql: "1 + 2") + /// SQLExpressionLiteral(literal: SQLLiteral(sql: "? + ?", arguments: [1, 2])) + /// SQLExpressionLiteral(literal: SQLLiteral(sql: ":one + :two", arguments: ["one": 1, "two": 2])) + /// + /// With Swift 5, you can safely embed raw values in your SQL queries, + /// without any risk of syntax errors or SQL injection: + /// + /// SQLExpressionLiteral(literal: "\(1) + \(2)") + public init(literal sqlLiteral: SQLLiteral) { + self.init(unsafeLiteral: sqlLiteral.mapSQL { "(\($0))" }) + } + + /// Creates an SQL literal expression without wrapping the SQL literal + /// inside parentheses. It is unsafe because the result expression can not + /// be safely composed with other expressions. + init(unsafeLiteral sqlLiteral: SQLLiteral) { + self.sqlLiteral = sqlLiteral + } + /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) /// :nodoc: public func expressionSQL(_ context: inout SQLGenerationContext) -> String { - if let arguments = arguments { - if context.appendArguments(arguments) == false { - // GRDB limitation: we don't know how to look for `?` in sql and - // replace them with with literals. - fatalError("Not implemented") - } - } - if unsafeRaw { - return sql - } else { - return "(" + sql + ")" + if context.append(arguments: sqlLiteral.arguments) == false { + // GRDB limitation: we don't know how to look for `?` in sql and + // replace them with with literals. + fatalError("Not implemented") } + return sqlLiteral.sql } /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) @@ -86,12 +89,6 @@ public struct SQLExpressionLiteral : SQLExpression { public func qualifiedExpression(with alias: TableAlias) -> SQLExpression { return self } - - /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) - /// :nodoc: - public func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression { - return self - } } // MARK: - SQLExpressionUnary @@ -163,12 +160,6 @@ public struct SQLExpressionUnary : SQLExpression { public func qualifiedExpression(with alias: TableAlias) -> SQLExpression { return SQLExpressionUnary(op, expression.qualifiedExpression(with: alias)) } - - /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) - /// :nodoc: - public func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression { - return SQLExpressionUnary(op, expression.resolvedExpression(inContext: context)) - } } // MARK: - SQLExpressionBinary @@ -212,18 +203,6 @@ public struct SQLBinaryOperator : Hashable { } return SQLBinaryOperator(negatedSQL, negated: sql) } - - #if !swift(>=4.2) - /// :nodoc: - public var hashValue: Int { - return sql.hashValue ^ (negatedSQL?.hashValue ?? 0) - } - - /// :nodoc: - public static func == (lhs: SQLBinaryOperator, rhs: SQLBinaryOperator) -> Bool { - return lhs.sql == rhs.sql && lhs.negatedSQL == rhs.negatedSQL - } - #endif } /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) @@ -284,12 +263,6 @@ public struct SQLExpressionBinary : SQLExpression { public func qualifiedExpression(with alias: TableAlias) -> SQLExpression { return SQLExpressionBinary(op, lhs.qualifiedExpression(with: alias), rhs.qualifiedExpression(with: alias)) } - - /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) - /// :nodoc: - public func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression { - return SQLExpressionBinary(op, lhs.resolvedExpression(inContext: context), rhs.resolvedExpression(inContext: context)) - } } // MARK: - SQLExpressionAnd @@ -317,10 +290,6 @@ struct SQLExpressionAnd : SQLExpression { return SQLExpressionAnd(expressions.map { $0.qualifiedExpression(with: alias) }) } - func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression { - return SQLExpressionAnd(expressions.map { $0.resolvedExpression(inContext: context) }) - } - func matchedRowIds(rowIdName: String?) -> Set? { let matchedRowIds = expressions.compactMap { $0.matchedRowIds(rowIdName: rowIdName) @@ -357,10 +326,6 @@ struct SQLExpressionOr : SQLExpression { return SQLExpressionOr(expressions.map { $0.qualifiedExpression(with: alias) }) } - func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression { - return SQLExpressionOr(expressions.map { $0.resolvedExpression(inContext: context) }) - } - func matchedRowIds(rowIdName: String?) -> Set? { if expressions.isEmpty { return [] @@ -423,10 +388,6 @@ struct SQLExpressionEqual: SQLExpression { return SQLExpressionEqual(op, lhs.qualifiedExpression(with: alias), rhs.qualifiedExpression(with: alias)) } - func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression { - return SQLExpressionEqual(op, lhs.resolvedExpression(inContext: context), rhs.resolvedExpression(inContext: context)) - } - func matchedRowIds(rowIdName: String?) -> Set? { // FIXME: this implementation ignores column aliases switch op { @@ -495,10 +456,6 @@ struct SQLExpressionContains : SQLExpression { return SQLExpressionContains(expression.qualifiedExpression(with: alias), collection, negated: isNegated) } - func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression { - return SQLExpressionContains(expression.resolvedExpression(inContext: context), collection, negated: isNegated) - } - func matchedRowIds(rowIdName: String?) -> Set? { // FIXME: this implementation ignores column aliases // Look for `id IN (1, 2, 3)` @@ -569,14 +526,6 @@ struct SQLExpressionBetween : SQLExpression { upperBound.qualifiedExpression(with: alias), negated: isNegated) } - - func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression { - return SQLExpressionBetween( - expression.resolvedExpression(inContext: context), - lowerBound.resolvedExpression(inContext: context), - upperBound.resolvedExpression(inContext: context), - negated: isNegated) - } } // MARK: - SQLExpressionFunction @@ -655,12 +604,6 @@ public struct SQLExpressionFunction : SQLExpression { public func qualifiedExpression(with alias: TableAlias) -> SQLExpression { return SQLExpressionFunction(functionName, arguments: arguments.map { $0.qualifiedExpression(with: alias) }) } - - /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) - /// :nodoc: - public func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression { - return SQLExpressionFunction(functionName, arguments: arguments.map { $0.resolvedExpression(inContext: context) }) - } } // MARK: - SQLExpressionCount @@ -684,10 +627,6 @@ struct SQLExpressionCount : SQLExpression { func qualifiedExpression(with alias: TableAlias) -> SQLExpression { return SQLExpressionCount(counted.qualifiedSelectable(with: alias)) } - - func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression { - return self - } } // MARK: - SQLExpressionCountDistinct @@ -710,10 +649,6 @@ struct SQLExpressionCountDistinct : SQLExpression { func qualifiedExpression(with alias: TableAlias) -> SQLExpression { return SQLExpressionCountDistinct(counted.qualifiedExpression(with: alias)) } - - func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression { - return self - } } // MARK: - SQLExpressionIsEmpty @@ -746,10 +681,6 @@ struct SQLExpressionIsEmpty : SQLExpression { func qualifiedExpression(with alias: TableAlias) -> SQLExpression { return SQLExpressionIsEmpty(countExpression.qualifiedExpression(with: alias), isEmpty: isEmpty) } - - func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression { - return SQLExpressionIsEmpty(countExpression.resolvedExpression(inContext: context), isEmpty: isEmpty) - } } // MARK: - TableMatchExpression @@ -767,12 +698,6 @@ struct TableMatchExpression: SQLExpression { alias: self.alias, pattern: pattern.qualifiedExpression(with: alias)) } - - func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression { - return TableMatchExpression( - alias: alias, - pattern: pattern.resolvedExpression(inContext: context)) - } } // MARK: - SQLExpressionCollate @@ -802,8 +727,4 @@ struct SQLExpressionCollate : SQLExpression { func qualifiedExpression(with alias: TableAlias) -> SQLExpression { return SQLExpressionCollate(expression.qualifiedExpression(with: alias), collationName: collationName) } - - func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression { - return SQLExpressionCollate(expression.resolvedExpression(inContext: context), collationName: collationName) - } } diff --git a/GRDB/QueryInterface/SQLExpression.swift b/GRDB/QueryInterface/SQL/SQLExpression.swift similarity index 92% rename from GRDB/QueryInterface/SQLExpression.swift rename to GRDB/QueryInterface/SQL/SQLExpression.swift index 4d491ebca..ff235ed34 100644 --- a/GRDB/QueryInterface/SQLExpression.swift +++ b/GRDB/QueryInterface/SQL/SQLExpression.swift @@ -48,9 +48,6 @@ public protocol SQLExpression : SQLSpecificExpressible, SQLSelectable, SQLOrderi /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) func qualifiedExpression(with alias: TableAlias) -> SQLExpression - - /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) - func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression } extension SQLExpression { @@ -147,8 +144,4 @@ struct SQLExpressionNot : SQLExpression { func qualifiedExpression(with alias: TableAlias) -> SQLExpression { return SQLExpressionNot(expression.qualifiedExpression(with: alias)) } - - func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression { - return SQLExpressionNot(expression.resolvedExpression(inContext: context)) - } } diff --git a/GRDB/QueryInterface/Association/ForeignKeyRequest.swift b/GRDB/QueryInterface/SQL/SQLForeignKeyRequest.swift similarity index 85% rename from GRDB/QueryInterface/Association/ForeignKeyRequest.swift rename to GRDB/QueryInterface/SQL/SQLForeignKeyRequest.swift index 268503c9d..8514256da 100644 --- a/GRDB/QueryInterface/Association/ForeignKeyRequest.swift +++ b/GRDB/QueryInterface/SQL/SQLForeignKeyRequest.swift @@ -1,11 +1,11 @@ -/// ForeignKeyRequest looks for the foreign keys associations need to +/// SQLForeignKeyRequest looks for the foreign keys associations need to /// join tables. /// /// Mappings come from foreign keys, when they exist in the database schema. /// /// When the schema does not define any foreign key, we can still infer complete /// mappings from partial information and primary keys. -struct ForeignKeyRequest: Equatable { +struct SQLForeignKeyRequest: Equatable { let originTable: String let destinationTable: String let originColumns: [String]? @@ -19,14 +19,15 @@ struct ForeignKeyRequest: Equatable { self.destinationColumns = foreignKey?.destinationColumns } - func fetch(_ db: Database) throws -> ForeignKeyInfo { + /// The (origin, destination) column pairs that join a left table to a right table. + func fetchMapping(_ db: Database) throws -> [(origin: String, destination: String)] { if let originColumns = originColumns, let destinationColumns = destinationColumns { // Total information: no need to query the database schema. GRDBPrecondition(originColumns.count == destinationColumns.count, "Number of columns don't match") let mapping = zip(originColumns, destinationColumns).map { (origin: $0, destination: $1) } - return ForeignKeyInfo(destinationTable: destinationTable, mapping: mapping) + return mapping } // Incomplete information: let's look for schema foreign keys @@ -56,7 +57,7 @@ struct ForeignKeyRequest: Equatable { if let foreignKey = foreignKeys.first { if foreignKeys.count == 1 { // Non-ambiguous - return foreignKey + return foreignKey.mapping } else { // Ambiguous: can't choose fatalError("Ambiguous foreign key from \(originTable) to \(destinationTable)") @@ -70,13 +71,10 @@ struct ForeignKeyRequest: Equatable { let mapping = zip(originColumns, destinationColumns).map { (origin: $0, destination: $1) } - return ForeignKeyInfo(destinationTable: destinationTable, mapping: mapping) + return mapping } } fatalError("Could not infer foreign key from \(originTable) to \(destinationTable)") } } - -/// The (origin, destination) column pairs that join a left table to a right table. -typealias ForeignKeyMapping = [(origin: String, destination: String)] diff --git a/GRDB/QueryInterface/Support/SQLFunctions.swift b/GRDB/QueryInterface/SQL/SQLFunctions.swift similarity index 96% rename from GRDB/QueryInterface/Support/SQLFunctions.swift rename to GRDB/QueryInterface/SQL/SQLFunctions.swift index 60f4f6575..e61af72fe 100644 --- a/GRDB/QueryInterface/Support/SQLFunctions.swift +++ b/GRDB/QueryInterface/SQL/SQLFunctions.swift @@ -1,6 +1,7 @@ // MARK: - Custom Functions extension DatabaseFunction { + // TODO: rename call (https://forums.swift.org/t/se-0253-callable-values-of-user-defined-nominal-types/24177) /// Returns an SQL expression that applies the function. /// /// See https://github.com/groue/GRDB.swift/#sql-functions @@ -187,7 +188,7 @@ extension SQLSpecificExpressible { /// let nameColumn = Column("name") /// let request = Player.select(nameColumn.localizedCapitalized) /// let names = try String.fetchAll(dbQueue, request) // [String] - @available(iOS 9.0, OSX 10.11, watchOS 3.0, *) + @available(OSX 10.11, watchOS 3.0, *) public var localizedCapitalized: SQLExpression { return DatabaseFunction.localizedCapitalize.apply(sqlExpression) } @@ -198,7 +199,7 @@ extension SQLSpecificExpressible { /// let nameColumn = Column("name") /// let request = Player.select(nameColumn.localizedLowercased) /// let names = try String.fetchAll(dbQueue, request) // [String] - @available(iOS 9.0, OSX 10.11, watchOS 3.0, *) + @available(OSX 10.11, watchOS 3.0, *) public var localizedLowercased: SQLExpression { return DatabaseFunction.localizedLowercase.apply(sqlExpression) } @@ -209,7 +210,7 @@ extension SQLSpecificExpressible { /// let nameColumn = Column("name") /// let request = Player.select(nameColumn.localizedUppercased) /// let names = try String.fetchAll(dbQueue, request) // [String] - @available(iOS 9.0, OSX 10.11, watchOS 3.0, *) + @available(OSX 10.11, watchOS 3.0, *) public var localizedUppercased: SQLExpression { return DatabaseFunction.localizedUppercase.apply(sqlExpression) } diff --git a/GRDB/QueryInterface/Support/SQLOperators.swift b/GRDB/QueryInterface/SQL/SQLOperators.swift similarity index 100% rename from GRDB/QueryInterface/Support/SQLOperators.swift rename to GRDB/QueryInterface/SQL/SQLOperators.swift diff --git a/GRDB/QueryInterface/SQLOrdering.swift b/GRDB/QueryInterface/SQL/SQLOrdering.swift similarity index 100% rename from GRDB/QueryInterface/SQLOrdering.swift rename to GRDB/QueryInterface/SQL/SQLOrdering.swift diff --git a/GRDB/QueryInterface/SQLSelectQuery.swift b/GRDB/QueryInterface/SQL/SQLQuery.swift similarity index 73% rename from GRDB/QueryInterface/SQLSelectQuery.swift rename to GRDB/QueryInterface/SQL/SQLQuery.swift index 15e62f6b0..3d0ba88f7 100644 --- a/GRDB/QueryInterface/SQLSelectQuery.swift +++ b/GRDB/QueryInterface/SQL/SQLQuery.swift @@ -1,58 +1,63 @@ -/// SQLSelectQuery is a representation of an SQL SELECT query. +/// SQLQuery is a representation of an SQL query. /// -/// See SQLSelectQueryGenerator for actual SQL generation. -struct SQLSelectQuery { +/// See SQLQueryGenerator for actual SQL generation. +struct SQLQuery { var relation: SQLRelation var isDistinct: Bool + var expectsSingleResult: Bool var groupPromise: DatabasePromise<[SQLExpression]>? var havingExpression: SQLExpression? var limit: SQLLimit? - + init( relation: SQLRelation, isDistinct: Bool = false, + expectsSingleResult: Bool = false, groupPromise: DatabasePromise<[SQLExpression]>? = nil, havingExpression: SQLExpression? = nil, limit: SQLLimit? = nil) { self.relation = relation self.isDistinct = isDistinct + self.expectsSingleResult = expectsSingleResult self.groupPromise = groupPromise self.havingExpression = havingExpression self.limit = limit } - - var alias: TableAlias? { - return relation.alias - } } -extension SQLSelectQuery: SelectionRequest, FilteredRequest, OrderedRequest { - func select(_ selection: [SQLSelectable]) -> SQLSelectQuery { +extension SQLQuery: SelectionRequest, FilteredRequest, OrderedRequest { + func select(_ selection: [SQLSelectable]) -> SQLQuery { return mapRelation { $0.select(selection) } } - func annotated(with selection: [SQLSelectable]) -> SQLSelectQuery { + func annotated(with selection: [SQLSelectable]) -> SQLQuery { return mapRelation { $0.annotated(with: selection) } } - func distinct() -> SQLSelectQuery { + func distinct() -> SQLQuery { var query = self query.isDistinct = true return query } + + func expectingSingleResult() -> SQLQuery { + var query = self + query.expectsSingleResult = true + return query + } - func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> SQLSelectQuery { + func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> SQLQuery { return mapRelation { $0.filter(predicate) } } - func group(_ expressions: @escaping (Database) throws -> [SQLExpressible]) -> SQLSelectQuery { + func group(_ expressions: @escaping (Database) throws -> [SQLExpressible]) -> SQLQuery { var query = self query.groupPromise = DatabasePromise { db in try expressions(db).map { $0.sqlExpression } } return query } - func having(_ predicate: SQLExpressible) -> SQLSelectQuery { + func having(_ predicate: SQLExpressible) -> SQLQuery { var query = self if let havingExpression = query.havingExpression { query.havingExpression = (havingExpression && predicate).sqlExpression @@ -62,50 +67,55 @@ extension SQLSelectQuery: SelectionRequest, FilteredRequest, OrderedRequest { return query } - func order(_ orderings: @escaping (Database) throws -> [SQLOrderingTerm]) -> SQLSelectQuery { + func order(_ orderings: @escaping (Database) throws -> [SQLOrderingTerm]) -> SQLQuery { return mapRelation { $0.order(orderings) } } - func reversed() -> SQLSelectQuery { + func reversed() -> SQLQuery { return mapRelation { $0.reversed() } } - func unordered() -> SQLSelectQuery { + func unordered() -> SQLQuery { return mapRelation { $0.unordered() } } - func limit(_ limit: Int, offset: Int? = nil) -> SQLSelectQuery { + func limit(_ limit: Int, offset: Int? = nil) -> SQLQuery { var query = self query.limit = SQLLimit(limit: limit, offset: offset) return query } - func qualified(with alias: TableAlias) -> SQLSelectQuery { + func qualified(with alias: TableAlias) -> SQLQuery { return mapRelation { $0.qualified(with: alias) } } /// Returns a query whose relation is transformed by the given closure. - func mapRelation(_ transform: (SQLRelation) -> SQLRelation) -> SQLSelectQuery { + func mapRelation(_ transform: (SQLRelation) -> SQLRelation) -> SQLQuery { var query = self query.relation = transform(relation) return query } } -extension SQLSelectQuery { +extension SQLQuery { func fetchCount(_ db: Database) throws -> Int { - let (statement, adapter) = try SQLSelectQueryGenerator(countQuery).prepare(db) + let (statement, adapter) = try SQLQueryGenerator(countQuery).prepare(db) return try Int.fetchOne(statement, adapter: adapter)! } - private var countQuery: SQLSelectQuery { + private var countQuery: SQLQuery { guard groupPromise == nil && limit == nil else { // SELECT ... GROUP BY ... // SELECT ... LIMIT ... return trivialCountQuery } - guard relation.joins.isEmpty, case .table = relation.source else { + if relation.children.contains(where: { $0.value.impactsParentCount }) { // TODO: not tested + // SELECT ... FROM ... JOIN ... + return trivialCountQuery + } + + guard case .table = relation.source else { // SELECT ... FROM (something which is not a plain table) return trivialCountQuery } @@ -139,11 +149,11 @@ extension SQLSelectQuery { } // SELECT COUNT(*) FROM (self) - private var trivialCountQuery: SQLSelectQuery { + private var trivialCountQuery: SQLQuery { let relation = SQLRelation( source: .query(unordered()), selection: [SQLExpressionCount(AllColumns())]) - return SQLSelectQuery(relation: relation) + return SQLQuery(relation: relation) } } diff --git a/GRDB/QueryInterface/SQL/SQLRelation.swift b/GRDB/QueryInterface/SQL/SQLRelation.swift new file mode 100644 index 000000000..dfc2c8479 --- /dev/null +++ b/GRDB/QueryInterface/SQL/SQLRelation.swift @@ -0,0 +1,809 @@ +/// A "relation", as defined by the [relational terminology](https://en.wikipedia.org/wiki/Relational_database#Terminology), +/// is "a set of tuples sharing the same attributes; a set of columns and rows." +/// +/// SQLRelation is defined with a selection, a source table of query, and an +/// eventual filter and ordering. +/// +/// SELECT ... FROM ... WHERE ... ORDER BY ... +/// | | | | +/// | | | • ordering +/// | | • filter +/// | • source +/// • selection +/// +/// Other SQL clauses such as GROUP BY, LIMIT are defined one level up, in the +/// SQLQuery type. +/// +/// ## Promises +/// +/// Filter and ordering are actually "promises", which are only resolved +/// when a database connection is available. This is how we can implement +/// requests such as `Record.filter(key: 1)` or `Record.orderByPrimaryKey()`: +/// both need a database connection in order to introspect the primary key. +/// +/// // SELECT * FROM player +/// // WHERE continent = 'EU' +/// // ORDER BY code -- primary key infered from the database schema +/// Country +/// .filter(Column("continent") == "EU") +/// .orderByPrimaryKey() +/// +/// ## Children +/// +/// Relations may also have children. A child is a link to another relation, and +/// provide support for joins and prefetched relations. +/// +/// Relations and their children constitute a tree of relations, which the user +/// builds with associations: +/// +/// // Builds a relation with two children: +/// Author +/// .including(required: Author.country) +/// .including(all: Author.books) +/// +/// There are four kinds of children: +/// +/// - `.oneOptional`: +/// +/// Such children are left joined. They may, or not, be included in +/// the selection. +/// +/// // SELECT book.* +/// // FROM book +/// // LEFT JOIN author ON author.id = book.id +/// Book.joining(optional: Book.author) +/// +/// // SELECT book.*, author.* +/// // FROM book +/// // LEFT JOIN author ON author.id = book.id +/// Book.including(optional: Book.author) +/// +/// - `.oneRequired`: +/// +/// Such children are inner joined. They may, or not, be included in +/// the selection. +/// +/// // SELECT book.* +/// // FROM book +/// // JOIN author ON author.id = book.id AND author.country = 'FR' +/// Book.joining(required: Book.author.filter(Column("country") == "FR")) +/// +/// // SELECT book.*, author.* +/// // FROM book +/// // JOIN author ON author.id = book.id AND author.country = 'FR' +/// Book.including(required: Book.author.filter(Column("country") == "FR")) +/// +/// - `.allPrefetched`: +/// +/// Such children are prefetched using several SQL requests: +/// +/// // SELECT * FROM countries WHERE continent = 'EU' +/// // SELECT * FROM passport WHERE countryCode IN ('BE', 'DE', 'FR', ...) +/// Country +/// .filter(Column("continent") == "EU") +/// .including(all: Country.passports) +/// +/// - `.allNotPrefetched`: +/// +/// Such children are not joined, and not prefetched. They are used as +/// intermediate children towards a prefetched child. In the example +/// below, the country relation has a `.allNotPrefetched` child to +/// passports, and the passport relation has a `.allPrefetched` child +/// to citizens. +/// +/// // SELECT * FROM countries WHERE continent = 'EU' +/// // SELECT citizens.* FROM citizens +/// // JOIN passport ON passport.citizenId = citizens.id +/// // AND passport.countryCode IN ('BE', 'DE', 'FR', ...) +/// Country +/// .filter(Column("continent") == "EU") +/// .including(all: Country.citizens) +struct SQLRelation { + struct Child { + enum Kind { + // Record.including(optional: association) + case oneOptional + // Record.including(required: association) + case oneRequired + // Record.including(all: association) + case allPrefetched + // Record.including(all: associationThroughPivot) + case allNotPrefetched + + var cardinality: SQLAssociationCardinality { + switch self { + case .oneOptional, .oneRequired: + return .toOne + case .allPrefetched, .allNotPrefetched: + return .toMany + } + } + } + + var kind: Kind + var condition: SQLAssociationCondition + var relation: SQLRelation + + /// Returns true iff this child can change the parent count. + /// + /// Record.including(required: association) // true + /// Record.including(all: association) // false + var impactsParentCount: Bool { + switch kind { + case .oneOptional, .oneRequired: + return true + case .allPrefetched, .allNotPrefetched: + return false + } + } + + fileprivate func makeAssociationForKey(_ key: String) -> SQLAssociation { + let key = SQLAssociationKey.fixed(key) + return SQLAssociation( + key: key, + condition: condition, + relation: relation, + cardinality: kind.cardinality) + } + + func mapRelation(_ transform: (SQLRelation) -> SQLRelation) -> Child { + return Child(kind: kind, condition: condition, relation: transform(relation)) + } + } + + var source: SQLSource + var selection: [SQLSelectable] + var filterPromise: DatabasePromise + var ordering: SQLRelation.Ordering + var children: OrderedDictionary + + var prefetchedAssociations: [SQLAssociation] { + return children.flatMap { key, child -> [SQLAssociation] in + switch child.kind { + case .allPrefetched: + return [child.makeAssociationForKey(key)] + case .oneOptional, .oneRequired, .allNotPrefetched: + return child.relation.prefetchedAssociations.map { + $0.through(child.makeAssociationForKey(key)) + } + } + } + } + + init( + source: SQLSource, + selection: [SQLSelectable] = [], + filterPromise: DatabasePromise = DatabasePromise(value: nil), + ordering: SQLRelation.Ordering = SQLRelation.Ordering(), + children: OrderedDictionary = [:]) + { + self.source = source + self.selection = selection + self.filterPromise = filterPromise + self.ordering = ordering + self.children = children + } +} + +extension SQLRelation { + func select(_ selection: [SQLSelectable]) -> SQLRelation { + var relation = self + relation.selection = selection + return relation + } + + func annotated(with selection: [SQLSelectable]) -> SQLRelation { + var relation = self + relation.selection.append(contentsOf: selection) + return relation + } + + func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> SQLRelation { + var relation = self + relation.filterPromise = relation.filterPromise.flatMap { filter in + if let filter = filter { + return DatabasePromise { try filter && predicate($0) } + } else { + return DatabasePromise { try predicate($0).sqlExpression } + } + } + return relation + } + + func order(_ orderings: @escaping (Database) throws -> [SQLOrderingTerm]) -> SQLRelation { + return order(SQLRelation.Ordering(orderings: orderings)) + } + + func reversed() -> SQLRelation { + return order(ordering.reversed) + } + + func unordered() -> SQLRelation { + var relation = self + relation.ordering = SQLRelation.Ordering() + relation.children = relation.children.mapValues { $0.mapRelation { $0.unordered() } } + return relation + } + + private func order(_ ordering: SQLRelation.Ordering) -> SQLRelation { + var relation = self + relation.ordering = ordering + return relation + } + + func qualified(with alias: TableAlias) -> SQLRelation { + var relation = self + relation.source = source.qualified(with: alias) + return relation + } +} + +extension SQLRelation { + func deletingChildren() -> SQLRelation { + var relation = self + relation.children = [:] + return relation + } + + /// Creates a relation that prefetches another one. + func including(all association: SQLAssociation) -> SQLRelation { + return appending(association, kind: .allPrefetched) + } + + /// Creates a relation that includes another one. The columns of the + /// associated record are selected. The returned relation does not + /// require that the associated database table contains a matching row. + func including(optional association: SQLAssociation) -> SQLRelation { + return appending(association, kind: .oneOptional) + } + + /// Creates a relation that includes another one. The columns of the + /// associated record are selected. The returned relation requires + /// that the associated database table contains a matching row. + func including(required association: SQLAssociation) -> SQLRelation { + return appending(association, kind: .oneRequired) + } + + /// Creates a relation that joins another one. The columns of the + /// associated record are not selected. The returned relation does not + /// require that the associated database table contains a matching row. + func joining(optional association: SQLAssociation) -> SQLRelation { + return appending(association.mapDestinationRelation { $0.select([]) }, kind: .oneOptional) + } + + /// Creates a relation that joins another one. The columns of the + /// associated record are not selected. The returned relation requires + /// that the associated database table contains a matching row. + func joining(required association: SQLAssociation) -> SQLRelation { + return appending(association.mapDestinationRelation { $0.select([]) }, kind: .oneRequired) + } + + /// Returns a relation extended with an association. + /// + /// This method provides support for public joining methods such + /// as `including(required:)`: + /// + /// struct Destination: TableRecord { } + /// struct Origin: TableRecord { + /// static let destination = belongsTo(Destination.self) + /// } + /// + /// // SELECT origin.*, destination.* + /// // FROM origin + /// // JOIN destination ON destination.id = origin.destinationId + /// let request = Origin.including(required: Origin.destination) + /// + /// At low-level, this gives: + /// + /// let sqlAssociation = Origin.destination.sqlAssociation + /// let origin = Origin.all().query.relation + /// let relation = origin.appending(sqlAssociation, kind: .oneRequired) + /// let query = SQLQuery(relation: relation) + /// let generator = SQLQueryGenerator(query) + /// let statement, _ = try generator.prepare(db) + /// print(statement.sql) + /// // SELECT origin.*, destination.* + /// // FROM origin + /// // JOIN destination ON destination.originId = origin.id + /// + /// This method works for simple direct associations such as BelongsTo or + /// HasMany in the above examples, but also for indirect associations such + /// as HasManyThrough, which have any number of pivot relations between the + /// origin and the destination. + func appending(_ association: SQLAssociation, kind: SQLRelation.Child.Kind) -> SQLRelation { + let destinationChildKey = association.destination.key.name(for: kind.cardinality) + let destinationChild = SQLRelation.Child( + kind: kind, + condition: association.destination.condition, + relation: association.destination.relation) + + let initialSteps = association.steps.dropLast() + if initialSteps.isEmpty { + // This is a direct join from origin to destination, without + // intermediate step. + // + // SELECT origin.*, destination.* + // FROM origin + // JOIN destination ON destination.id = origin.destinationId + // + // let association = Origin.belongsTo(Destination.self) + // Origin.including(required: association) + return appendingChild(destinationChild, forKey: destinationChildKey) + } + + // This is an indirect join from origin to destination, through + // some pivot(s): + // + // SELECT origin.*, destination.* + // FROM origin + // JOIN pivot ON pivot.originId = origin.id + // JOIN destination ON destination.id = pivot.destinationId + // + // let association = Origin.hasMany( + // Destination.self, + // through: Origin.hasMany(Pivot.self), + // via: Pivot.belongsTo(Destination.self)) + // Origin.including(required: association) + // + // Let's recurse toward a direct join, by making a new association which + // ends on the last pivot, to which we join our destination: + var reducedAssociation = SQLAssociation(steps: Array(initialSteps)) + + reducedAssociation.destination.relation = reducedAssociation.destination.relation + .select([]) // Intermediate steps are not prefetched + .appendingChild(destinationChild, forKey: destinationChildKey) + + switch kind { + case .oneRequired, .oneOptional, .allNotPrefetched: + return appending(reducedAssociation, kind: kind) + case .allPrefetched: + // Intermediate steps of indirect associations are not prefetched. + // + // For example, the request below prefetches citizens, not + // intermediate passports: + // + // extension Country { + // static let passports = hasMany(Passport.self) + // static let citizens = hasMany(Citizens.self, through: passports, using: Passport.citizen) + // } + // let request = Country.including(all: Country.citizens) + return appending(reducedAssociation, kind: .allNotPrefetched) + } + } + + private func appendingChild(_ child: SQLRelation.Child, forKey key: String) -> SQLRelation { + var relation = self + if let existingChild = relation.children.removeValue(forKey: key) { + guard let mergedChild = existingChild.merged(with: child) else { + // can't merge + fatalError("The association key \"\(key)\" is ambiguous. Use the Association.forKey(_:) method is order to disambiguate.") + } + relation.children.appendValue(mergedChild, forKey: key) + } else { + relation.children.appendValue(child, forKey: key) + } + return relation + } +} + +// MARK: - SQLSource + +enum SQLSource { + case table(tableName: String, alias: TableAlias?) + indirect case query(SQLQuery) + + func qualified(with alias: TableAlias) -> SQLSource { + switch self { + case .table(let tableName, let sourceAlias): + if let sourceAlias = sourceAlias { + alias.becomeProxy(of: sourceAlias) + return self + } else { + alias.setTableName(tableName) + return .table(tableName: tableName, alias: alias) + } + case .query(let query): + return .query(query.qualified(with: alias)) + } + } +} + +// MARK: - SQLRelation.Ordering + +extension SQLRelation { + /// SQLRelation.Ordering provides the order clause to SQLRelation. + struct Ordering { + private enum Element { + case terms(DatabasePromise<[SQLOrderingTerm]>) + case ordering(SQLRelation.Ordering) + + var reversed: Element { + switch self { + case .terms(let terms): + return .terms(terms.map { $0.map { $0.reversed } }) + case .ordering(let ordering): + return .ordering(ordering.reversed) + } + } + + func qualified(with alias: TableAlias) -> Element { + switch self { + case .terms(let terms): + return .terms(terms.map { $0.map { $0.qualifiedOrdering(with: alias) } }) + case .ordering(let ordering): + return .ordering(ordering.qualified(with: alias)) + } + } + + func resolve(_ db: Database) throws -> [SQLOrderingTerm] { + switch self { + case .terms(let terms): + return try terms.resolve(db) + case .ordering(let ordering): + return try ordering.resolve(db) + } + } + } + + private var elements: [Element] = [] + var isReversed: Bool + + var isEmpty: Bool { + return elements.isEmpty + } + + private init(elements: [Element], isReversed: Bool) { + self.elements = elements + self.isReversed = isReversed + } + + init() { + self.init( + elements: [], + isReversed: false) + } + + init(orderings: @escaping (Database) throws -> [SQLOrderingTerm]) { + self.init( + elements: [.terms(DatabasePromise(orderings))], + isReversed: false) + } + + var reversed: Ordering { + return Ordering( + elements: elements, + isReversed: !isReversed) + } + + func qualified(with alias: TableAlias) -> Ordering { + return Ordering( + elements: elements.map { $0.qualified(with: alias) }, + isReversed: isReversed) + } + + func appending(_ ordering: Ordering) -> Ordering { + return Ordering( + elements: elements + [.ordering(ordering)], + isReversed: isReversed) + } + + func resolve(_ db: Database) throws -> [SQLOrderingTerm] { + if isReversed { + return try elements.flatMap { try $0.reversed.resolve(db) } + } else { + return try elements.flatMap { try $0.resolve(db) } + } + } + } +} + +// MARK: - SQLAssociationCondition + +/// The condition that links two tables. +/// +/// Currently, we only support one kind of condition: foreign keys. +/// +/// SELECT ... FROM book JOIN author ON author.id = book.authorId +/// <---- the condition ----> +/// +/// When we eventually add support for new ways to link tables, +/// SQLAssociationCondition is the type we'll need to update. +/// +/// SQLAssociationCondition adopts Equatable so that we can merge associations: +/// +/// // request1 and request2 are equivalent +/// let request1 = Book +/// .including(required: Book.author) +/// let request2 = Book +/// .including(required: Book.author) +/// .including(required: Book.author) +/// +/// // request3 and request4 are equivalent +/// let request3 = Book +/// .including(required: Book.author.filter(condition1 && condition2)) +/// let request4 = Book +/// .joining(required: Book.author.filter(condition1)) +/// .including(optional: Book.author.filter(condition2)) +struct SQLAssociationCondition: Equatable { + /// Definition of a foreign key + var foreignKeyRequest: SQLForeignKeyRequest + + /// True if the table at the origin of the foreign key is on the left of + /// the sql JOIN operator. + /// + /// Let's consider the `book.authorId -> author.id` foreign key. + /// Its origin table is `book`. + /// + /// The origin table `book` is on the left of the JOIN operator for + /// the BelongsTo association: + /// + /// -- Book.including(required: Book.author) + /// SELECT ... FROM book JOIN author ON author.id = book.authorId + /// + /// The origin table `book`is on the right of the JOIN operator for + /// the HasMany and HasOne associations: + /// + /// -- Author.including(required: Author.books) + /// SELECT ... FROM author JOIN book ON author.id = book.authorId + var originIsLeft: Bool + + var reversed: SQLAssociationCondition { + return SQLAssociationCondition( + foreignKeyRequest: foreignKeyRequest, + originIsLeft: !originIsLeft) + } + + /// Orient foreignKey according to the originIsLeft flag + func columnMappings(_ db: Database) throws -> [(left: String, right: String)] { + let foreignKeyMapping = try foreignKeyRequest.fetchMapping(db) + if originIsLeft { + return foreignKeyMapping.map { (left: $0.origin, right: $0.destination) } + } else { + return foreignKeyMapping.map { (left: $0.destination, right: $0.origin) } + } + } + + /// Resolves the condition into an SQL expression which involves both left + /// and right tables. + /// + /// SELECT * FROM left JOIN right ON (right.a = left.b) + /// <----------------> + /// + /// - parameter db: A database connection. + /// - parameter leftAlias: A TableAlias for the table on the left of the + /// JOIN operator. + /// - parameter rightAlias: A TableAlias for the table on the right of the + /// JOIN operator. + /// - Returns: An SQL expression. + func joinExpression(_ db: Database, leftAlias: TableAlias, rightAlias: TableAlias) throws -> SQLExpression { + return try columnMappings(db) + .map { QualifiedColumn($0.right, alias: rightAlias) == QualifiedColumn($0.left, alias: leftAlias) } + .joined(operator: .and) + } + + /// Resolves the condition into an SQL expression which involves only the + /// right table. + /// + /// Given `right.a = left.b`, returns `right.a = 1` or + /// `right.a IN (1, 2, 3)`. + func filteringExpression(_ db: Database, leftRows: [Row], rightAlias: TableAlias) throws -> SQLExpression { + if leftRows.isEmpty { + // Degenerate case: there is no row to attach + return false.sqlExpression + } + + let columnMappings = try self.columnMappings(db) + guard let columnMapping = columnMappings.first else { + // Degenerate case: no joining column + return true.sqlExpression + } + + if columnMappings.count == 1 { + // Join on a single right column. + let rightColumn = QualifiedColumn(columnMapping.right, alias: rightAlias) + + // Unique database values and filter out NULL: + var dbValues = Set(leftRows.map { $0[columnMapping.left] as DatabaseValue }) + dbValues.remove(.null) + + if dbValues.isEmpty { + // Can't join + return false.sqlExpression + } else { + // table.a IN (1, 2, 3, ...) + // Sort database values for nicer output. + return dbValues.sorted(by: <).contains(rightColumn) + } + } else { + // Join on a multiple columns. + // ((table.a = 1) AND (table.b = 2)) OR ((table.a = 3) AND (table.b = 4)) ... + return leftRows + .map { leftRow in + // (table.a = 1) AND (table.b = 2) + columnMappings + .map { columns -> SQLExpression in + let rightColumn = QualifiedColumn(columns.right, alias: rightAlias) + let leftValue = leftRow[columns.left] as DatabaseValue + return rightColumn == leftValue + } + .joined(operator: .and) + } + .joined(operator: .or) + } + } +} + +// MARK: - Merging +// +// "Merging" is an operation that takes two relations and, if they are +// compatible, gathers them into a merged relation. +// +// It is an important feature that allows the user to define associated requests +// in several steps. For example, in the sample code below, both requests are +// equivalent and generate the same SQL query, thanks to merging: +// +// let request1 = Book.including(required: Book.author) +// +// let request2 = Book +// .including(required: Book.author) +// .including(required: Book.author) + +extension SQLRelation { + /// Returns nil if relations can't be merged (conflict in source, joins...) + func merged(with other: SQLRelation) -> SQLRelation? { + guard let mergedSource = source.merged(with: other.source) else { + // can't merge + return nil + } + + let mergedFilterPromise: DatabasePromise = filterPromise.flatMap { expression in + return DatabasePromise { db in + let otherExpression = try other.filterPromise.resolve(db) + let expressions = [expression, otherExpression].compactMap { $0 } + if expressions.isEmpty { + return nil + } else { + return expressions.joined(operator: .and) + } + } + } + + var mergedChildren: OrderedDictionary = [:] + for (key, child) in children { + if let otherChild = other.children[key] { + guard let mergedChild = child.merged(with: otherChild) else { + // can't merge + return nil + } + mergedChildren.appendValue(mergedChild, forKey: key) + } else { + mergedChildren.appendValue(child, forKey: key) + } + } + for (key, child) in other.children where mergedChildren[key] == nil { + mergedChildren.appendValue(child, forKey: key) + } + + // replace selection unless empty + let mergedSelection = other.selection.isEmpty ? selection : other.selection + + // replace ordering unless empty + let mergedOrdering = other.ordering.isEmpty ? ordering : other.ordering + + return SQLRelation( + source: mergedSource, + selection: mergedSelection, + filterPromise: mergedFilterPromise, + ordering: mergedOrdering, + children: mergedChildren) + } +} + +extension SQLSource { + /// Returns nil if sources can't be merged (conflict in tables, aliases...) + func merged(with other: SQLSource) -> SQLSource? { + switch (self, other) { + case let (.table(tableName: tableName, alias: alias), .table(tableName: otherTableName, alias: otherAlias)): + guard tableName == otherTableName else { + // can't merge + return nil + } + switch (alias, otherAlias) { + case (nil, nil): + return .table(tableName: tableName, alias: nil) + case let (alias?, nil), let (nil, alias?): + return .table(tableName: tableName, alias: alias) + case let (alias?, otherAlias?): + guard let mergedAlias = alias.merged(with: otherAlias) else { + // can't merge + return nil + } + return .table(tableName: tableName, alias: mergedAlias) + } + default: + // can't merge + return nil + } + } +} + +extension SQLRelation.Child { + /// Returns nil if joins can't be merged (conflict in condition, relation...) + func merged(with other: SQLRelation.Child) -> SQLRelation.Child? { + guard condition == other.condition else { + // can't merge + return nil + } + + guard let mergedRelation = relation.merged(with: other.relation) else { + // can't merge + return nil + } + + guard let mergedKind = kind.merged(with: other.kind) else { + // can't merge + return nil + } + + return SQLRelation.Child( + kind: mergedKind, + condition: condition, + relation: mergedRelation) + } +} + +extension SQLRelation.Child.Kind { + /// Returns nil if kinds can't be merged + func merged(with other: SQLRelation.Child.Kind) -> SQLRelation.Child.Kind? { + switch (self, other) { + case (.oneRequired, .oneRequired), + (.oneRequired, .oneOptional), + (.oneOptional, .oneRequired): + // Equivalent to Record.including(required: association): + // + // Record + // .including(required: association) + // .including(optional: association) + return .oneRequired + + case (.oneOptional, .oneOptional): + // Equivalent to Record.including(optional: association): + // + // Record + // .including(optional: association) + // .including(optional: association) + return .oneOptional + + case (.allPrefetched, .allPrefetched): + // Equivalent to Record.including(all: association): + // + // Record + // .including(all: association) + // .including(all: association) + return .allPrefetched + + case (.allPrefetched, .allNotPrefetched), + (.allNotPrefetched, .allPrefetched): + // Record + // .including(all: associationToDestinationThroughPivot) + // .including(all: associationToPivot) + fatalError("Not implemented: merging a direct association and an indirect one with including(all:)") + + case (.allNotPrefetched, .allNotPrefetched): + // Equivalent to Record.including(all: association) + // + // Record + // .including(all: association) + // .including(all: association) + return .allNotPrefetched + + default: + // Likely a programmer error: + // + // Record + // .including(all: Author.books.forKey("foo")) + // .including(optional: Author.books.forKey("foo")) + return nil + } + } +} diff --git a/GRDB/QueryInterface/SQLSelectable+QueryInterface.swift b/GRDB/QueryInterface/SQL/SQLSelectable+QueryInterface.swift similarity index 100% rename from GRDB/QueryInterface/SQLSelectable+QueryInterface.swift rename to GRDB/QueryInterface/SQL/SQLSelectable+QueryInterface.swift diff --git a/GRDB/QueryInterface/SQLSelectable.swift b/GRDB/QueryInterface/SQL/SQLSelectable.swift similarity index 83% rename from GRDB/QueryInterface/SQLSelectable.swift rename to GRDB/QueryInterface/SQL/SQLSelectable.swift index bbc0e43a9..cc492f4bb 100644 --- a/GRDB/QueryInterface/SQLSelectable.swift +++ b/GRDB/QueryInterface/SQL/SQLSelectable.swift @@ -26,23 +26,19 @@ public protocol SQLSelectable { // MARK: - SQLSelectionLiteral struct SQLSelectionLiteral : SQLSelectable { - let sql: String - let arguments: StatementArguments? + private let sqlLiteral: SQLLiteral - init(_ sql: String, arguments: StatementArguments? = nil) { - self.sql = sql - self.arguments = arguments + init(literal sqlLiteral: SQLLiteral) { + self.sqlLiteral = sqlLiteral } func resultColumnSQL(_ context: inout SQLGenerationContext) -> String { - if let arguments = arguments { - if context.appendArguments(arguments) == false { - // GRDB limitation: we don't know how to look for `?` in sql and - // replace them with with literals. - fatalError("Not implemented") - } + if context.append(arguments: sqlLiteral.arguments) == false { + // GRDB limitation: we don't know how to look for `?` in sql and + // replace them with with literals. + fatalError("Not implemented") } - return sql + return sqlLiteral.sql } func countedSQL(_ context: inout SQLGenerationContext) -> String { diff --git a/GRDB/QueryInterface/SQLSpecificExpressible+QueryInterface.swift b/GRDB/QueryInterface/SQL/SQLSpecificExpressible+QueryInterface.swift similarity index 100% rename from GRDB/QueryInterface/SQLSpecificExpressible+QueryInterface.swift rename to GRDB/QueryInterface/SQL/SQLSpecificExpressible+QueryInterface.swift diff --git a/GRDB/QueryInterface/SQLGenerationContext.swift b/GRDB/QueryInterface/SQLGeneration/SQLGenerationContext.swift similarity index 90% rename from GRDB/QueryInterface/SQLGenerationContext.swift rename to GRDB/QueryInterface/SQLGeneration/SQLGenerationContext.swift index 6a42c4790..60d5f4a1b 100644 --- a/GRDB/QueryInterface/SQLGenerationContext.swift +++ b/GRDB/QueryInterface/SQLGeneration/SQLGenerationContext.swift @@ -5,11 +5,12 @@ /// /// :nodoc: public struct SQLGenerationContext { - private(set) var arguments: StatementArguments? + var arguments: StatementArguments? private var resolvedNames: [TableAlias: String] private var qualifierNeeded: Bool /// Used for SQLExpression -> SQLExpressionLiteral conversion + /// and SQLInterpolation static func literalGenerationContext(withArguments: Bool) -> SQLGenerationContext { return SQLGenerationContext( arguments: withArguments ? [] : nil, @@ -17,8 +18,14 @@ public struct SQLGenerationContext { qualifierNeeded: false) } - /// Used for SQLSelectQuery.makeSelectStatement() and SQLSelectQuery.makeDeleteStatement() + /// Used for SQLQuery.makeSelectStatement() and SQLQuery.makeDeleteStatement() static func queryGenerationContext(aliases: [TableAlias]) -> SQLGenerationContext { + // TODO: since 5d9fa76, in the lines below, we started uniquing aliases. + // Something tells me this is a wrong fix. We should try to investigate + // and maybe revert this change. I don't see why we'd really need to + // unique aliases, and I'm afraid we're hiding some latent bug + // somewhere else. + // Unique aliases, but with preserved ordering, so that we have stable SQL generation let uniqueAliases = aliases.reduce(into: [TableAlias]()) { if !$0.contains($1) { @@ -32,7 +39,7 @@ public struct SQLGenerationContext { } /// Used for TableRecord.selectionSQL - static func recordSelectionGenerationContext(alias: TableAlias) -> SQLGenerationContext { + static func recordSelectionGenerationContext() -> SQLGenerationContext { return SQLGenerationContext( arguments: nil, resolvedNames: [:], @@ -40,7 +47,10 @@ public struct SQLGenerationContext { } /// Returns whether arguments could be appended - mutating func appendArguments(_ newArguments: StatementArguments) -> Bool { + mutating func append(arguments newArguments: StatementArguments) -> Bool { + if newArguments.isEmpty { + return true + } guard let arguments = arguments else { return false } @@ -271,17 +281,10 @@ public class TableAlias: Hashable { return expression.qualifiedExpression(with: self) } - #if swift(>=4.2) /// :nodoc: public func hash(into hasher: inout Hasher) { hasher.combine(ObjectIdentifier(root)) } - #else - /// :nodoc: - public var hashValue: Int { - return ObjectIdentifier(root).hashValue - } - #endif /// :nodoc: public static func == (lhs: TableAlias, rhs: TableAlias) -> Bool { @@ -312,7 +315,7 @@ extension Array where Element == TableAlias { for (lowercaseName, group) in groups { if group.count > 1 { // It is a programmer error to reuse the same alias for multiple tables - GRDBPrecondition(group.filter({ $0.hasUserName }).count < 2, "ambiguous alias: \(group[0].identityName)") + GRDBPrecondition(group.count { $0.hasUserName } < 2, "ambiguous alias: \(group[0].identityName)") ambiguousGroups.append(group) } else { uniqueLowercaseNames.insert(lowercaseName) @@ -324,7 +327,7 @@ extension Array where Element == TableAlias { var index = 1 for alias in group { if alias.hasUserName { continue } - let radical = alias.identityName.databaseQualifierRadical + let radical = alias.identityName.digitlessRadical var resolvedName: String repeat { resolvedName = "\(radical)\(index)" @@ -337,17 +340,3 @@ extension Array where Element == TableAlias { return resolvedNames } } - -extension String { - /// "bar" => "bar" - /// "foo12" => "foo" - var databaseQualifierRadical: String { - let digits: ClosedRange = "0"..."9" - let radicalEndIndex = self // "foo12" - .reversed() // "21oof" - .prefix(while: { digits.contains($0) }) // "21" - .endIndex // reversed(foo^12) - .base // foo^12 - return String(prefix(upTo: radicalEndIndex)) - } -} diff --git a/GRDB/QueryInterface/SQLSelectQueryGenerator.swift b/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift similarity index 84% rename from GRDB/QueryInterface/SQLSelectQueryGenerator.swift rename to GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift index 977786d19..e40a98579 100644 --- a/GRDB/QueryInterface/SQLSelectQueryGenerator.swift +++ b/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift @@ -1,12 +1,12 @@ -/// SQLSelectQueryGenerator is able to generate an SQL SELECT query. -struct SQLSelectQueryGenerator { +/// SQLQueryGenerator is able to generate an SQL SELECT query. +struct SQLQueryGenerator { fileprivate let relation: SQLQualifiedRelation private let isDistinct: Bool private let groupPromise: DatabasePromise<[SQLExpression]>? private let havingExpression: SQLExpression? private let limit: SQLLimit? - init(_ query: SQLSelectQuery) { + init(_ query: SQLQuery) { // To generate SQL, we need a "qualified" relation, where all tables, // expressions, etc, are identified with table aliases. // @@ -57,7 +57,7 @@ struct SQLSelectQueryGenerator { sql += try " FROM " + relation.source.sql(db, &context) for (_, join) in relation.joins { - sql += try " " + join.sql(db, &context, leftAlias: relation.alias, isRequiredAllowed: true) + sql += try " " + join.sql(db, &context, leftAlias: relation.alias) } if let filter = try relation.filterPromise.resolve(db) { @@ -163,7 +163,7 @@ struct SQLSelectQueryGenerator { } } - let statement = try db.makeUpdateStatement(sql) + let statement = try db.makeUpdateStatement(sql: sql) statement.arguments = context.arguments! return statement } @@ -179,7 +179,7 @@ struct SQLSelectQueryGenerator { let sql = try self.sql(db, &context) // Compile & set arguments - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) statement.arguments = context.arguments! // not nil for this kind of context return statement } @@ -215,11 +215,21 @@ struct SQLSelectQueryGenerator { } /// A "qualified" relation, where all tables are identified with a table alias. +/// +/// SELECT ... FROM ... AS ... JOIN ... WHERE ... ORDER BY ... +/// | | | | | | +/// | | | | | • ordering +/// | | | | • filterPromise +/// | | | • joins +/// | | • alias +/// | • source +/// • fullSelection private struct SQLQualifiedRelation { /// The alias for the relation /// /// SELECT ... FROM ... AS ... JOIN ... WHERE ... ORDER BY ... - /// ^ alias + /// | + /// • alias let alias: TableAlias /// All aliases, including aliases of joined relations @@ -235,7 +245,8 @@ private struct SQLQualifiedRelation { /// The source /// /// SELECT ... FROM ... AS ... JOIN ... WHERE ... ORDER BY ... - /// ^ source + /// | + /// • source let source: SQLQualifiedSource /// The selection, not including selection of joined relations @@ -244,7 +255,8 @@ private struct SQLQualifiedRelation { /// The full selection, including selection of joined relations /// /// SELECT ... FROM ... AS ... JOIN ... WHERE ... ORDER BY ... - /// ^ fullSelection + /// | + /// • fullSelection var selection: [SQLSelectable] { return joins.reduce(into: ownSelection) { $0.append(contentsOf: $1.value.relation.selection) @@ -254,7 +266,8 @@ private struct SQLQualifiedRelation { /// The filtering clause /// /// SELECT ... FROM ... AS ... JOIN ... WHERE ... ORDER BY ... - /// ^ filterPromise + /// | + /// • filterPromise let filterPromise: DatabasePromise /// The ordering, not including ordering of joined relations @@ -263,7 +276,8 @@ private struct SQLQualifiedRelation { /// The full ordering, including orderings of joined relations /// /// SELECT ... FROM ... AS ... JOIN ... WHERE ... ORDER BY ... - /// ^ ordering + /// | + /// • ordering var ordering: SQLRelation.Ordering { return joins.reduce(ownOrdering) { $0.appending($1.value.relation.ordering) @@ -273,7 +287,8 @@ private struct SQLQualifiedRelation { /// The joins /// /// SELECT ... FROM ... AS ... JOIN ... WHERE ... ORDER BY ... - /// ^ joins + /// | + /// • joins let joins: OrderedDictionary init(_ relation: SQLRelation) { @@ -288,18 +303,34 @@ private struct SQLQualifiedRelation { // Qualify all joins, selection, filter, and ordering, so that all // identifiers can be correctly disambiguated and qualified. - joins = relation.joins.mapValues(SQLQualifiedJoin.init) + joins = relation.children.compactMapValues { child -> SQLQualifiedJoin? in + let kind: SQLQualifiedJoin.Kind + switch child.kind { + case .oneRequired: + kind = .innerJoin + case .oneOptional: + kind = .leftJoin + case .allPrefetched, .allNotPrefetched: + // This relation child is not fetched with an SQL join. + return nil + } + + return SQLQualifiedJoin( + kind: kind, + condition: child.condition, + relation: SQLQualifiedRelation(child.relation)) + } ownSelection = relation.selection.map { $0.qualifiedSelectable(with: alias) } filterPromise = relation.filterPromise.map { [alias] in $0?.qualifiedExpression(with: alias) } ownOrdering = relation.ordering.qualified(with: alias) } - /// See SQLSelectQueryGenerator.rowAdapter(_:) + /// See SQLQueryGenerator.rowAdapter(_:) /// /// - parameter db: A database connection. /// - parameter startIndex: The index of the leftmost selected column of /// this relation in a full SQL query. `startIndex` is 0 for the relation - /// at the root of a SQLSelectQueryGenerator (as opposed to the + /// at the root of a SQLQueryGenerator (as opposed to the /// joined relations). /// - returns: An optional tuple made of a RowAdapter and the index past the /// rightmost selected column of this relation. Nil is returned if this @@ -358,7 +389,7 @@ private struct SQLQualifiedRelation { /// A "qualified" source, where all tables are identified with a table alias. private enum SQLQualifiedSource { case table(tableName: String, alias: TableAlias) - indirect case query(SQLSelectQueryGenerator) + indirect case query(SQLQueryGenerator) var alias: TableAlias { switch self { @@ -377,14 +408,14 @@ private enum SQLQualifiedSource { return query.relation.allAliases } } - + init(_ source: SQLSource) { switch source { case .table(let tableName, let alias): let alias = alias ?? TableAlias(tableName: tableName) self = .table(tableName: tableName, alias: alias) case .query(let query): - self = .query(SQLSelectQueryGenerator(query)) + self = .query(SQLQueryGenerator(query)) } } @@ -404,36 +435,37 @@ private enum SQLQualifiedSource { /// A "qualified" join, where all tables are identified with a table alias. private struct SQLQualifiedJoin { - private let joinOperator: JoinOperator - private let joinCondition: JoinCondition + enum Kind: String { + case leftJoin = "LEFT JOIN" + case innerJoin = "JOIN" + } + let kind: Kind + let condition: SQLAssociationCondition let relation: SQLQualifiedRelation - init(_ join: SQLJoin) { - self.joinOperator = join.joinOperator - self.joinCondition = join.joinCondition - self.relation = SQLQualifiedRelation(join.relation) + func sql(_ db: Database,_ context: inout SQLGenerationContext, leftAlias: TableAlias) throws -> String { + return try sql(db, &context, leftAlias: leftAlias, allowingInnerJoin: true) } - func sql(_ db: Database,_ context: inout SQLGenerationContext, leftAlias: TableAlias, isRequiredAllowed: Bool) throws -> String { - var isRequiredAllowed = isRequiredAllowed + private func sql(_ db: Database,_ context: inout SQLGenerationContext, leftAlias: TableAlias, allowingInnerJoin allowsInnerJoin: Bool) throws -> String { + var allowsInnerJoin = allowsInnerJoin var sql = "" - switch joinOperator { - case .optional: - isRequiredAllowed = false - sql += "LEFT JOIN" - case .required: - guard isRequiredAllowed else { + + switch self.kind { + case .innerJoin: + guard allowsInnerJoin else { // TODO: chainOptionalRequired fatalError("Not implemented: chaining a required association behind an optional association") } - sql += "JOIN" + case .leftJoin: + allowsInnerJoin = false } - + sql += kind.rawValue sql += try " " + relation.source.sql(db, &context) let rightAlias = relation.alias let filters = try [ - joinCondition.sqlExpression(db, leftAlias: leftAlias, rightAlias: rightAlias), + condition.joinExpression(db, leftAlias: leftAlias, rightAlias: rightAlias), relation.filterPromise.resolve(db) ].compactMap { $0 } if !filters.isEmpty { @@ -441,7 +473,7 @@ private struct SQLQualifiedJoin { } for (_, join) in relation.joins { - sql += try " " + join.sql(db, &context, leftAlias: rightAlias, isRequiredAllowed: isRequiredAllowed) + sql += try " " + join.sql(db, &context, leftAlias: rightAlias, allowingInnerJoin: allowsInnerJoin) } return sql diff --git a/GRDB/QueryInterface/SQLInterpolation+QueryInterface.swift b/GRDB/QueryInterface/SQLInterpolation+QueryInterface.swift new file mode 100644 index 000000000..1b16bed5c --- /dev/null +++ b/GRDB/QueryInterface/SQLInterpolation+QueryInterface.swift @@ -0,0 +1,149 @@ +#if swift(>=5.0) +/// :nodoc: +extension SQLInterpolation { + /// Appends the table name of the record type. + /// + /// // SELECT * FROM player + /// let request: SQLRequest = "SELECT * FROM \(Player.self)" + public mutating func appendInterpolation(_ table: T.Type) { + sql += table.databaseTableName.quotedDatabaseIdentifier + } + + /// Appends the table name of the record. + /// + /// // INSERT INTO player ... + /// let player: Player = ... + /// let request: SQLRequest = "INSERT INTO \(tableOf: player) ..." + public mutating func appendInterpolation(tableOf record: T) { + sql += type(of: record).databaseTableName.quotedDatabaseIdentifier + } + + /// Appends the selectable SQL. + /// + /// // SELECT * FROM player + /// let request: SQLRequest = """ + /// SELECT \(AllColumns()) FROM player + /// """ + public mutating func appendInterpolation(_ selection: SQLSelectable) { + sql += selection.resultColumnSQL(&context) + } + + /// Appends the expression SQL. + /// + /// // SELECT name FROM player + /// let request: SQLRequest = """ + /// SELECT \(Column("name")) FROM player + /// """ + public mutating func appendInterpolation(_ expressible: SQLExpressible & SQLSelectable & SQLOrderingTerm) { + sql += expressible.sqlExpression.expressionSQL(&context) + } + + /// Appends the name of the coding key. + /// + /// // SELECT name FROM player + /// let request: SQLRequest = " + /// SELECT \(CodingKey.name) FROM player + /// """ + public mutating func appendInterpolation(_ codingKey: SQLExpressible & SQLSelectable & SQLOrderingTerm & CodingKey) { + sql += codingKey.sqlExpression.expressionSQL(&context) + } + + /// Appends the expression SQL, or NULL if it is nil. + /// + /// // SELECT score + ? FROM player + /// let bonus = 1000 + /// let request: SQLRequest = """ + /// SELECT score + \(bonus) FROM player + /// """ + public mutating func appendInterpolation(_ expressible: T?) { + if let expressible = expressible { + sql += expressible.sqlExpression.expressionSQL(&context) + } else { + sql += "NULL" + } + } + + /// Appends the name of the coding key. + /// + /// // SELECT name FROM player + /// let request: SQLRequest = """ + /// SELECT \(CodingKey.name) FROM player + /// """ + public mutating func appendInterpolation(_ codingKey: CodingKey) { + appendInterpolation(Column(codingKey.stringValue)) + } + + /// Appends a sequence of expressions, wrapped in parentheses. + /// + /// // SELECT * FROM player WHERE id IN (?,?,?) + /// let ids = [1, 2, 3] + /// let request: SQLRequest = """ + /// SELECT * FROM player WHERE id IN \(ids) + /// """ + /// + /// If the sequence is empty, an empty subquery is appended: + /// + /// // SELECT * FROM player WHERE id IN (SELECT NULL WHERE NULL) + /// let ids: [Int] = [] + /// let request: SQLRequest = """ + /// SELECT * FROM player WHERE id IN \(ids) + /// """ + public mutating func appendInterpolation(_ sequence: S) where S: Sequence, S.Element: SQLExpressible { + appendInterpolation(sequence.lazy.map { $0.sqlExpression }) + } + + /// Appends a sequence of expressions, wrapped in parentheses. + /// + /// // SELECT * FROM player WHERE a IN (b, c + 2) + /// let expressions = [Column("b"), Column("c") + 2] + /// let request: SQLRequest = """ + /// SELECT * FROM player WHERE a IN \(expressions) + /// """ + /// + /// If the sequence is empty, an empty subquery is appended: + /// + /// // SELECT * FROM player WHERE a IN (SELECT NULL WHERE NULL) + /// let expressions: [SQLExpression] = [] + /// let request: SQLRequest = """ + /// SELECT * FROM player WHERE a IN \(expressions) + /// """ + public mutating func appendInterpolation(_ sequence: S) where S: Sequence, S.Element == SQLExpression { + sql += "(" + var first = true + for element in sequence { + if first { + first = false + } else { + sql += "," + } + appendInterpolation(element) + } + if first { + sql += "SELECT NULL WHERE NULL" + } + sql += ")" + } + + /// Appends the ordering SQL. + /// + /// // SELECT name FROM player ORDER BY name DESC + /// let request: SQLRequest = """ + /// SELECT * FROM player ORDER BY \(Column("name").desc) + /// """ + public mutating func appendInterpolation(_ ordering: SQLOrderingTerm) { + sql += ordering.orderingTermSQL(&context) + } + + /// Appends the request SQL, wrapped in parentheses + /// + /// // SELECT name FROM player WHERE score = (SELECT MAX(score) FROM player) + /// let subQuery: SQLRequest = "SELECT MAX(score) FROM player" + /// let request: SQLRequest = """ + /// SELECT * FROM player WHERE score = \(subQuery) + /// """ + public mutating func appendInterpolation(_ request: SQLRequest) { + sql += "(" + request.sql + ")" + arguments += request.arguments + } +} +#endif diff --git a/GRDB/QueryInterface/SQLRelation.swift b/GRDB/QueryInterface/SQLRelation.swift deleted file mode 100644 index 144d91185..000000000 --- a/GRDB/QueryInterface/SQLRelation.swift +++ /dev/null @@ -1,471 +0,0 @@ -/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) -/// -/// A "relation" as defined by the [relational terminology](https://en.wikipedia.org/wiki/Relational_database#Terminology): -/// -/// > A set of tuples sharing the same attributes; a set of columns and rows. -/// -/// :nodoc: -public /* TODO: internal */ struct SQLRelation { - var source: SQLSource - var selection: [SQLSelectable] - var filterPromise: DatabasePromise - var ordering: SQLRelation.Ordering - var joins: OrderedDictionary - - var alias: TableAlias? { - return source.alias - } - - init( - source: SQLSource, - selection: [SQLSelectable] = [], - filterPromise: DatabasePromise = DatabasePromise(value: nil), - ordering: SQLRelation.Ordering = SQLRelation.Ordering(), - joins: OrderedDictionary = [:]) - { - self.source = source - self.selection = selection - self.filterPromise = filterPromise - self.ordering = ordering - self.joins = joins - } -} - -extension SQLRelation { - func select(_ selection: [SQLSelectable]) -> SQLRelation { - var relation = self - relation.selection = selection - return relation - } - - func annotated(with selection: [SQLSelectable]) -> SQLRelation { - var relation = self - relation.selection.append(contentsOf: selection) - return relation - } - - func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> SQLRelation { - var relation = self - relation.filterPromise = relation.filterPromise.flatMap { filter in - if let filter = filter { - return DatabasePromise { try filter && predicate($0) } - } else { - return DatabasePromise { try predicate($0).sqlExpression } - } - } - return relation - } - - func order(_ orderings: @escaping (Database) throws -> [SQLOrderingTerm]) -> SQLRelation { - return order(SQLRelation.Ordering(orderings: orderings)) - } - - func reversed() -> SQLRelation { - return order(ordering.reversed) - } - - private func order(_ ordering: SQLRelation.Ordering) -> SQLRelation { - var relation = self - relation.ordering = ordering - return relation - } - - func unordered() -> SQLRelation { - return order(SQLRelation.Ordering()) - } - - func appendingJoin(_ join: SQLJoin, forKey key: String) -> SQLRelation { - var relation = self - if let existingJoin = relation.joins.removeValue(forKey: key) { - guard let mergedJoin = existingJoin.merged(with: join) else { - // can't merge - fatalError("The association key \"\(key)\" is ambiguous. Use the Association.forKey(_:) method is order to disambiguate.") - } - relation.joins.appendValue(mergedJoin, forKey: key) - } else { - relation.joins.appendValue(join, forKey: key) - } - return relation - } - - func qualified(with alias: TableAlias) -> SQLRelation { - var relation = self - relation.source = source.qualified(with: alias) - return relation - } -} - -// MARK: - SQLSource - -enum SQLSource { - case table(tableName: String, alias: TableAlias?) - indirect case query(SQLSelectQuery) - - var alias: TableAlias? { - switch self { - case .table(_, let alias): - return alias - case .query(let query): - return query.alias - } - } - - func qualified(with alias: TableAlias) -> SQLSource { - switch self { - case .table(let tableName, let sourceAlias): - if let sourceAlias = sourceAlias { - alias.becomeProxy(of: sourceAlias) - return self - } else { - alias.setTableName(tableName) - return .table(tableName: tableName, alias: alias) - } - case .query(let query): - return .query(query.qualified(with: alias)) - } - } -} - -// MARK: - SQLRelation.Ordering - -extension SQLRelation { - /// SQLRelation.Ordering provides the order clause to SQLRelation. - struct Ordering { - private enum Element { - case terms(DatabasePromise<[SQLOrderingTerm]>) - case ordering(SQLRelation.Ordering) - - var reversed: Element { - switch self { - case .terms(let terms): - return .terms(terms.map { $0.map { $0.reversed } }) - case .ordering(let ordering): - return .ordering(ordering.reversed) - } - } - - func qualified(with alias: TableAlias) -> Element { - switch self { - case .terms(let terms): - return .terms(terms.map { $0.map { $0.qualifiedOrdering(with: alias) } }) - case .ordering(let ordering): - return .ordering(ordering.qualified(with: alias)) - } - } - - func resolve(_ db: Database) throws -> [SQLOrderingTerm] { - switch self { - case .terms(let terms): - return try terms.resolve(db) - case .ordering(let ordering): - return try ordering.resolve(db) - } - } - } - - private var elements: [Element] = [] - var isReversed: Bool - - var isEmpty: Bool { - return elements.isEmpty - } - - private init(elements: [Element], isReversed: Bool) { - self.elements = elements - self.isReversed = isReversed - } - - init() { - self.init( - elements: [], - isReversed: false) - } - - init(orderings: @escaping (Database) throws -> [SQLOrderingTerm]) { - self.init( - elements: [.terms(DatabasePromise(orderings))], - isReversed: false) - } - - var reversed: Ordering { - return Ordering( - elements: elements, - isReversed: !isReversed) - } - - func qualified(with alias: TableAlias) -> Ordering { - return Ordering( - elements: elements.map { $0.qualified(with: alias) }, - isReversed: isReversed) - } - - func appending(_ ordering: Ordering) -> Ordering { - return Ordering( - elements: elements + [.ordering(ordering)], - isReversed: isReversed) - } - - func resolve(_ db: Database) throws -> [SQLOrderingTerm] { - if isReversed { - return try elements.flatMap { try $0.reversed.resolve(db) } - } else { - return try elements.flatMap { try $0.resolve(db) } - } - } - } -} - -// MARK: - SQLJoin - -/// Not to be mismatched with SQL join operators (inner join, left join). -/// -/// JoinOperator is designed to be hierarchically nested, unlike -/// SQL join operators. -/// -/// Consider the following request for (A, B, C) tuples: -/// -/// let r = A.including(optional: A.b.including(required: B.c)) -/// -/// It chains three associations, the first optional, the second required. -/// -/// It looks like it means: "Give me all As, along with their Bs, granted those -/// Bs have their Cs. For As whose B has no C, give me a nil B". -/// -/// It can not be expressed as one left join, and a regular join, as below, -/// Because this would not honor the first optional: -/// -/// -- dubious -/// SELECT a.*, b.*, c.* -/// FROM a -/// LEFT JOIN b ON ... -/// JOIN c ON ... -/// -/// Instead, it should: -/// - allow (A + missing (B + C)) -/// - prevent (A + (B + missing C)). -/// -/// This can be expressed in SQL with two left joins, and an extra condition: -/// -/// -- likely correct -/// SELECT a.*, b.*, c.* -/// FROM a -/// LEFT JOIN b ON ... -/// LEFT JOIN c ON ... -/// WHERE NOT((b.id IS NOT NULL) AND (c.id IS NULL)) -- no B without C -/// -/// This is currently not implemented, and requires a little more thought. -/// I don't even know if inventing a whole new way to perform joins should even -/// be on the table. But we have a hierarchical way to express joined queries, -/// and they have a meaning: -/// -/// // what is my meaning? -/// A.including(optional: A.b.including(required: B.c)) -/// -/// :nodoc: -public /* TODO: internal */ enum JoinOperator { - case required, optional -} - -/// The condition that links two joined tables. -/// -/// Currently, we only support one kind of join condition: foreign keys. -/// -/// SELECT ... FROM book JOIN author ON author.id = book.authorId -/// <- the join condition --> -/// -/// When we eventually add support for new ways to join tables, JoinCondition -/// is the type we'll need to update. -/// -/// JoinCondition equality allows merging of associations: -/// -/// // request1 and request2 are equivalent -/// let request1 = Book -/// .including(required: Book.author) -/// let request2 = Book -/// .including(required: Book.author) -/// .including(required: Book.author) -/// -/// // request3 and request4 are equivalent -/// let request3 = Book -/// .including(required: Book.author.filter(condition1 && condition2)) -/// let request4 = Book -/// .joining(required: Book.author.filter(condition1)) -/// .including(optional: Book.author.filter(condition2)) -/// -/// :nodoc: -public /* TODO: internal */ struct JoinCondition: Equatable { - /// Definition of a foreign key - var foreignKeyRequest: ForeignKeyRequest - - /// True if the table at the origin of the foreign key is on the left of - /// the sql JOIN operator. - /// - /// Let's consider the `book.authorId -> author.id` foreign key. - /// Its origin table is `book`. - /// - /// The origin table `book` is on the left of the JOIN operator for - /// the BelongsTo association: - /// - /// -- Book.including(required: Book.author) - /// SELECT ... FROM book JOIN author ON author.id = book.authorId - /// - /// The origin table `book`is on the right of the JOIN operator for - /// the HasMany and HasOne associations: - /// - /// -- Author.including(required: Author.books) - /// SELECT ... FROM author JOIN book ON author.id = book.authorId - var originIsLeft: Bool - - /// Returns an SQL expression for the join condition. - /// - /// SELECT ... FROM book JOIN author ON author.id = book.authorId - /// <- the SQL expression --> - /// - /// - parameter db: A database connection. - /// - parameter leftAlias: A TableAlias for the table on the left of the - /// JOIN operator. - /// - parameter rightAlias: A TableAlias for the table on the right of the - /// JOIN operator. - /// - Returns: An SQL expression. - func sqlExpression(_ db: Database, leftAlias: TableAlias, rightAlias: TableAlias) throws -> SQLExpression { - let foreignKeyMapping = try foreignKeyRequest.fetch(db).mapping - let columnMapping: [(left: Column, right: Column)] - if originIsLeft { - columnMapping = foreignKeyMapping.map { (left: Column($0.origin), right: Column($0.destination)) } - } else { - columnMapping = foreignKeyMapping.map { (left: Column($0.destination), right: Column($0.origin)) } - } - - return columnMapping - .map { $0.right.qualifiedExpression(with: rightAlias) == $0.left.qualifiedExpression(with: leftAlias) } - .joined(operator: .and) - } -} - -struct SQLJoin { - var joinOperator: JoinOperator - var joinCondition: JoinCondition - var relation: SQLRelation -} - -// MARK: - Merging -// -// "Merging" is an operation that takes two relations and, if they are -// compatible, gathers them into a merged relation. -// -// It is an important feature that allows the user to define associated requests -// in several steps. For example, in the sample code below, both requests are -// equivalent and generate the same SQL query, thanks to merging: -// -// let request1 = Book.including(required: Book.author) -// -// let request2 = Book -// .including(required: Book.author) -// .including(required: Book.author) - -extension SQLRelation { - /// Returns nil if relations can't be merged (conflict in source, joins...) - func merged(with other: SQLRelation) -> SQLRelation? { - guard let mergedSource = source.merged(with: other.source) else { - // can't merge - return nil - } - - let mergedFilterPromise: DatabasePromise = filterPromise.flatMap { expression in - return DatabasePromise { db in - let otherExpression = try other.filterPromise.resolve(db) - let expressions = [expression, otherExpression].compactMap { $0 } - if expressions.isEmpty { - return nil - } else { - return expressions.joined(operator: .and) - } - } - } - - var mergedJoins: OrderedDictionary = [:] - for (key, join) in joins { - if let otherJoin = other.joins[key] { - guard let mergedJoin = join.merged(with: otherJoin) else { - // can't merge - return nil - } - mergedJoins.appendValue(mergedJoin, forKey: key) - } else { - mergedJoins.appendValue(join, forKey: key) - } - } - for (key, join) in other.joins where mergedJoins[key] == nil { - mergedJoins.appendValue(join, forKey: key) - } - - // replace selection unless empty - let mergedSelection = other.selection.isEmpty ? selection : other.selection - - // replace ordering unless empty - let mergedOrdering = other.ordering.isEmpty ? ordering : other.ordering - - return SQLRelation( - source: mergedSource, - selection: mergedSelection, - filterPromise: mergedFilterPromise, - ordering: mergedOrdering, - joins: mergedJoins) - } -} - -extension SQLSource { - /// Returns nil if sources can't be merged (conflict in tables, aliases...) - func merged(with other: SQLSource) -> SQLSource? { - switch (self, other) { - case let (.table(tableName: tableName, alias: alias), .table(tableName: otherTableName, alias: otherAlias)): - guard tableName == otherTableName else { - // can't merge - return nil - } - switch (alias, otherAlias) { - case (nil, nil): - return .table(tableName: tableName, alias: nil) - case let (alias?, nil), let (nil, alias?): - return .table(tableName: tableName, alias: alias) - case let (alias?, otherAlias?): - guard let mergedAlias = alias.merged(with: otherAlias) else { - // can't merge - return nil - } - return .table(tableName: tableName, alias: mergedAlias) - } - default: - // can't merge - return nil - } - } -} - -extension SQLJoin { - /// Returns nil if joins can't be merged (conflict in condition, relation...) - func merged(with other: SQLJoin) -> SQLJoin? { - guard joinCondition == other.joinCondition else { - // can't merge - return nil - } - - guard let mergedRelation = relation.merged(with: other.relation) else { - // can't merge - return nil - } - - let mergedJoinOperator: JoinOperator - switch (joinOperator, other.joinOperator) { - case (.required, _), (_, .required): - mergedJoinOperator = .required - default: - mergedJoinOperator = .optional - } - - return SQLJoin( - joinOperator: mergedJoinOperator, - joinCondition: joinCondition, - relation: mergedRelation) - } -} diff --git a/GRDB/QueryInterface/TableDefinition.swift b/GRDB/QueryInterface/Schema/TableDefinition.swift similarity index 94% rename from GRDB/QueryInterface/TableDefinition.swift rename to GRDB/QueryInterface/Schema/TableDefinition.swift index 41fefb83c..d6203caa6 100644 --- a/GRDB/QueryInterface/TableDefinition.swift +++ b/GRDB/QueryInterface/Schema/TableDefinition.swift @@ -29,7 +29,7 @@ extension Database { let definition = TableDefinition(name: name, temporary: temporary, ifNotExists: ifNotExists, withoutRowID: withoutRowID) body(definition) let sql = try definition.sql(self) - try execute(sql) + try execute(sql: sql) } #else /// Creates a database table. @@ -54,14 +54,14 @@ extension Database { /// - withoutRowID: If true, uses WITHOUT ROWID optimization. /// - body: A closure that defines table columns and constraints. /// - throws: A DatabaseError whenever an SQLite error occurs. - @available(iOS 8.2, OSX 10.10, *) + @available(OSX 10.10, *) public func create(table name: String, temporary: Bool = false, ifNotExists: Bool = false, withoutRowID: Bool, body: (TableDefinition) -> Void) throws { // WITHOUT ROWID was added in SQLite 3.8.2 http://www.sqlite.org/changes.html#version_3_8_2 // It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS) let definition = TableDefinition(name: name, temporary: temporary, ifNotExists: ifNotExists, withoutRowID: withoutRowID) body(definition) let sql = try definition.sql(self) - try execute(sql) + try execute(sql: sql) } /// Creates a database table. @@ -88,7 +88,7 @@ extension Database { let definition = TableDefinition(name: name, temporary: temporary, ifNotExists: ifNotExists, withoutRowID: false) body(definition) let sql = try definition.sql(self) - try execute(sql) + try execute(sql: sql) } #endif @@ -98,7 +98,7 @@ extension Database { /// /// - throws: A DatabaseError whenever an SQLite error occurs. public func rename(table name: String, to newName: String) throws { - try execute("ALTER TABLE \(name.quotedDatabaseIdentifier) RENAME TO \(newName.quotedDatabaseIdentifier)") + try execute(sql: "ALTER TABLE \(name.quotedDatabaseIdentifier) RENAME TO \(newName.quotedDatabaseIdentifier)") } /// Modifies a database table. @@ -117,7 +117,7 @@ extension Database { let alteration = TableAlteration(name: name) body(alteration) let sql = try alteration.sql(self) - try execute(sql) + try execute(sql: sql) } /// Deletes a database table. @@ -126,7 +126,7 @@ extension Database { /// /// - throws: A DatabaseError whenever an SQLite error occurs. public func drop(table name: String) throws { - try execute("DROP TABLE \(name.quotedDatabaseIdentifier)") + try execute(sql: "DROP TABLE \(name.quotedDatabaseIdentifier)") } #if GRDBCUSTOMSQLITE || GRDBCIPHER @@ -138,7 +138,7 @@ extension Database { /// and use specific collations. To create such an index, use a raw SQL /// query. /// - /// try db.execute("CREATE INDEX ...") + /// try db.execute(sql: "CREATE INDEX ...") /// /// See https://www.sqlite.org/lang_createindex.html /// @@ -155,7 +155,7 @@ extension Database { // It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS) let definition = IndexDefinition(name: name, table: table, columns: columns, unique: unique, ifNotExists: ifNotExists, condition: condition?.sqlExpression) let sql = definition.sql() - try execute(sql) + try execute(sql: sql) } #else /// Creates an index. @@ -166,7 +166,7 @@ extension Database { /// and use specific collations. To create such an index, use a raw SQL /// query. /// - /// try db.execute("CREATE INDEX ...") + /// try db.execute(sql: "CREATE INDEX ...") /// /// See https://www.sqlite.org/lang_createindex.html /// @@ -181,7 +181,7 @@ extension Database { // It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS) let definition = IndexDefinition(name: name, table: table, columns: columns, unique: unique, ifNotExists: ifNotExists, condition: nil) let sql = definition.sql() - try execute(sql) + try execute(sql: sql) } /// Creates a partial index. @@ -198,13 +198,13 @@ extension Database { /// - unique: If true, creates a unique index. /// - ifNotExists: If false, no error is thrown if index already exists. /// - condition: The condition that indexed rows must verify. - @available(iOS 8.2, OSX 10.10, *) + @available(OSX 10.10, *) public func create(index name: String, on table: String, columns: [String], unique: Bool = false, ifNotExists: Bool = false, condition: SQLExpressible) throws { // Partial indexes were introduced in SQLite 3.8.0 http://www.sqlite.org/changes.html#version_3_8_0 // It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS) let definition = IndexDefinition(name: name, table: table, columns: columns, unique: unique, ifNotExists: ifNotExists, condition: condition.sqlExpression) let sql = definition.sql() - try execute(sql) + try execute(sql: sql) } #endif @@ -214,7 +214,7 @@ extension Database { /// /// - throws: A DatabaseError whenever an SQLite error occurs. public func drop(index name: String) throws { - try execute("DROP INDEX \(name.quotedDatabaseIdentifier)") + try execute(sql: "DROP INDEX \(name.quotedDatabaseIdentifier)") } /// Delete and recreate from scratch all indices that use this collation. @@ -226,7 +226,7 @@ extension Database { /// /// - throws: A DatabaseError whenever an SQLite error occurs. public func reindex(collation: Database.CollationName) throws { - try execute("REINDEX \(collation.rawValue)") + try execute(sql: "REINDEX \(collation.rawValue)") } /// Delete and recreate from scratch all indices that use this collation. @@ -296,7 +296,7 @@ public final class TableDefinition { /// See https://www.sqlite.org/lang_createtable.html#primkeyconst and /// https://www.sqlite.org/lang_createtable.html#rowid /// - /// - parameter conflitResolution: An optional conflict resolution + /// - parameter conflictResolution: An optional conflict resolution /// (see https://www.sqlite.org/lang_conflict.html). /// - returns: Self so that you can further refine the column definition. @discardableResult @@ -335,7 +335,7 @@ public final class TableDefinition { /// https://www.sqlite.org/lang_createtable.html#rowid /// /// - parameter columns: The primary key columns. - /// - parameter conflitResolution: An optional conflict resolution + /// - parameter conflictResolution: An optional conflict resolution /// (see https://www.sqlite.org/lang_conflict.html). public func primaryKey(_ columns: [String], onConflict conflictResolution: Database.ConflictResolution? = nil) { guard primaryKeyConstraint == nil else { @@ -356,7 +356,7 @@ public final class TableDefinition { /// See https://www.sqlite.org/lang_createtable.html#uniqueconst /// /// - parameter columns: The unique key columns. - /// - parameter conflitResolution: An optional conflict resolution + /// - parameter conflictResolution: An optional conflict resolution /// (see https://www.sqlite.org/lang_conflict.html). public func uniqueKey(_ columns: [String], onConflict conflictResolution: Database.ConflictResolution? = nil) { uniqueKeyConstraints.append((columns: columns, conflictResolution: conflictResolution)) @@ -416,9 +416,9 @@ public final class TableDefinition { /// /// - parameter sql: An SQL snippet public func check(sql: String) { - var expression = SQLExpressionLiteral(sql) - expression.unsafeRaw = true // It's safe because this expression can't be composed with others - checkConstraints.append(expression) + // We do not want to wrap the SQL snippet inside parentheses around the + // checked SQL. This is why we use the "unsafeLiteral" initializer. + checkConstraints.append(SQLExpressionLiteral(unsafeLiteral: SQLLiteral(sql: sql))) } fileprivate func sql(_ db: Database) throws -> String { @@ -439,7 +439,7 @@ public final class TableDefinition { let primaryKeyColumns: [String] if let (columns, _) = primaryKeyConstraint { primaryKeyColumns = columns - } else if let index = columns.index(where: { $0.primaryKey != nil }) { + } else if let index = columns.firstIndex(where: { $0.primaryKey != nil }) { primaryKeyColumns = [columns[index].name] } else { // WITHOUT ROWID optimization requires a primary key. If the @@ -507,7 +507,7 @@ public final class TableDefinition { for checkExpression in checkConstraints { var chunks: [String] = [] chunks.append("CHECK") - chunks.append("(" + checkExpression.sql + ")") + chunks.append("(" + checkExpression.quotedSQL() + ")") items.append(chunks.joined(separator: " ")) } @@ -631,7 +631,7 @@ public final class ColumnDefinition { /// https://www.sqlite.org/lang_createtable.html#rowid /// /// - parameters: - /// - conflitResolution: An optional conflict resolution + /// - conflictResolution: An optional conflict resolution /// (see https://www.sqlite.org/lang_conflict.html). /// - autoincrement: If true, the primary key is autoincremented. /// - returns: Self so that you can further refine the column definition. @@ -649,7 +649,7 @@ public final class ColumnDefinition { /// /// See https://www.sqlite.org/lang_createtable.html#notnullconst /// - /// - parameter conflitResolution: An optional conflict resolution + /// - parameter conflictResolution: An optional conflict resolution /// (see https://www.sqlite.org/lang_conflict.html). /// - returns: Self so that you can further refine the column definition. @discardableResult @@ -666,7 +666,7 @@ public final class ColumnDefinition { /// /// See https://www.sqlite.org/lang_createtable.html#uniqueconst /// - /// - parameter conflitResolution: An optional conflict resolution + /// - parameter conflictResolution: An optional conflict resolution /// (see https://www.sqlite.org/lang_conflict.html). /// - returns: Self so that you can further refine the column definition. @discardableResult @@ -721,9 +721,9 @@ public final class ColumnDefinition { /// - returns: Self so that you can further refine the column definition. @discardableResult public func check(sql: String) -> Self { - var expression = SQLExpressionLiteral(sql) - expression.unsafeRaw = true // It's safe because this expression can't be composed with others - checkConstraints.append(expression) + // We do not want to wrap the SQL snippet inside parentheses around the + // checked SQL. This is why we use the "unsafeLiteral" initializer. + checkConstraints.append(SQLExpressionLiteral(unsafeLiteral: SQLLiteral(sql: sql))) return self } @@ -755,9 +755,9 @@ public final class ColumnDefinition { /// - returns: Self so that you can further refine the column definition. @discardableResult public func defaults(sql: String) -> Self { - var expression = SQLExpressionLiteral(sql) - expression.unsafeRaw = true // It's safe because this expression can't be composed with others - defaultExpression = expression + // We do not want to wrap the SQL snippet inside parentheses around the + // checked SQL. This is why we use the "unsafeLiteral" initializer. + defaultExpression = SQLExpressionLiteral(unsafeLiteral: SQLLiteral(sql: sql)) return self } @@ -861,12 +861,12 @@ public final class ColumnDefinition { for checkConstraint in checkConstraints { chunks.append("CHECK") - chunks.append("(" + checkConstraint.sql + ")") + chunks.append("(" + checkConstraint.quotedSQL() + ")") } if let defaultExpression = defaultExpression { chunks.append("DEFAULT") - chunks.append(defaultExpression.sql) + chunks.append(defaultExpression.quotedSQL()) } if let collationName = collationName { @@ -943,7 +943,7 @@ private struct IndexDefinition { chunks.append("\(table.quotedDatabaseIdentifier)(\((columns.map { $0.quotedDatabaseIdentifier } as [String]).joined(separator: ", ")))") if let condition = condition { chunks.append("WHERE") - chunks.append(condition.sql) + chunks.append(condition.quotedSQL()) } return chunks.joined(separator: " ") } diff --git a/GRDB/QueryInterface/VirtualTableModule.swift b/GRDB/QueryInterface/Schema/VirtualTableModule.swift similarity index 98% rename from GRDB/QueryInterface/VirtualTableModule.swift rename to GRDB/QueryInterface/Schema/VirtualTableModule.swift index 3814a1132..06eaa3ea2 100644 --- a/GRDB/QueryInterface/VirtualTableModule.swift +++ b/GRDB/QueryInterface/Schema/VirtualTableModule.swift @@ -64,7 +64,7 @@ extension Database { chunks.append("USING") chunks.append(module) let sql = chunks.joined(separator: " ") - try execute(sql) + try execute(sql: sql) } /// Creates a virtual database table. @@ -120,7 +120,7 @@ extension Database { let sql = chunks.joined(separator: " ") try inSavepoint { - try execute(sql) + try execute(sql: sql) try module.database(self, didCreate: tableName, using: definition) return .commit } diff --git a/GRDB/QueryInterface/TableRecord+Association.swift b/GRDB/QueryInterface/TableRecord+Association.swift new file mode 100644 index 000000000..5ea8bf58f --- /dev/null +++ b/GRDB/QueryInterface/TableRecord+Association.swift @@ -0,0 +1,627 @@ +extension TableRecord { + /// Creates a "Belongs To" association between Self and the + /// destination type. + /// + /// struct Author: TableRecord { ... } + /// struct Book: TableRecord { + /// static let author = belongsTo(Author.self) + /// } + /// + /// The association will let you define requests that load both the source + /// and the destination type: + /// + /// // A request for all books with their authors: + /// let request = Book.including(optional: Book.author) + /// + /// To consume those requests, define a type that adopts both the + /// FetchableRecord and Decodable protocols: + /// + /// struct BookInfo: FetchableRecord, Decodable { + /// var book: Book + /// var author: Author? + /// } + /// + /// let bookInfos = try dbQueue.read { db in + /// return try BookInfo.fetchAll(db, request) + /// } + /// for bookInfo in bookInfos { + /// print("\(bookInfo.book.title) by \(bookInfo.author.name)") + /// } + /// + /// It is recommended that you define, alongside the static association, a + /// property with the same name: + /// + /// struct Book: TableRecord, EncodableRecord { + /// static let author = belongsTo(Author.self) + /// var author: QueryInterfaceRequest { + /// return request(for: Book.author) + /// } + /// } + /// + /// This property will let you navigate from the source type to the + /// destination type: + /// + /// try dbQueue.read { db in + /// let book: Book = ... + /// let author = try book.author.fetchOne(db) // Author? + /// } + /// + /// - parameters: + /// - destination: The record type at the other side of the association. + /// - key: An eventual decoding key for the association. By default, it + /// is `destination.databaseTableName`. + /// - foreignKey: An eventual foreign key. You need to provide an + /// explicit foreign key when GRDB can't infer one from the database + /// schema. This happens when the schema does not define any foreign + /// key to the destination table, or when the schema defines several + /// foreign keys to the destination table. + public static func belongsTo( + _ destination: Destination.Type, + key: String? = nil, + using foreignKey: ForeignKey? = nil) + -> BelongsToAssociation + where Destination: TableRecord + { + let foreignKeyRequest = SQLForeignKeyRequest( + originTable: databaseTableName, + destinationTable: Destination.databaseTableName, + foreignKey: foreignKey) + + let condition = SQLAssociationCondition( + foreignKeyRequest: foreignKeyRequest, + originIsLeft: true) + + let associationKey: SQLAssociationKey + if let key = key { + associationKey = .fixedSingular(key) + } else { + associationKey = .inflected(Destination.databaseTableName) + } + + return BelongsToAssociation(sqlAssociation: SQLAssociation( + key: associationKey, + condition: condition, + relation: Destination.all().relation, + cardinality: .toOne)) + } + + /// Creates a "Has many" association between Self and the + /// destination type. + /// + /// struct Book: TableRecord { ... } + /// struct Author: TableRecord { + /// static let books = hasMany(Book.self) + /// } + /// + /// The association will let you define requests that load both the source + /// and the destination type: + /// + /// // A request for all (author, book) pairs: + /// let request = Author.including(required: Author.books) + /// + /// To consume those requests, define a type that adopts both the + /// FetchableRecord and Decodable protocols: + /// + /// struct Authorship: FetchableRecord, Decodable { + /// var author: Author + /// var book: Book + /// } + /// + /// let authorships = try dbQueue.read { db in + /// return try Authorship.fetchAll(db, request) + /// } + /// for authorship in authorships { + /// print("\(authorship.author.name) wrote \(authorship.book.title)") + /// } + /// + /// It is recommended that you define, alongside the static association, a + /// property with the same name: + /// + /// struct Author: TableRecord, EncodableRecord { + /// static let books = hasMany(Book.self) + /// var books: QueryInterfaceRequest { + /// return request(for: Author.books) + /// } + /// } + /// + /// This property will let you navigate from the source type to the + /// destination type: + /// + /// try dbQueue.read { db in + /// let author: Author = ... + /// let books = try author.books.fetchAll(db) // [Book] + /// } + /// + /// - parameters: + /// - destination: The record type at the other side of the association. + /// - key: An eventual decoding key for the association. By default, it + /// is `destination.databaseTableName`. + /// - foreignKey: An eventual foreign key. You need to provide an + /// explicit foreign key when GRDB can't infer one from the database + /// schema. This happens when the schema does not define any foreign + /// key from the destination table, or when the schema defines several + /// foreign keys from the destination table. + public static func hasMany( + _ destination: Destination.Type, + key: String? = nil, + using foreignKey: ForeignKey? = nil) + -> HasManyAssociation + where Destination: TableRecord + { + let foreignKeyRequest = SQLForeignKeyRequest( + originTable: Destination.databaseTableName, + destinationTable: databaseTableName, + foreignKey: foreignKey) + + let condition = SQLAssociationCondition( + foreignKeyRequest: foreignKeyRequest, + originIsLeft: false) + + let associationKey: SQLAssociationKey + if let key = key { + associationKey = .fixedPlural(key) + } else { + associationKey = .inflected(Destination.databaseTableName) + } + + return HasManyAssociation(sqlAssociation: SQLAssociation( + key: associationKey, + condition: condition, + relation: Destination.all().relation, + cardinality: .toMany)) + } + + /// Creates a "Has Many Through" association between Self and the + /// destination type. + /// + /// struct Country: TableRecord { + /// static let passports = hasMany(Passport.self) + /// static let citizens = hasMany(Citizen.self, through: passports, using: Passport.citizen) + /// } + /// + /// struct Passport: TableRecord { + /// static let citizen = belongsTo(Citizen.self) + /// } + /// + /// struct Citizen: TableRecord { } + /// + /// The association will let you define requests that load both the source + /// and the destination type: + /// + /// // A request for all (country, citizen) pairs: + /// let request = Country.including(required: Coutry.citizens) + /// + /// To consume those requests, define a type that adopts both the + /// FetchableRecord and Decodable protocols: + /// + /// struct Citizenship: FetchableRecord, Decodable { + /// var country: Country + /// var citizen: Citizen + /// } + /// + /// let citizenships = try dbQueue.read { db in + /// return try Citizenship.fetchAll(db, request) + /// } + /// for citizenship in citizenships { + /// print("\(citizenship.citizen.name) is a citizen of \(citizenship.country.name)") + /// } + /// + /// It is recommended that you define, alongside the static association, a + /// property with the same name: + /// + /// struct Country: TableRecord, EncodableRecord { + /// static let passports = hasMany(Passport.self) + /// static let citizens = hasMany(Citizen.self, through: passports, using: Passport.citizen) + /// var citizens: QueryInterfaceRequest { + /// return request(for: Country.citizens) + /// } + /// } + /// + /// This property will let you navigate from the source type to the + /// destination type: + /// + /// try dbQueue.read { db in + /// let country: Country = ... + /// let citizens = try country.citizens.fetchAll(db) // [Country] + /// } + /// + /// - parameters: + /// - destination: The record type at the other side of the association. + /// - pivot: An association from Self to the intermediate type. + /// - target: A target association from the intermediate type to the + /// destination type. + /// - key: An eventual decoding key for the association. By default, it + /// is the same key as the target. + public static func hasMany( + _ destination: Target.RowDecoder.Type, + through pivot: Pivot, + using target: Target, + key: String? = nil) + -> HasManyThroughAssociation + where Pivot: Association, + Target: Association, + Pivot.OriginRowDecoder == Self, + Pivot.RowDecoder == Target.OriginRowDecoder + { + let association = HasManyThroughAssociation( + sqlAssociation: target.sqlAssociation.through(pivot.sqlAssociation)) + + if let key = key { + return association.forKey(key) + } else { + return association + } + } + + /// Creates a "Has one" association between Self and the + /// destination type. + /// + /// struct Demographics: TableRecord { ... } + /// struct Country: TableRecord { + /// static let demographics = hasOne(Demographics.self) + /// } + /// + /// The association will let you define requests that load both the source + /// and the destination type: + /// + /// // A request for all countries with their demographic profile: + /// let request = Country.including(optional: Country.demographics) + /// + /// To consume those requests, define a type that adopts both the + /// FetchableRecord and Decodable protocols: + /// + /// struct CountryInfo: FetchableRecord, Decodable { + /// var country: Country + /// var demographics: Demographics? + /// } + /// + /// let countryInfos = try dbQueue.read { db in + /// return try CountryInfo.fetchAll(db, request) + /// } + /// for countryInfo in countryInfos { + /// print("\(countryInfo.country.name) has \(countryInfo.demographics.population) citizens") + /// } + /// + /// It is recommended that you define, alongside the static association, a + /// property with the same name: + /// + /// struct Country: TableRecord, EncodableRecord { + /// static let demographics = hasOne(Demographics.self) + /// var demographics: QueryInterfaceRequest { + /// return request(for: Country.demographics) + /// } + /// } + /// + /// This property will let you navigate from the source type to the + /// destination type: + /// + /// try dbQueue.read { db in + /// let country: Country = ... + /// let demographics = try country.demographics.fetchOne(db) // Demographics? + /// } + /// + /// - parameters: + /// - destination: The record type at the other side of the association. + /// - key: An eventual decoding key for the association. By default, it + /// is `destination.databaseTableName`. + /// - foreignKey: An eventual foreign key. You need to provide an + /// explicit foreign key when GRDB can't infer one from the database + /// schema. This happens when the schema does not define any foreign + /// key from the destination table, or when the schema defines several + /// foreign keys from the destination table. + public static func hasOne( + _ destination: Destination.Type, + key: String? = nil, + using foreignKey: ForeignKey? = nil) + -> HasOneAssociation + where Destination: TableRecord + { + let foreignKeyRequest = SQLForeignKeyRequest( + originTable: Destination.databaseTableName, + destinationTable: databaseTableName, + foreignKey: foreignKey) + + let condition = SQLAssociationCondition( + foreignKeyRequest: foreignKeyRequest, + originIsLeft: false) + + let associationKey: SQLAssociationKey + if let key = key { + associationKey = .fixedSingular(key) + } else { + associationKey = .inflected(Destination.databaseTableName) + } + + return HasOneAssociation(sqlAssociation: SQLAssociation( + key: associationKey, + condition: condition, + relation: Destination.all().relation, + cardinality: .toOne)) + } + + /// Creates a "Has One Through" association between Self and the + /// destination type. + /// + /// struct Book: TableRecord { + /// static let library = belongsTo(Library.self) + /// static let returnAddress = hasOne(Address.self, through: library, using: library.address) + /// } + /// + /// struct Library: TableRecord { + /// static let address = hasOne(Address.self) + /// } + /// + /// struct Address: TableRecord { ... } + /// + /// The association will let you define requests that load both the source + /// and the destination type: + /// + /// // A request for all (book, returnAddress) pairs: + /// let request = Book.including(required: Book.returnAddress) + /// + /// To consume those requests, define a type that adopts both the + /// FetchableRecord and Decodable protocols: + /// + /// struct Todo: FetchableRecord, Decodable { + /// var book: Book + /// var address: Address + /// } + /// + /// let todos = try dbQueue.read { db in + /// return try Todo.fetchAll(db, request) + /// } + /// for todo in todos { + /// print("Please return \(todo.book) to \(todo.address)") + /// } + /// + /// It is recommended that you define, alongside the static association, a + /// property with the same name: + /// + /// struct Book: TableRecord, EncodableRecord { + /// static let library = belongsTo(Library.self) + /// static let returnAddress = hasOne(Address.self, through: library, using: library.address) + /// var returnAddress: QueryInterfaceRequest
{ + /// return request(for: Book.returnAddress) + /// } + /// } + /// + /// This property will let you navigate from the source type to the + /// destination type: + /// + /// try dbQueue.read { db in + /// let book: Book = ... + /// let address = try book.returnAddress.fetchOne(db) // Address? + /// } + /// + /// - parameters: + /// - destination: The record type at the other side of the association. + /// - pivot: An association from Self to the intermediate type. + /// - target: A target association from the intermediate type to the + /// destination type. + /// - key: An eventual decoding key for the association. By default, it + /// is the same key as the target. + public static func hasOne( + _ destination: Target.RowDecoder.Type, + through pivot: Pivot, + using target: Target, + key: String? = nil) + -> HasOneThroughAssociation + where Pivot: AssociationToOne, + Target: AssociationToOne, + Pivot.OriginRowDecoder == Self, + Pivot.RowDecoder == Target.OriginRowDecoder + { + let association = HasOneThroughAssociation( + sqlAssociation: target.sqlAssociation.through(pivot.sqlAssociation)) + + if let key = key { + return association.forKey(key) + } else { + return association + } + } +} + +/// A ForeignKey helps building associations when GRDB can't infer a foreign +/// key from the database schema. +/// +/// Sometimes the database schema does not define any foreign key between two +/// tables. And sometimes, there are several foreign keys from a table +/// to another: +/// +/// | Table book | | Table person | +/// | ------------ | | ------------ | +/// | id | +-->• id | +/// | authorId •---+ | name | +/// | translatorId •---+ +/// | title | +/// +/// When this happens, associations can't be automatically inferred from the +/// database schema. GRDB will complain with a fatal error such as "Ambiguous +/// foreign key from book to person", or "Could not infer foreign key from book +/// to person". +/// +/// Your help is needed. You have to instruct GRDB which foreign key to use: +/// +/// struct Book: TableRecord { +/// // Define foreign keys +/// static let authorForeignKey = ForeignKey(["authorId"])) +/// static let translatorForeignKey = ForeignKey(["translatorId"])) +/// +/// // Use foreign keys to define associations: +/// static let author = belongsTo(Person.self, using: authorForeignKey) +/// static let translator = belongsTo(Person.self, using: translatorForeignKey) +/// } +/// +/// Foreign keys are always defined from the table that contains the columns at +/// the origin of the foreign key. Person's symmetric HasMany associations reuse +/// Book's foreign keys: +/// +/// struct Person: TableRecord { +/// static let writtenBooks = hasMany(Book.self, using: Book.authorForeignKey) +/// static let translatedBooks = hasMany(Book.self, using: Book.translatorForeignKey) +/// } +/// +/// Foreign keys can also be defined from query interface columns: +/// +/// struct Book: TableRecord { +/// enum Columns: String, ColumnExpression { +/// case id, title, authorId, translatorId +/// } +/// +/// static let authorForeignKey = ForeignKey([Columns.authorId])) +/// static let translatorForeignKey = ForeignKey([Columns.translatorId])) +/// } +/// +/// When the destination table of a foreign key does not define any primary key, +/// you need to provide the full definition of a foreign key: +/// +/// struct Book: TableRecord { +/// static let authorForeignKey = ForeignKey(["authorId"], to: ["id"])) +/// static let author = belongsTo(Person.self, using: authorForeignKey) +/// } +public struct ForeignKey { + var originColumns: [String] + var destinationColumns: [String]? + + /// Creates a ForeignKey intended to define a record association. + /// + /// struct Book: TableRecord { + /// // Define foreign keys + /// static let authorForeignKey = ForeignKey(["authorId"])) + /// static let translatorForeignKey = ForeignKey(["translatorId"])) + /// + /// // Use foreign keys to define associations: + /// static let author = belongsTo(Person.self, using: authorForeignKey) + /// static let translator = belongsTo(Person.self, using: translatorForeignKey) + /// } + /// + /// - parameter originColumns: The columns at the origin of the foreign key. + /// - parameter destinationColumns: The columns at the destination of the + /// foreign key. When nil (the default), GRDB automatically uses the + /// primary key. + public init(_ originColumns: [String], to destinationColumns: [String]? = nil) { + self.originColumns = originColumns + self.destinationColumns = destinationColumns + } + + /// Creates a ForeignKey intended to define a record association. + /// + /// struct Book: TableRecord { + /// // Define columns + /// enum Columns: String, ColumnExpression { + /// case id, title, authorId, translatorId + /// } + /// + /// // Define foreign keys + /// static let authorForeignKey = ForeignKey([Columns.authorId])) + /// static let translatorForeignKey = ForeignKey([Columns.translatorId])) + /// + /// // Use foreign keys to define associations: + /// static let author = belongsTo(Person.self, using: authorForeignKey) + /// static let translator = belongsTo(Person.self, using: translatorForeignKey) + /// } + /// + /// - parameter originColumns: The columns at the origin of the foreign key. + /// - parameter destinationColumns: The columns at the destination of the + /// foreign key. When nil (the default), GRDB automatically uses the + /// primary key. + public init(_ originColumns: [ColumnExpression], to destinationColumns: [ColumnExpression]? = nil) { + self.init(originColumns.map { $0.name }, to: destinationColumns?.map { $0.name }) + } +} + +extension TableRecord where Self: EncodableRecord { + /// Creates a request that fetches the associated record(s). + /// + /// For example: + /// + /// struct Team: TableRecord, EncodableRecord { + /// static let players = hasMany(Player.self) + /// var players: QueryInterfaceRequest { + /// return request(for: Team.players) + /// } + /// } + /// + /// let team: Team = ... + /// let players = try team.players.fetchAll(db) // [Player] + public func request(for association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == Self { + let destinationRelation = association.sqlAssociation.destinationRelation(fromOriginRows: { db in + try [Row(PersistenceContainer(db, self))] + }) + return QueryInterfaceRequest(relation: destinationRelation) + } +} + +extension TableRecord { + + // MARK: - Associations + + /// Creates a request that prefetches an association. + public static func including(all association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == Self { + return all().including(all: association) + } + + /// Creates a request that includes an association. The columns of the + /// associated record are selected. The returned association does not + /// require that the associated database table contains a matching row. + public static func including(optional association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == Self { + return all().including(optional: association) + } + + /// Creates a request that includes an association. The columns of the + /// associated record are selected. The returned association requires + /// that the associated database table contains a matching row. + public static func including(required association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == Self { + return all().including(required: association) + } + + /// Creates a request that includes an association. The columns of the + /// associated record are not selected. The returned association does not + /// require that the associated database table contains a matching row. + public static func joining(optional association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == Self { + return all().joining(optional: association) + } + + /// Creates a request that includes an association. The columns of the + /// associated record are not selected. The returned association requires + /// that the associated database table contains a matching row. + public static func joining(required association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == Self { + return all().joining(required: association) + } + + // MARK: - Association Aggregates + + /// Creates a request with *aggregates* appended to the selection. + /// + /// // SELECT player.*, COUNT(DISTINCT book.rowid) AS bookCount + /// // FROM player LEFT JOIN book ... + /// var request = Player.annotated(with: Player.books.count) + public static func annotated(with aggregates: AssociationAggregate...) -> QueryInterfaceRequest { + return all().annotated(with: aggregates) + } + + /// Creates a request with *aggregates* appended to the selection. + /// + /// // SELECT player.*, COUNT(DISTINCT book.rowid) AS bookCount + /// // FROM player LEFT JOIN book ... + /// var request = Player.annotated(with: [Player.books.count]) + public static func annotated(with aggregates: [AssociationAggregate]) -> QueryInterfaceRequest { + return all().annotated(with: aggregates) + } + + /// Creates a request with the provided aggregate *predicate*. + /// + /// // SELECT player.* + /// // FROM player LEFT JOIN book ... + /// // HAVING COUNT(DISTINCT book.rowid) = 0 + /// var request = Player.all() + /// request = request.having(Player.books.isEmpty) + /// + /// The selection defaults to all columns. This default can be changed for + /// all requests by the `TableRecord.databaseSelection` property, or + /// for individual requests with the `TableRecord.select` method. + public static func having(_ predicate: AssociationAggregate) -> QueryInterfaceRequest { + return all().having(predicate) + } +} diff --git a/GRDB/QueryInterface/QueryInterfaceRequest.swift b/GRDB/QueryInterface/TableRecord+QueryInterfaceRequest.swift similarity index 50% rename from GRDB/QueryInterface/QueryInterfaceRequest.swift rename to GRDB/QueryInterface/TableRecord+QueryInterfaceRequest.swift index 5d155f840..e759a39d0 100644 --- a/GRDB/QueryInterface/QueryInterfaceRequest.swift +++ b/GRDB/QueryInterface/TableRecord+QueryInterfaceRequest.swift @@ -1,300 +1,3 @@ -/// QueryInterfaceRequest is the type of requests generated by TableRecord: -/// -/// struct Player: TableRecord { ... } -/// let playerRequest = Player.all() // QueryInterfaceRequest -/// -/// It wraps an SQLSelectQuery, and has an attached type. -/// -/// The attached type helps decoding raw database values: -/// -/// try dbQueue.read { db in -/// try playerRequest.fetchAll(db) // [Player] -/// try playerRequest.asRequest(of: Row.self).fetchAll(db) // [Row] -/// } -/// -/// The attached type also helps the compiler validate associated requests: -/// -/// playerRequest.including(required: Player.team) // OK -/// fruitRequest.including(required: Player.team) // Does not compile - -/// A QueryInterfaceRequest describes an SQL query. -/// -/// See https://github.com/groue/GRDB.swift#the-query-interface -public struct QueryInterfaceRequest { - var query: SQLSelectQuery -} - -extension QueryInterfaceRequest : FetchRequest { - public typealias RowDecoder = T - - /// Returns a tuple that contains a prepared statement that is ready to be - /// executed, and an eventual row adapter. - /// - /// - parameter db: A database connection. - /// - returns: A prepared statement and an eventual row adapter. - /// :nodoc: - public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) { - return try SQLSelectQueryGenerator(query).prepare(db) - } - - /// Returns the number of rows fetched by the request. - /// - /// - parameter db: A database connection. - /// :nodoc: - public func fetchCount(_ db: Database) throws -> Int { - return try query.fetchCount(db) - } - - /// Returns the database region that the request looks into. - /// - /// - parameter db: A database connection. - /// :nodoc: - public func databaseRegion(_ db: Database) throws -> DatabaseRegion { - return try SQLSelectQueryGenerator(query).databaseRegion(db) - } -} - -extension QueryInterfaceRequest : DerivableRequest, AggregatingRequest { - - // MARK: Request Derivation - - /// Creates a request which selects *selection*. - /// - /// // SELECT id, email FROM player - /// var request = Player.all() - /// request = request.select([Column("id"), Column("email")]) - /// - /// Any previous selection is replaced: - /// - /// // SELECT email FROM player - /// request - /// .select([Column("id")]) - /// .select([Column("email")]) - public func select(_ selection: [SQLSelectable]) -> QueryInterfaceRequest { - return mapQuery { $0.select(selection) } - } - - /// Creates a request which selects *selection*, and fetches values of - /// type *type*. - /// - /// try dbQueue.read { db in - /// // SELECT max(score) FROM player - /// let request = Player.all().select([max(Column("score"))], as: Int.self) - /// let maxScore: Int? = try request.fetchOne(db) - /// } - public func select(_ selection: [SQLSelectable], as type: RowDecoder.Type) -> QueryInterfaceRequest { - return mapQuery { $0.select(selection) }.asRequest(of: RowDecoder.self) - } - - /// Creates a request which selects *selection*, and fetches values of - /// type *type*. - /// - /// try dbQueue.read { db in - /// // SELECT max(score) FROM player - /// let request = Player.all().select(max(Column("score")), as: Int.self) - /// let maxScore: Int? = try request.fetchOne(db) - /// } - public func select(_ selection: SQLSelectable..., as type: RowDecoder.Type) -> QueryInterfaceRequest { - return select(selection, as: type) - } - - /// Creates a request which selects *sql*, and fetches values of - /// type *type*. - /// - /// try dbQueue.read { db in - /// // SELECT max(score) FROM player - /// let request = Player.all().select(sql: "max(score)", as: Int.self) - /// let maxScore: Int? = try request.fetchOne(db) - /// } - public func select(sql: String, arguments: StatementArguments? = nil, as type: RowDecoder.Type) -> QueryInterfaceRequest { - return select(SQLSelectionLiteral(sql, arguments: arguments), as: type) - } - - /// Creates a request which appends *selection*. - /// - /// // SELECT id, email, name FROM player - /// var request = Player.all() - /// request = request - /// .select([Column("id"), Column("email")]) - /// .annotated(with: [Column("name")]) - public func annotated(with selection: [SQLSelectable]) -> QueryInterfaceRequest { - return mapQuery { $0.annotated(with: selection) } - } - - /// Creates a request which returns distinct rows. - /// - /// // SELECT DISTINCT * FROM player - /// var request = Player.all() - /// request = request.distinct() - /// - /// // SELECT DISTINCT name FROM player - /// var request = Player.select(Column("name")) - /// request = request.distinct() - public func distinct() -> QueryInterfaceRequest { - return mapQuery { $0.distinct() } - } - - /// Creates a request with the provided *predicate promise* added to the - /// eventual set of already applied predicates. - /// - /// // SELECT * FROM player WHERE 1 - /// var request = Player.all() - /// request = request.filter { db in true } - public func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> QueryInterfaceRequest { - return mapQuery { $0.filter(predicate) } - } - - /// Creates a request grouped according to *expressions promise*. - public func group(_ expressions: @escaping (Database) throws -> [SQLExpressible]) -> QueryInterfaceRequest { - return mapQuery { $0.group(expressions) } - } - - /// Creates a request with the provided *predicate* added to the - /// eventual set of already applied predicates. - public func having(_ predicate: SQLExpressible) -> QueryInterfaceRequest { - return mapQuery { $0.having(predicate) } - } - - /// Creates a request with the provided *orderings promise*. - /// - /// // SELECT * FROM player ORDER BY name - /// var request = Player.all() - /// request = request.order { _ in [Column("name")] } - /// - /// Any previous ordering is replaced: - /// - /// // SELECT * FROM player ORDER BY name - /// request - /// .order{ _ in [Column("email")] } - /// .reversed() - /// .order{ _ in [Column("name")] } - public func order(_ orderings: @escaping (Database) throws -> [SQLOrderingTerm]) -> QueryInterfaceRequest { - return mapQuery { $0.order(orderings) } - } - - /// Creates a request that reverses applied orderings. - /// - /// // SELECT * FROM player ORDER BY name DESC - /// var request = Player.all().order(Column("name")) - /// request = request.reversed() - /// - /// If no ordering was applied, the returned request is identical. - /// - /// // SELECT * FROM player - /// var request = Player.all() - /// request = request.reversed() - public func reversed() -> QueryInterfaceRequest { - return mapQuery { $0.reversed() } - } - - /// Creates a request which fetches *limit* rows, starting at *offset*. - /// - /// // SELECT * FROM player LIMIT 1 - /// var request = Player.all() - /// request = request.limit(1) - /// - /// Any previous limit is replaced. - public func limit(_ limit: Int, offset: Int? = nil) -> QueryInterfaceRequest { - return mapQuery { $0.limit(limit, offset: offset) } - } - - /// Creates a request that allows you to define expressions that target - /// a specific database table. - /// - /// In the example below, the "team.avgScore < player.score" condition in - /// the ON clause could be not achieved without table aliases. - /// - /// struct Player: TableRecord { - /// static let team = belongsTo(Team.self) - /// } - /// - /// // SELECT player.*, team.* - /// // JOIN team ON ... AND team.avgScore < player.score - /// let playerAlias = TableAlias() - /// let request = Player - /// .all() - /// .aliased(playerAlias) - /// .including(required: Player.team.filter(Column("avgScore") < playerAlias[Column("score")]) - public func aliased(_ alias: TableAlias) -> QueryInterfaceRequest { - return mapQuery { $0.qualified(with: alias) } - } - - /// Creates a request bound to type Target. - /// - /// The returned request can fetch if the type Target is fetchable (Row, - /// value, record). - /// - /// // Int? - /// let maxScore = try Player - /// .select(max(scoreColumn)) - /// .asRequest(of: Int.self) // <-- - /// .fetchOne(db) - /// - /// - parameter type: The fetched type Target - /// - returns: A typed request bound to type Target. - public func asRequest(of type: RowDecoder.Type) -> QueryInterfaceRequest { - return QueryInterfaceRequest(query: query) - } - - /// Returns a request whose query is transformed by the given closure. - func mapQuery(_ transform: (SQLSelectQuery) -> SQLSelectQuery) -> QueryInterfaceRequest { - var request = self - request.query = transform(query) - return request - } -} - -extension QueryInterfaceRequest { - /// Turns a request into a SQLRelation. - /// - /// This method helps initializing associations: - /// - /// struct Book: TableRecord { - /// // invokes Author.all().relation - /// static let author = belongsTo(Author.self) - /// } - var relation: SQLRelation { - let query = self.query - - // Prevent information loss - GRDBPrecondition(!query.isDistinct, "Not implemented: join distinct queries") - GRDBPrecondition(query.groupPromise == nil, "Can't join aggregated queries") - GRDBPrecondition(query.havingExpression == nil, "Can't join aggregated queries") - GRDBPrecondition(query.limit == nil, "Can't join limited queries") - - return query.relation - } -} - -/// Conditional conformance to TableRequest when RowDecoder conforms -/// to TableRecord: -/// -/// let request = Player.all() -/// request.filter(key: ...) -/// request.filter(keys: ...) -extension QueryInterfaceRequest: TableRequest where RowDecoder: TableRecord { - /// :nodoc: - public var databaseTableName: String { - return RowDecoder.databaseTableName - } -} - -extension QueryInterfaceRequest where T: MutablePersistableRecord { - - // MARK: Deleting - - /// Deletes matching rows; returns the number of deleted rows. - /// - /// - parameter db: A database connection. - /// - returns: The number of deleted rows - /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @discardableResult - public func deleteAll(_ db: Database) throws -> Int { - try SQLSelectQueryGenerator(query).makeDeleteStatement(db).execute() - return db.changesCount - } -} - extension TableRecord { // MARK: Request Derivation @@ -311,8 +14,7 @@ extension TableRecord { let relation = SQLRelation( source: .table(tableName: databaseTableName, alias: nil), selection: databaseSelection) - let query = SQLSelectQuery(relation: relation) - return QueryInterfaceRequest(query: query) + return QueryInterfaceRequest(relation: relation) } /// Creates a request which fetches no record. @@ -340,8 +42,16 @@ extension TableRecord { /// /// // SELECT id, email FROM player /// let request = Player.select(sql: "id, email") - public static func select(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest { - return all().select(sql: sql, arguments: arguments) + public static func select(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest { + return select(literal: SQLLiteral(sql: sql, arguments: arguments)) + } + + /// Creates a request which selects an SQL *literal*. + /// + /// // SELECT id, email FROM player + /// let request = Player.select(literal: SQLLiteral(sql: "id, email")) + public static func select(literal sqlLiteral: SQLLiteral) -> QueryInterfaceRequest { + return all().select(literal: sqlLiteral) } /// Creates a request which selects *selection*, and fetches values of @@ -376,10 +86,42 @@ extension TableRecord { /// let request = Player.select(sql: "max(score)", as: Int.self) /// let maxScore: Int? = try request.fetchOne(db) /// } - public static func select(sql: String, arguments: StatementArguments? = nil, as type: RowDecoder.Type) -> QueryInterfaceRequest { - return all().select(sql: sql, arguments: arguments, as: type) + public static func select(sql: String, arguments: StatementArguments = StatementArguments(), as type: RowDecoder.Type) -> QueryInterfaceRequest { + return all().select(literal: SQLLiteral(sql: sql, arguments: arguments), as: type) } - + + /// Creates a request which selects an SQL *literal*, and fetches values of + /// type *type*. + /// + /// try dbQueue.read { db in + /// // SELECT max(score) FROM player + /// let request = Player.select(literal: SQLLiteral(sql: "max(score)"), as: Int.self) + /// let maxScore: Int? = try request.fetchOne(db) + /// } + public static func select(literal sqlLiteral: SQLLiteral, as type: RowDecoder.Type) -> QueryInterfaceRequest { + return all().select(literal: sqlLiteral, as: type) + } + + /// Creates a request which appends *selection*. + /// + /// // SELECT id, email, name FROM player + /// le request = Player + /// .select([Column("id"), Column("email")]) + /// .annotated(with: [Column("name")]) + public static func annotated(with selection: [SQLSelectable]) -> QueryInterfaceRequest { + return all().annotated(with: selection) + } + + /// Creates a request which appends *selection*. + /// + /// // SELECT id, email, name FROM player + /// le request = Player + /// .select([Column("id"), Column("email")]) + /// .annotated(with: Column("name")) + public static func annotated(with selection: SQLSelectable...) -> QueryInterfaceRequest { + return all().annotated(with: selection) + } + /// Creates a request with the provided *predicate*. /// /// // SELECT * FROM player WHERE email = 'arthur@example.com' @@ -454,8 +196,26 @@ extension TableRecord { /// The selection defaults to all columns. This default can be changed for /// all requests by the `TableRecord.databaseSelection` property, or /// for individual requests with the `TableRecord.select` method. - public static func filter(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest { - return all().filter(sql: sql, arguments: arguments) + public static func filter(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest { + return filter(literal: SQLLiteral(sql: sql, arguments: arguments)) + } + + /// Creates a request with the provided *predicate*. + /// + /// // SELECT * FROM player WHERE email = 'arthur@example.com' + /// let request = Player.filter(literal: SQLLiteral(sql: "email = ?", arguments: ["arthur@example.com"])) + /// + /// With Swift 5, you can safely embed raw values in your SQL queries, + /// without any risk of syntax errors or SQL injection: + /// + /// let request = Player.filter(literal: "name = \("O'Brien")) + /// + /// The selection defaults to all columns. This default can be changed for + /// all requests by the `TableRecord.databaseSelection` property, or + /// for individual requests with the `TableRecord.select` method. + public static func filter(literal sqlLiteral: SQLLiteral) -> QueryInterfaceRequest { + // NOT TESTED + return all().filter(literal: sqlLiteral) } /// Creates a request sorted according to the @@ -507,8 +267,26 @@ extension TableRecord { /// The selection defaults to all columns. This default can be changed for /// all requests by the `TableRecord.databaseSelection` property, or /// for individual requests with the `TableRecord.select` method. - public static func order(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest { - return all().order(sql: sql, arguments: arguments) + public static func order(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest { + return all().order(literal: SQLLiteral(sql: sql, arguments: arguments)) + } + + /// Creates a request sorted according to an SQL *literal*. + /// + /// // SELECT * FROM player ORDER BY name + /// let request = Player.order(literal: SQLLiteral(sql: "name")) + /// + /// With Swift 5, you can safely embed raw values in your SQL queries, + /// without any risk of syntax errors or SQL injection: + /// + /// // SELECT * FROM player ORDER BY name + /// let request = Player.order(literal: "name")) + /// + /// The selection defaults to all columns. This default can be changed for + /// all requests by the `TableRecord.databaseSelection` property, or + /// for individual requests with the `TableRecord.select` method. + public static func order(literal sqlLiteral: SQLLiteral) -> QueryInterfaceRequest { + return all().order(literal: sqlLiteral) } /// Creates a request which fetches *limit* rows, starting at diff --git a/GRDB/Record/PersistableRecord+Encodable.swift b/GRDB/Record/EncodableRecord+Encodable.swift similarity index 98% rename from GRDB/Record/PersistableRecord+Encodable.swift rename to GRDB/Record/EncodableRecord+Encodable.swift index b3abf3782..f38439a71 100644 --- a/GRDB/Record/PersistableRecord+Encodable.swift +++ b/GRDB/Record/EncodableRecord+Encodable.swift @@ -1,9 +1,8 @@ import Foundation -extension MutablePersistableRecord where Self: Encodable { +extension EncodableRecord where Self: Encodable { public func encode(to container: inout PersistenceContainer) { - let persistenceContainer = PersistenceContainer() - let encoder = RecordEncoder(persistenceContainer: persistenceContainer) + let encoder = RecordEncoder(persistenceContainer: container) try! encode(to: encoder) container = encoder.persistenceContainer } @@ -12,7 +11,7 @@ extension MutablePersistableRecord where Self: Encodable { // MARK: - RecordEncoder /// The encoder that encodes a record into GRDB's PersistenceContainer -private class RecordEncoder: Encoder { +private class RecordEncoder: Encoder { var codingPath: [CodingKey] { return [] } var userInfo: [CodingUserInfoKey: Any] { return Record.databaseEncodingUserInfo } private var _persistenceContainer: PersistenceContainer @@ -163,7 +162,7 @@ private class RecordEncoder: Encoder { // MARK: - ColumnEncoder /// The encoder that encodes into a database column -private class ColumnEncoder: Encoder { +private class ColumnEncoder: Encoder { var recordEncoder: RecordEncoder var key: CodingKey var codingPath: [CodingKey] { return [key] } @@ -226,7 +225,7 @@ extension ColumnEncoder: SingleValueEncodingContainer { private struct JSONRequiredError: Error { } /// The encoder that always ends up with a JSONRequiredError -private struct JSONRequiredEncoder: Encoder { +private struct JSONRequiredEncoder: Encoder { var codingPath: [CodingKey] var userInfo: [CodingUserInfoKey: Any] { return Record.databaseEncodingUserInfo } diff --git a/GRDB/Record/EncodableRecord.swift b/GRDB/Record/EncodableRecord.swift new file mode 100644 index 000000000..378fe7950 --- /dev/null +++ b/GRDB/Record/EncodableRecord.swift @@ -0,0 +1,387 @@ +import Foundation // For JSONEncoder + +/// Types that adopt EncodableRecord can be encoded into the database. +public protocol EncodableRecord { + /// Encodes the record into database values. + /// + /// Store in the *container* argument all values that should be stored in + /// the columns of the database table (see databaseTableName()). + /// + /// Primary key columns, if any, must be included. + /// + /// struct Player: EncodableRecord { + /// var id: Int64? + /// var name: String? + /// + /// func encode(to container: inout PersistenceContainer) { + /// container["id"] = id + /// container["name"] = name + /// } + /// } + /// + /// It is undefined behavior to set different values for the same column. + /// Column names are case insensitive, so defining both "name" and "NAME" + /// is considered undefined behavior. + func encode(to container: inout PersistenceContainer) + + // MARK: - Customizing the Format of Database Columns + + /// When the EncodableRecord type also adopts the standard Encodable + /// protocol, you can use this dictionary to customize the encoding process + /// into database rows. + /// + /// For example: + /// + /// // A key that holds a encoder's name + /// let encoderName = CodingUserInfoKey(rawValue: "encoderName")! + /// + /// struct Player: PersistableRecord, Encodable { + /// // Customize the encoder name when encoding a database row + /// static let databaseEncodingUserInfo: [CodingUserInfoKey: Any] = [encoderName: "Database"] + /// + /// func encode(to encoder: Encoder) throws { + /// // Print the encoder name + /// print(encoder.userInfo[encoderName]) + /// ... + /// } + /// } + /// + /// let player = Player(...) + /// + /// // prints "Database" + /// try player.insert(db) + /// + /// // prints "JSON" + /// let encoder = JSONEncoder() + /// encoder.userInfo = [encoderName: "JSON"] + /// let data = try encoder.encode(player) + static var databaseEncodingUserInfo: [CodingUserInfoKey: Any] { get } + + /// When the EncodableRecord type also adopts the standard Encodable + /// protocol, this method controls the encoding process of nested properties + /// into JSON database columns. + /// + /// The default implementation returns a JSONEncoder with the + /// following properties: + /// + /// - dataEncodingStrategy: .base64 + /// - dateEncodingStrategy: .millisecondsSince1970 + /// - nonConformingFloatEncodingStrategy: .throw + /// - outputFormatting: .sortedKeys (iOS 11.0+, macOS 10.13+, watchOS 4.0+) + /// + /// You can override those defaults: + /// + /// struct Achievement: Encodable { + /// var name: String + /// var date: Date + /// } + /// + /// struct Player: Encodable, PersistableRecord { + /// // stored in a JSON column + /// var achievements: [Achievement] + /// + /// static func databaseJSONEncoder(for column: String) -> JSONEncoder { + /// let encoder = JSONEncoder() + /// encoder.dateEncodingStrategy = .iso8601 + /// return encoder + /// } + /// } + static func databaseJSONEncoder(for column: String) -> JSONEncoder + + /// When the EncodableRecord type also adopts the standard Encodable + /// protocol, this property controls the encoding of date properties. + /// + /// Default value is .deferredToDate + /// + /// For example: + /// + /// struct Player: PersistableRecord, Encodable { + /// static let databaseDateEncodingStrategy: DatabaseDateEncodingStrategy = .timeIntervalSince1970 + /// + /// var name: String + /// var registrationDate: Date // encoded as an epoch timestamp + /// } + static var databaseDateEncodingStrategy: DatabaseDateEncodingStrategy { get } + + /// When the EncodableRecord type also adopts the standard Encodable + /// protocol, this property controls the encoding of UUID properties. + /// + /// Default value is .deferredToUUID + /// + /// For example: + /// + /// struct Player: PersistableProtocol, Encodable { + /// static let databaseUUIDEncodingStrategy: DatabaseUUIDEncodingStrategy = .string + /// + /// // encoded in a string like "E621E1F8-C36C-495A-93FC-0C247A3E6E5F" + /// var uuid: UUID + /// } + static var databaseUUIDEncodingStrategy: DatabaseUUIDEncodingStrategy { get } +} + +extension EncodableRecord { + public static var databaseEncodingUserInfo: [CodingUserInfoKey: Any] { + return [:] + } + + public static func databaseJSONEncoder(for column: String) -> JSONEncoder { + let encoder = JSONEncoder() + encoder.dataEncodingStrategy = .base64 + encoder.dateEncodingStrategy = .millisecondsSince1970 + encoder.nonConformingFloatEncodingStrategy = .throw + if #available(watchOS 4.0, OSX 10.13, iOS 11.0, *) { + // guarantee some stability in order to ease record comparison + encoder.outputFormatting = .sortedKeys + } + return encoder + } + + public static var databaseDateEncodingStrategy: DatabaseDateEncodingStrategy { + return .deferredToDate + } + + public static var databaseUUIDEncodingStrategy: DatabaseUUIDEncodingStrategy { + return .deferredToUUID + } +} + +extension EncodableRecord { + /// A dictionary whose keys are the columns encoded in the `encode(to:)` method. + public var databaseDictionary: [String: DatabaseValue] { + return Dictionary(PersistenceContainer(self).storage).mapValues { $0?.databaseValue ?? .null } + } +} + +extension EncodableRecord { + + // MARK: - Record Comparison + + /// Returns a boolean indicating whether this record and the other record + /// have the same database representation. + public func databaseEquals(_ record: Self) -> Bool { + return PersistenceContainer(self).changesIterator(from: PersistenceContainer(record)).next() == nil + } + + /// A dictionary of values changed from the other record. + /// + /// Its keys are column names. Its values come from the other record. + /// + /// Note that this method is not symmetrical, not only in terms of values, + /// but also in terms of columns. When the two records don't define the + /// same set of columns in their `encode(to:)` method, only the columns + /// defined by the receiver record are considered. + public func databaseChanges(from record: Record) -> [String: DatabaseValue] { + return Dictionary(uniqueKeysWithValues: PersistenceContainer(self).changesIterator(from: PersistenceContainer(record))) + } +} + +// MARK: - PersistenceContainer + +/// Use persistence containers in the `encode(to:)` method of your +/// encodable records: +/// +/// struct Player: EncodableRecord { +/// var id: Int64? +/// var name: String? +/// +/// func encode(to container: inout PersistenceContainer) { +/// container["id"] = id +/// container["name"] = name +/// } +/// } +public struct PersistenceContainer { + // fileprivate for Row(_:PersistenceContainer) + // The ordering of the OrderedDictionary helps generating always the same + // SQL queries, and hit the statement cache. + @usableFromInline var storage: OrderedDictionary + + /// Accesses the value associated with the given column. + /// + /// It is undefined behavior to set different values for the same column. + /// Column names are case insensitive, so defining both "name" and "NAME" + /// is considered undefined behavior. + @inlinable + public subscript(_ column: String) -> DatabaseValueConvertible? { + get { return storage[column] ?? nil } + set { storage.updateValue(newValue, forKey: column) } + } + + /// Accesses the value associated with the given column. + /// + /// It is undefined behavior to set different values for the same column. + /// Column names are case insensitive, so defining both "name" and "NAME" + /// is considered undefined behavior. + @inlinable + public subscript(_ column: Column) -> DatabaseValueConvertible? { + get { return self[column.name] } + set { self[column.name] = newValue } + } + + init() { + storage = OrderedDictionary() + } + + init(minimumCapacity: Int) { + storage = OrderedDictionary(minimumCapacity: minimumCapacity) + } + + /// Convenience initializer from a record + init(_ record: Record) { + self.init() + record.encode(to: &self) + } + + /// Columns stored in the container, ordered like values. + var columns: [String] { + return Array(storage.keys) + } + + /// Values stored in the container, ordered like columns. + var values: [DatabaseValueConvertible?] { + return Array(storage.values) + } + + /// Accesses the value associated with the given column, in a + /// case-insensitive fashion. + /// + /// :nodoc: + subscript(caseInsensitive column: String) -> DatabaseValueConvertible? { + get { + if let value = storage[column] { + return value + } + let lowercaseColumn = column.lowercased() + for (key, value) in storage where key.lowercased() == lowercaseColumn { + return value + } + return nil + } + set { + if storage[column] != nil { + storage[column] = newValue + return + } + let lowercaseColumn = column.lowercased() + for key in storage.keys where key.lowercased() == lowercaseColumn { + storage[key] = newValue + return + } + + storage[column] = newValue + } + } + + // Returns nil if column is not defined + func value(forCaseInsensitiveColumn column: String) -> DatabaseValue? { + let lowercaseColumn = column.lowercased() + for (key, value) in storage where key.lowercased() == lowercaseColumn { + return value?.databaseValue ?? .null + } + return nil + } + + var isEmpty: Bool { + return storage.isEmpty + } + + /// An iterator over the (column, value) pairs + func makeIterator() -> IndexingIterator> { + return storage.makeIterator() + } + + func changesIterator(from container: PersistenceContainer) -> AnyIterator<(String, DatabaseValue)> { + var newValueIterator = makeIterator() + return AnyIterator { + // Loop until we find a change, or exhaust columns: + while let (column, newValue) = newValueIterator.next() { + let oldValue = container[caseInsensitive: column] + let oldDbValue = oldValue?.databaseValue ?? .null + let newDbValue = newValue?.databaseValue ?? .null + if newDbValue != oldDbValue { + return (column, oldDbValue) + } + } + return nil + } + } +} + +extension Row { + convenience init(_ record: Record) { + self.init(PersistenceContainer(record)) + } + + convenience init(_ container: PersistenceContainer) { + self.init(Dictionary(container.storage)) + } +} + +// MARK: - DatabaseDateEncodingStrategy + +/// DatabaseDateEncodingStrategy specifies how EncodableRecord types that also +/// adopt the standard Encodable protocol encode their date properties. +/// +/// For example: +/// +/// struct Player: EncodableRecord, Encodable { +/// static let databaseDateEncodingStrategy: DatabaseDateEncodingStrategy = .timeIntervalSince1970 +/// +/// var name: String +/// var registrationDate: Date // encoded as an epoch timestamp +/// } +public enum DatabaseDateEncodingStrategy { + /// The strategy that uses formatting from the Date structure. + /// + /// It encodes dates using the format "YYYY-MM-DD HH:MM:SS.SSS" in the + /// UTC time zone. + case deferredToDate + + /// Encodes a Double: the number of seconds between the date and + /// midnight UTC on 1 January 2001 + case timeIntervalSinceReferenceDate + + /// Encodes a Double: the number of seconds between the date and + /// midnight UTC on 1 January 1970 + case timeIntervalSince1970 + + /// Encodes an Int64: the number of seconds between the date and + /// midnight UTC on 1 January 1970 + case secondsSince1970 + + /// Encodes an Int64: the number of milliseconds between the date and + /// midnight UTC on 1 January 1970 + case millisecondsSince1970 + + /// Encodes dates according to the ISO 8601 and RFC 3339 standards + @available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) + case iso8601 + + /// Encodes a String, according to the provided formatter + case formatted(DateFormatter) + + /// Encodes the result of the user-provided function + case custom((Date) -> DatabaseValueConvertible?) +} + +// MARK: - DatabaseUUIDEncodingStrategy + +/// DatabaseUUIDEncodingStrategy specifies how EncodableRecord types that also +/// adopt the standard Encodable protocol encode their UUID properties. +/// +/// For example: +/// +/// struct Player: EncodableProtocol, Encodable { +/// static let databaseUUIDEncodingStrategy: DatabaseUUIDEncodingStrategy = .string +/// +/// // encoded in a string like "E621E1F8-C36C-495A-93FC-0C247A3E6E5F" +/// var uuid: UUID +/// } +public enum DatabaseUUIDEncodingStrategy { + /// The strategy that uses formatting from the UUID type. + /// + /// It encodes UUIDs as 16-bytes data blobs. + case deferredToUUID + + /// Encodes UUIDs as strings such as "E621E1F8-C36C-495A-93FC-0C247A3E6E5F" + case string +} diff --git a/GRDB/Record/FetchableRecord+Decodable.swift b/GRDB/Record/FetchableRecord+Decodable.swift index 3df51d649..e37963192 100644 --- a/GRDB/Record/FetchableRecord+Decodable.swift +++ b/GRDB/Record/FetchableRecord+Decodable.swift @@ -1,6 +1,8 @@ import Foundation #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif @@ -15,17 +17,31 @@ extension FetchableRecord where Self: Decodable { // MARK: - RowDecoder /// The decoder that decodes a record from a database row -private struct RowDecoder: Decoder { +private struct RowDecoder: Decoder { var row: Row var codingPath: [CodingKey] - var userInfo: [CodingUserInfoKey: Any] { return Record.databaseDecodingUserInfo } + var userInfo: [CodingUserInfoKey: Any] { return R.databaseDecodingUserInfo } func container(keyedBy type: Key.Type) throws -> KeyedDecodingContainer { return KeyedDecodingContainer(KeyedContainer(decoder: self)) } func unkeyedContainer() throws -> UnkeyedDecodingContainer { - fatalError("unkeyed decoding from database row is not supported") + guard let codingKey = codingPath.last else { + fatalError("unkeyed decoding from database row is not supported") + } + let keys = row.prefetchedRows.keys + let debugDescription: String + if keys.isEmpty { + debugDescription = "No available prefetched rows" + } else { + debugDescription = "Available keys for prefetched rows: \(keys.sorted())" + } + throw DecodingError.keyNotFound( + codingKey, + DecodingError.Context( + codingPath: Array(codingPath.dropLast()), // TODO: remove Array initializer when Swift >= 5 + debugDescription: debugDescription)) } func singleValueContainer() throws -> SingleValueDecodingContainer { @@ -40,7 +56,7 @@ private struct RowDecoder: Decoder { } // TODO: test // See DatabaseValueConversionErrorTests.testDecodableFetchableRecord2 - return ColumnDecoder(row: row, columnIndex: index, codingPath: codingPath) + return ColumnDecoder(row: row, columnIndex: index, codingPath: codingPath) } struct KeyedContainer: KeyedDecodingContainerProtocol { @@ -53,9 +69,10 @@ private struct RowDecoder: Decoder { var allKeys: [Key] { let row = decoder.row - let columnNames = Set(row.columnNames) - let scopeNames = Set(row.scopesTree.names) - return columnNames.union(scopeNames).compactMap { Key(stringValue: $0) } + return Set(row.columnNames) + .union(Set(row.scopesTree.names)) + .union(Set(row.prefetchedRows.keys)) + .compactMap { Key(stringValue: $0) } } func contains(_ key: Key) -> Bool { @@ -92,7 +109,7 @@ private struct RowDecoder: Decoder { // Prefer DatabaseValueConvertible decoding over Decodable. // This allows decoding Date from String, or DatabaseValue from NULL. if type == Date.self { - return Record.databaseDateDecodingStrategy.decodeIfPresent(fromRow: row, columnAtIndex: index) as! T? + return R.databaseDateDecodingStrategy.decodeIfPresent(fromRow: row, columnAtIndex: index) as! T? } else if let type = T.self as? (DatabaseValueConvertible & StatementColumnConvertible).Type { return type.fastDecodeIfPresent(from: row, atUncheckedIndex: index) as! T? } else if let type = T.self as? DatabaseValueConvertible.Type { @@ -104,7 +121,7 @@ private struct RowDecoder: Decoder { } } - // Scope? (beware left joins, and check if scoped row contains non-null values) + // Scope? (beware left joins: check if scoped row contains non-null values) if let scopedRow = row.scopesTree[keyName], scopedRow.containsNonNullValue { return try decode(type, fromRow: scopedRow, codingPath: codingPath + [key]) } @@ -122,7 +139,7 @@ private struct RowDecoder: Decoder { // Prefer DatabaseValueConvertible decoding over Decodable. // This allows decoding Date from String, or DatabaseValue from NULL. if type == Date.self { - return Record.databaseDateDecodingStrategy.decode(fromRow: row, columnAtIndex: index) as! T + return R.databaseDateDecodingStrategy.decode(fromRow: row, columnAtIndex: index) as! T } else if let type = T.self as? (DatabaseValueConvertible & StatementColumnConvertible).Type { return type.fastDecode(from: row, atUncheckedIndex: index) as! T } else if let type = T.self as? DatabaseValueConvertible.Type { @@ -137,6 +154,12 @@ private struct RowDecoder: Decoder { return try decode(type, fromRow: scopedRow, codingPath: codingPath + [key]) } + // Prefetched Rows? + if let prefetchedRows = row.prefetchedRows[keyName] { + let decoder = PrefetchedRowsDecoder(rows: prefetchedRows, codingPath: codingPath) + return try T(from: decoder) + } + // Key is not a column, and not a scope. // // Should be throw an error? Well... The use case is the following: @@ -217,7 +240,7 @@ private struct RowDecoder: Decoder { // or unkeyed containers, because we're decoding a single // value here (string, int, double, data, null). If such an // error happens, we'll switch to JSON decoding. - let columnDecoder = ColumnDecoder( + let columnDecoder = ColumnDecoder( row: row, columnIndex: index, codingPath: codingPath + [key]) @@ -227,7 +250,7 @@ private struct RowDecoder: Decoder { guard let data = row.dataNoCopy(atIndex: index) else { fatalConversionError(to: T.self, from: row[index], conversionContext: ValueConversionContext(row).atColumn(index)) } - return try Record + return try R .databaseJSONDecoder(for: key.stringValue) .decode(type.self, from: data) } @@ -235,14 +258,73 @@ private struct RowDecoder: Decoder { } } +// MARK: - PrefetchedRowsDecoder + +private struct PrefetchedRowsDecoder: Decoder { + var rows: [Row] + var codingPath: [CodingKey] + var currentIndex: Int + var userInfo: [CodingUserInfoKey: Any] { return R.databaseDecodingUserInfo } + + init(rows: [Row], codingPath: [CodingKey]) { + self.rows = rows + self.codingPath = codingPath + self.currentIndex = 0 + } + + func container(keyedBy type: Key.Type) throws -> KeyedDecodingContainer where Key : CodingKey { + fatalError("keyed decoding from prefetched rows is not supported") + } + + func unkeyedContainer() throws -> UnkeyedDecodingContainer { + return self + } + + func singleValueContainer() throws -> SingleValueDecodingContainer { + fatalError("single value decoding from prefetched rows is not supported") + } +} + +extension PrefetchedRowsDecoder: UnkeyedDecodingContainer { + var count: Int? { + return rows.count + } + + var isAtEnd: Bool { + return currentIndex >= rows.count + } + + mutating func decodeNil() throws -> Bool { + return false + } + + mutating func decode(_ type: T.Type) throws -> T where T : Decodable { + defer { currentIndex += 1 } + let decoder = RowDecoder(row: rows[currentIndex], codingPath: codingPath) + return try T(from: decoder) + } + + mutating func nestedContainer(keyedBy type: NestedKey.Type) throws -> KeyedDecodingContainer where NestedKey : CodingKey { + fatalError("not implemented") + } + + mutating func nestedUnkeyedContainer() throws -> UnkeyedDecodingContainer { + fatalError("not implemented") + } + + mutating func superDecoder() throws -> Decoder { + fatalError("not implemented") + } +} + // MARK: - ColumnDecoder /// The decoder that decodes from a database column -private struct ColumnDecoder: Decoder { +private struct ColumnDecoder: Decoder { var row: Row var columnIndex: Int var codingPath: [CodingKey] - var userInfo: [CodingUserInfoKey: Any] { return Record.databaseDecodingUserInfo } + var userInfo: [CodingUserInfoKey: Any] { return R.databaseDecodingUserInfo } func container(keyedBy type: Key.Type) throws -> KeyedDecodingContainer { // We need to switch to JSON decoding @@ -283,7 +365,7 @@ extension ColumnDecoder: SingleValueDecodingContainer { // Prefer DatabaseValueConvertible decoding over Decodable. // This allows decoding Date from String, or DatabaseValue from NULL. if type == Date.self { - return Record.databaseDateDecodingStrategy.decode(fromRow: row, columnAtIndex: columnIndex) as! T + return R.databaseDateDecodingStrategy.decode(fromRow: row, columnAtIndex: columnIndex) as! T } else if let type = T.self as? (DatabaseValueConvertible & StatementColumnConvertible).Type { return type.fastDecode(from: row, atUncheckedIndex: columnIndex) as! T } else if let type = T.self as? DatabaseValueConvertible.Type { diff --git a/GRDB/Record/FetchableRecord.swift b/GRDB/Record/FetchableRecord.swift index 783ec7791..da3f35872 100644 --- a/GRDB/Record/FetchableRecord.swift +++ b/GRDB/Record/FetchableRecord.swift @@ -1,23 +1,25 @@ import Foundation #if SWIFT_PACKAGE import CSQLite +#elseif GRDBCIPHER + import SQLCipher #elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER import SQLite3 #endif /// Types that adopt FetchableRecord can be initialized from a database Row. /// -/// let row = try Row.fetchOne(db, "SELECT ...")! +/// let row = try Row.fetchOne(db, sql: "SELECT ...")! /// let player = Player(row) /// /// The protocol comes with built-in methods that allow to fetch cursors, /// arrays, or single records: /// -/// try Player.fetchCursor(db, "SELECT ...", arguments:...) // Cursor of Player -/// try Player.fetchAll(db, "SELECT ...", arguments:...) // [Player] -/// try Player.fetchOne(db, "SELECT ...", arguments:...) // Player? +/// try Player.fetchCursor(db, sql: "SELECT ...", arguments:...) // Cursor of Player +/// try Player.fetchAll(db, sql: "SELECT ...", arguments:...) // [Player] +/// try Player.fetchOne(db, sql: "SELECT ...", arguments:...) // Player? /// -/// let statement = try db.makeSelectStatement("SELECT ...") +/// let statement = try db.makeSelectStatement(sql: "SELECT ...") /// try Player.fetchCursor(statement, arguments:...) // Cursor of Player /// try Player.fetchAll(statement, arguments:...) // [Player] /// try Player.fetchOne(statement, arguments:...) // Player? @@ -141,7 +143,7 @@ extension FetchableRecord { /// A cursor over records fetched from a prepared statement. /// - /// let statement = try db.makeSelectStatement("SELECT * FROM player") + /// let statement = try db.makeSelectStatement(sql: "SELECT * FROM player") /// let players = try Player.fetchCursor(statement) // Cursor of Player /// while let player = try players.next() { // Player /// ... @@ -164,7 +166,7 @@ extension FetchableRecord { /// Returns an array of records fetched from a prepared statement. /// - /// let statement = try db.makeSelectStatement("SELECT * FROM player") + /// let statement = try db.makeSelectStatement(sql: "SELECT * FROM player") /// let players = try Player.fetchAll(statement) // [Player] /// /// - parameters: @@ -179,7 +181,7 @@ extension FetchableRecord { /// Returns a single record fetched from a prepared statement. /// - /// let statement = try db.makeSelectStatement("SELECT * FROM player") + /// let statement = try db.makeSelectStatement(sql: "SELECT * FROM player") /// let player = try Player.fetchOne(statement) // Player? /// /// - parameters: @@ -199,7 +201,7 @@ extension FetchableRecord { /// Returns a cursor over records fetched from an SQL query. /// - /// let players = try Player.fetchCursor(db, "SELECT * FROM player") // Cursor of Player + /// let players = try Player.fetchCursor(db, sql: "SELECT * FROM player") // Cursor of Player /// while let player = try players.next() { // Player /// ... /// } @@ -212,42 +214,42 @@ extension FetchableRecord { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RecordCursor { - return try fetchCursor(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + public static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> RecordCursor { + return try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns an array of records fetched from an SQL query. /// - /// let players = try Player.fetchAll(db, "SELECT * FROM player") // [Player] + /// let players = try Player.fetchAll(db, sql: "SELECT * FROM player") // [Player] /// /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An array of records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] { - return try fetchAll(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + public static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] { + return try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns a single record fetched from an SQL query. /// - /// let player = try Player.fetchOne(db, "SELECT * FROM player") // Player? + /// let player = try Player.fetchOne(db, sql: "SELECT * FROM player") // Player? /// /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An optional record. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? { - return try fetchOne(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + public static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? { + return try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } @@ -274,7 +276,7 @@ extension FetchableRecord { /// - returns: A cursor over fetched records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. public static func fetchCursor(_ db: Database, _ request: R) throws -> RecordCursor { - let (statement, adapter) = try request.prepare(db) + let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchCursor(statement, adapter: adapter) } @@ -289,7 +291,7 @@ extension FetchableRecord { /// - returns: An array of records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. public static func fetchAll(_ db: Database, _ request: R) throws -> [Self] { - let (statement, adapter) = try request.prepare(db) + let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchAll(statement, adapter: adapter) } @@ -304,7 +306,7 @@ extension FetchableRecord { /// - returns: An optional record. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. public static func fetchOne(_ db: Database, _ request: R) throws -> Self? { - let (statement, adapter) = try request.prepare(db) + let (statement, adapter) = try request.prepare(db, forSingleResult: true) return try fetchOne(statement, adapter: adapter) } } @@ -317,7 +319,7 @@ extension FetchRequest where RowDecoder: FetchableRecord { /// A cursor over fetched records. /// - /// let request: ... // Some TypedRequest that fetches Player + /// let request: ... // Some FetchRequest that fetches Player /// let players = try request.fetchCursor(db) // Cursor of Player /// while let player = try players.next() { // Player /// ... @@ -337,7 +339,7 @@ extension FetchRequest where RowDecoder: FetchableRecord { /// An array of fetched records. /// - /// let request: ... // Some TypedRequest that fetches Player + /// let request: ... // Some FetchRequest that fetches Player /// let players = try request.fetchAll(db) // [Player] /// /// - parameter db: A database connection. @@ -349,7 +351,7 @@ extension FetchRequest where RowDecoder: FetchableRecord { /// The first fetched record. /// - /// let request: ... // Some TypedRequest that fetches Player + /// let request: ... // Some FetchRequest that fetches Player /// let player = try request.fetchOne(db) // Player? /// /// - parameter db: A database connection. @@ -366,43 +368,43 @@ extension FetchRequest where RowDecoder: FetchableRecord { /// /// struct Player : FetchableRecord { ... } /// try dbQueue.read { db in -/// let players: RecordCursor = try Player.fetchCursor(db, "SELECT * FROM player") +/// let players: RecordCursor = try Player.fetchCursor(db, sql: "SELECT * FROM player") /// } public final class RecordCursor : Cursor { - private let statement: SelectStatement - private let row: Row // Reused for performance - private let sqliteStatement: SQLiteStatement - private var done = false + @usableFromInline let _statement: SelectStatement + @usableFromInline let _row: Row // Reused for performance + @usableFromInline let _sqliteStatement: SQLiteStatement + @usableFromInline var _done = false init(statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { - self.statement = statement - self.row = try Row(statement: statement).adapted(with: adapter, layout: statement) - self.sqliteStatement = statement.sqliteStatement - statement.reset(withArguments: arguments) + _statement = statement + _row = try Row(statement: statement).adapted(with: adapter, layout: statement) + _sqliteStatement = statement.sqliteStatement + _statement.reset(withArguments: arguments) } deinit { // Statement reset fails when sqlite3_step has previously failed. // Just ignore reset error. - try? statement.reset() + try? _statement.reset() } /// :nodoc: + @inlinable public func next() throws -> Record? { - if done { + if _done { // make sure this instance never yields a value again, even if the // statement is reset by another cursor. return nil } - switch sqlite3_step(sqliteStatement) { + switch sqlite3_step(_sqliteStatement) { case SQLITE_DONE: - done = true + _done = true return nil case SQLITE_ROW: - return Record(row: row) + return Record(row: _row) case let code: - statement.database.selectStatementDidFail(statement) - throw DatabaseError(resultCode: code, message: statement.database.lastErrorMessage, sql: statement.sql, arguments: statement.arguments) + try _statement.didFail(withResultCode: code) } } } diff --git a/GRDB/Record/FetchedRecordsController.swift b/GRDB/Record/FetchedRecordsController.swift index f4e3ca161..8238fc995 100644 --- a/GRDB/Record/FetchedRecordsController.swift +++ b/GRDB/Record/FetchedRecordsController.swift @@ -40,14 +40,14 @@ public final class FetchedRecordsController { public convenience init( _ databaseWriter: DatabaseWriter, sql: String, - arguments: StatementArguments? = nil, + arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil, queue: DispatchQueue = .main, isSameRecord: ((Record, Record) -> Bool)? = nil) throws { try self.init( databaseWriter, - request: SQLRequest(sql, arguments: arguments, adapter: adapter), + request: SQLRequest(sql: sql, arguments: arguments, adapter: adapter), queue: queue, isSameRecord: isSameRecord) } @@ -196,8 +196,8 @@ public final class FetchedRecordsController { /// /// This method must be used from the controller's dispatch queue (the /// main queue unless stated otherwise in the controller's initializer). - public func setRequest(sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { - try setRequest(SQLRequest(sql, arguments: arguments, adapter: adapter)) + public func setRequest(sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws { + try setRequest(SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Registers changes notification callbacks. @@ -429,13 +429,13 @@ extension FetchedRecordsController where Record: TableRecord { public convenience init( _ databaseWriter: DatabaseWriter, sql: String, - arguments: StatementArguments? = nil, + arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil, queue: DispatchQueue = .main) throws { try self.init( databaseWriter, - request: SQLRequest(sql, arguments: arguments, adapter: adapter), + request: SQLRequest(sql: sql, arguments: arguments, adapter: adapter), queue: queue) } @@ -879,7 +879,7 @@ extension FetchedRecordsController { } } -extension FetchedRecordsController where Record: MutablePersistableRecord { +extension FetchedRecordsController where Record: EncodableRecord { /// Returns the indexPath of a given record. /// @@ -887,7 +887,7 @@ extension FetchedRecordsController where Record: MutablePersistableRecord { /// if record could not be found. public func indexPath(for record: Record) -> IndexPath? { let item = Item(row: Row(record)) - guard let fetchedItems = fetchedItems, let index = fetchedItems.index(where: { itemsAreIdentical($0, item) }) else { + guard let fetchedItems = fetchedItems, let index = fetchedItems.firstIndex(where: { itemsAreIdentical($0, item) }) else { return nil } return IndexPath(indexes: [0, index]) diff --git a/GRDB/Record/PersistableRecord.swift b/GRDB/Record/PersistableRecord.swift index 3c454cfcf..1fb4772ea 100644 --- a/GRDB/Record/PersistableRecord.swift +++ b/GRDB/Record/PersistableRecord.swift @@ -1,6 +1,5 @@ -import Foundation - extension Database.ConflictResolution { + @usableFromInline var invalidatesLastInsertedRowID: Bool { switch self { case .abort, .fail, .rollback, .replace: @@ -12,14 +11,15 @@ extension Database.ConflictResolution { } } -// MARK: - PersistenceError - /// An error thrown by a type that adopts PersistableRecord. public enum PersistenceError: Error, CustomStringConvertible { /// Thrown by MutablePersistableRecord.update() when no matching row could be /// found in the database. - case recordNotFound(MutablePersistableRecord) + /// + /// - databaseTableName: the table of the unfound record + /// - key: the key of the unfound record (column and values) + case recordNotFound(databaseTableName: String, key: [String: DatabaseValue]) } // CustomStringConvertible @@ -27,138 +27,13 @@ extension PersistenceError { /// :nodoc: public var description: String { switch self { - case .recordNotFound(let record): - return "Not found: \(record)" + case let .recordNotFound(databaseTableName: databaseTableName, key: key): + let row = Row(key) // For nice output + return "Key not found in table \(databaseTableName): \(row.description)" } } } -// MARK: - PersistenceContainer - -/// Use persistence containers in the `encode(to:)` method of your -/// encodable records: -/// -/// struct Player : MutablePersistableRecord { -/// var id: Int64? -/// var name: String? -/// -/// func encode(to container: inout PersistenceContainer) { -/// container["id"] = id -/// container["name"] = name -/// } -/// } -public struct PersistenceContainer { - // fileprivate for Row(_:PersistenceContainer) - fileprivate var storage: [String: DatabaseValueConvertible?] - - /// Accesses the value associated with the given column. - /// - /// It is undefined behavior to set different values for the same column. - /// Column names are case insensitive, so defining both "name" and "NAME" - /// is considered undefined behavior. - public subscript(_ column: String) -> DatabaseValueConvertible? { - get { return storage[column] ?? nil } - set { storage.updateValue(newValue, forKey: column) } - } - - /// Accesses the value associated with the given column. - /// - /// It is undefined behavior to set different values for the same column. - /// Column names are case insensitive, so defining both "name" and "NAME" - /// is considered undefined behavior. - public subscript(_ column: ColumnExpression) -> DatabaseValueConvertible? { - get { return self[column.name] } - set { self[column.name] = newValue } - } - - init() { - storage = [:] - } - - /// Convenience initializer from a record - /// - /// // Sweet - /// let container = PersistenceContainer(record) - /// - /// // Meh - /// var container = PersistenceContainer() - /// record.encode(to: container) - init(_ record: MutablePersistableRecord) { - storage = [:] - record.encode(to: &self) - } - - /// Columns stored in the container, ordered like values. - var columns: [String] { - return Array(storage.keys) - } - - /// Values stored in the container, ordered like columns. - var values: [DatabaseValueConvertible?] { - return Array(storage.values) - } - - /// Accesses the value associated with the given column, in a - /// case-insensitive fashion. - /// - /// :nodoc: - subscript(caseInsensitive column: String) -> DatabaseValueConvertible? { - get { - if let value = storage[column] { - return value - } - let lowercaseColumn = column.lowercased() - for (key, value) in storage where key.lowercased() == lowercaseColumn { - return value - } - return nil - } - set { - if storage[column] != nil { - storage[column] = newValue - return - } - let lowercaseColumn = column.lowercased() - for key in storage.keys where key.lowercased() == lowercaseColumn { - storage[key] = newValue - return - } - - storage[column] = newValue - } - } - - // Returns nil if column is not defined - func value(forCaseInsensitiveColumn column: String) -> DatabaseValue? { - let lowercaseColumn = column.lowercased() - for (key, value) in storage where key.lowercased() == lowercaseColumn { - return value?.databaseValue ?? .null - } - return nil - } - - var isEmpty: Bool { - return storage.isEmpty - } - - /// An iterator over the (column, value) pairs - func makeIterator() -> DictionaryIterator { - return storage.makeIterator() - } -} - -extension Row { - convenience init(_ record: MutablePersistableRecord) { - self.init(PersistenceContainer(record)) - } - - convenience init(_ container: PersistenceContainer) { - self.init(container.storage) - } -} - -// MARK: - MutablePersistableRecord - /// The MutablePersistableRecord protocol uses this type in order to handle SQLite /// conflicts when records are inserted or updated. /// @@ -180,7 +55,7 @@ public struct PersistenceConflictPolicy { } /// Types that adopt MutablePersistableRecord can be inserted, updated, and deleted. -public protocol MutablePersistableRecord : TableRecord { +public protocol MutablePersistableRecord : EncodableRecord, TableRecord { /// The policy that handles SQLite conflicts when records are inserted /// or updated. /// @@ -195,28 +70,6 @@ public protocol MutablePersistableRecord : TableRecord { /// See https://www.sqlite.org/lang_conflict.html static var persistenceConflictPolicy: PersistenceConflictPolicy { get } - /// Defines the values persisted in the database. - /// - /// Store in the *container* argument all values that should be stored in - /// the columns of the database table (see databaseTableName()). - /// - /// Primary key columns, if any, must be included. - /// - /// struct Player : MutablePersistableRecord { - /// var id: Int64? - /// var name: String? - /// - /// func encode(to container: inout PersistenceContainer) { - /// container["id"] = id - /// container["name"] = name - /// } - /// } - /// - /// It is undefined behavior to set different values for the same column. - /// Column names are case insensitive, so defining both "name" and "NAME" - /// is considered undefined behavior. - func encode(to container: inout PersistenceContainer) - /// Notifies the record that it was succesfully inserted. /// /// Do not call this method directly: it is called for you, in a protected @@ -322,134 +175,6 @@ public protocol MutablePersistableRecord : TableRecord { /// - returns: Whether the primary key matches a row in the database. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. func exists(_ db: Database) throws -> Bool - - // MARK: - Customizing the Format of Database Columns - - /// When the PersistableRecord type also adopts the standard Encodable - /// protocol, you can use this dictionary to customize the encoding process - /// into database rows. - /// - /// For example: - /// - /// // A key that holds a encoder's name - /// let encoderName = CodingUserInfoKey(rawValue: "encoderName")! - /// - /// // A PersistableRecord + Encodable record - /// struct Player: PersistableRecord, Encodable { - /// // Customize the encoder name when encoding a database row - /// static let databaseEncodingUserInfo: [CodingUserInfoKey: Any] = [encoderName: "Database"] - /// - /// func encode(to encoder: Encoder) throws { - /// // Print the encoder name - /// print(encoder.userInfo[encoderName]) - /// ... - /// } - /// } - /// - /// let player = Player(...) - /// - /// // prints "Database" - /// try player.insert(db) - /// - /// // prints "JSON" - /// let encoder = JSONEncoder() - /// encoder.userInfo = [encoderName: "JSON"] - /// let data = try encoder.encode(player) - static var databaseEncodingUserInfo: [CodingUserInfoKey: Any] { get } - - /// When the PersistableRecord type also adopts the standard Encodable - /// protocol, this method controls the encoding process of nested properties - /// into JSON database columns. - /// - /// The default implementation returns a JSONEncoder with the - /// following properties: - /// - /// - dataEncodingStrategy: .base64 - /// - dateEncodingStrategy: .millisecondsSince1970 - /// - nonConformingFloatEncodingStrategy: .throw - /// - outputFormatting: .sortedKeys (iOS 11.0+, macOS 10.13+, watchOS 4.0+) - /// - /// You can override those defaults: - /// - /// struct Achievement: Encodable { - /// var name: String - /// var date: Date - /// } - /// - /// struct Player: Encodable, PersistableRecord { - /// // stored in a JSON column - /// var achievements: [Achievement] - /// - /// static func databaseJSONEncoder(for column: String) -> JSONEncoder { - /// let encoder = JSONEncoder() - /// encoder.dateEncodingStrategy = .iso8601 - /// return encoder - /// } - /// } - static func databaseJSONEncoder(for column: String) -> JSONEncoder - - /// When the PersistableRecord type also adopts the standard Encodable - /// protocol, this property controls the encoding of date properties. - /// - /// Default value is .deferredToDate - /// - /// For example: - /// - /// struct Player: PersistableRecord, Encodable { - /// static let databaseDateEncodingStrategy: DatabaseDateEncodingStrategy = .timeIntervalSince1970 - /// - /// var name: String - /// var registrationDate: Date // encoded as an epoch timestamp - /// } - static var databaseDateEncodingStrategy: DatabaseDateEncodingStrategy { get } - - /// When the PersistableRecord type also adopts the standard Encodable - /// protocol, this property controls the encoding of UUID properties. - /// - /// Default value is .deferredToUUID - /// - /// For example: - /// - /// struct Player: PersistableProtocol, Encodable { - /// static let databaseUUIDEncodingStrategy: DatabaseUUIDEncodingStrategy = .string - /// - /// // encoded in a string like "E621E1F8-C36C-495A-93FC-0C247A3E6E5F" - /// var uuid: UUID - /// } - static var databaseUUIDEncodingStrategy: DatabaseUUIDEncodingStrategy { get } -} - -extension MutablePersistableRecord { - public static var databaseEncodingUserInfo: [CodingUserInfoKey: Any] { - return [:] - } - - public static func databaseJSONEncoder(for column: String) -> JSONEncoder { - let encoder = JSONEncoder() - encoder.dataEncodingStrategy = .base64 - encoder.dateEncodingStrategy = .millisecondsSince1970 - encoder.nonConformingFloatEncodingStrategy = .throw - if #available(watchOS 4.0, OSX 10.13, iOS 11.0, *) { - // guarantee some stability in order to ease record comparison - encoder.outputFormatting = .sortedKeys - } - return encoder - } - - public static var databaseDateEncodingStrategy: DatabaseDateEncodingStrategy { - return .deferredToDate - } - - public static var databaseUUIDEncodingStrategy: DatabaseUUIDEncodingStrategy { - return .deferredToUUID - } -} - -extension MutablePersistableRecord { - /// A dictionary whose keys are the columns encoded in the `encode(to:)` method. - public var databaseDictionary: [String: DatabaseValue] { - return PersistenceContainer(self).storage.mapValues { $0?.databaseValue ?? .null } - } } extension MutablePersistableRecord { @@ -545,8 +270,8 @@ extension MutablePersistableRecord { /// match any row in the database and record could not be updated. /// - SeeAlso: updateChanges(_:with:) @discardableResult - public func updateChanges(_ db: Database, from record: MutablePersistableRecord) throws -> Bool { - return try updateChanges(db, from: PersistenceContainer(record)) + public func updateChanges(_ db: Database, from record: Record) throws -> Bool { + return try updateChanges(db, from: PersistenceContainer(db, record)) } /// Mutates the record according to the provided closure, and then, if the @@ -574,7 +299,7 @@ extension MutablePersistableRecord { /// match any row in the database and record could not be updated. @discardableResult public mutating func updateChanges(_ db: Database, with change: (inout Self) throws -> Void) throws -> Bool { - let container = PersistenceContainer(self) + let container = try PersistenceContainer(db, self) try change(&self) return try updateChanges(db, from: container) } @@ -605,43 +330,9 @@ extension MutablePersistableRecord { // MARK: - Record Comparison - /// Returns a boolean indicating whether this record and the other record - /// have the same database representation. - public func databaseEquals(_ record: Self) -> Bool { - return databaseChangesIterator(from: PersistenceContainer(record)).next() == nil - } - - /// A dictionary of values changed from the other record. - /// - /// Its keys are column names. Its values come from the other record. - /// - /// Note that this method is not symmetrical, not only in terms of values, - /// but also in terms of columns. When the two records don't define the - /// same set of columns in their `encode(to:)` method, only the columns - /// defined by the receiver record are considered. - public func databaseChanges(from record: MutablePersistableRecord) -> [String: DatabaseValue] { - return Dictionary(uniqueKeysWithValues: databaseChangesIterator(from: PersistenceContainer(record))) - } - - private func databaseChangesIterator(from container: PersistenceContainer) -> AnyIterator<(String, DatabaseValue)> { - var newValueIterator = PersistenceContainer(self).makeIterator() - return AnyIterator { - // Loop until we find a change, or exhaust columns: - while let (column, newValue) = newValueIterator.next() { - let oldValue = container[caseInsensitive: column] - let oldDbValue = oldValue?.databaseValue ?? .null - let newDbValue = newValue?.databaseValue ?? .null - if newDbValue != oldDbValue { - return (column, oldDbValue) - } - } - return nil - } - } - @discardableResult fileprivate func updateChanges(_ db: Database, from container: PersistenceContainer) throws -> Bool { - let changes = databaseChangesIterator(from: container) + let changes = try PersistenceContainer(db, self).changesIterator(from: container) let changedColumns: Set = changes.reduce(into: []) { $0.insert($1.0) } if changedColumns.isEmpty { return false @@ -652,17 +343,19 @@ extension MutablePersistableRecord { // MARK: - CRUD Internals - /// Return true if record has a non-null primary key - fileprivate func canUpdate(_ db: Database) throws -> Bool { + /// Return a non-nil dictionary if record has a non-null primary key + @usableFromInline + func primaryKey(_ db: Database) throws -> [String: DatabaseValue]? { let databaseTableName = type(of: self).databaseTableName - let primaryKey = try db.primaryKey(databaseTableName) - let container = PersistenceContainer(self) - for column in primaryKey.columns { - if let value = container[caseInsensitive: column], !value.databaseValue.isNull { - return true - } + let primaryKeyInfo = try db.primaryKey(databaseTableName) + let container = try PersistenceContainer(db, self) + let primaryKey = Dictionary(uniqueKeysWithValues: primaryKeyInfo.columns.map { + ($0, container[caseInsensitive: $0]?.databaseValue ?? .null) + }) + if primaryKey.allSatisfy({ $0.value.isNull }) { + return nil } - return false + return primaryKey } /// Don't invoke this method directly: it is an internal method for types @@ -672,6 +365,7 @@ extension MutablePersistableRecord { /// that adopt MutablePersistableRecord can invoke performInsert() in their /// implementation of insert(). They should not provide their own /// implementation of performInsert(). + @inlinable public mutating func performInsert(_ db: Database) throws { let conflictResolutionForInsert = type(of: self).persistenceConflictPolicy.conflictResolutionForInsert let dao = try DAO(db, self) @@ -695,14 +389,16 @@ extension MutablePersistableRecord { /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. /// PersistenceError.recordNotFound is thrown if the primary key does not /// match any row in the database. + @inlinable public func performUpdate(_ db: Database, columns: Set) throws { - guard let statement = try DAO(db, self).updateStatement(db, columns: columns, onConflict: type(of: self).persistenceConflictPolicy.conflictResolutionForUpdate) else { + let dao = try DAO(db, self) + guard let statement = try dao.updateStatement(columns: columns, onConflict: type(of: self).persistenceConflictPolicy.conflictResolutionForUpdate) else { // Nil primary key - throw PersistenceError.recordNotFound(self) + throw dao.makeRecordNotFoundError() } try statement.execute() if db.changesCount == 0 { - throw PersistenceError.recordNotFound(self) + throw dao.makeRecordNotFoundError() } } @@ -715,19 +411,14 @@ extension MutablePersistableRecord { /// implementation of performSave(). /// /// This default implementation forwards the job to `update` or `insert`. + @inlinable public mutating func performSave(_ db: Database) throws { - // Make sure we call self.insert and self.update so that classes - // that override insert or save have opportunity to perform their - // custom job. - - if try canUpdate(db) { + // Call self.insert and self.update so that we support classes that + // override those methods. + if let key = try primaryKey(db) { do { try update(db) - } catch PersistenceError.recordNotFound { - // TODO: check that the not persisted objet is self - // - // Why? Adopting types could override update() and update - // another object which may be the one throwing this error. + } catch PersistenceError.recordNotFound(databaseTableName: type(of: self).databaseTableName, key: key) { try insert(db) } } else { @@ -742,6 +433,7 @@ extension MutablePersistableRecord { /// that adopt MutablePersistableRecord can invoke performDelete() in /// their implementation of delete(). They should not provide their own /// implementation of performDelete(). + @inlinable public func performDelete(_ db: Database) throws -> Bool { guard let statement = try DAO(db, self).deleteStatement() else { // Nil primary key @@ -758,6 +450,7 @@ extension MutablePersistableRecord { /// that adopt MutablePersistableRecord can invoke performExists() in /// their implementation of exists(). They should not provide their own /// implementation of performExists(). + @inlinable public func performExists(_ db: Database) throws -> Bool { guard let statement = try DAO(db, self).existsStatement() else { // Nil primary key @@ -796,11 +489,10 @@ extension MutablePersistableRecord where Self: AnyObject { /// match any row in the database and record could not be updated. @discardableResult public func updateChanges(_ db: Database, with change: (Self) throws -> Void) throws -> Bool { - let container = PersistenceContainer(self) + let container = try PersistenceContainer(db, self) try change(self) return try updateChanges(db, from: container) } - } extension MutablePersistableRecord { @@ -1017,6 +709,7 @@ extension PersistableRecord { /// that adopt PersistableRecord can invoke performInsert() in their /// implementation of insert(). They should not provide their own /// implementation of performInsert(). + @inlinable public func performInsert(_ db: Database) throws { let conflictResolutionForInsert = type(of: self).persistenceConflictPolicy.conflictResolutionForInsert let dao = try DAO(db, self) @@ -1036,18 +729,14 @@ extension PersistableRecord { /// implementation of performSave(). /// /// This default implementation forwards the job to `update` or `insert`. + @inlinable public func performSave(_ db: Database) throws { - // Make sure we call self.insert and self.update so that classes that - // override insert or save have opportunity to perform their custom job. - - if try canUpdate(db) { + // Call self.insert and self.update so that we support classes that + // override those methods. + if let key = try primaryKey(db) { do { try update(db) - } catch PersistenceError.recordNotFound { - // TODO: check that the not persisted objet is self - // - // Why? Adopting types could override update() and update another - // object which may be the one throwing this error. + } catch PersistenceError.recordNotFound(databaseTableName: type(of: self).databaseTableName, key: key) { try insert(db) } } else { @@ -1056,88 +745,24 @@ extension PersistableRecord { } } - -// MARK: - DatabaseDateEncodingStrategy - -/// DatabaseDateEncodingStrategy specifies how PersistableRecord types that also -/// adopt the standard Encodable protocol encode their date properties. -/// -/// For example: -/// -/// struct Player: PersistableRecord, Encodable { -/// static let databaseDateEncodingStrategy: DatabaseDateEncodingStrategy = .timeIntervalSince1970 -/// -/// var name: String -/// var registrationDate: Date // encoded as an epoch timestamp -/// } -public enum DatabaseDateEncodingStrategy { - /// The strategy that uses formatting from the Date structure. - /// - /// It encodes dates using the format "YYYY-MM-DD HH:MM:SS.SSS" in the - /// UTC time zone. - case deferredToDate - - /// Encodes a Double: the number of seconds between the date and - /// midnight UTC on 1 January 2001 - case timeIntervalSinceReferenceDate - - /// Encodes a Double: the number of seconds between the date and - /// midnight UTC on 1 January 1970 - case timeIntervalSince1970 - - /// Encodes an Int64: the number of seconds between the date and - /// midnight UTC on 1 January 1970 - case secondsSince1970 - - /// Encodes an Int64: the number of milliseconds between the date and - /// midnight UTC on 1 January 1970 - case millisecondsSince1970 - - /// Encodes dates according to the ISO 8601 and RFC 3339 standards - @available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) - case iso8601 - - /// Encodes a String, according to the provided formatter - case formatted(DateFormatter) - - /// Encodes the result of the user-provided function - case custom((Date) -> DatabaseValueConvertible?) -} - -// MARK: - DatabaseUUIDEncodingStrategy - -/// DatabaseUUIDEncodingStrategy specifies how FetchableRecord types that also -/// adopt the standard Encodable protocol encode their UUID properties. -/// -/// For example: -/// -/// struct Player: PersistableProtocol, Encodable { -/// static let databaseUUIDEncodingStrategy: DatabaseUUIDEncodingStrategy = .string -/// -/// // encoded in a string like "E621E1F8-C36C-495A-93FC-0C247A3E6E5F" -/// var uuid: UUID -/// } -public enum DatabaseUUIDEncodingStrategy { - /// The strategy that uses formatting from the UUID type. - /// - /// It encodes UUIDs as 16-bytes data blobs. - case deferredToUUID - - /// Encodes UUIDs as strings such as "E621E1F8-C36C-495A-93FC-0C247A3E6E5F" - case string -} - // MARK: - DAO +extension PersistenceContainer { + /// Convenience initializer from a database connection and a record + init(_ db: Database,_ record: Record) throws { + let databaseTableName = type(of: record).databaseTableName + let columnCount = try db.columns(in: databaseTableName).count + self.init(minimumCapacity: columnCount) + record.encode(to: &self) + } +} + /// DAO takes care of PersistableRecord CRUD -final class DAO { - +@usableFromInline +final class DAO { /// The database let db: Database - /// The record - let record: MutablePersistableRecord - /// DAO keeps a copy the record's persistenceContainer, so that this /// dictionary is built once whatever the database operation. It is /// guaranteed to have at least one (key, value) pair. @@ -1146,41 +771,40 @@ final class DAO { /// The table name let databaseTableName: String - /// The table primary key - let primaryKey: PrimaryKeyInfo + /// The table primary key info + @usableFromInline let primaryKey: PrimaryKeyInfo - init(_ db: Database, _ record: MutablePersistableRecord) throws { - let databaseTableName = type(of: record).databaseTableName - let primaryKey = try db.primaryKey(databaseTableName) - let persistenceContainer = PersistenceContainer(record) - - GRDBPrecondition(!persistenceContainer.isEmpty, "\(type(of: record)): invalid empty persistence container") - + @usableFromInline + init(_ db: Database, _ record: Record) throws { self.db = db - self.record = record - self.persistenceContainer = persistenceContainer - self.databaseTableName = databaseTableName - self.primaryKey = primaryKey + databaseTableName = type(of: record).databaseTableName + primaryKey = try db.primaryKey(databaseTableName) + persistenceContainer = try PersistenceContainer(db, record) + GRDBPrecondition(!persistenceContainer.isEmpty, "\(type(of: record)): invalid empty persistence container") } + @usableFromInline func insertStatement(onConflict: Database.ConflictResolution) throws -> UpdateStatement { let query = InsertQuery( onConflict: onConflict, tableName: databaseTableName, insertedColumns: persistenceContainer.columns) - let statement = try db.internalCachedUpdateStatement(query.sql) + let statement = try db.internalCachedUpdateStatement(sql: query.sql) statement.unsafeSetArguments(StatementArguments(persistenceContainer.values)) return statement } /// Returns nil if and only if primary key is nil - func updateStatement(_ db: Database, columns: Set, onConflict: Database.ConflictResolution) throws -> UpdateStatement? { + @usableFromInline + func updateStatement(columns: Set, onConflict: Database.ConflictResolution) throws -> UpdateStatement? { // Fail early if primary key does not resolve to a database row. let primaryKeyColumns = primaryKey.columns let primaryKeyValues = primaryKeyColumns.map { persistenceContainer[caseInsensitive: $0]?.databaseValue ?? .null } - guard primaryKeyValues.contains(where: { !$0.isNull }) else { return nil } + if primaryKeyValues.allSatisfy({ $0.isNull }) { + return nil + } // Don't update columns not present in columns // Don't update columns not present in the persistenceContainer @@ -1215,44 +839,61 @@ final class DAO { tableName: databaseTableName, updatedColumns: updatedColumns, conditionColumns: primaryKeyColumns) - let statement = try db.internalCachedUpdateStatement(query.sql) + let statement = try db.internalCachedUpdateStatement(sql: query.sql) statement.unsafeSetArguments(StatementArguments(updatedValues + primaryKeyValues)) return statement } /// Returns nil if and only if primary key is nil + @usableFromInline func deleteStatement() throws -> UpdateStatement? { // Fail early if primary key does not resolve to a database row. let primaryKeyColumns = primaryKey.columns let primaryKeyValues = primaryKeyColumns.map { persistenceContainer[caseInsensitive: $0]?.databaseValue ?? .null } - guard primaryKeyValues.contains(where: { !$0.isNull }) else { return nil } + if primaryKeyValues.allSatisfy({ $0.isNull }) { + return nil + } let query = DeleteQuery( tableName: databaseTableName, conditionColumns: primaryKeyColumns) - let statement = try db.internalCachedUpdateStatement(query.sql) + let statement = try db.internalCachedUpdateStatement(sql: query.sql) statement.unsafeSetArguments(StatementArguments(primaryKeyValues)) return statement } /// Returns nil if and only if primary key is nil + @usableFromInline func existsStatement() throws -> SelectStatement? { // Fail early if primary key does not resolve to a database row. let primaryKeyColumns = primaryKey.columns let primaryKeyValues = primaryKeyColumns.map { persistenceContainer[caseInsensitive: $0]?.databaseValue ?? .null } - guard primaryKeyValues.contains(where: { !$0.isNull }) else { return nil } + if primaryKeyValues.allSatisfy({ $0.isNull }) { + return nil + } let query = ExistsQuery( tableName: databaseTableName, conditionColumns: primaryKeyColumns) - let statement = try db.internalCachedSelectStatement(query.sql) + let statement = try db.internalCachedSelectStatement(sql: query.sql) statement.unsafeSetArguments(StatementArguments(primaryKeyValues)) return statement } + + /// Throws a PersistenceError.recordNotFound error + @usableFromInline + func makeRecordNotFoundError() -> Error { + let key = Dictionary(uniqueKeysWithValues: primaryKey.columns.map { + ($0, persistenceContainer[caseInsensitive: $0]?.databaseValue ?? .null) + }) + return PersistenceError.recordNotFound( + databaseTableName: databaseTableName, + key: key) + } } @@ -1262,10 +903,6 @@ private struct InsertQuery: Hashable { let onConflict: Database.ConflictResolution let tableName: String let insertedColumns: [String] - - #if !swift(>=4.2) - var hashValue: Int { return tableName.hashValue } - #endif } extension InsertQuery { @@ -1296,10 +933,6 @@ private struct UpdateQuery: Hashable { let tableName: String let updatedColumns: [String] let conditionColumns: [String] - - #if !swift(>=4.2) - var hashValue: Int { return tableName.hashValue } - #endif } extension UpdateQuery { diff --git a/GRDB/Record/Record.swift b/GRDB/Record/Record.swift index 30b0f7894..4b220218e 100644 --- a/GRDB/Record/Record.swift +++ b/GRDB/Record/Record.swift @@ -274,13 +274,13 @@ open class Record : FetchableRecord, TableRecord, PersistableRecord { // // But this would trigger two calls to `encode(to:)`. let dao = try DAO(db, self) - guard let statement = try dao.updateStatement(db, columns: columns, onConflict: type(of: self).persistenceConflictPolicy.conflictResolutionForUpdate) else { + guard let statement = try dao.updateStatement(columns: columns, onConflict: type(of: self).persistenceConflictPolicy.conflictResolutionForUpdate) else { // Nil primary key - throw PersistenceError.recordNotFound(self) + throw dao.makeRecordNotFoundError() } try statement.execute() if db.changesCount == 0 { - throw PersistenceError.recordNotFound(self) + throw dao.makeRecordNotFoundError() } // Set hasDatabaseChanges to false diff --git a/GRDB/Record/TableRecord.swift b/GRDB/Record/TableRecord.swift index 1c36ce8fe..d7ea7513d 100644 --- a/GRDB/Record/TableRecord.swift +++ b/GRDB/Record/TableRecord.swift @@ -122,7 +122,7 @@ extension TableRecord { public static func selectionSQL(alias: String? = nil) -> String { let alias = TableAlias(tableName: databaseTableName, userName: alias) let selection = databaseSelection.map { $0.qualifiedSelectable(with: alias) } - var context = SQLGenerationContext.recordSelectionGenerationContext(alias: alias) + var context = SQLGenerationContext.recordSelectionGenerationContext() return selection .map { $0.resultColumnSQL(&context) } .joined(separator: ", ") diff --git a/GRDB/Utils/Inflections+English.swift b/GRDB/Utils/Inflections+English.swift new file mode 100644 index 000000000..c9f527035 --- /dev/null +++ b/GRDB/Utils/Inflections+English.swift @@ -0,0 +1,138 @@ +// Copyright (C) 2019 Gwendal Roué +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// ============================================================================= +// +// Copyright (c) 2005-2019 David Heinemeier Hansson +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +extension Inflections { + /// The default inflections + public static var `default`: Inflections = { + // Defines the standard inflection rules. These are the starting point + // for new projects and are not considered complete. The current set of + // inflection rules is frozen. This means, we do not change them to + // become more complete. This is a safety measure to keep existing + // applications from breaking. + // + // https://github.com/rails/rails/blob/b2eb1d1c55a59fee1e6c4cba7030d8ceb524267c/activesupport/lib/active_support/inflections.rb + var inflections = Inflections() + + inflections.plural("$", "s") + inflections.plural("s$", "s") + inflections.plural("^(ax|test)is$", "$1es") + inflections.plural("(octop|vir)us$", "$1i") + inflections.plural("(octop|vir)i$", "$1i") + inflections.plural("(alias|status)$", "$1es") + inflections.plural("(bu)s$", "$1ses") + inflections.plural("(buffal|tomat|her)o$", "$1oes") + inflections.plural("([ti])um$", "$1a") + inflections.plural("([ti])a$", "$1a") + inflections.plural("sis$", "ses") + inflections.plural("(?:([^f])fe|([lr])f)$", "$1$2ves") + inflections.plural("(hive)$", "$1s") + inflections.plural("([^aeiouy]|qu)y$", "$1ies") + inflections.plural("(x|ch|ss|sh)$", "$1es") + inflections.plural("(matr|vert|ind)(?:ix|ex)$", "$1ices") + inflections.plural("^(m|l)ouse$", "$1ice") + inflections.plural("^(m|l)ice$", "$1ice") + inflections.plural("^(ox)$", "$1en") + inflections.plural("^(oxen)$", "$1") + inflections.plural("(quiz)$", "$1zes") + inflections.plural("(canva)s$", "$1ses") + + inflections.singular("s$", "") + inflections.singular("(ss)$", "$1") + inflections.singular("(n)ews$", "$1ews") + inflections.singular("([ti])a$", "$1um") + inflections.singular("((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$", "$1sis") + inflections.singular("(^analy)(sis|ses)$", "$1sis") + inflections.singular("([^f])ves$", "$1fe") + inflections.singular("(hive)s$", "$1") + inflections.singular("(tive)s$", "$1") + inflections.singular("([lr])ves$", "$1f") + inflections.singular("([^aeiouy]|qu)ies$", "$1y") + inflections.singular("(s)eries$", "$1eries") + inflections.singular("(m)ovies$", "$1ovie") + inflections.singular("(x|ch|ss|sh)es$", "$1") + inflections.singular("^(m|l)ice$", "$1ouse") + inflections.singular("(bus)(es)?$", "$1") + inflections.singular("(o)es$", "$1") + inflections.singular("(shoe)s$", "$1") + inflections.singular("(cris|test)(is|es)$", "$1is") + inflections.singular("^(a)x[ie]s$", "$1xis") + inflections.singular("(octop|vir)(us|i)$", "$1us") + inflections.singular("(alias|status)(es)?$", "$1") + inflections.singular("^(ox)en$", "$1") + inflections.singular("(vert|ind)ices$", "$1ex") + inflections.singular("(matr)ices$", "$1ix") + inflections.singular("(quiz)zes$", "$1") + inflections.singular("(database)s$", "$1") + inflections.singular("(canvas)(es)?$", "$1") + + inflections.uncountableWords([ + "advice", + "corps", + "dice", + "equipment", + "fish", + "information", + "jeans", + "kudos", + "money", + "offspring", + "police", + "rice", + "sheep", + "species", + ]) + + inflections.irregularSuffix("child", "children") + inflections.irregularSuffix("foot", "feet") + inflections.irregularSuffix("leaf", "leaves") + inflections.irregularSuffix("man", "men") + inflections.irregularSuffix("move", "moves") + inflections.irregularSuffix("person", "people") + inflections.irregularSuffix("sex", "sexes") + inflections.irregularSuffix("specimen", "specimens") + inflections.irregularSuffix("zombie", "zombies") + + return inflections + }() +} diff --git a/GRDB/Utils/Inflections.swift b/GRDB/Utils/Inflections.swift index d5f1f8637..f8dbabf33 100644 --- a/GRDB/Utils/Inflections.swift +++ b/GRDB/Utils/Inflections.swift @@ -1,10 +1,238 @@ import Foundation extension String { + /// "player" -> "Player" var uppercasingFirstCharacter: String { guard let first = first else { return self } return String(first).uppercased() + dropFirst() } + + /// "player" -> "players" + /// "players" -> "players" + var pluralized: String { + return Inflections.default.pluralize(self) + } + + /// "player" -> "player" + /// "players" -> "player" + var singularized: String { + return Inflections.default.singularize(self) + } + + /// "bar" -> "bar" + /// "foo12" -> "foo" + var digitlessRadical: String { + return String(prefix(upTo: Inflections.endIndexOfDigitlessRadical(self))) + } } + +/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) +/// +/// A type that controls GRDB string inflections. +public struct Inflections { + private var pluralizeRules: [(NSRegularExpression, String)] = [] + private var singularizeRules: [(NSRegularExpression, String)] = [] + private var uncountablesRegularExpressions: [String: NSRegularExpression] = [:] + + // For testability + var uncountables: Set { + return Set(uncountablesRegularExpressions.keys) + } + + // MARK: - Initialization + + public init() { + } + + // MARK: - Configuration + + /// Appends a pluralization rule. + /// + /// var inflections = Inflections() + /// inflections.plural("$", "s") + /// inflections.pluralize("player") // "players" + /// + /// - parameters: + /// - pattern: A regular expression pattern. + /// - options: Regular expression options (defaults to + /// `[.caseInsensitive]`). + /// - template: A replacement template string. + public mutating func plural(_ pattern: String, options: NSRegularExpression.Options = [.caseInsensitive], _ template: String) { + let reg = try! NSRegularExpression(pattern: pattern, options: options) + pluralizeRules.append((reg, template)) + } + + /// Appends a singularization rule. + /// + /// var inflections = Inflections() + /// inflections.singular("s$", "") + /// inflections.singularize("players") // "player" + /// + /// - parameters: + /// - pattern: A regular expression pattern. + /// - options: Regular expression options (defaults to + /// `[.caseInsensitive]`). + /// - template: A replacement template string. + public mutating func singular(_ pattern: String, options: NSRegularExpression.Options = [.caseInsensitive], _ template: String) { + let reg = try! NSRegularExpression(pattern: pattern, options: options) + singularizeRules.append((reg, template)) + } + + /// Appends uncountable words. + /// + /// var inflections = Inflections() + /// inflections.plural("$", "s") + /// inflections.uncountableWords(["foo"]) + /// inflections.pluralize("foo") // "foo" + /// inflections.pluralize("bar") // "bars" + public mutating func uncountableWords(_ words: [String]) { + for word in words { + uncountableWord(word) + } + } + + /// Appends an irregular singular/plural pair. + /// + /// var inflections = Inflections() + /// inflections.plural("$", "s") + /// inflections.irregularSuffix("man", "men") + /// inflections.pluralize("man") // "men" + /// inflections.singularizes("women") // "woman" + /// + /// - parameters: + /// - singular: The singular form. + /// - plural: The plural form. + public mutating func irregularSuffix(_ singular: String, _ plural: String) { + let s0 = singular.first! + let srest = singular.dropFirst() + + let p0 = plural.first! + let prest = plural.dropFirst() + + if s0.uppercased() == p0.uppercased() { + self.plural("(\(s0))\(srest)$", options: [.caseInsensitive], "$1\(prest)") + self.plural("(\(p0))\(prest)$", options: [.caseInsensitive], "$1\(prest)") + + self.singular("(\(s0))\(srest)$", options: [.caseInsensitive], "$1\(srest)") + self.singular("(\(p0))\(prest)$", options: [.caseInsensitive], "$1\(srest)") + } else { + self.plural("\(s0.uppercased())(?i)\(srest)$", options: [], p0.uppercased() + prest) + self.plural("\(s0.lowercased())(?i)\(srest)$", options: [], p0.lowercased() + prest) + self.plural("\(p0.uppercased())(?i)\(prest)$", options: [], p0.uppercased() + prest) + self.plural("\(p0.lowercased())(?i)\(prest)$", options: [], p0.lowercased() + prest) + + self.singular("\(s0.uppercased())(?i)\(srest)$", options: [], s0.uppercased() + srest) + self.singular("\(s0.lowercased())(?i)\(srest)$", options: [], s0.lowercased() + srest) + self.singular("\(p0.uppercased())(?i)\(prest)$", options: [], s0.uppercased() + srest) + self.singular("\(p0.lowercased())(?i)\(prest)$", options: [], s0.lowercased() + srest) + } + } + + // MARK: - Inflections + + /// Returns a pluralized string. + /// + /// Inflections.default.pluralize("player") // "players" + public func pluralize(_ string: String) -> String { + return inflectString(string, with: pluralizeRules) + } + + /// Returns a singularized string. + public func singularize(_ string: String) -> String { + return inflectString(string, with: singularizeRules) + } + + // MARK: - Utils + + /// Appends an uncountable word. + /// + /// var inflections = Inflections() + /// inflections.plural("$", "s") + /// inflections.uncountableWord("foo") + /// inflections.pluralize("foo") // "foo" + /// inflections.pluralize("bar") // "bars" + private mutating func uncountableWord(_ word: String) { + let escWord = NSRegularExpression.escapedPattern(for: word) + uncountablesRegularExpressions[word] = try! NSRegularExpression(pattern: "\\b\(escWord)\\Z", options: [.caseInsensitive]) + } + + private func isUncountable(_ string: String) -> Bool { + let range = NSRange(location: 0, length: string.utf16.count) + for (_, reg) in uncountablesRegularExpressions { + if reg.firstMatch(in: string, options: [], range: range) != nil { + return true + } + } + return false + } + + private func inflectString(_ string: String, with rules: [(NSRegularExpression, String)]) -> String { + let indexOfLastWord = Inflections.startIndexOfLastWord(string) + let endIndexOfDigitlessRadical = Inflections.endIndexOfDigitlessRadical(string) + let lastWord = String(string[indexOfLastWord.. String { + if string.isEmpty { + return string + } + let range = NSRange(string.startIndex.. 0 { + return String(result) + } + } + return string + } + + /// startIndexOfLastWord("foo") -> "foo" + /// startIndexOfLastWord("foo bar") -> "bar" + /// startIndexOfLastWord("foo_bar") -> "bar" + /// startIndexOfLastWord("fooBar") -> "Bar" + static func startIndexOfLastWord(_ string: String) -> String.Index { + let range = NSRange(string.startIndex.. "bar" + /// "foo12" -> "foo" + static func endIndexOfDigitlessRadical(_ string: String) -> String.Index { + let digits: ClosedRange = "0"..."9" + return string // "foo12" + .reversed() // "21oof" + .prefix(while: { digits.contains($0) }) // "21" + .endIndex // reversed(foo^12) + .base // foo^12 + } + + private static let wordBoundaryReg = try! NSRegularExpression(pattern: "\\b\\w+$", options: []) + private static let underscoreBoundaryReg = try! NSRegularExpression(pattern: "_[^_]+$", options: []) + private static let caseBoundaryReg = try! NSRegularExpression(pattern: "[^A-Z][A-Z]+[a-z1-9]+$", options: []) +} + diff --git a/GRDB/Utils/OrderedDictionary.swift b/GRDB/Utils/OrderedDictionary.swift index 126c2f97c..dd51231c8 100644 --- a/GRDB/Utils/OrderedDictionary.swift +++ b/GRDB/Utils/OrderedDictionary.swift @@ -8,9 +8,10 @@ /// dict["bar"] // 2 /// dict["qux"] // nil /// dict.map { $0.key } // ["foo", "bar"], in this order. +@usableFromInline struct OrderedDictionary { - private(set) var keys: [Key] - private(set) var dictionary: [Key: Value] + @usableFromInline /* private(set) */ var keys: [Key] + @usableFromInline /* private(set) */ var dictionary: [Key: Value] var values: [Value] { return keys.map { dictionary[$0]! } @@ -28,8 +29,9 @@ struct OrderedDictionary { keys.reserveCapacity(minimumCapacity) dictionary = Dictionary(minimumCapacity: minimumCapacity) } - + /// Returns the value associated with key, or nil. + @usableFromInline subscript(_ key: Key) -> Value? { get { return dictionary[key] } set { @@ -40,7 +42,14 @@ struct OrderedDictionary { } } } - + + /// Returns the value associated with key, or the default value. + @inlinable + subscript(_ key: Key, default defaultValue: Value) -> Value { + get { return dictionary[key] ?? defaultValue } + set { self[key] = newValue } + } + /// Appends the given value for the given key. /// /// - precondition: There is no value associated with key yet. @@ -59,6 +68,7 @@ struct OrderedDictionary { /// original value. If the given key is not present in the dictionary, this /// method appends the key-value pair and returns nil. @discardableResult + @usableFromInline mutating func updateValue(_ value: Value, forKey key: Key) -> Value? { if let oldValue = dictionary.updateValue(value, forKey: key) { return oldValue @@ -69,11 +79,12 @@ struct OrderedDictionary { /// Removes the value associated with key. @discardableResult + @inlinable mutating func removeValue(forKey key: Key) -> Value? { guard let value = dictionary.removeValue(forKey: key) else { return nil } - let index = keys.index { $0 == key }! + let index = keys.firstIndex { $0 == key }! keys.remove(at: index) return value } @@ -81,40 +92,59 @@ struct OrderedDictionary { /// Returns a new ordered dictionary containing the keys of this dictionary /// with the values transformed by the given closure. func mapValues(_ transform: (Value) throws -> T) rethrows -> OrderedDictionary { - return try reduce(into: OrderedDictionary()) { dict, pair in - dict.appendValue(try transform(pair.value), forKey: pair.key) + return try reduce(into: .init()) { dict, pair in + let value = try transform(pair.value) + dict.appendValue(value, forKey: pair.key) + } + } + + /// Returns a new ordered dictionary containing only the key-value pairs + /// that have non-nil values as the result of transformation by the + /// given closure. + func compactMapValues(_ transform: (Value) throws -> T?) rethrows -> OrderedDictionary { + return try reduce(into: .init()) { dict, pair in + if let value = try transform(pair.value) { + dict.appendValue(value, forKey: pair.key) + } } } } extension OrderedDictionary: Collection { - typealias Index = Int + @usableFromInline typealias Index = Int - var startIndex: Int { + @usableFromInline var startIndex: Int { return 0 } - var endIndex: Int { + @usableFromInline var endIndex: Int { return keys.count } - func index(after i: Int) -> Int { + @usableFromInline func index(after i: Int) -> Int { return i + 1 } - subscript(position: Int) -> (key: Key, value: Value) { + @usableFromInline subscript(position: Int) -> (key: Key, value: Value) { let key = keys[position] return (key: key, value: dictionary[key]!) } } extension OrderedDictionary: ExpressibleByDictionaryLiteral { - init(dictionaryLiteral elements: (Key, Value)...) { + @usableFromInline init(dictionaryLiteral elements: (Key, Value)...) { self.keys = elements.map { $0.0 } self.dictionary = Dictionary(uniqueKeysWithValues: elements) } } +extension OrderedDictionary: Equatable where Value: Equatable { + @usableFromInline + static func == (lhs: OrderedDictionary, rhs: OrderedDictionary) -> Bool { + return (lhs.keys == rhs.keys) && (lhs.dictionary == rhs.dictionary) + } +} + extension Dictionary { init(_ orderedDictionary: OrderedDictionary) { self = orderedDictionary.dictionary diff --git a/GRDB/Utils/Result.swift b/GRDB/Utils/Result.swift index ee5bbfdfc..028259c1a 100644 --- a/GRDB/Utils/Result.swift +++ b/GRDB/Utils/Result.swift @@ -1,49 +1,34 @@ -enum Result { - case success(Value) +#if compiler(>=5.0) +typealias Result = Swift.Result +#else +enum Result { + case success(Success) case failure(Error) - init(value: () throws -> Value) { + init(catching body: () throws -> Success) { do { - self = try .success(value()) + self = try .success(body()) } catch { self = .failure(error) } } - /// Evaluates the given closure when this `Result` is a success, passing the - /// unwrapped value as a parameter. - /// - /// Use the `map` method with a closure that does not throw. For example: - /// - /// let possibleData: Result = .success(Data()) - /// let possibleInt = possibleData.map { $0.count } - /// try print(possibleInt.unwrap()) - /// // Prints "0" - /// - /// let noData: Result = .failure(error) - /// let noInt = noData.map { $0.count } - /// try print(noInt.unwrap()) - /// // Throws error - /// - /// - parameter transform: A closure that takes the success value of - /// the instance. - /// - returns: A `Result` containing the result of the given closure. If - /// this instance is a failure, returns the same failure. - func map(_ transform: (Value) -> T) -> Result { + func map(_ transform: (Success) -> T) -> Result { switch self { - case .success(let value): - return .success(transform(value)) + case .success(let success): + return .success(transform(success)) case .failure(let error): return .failure(error) } } - func unwrap() throws -> Value { + func get() throws -> Success { switch self { - case .success(let value): - return value + case .success(let success): + return success case .failure(let error): throw error } } } +#endif diff --git a/GRDB/Utils/Utils.swift b/GRDB/Utils/Utils.swift index 484dab35c..ae666ec52 100644 --- a/GRDB/Utils/Utils.swift +++ b/GRDB/Utils/Utils.swift @@ -6,18 +6,20 @@ extension String { /// Returns the receiver, quoted for safe insertion as an identifier in an /// SQL query. /// - /// db.execute("SELECT * FROM \(tableName.quotedDatabaseIdentifier)") + /// db.execute(sql: "SELECT * FROM \(tableName.quotedDatabaseIdentifier)") + @inlinable public var quotedDatabaseIdentifier: String { // See https://www.sqlite.org/lang_keywords.html - return "\"" + self + "\"" + return "\"\(self)\"" } } /// Return as many question marks separated with commas as the *count* argument. /// /// databaseQuestionMarks(count: 3) // "?,?,?" +@inlinable public func databaseQuestionMarks(count: Int) -> String { - return Array(repeating: "?", count: count).joined(separator: ",") + return repeatElement("?", count: count).joined(separator: ",") } /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) @@ -46,13 +48,13 @@ extension Optional : _OptionalProtocol { // MARK: - Internal /// Reserved for GRDB: do not use. -@inline(__always) +@inlinable func GRDBPrecondition(_ condition: @autoclosure() -> Bool, _ message: @autoclosure() -> String = "", file: StaticString = #file, line: UInt = #line) { /// Custom precondition function which aims at solving /// https://bugs.swift.org/browse/SR-905 and /// https://github.com/groue/GRDB.swift/issues/37 if !condition() { - fatalError(message, file: file, line: line) + fatalError(message(), file: file, line: line) } } @@ -61,10 +63,19 @@ func cast(_ value: T) -> U? { return value as? U } -extension Array { +extension RangeReplaceableCollection { /// Removes the first object that matches *predicate*. - mutating func removeFirst(_ predicate: (Element) throws -> Bool) rethrows { - if let index = try index(where: predicate) { + mutating func removeFirst(where predicate: (Element) throws -> Bool) rethrows { + if let index = try firstIndex(where: predicate) { + remove(at: index) + } + } +} + +extension Dictionary { + /// Removes the first object that matches *predicate*. + mutating func removeFirst(where predicate: (Element) throws -> Bool) rethrows { + if let index = try firstIndex(where: predicate) { remove(at: index) } } @@ -81,3 +92,29 @@ extension DispatchQueue { return DispatchQueue.getSpecific(key: mainKey) != nil } } + +// Has SE-0220 been removed in Xcode 10.2 beta 4? +// #if compiler(<5.0) +extension Sequence { + @inlinable + func count(where predicate: (Element) throws -> Bool) rethrows -> Int { + var count = 0 + for e in self where try predicate(e) { + count += 1 + } + return count + } +} +// #endif + +#if !compiler(>=5.0) +extension Character { + func uppercased() -> String { + return String(self).uppercased() + } + + func lowercased() -> String { + return String(self).lowercased() + } +} +#endif diff --git a/GRDB/ValueObservation/ValueObservation+Count.swift b/GRDB/ValueObservation/ValueObservation+Count.swift index a702fc933..78ff705bc 100644 --- a/GRDB/ValueObservation/ValueObservation+Count.swift +++ b/GRDB/ValueObservation/ValueObservation+Count.swift @@ -28,7 +28,6 @@ extension ValueObservation where Reducer == Void { public static func trackingCount(_ request: Request) -> ValueObservation>> { - // TODO: Remove distinctUntilChanged in GRDB 4 return ValueObservation.tracking(request, fetch: request.fetchCount).distinctUntilChanged() } } diff --git a/GRDB/ValueObservation/ValueObservation+DatabaseValueConvertible.swift b/GRDB/ValueObservation/ValueObservation+DatabaseValueConvertible.swift index de4b240d6..c32634532 100644 --- a/GRDB/ValueObservation/ValueObservation+DatabaseValueConvertible.swift +++ b/GRDB/ValueObservation/ValueObservation+DatabaseValueConvertible.swift @@ -124,7 +124,6 @@ public struct DatabaseValuesReducer: ValueReducer public mutating func value(_ dbValues: [DatabaseValue]) -> [Request.RowDecoder]? { if let previousDbValues = previousDbValues, previousDbValues == dbValues { // Don't notify consecutive identical dbValue arrays - // TODO: Remove this implicit `distinctUntilDatabaseChanged` in GRDB 4 return nil } self.previousDbValues = dbValues @@ -158,7 +157,6 @@ public struct DatabaseValueReducer: ValueReducer public mutating func value(_ dbValue: DatabaseValue?) -> Request.RowDecoder?? { if let previousDbValue = previousDbValue, previousDbValue == dbValue { // Don't notify consecutive identical dbValue - // TODO: Remove this implicit `distinctUntilDatabaseChanged` in GRDB 4 return nil } self.previousDbValue = dbValue @@ -169,7 +167,6 @@ public struct DatabaseValueReducer: ValueReducer return .some(value) } else if previousValueWasNil { // Don't notify consecutive nil values - // TODO: Remove this implicit `distinctUntilDatabaseChanged` in GRDB 4 return nil } else { previousValueWasNil = true @@ -203,7 +200,6 @@ public struct OptionalDatabaseValuesReducer: ValueReducer public mutating func value(_ dbValues: [DatabaseValue]) -> [Request.RowDecoder._Wrapped?]? { if let previousDbValues = previousDbValues, previousDbValues == dbValues { // Don't notify consecutive identical dbValue arrays - // TODO: Remove this implicit `distinctUntilDatabaseChanged` in GRDB 4 return nil } self.previousDbValues = dbValues diff --git a/GRDB/ValueObservation/ValueObservation+FetchableRecord.swift b/GRDB/ValueObservation/ValueObservation+FetchableRecord.swift index 2a3ac9d7c..df28ced1d 100644 --- a/GRDB/ValueObservation/ValueObservation+FetchableRecord.swift +++ b/GRDB/ValueObservation/ValueObservation+FetchableRecord.swift @@ -27,11 +27,43 @@ extension ValueObservation where Reducer == Void { /// - parameter request: the observed request. /// - returns: a ValueObservation. public static func trackingAll(_ request: Request) - -> ValueObservation> + -> ValueObservation> where Request.RowDecoder: FetchableRecord { - return ValueObservation>.tracking(request, reducer: { _ in - FetchableRecordsReducer(request: request) + return ValueObservation>.tracking(request, reducer: { _ in + FetchableRecordsReducer { try Row.fetchAll($0, request) } + }) + } + + /// Creates a ValueObservation which observes *request*, and notifies + /// fresh records whenever the request is modified by a + /// database transaction. + /// + /// For example: + /// + /// let request = Player.all() + /// let observation = ValueObservation.trackingAll(request) + /// + /// let observer = try observation.start(in: dbQueue) { players: [Player] in + /// print("Players have changed") + /// } + /// + /// The returned observation has the default configuration: + /// + /// - When started with the `start(in:onError:onChange:)` method, a fresh + /// value is immediately notified on the main queue. + /// - Upon subsequent database changes, fresh values are notified on the + /// main queue. + /// - The observation lasts until the observer returned by + /// `start` is deallocated. + /// + /// - parameter request: the observed request. + /// - returns: a ValueObservation. + public static func trackingAll(_ request: QueryInterfaceRequest) + -> ValueObservation> + { + return ValueObservation>.tracking(request, reducer: { _ in + FetchableRecordsReducer { try Row.fetchAll($0, request) } }) } @@ -59,11 +91,42 @@ extension ValueObservation where Reducer == Void { /// - parameter request: the observed request. /// - returns: a ValueObservation. public static func trackingOne(_ request: Request) -> - ValueObservation> + ValueObservation> where Request.RowDecoder: FetchableRecord { - return ValueObservation>.tracking(request, reducer: { _ in - FetchableRecordReducer(request: request) + return ValueObservation>.tracking(request, reducer: { _ in + FetchableRecordReducer { try Row.fetchOne($0, request) } + }) + } + + /// Creates a ValueObservation which observes *request*, and notifies a + /// fresh record whenever the request is modified by a database transaction. + /// + /// For example: + /// + /// let request = Player.filter(key: 1) + /// let observation = ValueObservation.trackingOne(request) + /// + /// let observer = try observation.start(in: dbQueue) { player: Player? in + /// print("Player has changed") + /// } + /// + /// The returned observation has the default configuration: + /// + /// - When started with the `start(in:onError:onChange:)` method, a fresh + /// value is immediately notified on the main queue. + /// - Upon subsequent database changes, fresh values are notified on the + /// main queue. + /// - The observation lasts until the observer returned by + /// `start` is deallocated. + /// + /// - parameter request: the observed request. + /// - returns: a ValueObservation. + public static func trackingOne(_ request: QueryInterfaceRequest) + -> ValueObservation> + { + return ValueObservation>.tracking(request, reducer: { _ in + FetchableRecordReducer { try Row.fetchOne($0, request) } }) } } @@ -74,28 +137,27 @@ extension ValueObservation where Reducer == Void { /// identical database rows. /// /// :nodoc: -public struct FetchableRecordsReducer: ValueReducer - where Request.RowDecoder: FetchableRecord +public struct FetchableRecordsReducer: ValueReducer + where RowDecoder: FetchableRecord { - public let request: Request + private let _fetch: (Database) throws -> [Row] private var previousRows: [Row]? - init(request: Request) { - self.request = request + init(fetch: @escaping (Database) throws -> [Row]) { + self._fetch = fetch } - + public func fetch(_ db: Database) throws -> [Row] { - return try Row.fetchAll(db, request) + return try _fetch(db) } - public mutating func value(_ rows: [Row]) -> [Request.RowDecoder]? { + public mutating func value(_ rows: [Row]) -> [RowDecoder]? { if let previousRows = previousRows, previousRows == rows { // Don't notify consecutive identical row arrays - // TODO: Remove this implicit `distinctUntilDatabaseChanged` in GRDB 4 return nil } self.previousRows = rows - return rows.map(Request.RowDecoder.init(row:)) + return rows.map(RowDecoder.init(row:)) } } @@ -105,27 +167,26 @@ public struct FetchableRecordsReducer: ValueReducer /// identical database rows. /// /// :nodoc: -public struct FetchableRecordReducer: ValueReducer - where Request.RowDecoder: FetchableRecord +public struct FetchableRecordReducer: ValueReducer + where RowDecoder: FetchableRecord { - public let request: Request + private let _fetch: (Database) throws -> Row? private var previousRow: Row?? - init(request: Request) { - self.request = request + init(fetch: @escaping (Database) throws -> Row?) { + self._fetch = fetch } - + public func fetch(_ db: Database) throws -> Row? { - return try Row.fetchOne(db, request) + return try _fetch(db) } - public mutating func value(_ row: Row?) -> Request.RowDecoder?? { + public mutating func value(_ row: Row?) -> RowDecoder?? { if let previousRow = previousRow, previousRow == row { // Don't notify consecutive identical rows - // TODO: Remove this implicit `distinctUntilDatabaseChanged` in GRDB 4 return nil } self.previousRow = row - return .some(row.map(Request.RowDecoder.init(row:))) + return .some(row.map(RowDecoder.init(row:))) } } diff --git a/GRDB/ValueObservation/ValueObservation+MapReducer.swift b/GRDB/ValueObservation/ValueObservation+MapReducer.swift index baea470b8..0f9705c3b 100644 --- a/GRDB/ValueObservation/ValueObservation+MapReducer.swift +++ b/GRDB/ValueObservation/ValueObservation+MapReducer.swift @@ -7,7 +7,6 @@ extension ValueObservation { var observation = ValueObservation( tracking: observedRegion, reducer: { db in try transform(db, makeReducer(db)) }) - observation.extent = extent observation.scheduling = scheduling observation.requiresWriteAccess = requiresWriteAccess return observation diff --git a/GRDB/ValueObservation/ValueObservation+Row.swift b/GRDB/ValueObservation/ValueObservation+Row.swift index e3c1f55ba..32038ee65 100644 --- a/GRDB/ValueObservation/ValueObservation+Row.swift +++ b/GRDB/ValueObservation/ValueObservation+Row.swift @@ -7,7 +7,7 @@ extension ValueObservation where Reducer == Void { /// /// For example: /// - /// let request = SQLRequest("SELECT * FROM player") + /// let request = SQLRequest(sql: "SELECT * FROM player") /// let observation = ValueObservation.trackingAll(request) /// /// let observer = try observation.start(in: dbQueue) { rows: [Row] in @@ -26,11 +26,42 @@ extension ValueObservation where Reducer == Void { /// - parameter request: the observed request. /// - returns: a ValueObservation. public static func trackingAll(_ request: Request) - -> ValueObservation> + -> ValueObservation where Request.RowDecoder == Row { - return ValueObservation>.tracking(request, reducer: { _ in - RowsReducer(request: request) + return ValueObservation.tracking(request, reducer: { _ in + RowsReducer(fetch: request.fetchAll) + }) + } + + /// Creates a ValueObservation which observes *request*, and notifies + /// fresh rows whenever the request is modified by a database transaction. + /// + /// For example: + /// + /// let request = SQLRequest(sql: "SELECT * FROM player") + /// let observation = ValueObservation.trackingAll(request) + /// + /// let observer = try observation.start(in: dbQueue) { rows: [Row] in + /// print("Players have changed") + /// } + /// + /// The returned observation has the default configuration: + /// + /// - When started with the `start(in:onError:onChange:)` method, a fresh + /// value is immediately notified on the main queue. + /// - Upon subsequent database changes, fresh values are notified on the + /// main queue. + /// - The observation lasts until the observer returned by + /// `start` is deallocated. + /// + /// - parameter request: the observed request. + /// - returns: a ValueObservation. + public static func trackingAll(_ request: QueryInterfaceRequest) + -> ValueObservation + { + return ValueObservation.tracking(request, reducer: { _ in + RowsReducer(fetch: request.fetchAll) }) } @@ -39,7 +70,7 @@ extension ValueObservation where Reducer == Void { /// /// For example: /// - /// let request = SQLRequest("SELECT * FROM player WHERE id = ?", arguments: [1]) + /// let request = SQLRequest(sql: "SELECT * FROM player WHERE id = ?", arguments: [1]) /// let observation = ValueObservation.trackingOne(request) /// /// let observer = try observation.start(in: dbQueue) { row: Row? in @@ -58,11 +89,42 @@ extension ValueObservation where Reducer == Void { /// - parameter request: the observed request. /// - returns: a ValueObservation. public static func trackingOne(_ request: Request) - -> ValueObservation> + -> ValueObservation where Request.RowDecoder == Row { - return ValueObservation>.tracking(request, reducer: { _ in - RowReducer(request: request) + return ValueObservation.tracking(request, reducer: { _ in + RowReducer(fetch: request.fetchOne) + }) + } + + /// Creates a ValueObservation which observes *request*, and notifies a + /// fresh row whenever the request is modified by a database transaction. + /// + /// For example: + /// + /// let request = SQLRequest(sql: "SELECT * FROM player WHERE id = ?", arguments: [1]) + /// let observation = ValueObservation.trackingOne(request) + /// + /// let observer = try observation.start(in: dbQueue) { row: Row? in + /// print("Players have changed") + /// } + /// + /// The returned observation has the default configuration: + /// + /// - When started with the `start(in:onError:onChange:)` method, a fresh + /// value is immediately notified on the main queue. + /// - Upon subsequent database changes, fresh values are notified on the + /// main queue. + /// - The observation lasts until the observer returned by + /// `start` is deallocated. + /// + /// - parameter request: the observed request. + /// - returns: a ValueObservation. + public static func trackingOne(_ request: QueryInterfaceRequest) + -> ValueObservation + { + return ValueObservation.tracking(request, reducer: { _ in + RowReducer(fetch: request.fetchOne) }) } } @@ -73,18 +135,16 @@ extension ValueObservation where Reducer == Void { /// consecutive identical arrays. /// /// :nodoc: -public struct RowsReducer: ValueReducer - where Request.RowDecoder == Row -{ - public let request: Request +public struct RowsReducer: ValueReducer { + private let _fetch: (Database) throws -> [Row] private var previousRows: [Row]? - init(request: Request) { - self.request = request + init(fetch: @escaping (Database) throws -> [Row]) { + self._fetch = fetch } public func fetch(_ db: Database) throws -> [Row] { - return try request.fetchAll(db) + return try _fetch(db) } public mutating func value(_ rows: [Row]) -> [Row]? { @@ -103,24 +163,21 @@ public struct RowsReducer: ValueReducer /// identical database rows. /// /// :nodoc: -public struct RowReducer: ValueReducer - where Request.RowDecoder == Row -{ - public let request: Request +public struct RowReducer: ValueReducer { + private let _fetch: (Database) throws -> Row? private var previousRow: Row?? - init(request: Request) { - self.request = request + init(fetch: @escaping (Database) throws -> Row?) { + self._fetch = fetch } public func fetch(_ db: Database) throws -> Row? { - return try request.fetchOne(db) + return try _fetch(db) } public mutating func value(_ row: Row?) -> Row?? { if let previousRow = previousRow, previousRow == row { // Don't notify consecutive identical rows - // TODO: Remove this implicit `distinctUntilDatabaseChanged` in GRDB 4 return nil } self.previousRow = row diff --git a/GRDB/ValueObservation/ValueObservation.swift b/GRDB/ValueObservation/ValueObservation.swift index b142571df..c263e73a5 100644 --- a/GRDB/ValueObservation/ValueObservation.swift +++ b/GRDB/ValueObservation/ValueObservation.swift @@ -40,7 +40,7 @@ public enum ValueScheduling { /// /// An initial value is fetched and notified if `startImmediately` /// is true. - case onQueue(DispatchQueue, startImmediately: Bool) + case async(onQueue: DispatchQueue, startImmediately: Bool) /// Values are not all notified on the same dispatch queue. /// @@ -89,12 +89,6 @@ public struct ValueObservation { /// observation is less efficient than a read-only observation. public var requiresWriteAccess: Bool = false - /// The extent of the database observation. The default is - /// `.observerLifetime`: the observation lasts until the - /// observer returned by the `start(in:onError:onChange:)` method - /// is deallocated. - public var extent = Database.TransactionObservationExtent.observerLifetime - /// `scheduling` controls how fresh values are notified. Default /// is `.mainQueue`. /// @@ -157,7 +151,7 @@ public struct ValueObservation { switch scheduling { case .mainQueue: return DispatchQueue.main - case .onQueue(let queue, startImmediately: _): + case let .async(onQueue: queue, startImmediately: _): return queue case .unsafe: return nil @@ -208,48 +202,6 @@ extension ValueObservation { // MARK: - Creating ValueObservation from ValueReducer - /// Returns a ValueObservation which observes *regions*, and notifies the - /// values returned by the *reducer* whenever one of the observed - /// regions is modified by a database transaction. - /// - /// This method is the most fundamental way to create a ValueObservation. - /// - /// For example, this observation counts the number of a times the player - /// table is modified: - /// - /// var count = 0 - /// let reducer = AnyValueReducer( - /// fetch: { _ in }, - /// value: { _ -> Int? in - /// count += 1 - /// return count }) - /// let observation = ValueObservation.tracking(Player.all(), reducer: reducer) - /// let observer = observation.start(in: dbQueue) { count: Int in - /// print("Players have been modified \(count) times.") - /// } - /// - /// The returned observation has the default configuration: - /// - /// - When started with the `start(in:onError:onChange:)` method, a fresh - /// value is immediately notified on the main queue. - /// - Upon subsequent database changes, fresh values are notified on the - /// main queue. - /// - The observation lasts until the observer returned by - /// `start` is deallocated. - /// - /// - parameter regions: A list of observed regions. - /// - parameter reducer: A reducer that turns database changes in the - /// modified regions into fresh values. Currently only reducers that adopt - /// the ValueReducer protocol are supported. - @available(*, deprecated, message: "Provide the reducer in a (Database) -> Reducer closure") - public static func tracking( - _ regions: DatabaseRegionConvertible..., - reducer: Reducer) - -> ValueObservation - { - return ValueObservation.tracking(regions, reducer: { _ in reducer }) - } - /// Returns a ValueObservation which observes *regions*, and notifies the /// values returned by the *reducer* whenever one of the observed /// regions is modified by a database transaction. @@ -406,40 +358,4 @@ extension ValueObservation where Reducer == Void { tracking: DatabaseRegion.union(regions), reducer: { _ in RawValueReducer(fetch) }) } - - /// Creates a ValueObservation which observes *regions*, and notifies the - /// values returned by the *fetch* closure whenever one of the observed - /// regions is modified by a database transaction. Consecutive equal values - /// are filtered out. - /// - /// For example: - /// - /// let observation = ValueObservation.tracking( - /// Player.all(), - /// fetchDistinct: { db in return try Player.fetchAll(db) }) - /// - /// let observer = try observation.start(in: dbQueue) { players: [Player] in - /// print("Players have changed") - /// } - /// - /// The returned observation has the default configuration: - /// - /// - When started with the `start(in:onError:onChange:)` method, a fresh - /// value is immediately notified on the main queue. - /// - Upon subsequent database changes, fresh values are notified on the - /// main queue. - /// - The observation lasts until the observer returned by - /// `start` is deallocated. - /// - /// - parameter regions: A list of observed regions. - /// - parameter fetch: A closure that fetches a value. - @available(*, deprecated, message: "Use distinctUntilChanged() instead") - public static func tracking( - _ regions: DatabaseRegionConvertible..., - fetchDistinct fetch: @escaping (Database) throws -> Value) - -> ValueObservation>> - where Value: Equatable - { - return ValueObservation.tracking(regions, fetch: fetch).distinctUntilChanged() - } } diff --git a/GRDB/ValueObservation/ValueObserver.swift b/GRDB/ValueObservation/ValueObserver.swift index c17adf6a5..a25e77827 100644 --- a/GRDB/ValueObservation/ValueObserver.swift +++ b/GRDB/ValueObservation/ValueObserver.swift @@ -5,7 +5,7 @@ import Foundation class ValueObserver: TransactionObserver { /* private */ let region: DatabaseRegion // Internal for testability private var reducer: Reducer - private let fetch: (Database, Reducer) -> Future + private let fetch: (Database, Reducer) -> DatabaseFuture private let notificationQueue: DispatchQueue? private let onError: ((Error) -> Void)? private let onChange: (Reducer.Value) -> Void @@ -16,7 +16,7 @@ class ValueObserver: TransactionObserver { region: DatabaseRegion, reducer: Reducer, configuration: Configuration, - fetch: @escaping (Database, Reducer) -> Future, + fetch: @escaping (Database, Reducer) -> DatabaseFuture, notificationQueue: DispatchQueue?, onError: ((Error) -> Void)?, onChange: @escaping (Reducer.Value) -> Void) diff --git a/GRDBCipher.podspec b/GRDBCipher.podspec deleted file mode 100644 index b4c8976de..000000000 --- a/GRDBCipher.podspec +++ /dev/null @@ -1,25 +0,0 @@ -Pod::Spec.new do |s| - s.name = 'GRDBCipher' - s.version = '3.7.0' - - s.license = { :type => 'MIT', :file => 'LICENSE' } - s.summary = 'A toolkit for SQLite databases, with a focus on application development.' - s.homepage = 'https://github.com/groue/GRDB.swift' - s.author = { 'Gwendal Roué' => 'gr@pierlis.com' } - s.source = { :git => 'https://github.com/groue/GRDB.swift.git', :tag => "v#{s.version}" } - s.module_name = 'GRDBCipher' - - s.ios.deployment_target = '8.0' - s.osx.deployment_target = '10.9' - s.watchos.deployment_target = '2.0' - - s.source_files = 'GRDB/**/*.swift', 'SQLCipher/*.h', 'Support/grdb_config.h' - s.module_map = 'SQLCipher/module.modulemap' - s.xcconfig = { - 'OTHER_SWIFT_FLAGS' => '$(inherited) -D SQLITE_HAS_CODEC -D GRDBCIPHER -D SQLITE_ENABLE_FTS5', - 'OTHER_CFLAGS' => '$(inherited) -DSQLITE_HAS_CODEC -DGRDBCIPHER -DSQLITE_ENABLE_FTS5', - 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) SQLITE_HAS_CODEC=1 GRDBCIPHER=1 SQLITE_ENABLE_FTS5=1' - } - s.framework = 'Foundation' - s.dependency 'SQLCipher', '~> 3.4.1' -end diff --git a/GRDBCipher.xcodeproj/project.pbxproj b/GRDBCipher.xcodeproj/project.pbxproj deleted file mode 100755 index 71a9ec433..000000000 --- a/GRDBCipher.xcodeproj/project.pbxproj +++ /dev/null @@ -1,3739 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 47; - objects = { - -/* Begin PBXBuildFile section */ - 56071A4E1DB54ED200CA6E47 /* FetchedRecordsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B15D0A1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift */; }; - 56071A4F1DB54ED300CA6E47 /* FetchedRecordsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B15D0A1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift */; }; - 560FC51C1CB003810014AA8E /* QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */; }; - 560FC51D1CB003810014AA8E /* SQLCollatedExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */; }; - 560FC51F1CB003810014AA8E /* CGFloat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1491C672E4000235C62 /* CGFloat.swift */; }; - 560FC5201CB003810014AA8E /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F14F1C672E4000235C62 /* Date.swift */; }; - 560FC5221CB003810014AA8E /* DatabaseValueConvertible+RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1571C672E4000235C62 /* DatabaseValueConvertible+RawRepresentable.swift */; }; - 560FC5231CB003810014AA8E /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238701B9C75030082EB20 /* Configuration.swift */; }; - 560FC5241CB003810014AA8E /* DatabaseWriter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363C31C942C37000BE133 /* DatabaseWriter.swift */; }; - 560FC5261CB003810014AA8E /* SerializedDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37A61C8FF6E500949E71 /* SerializedDatabase.swift */; }; - 560FC5271CB003810014AA8E /* NSString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1521C672E4000235C62 /* NSString.swift */; }; - 560FC5291CB003810014AA8E /* DatabaseValueConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560D923E1C672C3E00F4F92B /* DatabaseValueConvertible.swift */; }; - 560FC52A1CB003810014AA8E /* DatabaseError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238731B9C75030082EB20 /* DatabaseError.swift */; }; - 560FC52B1CB003810014AA8E /* DatabaseValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238751B9C75030082EB20 /* DatabaseValue.swift */; }; - 560FC52E1CB003810014AA8E /* Record.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238A11B9C753B0082EB20 /* Record.swift */; }; - 560FC5311CB003810014AA8E /* TableRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560D92461C672C4B00F4F92B /* TableRecord.swift */; }; - 560FC5321CB003810014AA8E /* DatabasePool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37A31C8F625000949E71 /* DatabasePool.swift */; }; - 560FC5331CB003810014AA8E /* Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4391BEB42D500E39BBF /* Migration.swift */; }; - 560FC5351CB003810014AA8E /* Statement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238781B9C75030082EB20 /* Statement.swift */; }; - 560FC5361CB003810014AA8E /* DatabaseMigrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238921B9C750B0082EB20 /* DatabaseMigrator.swift */; }; - 560FC5371CB003810014AA8E /* DatabaseSchemaCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5695311E1C907A8C00CF1A2B /* DatabaseSchemaCache.swift */; }; - 560FC5381CB003810014AA8E /* DatabaseDateComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F14C1C672E4000235C62 /* DatabaseDateComponents.swift */; }; - 560FC5391CB003810014AA8E /* DatabaseReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363BF1C942C04000BE133 /* DatabaseReader.swift */; }; - 560FC53A1CB003810014AA8E /* NSNull.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1501C672E4000235C62 /* NSNull.swift */; }; - 560FC53B1CB003810014AA8E /* Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238711B9C75030082EB20 /* Database.swift */; }; - 560FC53C1CB003810014AA8E /* DatabaseQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238741B9C75030082EB20 /* DatabaseQueue.swift */; }; - 560FC53D1CB003810014AA8E /* NSNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1511C672E4000235C62 /* NSNumber.swift */; }; - 560FC53F1CB003810014AA8E /* Row.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238761B9C75030082EB20 /* Row.swift */; }; - 560FC5401CB003810014AA8E /* StandardLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1581C672E4000235C62 /* StandardLibrary.swift */; }; - 560FC5411CB003810014AA8E /* PersistableRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560D92441C672C4B00F4F92B /* PersistableRecord.swift */; }; - 560FC5421CB003810014AA8E /* StatementColumnConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560D923F1C672C3E00F4F92B /* StatementColumnConvertible.swift */; }; - 560FC5611CB00B880014AA8E /* DatabaseValueConversionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381B1B9C74A90082EB20 /* DatabaseValueConversionTests.swift */; }; - 560FC5621CB00B880014AA8E /* Record+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B841C54DC95005A543B /* Record+QueryInterfaceRequestTests.swift */; }; - 560FC5651CB00B880014AA8E /* RecordPrimaryKeyNoneTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238291B9C74A90082EB20 /* RecordPrimaryKeyNoneTests.swift */; }; - 560FC5661CB00B880014AA8E /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238261B9C74A90082EB20 /* RecordMinimalPrimaryKeyRowIDTests.swift */; }; - 560FC5671CB00B880014AA8E /* RowFromDictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381E1B9C74A90082EB20 /* RowFromDictionaryTests.swift */; }; - 560FC5681CB00B880014AA8E /* SelectStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238211B9C74A90082EB20 /* SelectStatementTests.swift */; }; - 560FC56A1CB00B880014AA8E /* QueryInterfaceExpressionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B671C53D25E005A543B /* QueryInterfaceExpressionsTests.swift */; }; - 560FC56B1CB00B880014AA8E /* DatabaseCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A50C61BFF4B7F00B3A3A2 /* DatabaseCollationTests.swift */; }; - 560FC56C1CB00B880014AA8E /* UpdateStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238221B9C74A90082EB20 /* UpdateStatementTests.swift */; }; - 560FC56D1CB00B880014AA8E /* DatabaseMigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238241B9C74A90082EB20 /* DatabaseMigratorTests.swift */; }; - 560FC5701CB00B880014AA8E /* DatabasePoolCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531331C919DF200CF1A2B /* DatabasePoolCollationTests.swift */; }; - 560FC5711CB00B880014AA8E /* RecordPrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382B1B9C74A90082EB20 /* RecordPrimaryKeySingleTests.swift */; }; - 560FC5741CB00B880014AA8E /* DatabasePoolFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531361C919DF700CF1A2B /* DatabasePoolFunctionTests.swift */; }; - 560FC5761CB00B880014AA8E /* RowCopiedFromStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381F1B9C74A90082EB20 /* RowCopiedFromStatementTests.swift */; }; - 560FC5771CB00B880014AA8E /* DatabaseQueueSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531231C90878D00CF1A2B /* DatabaseQueueSchemaCacheTests.swift */; }; - 560FC5781CB00B880014AA8E /* RowFromStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FDECE11BB32DFD009AD709 /* RowFromStatementTests.swift */; }; - 560FC5791CB00B880014AA8E /* RecordPrimaryKeyMultipleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238281B9C74A90082EB20 /* RecordPrimaryKeyMultipleTests.swift */; }; - 560FC57C1CB00B880014AA8E /* StatementArgumentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DE7B101C3D93ED00861EB8 /* StatementArgumentsTests.swift */; }; - 560FC57D1CB00B880014AA8E /* RecordInitializersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238321B9C74A90082EB20 /* RecordInitializersTests.swift */; }; - 560FC57E1CB00B880014AA8E /* MutablePersistableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363A91C933FF8000BE133 /* MutablePersistableRecordTests.swift */; }; - 560FC57F1CB00B880014AA8E /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B601C53C42C005A543B /* FetchableRecord+QueryInterfaceRequestTests.swift */; }; - 560FC5811CB00B880014AA8E /* RecordCopyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382D1B9C74A90082EB20 /* RecordCopyTests.swift */; }; - 560FC5821CB00B880014AA8E /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381C1B9C74A90082EB20 /* RawRepresentable+DatabaseValueConvertibleTests.swift */; }; - 560FC5841CB00B880014AA8E /* PersistableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AA1C933FF8000BE133 /* PersistableRecordTests.swift */; }; - 560FC5871CB00B880014AA8E /* RecordSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238331B9C74A90082EB20 /* RecordSubClassTests.swift */; }; - 560FC5891CB00B880014AA8E /* TransactionObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5607EFD21BB8254800605DE3 /* TransactionObserverTests.swift */; }; - 560FC58B1CB00B880014AA8E /* DatabaseValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238181B9C74A90082EB20 /* DatabaseValueTests.swift */; }; - 560FC58D1CB00B880014AA8E /* Row+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D701BBC694D00DC9BD4 /* Row+FoundationTests.swift */; }; - 560FC58E1CB00B880014AA8E /* RecordPrimaryKeyRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382A1B9C74A90082EB20 /* RecordPrimaryKeyRowIDTests.swift */; }; - 560FC58F1CB00B880014AA8E /* DatabaseReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA86931C91DFE7002BB4DF /* DatabaseReaderTests.swift */; }; - 560FC5901CB00B880014AA8E /* RecordEditedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382F1B9C74A90082EB20 /* RecordEditedTests.swift */; }; - 560FC5911CB00B880014AA8E /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382C1B9C74A90082EB20 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift */; }; - 560FC5921CB00B880014AA8E /* FetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565B0FEE1BBC7D980098DE03 /* FetchableRecordTests.swift */; }; - 560FC5941CB00B880014AA8E /* DatabaseValueConvertibleSubclassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381A1B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift */; }; - 560FC5961CB00B880014AA8E /* DatabaseValueConvertibleFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E8CE0C1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift */; }; - 560FC5971CB00B880014AA8E /* DatabaseErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238161B9C74A90082EB20 /* DatabaseErrorTests.swift */; }; - 560FC5991CB00B880014AA8E /* RecordMinimalPrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238271B9C74A90082EB20 /* RecordMinimalPrimaryKeySingleTests.swift */; }; - 560FC59B1CB00B880014AA8E /* DatabaseTimestampTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238B51B9CA2590082EB20 /* DatabaseTimestampTests.swift */; }; - 560FC59C1CB00B880014AA8E /* StatementArguments+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D731BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift */; }; - 560FC59D1CB00B880014AA8E /* TableRecord+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B6A1C53D3E8005A543B /* TableRecord+QueryInterfaceRequestTests.swift */; }; - 560FC59E1CB00B880014AA8E /* FoundationNSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* FoundationNSDateTests.swift */; }; - 560FC59F1CB00B880014AA8E /* DatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238131B9C74A90082EB20 /* DatabaseTests.swift */; }; - 560FC5A01CB00B880014AA8E /* QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B5D1C53C38F005A543B /* QueryInterfaceRequestTests.swift */; }; - 560FC5A21CB00B880014AA8E /* DatabaseFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560C97C61BFD0B8400BF8471 /* DatabaseFunctionTests.swift */; }; - 560FC5A41CB00B880014AA8E /* RecordWithColumnNameManglingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A5E4081BA2BCF900707640 /* RecordWithColumnNameManglingTests.swift */; }; - 560FC5A51CB00B880014AA8E /* CGFloatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4291BE14A1900E39BBF /* CGFloatTests.swift */; }; - 560FC5A61CB00B880014AA8E /* DatabaseRegionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1861C69111300235C62 /* DatabaseRegionTests.swift */; }; - 560FC5A71CB00B880014AA8E /* GRDBTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623E0901B4AFACC00B20B7F /* GRDBTestCase.swift */; }; - 560FC5B21CB031E30014AA8E /* StatementColumnConvertibleFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E8CE0F1BB4FE5B00828BEC /* StatementColumnConvertibleFetchTests.swift */; }; - 560FC5B31CB031EA0014AA8E /* DataMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EB0AB11BCD787300A3DC55 /* DataMemoryTests.swift */; }; - 5613ED7B21A95E8400DC7A68 /* ValueObservation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED7321A95E8400DC7A68 /* ValueObservation.swift */; }; - 5613ED7C21A95E8400DC7A68 /* ValueObservation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED7321A95E8400DC7A68 /* ValueObservation.swift */; }; - 5613ED7D21A95E8400DC7A68 /* ValueObservation+Combine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED7421A95E8400DC7A68 /* ValueObservation+Combine.swift */; }; - 5613ED7E21A95E8400DC7A68 /* ValueObservation+Combine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED7421A95E8400DC7A68 /* ValueObservation+Combine.swift */; }; - 5613ED7F21A95E8400DC7A68 /* ValueObservation+Map.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED7521A95E8400DC7A68 /* ValueObservation+Map.swift */; }; - 5613ED8021A95E8400DC7A68 /* ValueObservation+Map.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED7521A95E8400DC7A68 /* ValueObservation+Map.swift */; }; - 5613ED8121A95E8400DC7A68 /* ValueObservation+Row.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED7621A95E8400DC7A68 /* ValueObservation+Row.swift */; }; - 5613ED8221A95E8400DC7A68 /* ValueObservation+Row.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED7621A95E8400DC7A68 /* ValueObservation+Row.swift */; }; - 5613ED8321A95E8400DC7A68 /* ValueObservation+FetchableRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED7721A95E8400DC7A68 /* ValueObservation+FetchableRecord.swift */; }; - 5613ED8421A95E8400DC7A68 /* ValueObservation+FetchableRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED7721A95E8400DC7A68 /* ValueObservation+FetchableRecord.swift */; }; - 5613ED8521A95E8400DC7A68 /* ValueObservation+DatabaseValueConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED7821A95E8400DC7A68 /* ValueObservation+DatabaseValueConvertible.swift */; }; - 5613ED8621A95E8400DC7A68 /* ValueObservation+DatabaseValueConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED7821A95E8400DC7A68 /* ValueObservation+DatabaseValueConvertible.swift */; }; - 5613ED8721A95E8400DC7A68 /* ValueReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED7921A95E8400DC7A68 /* ValueReducer.swift */; }; - 5613ED8821A95E8400DC7A68 /* ValueReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED7921A95E8400DC7A68 /* ValueReducer.swift */; }; - 5613ED8921A95E8400DC7A68 /* ValueObservation+Count.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED7A21A95E8400DC7A68 /* ValueObservation+Count.swift */; }; - 5613ED8A21A95E8400DC7A68 /* ValueObservation+Count.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED7A21A95E8400DC7A68 /* ValueObservation+Count.swift */; }; - 5613ED9E21A96A6F00DC7A68 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED9D21A96A6F00DC7A68 /* ValueObservationCombineTests.swift */; }; - 5613ED9F21A96A6F00DC7A68 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED9D21A96A6F00DC7A68 /* ValueObservationCombineTests.swift */; }; - 5613EDA021A96A6F00DC7A68 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED9D21A96A6F00DC7A68 /* ValueObservationCombineTests.swift */; }; - 5613EDA121A96A6F00DC7A68 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED9D21A96A6F00DC7A68 /* ValueObservationCombineTests.swift */; }; - 561667021D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 561667001D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift */; }; - 561667031D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 561667001D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift */; }; - 561667061D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 561667001D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift */; }; - 561667071D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 561667001D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift */; }; - 5616AAF9207CD5A900AC3664 /* RequestProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5616AAF8207CD5A900AC3664 /* RequestProtocols.swift */; }; - 5616AAFA207CD5A900AC3664 /* RequestProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5616AAF8207CD5A900AC3664 /* RequestProtocols.swift */; }; - 56176C5F1EACCCC7000F3F2B /* FTS5CustomTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD001DAA8ACA0056AF8C /* FTS5CustomTokenizerTests.swift */; }; - 56176C601EACCCC7000F3F2B /* FTS5PatternTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964C01DA521450002DA19 /* FTS5PatternTests.swift */; }; - 56176C611EACCCC7000F3F2B /* FTS5RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964C11DA521450002DA19 /* FTS5RecordTests.swift */; }; - 56176C621EACCCC7000F3F2B /* FTS5TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964C21DA521450002DA19 /* FTS5TableBuilderTests.swift */; }; - 56176C631EACCCC7000F3F2B /* FTS5TokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698ACCA1DA62A2D0056AF8C /* FTS5TokenizerTests.swift */; }; - 56176C641EACCCC7000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56ED8A7E1DAB8D6800BD0ABC /* FTS5WrapperTokenizerTests.swift */; }; - 56176C651EACCCC8000F3F2B /* FTS5CustomTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD001DAA8ACA0056AF8C /* FTS5CustomTokenizerTests.swift */; }; - 56176C661EACCCC8000F3F2B /* FTS5PatternTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964C01DA521450002DA19 /* FTS5PatternTests.swift */; }; - 56176C671EACCCC8000F3F2B /* FTS5RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964C11DA521450002DA19 /* FTS5RecordTests.swift */; }; - 56176C681EACCCC8000F3F2B /* FTS5TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964C21DA521450002DA19 /* FTS5TableBuilderTests.swift */; }; - 56176C691EACCCC8000F3F2B /* FTS5TokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698ACCA1DA62A2D0056AF8C /* FTS5TokenizerTests.swift */; }; - 56176C6A1EACCCC8000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56ED8A7E1DAB8D6800BD0ABC /* FTS5WrapperTokenizerTests.swift */; }; - 56176C711EACCCCA000F3F2B /* FTS5CustomTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD001DAA8ACA0056AF8C /* FTS5CustomTokenizerTests.swift */; }; - 56176C721EACCCCA000F3F2B /* FTS5PatternTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964C01DA521450002DA19 /* FTS5PatternTests.swift */; }; - 56176C731EACCCCA000F3F2B /* FTS5RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964C11DA521450002DA19 /* FTS5RecordTests.swift */; }; - 56176C741EACCCCA000F3F2B /* FTS5TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964C21DA521450002DA19 /* FTS5TableBuilderTests.swift */; }; - 56176C751EACCCCA000F3F2B /* FTS5TokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698ACCA1DA62A2D0056AF8C /* FTS5TokenizerTests.swift */; }; - 56176C761EACCCCA000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56ED8A7E1DAB8D6800BD0ABC /* FTS5WrapperTokenizerTests.swift */; }; - 56176C771EACCCCB000F3F2B /* FTS5CustomTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD001DAA8ACA0056AF8C /* FTS5CustomTokenizerTests.swift */; }; - 56176C781EACCCCB000F3F2B /* FTS5PatternTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964C01DA521450002DA19 /* FTS5PatternTests.swift */; }; - 56176C791EACCCCB000F3F2B /* FTS5RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964C11DA521450002DA19 /* FTS5RecordTests.swift */; }; - 56176C7A1EACCCCB000F3F2B /* FTS5TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964C21DA521450002DA19 /* FTS5TableBuilderTests.swift */; }; - 56176C7B1EACCCCB000F3F2B /* FTS5TokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698ACCA1DA62A2D0056AF8C /* FTS5TokenizerTests.swift */; }; - 56176C7C1EACCCCB000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56ED8A7E1DAB8D6800BD0ABC /* FTS5WrapperTokenizerTests.swift */; }; - 56193E961CD8A3E300F95862 /* FetchedRecordsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31A7787C1C6A4DD600F507F6 /* FetchedRecordsController.swift */; }; - 562205F41E420E48005860AC /* DatabasePoolReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363CF1C943D13000BE133 /* DatabasePoolReleaseMemoryTests.swift */; }; - 562205F51E420E48005860AC /* DatabasePoolSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531281C908A5B00CF1A2B /* DatabasePoolSchemaCacheTests.swift */; }; - 562205F61E420E48005860AC /* DatabaseQueueReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363D41C94484E000BE133 /* DatabaseQueueReleaseMemoryTests.swift */; }; - 562205F71E420E49005860AC /* DatabasePoolReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363CF1C943D13000BE133 /* DatabasePoolReleaseMemoryTests.swift */; }; - 562205F81E420E49005860AC /* DatabasePoolSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531281C908A5B00CF1A2B /* DatabasePoolSchemaCacheTests.swift */; }; - 562205F91E420E49005860AC /* DatabaseQueueReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363D41C94484E000BE133 /* DatabaseQueueReleaseMemoryTests.swift */; }; - 562206001E420EA3005860AC /* DatabasePoolBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5672DE661CDB751D0022BA81 /* DatabasePoolBackupTests.swift */; }; - 562206011E420EA3005860AC /* DatabasePoolConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37AA1C90085D00949E71 /* DatabasePoolConcurrencyTests.swift */; }; - 562206021E420EA3005860AC /* DatabasePoolReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA869D1C932597002BB4DF /* DatabasePoolReadOnlyTests.swift */; }; - 562206031E420EA3005860AC /* DatabasePoolBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5672DE661CDB751D0022BA81 /* DatabasePoolBackupTests.swift */; }; - 562206041E420EA3005860AC /* DatabasePoolConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37AA1C90085D00949E71 /* DatabasePoolConcurrencyTests.swift */; }; - 562206051E420EA3005860AC /* DatabasePoolReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA869D1C932597002BB4DF /* DatabasePoolReadOnlyTests.swift */; }; - 5622060A1E420EB2005860AC /* DatabaseQueueConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363BC1C93FD5E000BE133 /* DatabaseQueueConcurrencyTests.swift */; }; - 5622060B1E420EB3005860AC /* DatabaseQueueConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363BC1C93FD5E000BE133 /* DatabaseQueueConcurrencyTests.swift */; }; - 562393191DECC02000A6B01F /* RowFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393171DECC02000A6B01F /* RowFetchTests.swift */; }; - 5623931A1DECC02000A6B01F /* RowFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393171DECC02000A6B01F /* RowFetchTests.swift */; }; - 5623931D1DECC02000A6B01F /* RowFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393171DECC02000A6B01F /* RowFetchTests.swift */; }; - 5623931E1DECC02000A6B01F /* RowFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393171DECC02000A6B01F /* RowFetchTests.swift */; }; - 562393311DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623932F1DEDFC5700A6B01F /* AnyCursorTests.swift */; }; - 562393321DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623932F1DEDFC5700A6B01F /* AnyCursorTests.swift */; }; - 562393351DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623932F1DEDFC5700A6B01F /* AnyCursorTests.swift */; }; - 562393361DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623932F1DEDFC5700A6B01F /* AnyCursorTests.swift */; }; - 5623934F1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */; }; - 562393501DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */; }; - 562393531DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */; }; - 562393541DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */; }; - 562393581DEE013C00A6B01F /* FilterCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393561DEE013C00A6B01F /* FilterCursorTests.swift */; }; - 562393591DEE013C00A6B01F /* FilterCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393561DEE013C00A6B01F /* FilterCursorTests.swift */; }; - 5623935C1DEE013C00A6B01F /* FilterCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393561DEE013C00A6B01F /* FilterCursorTests.swift */; }; - 5623935D1DEE013C00A6B01F /* FilterCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393561DEE013C00A6B01F /* FilterCursorTests.swift */; }; - 562393611DEE06D300A6B01F /* CursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623935F1DEE06D300A6B01F /* CursorTests.swift */; }; - 562393621DEE06D300A6B01F /* CursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623935F1DEE06D300A6B01F /* CursorTests.swift */; }; - 562393651DEE06D300A6B01F /* CursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623935F1DEE06D300A6B01F /* CursorTests.swift */; }; - 562393661DEE06D300A6B01F /* CursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623935F1DEE06D300A6B01F /* CursorTests.swift */; }; - 5623936A1DEE0CD200A6B01F /* FlattenCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393681DEE0CD200A6B01F /* FlattenCursorTests.swift */; }; - 5623936B1DEE0CD200A6B01F /* FlattenCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393681DEE0CD200A6B01F /* FlattenCursorTests.swift */; }; - 5623936E1DEE0CD200A6B01F /* FlattenCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393681DEE0CD200A6B01F /* FlattenCursorTests.swift */; }; - 5623936F1DEE0CD200A6B01F /* FlattenCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393681DEE0CD200A6B01F /* FlattenCursorTests.swift */; }; - 562393731DEE104400A6B01F /* MapCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393711DEE104400A6B01F /* MapCursorTests.swift */; }; - 562393741DEE104400A6B01F /* MapCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393711DEE104400A6B01F /* MapCursorTests.swift */; }; - 562393771DEE104400A6B01F /* MapCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393711DEE104400A6B01F /* MapCursorTests.swift */; }; - 562393781DEE104400A6B01F /* MapCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393711DEE104400A6B01F /* MapCursorTests.swift */; }; - 562756441E963AAC0035B653 /* DatabaseWriterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562756421E963AAC0035B653 /* DatabaseWriterTests.swift */; }; - 562756451E963AAC0035B653 /* DatabaseWriterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562756421E963AAC0035B653 /* DatabaseWriterTests.swift */; }; - 562756481E963AAC0035B653 /* DatabaseWriterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562756421E963AAC0035B653 /* DatabaseWriterTests.swift */; }; - 562756491E963AAC0035B653 /* DatabaseWriterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562756421E963AAC0035B653 /* DatabaseWriterTests.swift */; }; - 562EA8271F17B2AC00FA528C /* CompilationProtocolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562EA8251F17B2AC00FA528C /* CompilationProtocolTests.swift */; }; - 562EA8281F17B2AC00FA528C /* CompilationProtocolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562EA8251F17B2AC00FA528C /* CompilationProtocolTests.swift */; }; - 562EA82B1F17B2AC00FA528C /* CompilationProtocolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562EA8251F17B2AC00FA528C /* CompilationProtocolTests.swift */; }; - 562EA82C1F17B2AC00FA528C /* CompilationProtocolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562EA8251F17B2AC00FA528C /* CompilationProtocolTests.swift */; }; - 562EA8301F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562EA82E1F17B9EB00FA528C /* CompilationSubClassTests.swift */; }; - 562EA8311F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562EA82E1F17B9EB00FA528C /* CompilationSubClassTests.swift */; }; - 562EA8341F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562EA82E1F17B9EB00FA528C /* CompilationSubClassTests.swift */; }; - 562EA8351F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562EA82E1F17B9EB00FA528C /* CompilationSubClassTests.swift */; }; - 5634B1081CF9B970005360B9 /* TransactionObserverSavepointsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5634B1061CF9B970005360B9 /* TransactionObserverSavepointsTests.swift */; }; - 5634B1091CF9B970005360B9 /* TransactionObserverSavepointsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5634B1061CF9B970005360B9 /* TransactionObserverSavepointsTests.swift */; }; - 5634B10B1CF9B970005360B9 /* TransactionObserverSavepointsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5634B1061CF9B970005360B9 /* TransactionObserverSavepointsTests.swift */; }; - 5634B10C1CF9B970005360B9 /* TransactionObserverSavepointsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5634B1061CF9B970005360B9 /* TransactionObserverSavepointsTests.swift */; }; - 5636E9BD1D22574100B9B05F /* FetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5636E9BB1D22574100B9B05F /* FetchRequest.swift */; }; - 5636E9C01D22574100B9B05F /* FetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5636E9BB1D22574100B9B05F /* FetchRequest.swift */; }; - 563B06E12185E07200B38F35 /* ValueObservationExtentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06DC2185E07100B38F35 /* ValueObservationExtentTests.swift */; }; - 563B06E22185E07200B38F35 /* ValueObservationExtentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06DC2185E07100B38F35 /* ValueObservationExtentTests.swift */; }; - 563B06E32185E07300B38F35 /* ValueObservationExtentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06DC2185E07100B38F35 /* ValueObservationExtentTests.swift */; }; - 563B06E42185E07300B38F35 /* ValueObservationExtentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06DC2185E07100B38F35 /* ValueObservationExtentTests.swift */; }; - 563B06E52185E07300B38F35 /* ValueObservationReadonlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06DD2185E07200B38F35 /* ValueObservationReadonlyTests.swift */; }; - 563B06E62185E07300B38F35 /* ValueObservationReadonlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06DD2185E07200B38F35 /* ValueObservationReadonlyTests.swift */; }; - 563B06E72185E07300B38F35 /* ValueObservationReadonlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06DD2185E07200B38F35 /* ValueObservationReadonlyTests.swift */; }; - 563B06E82185E07300B38F35 /* ValueObservationReadonlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06DD2185E07200B38F35 /* ValueObservationReadonlyTests.swift */; }; - 563B06E92185E07300B38F35 /* ValueObservationFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06DE2185E07200B38F35 /* ValueObservationFetchTests.swift */; }; - 563B06EA2185E07300B38F35 /* ValueObservationFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06DE2185E07200B38F35 /* ValueObservationFetchTests.swift */; }; - 563B06EB2185E07300B38F35 /* ValueObservationFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06DE2185E07200B38F35 /* ValueObservationFetchTests.swift */; }; - 563B06EC2185E07300B38F35 /* ValueObservationFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06DE2185E07200B38F35 /* ValueObservationFetchTests.swift */; }; - 563B06ED2185E07300B38F35 /* ValueObservationReducerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06DF2185E07200B38F35 /* ValueObservationReducerTests.swift */; }; - 563B06EE2185E07300B38F35 /* ValueObservationReducerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06DF2185E07200B38F35 /* ValueObservationReducerTests.swift */; }; - 563B06EF2185E07300B38F35 /* ValueObservationReducerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06DF2185E07200B38F35 /* ValueObservationReducerTests.swift */; }; - 563B06F02185E07300B38F35 /* ValueObservationReducerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06DF2185E07200B38F35 /* ValueObservationReducerTests.swift */; }; - 563B06F12185E07300B38F35 /* ValueObservationSchedulingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06E02185E07200B38F35 /* ValueObservationSchedulingTests.swift */; }; - 563B06F22185E07300B38F35 /* ValueObservationSchedulingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06E02185E07200B38F35 /* ValueObservationSchedulingTests.swift */; }; - 563B06F32185E07300B38F35 /* ValueObservationSchedulingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06E02185E07200B38F35 /* ValueObservationSchedulingTests.swift */; }; - 563B06F42185E07300B38F35 /* ValueObservationSchedulingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06E02185E07200B38F35 /* ValueObservationSchedulingTests.swift */; }; - 563B06FA21861D8B00B38F35 /* ValueObservationCountTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06F921861D8B00B38F35 /* ValueObservationCountTests.swift */; }; - 563B06FB21861D8B00B38F35 /* ValueObservationCountTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06F921861D8B00B38F35 /* ValueObservationCountTests.swift */; }; - 563B06FC21861D8B00B38F35 /* ValueObservationCountTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06F921861D8B00B38F35 /* ValueObservationCountTests.swift */; }; - 563B06FD21861D8B00B38F35 /* ValueObservationCountTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06F921861D8B00B38F35 /* ValueObservationCountTests.swift */; }; - 563B07082186280600B38F35 /* ValueObservationRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B07072186280500B38F35 /* ValueObservationRowTests.swift */; }; - 563B07092186280600B38F35 /* ValueObservationRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B07072186280500B38F35 /* ValueObservationRowTests.swift */; }; - 563B070A2186280600B38F35 /* ValueObservationRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B07072186280500B38F35 /* ValueObservationRowTests.swift */; }; - 563B070B2186280600B38F35 /* ValueObservationRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B07072186280500B38F35 /* ValueObservationRowTests.swift */; }; - 563B070D21862C3600B38F35 /* ValueObservationRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B070C21862C3500B38F35 /* ValueObservationRecordTests.swift */; }; - 563B070E21862C3600B38F35 /* ValueObservationRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B070C21862C3500B38F35 /* ValueObservationRecordTests.swift */; }; - 563B070F21862C3600B38F35 /* ValueObservationRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B070C21862C3500B38F35 /* ValueObservationRecordTests.swift */; }; - 563B071021862C3600B38F35 /* ValueObservationRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B070C21862C3500B38F35 /* ValueObservationRecordTests.swift */; }; - 563B071E21862F5D00B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B071D21862F5D00B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift */; }; - 563B071F21862F5D00B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B071D21862F5D00B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift */; }; - 563B072021862F5D00B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B071D21862F5D00B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift */; }; - 563B072121862F5D00B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B071D21862F5D00B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift */; }; - 563EF424215F8A88007DAACD /* OrderedDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF422215F8A88007DAACD /* OrderedDictionary.swift */; }; - 563EF425215F8A88007DAACD /* OrderedDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF422215F8A88007DAACD /* OrderedDictionary.swift */; }; - 563EF43C2161183E007DAACD /* AssociationAggregate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF43A2161183E007DAACD /* AssociationAggregate.swift */; }; - 563EF43D2161183E007DAACD /* AssociationAggregate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF43A2161183E007DAACD /* AssociationAggregate.swift */; }; - 563EF44521613213007DAACD /* AssociationAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF44421613212007DAACD /* AssociationAggregateTests.swift */; }; - 563EF44621613213007DAACD /* AssociationAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF44421613212007DAACD /* AssociationAggregateTests.swift */; }; - 563EF44721613213007DAACD /* AssociationAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF44421613212007DAACD /* AssociationAggregateTests.swift */; }; - 563EF44821613213007DAACD /* AssociationAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF44421613212007DAACD /* AssociationAggregateTests.swift */; }; - 563EF4502161F1A8007DAACD /* Inflections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF44F2161F1A7007DAACD /* Inflections.swift */; }; - 563EF4512161F1A8007DAACD /* Inflections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF44F2161F1A7007DAACD /* Inflections.swift */; }; - 563EF45921631E51007DAACD /* QueryInterfacePromiseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF45821631E51007DAACD /* QueryInterfacePromiseTests.swift */; }; - 563EF45A21631E51007DAACD /* QueryInterfacePromiseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF45821631E51007DAACD /* QueryInterfacePromiseTests.swift */; }; - 563EF45B21631E51007DAACD /* QueryInterfacePromiseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF45821631E51007DAACD /* QueryInterfacePromiseTests.swift */; }; - 563EF45C21631E51007DAACD /* QueryInterfacePromiseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF45821631E51007DAACD /* QueryInterfacePromiseTests.swift */; }; - 564448841EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564448821EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift */; }; - 564448851EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564448821EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift */; }; - 564448881EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564448821EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift */; }; - 564448891EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564448821EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift */; }; - 5644DE7C20F8C903001FFDDE /* DatabaseValueConversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5644DE7A20F8C903001FFDDE /* DatabaseValueConversion.swift */; }; - 5644DE7D20F8C903001FFDDE /* DatabaseValueConversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5644DE7A20F8C903001FFDDE /* DatabaseValueConversion.swift */; }; - 5644DE8220F8D1E4001FFDDE /* DatabaseValueConversionErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5644DE8120F8D1E4001FFDDE /* DatabaseValueConversionErrorTests.swift */; }; - 5644DE8320F8D1E4001FFDDE /* DatabaseValueConversionErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5644DE8120F8D1E4001FFDDE /* DatabaseValueConversionErrorTests.swift */; }; - 5644DE8420F8D1E4001FFDDE /* DatabaseValueConversionErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5644DE8120F8D1E4001FFDDE /* DatabaseValueConversionErrorTests.swift */; }; - 5644DE8520F8D1E4001FFDDE /* DatabaseValueConversionErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5644DE8120F8D1E4001FFDDE /* DatabaseValueConversionErrorTests.swift */; }; - 564CE44021AA957000652B19 /* ValueObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE43F21AA957000652B19 /* ValueObserver.swift */; }; - 564CE44121AA957000652B19 /* ValueObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE43F21AA957000652B19 /* ValueObserver.swift */; }; - 564CE4DD21B2DEF700652B19 /* ValueObservation+CompactMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE4DC21B2DEF700652B19 /* ValueObservation+CompactMap.swift */; }; - 564CE4DE21B2DEF700652B19 /* ValueObservation+CompactMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE4DC21B2DEF700652B19 /* ValueObservation+CompactMap.swift */; }; - 564CE4EC21B2E08300652B19 /* ValueObservationCompactMapTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE4EB21B2E08200652B19 /* ValueObservationCompactMapTests.swift */; }; - 564CE4ED21B2E08300652B19 /* ValueObservationCompactMapTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE4EB21B2E08200652B19 /* ValueObservationCompactMapTests.swift */; }; - 564CE4EE21B2E08300652B19 /* ValueObservationCompactMapTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE4EB21B2E08200652B19 /* ValueObservationCompactMapTests.swift */; }; - 564CE4EF21B2E08300652B19 /* ValueObservationCompactMapTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE4EB21B2E08200652B19 /* ValueObservationCompactMapTests.swift */; }; - 564CE4F121B2E08A00652B19 /* ValueObservationMapTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE4F021B2E08A00652B19 /* ValueObservationMapTests.swift */; }; - 564CE4F221B2E08A00652B19 /* ValueObservationMapTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE4F021B2E08A00652B19 /* ValueObservationMapTests.swift */; }; - 564CE4F321B2E08A00652B19 /* ValueObservationMapTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE4F021B2E08A00652B19 /* ValueObservationMapTests.swift */; }; - 564CE4F421B2E08A00652B19 /* ValueObservationMapTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE4F021B2E08A00652B19 /* ValueObservationMapTests.swift */; }; - 564CE52621B312B500652B19 /* ValueObservation+MapReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE51A21B3128400652B19 /* ValueObservation+MapReducer.swift */; }; - 564CE52721B312B700652B19 /* ValueObservation+MapReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE51A21B3128400652B19 /* ValueObservation+MapReducer.swift */; }; - 564CE5A621B7A9D600652B19 /* ValueObservation+DistinctUntilChanged.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE5A421B7A9D600652B19 /* ValueObservation+DistinctUntilChanged.swift */; }; - 564CE5A721B7A9D600652B19 /* ValueObservation+DistinctUntilChanged.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE5A421B7A9D600652B19 /* ValueObservation+DistinctUntilChanged.swift */; }; - 564CE5BB21B8FBFD00652B19 /* DatabaseRegionObservation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE5B921B8FBFD00652B19 /* DatabaseRegionObservation.swift */; }; - 564CE5BC21B8FBFD00652B19 /* DatabaseRegionObservation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE5B921B8FBFD00652B19 /* DatabaseRegionObservation.swift */; }; - 564CE5C121B8FFD800652B19 /* DatabaseRegionObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE5C021B8FFD800652B19 /* DatabaseRegionObservationTests.swift */; }; - 564CE5C221B8FFD800652B19 /* DatabaseRegionObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE5C021B8FFD800652B19 /* DatabaseRegionObservationTests.swift */; }; - 564CE5C321B8FFD800652B19 /* DatabaseRegionObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE5C021B8FFD800652B19 /* DatabaseRegionObservationTests.swift */; }; - 564CE5C421B8FFD800652B19 /* DatabaseRegionObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564CE5C021B8FFD800652B19 /* DatabaseRegionObservationTests.swift */; }; - 564E73EF203DA2A2000C443C /* JoinSupportTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564E73EB203DA29B000C443C /* JoinSupportTests.swift */; }; - 564E73F0203DA2A3000C443C /* JoinSupportTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564E73EB203DA29B000C443C /* JoinSupportTests.swift */; }; - 564E73F1203DA2A3000C443C /* JoinSupportTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564E73EB203DA29B000C443C /* JoinSupportTests.swift */; }; - 564E73F2203DA2A4000C443C /* JoinSupportTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564E73EB203DA29B000C443C /* JoinSupportTests.swift */; }; - 564F9C1F1F069B4E00877A00 /* DatabaseAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C1D1F069B4E00877A00 /* DatabaseAggregateTests.swift */; }; - 564F9C201F069B4E00877A00 /* DatabaseAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C1D1F069B4E00877A00 /* DatabaseAggregateTests.swift */; }; - 564F9C231F069B4E00877A00 /* DatabaseAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C1D1F069B4E00877A00 /* DatabaseAggregateTests.swift */; }; - 564F9C241F069B4E00877A00 /* DatabaseAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C1D1F069B4E00877A00 /* DatabaseAggregateTests.swift */; }; - 564F9C2F1F07611400877A00 /* DatabaseFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */; }; - 564F9C321F07611700877A00 /* DatabaseFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */; }; - 5653EB8F20961FC000F46237 /* BelongsToAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8520961FBF00F46237 /* BelongsToAssociation.swift */; }; - 5653EB9020961FC000F46237 /* BelongsToAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8520961FBF00F46237 /* BelongsToAssociation.swift */; }; - 5653EB9120961FC000F46237 /* HasOneAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8620961FBF00F46237 /* HasOneAssociation.swift */; }; - 5653EB9220961FC000F46237 /* HasOneAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8620961FBF00F46237 /* HasOneAssociation.swift */; }; - 5653EB9520961FC000F46237 /* HasManyAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8820961FBF00F46237 /* HasManyAssociation.swift */; }; - 5653EB9620961FC000F46237 /* HasManyAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8820961FBF00F46237 /* HasManyAssociation.swift */; }; - 5653EB9720961FC000F46237 /* ForeignKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8920961FBF00F46237 /* ForeignKey.swift */; }; - 5653EB9820961FC000F46237 /* ForeignKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8920961FBF00F46237 /* ForeignKey.swift */; }; - 5653EB9920961FC000F46237 /* ForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8A20961FBF00F46237 /* ForeignKeyRequest.swift */; }; - 5653EB9A20961FC000F46237 /* ForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8A20961FBF00F46237 /* ForeignKeyRequest.swift */; }; - 5653EB9D20961FC000F46237 /* Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8C20961FBF00F46237 /* Association.swift */; }; - 5653EB9E20961FC000F46237 /* Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8C20961FBF00F46237 /* Association.swift */; }; - 5653EBA220961FCA00F46237 /* QueryInterfaceRequest+Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA120961FCA00F46237 /* QueryInterfaceRequest+Association.swift */; }; - 5653EBA320961FCA00F46237 /* QueryInterfaceRequest+Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA120961FCA00F46237 /* QueryInterfaceRequest+Association.swift */; }; - 5653EBB820961FE800F46237 /* AssociationParallelSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA620961FE600F46237 /* AssociationParallelSQLTests.swift */; }; - 5653EBB920961FE800F46237 /* AssociationParallelSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA620961FE600F46237 /* AssociationParallelSQLTests.swift */; }; - 5653EBBA20961FE800F46237 /* AssociationParallelSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA620961FE600F46237 /* AssociationParallelSQLTests.swift */; }; - 5653EBBB20961FE800F46237 /* AssociationParallelSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA620961FE600F46237 /* AssociationParallelSQLTests.swift */; }; - 5653EBBC20961FE800F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA720961FE600F46237 /* AssociationBelongsToFetchableRecordTests.swift */; }; - 5653EBBD20961FE800F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA720961FE600F46237 /* AssociationBelongsToFetchableRecordTests.swift */; }; - 5653EBBE20961FE800F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA720961FE600F46237 /* AssociationBelongsToFetchableRecordTests.swift */; }; - 5653EBBF20961FE800F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA720961FE600F46237 /* AssociationBelongsToFetchableRecordTests.swift */; }; - 5653EBC020961FE800F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA820961FE600F46237 /* AssociationParallelDecodableRecordTests.swift */; }; - 5653EBC120961FE800F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA820961FE600F46237 /* AssociationParallelDecodableRecordTests.swift */; }; - 5653EBC220961FE800F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA820961FE600F46237 /* AssociationParallelDecodableRecordTests.swift */; }; - 5653EBC320961FE800F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA820961FE600F46237 /* AssociationParallelDecodableRecordTests.swift */; }; - 5653EBC420961FE800F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA920961FE700F46237 /* AssociationBelongsToSQLDerivationTests.swift */; }; - 5653EBC520961FE800F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA920961FE700F46237 /* AssociationBelongsToSQLDerivationTests.swift */; }; - 5653EBC620961FE800F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA920961FE700F46237 /* AssociationBelongsToSQLDerivationTests.swift */; }; - 5653EBC720961FE800F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA920961FE700F46237 /* AssociationBelongsToSQLDerivationTests.swift */; }; - 5653EBC820961FE800F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAA20961FE700F46237 /* AssociationTableAliasTestsSQLTests.swift */; }; - 5653EBC920961FE800F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAA20961FE700F46237 /* AssociationTableAliasTestsSQLTests.swift */; }; - 5653EBCA20961FE800F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAA20961FE700F46237 /* AssociationTableAliasTestsSQLTests.swift */; }; - 5653EBCB20961FE800F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAA20961FE700F46237 /* AssociationTableAliasTestsSQLTests.swift */; }; - 5653EBCC20961FE800F46237 /* AssociationHasOneSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAB20961FE700F46237 /* AssociationHasOneSQLTests.swift */; }; - 5653EBCD20961FE800F46237 /* AssociationHasOneSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAB20961FE700F46237 /* AssociationHasOneSQLTests.swift */; }; - 5653EBCE20961FE800F46237 /* AssociationHasOneSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAB20961FE700F46237 /* AssociationHasOneSQLTests.swift */; }; - 5653EBCF20961FE800F46237 /* AssociationHasOneSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAB20961FE700F46237 /* AssociationHasOneSQLTests.swift */; }; - 5653EBD020961FE800F46237 /* AssociationRowScopeSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAC20961FE700F46237 /* AssociationRowScopeSearchTests.swift */; }; - 5653EBD120961FE800F46237 /* AssociationRowScopeSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAC20961FE700F46237 /* AssociationRowScopeSearchTests.swift */; }; - 5653EBD220961FE800F46237 /* AssociationRowScopeSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAC20961FE700F46237 /* AssociationRowScopeSearchTests.swift */; }; - 5653EBD320961FE800F46237 /* AssociationRowScopeSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAC20961FE700F46237 /* AssociationRowScopeSearchTests.swift */; }; - 5653EBD420961FE800F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAD20961FE700F46237 /* AssociationHasOneSQLDerivationTests.swift */; }; - 5653EBD520961FE800F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAD20961FE700F46237 /* AssociationHasOneSQLDerivationTests.swift */; }; - 5653EBD620961FE800F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAD20961FE700F46237 /* AssociationHasOneSQLDerivationTests.swift */; }; - 5653EBD720961FE800F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAD20961FE700F46237 /* AssociationHasOneSQLDerivationTests.swift */; }; - 5653EBD820961FE800F46237 /* AssociationChainRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAE20961FE700F46237 /* AssociationChainRowScopesTests.swift */; }; - 5653EBD920961FE800F46237 /* AssociationChainRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAE20961FE700F46237 /* AssociationChainRowScopesTests.swift */; }; - 5653EBDA20961FE800F46237 /* AssociationChainRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAE20961FE700F46237 /* AssociationChainRowScopesTests.swift */; }; - 5653EBDB20961FE800F46237 /* AssociationChainRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAE20961FE700F46237 /* AssociationChainRowScopesTests.swift */; }; - 5653EBDC20961FE800F46237 /* AssociationParallelRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAF20961FE700F46237 /* AssociationParallelRowScopesTests.swift */; }; - 5653EBDD20961FE800F46237 /* AssociationParallelRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAF20961FE700F46237 /* AssociationParallelRowScopesTests.swift */; }; - 5653EBDE20961FE800F46237 /* AssociationParallelRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAF20961FE700F46237 /* AssociationParallelRowScopesTests.swift */; }; - 5653EBDF20961FE800F46237 /* AssociationParallelRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAF20961FE700F46237 /* AssociationParallelRowScopesTests.swift */; }; - 5653EBE020961FE800F46237 /* AssociationBelongsToSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB020961FE700F46237 /* AssociationBelongsToSQLTests.swift */; }; - 5653EBE120961FE800F46237 /* AssociationBelongsToSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB020961FE700F46237 /* AssociationBelongsToSQLTests.swift */; }; - 5653EBE220961FE800F46237 /* AssociationBelongsToSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB020961FE700F46237 /* AssociationBelongsToSQLTests.swift */; }; - 5653EBE320961FE800F46237 /* AssociationBelongsToSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB020961FE700F46237 /* AssociationBelongsToSQLTests.swift */; }; - 5653EBE420961FE800F46237 /* AssociationChainSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB120961FE800F46237 /* AssociationChainSQLTests.swift */; }; - 5653EBE520961FE800F46237 /* AssociationChainSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB120961FE800F46237 /* AssociationChainSQLTests.swift */; }; - 5653EBE620961FE800F46237 /* AssociationChainSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB120961FE800F46237 /* AssociationChainSQLTests.swift */; }; - 5653EBE720961FE800F46237 /* AssociationChainSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB120961FE800F46237 /* AssociationChainSQLTests.swift */; }; - 5653EBE820961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB220961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift */; }; - 5653EBE920961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB220961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift */; }; - 5653EBEA20961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB220961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift */; }; - 5653EBEB20961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB220961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift */; }; - 5653EBEC20961FE800F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB320961FE800F46237 /* AssociationBelongsToRowScopeTests.swift */; }; - 5653EBED20961FE800F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB320961FE800F46237 /* AssociationBelongsToRowScopeTests.swift */; }; - 5653EBEE20961FE800F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB320961FE800F46237 /* AssociationBelongsToRowScopeTests.swift */; }; - 5653EBEF20961FE800F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB320961FE800F46237 /* AssociationBelongsToRowScopeTests.swift */; }; - 5653EC17209873A400F46237 /* SQLExpression+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EC15209873A400F46237 /* SQLExpression+QueryInterface.swift */; }; - 5653EC18209873A400F46237 /* SQLExpression+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EC15209873A400F46237 /* SQLExpression+QueryInterface.swift */; }; - 5653EC1A209873E600F46237 /* SQLGenerationContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EC19209873E600F46237 /* SQLGenerationContext.swift */; }; - 5653EC1B209873E600F46237 /* SQLGenerationContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EC19209873E600F46237 /* SQLGenerationContext.swift */; }; - 5657AABA1D107001006283EF /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AAB81D107001006283EF /* NSData.swift */; }; - 5657AABD1D107001006283EF /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AAB81D107001006283EF /* NSData.swift */; }; - 5657AB101D10899D006283EF /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB0E1D10899D006283EF /* URL.swift */; }; - 5657AB131D10899D006283EF /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB0E1D10899D006283EF /* URL.swift */; }; - 5657AB371D108BA9006283EF /* FoundationDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB2F1D108BA9006283EF /* FoundationDataTests.swift */; }; - 5657AB381D108BA9006283EF /* FoundationDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB2F1D108BA9006283EF /* FoundationDataTests.swift */; }; - 5657AB3B1D108BA9006283EF /* FoundationDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB2F1D108BA9006283EF /* FoundationDataTests.swift */; }; - 5657AB3C1D108BA9006283EF /* FoundationDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB2F1D108BA9006283EF /* FoundationDataTests.swift */; }; - 5657AB3F1D108BA9006283EF /* FoundationNSDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB301D108BA9006283EF /* FoundationNSDataTests.swift */; }; - 5657AB401D108BA9006283EF /* FoundationNSDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB301D108BA9006283EF /* FoundationNSDataTests.swift */; }; - 5657AB431D108BA9006283EF /* FoundationNSDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB301D108BA9006283EF /* FoundationNSDataTests.swift */; }; - 5657AB441D108BA9006283EF /* FoundationNSDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB301D108BA9006283EF /* FoundationNSDataTests.swift */; }; - 5657AB471D108BA9006283EF /* FoundationNSNullTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB311D108BA9006283EF /* FoundationNSNullTests.swift */; }; - 5657AB481D108BA9006283EF /* FoundationNSNullTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB311D108BA9006283EF /* FoundationNSNullTests.swift */; }; - 5657AB4B1D108BA9006283EF /* FoundationNSNullTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB311D108BA9006283EF /* FoundationNSNullTests.swift */; }; - 5657AB4C1D108BA9006283EF /* FoundationNSNullTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB311D108BA9006283EF /* FoundationNSNullTests.swift */; }; - 5657AB4F1D108BA9006283EF /* FoundationNSNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB321D108BA9006283EF /* FoundationNSNumberTests.swift */; }; - 5657AB501D108BA9006283EF /* FoundationNSNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB321D108BA9006283EF /* FoundationNSNumberTests.swift */; }; - 5657AB531D108BA9006283EF /* FoundationNSNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB321D108BA9006283EF /* FoundationNSNumberTests.swift */; }; - 5657AB541D108BA9006283EF /* FoundationNSNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB321D108BA9006283EF /* FoundationNSNumberTests.swift */; }; - 5657AB571D108BA9006283EF /* FoundationNSStringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB331D108BA9006283EF /* FoundationNSStringTests.swift */; }; - 5657AB581D108BA9006283EF /* FoundationNSStringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB331D108BA9006283EF /* FoundationNSStringTests.swift */; }; - 5657AB5B1D108BA9006283EF /* FoundationNSStringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB331D108BA9006283EF /* FoundationNSStringTests.swift */; }; - 5657AB5C1D108BA9006283EF /* FoundationNSStringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB331D108BA9006283EF /* FoundationNSStringTests.swift */; }; - 5657AB5F1D108BA9006283EF /* FoundationNSURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB341D108BA9006283EF /* FoundationNSURLTests.swift */; }; - 5657AB601D108BA9006283EF /* FoundationNSURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB341D108BA9006283EF /* FoundationNSURLTests.swift */; }; - 5657AB631D108BA9006283EF /* FoundationNSURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB341D108BA9006283EF /* FoundationNSURLTests.swift */; }; - 5657AB641D108BA9006283EF /* FoundationNSURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB341D108BA9006283EF /* FoundationNSURLTests.swift */; }; - 5657AB671D108BA9006283EF /* FoundationURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB351D108BA9006283EF /* FoundationURLTests.swift */; }; - 5657AB681D108BA9006283EF /* FoundationURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB351D108BA9006283EF /* FoundationURLTests.swift */; }; - 5657AB6B1D108BA9006283EF /* FoundationURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB351D108BA9006283EF /* FoundationURLTests.swift */; }; - 5657AB6C1D108BA9006283EF /* FoundationURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB351D108BA9006283EF /* FoundationURLTests.swift */; }; - 5659F4891EA8D94E004A4992 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5659F4871EA8D94E004A4992 /* Utils.swift */; }; - 5659F48C1EA8D94E004A4992 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5659F4871EA8D94E004A4992 /* Utils.swift */; }; - 5659F4911EA8D964004A4992 /* ReadWriteBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5659F48F1EA8D964004A4992 /* ReadWriteBox.swift */; }; - 5659F4941EA8D964004A4992 /* ReadWriteBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5659F48F1EA8D964004A4992 /* ReadWriteBox.swift */; }; - 5659F4991EA8D989004A4992 /* Pool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5659F4971EA8D989004A4992 /* Pool.swift */; }; - 5659F49C1EA8D989004A4992 /* Pool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5659F4971EA8D989004A4992 /* Pool.swift */; }; - 5659F4A11EA8D997004A4992 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5659F49F1EA8D997004A4992 /* Result.swift */; }; - 5659F4A41EA8D997004A4992 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5659F49F1EA8D997004A4992 /* Result.swift */; }; - 565EFAEF1D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */; }; - 565EFAF01D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */; }; - 565EFAF31D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */; }; - 565EFAF41D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */; }; - 565F03C31CE5D3AA00DE108F /* RowAdapterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565F03C11CE5D3AA00DE108F /* RowAdapterTests.swift */; }; - 565F03C41CE5D3AA00DE108F /* RowAdapterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565F03C11CE5D3AA00DE108F /* RowAdapterTests.swift */; }; - 565F03C71CE5D3AA00DE108F /* RowAdapterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565F03C11CE5D3AA00DE108F /* RowAdapterTests.swift */; }; - 5664759B1D97D8A000FF74B8 /* SQLCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475991D97D8A000FF74B8 /* SQLCollection.swift */; }; - 5664759E1D97D8A000FF74B8 /* SQLCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475991D97D8A000FF74B8 /* SQLCollection.swift */; }; - 566475A31D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475A11D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift */; }; - 566475A61D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475A11D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift */; }; - 566475BB1D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475B91D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift */; }; - 566475BE1D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475B91D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift */; }; - 566475CD1D981D5E00FF74B8 /* SQLFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475CA1D981D5E00FF74B8 /* SQLFunctions.swift */; }; - 566475D01D981D5E00FF74B8 /* SQLFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475CA1D981D5E00FF74B8 /* SQLFunctions.swift */; }; - 566475D41D981D5E00FF74B8 /* SQLOperators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475CB1D981D5E00FF74B8 /* SQLOperators.swift */; }; - 566475D71D981D5E00FF74B8 /* SQLOperators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475CB1D981D5E00FF74B8 /* SQLOperators.swift */; }; - 5665F86C203EF47D0084C6C0 /* ColumnInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5665F86A203EF47C0084C6C0 /* ColumnInfoTests.swift */; }; - 5665F86D203EF47D0084C6C0 /* ColumnInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5665F86A203EF47C0084C6C0 /* ColumnInfoTests.swift */; }; - 5665F86E203EF47D0084C6C0 /* ColumnInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5665F86A203EF47C0084C6C0 /* ColumnInfoTests.swift */; }; - 5665F86F203EF47D0084C6C0 /* ColumnInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5665F86A203EF47C0084C6C0 /* ColumnInfoTests.swift */; }; - 5665FA222129D81F004D8612 /* DatabaseDateDecodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5665FA202129D81F004D8612 /* DatabaseDateDecodingStrategyTests.swift */; }; - 5665FA232129D81F004D8612 /* DatabaseDateDecodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5665FA202129D81F004D8612 /* DatabaseDateDecodingStrategyTests.swift */; }; - 5665FA242129D81F004D8612 /* DatabaseDateDecodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5665FA202129D81F004D8612 /* DatabaseDateDecodingStrategyTests.swift */; }; - 5665FA252129D81F004D8612 /* DatabaseDateDecodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5665FA202129D81F004D8612 /* DatabaseDateDecodingStrategyTests.swift */; }; - 5665FA412129EEEF004D8612 /* DatabaseDateEncodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5665FA3F2129EEEF004D8612 /* DatabaseDateEncodingStrategyTests.swift */; }; - 5665FA422129EEEF004D8612 /* DatabaseDateEncodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5665FA3F2129EEEF004D8612 /* DatabaseDateEncodingStrategyTests.swift */; }; - 5665FA432129EEEF004D8612 /* DatabaseDateEncodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5665FA3F2129EEEF004D8612 /* DatabaseDateEncodingStrategyTests.swift */; }; - 5665FA442129EEEF004D8612 /* DatabaseDateEncodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5665FA3F2129EEEF004D8612 /* DatabaseDateEncodingStrategyTests.swift */; }; - 566A842920413D6F00E50BFD /* DatabaseSnapshot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566A842720413D6E00E50BFD /* DatabaseSnapshot.swift */; }; - 566A842A20413D8500E50BFD /* DatabaseSnapshot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566A842720413D6E00E50BFD /* DatabaseSnapshot.swift */; }; - 566A843020413DD000E50BFD /* DatabaseSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566A842F20413DCF00E50BFD /* DatabaseSnapshotTests.swift */; }; - 566A843120413DD000E50BFD /* DatabaseSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566A842F20413DCF00E50BFD /* DatabaseSnapshotTests.swift */; }; - 566A843220413DD000E50BFD /* DatabaseSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566A842F20413DCF00E50BFD /* DatabaseSnapshotTests.swift */; }; - 566A843320413DD000E50BFD /* DatabaseSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566A842F20413DCF00E50BFD /* DatabaseSnapshotTests.swift */; }; - 566A84462041AB3900E50BFD /* MutablePersistableRecordChangesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566A84452041AB3900E50BFD /* MutablePersistableRecordChangesTests.swift */; }; - 566A84472041AB3900E50BFD /* MutablePersistableRecordChangesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566A84452041AB3900E50BFD /* MutablePersistableRecordChangesTests.swift */; }; - 566A84482041AB3900E50BFD /* MutablePersistableRecordChangesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566A84452041AB3900E50BFD /* MutablePersistableRecordChangesTests.swift */; }; - 566A84492041AB3900E50BFD /* MutablePersistableRecordChangesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566A84452041AB3900E50BFD /* MutablePersistableRecordChangesTests.swift */; }; - 566AD8B31D5318F4002EC1A8 /* TableDefinition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566AD8B11D5318F4002EC1A8 /* TableDefinition.swift */; }; - 566AD8B61D5318F4002EC1A8 /* TableDefinition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566AD8B11D5318F4002EC1A8 /* TableDefinition.swift */; }; - 566AD8C71D531BEA002EC1A8 /* TableDefinitionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566AD8C51D531BE4002EC1A8 /* TableDefinitionTests.swift */; }; - 566AD8C81D531BEB002EC1A8 /* TableDefinitionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566AD8C51D531BE4002EC1A8 /* TableDefinitionTests.swift */; }; - 566AD8CB1D531BED002EC1A8 /* TableDefinitionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566AD8C51D531BE4002EC1A8 /* TableDefinitionTests.swift */; }; - 566AD8CC1D531BEE002EC1A8 /* TableDefinitionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566AD8C51D531BE4002EC1A8 /* TableDefinitionTests.swift */; }; - 566B910A1FA4C3970012D5B0 /* Database+Statements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566B91081FA4C3960012D5B0 /* Database+Statements.swift */; }; - 566B910D1FA4C3970012D5B0 /* Database+Statements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566B91081FA4C3960012D5B0 /* Database+Statements.swift */; }; - 566B91141FA4C3F50012D5B0 /* DatabaseCollation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566B91121FA4C3F50012D5B0 /* DatabaseCollation.swift */; }; - 566B91171FA4C3F50012D5B0 /* DatabaseCollation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566B91121FA4C3F50012D5B0 /* DatabaseCollation.swift */; }; - 566B91241FA4CF810012D5B0 /* Database+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566B91221FA4CF810012D5B0 /* Database+Schema.swift */; }; - 566B91271FA4CF810012D5B0 /* Database+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566B91221FA4CF810012D5B0 /* Database+Schema.swift */; }; - 566B912C1FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566B912A1FA4D0CC0012D5B0 /* StatementAuthorizer.swift */; }; - 566B912F1FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566B912A1FA4D0CC0012D5B0 /* StatementAuthorizer.swift */; }; - 566B91341FA4D3810012D5B0 /* TransactionObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566B91321FA4D3810012D5B0 /* TransactionObserver.swift */; }; - 566B91371FA4D3810012D5B0 /* TransactionObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566B91321FA4D3810012D5B0 /* TransactionObserver.swift */; }; - 5670329F212B546E007D270F /* DatabaseUUIDEncodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5670329D212B546D007D270F /* DatabaseUUIDEncodingStrategyTests.swift */; }; - 567032A0212B546E007D270F /* DatabaseUUIDEncodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5670329D212B546D007D270F /* DatabaseUUIDEncodingStrategyTests.swift */; }; - 567032A1212B546E007D270F /* DatabaseUUIDEncodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5670329D212B546D007D270F /* DatabaseUUIDEncodingStrategyTests.swift */; }; - 567032A2212B546E007D270F /* DatabaseUUIDEncodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5670329D212B546D007D270F /* DatabaseUUIDEncodingStrategyTests.swift */; }; - 567071F8208A00D4006AD95A /* SQLiteDateParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567071F6208A00D4006AD95A /* SQLiteDateParser.swift */; }; - 567071F9208A00D4006AD95A /* SQLiteDateParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567071F6208A00D4006AD95A /* SQLiteDateParser.swift */; }; - 567156141CB141D0007DC145 /* DatabaseQueueInMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238141B9C74A90082EB20 /* DatabaseQueueInMemoryTests.swift */; }; - 567156171CB142AA007DC145 /* DatabaseQueueReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567156151CB142AA007DC145 /* DatabaseQueueReadOnlyTests.swift */; }; - 5671561D1CB16729007DC145 /* DatabaseValueConversionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381B1B9C74A90082EB20 /* DatabaseValueConversionTests.swift */; }; - 5671561E1CB16729007DC145 /* DataMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EB0AB11BCD787300A3DC55 /* DataMemoryTests.swift */; }; - 5671561F1CB16729007DC145 /* Record+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B841C54DC95005A543B /* Record+QueryInterfaceRequestTests.swift */; }; - 567156221CB16729007DC145 /* StatementColumnConvertibleFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E8CE0F1BB4FE5B00828BEC /* StatementColumnConvertibleFetchTests.swift */; }; - 567156231CB16729007DC145 /* RecordPrimaryKeyNoneTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238291B9C74A90082EB20 /* RecordPrimaryKeyNoneTests.swift */; }; - 567156241CB16729007DC145 /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238261B9C74A90082EB20 /* RecordMinimalPrimaryKeyRowIDTests.swift */; }; - 567156251CB16729007DC145 /* RowFromDictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381E1B9C74A90082EB20 /* RowFromDictionaryTests.swift */; }; - 567156261CB16729007DC145 /* SelectStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238211B9C74A90082EB20 /* SelectStatementTests.swift */; }; - 567156281CB16729007DC145 /* QueryInterfaceExpressionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B671C53D25E005A543B /* QueryInterfaceExpressionsTests.swift */; }; - 567156291CB16729007DC145 /* DatabaseCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A50C61BFF4B7F00B3A3A2 /* DatabaseCollationTests.swift */; }; - 5671562A1CB16729007DC145 /* UpdateStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238221B9C74A90082EB20 /* UpdateStatementTests.swift */; }; - 5671562B1CB16729007DC145 /* DatabaseMigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238241B9C74A90082EB20 /* DatabaseMigratorTests.swift */; }; - 5671562E1CB16729007DC145 /* DatabasePoolCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531331C919DF200CF1A2B /* DatabasePoolCollationTests.swift */; }; - 5671562F1CB16729007DC145 /* RecordPrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382B1B9C74A90082EB20 /* RecordPrimaryKeySingleTests.swift */; }; - 567156321CB16729007DC145 /* DatabasePoolFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531361C919DF700CF1A2B /* DatabasePoolFunctionTests.swift */; }; - 567156341CB16729007DC145 /* RowCopiedFromStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381F1B9C74A90082EB20 /* RowCopiedFromStatementTests.swift */; }; - 567156351CB16729007DC145 /* DatabaseQueueSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531231C90878D00CF1A2B /* DatabaseQueueSchemaCacheTests.swift */; }; - 567156361CB16729007DC145 /* RowFromStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FDECE11BB32DFD009AD709 /* RowFromStatementTests.swift */; }; - 567156371CB16729007DC145 /* RecordPrimaryKeyMultipleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238281B9C74A90082EB20 /* RecordPrimaryKeyMultipleTests.swift */; }; - 5671563A1CB16729007DC145 /* StatementArgumentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DE7B101C3D93ED00861EB8 /* StatementArgumentsTests.swift */; }; - 5671563B1CB16729007DC145 /* RecordInitializersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238321B9C74A90082EB20 /* RecordInitializersTests.swift */; }; - 5671563C1CB16729007DC145 /* MutablePersistableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363A91C933FF8000BE133 /* MutablePersistableRecordTests.swift */; }; - 5671563D1CB16729007DC145 /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B601C53C42C005A543B /* FetchableRecord+QueryInterfaceRequestTests.swift */; }; - 5671563F1CB16729007DC145 /* RecordCopyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382D1B9C74A90082EB20 /* RecordCopyTests.swift */; }; - 567156401CB16729007DC145 /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381C1B9C74A90082EB20 /* RawRepresentable+DatabaseValueConvertibleTests.swift */; }; - 567156411CB16729007DC145 /* PersistableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AA1C933FF8000BE133 /* PersistableRecordTests.swift */; }; - 567156441CB16729007DC145 /* RecordSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238331B9C74A90082EB20 /* RecordSubClassTests.swift */; }; - 567156461CB16729007DC145 /* TransactionObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5607EFD21BB8254800605DE3 /* TransactionObserverTests.swift */; }; - 567156481CB16729007DC145 /* DatabaseValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238181B9C74A90082EB20 /* DatabaseValueTests.swift */; }; - 5671564A1CB16729007DC145 /* DatabaseQueueReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567156151CB142AA007DC145 /* DatabaseQueueReadOnlyTests.swift */; }; - 5671564B1CB16729007DC145 /* Row+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D701BBC694D00DC9BD4 /* Row+FoundationTests.swift */; }; - 5671564C1CB16729007DC145 /* DatabaseQueueInMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238141B9C74A90082EB20 /* DatabaseQueueInMemoryTests.swift */; }; - 5671564D1CB16729007DC145 /* RecordPrimaryKeyRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382A1B9C74A90082EB20 /* RecordPrimaryKeyRowIDTests.swift */; }; - 5671564E1CB16729007DC145 /* DatabaseReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA86931C91DFE7002BB4DF /* DatabaseReaderTests.swift */; }; - 5671564F1CB16729007DC145 /* RecordEditedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382F1B9C74A90082EB20 /* RecordEditedTests.swift */; }; - 567156501CB16729007DC145 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382C1B9C74A90082EB20 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift */; }; - 567156511CB16729007DC145 /* FetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565B0FEE1BBC7D980098DE03 /* FetchableRecordTests.swift */; }; - 567156531CB16729007DC145 /* DatabaseValueConvertibleSubclassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381A1B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift */; }; - 567156551CB16729007DC145 /* DatabaseValueConvertibleFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E8CE0C1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift */; }; - 567156561CB16729007DC145 /* DatabaseErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238161B9C74A90082EB20 /* DatabaseErrorTests.swift */; }; - 567156571CB16729007DC145 /* RecordMinimalPrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238271B9C74A90082EB20 /* RecordMinimalPrimaryKeySingleTests.swift */; }; - 567156591CB16729007DC145 /* DatabaseTimestampTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238B51B9CA2590082EB20 /* DatabaseTimestampTests.swift */; }; - 5671565A1CB16729007DC145 /* StatementArguments+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D731BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift */; }; - 5671565B1CB16729007DC145 /* TableRecord+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B6A1C53D3E8005A543B /* TableRecord+QueryInterfaceRequestTests.swift */; }; - 5671565C1CB16729007DC145 /* FoundationNSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* FoundationNSDateTests.swift */; }; - 5671565D1CB16729007DC145 /* DatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238131B9C74A90082EB20 /* DatabaseTests.swift */; }; - 5671565E1CB16729007DC145 /* QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B5D1C53C38F005A543B /* QueryInterfaceRequestTests.swift */; }; - 567156601CB16729007DC145 /* DatabaseFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560C97C61BFD0B8400BF8471 /* DatabaseFunctionTests.swift */; }; - 567156611CB16729007DC145 /* RecordWithColumnNameManglingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A5E4081BA2BCF900707640 /* RecordWithColumnNameManglingTests.swift */; }; - 567156621CB16729007DC145 /* CGFloatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4291BE14A1900E39BBF /* CGFloatTests.swift */; }; - 567156631CB16729007DC145 /* DatabaseRegionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1861C69111300235C62 /* DatabaseRegionTests.swift */; }; - 567156641CB16729007DC145 /* GRDBTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623E0901B4AFACC00B20B7F /* GRDBTestCase.swift */; }; - 567156671CB16729007DC145 /* GRDBCipher.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 560FC54D1CB003810014AA8E /* GRDBCipher.framework */; }; - 5671FC211DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5671FC1F1DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift */; }; - 5671FC241DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5671FC1F1DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift */; }; - 5672DE5A1CDB72520022BA81 /* DatabaseQueueBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5672DE581CDB72520022BA81 /* DatabaseQueueBackupTests.swift */; }; - 5672DE5B1CDB72520022BA81 /* DatabaseQueueBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5672DE581CDB72520022BA81 /* DatabaseQueueBackupTests.swift */; }; - 5672DE5D1CDB72520022BA81 /* DatabaseQueueBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5672DE581CDB72520022BA81 /* DatabaseQueueBackupTests.swift */; }; - 5672DE5E1CDB72520022BA81 /* DatabaseQueueBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5672DE581CDB72520022BA81 /* DatabaseQueueBackupTests.swift */; }; - 5672DE6B1CDB751D0022BA81 /* DatabasePoolBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5672DE661CDB751D0022BA81 /* DatabasePoolBackupTests.swift */; }; - 5672DE6C1CDB751D0022BA81 /* DatabasePoolBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5672DE661CDB751D0022BA81 /* DatabasePoolBackupTests.swift */; }; - 567404891CEF84C8003ED5CC /* RowAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567404871CEF84C8003ED5CC /* RowAdapter.swift */; }; - 5674048B1CEF84C8003ED5CC /* RowAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567404871CEF84C8003ED5CC /* RowAdapter.swift */; }; - 56741EA91E66A8B3003E422D /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* FetchRequestTests.swift */; }; - 56741EAA1E66A8B3003E422D /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* FetchRequestTests.swift */; }; - 56741EAD1E66A8B3003E422D /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* FetchRequestTests.swift */; }; - 56741EAE1E66A8B3003E422D /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* FetchRequestTests.swift */; }; - 5674A6E71F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E31F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift */; }; - 5674A6EA1F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E31F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift */; }; - 5674A6EE1F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E21F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift */; }; - 5674A6F11F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E21F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift */; }; - 5674A6F71F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F31F307F600095F066 /* PersistableRecord+Encodable.swift */; }; - 5674A6FA1F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F31F307F600095F066 /* PersistableRecord+Encodable.swift */; }; - 5674A6FE1F307F600095F066 /* FetchableRecord+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F21F307F600095F066 /* FetchableRecord+Decodable.swift */; }; - 5674A7011F307F600095F066 /* FetchableRecord+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F21F307F600095F066 /* FetchableRecord+Decodable.swift */; }; - 5674A7061F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A7021F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift */; }; - 5674A7091F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A7021F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift */; }; - 5674A70D1F3087710095F066 /* DatabaseValueConvertibleEncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A70B1F3087700095F066 /* DatabaseValueConvertibleEncodableTests.swift */; }; - 5674A7101F3087710095F066 /* DatabaseValueConvertibleEncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A70B1F3087700095F066 /* DatabaseValueConvertibleEncodableTests.swift */; }; - 5674A7111F3087710095F066 /* DatabaseValueConvertibleEncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A70B1F3087700095F066 /* DatabaseValueConvertibleEncodableTests.swift */; }; - 5674A7131F3087710095F066 /* DatabaseValueConvertibleEncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A70B1F3087700095F066 /* DatabaseValueConvertibleEncodableTests.swift */; }; - 5674A7151F3087710095F066 /* DatabaseValueConvertibleDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A70A1F3087700095F066 /* DatabaseValueConvertibleDecodableTests.swift */; }; - 5674A7181F3087710095F066 /* DatabaseValueConvertibleDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A70A1F3087700095F066 /* DatabaseValueConvertibleDecodableTests.swift */; }; - 5674A7191F3087710095F066 /* DatabaseValueConvertibleDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A70A1F3087700095F066 /* DatabaseValueConvertibleDecodableTests.swift */; }; - 5674A71B1F3087710095F066 /* DatabaseValueConvertibleDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A70A1F3087700095F066 /* DatabaseValueConvertibleDecodableTests.swift */; }; - 5674A71E1F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A71C1F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift */; }; - 5674A7211F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A71C1F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift */; }; - 5674A7221F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A71C1F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift */; }; - 5674A7241F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A71C1F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift */; }; - 5674A7281F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A7261F30A9090095F066 /* FetchableRecordDecodableTests.swift */; }; - 5674A72B1F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A7261F30A9090095F066 /* FetchableRecordDecodableTests.swift */; }; - 5674A72C1F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A7261F30A9090095F066 /* FetchableRecordDecodableTests.swift */; }; - 5674A72E1F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A7261F30A9090095F066 /* FetchableRecordDecodableTests.swift */; }; - 567A80541D41350C00C7DCEC /* IndexInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567A80521D41350C00C7DCEC /* IndexInfoTests.swift */; }; - 567A80551D41350C00C7DCEC /* IndexInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567A80521D41350C00C7DCEC /* IndexInfoTests.swift */; }; - 567A80581D41350C00C7DCEC /* IndexInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567A80521D41350C00C7DCEC /* IndexInfoTests.swift */; }; - 567A80591D41350C00C7DCEC /* IndexInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567A80521D41350C00C7DCEC /* IndexInfoTests.swift */; }; - 567DAF1D1EAB61ED00FC0928 /* grdb_config.h in Headers */ = {isa = PBXBuildFile; fileRef = 567DAF141EAB61ED00FC0928 /* grdb_config.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 567DAF201EAB61ED00FC0928 /* grdb_config.h in Headers */ = {isa = PBXBuildFile; fileRef = 567DAF141EAB61ED00FC0928 /* grdb_config.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 567DAF361EAB789800FC0928 /* DatabaseLogErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567DAF341EAB789800FC0928 /* DatabaseLogErrorTests.swift */; }; - 567DAF371EAB789800FC0928 /* DatabaseLogErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567DAF341EAB789800FC0928 /* DatabaseLogErrorTests.swift */; }; - 567DAF3A1EAB789800FC0928 /* DatabaseLogErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567DAF341EAB789800FC0928 /* DatabaseLogErrorTests.swift */; }; - 567DAF3B1EAB789800FC0928 /* DatabaseLogErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567DAF341EAB789800FC0928 /* DatabaseLogErrorTests.swift */; }; - 567E55ED1D2BDD3D00CC6F79 /* EncryptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567156701CB18050007DC145 /* EncryptionTests.swift */; }; - 567E55EE1D2BDD3F00CC6F79 /* EncryptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567156701CB18050007DC145 /* EncryptionTests.swift */; }; - 567E55F31D2BDDFE00CC6F79 /* EncryptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567156701CB18050007DC145 /* EncryptionTests.swift */; }; - 567E55F41D2BDDFF00CC6F79 /* EncryptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567156701CB18050007DC145 /* EncryptionTests.swift */; }; - 567F45A91F888B2600030B59 /* TruncateOptimizationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567F45A71F888B2600030B59 /* TruncateOptimizationTests.swift */; }; - 567F45AA1F888B2600030B59 /* TruncateOptimizationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567F45A71F888B2600030B59 /* TruncateOptimizationTests.swift */; }; - 567F45AD1F888B2600030B59 /* TruncateOptimizationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567F45A71F888B2600030B59 /* TruncateOptimizationTests.swift */; }; - 567F45AE1F888B2600030B59 /* TruncateOptimizationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567F45A71F888B2600030B59 /* TruncateOptimizationTests.swift */; }; - 568068321EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 568068301EBBA26100EFB8AA /* SQLRequestTests.swift */; }; - 568068331EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 568068301EBBA26100EFB8AA /* SQLRequestTests.swift */; }; - 568068361EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 568068301EBBA26100EFB8AA /* SQLRequestTests.swift */; }; - 568068371EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 568068301EBBA26100EFB8AA /* SQLRequestTests.swift */; }; - 568735A01CEDE16C009B9116 /* Betty.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = 5687359E1CEDE16C009B9116 /* Betty.jpeg */; }; - 568735A11CEDE16C009B9116 /* Betty.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = 5687359E1CEDE16C009B9116 /* Betty.jpeg */; }; - 568735A31CEDE16C009B9116 /* Betty.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = 5687359E1CEDE16C009B9116 /* Betty.jpeg */; }; - 568735A41CEDE16C009B9116 /* Betty.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = 5687359E1CEDE16C009B9116 /* Betty.jpeg */; }; - 56873BED1F2CB400004D24B4 /* Fixits-1.2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */; }; - 56873BF01F2CB400004D24B4 /* Fixits-1.2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */; }; - 568BE5231CB0371D00270F93 /* GRDBCipher.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 560FC54D1CB003810014AA8E /* GRDBCipher.framework */; }; - 568D13242207214D00674B58 /* SQLSelectQueryGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 568D13222207214D00674B58 /* SQLSelectQueryGenerator.swift */; }; - 568D13252207214D00674B58 /* SQLSelectQueryGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 568D13222207214D00674B58 /* SQLSelectQueryGenerator.swift */; }; - 568E1CB21CB037BA008D97A6 /* sqlite3.h in Headers */ = {isa = PBXBuildFile; fileRef = 568BE5191CB035A900270F93 /* sqlite3.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 568E1CB91CB03847008D97A6 /* GRDBCipher-Bridging.h in Headers */ = {isa = PBXBuildFile; fileRef = 568E1CB71CB03847008D97A6 /* GRDBCipher-Bridging.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 568E1CBA1CB03847008D97A6 /* GRDBCipher.h in Headers */ = {isa = PBXBuildFile; fileRef = 568E1CB81CB03847008D97A6 /* GRDBCipher.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 5690C3271D23E6D800E59934 /* FoundationDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690C3251D23E6D800E59934 /* FoundationDateComponentsTests.swift */; }; - 5690C3281D23E6D800E59934 /* FoundationDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690C3251D23E6D800E59934 /* FoundationDateComponentsTests.swift */; }; - 5690C32B1D23E6D800E59934 /* FoundationDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690C3251D23E6D800E59934 /* FoundationDateComponentsTests.swift */; }; - 5690C32C1D23E6D800E59934 /* FoundationDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690C3251D23E6D800E59934 /* FoundationDateComponentsTests.swift */; }; - 5690C3381D23E7D200E59934 /* FoundationDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690C3361D23E7D200E59934 /* FoundationDateTests.swift */; }; - 5690C3391D23E7D200E59934 /* FoundationDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690C3361D23E7D200E59934 /* FoundationDateTests.swift */; }; - 5690C33C1D23E7D200E59934 /* FoundationDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690C3361D23E7D200E59934 /* FoundationDateTests.swift */; }; - 5690C33D1D23E7D200E59934 /* FoundationDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690C3361D23E7D200E59934 /* FoundationDateTests.swift */; }; - 5690C3411D23E82A00E59934 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690C33F1D23E82A00E59934 /* Data.swift */; }; - 5690C3441D23E82A00E59934 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690C33F1D23E82A00E59934 /* Data.swift */; }; - 569178471CED9B6000E179EA /* DatabaseQueueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569178451CED9B6000E179EA /* DatabaseQueueTests.swift */; }; - 569178481CED9B6000E179EA /* DatabaseQueueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569178451CED9B6000E179EA /* DatabaseQueueTests.swift */; }; - 5691784A1CED9B6000E179EA /* DatabaseQueueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569178451CED9B6000E179EA /* DatabaseQueueTests.swift */; }; - 5691784B1CED9B6000E179EA /* DatabaseQueueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569178451CED9B6000E179EA /* DatabaseQueueTests.swift */; }; - 5698AC041D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC021D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift */; }; - 5698AC051D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC021D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift */; }; - 5698AC081D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC021D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift */; }; - 5698AC091D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC021D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift */; }; - 5698AC381D9E5A590056AF8C /* FTS3Pattern.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC361D9E5A590056AF8C /* FTS3Pattern.swift */; }; - 5698AC3B1D9E5A590056AF8C /* FTS3Pattern.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC361D9E5A590056AF8C /* FTS3Pattern.swift */; }; - 5698AC411DA2BED90056AF8C /* FTS3PatternTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC3F1DA2BED90056AF8C /* FTS3PatternTests.swift */; }; - 5698AC421DA2BED90056AF8C /* FTS3PatternTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC3F1DA2BED90056AF8C /* FTS3PatternTests.swift */; }; - 5698AC451DA2BED90056AF8C /* FTS3PatternTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC3F1DA2BED90056AF8C /* FTS3PatternTests.swift */; }; - 5698AC461DA2BED90056AF8C /* FTS3PatternTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC3F1DA2BED90056AF8C /* FTS3PatternTests.swift */; }; - 5698AC4A1DA2D48A0056AF8C /* FTS3RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC481DA2D48A0056AF8C /* FTS3RecordTests.swift */; }; - 5698AC4B1DA2D48A0056AF8C /* FTS3RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC481DA2D48A0056AF8C /* FTS3RecordTests.swift */; }; - 5698AC4E1DA2D48A0056AF8C /* FTS3RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC481DA2D48A0056AF8C /* FTS3RecordTests.swift */; }; - 5698AC4F1DA2D48A0056AF8C /* FTS3RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC481DA2D48A0056AF8C /* FTS3RecordTests.swift */; }; - 5698AC791DA37DCB0056AF8C /* VirtualTableModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC771DA37DCB0056AF8C /* VirtualTableModule.swift */; }; - 5698AC7C1DA37DCB0056AF8C /* VirtualTableModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC771DA37DCB0056AF8C /* VirtualTableModule.swift */; }; - 5698AC811DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC7F1DA380A20056AF8C /* VirtualTableModuleTests.swift */; }; - 5698AC821DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC7F1DA380A20056AF8C /* VirtualTableModuleTests.swift */; }; - 5698AC851DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC7F1DA380A20056AF8C /* VirtualTableModuleTests.swift */; }; - 5698AC861DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC7F1DA380A20056AF8C /* VirtualTableModuleTests.swift */; }; - 5698AC8A1DA389380056AF8C /* FTS3TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC881DA389380056AF8C /* FTS3TableBuilderTests.swift */; }; - 5698AC8B1DA389380056AF8C /* FTS3TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC881DA389380056AF8C /* FTS3TableBuilderTests.swift */; }; - 5698AC8E1DA389380056AF8C /* FTS3TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC881DA389380056AF8C /* FTS3TableBuilderTests.swift */; }; - 5698AC8F1DA389380056AF8C /* FTS3TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC881DA389380056AF8C /* FTS3TableBuilderTests.swift */; }; - 5698AC971DA4B0430056AF8C /* FTS4RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC941DA4B0430056AF8C /* FTS4RecordTests.swift */; }; - 5698AC981DA4B0430056AF8C /* FTS4RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC941DA4B0430056AF8C /* FTS4RecordTests.swift */; }; - 5698AC9B1DA4B0430056AF8C /* FTS4RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC941DA4B0430056AF8C /* FTS4RecordTests.swift */; }; - 5698AC9C1DA4B0430056AF8C /* FTS4RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC941DA4B0430056AF8C /* FTS4RecordTests.swift */; }; - 5698AC9F1DA4B0430056AF8C /* FTS4TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC951DA4B0430056AF8C /* FTS4TableBuilderTests.swift */; }; - 5698ACA01DA4B0430056AF8C /* FTS4TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC951DA4B0430056AF8C /* FTS4TableBuilderTests.swift */; }; - 5698ACA31DA4B0430056AF8C /* FTS4TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC951DA4B0430056AF8C /* FTS4TableBuilderTests.swift */; }; - 5698ACA41DA4B0430056AF8C /* FTS4TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC951DA4B0430056AF8C /* FTS4TableBuilderTests.swift */; }; - 5698ACB71DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698ACB51DA6285E0056AF8C /* FTS3TokenizerTests.swift */; }; - 5698ACB81DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698ACB51DA6285E0056AF8C /* FTS3TokenizerTests.swift */; }; - 5698ACBB1DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698ACB51DA6285E0056AF8C /* FTS3TokenizerTests.swift */; }; - 5698ACBC1DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698ACB51DA6285E0056AF8C /* FTS3TokenizerTests.swift */; }; - 5698ACCF1DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698ACCD1DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift */; }; - 5698ACD01DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698ACCD1DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift */; }; - 5698ACD31DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698ACCD1DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift */; }; - 5698ACD41DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698ACCD1DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift */; }; - 5698ACD81DA925420056AF8C /* RowTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698ACD61DA925420056AF8C /* RowTestCase.swift */; }; - 5698ACD91DA925420056AF8C /* RowTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698ACD61DA925420056AF8C /* RowTestCase.swift */; }; - 5698ACDC1DA925430056AF8C /* RowTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698ACD61DA925420056AF8C /* RowTestCase.swift */; }; - 5698ACDD1DA925430056AF8C /* RowTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698ACD61DA925420056AF8C /* RowTestCase.swift */; }; - 5698AD191DAAD17B0056AF8C /* FTS5Tokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD151DAAD16F0056AF8C /* FTS5Tokenizer.swift */; }; - 5698AD1A1DAAD17C0056AF8C /* FTS5Tokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD151DAAD16F0056AF8C /* FTS5Tokenizer.swift */; }; - 5698AD221DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD201DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift */; }; - 5698AD251DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD201DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift */; }; - 5698AD361DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */; }; - 5698AD391DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */; }; - 569A98FC2039B72D008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98FA2039B72C008D7DBF /* Fixits-3.0.swift */; }; - 569A98FD2039B72D008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98FA2039B72C008D7DBF /* Fixits-3.0.swift */; }; - 569C1EB31CF07DDD0042627B /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */; }; - 569C1EB41CF07DDD0042627B /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */; }; - 569C1EB61CF07DDD0042627B /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */; }; - 569C1EB71CF07DDD0042627B /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */; }; - 569EF0E9200D387000A9FA45 /* DatabaseRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569EF0E8200D387000A9FA45 /* DatabaseRegion.swift */; }; - 569EF0EA200D387000A9FA45 /* DatabaseRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569EF0E8200D387000A9FA45 /* DatabaseRegion.swift */; }; - 56A4CDB11D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A4CDAF1D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift */; }; - 56A4CDB21D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A4CDAF1D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift */; }; - 56A4CDB51D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A4CDAF1D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift */; }; - 56A4CDB61D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A4CDAF1D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift */; }; - 56A5EF101EF7F20B00F03071 /* ForeignKeyInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A5EF0E1EF7F20B00F03071 /* ForeignKeyInfoTests.swift */; }; - 56A5EF111EF7F20B00F03071 /* ForeignKeyInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A5EF0E1EF7F20B00F03071 /* ForeignKeyInfoTests.swift */; }; - 56A5EF141EF7F20B00F03071 /* ForeignKeyInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A5EF0E1EF7F20B00F03071 /* ForeignKeyInfoTests.swift */; }; - 56A5EF151EF7F20B00F03071 /* ForeignKeyInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A5EF0E1EF7F20B00F03071 /* ForeignKeyInfoTests.swift */; }; - 56A8C2311D1914540096E9D4 /* UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A8C22F1D1914540096E9D4 /* UUID.swift */; }; - 56A8C2341D1914540096E9D4 /* UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A8C22F1D1914540096E9D4 /* UUID.swift */; }; - 56A8C2411D1918EE0096E9D4 /* FoundationNSUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A8C2361D1914790096E9D4 /* FoundationNSUUIDTests.swift */; }; - 56A8C2421D1918EE0096E9D4 /* FoundationUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A8C21E1D1914110096E9D4 /* FoundationUUIDTests.swift */; }; - 56A8C2431D1918EE0096E9D4 /* FoundationNSUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A8C2361D1914790096E9D4 /* FoundationNSUUIDTests.swift */; }; - 56A8C2441D1918EE0096E9D4 /* FoundationUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A8C21E1D1914110096E9D4 /* FoundationUUIDTests.swift */; }; - 56A8C2491D1918F10096E9D4 /* FoundationNSUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A8C2361D1914790096E9D4 /* FoundationNSUUIDTests.swift */; }; - 56A8C24A1D1918F10096E9D4 /* FoundationUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A8C21E1D1914110096E9D4 /* FoundationUUIDTests.swift */; }; - 56A8C24B1D1918F10096E9D4 /* FoundationNSUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A8C2361D1914790096E9D4 /* FoundationNSUUIDTests.swift */; }; - 56A8C24C1D1918F10096E9D4 /* FoundationUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A8C21E1D1914110096E9D4 /* FoundationUUIDTests.swift */; }; - 56AF746C1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AF746A1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift */; }; - 56AF746D1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AF746A1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift */; }; - 56AF74701D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AF746A1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift */; }; - 56AF74711D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AF746A1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift */; }; - 56AFC97A1CB1A41E00F48B96 /* libsqlcipher.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 560FC5561CB004AD0014AA8E /* libsqlcipher.a */; }; - 56AFC9F11CB1A8BB00F48B96 /* QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */; }; - 56AFC9F21CB1A8BB00F48B96 /* SQLCollatedExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */; }; - 56AFC9F31CB1A8BB00F48B96 /* Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238711B9C75030082EB20 /* Database.swift */; }; - 56AFC9F41CB1A8BB00F48B96 /* CGFloat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1491C672E4000235C62 /* CGFloat.swift */; }; - 56AFC9F51CB1A8BB00F48B96 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F14F1C672E4000235C62 /* Date.swift */; }; - 56AFC9F71CB1A8BB00F48B96 /* DatabaseValueConvertible+RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1571C672E4000235C62 /* DatabaseValueConvertible+RawRepresentable.swift */; }; - 56AFC9F91CB1A8BB00F48B96 /* DatabaseWriter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363C31C942C37000BE133 /* DatabaseWriter.swift */; }; - 56AFC9FB1CB1A8BB00F48B96 /* SerializedDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37A61C8FF6E500949E71 /* SerializedDatabase.swift */; }; - 56AFC9FC1CB1A8BB00F48B96 /* DatabaseMigrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238921B9C750B0082EB20 /* DatabaseMigrator.swift */; }; - 56AFC9FD1CB1A8BB00F48B96 /* NSString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1521C672E4000235C62 /* NSString.swift */; }; - 56AFC9FF1CB1A8BB00F48B96 /* DatabaseValueConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560D923E1C672C3E00F4F92B /* DatabaseValueConvertible.swift */; }; - 56AFCA001CB1A8BB00F48B96 /* Record.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238A11B9C753B0082EB20 /* Record.swift */; }; - 56AFCA031CB1A8BB00F48B96 /* TableRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560D92461C672C4B00F4F92B /* TableRecord.swift */; }; - 56AFCA061CB1A8BB00F48B96 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238701B9C75030082EB20 /* Configuration.swift */; }; - 56AFCA071CB1A8BB00F48B96 /* DatabasePool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37A31C8F625000949E71 /* DatabasePool.swift */; }; - 56AFCA081CB1A8BB00F48B96 /* Statement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238781B9C75030082EB20 /* Statement.swift */; }; - 56AFCA0A1CB1A8BB00F48B96 /* Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4391BEB42D500E39BBF /* Migration.swift */; }; - 56AFCA0B1CB1A8BB00F48B96 /* Row.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238761B9C75030082EB20 /* Row.swift */; }; - 56AFCA0C1CB1A8BB00F48B96 /* DatabaseSchemaCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5695311E1C907A8C00CF1A2B /* DatabaseSchemaCache.swift */; }; - 56AFCA0D1CB1A8BB00F48B96 /* DatabaseDateComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F14C1C672E4000235C62 /* DatabaseDateComponents.swift */; }; - 56AFCA0E1CB1A8BB00F48B96 /* DatabaseReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363BF1C942C04000BE133 /* DatabaseReader.swift */; }; - 56AFCA0F1CB1A8BB00F48B96 /* NSNull.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1501C672E4000235C62 /* NSNull.swift */; }; - 56AFCA101CB1A8BB00F48B96 /* DatabaseQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238741B9C75030082EB20 /* DatabaseQueue.swift */; }; - 56AFCA111CB1A8BB00F48B96 /* DatabaseError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238731B9C75030082EB20 /* DatabaseError.swift */; }; - 56AFCA121CB1A8BB00F48B96 /* NSNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1511C672E4000235C62 /* NSNumber.swift */; }; - 56AFCA141CB1A8BB00F48B96 /* StandardLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1581C672E4000235C62 /* StandardLibrary.swift */; }; - 56AFCA151CB1A8BB00F48B96 /* PersistableRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560D92441C672C4B00F4F92B /* PersistableRecord.swift */; }; - 56AFCA161CB1A8BB00F48B96 /* StatementColumnConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560D923F1C672C3E00F4F92B /* StatementColumnConvertible.swift */; }; - 56AFCA181CB1A8BB00F48B96 /* FetchedRecordsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31A7787C1C6A4DD600F507F6 /* FetchedRecordsController.swift */; }; - 56AFCA191CB1A8BB00F48B96 /* DatabaseValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238751B9C75030082EB20 /* DatabaseValue.swift */; }; - 56AFCA271CB1A97600F48B96 /* libsqlcipher.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 560FC5561CB004AD0014AA8E /* libsqlcipher.a */; }; - 56AFCA281CB1A98D00F48B96 /* sqlite3.h in Headers */ = {isa = PBXBuildFile; fileRef = 568BE5191CB035A900270F93 /* sqlite3.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 56AFCA291CB1A98D00F48B96 /* GRDBCipher.h in Headers */ = {isa = PBXBuildFile; fileRef = 568E1CB81CB03847008D97A6 /* GRDBCipher.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 56AFCA2A1CB1A98D00F48B96 /* GRDBCipher-Bridging.h in Headers */ = {isa = PBXBuildFile; fileRef = 568E1CB71CB03847008D97A6 /* GRDBCipher-Bridging.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 56AFCA301CB1AA9900F48B96 /* Record+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B841C54DC95005A543B /* Record+QueryInterfaceRequestTests.swift */; }; - 56AFCA311CB1AA9900F48B96 /* RecordPrimaryKeyNoneTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238291B9C74A90082EB20 /* RecordPrimaryKeyNoneTests.swift */; }; - 56AFCA321CB1AA9900F48B96 /* DatabaseQueueConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363BC1C93FD5E000BE133 /* DatabaseQueueConcurrencyTests.swift */; }; - 56AFCA331CB1AA9900F48B96 /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238261B9C74A90082EB20 /* RecordMinimalPrimaryKeyRowIDTests.swift */; }; - 56AFCA341CB1AA9900F48B96 /* RowFromDictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381E1B9C74A90082EB20 /* RowFromDictionaryTests.swift */; }; - 56AFCA361CB1AA9900F48B96 /* DatabaseCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A50C61BFF4B7F00B3A3A2 /* DatabaseCollationTests.swift */; }; - 56AFCA371CB1AA9900F48B96 /* StatementColumnConvertibleFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E8CE0F1BB4FE5B00828BEC /* StatementColumnConvertibleFetchTests.swift */; }; - 56AFCA381CB1AA9900F48B96 /* QueryInterfaceExpressionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B671C53D25E005A543B /* QueryInterfaceExpressionsTests.swift */; }; - 56AFCA391CB1AA9900F48B96 /* SelectStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238211B9C74A90082EB20 /* SelectStatementTests.swift */; }; - 56AFCA3A1CB1AA9900F48B96 /* UpdateStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238221B9C74A90082EB20 /* UpdateStatementTests.swift */; }; - 56AFCA3B1CB1AA9900F48B96 /* DatabaseMigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238241B9C74A90082EB20 /* DatabaseMigratorTests.swift */; }; - 56AFCA3E1CB1AA9900F48B96 /* DatabasePoolCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531331C919DF200CF1A2B /* DatabasePoolCollationTests.swift */; }; - 56AFCA3F1CB1AA9900F48B96 /* RecordPrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382B1B9C74A90082EB20 /* RecordPrimaryKeySingleTests.swift */; }; - 56AFCA421CB1AA9900F48B96 /* DatabasePoolFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531361C919DF700CF1A2B /* DatabasePoolFunctionTests.swift */; }; - 56AFCA441CB1AA9900F48B96 /* RowCopiedFromStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381F1B9C74A90082EB20 /* RowCopiedFromStatementTests.swift */; }; - 56AFCA451CB1AA9900F48B96 /* DatabaseQueueSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531231C90878D00CF1A2B /* DatabaseQueueSchemaCacheTests.swift */; }; - 56AFCA461CB1AA9900F48B96 /* RecordPrimaryKeyMultipleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238281B9C74A90082EB20 /* RecordPrimaryKeyMultipleTests.swift */; }; - 56AFCA471CB1AA9900F48B96 /* RowFromStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FDECE11BB32DFD009AD709 /* RowFromStatementTests.swift */; }; - 56AFCA491CB1AA9900F48B96 /* StatementArgumentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DE7B101C3D93ED00861EB8 /* StatementArgumentsTests.swift */; }; - 56AFCA4A1CB1AA9900F48B96 /* RecordInitializersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238321B9C74A90082EB20 /* RecordInitializersTests.swift */; }; - 56AFCA4B1CB1AA9900F48B96 /* MutablePersistableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363A91C933FF8000BE133 /* MutablePersistableRecordTests.swift */; }; - 56AFCA4C1CB1AA9900F48B96 /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B601C53C42C005A543B /* FetchableRecord+QueryInterfaceRequestTests.swift */; }; - 56AFCA4D1CB1AA9900F48B96 /* DatabasePoolReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA869D1C932597002BB4DF /* DatabasePoolReadOnlyTests.swift */; }; - 56AFCA4F1CB1AA9900F48B96 /* DataMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EB0AB11BCD787300A3DC55 /* DataMemoryTests.swift */; }; - 56AFCA501CB1AA9900F48B96 /* RecordCopyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382D1B9C74A90082EB20 /* RecordCopyTests.swift */; }; - 56AFCA521CB1AA9900F48B96 /* PersistableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AA1C933FF8000BE133 /* PersistableRecordTests.swift */; }; - 56AFCA531CB1AA9900F48B96 /* DatabaseValueConversionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381B1B9C74A90082EB20 /* DatabaseValueConversionTests.swift */; }; - 56AFCA551CB1AA9900F48B96 /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381C1B9C74A90082EB20 /* RawRepresentable+DatabaseValueConvertibleTests.swift */; }; - 56AFCA561CB1AA9900F48B96 /* DatabasePoolConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37AA1C90085D00949E71 /* DatabasePoolConcurrencyTests.swift */; }; - 56AFCA571CB1AA9900F48B96 /* TransactionObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5607EFD21BB8254800605DE3 /* TransactionObserverTests.swift */; }; - 56AFCA581CB1AA9900F48B96 /* Row+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D701BBC694D00DC9BD4 /* Row+FoundationTests.swift */; }; - 56AFCA5A1CB1AA9900F48B96 /* RecordSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238331B9C74A90082EB20 /* RecordSubClassTests.swift */; }; - 56AFCA5B1CB1AA9900F48B96 /* DatabaseValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238181B9C74A90082EB20 /* DatabaseValueTests.swift */; }; - 56AFCA5C1CB1AA9900F48B96 /* DatabaseQueueReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567156151CB142AA007DC145 /* DatabaseQueueReadOnlyTests.swift */; }; - 56AFCA5D1CB1AA9900F48B96 /* DatabaseReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA86931C91DFE7002BB4DF /* DatabaseReaderTests.swift */; }; - 56AFCA5E1CB1AA9900F48B96 /* FetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565B0FEE1BBC7D980098DE03 /* FetchableRecordTests.swift */; }; - 56AFCA5F1CB1AA9900F48B96 /* DatabaseValueConvertibleFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E8CE0C1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift */; }; - 56AFCA601CB1AA9900F48B96 /* RecordPrimaryKeyRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382A1B9C74A90082EB20 /* RecordPrimaryKeyRowIDTests.swift */; }; - 56AFCA611CB1AA9900F48B96 /* RecordEditedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382F1B9C74A90082EB20 /* RecordEditedTests.swift */; }; - 56AFCA621CB1AA9900F48B96 /* DatabasePoolSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531281C908A5B00CF1A2B /* DatabasePoolSchemaCacheTests.swift */; }; - 56AFCA631CB1AA9900F48B96 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382C1B9C74A90082EB20 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift */; }; - 56AFCA641CB1AA9900F48B96 /* DatabaseValueConvertibleSubclassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381A1B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift */; }; - 56AFCA651CB1AA9900F48B96 /* DatabaseErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238161B9C74A90082EB20 /* DatabaseErrorTests.swift */; }; - 56AFCA661CB1AA9900F48B96 /* DatabaseQueueReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363D41C94484E000BE133 /* DatabaseQueueReleaseMemoryTests.swift */; }; - 56AFCA671CB1AA9900F48B96 /* DatabasePoolReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363CF1C943D13000BE133 /* DatabasePoolReleaseMemoryTests.swift */; }; - 56AFCA681CB1AA9900F48B96 /* RecordMinimalPrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238271B9C74A90082EB20 /* RecordMinimalPrimaryKeySingleTests.swift */; }; - 56AFCA6B1CB1AA9900F48B96 /* DatabaseTimestampTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238B51B9CA2590082EB20 /* DatabaseTimestampTests.swift */; }; - 56AFCA6C1CB1AA9900F48B96 /* StatementArguments+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D731BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift */; }; - 56AFCA6D1CB1AA9900F48B96 /* TableRecord+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B6A1C53D3E8005A543B /* TableRecord+QueryInterfaceRequestTests.swift */; }; - 56AFCA6E1CB1AA9900F48B96 /* FoundationNSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* FoundationNSDateTests.swift */; }; - 56AFCA6F1CB1AA9900F48B96 /* DatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238131B9C74A90082EB20 /* DatabaseTests.swift */; }; - 56AFCA701CB1AA9900F48B96 /* QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B5D1C53C38F005A543B /* QueryInterfaceRequestTests.swift */; }; - 56AFCA721CB1AA9900F48B96 /* DatabaseFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560C97C61BFD0B8400BF8471 /* DatabaseFunctionTests.swift */; }; - 56AFCA731CB1AA9900F48B96 /* DatabaseQueueInMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238141B9C74A90082EB20 /* DatabaseQueueInMemoryTests.swift */; }; - 56AFCA741CB1AA9900F48B96 /* RecordWithColumnNameManglingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A5E4081BA2BCF900707640 /* RecordWithColumnNameManglingTests.swift */; }; - 56AFCA751CB1AA9900F48B96 /* CGFloatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4291BE14A1900E39BBF /* CGFloatTests.swift */; }; - 56AFCA761CB1AA9900F48B96 /* DatabaseRegionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1861C69111300235C62 /* DatabaseRegionTests.swift */; }; - 56AFCA771CB1AA9900F48B96 /* GRDBTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623E0901B4AFACC00B20B7F /* GRDBTestCase.swift */; }; - 56AFCA831CB1AAC900F48B96 /* GRDBCipher.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 56AFCA231CB1A8BB00F48B96 /* GRDBCipher.framework */; }; - 56AFCA891CB1ABC800F48B96 /* Record+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B841C54DC95005A543B /* Record+QueryInterfaceRequestTests.swift */; }; - 56AFCA8A1CB1ABC800F48B96 /* RecordPrimaryKeyNoneTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238291B9C74A90082EB20 /* RecordPrimaryKeyNoneTests.swift */; }; - 56AFCA8B1CB1ABC800F48B96 /* DatabaseQueueConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363BC1C93FD5E000BE133 /* DatabaseQueueConcurrencyTests.swift */; }; - 56AFCA8C1CB1ABC800F48B96 /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238261B9C74A90082EB20 /* RecordMinimalPrimaryKeyRowIDTests.swift */; }; - 56AFCA8D1CB1ABC800F48B96 /* RowFromDictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381E1B9C74A90082EB20 /* RowFromDictionaryTests.swift */; }; - 56AFCA8F1CB1ABC800F48B96 /* DatabaseCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A50C61BFF4B7F00B3A3A2 /* DatabaseCollationTests.swift */; }; - 56AFCA901CB1ABC800F48B96 /* StatementColumnConvertibleFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E8CE0F1BB4FE5B00828BEC /* StatementColumnConvertibleFetchTests.swift */; }; - 56AFCA911CB1ABC800F48B96 /* QueryInterfaceExpressionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B671C53D25E005A543B /* QueryInterfaceExpressionsTests.swift */; }; - 56AFCA921CB1ABC800F48B96 /* SelectStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238211B9C74A90082EB20 /* SelectStatementTests.swift */; }; - 56AFCA931CB1ABC800F48B96 /* UpdateStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238221B9C74A90082EB20 /* UpdateStatementTests.swift */; }; - 56AFCA941CB1ABC800F48B96 /* DatabaseMigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238241B9C74A90082EB20 /* DatabaseMigratorTests.swift */; }; - 56AFCA971CB1ABC800F48B96 /* DatabasePoolCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531331C919DF200CF1A2B /* DatabasePoolCollationTests.swift */; }; - 56AFCA981CB1ABC800F48B96 /* RecordPrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382B1B9C74A90082EB20 /* RecordPrimaryKeySingleTests.swift */; }; - 56AFCA9B1CB1ABC800F48B96 /* DatabasePoolFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531361C919DF700CF1A2B /* DatabasePoolFunctionTests.swift */; }; - 56AFCA9D1CB1ABC800F48B96 /* RowCopiedFromStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381F1B9C74A90082EB20 /* RowCopiedFromStatementTests.swift */; }; - 56AFCA9E1CB1ABC800F48B96 /* DatabaseQueueSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531231C90878D00CF1A2B /* DatabaseQueueSchemaCacheTests.swift */; }; - 56AFCA9F1CB1ABC800F48B96 /* RecordPrimaryKeyMultipleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238281B9C74A90082EB20 /* RecordPrimaryKeyMultipleTests.swift */; }; - 56AFCAA01CB1ABC800F48B96 /* RowFromStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FDECE11BB32DFD009AD709 /* RowFromStatementTests.swift */; }; - 56AFCAA21CB1ABC800F48B96 /* StatementArgumentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DE7B101C3D93ED00861EB8 /* StatementArgumentsTests.swift */; }; - 56AFCAA31CB1ABC800F48B96 /* RecordInitializersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238321B9C74A90082EB20 /* RecordInitializersTests.swift */; }; - 56AFCAA41CB1ABC800F48B96 /* MutablePersistableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363A91C933FF8000BE133 /* MutablePersistableRecordTests.swift */; }; - 56AFCAA51CB1ABC800F48B96 /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B601C53C42C005A543B /* FetchableRecord+QueryInterfaceRequestTests.swift */; }; - 56AFCAA61CB1ABC800F48B96 /* DatabasePoolReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA869D1C932597002BB4DF /* DatabasePoolReadOnlyTests.swift */; }; - 56AFCAA81CB1ABC800F48B96 /* DataMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EB0AB11BCD787300A3DC55 /* DataMemoryTests.swift */; }; - 56AFCAA91CB1ABC800F48B96 /* RecordCopyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382D1B9C74A90082EB20 /* RecordCopyTests.swift */; }; - 56AFCAAB1CB1ABC800F48B96 /* PersistableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363AA1C933FF8000BE133 /* PersistableRecordTests.swift */; }; - 56AFCAAC1CB1ABC800F48B96 /* DatabaseValueConversionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381B1B9C74A90082EB20 /* DatabaseValueConversionTests.swift */; }; - 56AFCAAE1CB1ABC800F48B96 /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381C1B9C74A90082EB20 /* RawRepresentable+DatabaseValueConvertibleTests.swift */; }; - 56AFCAAF1CB1ABC800F48B96 /* DatabasePoolConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37AA1C90085D00949E71 /* DatabasePoolConcurrencyTests.swift */; }; - 56AFCAB01CB1ABC800F48B96 /* TransactionObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5607EFD21BB8254800605DE3 /* TransactionObserverTests.swift */; }; - 56AFCAB11CB1ABC800F48B96 /* Row+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D701BBC694D00DC9BD4 /* Row+FoundationTests.swift */; }; - 56AFCAB31CB1ABC800F48B96 /* RecordSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238331B9C74A90082EB20 /* RecordSubClassTests.swift */; }; - 56AFCAB41CB1ABC800F48B96 /* DatabaseValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238181B9C74A90082EB20 /* DatabaseValueTests.swift */; }; - 56AFCAB51CB1ABC800F48B96 /* DatabaseQueueReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567156151CB142AA007DC145 /* DatabaseQueueReadOnlyTests.swift */; }; - 56AFCAB61CB1ABC800F48B96 /* DatabaseReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA86931C91DFE7002BB4DF /* DatabaseReaderTests.swift */; }; - 56AFCAB71CB1ABC800F48B96 /* FetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565B0FEE1BBC7D980098DE03 /* FetchableRecordTests.swift */; }; - 56AFCAB81CB1ABC800F48B96 /* DatabaseValueConvertibleFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E8CE0C1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift */; }; - 56AFCAB91CB1ABC800F48B96 /* RecordPrimaryKeyRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382A1B9C74A90082EB20 /* RecordPrimaryKeyRowIDTests.swift */; }; - 56AFCABA1CB1ABC800F48B96 /* RecordEditedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382F1B9C74A90082EB20 /* RecordEditedTests.swift */; }; - 56AFCABB1CB1ABC800F48B96 /* DatabasePoolSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569531281C908A5B00CF1A2B /* DatabasePoolSchemaCacheTests.swift */; }; - 56AFCABC1CB1ABC800F48B96 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2382C1B9C74A90082EB20 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift */; }; - 56AFCABD1CB1ABC800F48B96 /* DatabaseValueConvertibleSubclassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A2381A1B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift */; }; - 56AFCABE1CB1ABC800F48B96 /* DatabaseErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238161B9C74A90082EB20 /* DatabaseErrorTests.swift */; }; - 56AFCABF1CB1ABC800F48B96 /* DatabaseQueueReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363D41C94484E000BE133 /* DatabaseQueueReleaseMemoryTests.swift */; }; - 56AFCAC01CB1ABC800F48B96 /* DatabasePoolReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363CF1C943D13000BE133 /* DatabasePoolReleaseMemoryTests.swift */; }; - 56AFCAC11CB1ABC800F48B96 /* RecordMinimalPrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238271B9C74A90082EB20 /* RecordMinimalPrimaryKeySingleTests.swift */; }; - 56AFCAC41CB1ABC800F48B96 /* DatabaseTimestampTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238B51B9CA2590082EB20 /* DatabaseTimestampTests.swift */; }; - 56AFCAC51CB1ABC800F48B96 /* StatementArguments+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D731BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift */; }; - 56AFCAC61CB1ABC800F48B96 /* TableRecord+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B6A1C53D3E8005A543B /* TableRecord+QueryInterfaceRequestTests.swift */; }; - 56AFCAC71CB1ABC800F48B96 /* FoundationNSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* FoundationNSDateTests.swift */; }; - 56AFCAC81CB1ABC800F48B96 /* DatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238131B9C74A90082EB20 /* DatabaseTests.swift */; }; - 56AFCAC91CB1ABC800F48B96 /* QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B5D1C53C38F005A543B /* QueryInterfaceRequestTests.swift */; }; - 56AFCACB1CB1ABC800F48B96 /* DatabaseFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560C97C61BFD0B8400BF8471 /* DatabaseFunctionTests.swift */; }; - 56AFCACC1CB1ABC800F48B96 /* DatabaseQueueInMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238141B9C74A90082EB20 /* DatabaseQueueInMemoryTests.swift */; }; - 56AFCACD1CB1ABC800F48B96 /* RecordWithColumnNameManglingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A5E4081BA2BCF900707640 /* RecordWithColumnNameManglingTests.swift */; }; - 56AFCACE1CB1ABC800F48B96 /* CGFloatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4291BE14A1900E39BBF /* CGFloatTests.swift */; }; - 56AFCACF1CB1ABC800F48B96 /* DatabaseRegionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1861C69111300235C62 /* DatabaseRegionTests.swift */; }; - 56AFCAD01CB1ABC800F48B96 /* GRDBTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623E0901B4AFACC00B20B7F /* GRDBTestCase.swift */; }; - 56AFCAD21CB1ABC800F48B96 /* GRDBCipher.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 56AFCA231CB1A8BB00F48B96 /* GRDBCipher.framework */; }; - 56B021CA1D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */; }; - 56B021CB1D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */; }; - 56B021CE1D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */; }; - 56B021CF1D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */; }; - 56B14E801D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B14E7E1D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift */; }; - 56B14E811D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B14E7E1D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift */; }; - 56B14E841D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B14E7E1D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift */; }; - 56B14E851D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B14E7E1D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift */; }; - 56B15D0C1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B15D0A1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift */; }; - 56B15D0D1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B15D0A1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift */; }; - 56B6EF64208CB762002F0ACB /* ColumnExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B6EF62208CB762002F0ACB /* ColumnExpressionTests.swift */; }; - 56B6EF65208CB762002F0ACB /* ColumnExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B6EF62208CB762002F0ACB /* ColumnExpressionTests.swift */; }; - 56B6EF66208CB762002F0ACB /* ColumnExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B6EF62208CB762002F0ACB /* ColumnExpressionTests.swift */; }; - 56B6EF67208CB762002F0ACB /* ColumnExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B6EF62208CB762002F0ACB /* ColumnExpressionTests.swift */; }; - 56B9649E1DA51B4C0002DA19 /* FTS5.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B9649C1DA51B4C0002DA19 /* FTS5.swift */; }; - 56B964A11DA51B4C0002DA19 /* FTS5.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B9649C1DA51B4C0002DA19 /* FTS5.swift */; }; - 56B964B21DA51D010002DA19 /* FTS5TokenizerDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964B01DA51D010002DA19 /* FTS5TokenizerDescriptor.swift */; }; - 56B964B51DA51D010002DA19 /* FTS5TokenizerDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964B01DA51D010002DA19 /* FTS5TokenizerDescriptor.swift */; }; - 56B964BA1DA51D0A0002DA19 /* FTS5Pattern.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964B81DA51D0A0002DA19 /* FTS5Pattern.swift */; }; - 56B964BD1DA51D0A0002DA19 /* FTS5Pattern.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964B81DA51D0A0002DA19 /* FTS5Pattern.swift */; }; - 56BB6EAA1D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BB6EA81D3009B100A1CA52 /* SchedulingWatchdog.swift */; }; - 56BB6EAD1D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BB6EA81D3009B100A1CA52 /* SchedulingWatchdog.swift */; }; - 56BF6D301DEF47DA006039A3 /* Fixits-0-84-0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2C1DEF47DA006039A3 /* Fixits-0-84-0.swift */; }; - 56BF6D331DEF47DA006039A3 /* Fixits-0-84-0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2C1DEF47DA006039A3 /* Fixits-0-84-0.swift */; }; - 56BF6D371DEF47DA006039A3 /* Fixits-0-90-1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2D1DEF47DA006039A3 /* Fixits-0-90-1.swift */; }; - 56BF6D3A1DEF47DA006039A3 /* Fixits-0-90-1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2D1DEF47DA006039A3 /* Fixits-0-90-1.swift */; }; - 56BF6D3E1DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2E1DEF47DA006039A3 /* Fixits-Swift2.swift */; }; - 56BF6D411DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2E1DEF47DA006039A3 /* Fixits-Swift2.swift */; }; - 56C3F7541CF9F12400F6A361 /* DatabaseSavepointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C3F7521CF9F12400F6A361 /* DatabaseSavepointTests.swift */; }; - 56C3F7551CF9F12400F6A361 /* DatabaseSavepointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C3F7521CF9F12400F6A361 /* DatabaseSavepointTests.swift */; }; - 56C3F7571CF9F12400F6A361 /* DatabaseSavepointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C3F7521CF9F12400F6A361 /* DatabaseSavepointTests.swift */; }; - 56C3F7581CF9F12400F6A361 /* DatabaseSavepointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C3F7521CF9F12400F6A361 /* DatabaseSavepointTests.swift */; }; - 56CC9236201E009700CB597E /* DropWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC922E201DFFE200CB597E /* DropWhileCursorTests.swift */; }; - 56CC9237201E009800CB597E /* DropWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC922E201DFFE200CB597E /* DropWhileCursorTests.swift */; }; - 56CC9238201E009900CB597E /* DropWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC922E201DFFE200CB597E /* DropWhileCursorTests.swift */; }; - 56CC9239201E009A00CB597E /* DropWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC922E201DFFE200CB597E /* DropWhileCursorTests.swift */; }; - 56CC923E201E034200CB597E /* PrefixWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC923D201E034200CB597E /* PrefixWhileCursorTests.swift */; }; - 56CC923F201E034200CB597E /* PrefixWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC923D201E034200CB597E /* PrefixWhileCursorTests.swift */; }; - 56CC9240201E034200CB597E /* PrefixWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC923D201E034200CB597E /* PrefixWhileCursorTests.swift */; }; - 56CC9241201E034200CB597E /* PrefixWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC923D201E034200CB597E /* PrefixWhileCursorTests.swift */; }; - 56CC924C201E059100CB597E /* DropFirstCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC924B201E059100CB597E /* DropFirstCursorTests.swift */; }; - 56CC924D201E059100CB597E /* DropFirstCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC924B201E059100CB597E /* DropFirstCursorTests.swift */; }; - 56CC924E201E059100CB597E /* DropFirstCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC924B201E059100CB597E /* DropFirstCursorTests.swift */; }; - 56CC924F201E059100CB597E /* DropFirstCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC924B201E059100CB597E /* DropFirstCursorTests.swift */; }; - 56CC9257201E094F00CB597E /* PrefixCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC9256201E094E00CB597E /* PrefixCursorTests.swift */; }; - 56CC9258201E094F00CB597E /* PrefixCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC9256201E094E00CB597E /* PrefixCursorTests.swift */; }; - 56CC9259201E094F00CB597E /* PrefixCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC9256201E094E00CB597E /* PrefixCursorTests.swift */; }; - 56CC925A201E094F00CB597E /* PrefixCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC9256201E094E00CB597E /* PrefixCursorTests.swift */; }; - 56CEB4F21EAA2EFA00BFAF62 /* FetchableRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB4F01EAA2EFA00BFAF62 /* FetchableRecord.swift */; }; - 56CEB4F51EAA2EFA00BFAF62 /* FetchableRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB4F01EAA2EFA00BFAF62 /* FetchableRecord.swift */; }; - 56CEB4FB1EAA2F4D00BFAF62 /* FTS3.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB4F81EAA2F4D00BFAF62 /* FTS3.swift */; }; - 56CEB4FE1EAA2F4D00BFAF62 /* FTS3.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB4F81EAA2F4D00BFAF62 /* FTS3.swift */; }; - 56CEB5021EAA2F4D00BFAF62 /* FTS4.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB4F91EAA2F4D00BFAF62 /* FTS4.swift */; }; - 56CEB5051EAA2F4D00BFAF62 /* FTS4.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB4F91EAA2F4D00BFAF62 /* FTS4.swift */; }; - 56CEB5121EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */; }; - 56CEB5151EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */; }; - 56CEB51A1EAA328900BFAF62 /* FTS5+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */; }; - 56CEB51D1EAA328900BFAF62 /* FTS5+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */; }; - 56CEB5461EAA359A00BFAF62 /* Column.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5401EAA359A00BFAF62 /* Column.swift */; }; - 56CEB5491EAA359A00BFAF62 /* Column.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5401EAA359A00BFAF62 /* Column.swift */; }; - 56CEB54D1EAA359A00BFAF62 /* SQLExpressible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5411EAA359A00BFAF62 /* SQLExpressible.swift */; }; - 56CEB5501EAA359A00BFAF62 /* SQLExpressible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5411EAA359A00BFAF62 /* SQLExpressible.swift */; }; - 56CEB5541EAA359A00BFAF62 /* SQLExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5421EAA359A00BFAF62 /* SQLExpression.swift */; }; - 56CEB5571EAA359A00BFAF62 /* SQLExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5421EAA359A00BFAF62 /* SQLExpression.swift */; }; - 56CEB55B1EAA359A00BFAF62 /* SQLOrdering.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5431EAA359A00BFAF62 /* SQLOrdering.swift */; }; - 56CEB55E1EAA359A00BFAF62 /* SQLOrdering.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5431EAA359A00BFAF62 /* SQLOrdering.swift */; }; - 56CEB5621EAA359A00BFAF62 /* SQLSelectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5441EAA359A00BFAF62 /* SQLSelectable.swift */; }; - 56CEB5651EAA359A00BFAF62 /* SQLSelectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5441EAA359A00BFAF62 /* SQLSelectable.swift */; }; - 56D1215B1ED34978001347D2 /* Fixits-0.109.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D121591ED34978001347D2 /* Fixits-0.109.0.swift */; }; - 56D1215E1ED34978001347D2 /* Fixits-0.109.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D121591ED34978001347D2 /* Fixits-0.109.0.swift */; }; - 56D5075F1F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D5075D1F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift */; }; - 56D507601F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D5075D1F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift */; }; - 56D507631F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D5075D1F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift */; }; - 56D507641F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D5075D1F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift */; }; - 56D51D011EA789FA0074638A /* FetchableRecord+TableRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D51CFF1EA789FA0074638A /* FetchableRecord+TableRecord.swift */; }; - 56D51D041EA789FA0074638A /* FetchableRecord+TableRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D51CFF1EA789FA0074638A /* FetchableRecord+TableRecord.swift */; }; - 56D91A9C2205DD5200770D8D /* SQLRelation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91A9B2205DD5200770D8D /* SQLRelation.swift */; }; - 56D91A9D2205DD5200770D8D /* SQLRelation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91A9B2205DD5200770D8D /* SQLRelation.swift */; }; - 56D91AAD2205F30200770D8D /* DatabasePromise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91AAC2205F30200770D8D /* DatabasePromise.swift */; }; - 56D91AAE2205F30200770D8D /* DatabasePromise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91AAC2205F30200770D8D /* DatabasePromise.swift */; }; - 56D91AB42205F8C000770D8D /* SQLSelectQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91AB32205F8C000770D8D /* SQLSelectQuery.swift */; }; - 56D91AB52205F8C000770D8D /* SQLSelectQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91AB32205F8C000770D8D /* SQLSelectQuery.swift */; }; - 56DAA2D31DE99DAB006E10C8 /* DatabaseCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DAA2D11DE99DAB006E10C8 /* DatabaseCursorTests.swift */; }; - 56DAA2D41DE99DAB006E10C8 /* DatabaseCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DAA2D11DE99DAB006E10C8 /* DatabaseCursorTests.swift */; }; - 56DAA2D71DE99DAB006E10C8 /* DatabaseCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DAA2D11DE99DAB006E10C8 /* DatabaseCursorTests.swift */; }; - 56DAA2D81DE99DAB006E10C8 /* DatabaseCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DAA2D11DE99DAB006E10C8 /* DatabaseCursorTests.swift */; }; - 56DAA2DC1DE9C827006E10C8 /* Cursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DAA2DA1DE9C827006E10C8 /* Cursor.swift */; }; - 56DAA2DF1DE9C827006E10C8 /* Cursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DAA2DA1DE9C827006E10C8 /* Cursor.swift */; }; - 56E06F131E859068008AE2A4 /* Fixits-0.102.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E06F051E859064008AE2A4 /* Fixits-0.102.0.swift */; }; - 56E06F161E85906C008AE2A4 /* Fixits-0.102.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E06F051E859064008AE2A4 /* Fixits-0.102.0.swift */; }; - 56EA63CC209C7F31009715B8 /* DerivableRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA63CB209C7F31009715B8 /* DerivableRequestTests.swift */; }; - 56EA63CD209C7F31009715B8 /* DerivableRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA63CB209C7F31009715B8 /* DerivableRequestTests.swift */; }; - 56EA63CE209C7F31009715B8 /* DerivableRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA63CB209C7F31009715B8 /* DerivableRequestTests.swift */; }; - 56EA63CF209C7F31009715B8 /* DerivableRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA63CB209C7F31009715B8 /* DerivableRequestTests.swift */; }; - 56F26C241CEE3F34007969C4 /* RowAdapterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565F03C11CE5D3AA00DE108F /* RowAdapterTests.swift */; }; - 56F3E74A1E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */; }; - 56F3E74B1E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */; }; - 56F3E74E1E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */; }; - 56F3E74F1E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */; }; - 56F3E7641E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F3E7621E67F8C100BF0F01 /* Fixits-0.101.1.swift */; }; - 56F3E7671E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F3E7621E67F8C100BF0F01 /* Fixits-0.101.1.swift */; }; - 56FEE7FC1F47253700D930EA /* TableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FEE7FA1F47253700D930EA /* TableRecordTests.swift */; }; - 56FEE7FD1F47253700D930EA /* TableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FEE7FA1F47253700D930EA /* TableRecordTests.swift */; }; - 56FEE8001F47253700D930EA /* TableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FEE7FA1F47253700D930EA /* TableRecordTests.swift */; }; - 56FEE8011F47253700D930EA /* TableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FEE7FA1F47253700D930EA /* TableRecordTests.swift */; }; - 56FF45411D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FF453F1D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift */; }; - 56FF45421D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FF453F1D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift */; }; - 56FF45451D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FF453F1D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift */; }; - 56FF45461D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FF453F1D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift */; }; - 56FF45571D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FF45551D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift */; }; - 56FF45581D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FF45551D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift */; }; - 56FF455B1D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FF45551D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift */; }; - 56FF455C1D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FF45551D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift */; }; - 6340BF811E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6340BF7F1E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift */; }; - 6340BF821E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6340BF7F1E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift */; }; - 6340BF851E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6340BF7F1E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift */; }; - 6340BF861E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6340BF7F1E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift */; }; -/* End PBXBuildFile section */ - -/* Begin PBXContainerItemProxy section */ - 560FC5551CB004AD0014AA8E /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 560FC5501CB004AD0014AA8E /* sqlcipher.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = D2AAC046055464E500DB518D; - remoteInfo = sqlcipher; - }; - 5671561B1CB16729007DC145 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = DC3773EA19C8CBB3004FCF85 /* Project object */; - proxyType = 1; - remoteGlobalIDString = 560FC5191CB003810014AA8E; - remoteInfo = GRDBCipherOSX; - }; - 568BE5211CB0371000270F93 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = DC3773EA19C8CBB3004FCF85 /* Project object */; - proxyType = 1; - remoteGlobalIDString = 560FC5191CB003810014AA8E; - remoteInfo = GRDBCipherOSX; - }; - 56AFC9771CB1A3E200F48B96 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 560FC5501CB004AD0014AA8E /* sqlcipher.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = D2AAC045055464E500DB518D; - remoteInfo = sqlcipher; - }; - 56AFCA251CB1A96A00F48B96 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 560FC5501CB004AD0014AA8E /* sqlcipher.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = D2AAC045055464E500DB518D; - remoteInfo = sqlcipher; - }; - 56AFCA811CB1AAB400F48B96 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = DC3773EA19C8CBB3004FCF85 /* Project object */; - proxyType = 1; - remoteGlobalIDString = 56AFC9EE1CB1A8BB00F48B96; - remoteInfo = GRDBCipheriOS; - }; - 56AFCA861CB1ABC800F48B96 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = DC3773EA19C8CBB3004FCF85 /* Project object */; - proxyType = 1; - remoteGlobalIDString = 56AFC9EE1CB1A8BB00F48B96; - remoteInfo = GRDBCipheriOS; - }; -/* End PBXContainerItemProxy section */ - -/* Begin PBXFileReference section */ - 31A7787C1C6A4DD600F507F6 /* FetchedRecordsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedRecordsController.swift; sourceTree = ""; }; - 5605F1491C672E4000235C62 /* CGFloat.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGFloat.swift; sourceTree = ""; }; - 5605F14C1C672E4000235C62 /* DatabaseDateComponents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseDateComponents.swift; sourceTree = ""; }; - 5605F14F1C672E4000235C62 /* Date.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = ""; }; - 5605F1501C672E4000235C62 /* NSNull.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSNull.swift; sourceTree = ""; }; - 5605F1511C672E4000235C62 /* NSNumber.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSNumber.swift; sourceTree = ""; }; - 5605F1521C672E4000235C62 /* NSString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSString.swift; sourceTree = ""; }; - 5605F1571C672E4000235C62 /* DatabaseValueConvertible+RawRepresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DatabaseValueConvertible+RawRepresentable.swift"; sourceTree = ""; }; - 5605F1581C672E4000235C62 /* StandardLibrary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StandardLibrary.swift; sourceTree = ""; }; - 5605F1861C69111300235C62 /* DatabaseRegionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegionTests.swift; sourceTree = ""; }; - 5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLCollatedExpression.swift; sourceTree = ""; }; - 5607EFD21BB8254800605DE3 /* TransactionObserverTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionObserverTests.swift; sourceTree = ""; }; - 560A37A31C8F625000949E71 /* DatabasePool.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePool.swift; sourceTree = ""; }; - 560A37A61C8FF6E500949E71 /* SerializedDatabase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SerializedDatabase.swift; sourceTree = ""; }; - 560A37AA1C90085D00949E71 /* DatabasePoolConcurrencyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolConcurrencyTests.swift; sourceTree = ""; }; - 560C97C61BFD0B8400BF8471 /* DatabaseFunctionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseFunctionTests.swift; sourceTree = ""; }; - 560D923E1C672C3E00F4F92B /* DatabaseValueConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertible.swift; sourceTree = ""; }; - 560D923F1C672C3E00F4F92B /* StatementColumnConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementColumnConvertible.swift; sourceTree = ""; }; - 560D92441C672C4B00F4F92B /* PersistableRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersistableRecord.swift; sourceTree = ""; }; - 560D92461C672C4B00F4F92B /* TableRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableRecord.swift; sourceTree = ""; }; - 560FC54D1CB003810014AA8E /* GRDBCipher.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = GRDBCipher.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 560FC5501CB004AD0014AA8E /* sqlcipher.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = sqlcipher.xcodeproj; path = SQLCipher/src/sqlcipher.xcodeproj; sourceTree = ""; }; - 560FC5B01CB00B880014AA8E /* GRDBCipherOSXTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBCipherOSXTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 5613ED7321A95E8400DC7A68 /* ValueObservation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservation.swift; sourceTree = ""; }; - 5613ED7421A95E8400DC7A68 /* ValueObservation+Combine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ValueObservation+Combine.swift"; sourceTree = ""; }; - 5613ED7521A95E8400DC7A68 /* ValueObservation+Map.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ValueObservation+Map.swift"; sourceTree = ""; }; - 5613ED7621A95E8400DC7A68 /* ValueObservation+Row.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ValueObservation+Row.swift"; sourceTree = ""; }; - 5613ED7721A95E8400DC7A68 /* ValueObservation+FetchableRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ValueObservation+FetchableRecord.swift"; sourceTree = ""; }; - 5613ED7821A95E8400DC7A68 /* ValueObservation+DatabaseValueConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ValueObservation+DatabaseValueConvertible.swift"; sourceTree = ""; }; - 5613ED7921A95E8400DC7A68 /* ValueReducer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueReducer.swift; sourceTree = ""; }; - 5613ED7A21A95E8400DC7A68 /* ValueObservation+Count.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ValueObservation+Count.swift"; sourceTree = ""; }; - 5613ED9D21A96A6F00DC7A68 /* ValueObservationCombineTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationCombineTests.swift; sourceTree = ""; }; - 561667001D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSDecimalNumberTests.swift; sourceTree = ""; }; - 5616AAF8207CD5A900AC3664 /* RequestProtocols.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestProtocols.swift; sourceTree = ""; }; - 562393171DECC02000A6B01F /* RowFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFetchTests.swift; sourceTree = ""; }; - 5623932F1DEDFC5700A6B01F /* AnyCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyCursorTests.swift; sourceTree = ""; }; - 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnumeratedCursorTests.swift; sourceTree = ""; }; - 562393561DEE013C00A6B01F /* FilterCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FilterCursorTests.swift; sourceTree = ""; }; - 5623935F1DEE06D300A6B01F /* CursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CursorTests.swift; sourceTree = ""; }; - 562393681DEE0CD200A6B01F /* FlattenCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlattenCursorTests.swift; sourceTree = ""; }; - 562393711DEE104400A6B01F /* MapCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapCursorTests.swift; sourceTree = ""; }; - 5623E0901B4AFACC00B20B7F /* GRDBTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GRDBTestCase.swift; sourceTree = ""; }; - 562756421E963AAC0035B653 /* DatabaseWriterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseWriterTests.swift; sourceTree = ""; }; - 562EA8251F17B2AC00FA528C /* CompilationProtocolTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompilationProtocolTests.swift; sourceTree = ""; }; - 562EA82E1F17B9EB00FA528C /* CompilationSubClassTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompilationSubClassTests.swift; sourceTree = ""; }; - 56300B5D1C53C38F005A543B /* QueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceRequestTests.swift; sourceTree = ""; }; - 56300B601C53C42C005A543B /* FetchableRecord+QueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FetchableRecord+QueryInterfaceRequestTests.swift"; sourceTree = ""; }; - 56300B671C53D25E005A543B /* QueryInterfaceExpressionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceExpressionsTests.swift; sourceTree = ""; }; - 56300B6A1C53D3E8005A543B /* TableRecord+QueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TableRecord+QueryInterfaceRequestTests.swift"; sourceTree = ""; }; - 56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceRequest.swift; sourceTree = ""; }; - 56300B841C54DC95005A543B /* Record+QueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Record+QueryInterfaceRequestTests.swift"; sourceTree = ""; }; - 563363A91C933FF8000BE133 /* MutablePersistableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordTests.swift; sourceTree = ""; }; - 563363AA1C933FF8000BE133 /* PersistableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersistableRecordTests.swift; sourceTree = ""; }; - 563363BC1C93FD5E000BE133 /* DatabaseQueueConcurrencyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueConcurrencyTests.swift; sourceTree = ""; }; - 563363BF1C942C04000BE133 /* DatabaseReader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseReader.swift; sourceTree = ""; }; - 563363C31C942C37000BE133 /* DatabaseWriter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseWriter.swift; sourceTree = ""; }; - 563363CF1C943D13000BE133 /* DatabasePoolReleaseMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolReleaseMemoryTests.swift; sourceTree = ""; }; - 563363D41C94484E000BE133 /* DatabaseQueueReleaseMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueReleaseMemoryTests.swift; sourceTree = ""; }; - 5634B1061CF9B970005360B9 /* TransactionObserverSavepointsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionObserverSavepointsTests.swift; sourceTree = ""; }; - 5636E9BB1D22574100B9B05F /* FetchRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchRequest.swift; sourceTree = ""; }; - 563B06DC2185E07100B38F35 /* ValueObservationExtentTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationExtentTests.swift; sourceTree = ""; }; - 563B06DD2185E07200B38F35 /* ValueObservationReadonlyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationReadonlyTests.swift; sourceTree = ""; }; - 563B06DE2185E07200B38F35 /* ValueObservationFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationFetchTests.swift; sourceTree = ""; }; - 563B06DF2185E07200B38F35 /* ValueObservationReducerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationReducerTests.swift; sourceTree = ""; }; - 563B06E02185E07200B38F35 /* ValueObservationSchedulingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationSchedulingTests.swift; sourceTree = ""; }; - 563B06F921861D8B00B38F35 /* ValueObservationCountTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationCountTests.swift; sourceTree = ""; }; - 563B07072186280500B38F35 /* ValueObservationRowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationRowTests.swift; sourceTree = ""; }; - 563B070C21862C3500B38F35 /* ValueObservationRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationRecordTests.swift; sourceTree = ""; }; - 563B071D21862F5D00B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationDatabaseValueConvertibleTests.swift; sourceTree = ""; }; - 563EF422215F8A88007DAACD /* OrderedDictionary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OrderedDictionary.swift; sourceTree = ""; }; - 563EF43A2161183E007DAACD /* AssociationAggregate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationAggregate.swift; sourceTree = ""; }; - 563EF44421613212007DAACD /* AssociationAggregateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationAggregateTests.swift; sourceTree = ""; }; - 563EF44F2161F1A7007DAACD /* Inflections.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Inflections.swift; sourceTree = ""; }; - 563EF45821631E51007DAACD /* QueryInterfacePromiseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfacePromiseTests.swift; sourceTree = ""; }; - 564448821EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseAfterNextTransactionCommitTests.swift; sourceTree = ""; }; - 5644DE7A20F8C903001FFDDE /* DatabaseValueConversion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConversion.swift; sourceTree = ""; }; - 5644DE8120F8D1E4001FFDDE /* DatabaseValueConversionErrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConversionErrorTests.swift; sourceTree = ""; }; - 564A50C61BFF4B7F00B3A3A2 /* DatabaseCollationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseCollationTests.swift; sourceTree = ""; }; - 564CE43F21AA957000652B19 /* ValueObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObserver.swift; sourceTree = ""; }; - 564CE4DC21B2DEF700652B19 /* ValueObservation+CompactMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ValueObservation+CompactMap.swift"; sourceTree = ""; }; - 564CE4EB21B2E08200652B19 /* ValueObservationCompactMapTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationCompactMapTests.swift; sourceTree = ""; }; - 564CE4F021B2E08A00652B19 /* ValueObservationMapTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationMapTests.swift; sourceTree = ""; }; - 564CE51A21B3128400652B19 /* ValueObservation+MapReducer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ValueObservation+MapReducer.swift"; sourceTree = ""; }; - 564CE5A421B7A9D600652B19 /* ValueObservation+DistinctUntilChanged.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ValueObservation+DistinctUntilChanged.swift"; sourceTree = ""; }; - 564CE5B921B8FBFD00652B19 /* DatabaseRegionObservation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegionObservation.swift; sourceTree = ""; }; - 564CE5C021B8FFD800652B19 /* DatabaseRegionObservationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegionObservationTests.swift; sourceTree = ""; }; - 564E73EB203DA29B000C443C /* JoinSupportTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JoinSupportTests.swift; sourceTree = ""; }; - 564F9C1D1F069B4E00877A00 /* DatabaseAggregateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseAggregateTests.swift; sourceTree = ""; }; - 564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseFunction.swift; sourceTree = ""; }; - 5653EB8520961FBF00F46237 /* BelongsToAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BelongsToAssociation.swift; sourceTree = ""; }; - 5653EB8620961FBF00F46237 /* HasOneAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HasOneAssociation.swift; sourceTree = ""; }; - 5653EB8820961FBF00F46237 /* HasManyAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HasManyAssociation.swift; sourceTree = ""; }; - 5653EB8920961FBF00F46237 /* ForeignKey.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForeignKey.swift; sourceTree = ""; }; - 5653EB8A20961FBF00F46237 /* ForeignKeyRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForeignKeyRequest.swift; sourceTree = ""; }; - 5653EB8C20961FBF00F46237 /* Association.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Association.swift; sourceTree = ""; }; - 5653EBA120961FCA00F46237 /* QueryInterfaceRequest+Association.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "QueryInterfaceRequest+Association.swift"; sourceTree = ""; }; - 5653EBA620961FE600F46237 /* AssociationParallelSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelSQLTests.swift; sourceTree = ""; }; - 5653EBA720961FE600F46237 /* AssociationBelongsToFetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToFetchableRecordTests.swift; sourceTree = ""; }; - 5653EBA820961FE600F46237 /* AssociationParallelDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelDecodableRecordTests.swift; sourceTree = ""; }; - 5653EBA920961FE700F46237 /* AssociationBelongsToSQLDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToSQLDerivationTests.swift; sourceTree = ""; }; - 5653EBAA20961FE700F46237 /* AssociationTableAliasTestsSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationTableAliasTestsSQLTests.swift; sourceTree = ""; }; - 5653EBAB20961FE700F46237 /* AssociationHasOneSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneSQLTests.swift; sourceTree = ""; }; - 5653EBAC20961FE700F46237 /* AssociationRowScopeSearchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationRowScopeSearchTests.swift; sourceTree = ""; }; - 5653EBAD20961FE700F46237 /* AssociationHasOneSQLDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneSQLDerivationTests.swift; sourceTree = ""; }; - 5653EBAE20961FE700F46237 /* AssociationChainRowScopesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationChainRowScopesTests.swift; sourceTree = ""; }; - 5653EBAF20961FE700F46237 /* AssociationParallelRowScopesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelRowScopesTests.swift; sourceTree = ""; }; - 5653EBB020961FE700F46237 /* AssociationBelongsToSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToSQLTests.swift; sourceTree = ""; }; - 5653EBB120961FE800F46237 /* AssociationChainSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationChainSQLTests.swift; sourceTree = ""; }; - 5653EBB220961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToDecodableRecordTests.swift; sourceTree = ""; }; - 5653EBB320961FE800F46237 /* AssociationBelongsToRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToRowScopeTests.swift; sourceTree = ""; }; - 5653EC15209873A400F46237 /* SQLExpression+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SQLExpression+QueryInterface.swift"; sourceTree = ""; }; - 5653EC19209873E600F46237 /* SQLGenerationContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLGenerationContext.swift; sourceTree = ""; }; - 5657AAB81D107001006283EF /* NSData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSData.swift; sourceTree = ""; }; - 5657AB0E1D10899D006283EF /* URL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URL.swift; sourceTree = ""; }; - 5657AB2F1D108BA9006283EF /* FoundationDataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationDataTests.swift; sourceTree = ""; }; - 5657AB301D108BA9006283EF /* FoundationNSDataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSDataTests.swift; sourceTree = ""; }; - 5657AB311D108BA9006283EF /* FoundationNSNullTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSNullTests.swift; sourceTree = ""; }; - 5657AB321D108BA9006283EF /* FoundationNSNumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSNumberTests.swift; sourceTree = ""; }; - 5657AB331D108BA9006283EF /* FoundationNSStringTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSStringTests.swift; sourceTree = ""; }; - 5657AB341D108BA9006283EF /* FoundationNSURLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSURLTests.swift; sourceTree = ""; }; - 5657AB351D108BA9006283EF /* FoundationURLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationURLTests.swift; sourceTree = ""; }; - 5659F4871EA8D94E004A4992 /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; - 5659F48F1EA8D964004A4992 /* ReadWriteBox.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReadWriteBox.swift; sourceTree = ""; }; - 5659F4971EA8D989004A4992 /* Pool.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Pool.swift; sourceTree = ""; }; - 5659F49F1EA8D997004A4992 /* Result.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Result.swift; sourceTree = ""; }; - 565B0FEE1BBC7D980098DE03 /* FetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchableRecordTests.swift; sourceTree = ""; }; - 565D5D701BBC694D00DC9BD4 /* Row+FoundationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Row+FoundationTests.swift"; sourceTree = ""; }; - 565D5D731BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StatementArguments+FoundationTests.swift"; sourceTree = ""; }; - 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumericOverflowTests.swift; sourceTree = ""; }; - 565F03C11CE5D3AA00DE108F /* RowAdapterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowAdapterTests.swift; sourceTree = ""; }; - 566475991D97D8A000FF74B8 /* SQLCollection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLCollection.swift; sourceTree = ""; }; - 566475A11D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SQLSelectable+QueryInterface.swift"; sourceTree = ""; }; - 566475B91D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SQLSpecificExpressible+QueryInterface.swift"; sourceTree = ""; }; - 566475CA1D981D5E00FF74B8 /* SQLFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLFunctions.swift; sourceTree = ""; }; - 566475CB1D981D5E00FF74B8 /* SQLOperators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLOperators.swift; sourceTree = ""; }; - 5665F86A203EF47C0084C6C0 /* ColumnInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColumnInfoTests.swift; sourceTree = ""; }; - 5665FA202129D81F004D8612 /* DatabaseDateDecodingStrategyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseDateDecodingStrategyTests.swift; sourceTree = ""; }; - 5665FA3F2129EEEF004D8612 /* DatabaseDateEncodingStrategyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseDateEncodingStrategyTests.swift; sourceTree = ""; }; - 566A842720413D6E00E50BFD /* DatabaseSnapshot.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseSnapshot.swift; sourceTree = ""; }; - 566A842F20413DCF00E50BFD /* DatabaseSnapshotTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseSnapshotTests.swift; sourceTree = ""; }; - 566A84452041AB3900E50BFD /* MutablePersistableRecordChangesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordChangesTests.swift; sourceTree = ""; }; - 566AD8B11D5318F4002EC1A8 /* TableDefinition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableDefinition.swift; sourceTree = ""; }; - 566AD8C51D531BE4002EC1A8 /* TableDefinitionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableDefinitionTests.swift; sourceTree = ""; }; - 566B91081FA4C3960012D5B0 /* Database+Statements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Database+Statements.swift"; sourceTree = ""; }; - 566B91121FA4C3F50012D5B0 /* DatabaseCollation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseCollation.swift; sourceTree = ""; }; - 566B91221FA4CF810012D5B0 /* Database+Schema.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Database+Schema.swift"; sourceTree = ""; }; - 566B912A1FA4D0CC0012D5B0 /* StatementAuthorizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatementAuthorizer.swift; sourceTree = ""; }; - 566B91321FA4D3810012D5B0 /* TransactionObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionObserver.swift; sourceTree = ""; }; - 5670329D212B546D007D270F /* DatabaseUUIDEncodingStrategyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseUUIDEncodingStrategyTests.swift; sourceTree = ""; }; - 567071F6208A00D4006AD95A /* SQLiteDateParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLiteDateParser.swift; sourceTree = ""; }; - 567156151CB142AA007DC145 /* DatabaseQueueReadOnlyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueReadOnlyTests.swift; sourceTree = ""; }; - 5671566C1CB16729007DC145 /* GRDBCipherOSXEncryptedTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBCipherOSXEncryptedTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 567156701CB18050007DC145 /* EncryptionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EncryptionTests.swift; sourceTree = ""; }; - 5671FC1F1DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3TokenizerDescriptor.swift; sourceTree = ""; }; - 5672DE581CDB72520022BA81 /* DatabaseQueueBackupTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueBackupTests.swift; sourceTree = ""; }; - 5672DE661CDB751D0022BA81 /* DatabasePoolBackupTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolBackupTests.swift; sourceTree = ""; }; - 567404871CEF84C8003ED5CC /* RowAdapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowAdapter.swift; sourceTree = ""; }; - 56741EA71E66A8B3003E422D /* FetchRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchRequestTests.swift; sourceTree = ""; }; - 5674A6E21F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DatabaseValueConvertible+Encodable.swift"; sourceTree = ""; }; - 5674A6E31F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DatabaseValueConvertible+Decodable.swift"; sourceTree = ""; }; - 5674A6F21F307F600095F066 /* FetchableRecord+Decodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FetchableRecord+Decodable.swift"; sourceTree = ""; }; - 5674A6F31F307F600095F066 /* PersistableRecord+Encodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PersistableRecord+Encodable.swift"; sourceTree = ""; }; - 5674A7021F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DatabaseValueConvertible+ReferenceConvertible.swift"; sourceTree = ""; }; - 5674A70A1F3087700095F066 /* DatabaseValueConvertibleDecodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleDecodableTests.swift; sourceTree = ""; }; - 5674A70B1F3087700095F066 /* DatabaseValueConvertibleEncodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleEncodableTests.swift; sourceTree = ""; }; - 5674A71C1F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordEncodableTests.swift; sourceTree = ""; }; - 5674A7261F30A9090095F066 /* FetchableRecordDecodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchableRecordDecodableTests.swift; sourceTree = ""; }; - 567A80521D41350C00C7DCEC /* IndexInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IndexInfoTests.swift; sourceTree = ""; }; - 567DAF141EAB61ED00FC0928 /* grdb_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = grdb_config.h; sourceTree = ""; }; - 567DAF341EAB789800FC0928 /* DatabaseLogErrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseLogErrorTests.swift; sourceTree = ""; }; - 567F45A71F888B2600030B59 /* TruncateOptimizationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TruncateOptimizationTests.swift; sourceTree = ""; }; - 568068301EBBA26100EFB8AA /* SQLRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLRequestTests.swift; sourceTree = ""; }; - 5687359E1CEDE16C009B9116 /* Betty.jpeg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Betty.jpeg; sourceTree = ""; }; - 56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Fixits-1.2.swift"; sourceTree = ""; }; - 568BE5191CB035A900270F93 /* sqlite3.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sqlite3.h; path = SQLCipher/src/sqlite3.h; sourceTree = ""; }; - 568BE51F1CB0360500270F93 /* GRDBCipher.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = GRDBCipher.xcconfig; path = SQLCipher/GRDBCipher.xcconfig; sourceTree = ""; }; - 568BE5201CB0360500270F93 /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; name = module.modulemap; path = SQLCipher/module.modulemap; sourceTree = ""; }; - 568D13222207214D00674B58 /* SQLSelectQueryGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLSelectQueryGenerator.swift; sourceTree = ""; }; - 568E1CB71CB03847008D97A6 /* GRDBCipher-Bridging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "GRDBCipher-Bridging.h"; path = "SQLCipher/GRDBCipher-Bridging.h"; sourceTree = ""; }; - 568E1CB81CB03847008D97A6 /* GRDBCipher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GRDBCipher.h; path = SQLCipher/GRDBCipher.h; sourceTree = ""; }; - 5690C3251D23E6D800E59934 /* FoundationDateComponentsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationDateComponentsTests.swift; sourceTree = ""; }; - 5690C3361D23E7D200E59934 /* FoundationDateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationDateTests.swift; sourceTree = ""; }; - 5690C33F1D23E82A00E59934 /* Data.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; - 569178451CED9B6000E179EA /* DatabaseQueueTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueTests.swift; sourceTree = ""; }; - 5695311E1C907A8C00CF1A2B /* DatabaseSchemaCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseSchemaCache.swift; sourceTree = ""; }; - 569531231C90878D00CF1A2B /* DatabaseQueueSchemaCacheTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueSchemaCacheTests.swift; sourceTree = ""; }; - 569531281C908A5B00CF1A2B /* DatabasePoolSchemaCacheTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolSchemaCacheTests.swift; sourceTree = ""; }; - 569531331C919DF200CF1A2B /* DatabasePoolCollationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolCollationTests.swift; sourceTree = ""; }; - 569531361C919DF700CF1A2B /* DatabasePoolFunctionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolFunctionTests.swift; sourceTree = ""; }; - 5698AC021D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceExtensibilityTests.swift; sourceTree = ""; }; - 5698AC361D9E5A590056AF8C /* FTS3Pattern.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3Pattern.swift; sourceTree = ""; }; - 5698AC3F1DA2BED90056AF8C /* FTS3PatternTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3PatternTests.swift; sourceTree = ""; }; - 5698AC481DA2D48A0056AF8C /* FTS3RecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3RecordTests.swift; sourceTree = ""; }; - 5698AC771DA37DCB0056AF8C /* VirtualTableModule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VirtualTableModule.swift; sourceTree = ""; }; - 5698AC7F1DA380A20056AF8C /* VirtualTableModuleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VirtualTableModuleTests.swift; sourceTree = ""; }; - 5698AC881DA389380056AF8C /* FTS3TableBuilderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3TableBuilderTests.swift; sourceTree = ""; }; - 5698AC941DA4B0430056AF8C /* FTS4RecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS4RecordTests.swift; sourceTree = ""; }; - 5698AC951DA4B0430056AF8C /* FTS4TableBuilderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS4TableBuilderTests.swift; sourceTree = ""; }; - 5698ACB51DA6285E0056AF8C /* FTS3TokenizerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3TokenizerTests.swift; sourceTree = ""; }; - 5698ACCA1DA62A2D0056AF8C /* FTS5TokenizerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5TokenizerTests.swift; sourceTree = ""; }; - 5698ACCD1DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPrimaryKeyHiddenRowIDTests.swift; sourceTree = ""; }; - 5698ACD61DA925420056AF8C /* RowTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowTestCase.swift; sourceTree = ""; }; - 5698AD001DAA8ACA0056AF8C /* FTS5CustomTokenizerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5CustomTokenizerTests.swift; sourceTree = ""; }; - 5698AD151DAAD16F0056AF8C /* FTS5Tokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5Tokenizer.swift; sourceTree = ""; }; - 5698AD201DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5WrapperTokenizer.swift; sourceTree = ""; }; - 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5CustomTokenizer.swift; sourceTree = ""; }; - 569A98FA2039B72C008D7DBF /* Fixits-3.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-3.0.swift"; sourceTree = ""; }; - 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SchedulingWatchdogTests.swift; sourceTree = ""; }; - 569EF0E8200D387000A9FA45 /* DatabaseRegion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegion.swift; sourceTree = ""; }; - 56A238131B9C74A90082EB20 /* DatabaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseTests.swift; sourceTree = ""; }; - 56A238141B9C74A90082EB20 /* DatabaseQueueInMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueInMemoryTests.swift; sourceTree = ""; }; - 56A238161B9C74A90082EB20 /* DatabaseErrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseErrorTests.swift; sourceTree = ""; }; - 56A238181B9C74A90082EB20 /* DatabaseValueTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueTests.swift; sourceTree = ""; }; - 56A2381A1B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleSubclassTests.swift; sourceTree = ""; }; - 56A2381B1B9C74A90082EB20 /* DatabaseValueConversionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConversionTests.swift; sourceTree = ""; }; - 56A2381C1B9C74A90082EB20 /* RawRepresentable+DatabaseValueConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "RawRepresentable+DatabaseValueConvertibleTests.swift"; sourceTree = ""; }; - 56A2381E1B9C74A90082EB20 /* RowFromDictionaryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFromDictionaryTests.swift; sourceTree = ""; }; - 56A2381F1B9C74A90082EB20 /* RowCopiedFromStatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowCopiedFromStatementTests.swift; sourceTree = ""; }; - 56A238211B9C74A90082EB20 /* SelectStatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectStatementTests.swift; sourceTree = ""; }; - 56A238221B9C74A90082EB20 /* UpdateStatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateStatementTests.swift; sourceTree = ""; }; - 56A238241B9C74A90082EB20 /* DatabaseMigratorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseMigratorTests.swift; sourceTree = ""; }; - 56A238261B9C74A90082EB20 /* RecordMinimalPrimaryKeyRowIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordMinimalPrimaryKeyRowIDTests.swift; sourceTree = ""; }; - 56A238271B9C74A90082EB20 /* RecordMinimalPrimaryKeySingleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordMinimalPrimaryKeySingleTests.swift; sourceTree = ""; }; - 56A238281B9C74A90082EB20 /* RecordPrimaryKeyMultipleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPrimaryKeyMultipleTests.swift; sourceTree = ""; }; - 56A238291B9C74A90082EB20 /* RecordPrimaryKeyNoneTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPrimaryKeyNoneTests.swift; sourceTree = ""; }; - 56A2382A1B9C74A90082EB20 /* RecordPrimaryKeyRowIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPrimaryKeyRowIDTests.swift; sourceTree = ""; }; - 56A2382B1B9C74A90082EB20 /* RecordPrimaryKeySingleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPrimaryKeySingleTests.swift; sourceTree = ""; }; - 56A2382C1B9C74A90082EB20 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift; sourceTree = ""; }; - 56A2382D1B9C74A90082EB20 /* RecordCopyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordCopyTests.swift; sourceTree = ""; }; - 56A2382F1B9C74A90082EB20 /* RecordEditedTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordEditedTests.swift; sourceTree = ""; }; - 56A238321B9C74A90082EB20 /* RecordInitializersTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordInitializersTests.swift; sourceTree = ""; }; - 56A238331B9C74A90082EB20 /* RecordSubClassTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordSubClassTests.swift; sourceTree = ""; }; - 56A238701B9C75030082EB20 /* Configuration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = ""; }; - 56A238711B9C75030082EB20 /* Database.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Database.swift; sourceTree = ""; }; - 56A238731B9C75030082EB20 /* DatabaseError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseError.swift; sourceTree = ""; }; - 56A238741B9C75030082EB20 /* DatabaseQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueue.swift; sourceTree = ""; }; - 56A238751B9C75030082EB20 /* DatabaseValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValue.swift; sourceTree = ""; }; - 56A238761B9C75030082EB20 /* Row.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Row.swift; sourceTree = ""; }; - 56A238781B9C75030082EB20 /* Statement.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Statement.swift; sourceTree = ""; }; - 56A238921B9C750B0082EB20 /* DatabaseMigrator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseMigrator.swift; sourceTree = ""; }; - 56A238A11B9C753B0082EB20 /* Record.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Record.swift; sourceTree = ""; }; - 56A238B51B9CA2590082EB20 /* DatabaseTimestampTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseTimestampTests.swift; sourceTree = ""; }; - 56A4CDAF1D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLExpressionLiteralTests.swift; sourceTree = ""; }; - 56A5E4081BA2BCF900707640 /* RecordWithColumnNameManglingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordWithColumnNameManglingTests.swift; sourceTree = ""; }; - 56A5EF0E1EF7F20B00F03071 /* ForeignKeyInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForeignKeyInfoTests.swift; sourceTree = ""; }; - 56A8C21E1D1914110096E9D4 /* FoundationUUIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationUUIDTests.swift; sourceTree = ""; }; - 56A8C22F1D1914540096E9D4 /* UUID.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UUID.swift; sourceTree = ""; }; - 56A8C2361D1914790096E9D4 /* FoundationNSUUIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSUUIDTests.swift; sourceTree = ""; }; - 56AF746A1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleEscapingTests.swift; sourceTree = ""; }; - 56AFCA231CB1A8BB00F48B96 /* GRDBCipher.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = GRDBCipher.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 56AFCA7F1CB1AA9900F48B96 /* GRDBCipheriOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBCipheriOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 56AFCAD71CB1ABC800F48B96 /* GRDBCipheriOSEncryptedTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBCipheriOSEncryptedTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordPersistenceConflictPolicyTests.swift; sourceTree = ""; }; - 56B14E7E1D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFromDictionaryLiteralTests.swift; sourceTree = ""; }; - 56B15D0A1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedRecordsControllerTests.swift; sourceTree = ""; }; - 56B6EF62208CB762002F0ACB /* ColumnExpressionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColumnExpressionTests.swift; sourceTree = ""; }; - 56B7F4291BE14A1900E39BBF /* CGFloatTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGFloatTests.swift; sourceTree = ""; }; - 56B7F4391BEB42D500E39BBF /* Migration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Migration.swift; sourceTree = ""; }; - 56B8F49A1B4E2F3600C24296 /* GRDB.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = GRDB.xcconfig; sourceTree = ""; }; - 56B9649C1DA51B4C0002DA19 /* FTS5.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5.swift; sourceTree = ""; }; - 56B964B01DA51D010002DA19 /* FTS5TokenizerDescriptor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5TokenizerDescriptor.swift; sourceTree = ""; }; - 56B964B81DA51D0A0002DA19 /* FTS5Pattern.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5Pattern.swift; sourceTree = ""; }; - 56B964C01DA521450002DA19 /* FTS5PatternTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5PatternTests.swift; sourceTree = ""; }; - 56B964C11DA521450002DA19 /* FTS5RecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5RecordTests.swift; sourceTree = ""; }; - 56B964C21DA521450002DA19 /* FTS5TableBuilderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5TableBuilderTests.swift; sourceTree = ""; }; - 56BB6EA81D3009B100A1CA52 /* SchedulingWatchdog.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SchedulingWatchdog.swift; sourceTree = ""; }; - 56BF6D2C1DEF47DA006039A3 /* Fixits-0-84-0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0-84-0.swift"; sourceTree = ""; }; - 56BF6D2D1DEF47DA006039A3 /* Fixits-0-90-1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0-90-1.swift"; sourceTree = ""; }; - 56BF6D2E1DEF47DA006039A3 /* Fixits-Swift2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-Swift2.swift"; sourceTree = ""; }; - 56C3F7521CF9F12400F6A361 /* DatabaseSavepointTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseSavepointTests.swift; sourceTree = ""; }; - 56C48E731C9A9923005DF1D9 /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = ""; }; - 56C494401ED7255500CC72AF /* GRDBDeploymentTarget.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = GRDBDeploymentTarget.xcconfig; sourceTree = ""; }; - 56C494411ED7269800CC72AF /* GRDBDeploymentTarget.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = GRDBDeploymentTarget.xcconfig; path = SQLCipher/GRDBDeploymentTarget.xcconfig; sourceTree = ""; }; - 56CC922E201DFFE200CB597E /* DropWhileCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropWhileCursorTests.swift; sourceTree = ""; }; - 56CC923D201E034200CB597E /* PrefixWhileCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrefixWhileCursorTests.swift; sourceTree = ""; }; - 56CC924B201E059100CB597E /* DropFirstCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropFirstCursorTests.swift; sourceTree = ""; }; - 56CC9256201E094E00CB597E /* PrefixCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrefixCursorTests.swift; sourceTree = ""; }; - 56CEB4F01EAA2EFA00BFAF62 /* FetchableRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchableRecord.swift; sourceTree = ""; }; - 56CEB4F81EAA2F4D00BFAF62 /* FTS3.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3.swift; sourceTree = ""; }; - 56CEB4F91EAA2F4D00BFAF62 /* FTS4.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS4.swift; sourceTree = ""; }; - 56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FTS3+QueryInterfaceRequest.swift"; sourceTree = ""; }; - 56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FTS5+QueryInterface.swift"; sourceTree = ""; }; - 56CEB5401EAA359A00BFAF62 /* Column.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Column.swift; sourceTree = ""; }; - 56CEB5411EAA359A00BFAF62 /* SQLExpressible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLExpressible.swift; sourceTree = ""; }; - 56CEB5421EAA359A00BFAF62 /* SQLExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLExpression.swift; sourceTree = ""; }; - 56CEB5431EAA359A00BFAF62 /* SQLOrdering.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLOrdering.swift; sourceTree = ""; }; - 56CEB5441EAA359A00BFAF62 /* SQLSelectable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLSelectable.swift; sourceTree = ""; }; - 56D121591ED34978001347D2 /* Fixits-0.109.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0.109.0.swift"; sourceTree = ""; }; - 56D5075D1F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrimaryKeyInfoTests.swift; sourceTree = ""; }; - 56D51CFF1EA789FA0074638A /* FetchableRecord+TableRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FetchableRecord+TableRecord.swift"; sourceTree = ""; }; - 56D91A9B2205DD5200770D8D /* SQLRelation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLRelation.swift; sourceTree = ""; }; - 56D91AAC2205F30200770D8D /* DatabasePromise.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePromise.swift; sourceTree = ""; }; - 56D91AB32205F8C000770D8D /* SQLSelectQuery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLSelectQuery.swift; sourceTree = ""; }; - 56DAA2D11DE99DAB006E10C8 /* DatabaseCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseCursorTests.swift; sourceTree = ""; }; - 56DAA2DA1DE9C827006E10C8 /* Cursor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cursor.swift; sourceTree = ""; }; - 56DE7B101C3D93ED00861EB8 /* StatementArgumentsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementArgumentsTests.swift; sourceTree = ""; }; - 56E06F051E859064008AE2A4 /* Fixits-0.102.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0.102.0.swift"; sourceTree = ""; }; - 56E8CE0C1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleFetchTests.swift; sourceTree = ""; }; - 56E8CE0F1BB4FE5B00828BEC /* StatementColumnConvertibleFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementColumnConvertibleFetchTests.swift; sourceTree = ""; }; - 56EA63CB209C7F31009715B8 /* DerivableRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DerivableRequestTests.swift; sourceTree = ""; }; - 56EA86931C91DFE7002BB4DF /* DatabaseReaderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseReaderTests.swift; sourceTree = ""; }; - 56EA869D1C932597002BB4DF /* DatabasePoolReadOnlyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolReadOnlyTests.swift; sourceTree = ""; }; - 56EB0AB11BCD787300A3DC55 /* DataMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataMemoryTests.swift; sourceTree = ""; }; - 56ED8A7E1DAB8D6800BD0ABC /* FTS5WrapperTokenizerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5WrapperTokenizerTests.swift; sourceTree = ""; }; - 56F0B98E1B6001C600A2F135 /* FoundationNSDateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSDateTests.swift; sourceTree = ""; }; - 56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResultCodeTests.swift; sourceTree = ""; }; - 56F3E7621E67F8C100BF0F01 /* Fixits-0.101.1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0.101.1.swift"; sourceTree = ""; }; - 56FDECE11BB32DFD009AD709 /* RowFromStatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFromStatementTests.swift; sourceTree = ""; }; - 56FEE7FA1F47253700D930EA /* TableRecordTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableRecordTests.swift; sourceTree = ""; }; - 56FF453F1D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordDeleteTests.swift; sourceTree = ""; }; - 56FF45551D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordUniqueIndexTests.swift; sourceTree = ""; }; - 6340BF7F1E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPersistenceConflictPolicy.swift; sourceTree = ""; }; - DC2393C61ABE35F8003FF113 /* GRDB-Bridging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GRDB-Bridging.h"; sourceTree = ""; }; - DC3773F719C8CBB3004FCF85 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - DC3773F819C8CBB3004FCF85 /* GRDB.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GRDB.h; sourceTree = ""; }; - DC37740419C8CBB3004FCF85 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 560FC5441CB003810014AA8E /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 56AFC97A1CB1A41E00F48B96 /* libsqlcipher.a in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 560FC5A91CB00B880014AA8E /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 568BE5231CB0371D00270F93 /* GRDBCipher.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 567156661CB16729007DC145 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 567156671CB16729007DC145 /* GRDBCipher.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 56AFCA1A1CB1A8BB00F48B96 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 56AFCA271CB1A97600F48B96 /* libsqlcipher.a in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 56AFCA781CB1AA9900F48B96 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 56AFCA831CB1AAC900F48B96 /* GRDBCipher.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 56AFCAD11CB1ABC800F48B96 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 56AFCAD21CB1ABC800F48B96 /* GRDBCipher.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 5605F1471C672E4000235C62 /* Support */ = { - isa = PBXGroup; - children = ( - 5605F1481C672E4000235C62 /* CoreGraphics */, - 5605F14A1C672E4000235C62 /* Foundation */, - 5605F1561C672E4000235C62 /* StandardLibrary */, - ); - path = Support; - sourceTree = ""; - }; - 5605F1481C672E4000235C62 /* CoreGraphics */ = { - isa = PBXGroup; - children = ( - 5605F1491C672E4000235C62 /* CGFloat.swift */, - ); - path = CoreGraphics; - sourceTree = ""; - }; - 5605F14A1C672E4000235C62 /* Foundation */ = { - isa = PBXGroup; - children = ( - 5690C33F1D23E82A00E59934 /* Data.swift */, - 5605F14C1C672E4000235C62 /* DatabaseDateComponents.swift */, - 5674A7021F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift */, - 5605F14F1C672E4000235C62 /* Date.swift */, - 5657AAB81D107001006283EF /* NSData.swift */, - 5605F1501C672E4000235C62 /* NSNull.swift */, - 5605F1511C672E4000235C62 /* NSNumber.swift */, - 5605F1521C672E4000235C62 /* NSString.swift */, - 5657AB0E1D10899D006283EF /* URL.swift */, - 56A8C22F1D1914540096E9D4 /* UUID.swift */, - 567071F6208A00D4006AD95A /* SQLiteDateParser.swift */, - ); - path = Foundation; - sourceTree = ""; - }; - 5605F1561C672E4000235C62 /* StandardLibrary */ = { - isa = PBXGroup; - children = ( - 5674A6E31F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift */, - 5674A6E21F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift */, - 5605F1571C672E4000235C62 /* DatabaseValueConvertible+RawRepresentable.swift */, - 5605F1581C672E4000235C62 /* StandardLibrary.swift */, - ); - path = StandardLibrary; - sourceTree = ""; - }; - 5607EFD11BB8253300605DE3 /* TransactionObserver */ = { - isa = PBXGroup; - children = ( - 5634B1061CF9B970005360B9 /* TransactionObserverSavepointsTests.swift */, - 5607EFD21BB8254800605DE3 /* TransactionObserverTests.swift */, - 567F45A71F888B2600030B59 /* TruncateOptimizationTests.swift */, - ); - name = TransactionObserver; - sourceTree = ""; - }; - 560A37A91C90084600949E71 /* DatabasePool */ = { - isa = PBXGroup; - children = ( - 5672DE661CDB751D0022BA81 /* DatabasePoolBackupTests.swift */, - 569531331C919DF200CF1A2B /* DatabasePoolCollationTests.swift */, - 560A37AA1C90085D00949E71 /* DatabasePoolConcurrencyTests.swift */, - 569531361C919DF700CF1A2B /* DatabasePoolFunctionTests.swift */, - 56EA869D1C932597002BB4DF /* DatabasePoolReadOnlyTests.swift */, - ); - name = DatabasePool; - sourceTree = ""; - }; - 560B3FA41C19DFF800C58EC7 /* PersistableRecord */ = { - isa = PBXGroup; - children = ( - 5665FA3F2129EEEF004D8612 /* DatabaseDateEncodingStrategyTests.swift */, - 5670329D212B546D007D270F /* DatabaseUUIDEncodingStrategyTests.swift */, - 566A84452041AB3900E50BFD /* MutablePersistableRecordChangesTests.swift */, - 56FF453F1D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift */, - 5674A71C1F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift */, - 56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */, - 563363A91C933FF8000BE133 /* MutablePersistableRecordTests.swift */, - 563363AA1C933FF8000BE133 /* PersistableRecordTests.swift */, - ); - name = PersistableRecord; - sourceTree = ""; - }; - 560FC54F1CB0047D0014AA8E /* GRDBCipher */ = { - isa = PBXGroup; - children = ( - 568BE51F1CB0360500270F93 /* GRDBCipher.xcconfig */, - 56C494411ED7269800CC72AF /* GRDBDeploymentTarget.xcconfig */, - 568BE5201CB0360500270F93 /* module.modulemap */, - 568BE5191CB035A900270F93 /* sqlite3.h */, - 568E1CB81CB03847008D97A6 /* GRDBCipher.h */, - 568E1CB71CB03847008D97A6 /* GRDBCipher-Bridging.h */, - 560FC5501CB004AD0014AA8E /* sqlcipher.xcodeproj */, - ); - name = GRDBCipher; - sourceTree = ""; - }; - 560FC5511CB004AD0014AA8E /* Products */ = { - isa = PBXGroup; - children = ( - 560FC5561CB004AD0014AA8E /* libsqlcipher.a */, - ); - name = Products; - sourceTree = ""; - }; - 5613ED7221A95E8400DC7A68 /* ValueObservation */ = { - isa = PBXGroup; - children = ( - 5613ED7321A95E8400DC7A68 /* ValueObservation.swift */, - 5613ED7421A95E8400DC7A68 /* ValueObservation+Combine.swift */, - 564CE4DC21B2DEF700652B19 /* ValueObservation+CompactMap.swift */, - 5613ED7A21A95E8400DC7A68 /* ValueObservation+Count.swift */, - 5613ED7821A95E8400DC7A68 /* ValueObservation+DatabaseValueConvertible.swift */, - 564CE5A421B7A9D600652B19 /* ValueObservation+DistinctUntilChanged.swift */, - 5613ED7721A95E8400DC7A68 /* ValueObservation+FetchableRecord.swift */, - 5613ED7521A95E8400DC7A68 /* ValueObservation+Map.swift */, - 564CE51A21B3128400652B19 /* ValueObservation+MapReducer.swift */, - 5613ED7621A95E8400DC7A68 /* ValueObservation+Row.swift */, - 564CE43F21AA957000652B19 /* ValueObserver.swift */, - 5613ED7921A95E8400DC7A68 /* ValueReducer.swift */, - ); - path = ValueObservation; - sourceTree = ""; - }; - 56176C581EACC2D8000F3F2B /* GRDBTests */ = { - isa = PBXGroup; - children = ( - 5623E0901B4AFACC00B20B7F /* GRDBTestCase.swift */, - 562EA81E1F17B26F00FA528C /* Compilation */, - 56A238111B9C74A90082EB20 /* Core */, - 5698AC3E1DA2BEBB0056AF8C /* FTS */, - 56176CA01EACEE2A000F3F2B /* GRDBCipher */, - 56A238231B9C74A90082EB20 /* Migrations */, - 569978D31B539038005EBEED /* Private */, - 56300B5C1C53C38F005A543B /* QueryInterface */, - 56A238251B9C74A90082EB20 /* Record */, - 56176C9F1EACEE15000F3F2B /* Support */, - 563B06F52185E07C00B38F35 /* ValueObservation */, - ); - path = GRDBTests; - sourceTree = ""; - }; - 56176C9C1EACEA8C000F3F2B /* TableRecord */ = { - isa = PBXGroup; - children = ( - 56FEE7FA1F47253700D930EA /* TableRecordTests.swift */, - ); - name = TableRecord; - sourceTree = ""; - }; - 56176C9E1EACEDF9000F3F2B /* Record */ = { - isa = PBXGroup; - children = ( - 56A2382D1B9C74A90082EB20 /* RecordCopyTests.swift */, - 56A2382F1B9C74A90082EB20 /* RecordEditedTests.swift */, - 56A238321B9C74A90082EB20 /* RecordInitializersTests.swift */, - 56A238261B9C74A90082EB20 /* RecordMinimalPrimaryKeyRowIDTests.swift */, - 56A238271B9C74A90082EB20 /* RecordMinimalPrimaryKeySingleTests.swift */, - 6340BF7F1E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift */, - 5698ACCD1DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift */, - 56A238281B9C74A90082EB20 /* RecordPrimaryKeyMultipleTests.swift */, - 56A238291B9C74A90082EB20 /* RecordPrimaryKeyNoneTests.swift */, - 56A2382A1B9C74A90082EB20 /* RecordPrimaryKeyRowIDTests.swift */, - 56A2382B1B9C74A90082EB20 /* RecordPrimaryKeySingleTests.swift */, - 56A2382C1B9C74A90082EB20 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift */, - 56A238331B9C74A90082EB20 /* RecordSubClassTests.swift */, - 56A5E4081BA2BCF900707640 /* RecordWithColumnNameManglingTests.swift */, - ); - name = Record; - sourceTree = ""; - }; - 56176C9F1EACEE15000F3F2B /* Support */ = { - isa = PBXGroup; - children = ( - 56B7F4291BE14A1900E39BBF /* CGFloatTests.swift */, - 56F0B98C1B6001C600A2F135 /* Foundation */, - ); - name = Support; - sourceTree = ""; - }; - 56176CA01EACEE2A000F3F2B /* GRDBCipher */ = { - isa = PBXGroup; - children = ( - 567156701CB18050007DC145 /* EncryptionTests.swift */, - ); - name = GRDBCipher; - sourceTree = ""; - }; - 562EA81E1F17B26F00FA528C /* Compilation */ = { - isa = PBXGroup; - children = ( - 562EA82E1F17B9EB00FA528C /* CompilationSubClassTests.swift */, - 562EA8251F17B2AC00FA528C /* CompilationProtocolTests.swift */, - ); - name = Compilation; - sourceTree = ""; - }; - 56300B5C1C53C38F005A543B /* QueryInterface */ = { - isa = PBXGroup; - children = ( - 5653EBA420961FD300F46237 /* Association */, - 56B6EF62208CB762002F0ACB /* ColumnExpressionTests.swift */, - 56EA63CB209C7F31009715B8 /* DerivableRequestTests.swift */, - 56300B601C53C42C005A543B /* FetchableRecord+QueryInterfaceRequestTests.swift */, - 56300B671C53D25E005A543B /* QueryInterfaceExpressionsTests.swift */, - 5698AC021D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift */, - 563EF45821631E51007DAACD /* QueryInterfacePromiseTests.swift */, - 56300B5D1C53C38F005A543B /* QueryInterfaceRequestTests.swift */, - 56300B841C54DC95005A543B /* Record+QueryInterfaceRequestTests.swift */, - 566AD8C51D531BE4002EC1A8 /* TableDefinitionTests.swift */, - 56300B6A1C53D3E8005A543B /* TableRecord+QueryInterfaceRequestTests.swift */, - 5698AC7F1DA380A20056AF8C /* VirtualTableModuleTests.swift */, - ); - name = QueryInterface; - sourceTree = ""; - }; - 56300B6D1C53F592005A543B /* QueryInterface */ = { - isa = PBXGroup; - children = ( - 5653EB8420961FBF00F46237 /* Association */, - 56CEB5401EAA359A00BFAF62 /* Column.swift */, - 56D91AAC2205F30200770D8D /* DatabasePromise.swift */, - 56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */, - 56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */, - 56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */, - 5653EBA120961FCA00F46237 /* QueryInterfaceRequest+Association.swift */, - 5616AAF8207CD5A900AC3664 /* RequestProtocols.swift */, - 5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */, - 566475991D97D8A000FF74B8 /* SQLCollection.swift */, - 56CEB5411EAA359A00BFAF62 /* SQLExpressible.swift */, - 56CEB5421EAA359A00BFAF62 /* SQLExpression.swift */, - 5653EC15209873A400F46237 /* SQLExpression+QueryInterface.swift */, - 5653EC19209873E600F46237 /* SQLGenerationContext.swift */, - 56CEB5431EAA359A00BFAF62 /* SQLOrdering.swift */, - 56D91A9B2205DD5200770D8D /* SQLRelation.swift */, - 56CEB5441EAA359A00BFAF62 /* SQLSelectable.swift */, - 566475A11D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift */, - 56D91AB32205F8C000770D8D /* SQLSelectQuery.swift */, - 568D13222207214D00674B58 /* SQLSelectQueryGenerator.swift */, - 566475B91D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift */, - 566475C91D981D5E00FF74B8 /* Support */, - 566AD8B11D5318F4002EC1A8 /* TableDefinition.swift */, - 5698AC771DA37DCB0056AF8C /* VirtualTableModule.swift */, - ); - path = QueryInterface; - sourceTree = ""; - }; - 563363BB1C93FD32000BE133 /* DatabaseQueue */ = { - isa = PBXGroup; - children = ( - 5687359E1CEDE16C009B9116 /* Betty.jpeg */, - 5672DE581CDB72520022BA81 /* DatabaseQueueBackupTests.swift */, - 563363BC1C93FD5E000BE133 /* DatabaseQueueConcurrencyTests.swift */, - 56A238141B9C74A90082EB20 /* DatabaseQueueInMemoryTests.swift */, - 567156151CB142AA007DC145 /* DatabaseQueueReadOnlyTests.swift */, - 569178451CED9B6000E179EA /* DatabaseQueueTests.swift */, - ); - name = DatabaseQueue; - sourceTree = ""; - }; - 563B06F52185E07C00B38F35 /* ValueObservation */ = { - isa = PBXGroup; - children = ( - 5613ED9D21A96A6F00DC7A68 /* ValueObservationCombineTests.swift */, - 564CE4EB21B2E08200652B19 /* ValueObservationCompactMapTests.swift */, - 563B06F921861D8B00B38F35 /* ValueObservationCountTests.swift */, - 563B071D21862F5D00B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift */, - 563B06DC2185E07100B38F35 /* ValueObservationExtentTests.swift */, - 563B06DE2185E07200B38F35 /* ValueObservationFetchTests.swift */, - 564CE4F021B2E08A00652B19 /* ValueObservationMapTests.swift */, - 563B06DD2185E07200B38F35 /* ValueObservationReadonlyTests.swift */, - 563B070C21862C3500B38F35 /* ValueObservationRecordTests.swift */, - 563B06DF2185E07200B38F35 /* ValueObservationReducerTests.swift */, - 563B07072186280500B38F35 /* ValueObservationRowTests.swift */, - 563B06E02185E07200B38F35 /* ValueObservationSchedulingTests.swift */, - ); - name = ValueObservation; - sourceTree = ""; - }; - 5653EB8420961FBF00F46237 /* Association */ = { - isa = PBXGroup; - children = ( - 5653EB8C20961FBF00F46237 /* Association.swift */, - 563EF43A2161183E007DAACD /* AssociationAggregate.swift */, - 5653EB8520961FBF00F46237 /* BelongsToAssociation.swift */, - 5653EB8920961FBF00F46237 /* ForeignKey.swift */, - 5653EB8A20961FBF00F46237 /* ForeignKeyRequest.swift */, - 5653EB8820961FBF00F46237 /* HasManyAssociation.swift */, - 5653EB8620961FBF00F46237 /* HasOneAssociation.swift */, - ); - path = Association; - sourceTree = ""; - }; - 5653EBA420961FD300F46237 /* Association */ = { - isa = PBXGroup; - children = ( - 563EF44421613212007DAACD /* AssociationAggregateTests.swift */, - 5653EBB220961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift */, - 5653EBA720961FE600F46237 /* AssociationBelongsToFetchableRecordTests.swift */, - 5653EBB320961FE800F46237 /* AssociationBelongsToRowScopeTests.swift */, - 5653EBA920961FE700F46237 /* AssociationBelongsToSQLDerivationTests.swift */, - 5653EBB020961FE700F46237 /* AssociationBelongsToSQLTests.swift */, - 5653EBAE20961FE700F46237 /* AssociationChainRowScopesTests.swift */, - 5653EBB120961FE800F46237 /* AssociationChainSQLTests.swift */, - 5653EBAD20961FE700F46237 /* AssociationHasOneSQLDerivationTests.swift */, - 5653EBAB20961FE700F46237 /* AssociationHasOneSQLTests.swift */, - 5653EBA820961FE600F46237 /* AssociationParallelDecodableRecordTests.swift */, - 5653EBAF20961FE700F46237 /* AssociationParallelRowScopesTests.swift */, - 5653EBA620961FE600F46237 /* AssociationParallelSQLTests.swift */, - 5653EBAC20961FE700F46237 /* AssociationRowScopeSearchTests.swift */, - 5653EBAA20961FE700F46237 /* AssociationTableAliasTestsSQLTests.swift */, - ); - name = Association; - sourceTree = ""; - }; - 5659F4861EA8D94E004A4992 /* Utils */ = { - isa = PBXGroup; - children = ( - 563EF44F2161F1A7007DAACD /* Inflections.swift */, - 563EF422215F8A88007DAACD /* OrderedDictionary.swift */, - 5659F4971EA8D989004A4992 /* Pool.swift */, - 5659F48F1EA8D964004A4992 /* ReadWriteBox.swift */, - 5659F49F1EA8D997004A4992 /* Result.swift */, - 5659F4871EA8D94E004A4992 /* Utils.swift */, - ); - path = Utils; - sourceTree = ""; - }; - 566475C91D981D5E00FF74B8 /* Support */ = { - isa = PBXGroup; - children = ( - 566475CA1D981D5E00FF74B8 /* SQLFunctions.swift */, - 566475CB1D981D5E00FF74B8 /* SQLOperators.swift */, - ); - path = Support; - sourceTree = ""; - }; - 5674A7251F30A8EF0095F066 /* FetchableRecord */ = { - isa = PBXGroup; - children = ( - 5665FA202129D81F004D8612 /* DatabaseDateDecodingStrategyTests.swift */, - 5674A7261F30A9090095F066 /* FetchableRecordDecodableTests.swift */, - 565B0FEE1BBC7D980098DE03 /* FetchableRecordTests.swift */, - ); - name = FetchableRecord; - sourceTree = ""; - }; - 5698AC291D9E5A480056AF8C /* FTS */ = { - isa = PBXGroup; - children = ( - 56CEB4F81EAA2F4D00BFAF62 /* FTS3.swift */, - 56CEB4F91EAA2F4D00BFAF62 /* FTS4.swift */, - 5698AC361D9E5A590056AF8C /* FTS3Pattern.swift */, - 5671FC1F1DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift */, - 56B9649C1DA51B4C0002DA19 /* FTS5.swift */, - 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */, - 56B964B81DA51D0A0002DA19 /* FTS5Pattern.swift */, - 5698AD151DAAD16F0056AF8C /* FTS5Tokenizer.swift */, - 56B964B01DA51D010002DA19 /* FTS5TokenizerDescriptor.swift */, - 5698AD201DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift */, - ); - path = FTS; - sourceTree = ""; - }; - 5698AC3E1DA2BEBB0056AF8C /* FTS */ = { - isa = PBXGroup; - children = ( - 5698AC3F1DA2BED90056AF8C /* FTS3PatternTests.swift */, - 5698AC481DA2D48A0056AF8C /* FTS3RecordTests.swift */, - 5698AC881DA389380056AF8C /* FTS3TableBuilderTests.swift */, - 5698ACB51DA6285E0056AF8C /* FTS3TokenizerTests.swift */, - 5698AC941DA4B0430056AF8C /* FTS4RecordTests.swift */, - 5698AC951DA4B0430056AF8C /* FTS4TableBuilderTests.swift */, - 5698AD001DAA8ACA0056AF8C /* FTS5CustomTokenizerTests.swift */, - 56B964C01DA521450002DA19 /* FTS5PatternTests.swift */, - 56B964C11DA521450002DA19 /* FTS5RecordTests.swift */, - 56B964C21DA521450002DA19 /* FTS5TableBuilderTests.swift */, - 5698ACCA1DA62A2D0056AF8C /* FTS5TokenizerTests.swift */, - 56ED8A7E1DAB8D6800BD0ABC /* FTS5WrapperTokenizerTests.swift */, - ); - name = FTS; - sourceTree = ""; - }; - 569978D31B539038005EBEED /* Private */ = { - isa = PBXGroup; - children = ( - 563363CF1C943D13000BE133 /* DatabasePoolReleaseMemoryTests.swift */, - 569531281C908A5B00CF1A2B /* DatabasePoolSchemaCacheTests.swift */, - 563363D41C94484E000BE133 /* DatabaseQueueReleaseMemoryTests.swift */, - 569531231C90878D00CF1A2B /* DatabaseQueueSchemaCacheTests.swift */, - 5605F1861C69111300235C62 /* DatabaseRegionTests.swift */, - 56AF746A1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift */, - 56EB0AB11BCD787300A3DC55 /* DataMemoryTests.swift */, - 56FF45551D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift */, - 56A4CDAF1D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift */, - ); - name = Private; - sourceTree = ""; - }; - 56A238111B9C74A90082EB20 /* Core */ = { - isa = PBXGroup; - children = ( - 5665F86A203EF47C0084C6C0 /* ColumnInfoTests.swift */, - 56DAA2C41DE99D8D006E10C8 /* Cursor */, - 564448821EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift */, - 564F9C1D1F069B4E00877A00 /* DatabaseAggregateTests.swift */, - 564A50C61BFF4B7F00B3A3A2 /* DatabaseCollationTests.swift */, - 56A238161B9C74A90082EB20 /* DatabaseErrorTests.swift */, - 560C97C61BFD0B8400BF8471 /* DatabaseFunctionTests.swift */, - 567DAF341EAB789800FC0928 /* DatabaseLogErrorTests.swift */, - 560A37A91C90084600949E71 /* DatabasePool */, - 563363BB1C93FD32000BE133 /* DatabaseQueue */, - 56EA86931C91DFE7002BB4DF /* DatabaseReaderTests.swift */, - 564CE5C021B8FFD800652B19 /* DatabaseRegionObservationTests.swift */, - 56C3F7521CF9F12400F6A361 /* DatabaseSavepointTests.swift */, - 566A842F20413DCF00E50BFD /* DatabaseSnapshotTests.swift */, - 56A238131B9C74A90082EB20 /* DatabaseTests.swift */, - 5644DE8120F8D1E4001FFDDE /* DatabaseValueConversionErrorTests.swift */, - 56A2381B1B9C74A90082EB20 /* DatabaseValueConversionTests.swift */, - 56A238191B9C74A90082EB20 /* DatabaseValueConvertible */, - 56A238181B9C74A90082EB20 /* DatabaseValueTests.swift */, - 562756421E963AAC0035B653 /* DatabaseWriterTests.swift */, - 56A5EF0E1EF7F20B00F03071 /* ForeignKeyInfoTests.swift */, - 56741EA71E66A8B3003E422D /* FetchRequestTests.swift */, - 567A80521D41350C00C7DCEC /* IndexInfoTests.swift */, - 56D5075D1F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift */, - 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */, - 56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */, - 56A2381D1B9C74A90082EB20 /* Row */, - 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */, - 568068301EBBA26100EFB8AA /* SQLRequestTests.swift */, - 56A238201B9C74A90082EB20 /* Statement */, - 56E8CE0F1BB4FE5B00828BEC /* StatementColumnConvertibleFetchTests.swift */, - 5607EFD11BB8253300605DE3 /* TransactionObserver */, - ); - name = Core; - sourceTree = ""; - }; - 56A238191B9C74A90082EB20 /* DatabaseValueConvertible */ = { - isa = PBXGroup; - children = ( - 5674A70A1F3087700095F066 /* DatabaseValueConvertibleDecodableTests.swift */, - 5674A70B1F3087700095F066 /* DatabaseValueConvertibleEncodableTests.swift */, - 56A238B51B9CA2590082EB20 /* DatabaseTimestampTests.swift */, - 56E8CE0C1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift */, - 56A2381A1B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift */, - 56A2381C1B9C74A90082EB20 /* RawRepresentable+DatabaseValueConvertibleTests.swift */, - ); - name = DatabaseValueConvertible; - sourceTree = ""; - }; - 56A2381D1B9C74A90082EB20 /* Row */ = { - isa = PBXGroup; - children = ( - 565F03C11CE5D3AA00DE108F /* RowAdapterTests.swift */, - 56A2381F1B9C74A90082EB20 /* RowCopiedFromStatementTests.swift */, - 562393171DECC02000A6B01F /* RowFetchTests.swift */, - 56B14E7E1D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift */, - 56A2381E1B9C74A90082EB20 /* RowFromDictionaryTests.swift */, - 56FDECE11BB32DFD009AD709 /* RowFromStatementTests.swift */, - 5698ACD61DA925420056AF8C /* RowTestCase.swift */, - ); - name = Row; - sourceTree = ""; - }; - 56A238201B9C74A90082EB20 /* Statement */ = { - isa = PBXGroup; - children = ( - 56A238211B9C74A90082EB20 /* SelectStatementTests.swift */, - 56DE7B101C3D93ED00861EB8 /* StatementArgumentsTests.swift */, - 56A238221B9C74A90082EB20 /* UpdateStatementTests.swift */, - ); - name = Statement; - sourceTree = ""; - }; - 56A238231B9C74A90082EB20 /* Migrations */ = { - isa = PBXGroup; - children = ( - 56A238241B9C74A90082EB20 /* DatabaseMigratorTests.swift */, - ); - name = Migrations; - sourceTree = ""; - }; - 56A238251B9C74A90082EB20 /* Record */ = { - isa = PBXGroup; - children = ( - 5674A7251F30A8EF0095F066 /* FetchableRecord */, - 56B15D0A1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift */, - 564E73EB203DA29B000C443C /* JoinSupportTests.swift */, - 560B3FA41C19DFF800C58EC7 /* PersistableRecord */, - 56176C9E1EACEDF9000F3F2B /* Record */, - 56176C9C1EACEA8C000F3F2B /* TableRecord */, - ); - name = Record; - sourceTree = ""; - }; - 56A2386F1B9C75030082EB20 /* Core */ = { - isa = PBXGroup; - children = ( - 56A238701B9C75030082EB20 /* Configuration.swift */, - 56DAA2DA1DE9C827006E10C8 /* Cursor.swift */, - 56A238711B9C75030082EB20 /* Database.swift */, - 566B91221FA4CF810012D5B0 /* Database+Schema.swift */, - 566B91081FA4C3960012D5B0 /* Database+Statements.swift */, - 566B91121FA4C3F50012D5B0 /* DatabaseCollation.swift */, - 56A238731B9C75030082EB20 /* DatabaseError.swift */, - 564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */, - 560A37A31C8F625000949E71 /* DatabasePool.swift */, - 56A238741B9C75030082EB20 /* DatabaseQueue.swift */, - 563363BF1C942C04000BE133 /* DatabaseReader.swift */, - 569EF0E8200D387000A9FA45 /* DatabaseRegion.swift */, - 564CE5B921B8FBFD00652B19 /* DatabaseRegionObservation.swift */, - 5695311E1C907A8C00CF1A2B /* DatabaseSchemaCache.swift */, - 566A842720413D6E00E50BFD /* DatabaseSnapshot.swift */, - 56A238751B9C75030082EB20 /* DatabaseValue.swift */, - 5644DE7A20F8C903001FFDDE /* DatabaseValueConversion.swift */, - 560D923E1C672C3E00F4F92B /* DatabaseValueConvertible.swift */, - 563363C31C942C37000BE133 /* DatabaseWriter.swift */, - 5636E9BB1D22574100B9B05F /* FetchRequest.swift */, - 56A238761B9C75030082EB20 /* Row.swift */, - 567404871CEF84C8003ED5CC /* RowAdapter.swift */, - 56BB6EA81D3009B100A1CA52 /* SchedulingWatchdog.swift */, - 560A37A61C8FF6E500949E71 /* SerializedDatabase.swift */, - 56A238781B9C75030082EB20 /* Statement.swift */, - 566B912A1FA4D0CC0012D5B0 /* StatementAuthorizer.swift */, - 560D923F1C672C3E00F4F92B /* StatementColumnConvertible.swift */, - 5605F1471C672E4000235C62 /* Support */, - 566B91321FA4D3810012D5B0 /* TransactionObserver.swift */, - ); - path = Core; - sourceTree = ""; - }; - 56A238911B9C750B0082EB20 /* Migration */ = { - isa = PBXGroup; - children = ( - 56A238921B9C750B0082EB20 /* DatabaseMigrator.swift */, - 56B7F4391BEB42D500E39BBF /* Migration.swift */, - ); - path = Migration; - sourceTree = ""; - }; - 56A2389F1B9C753B0082EB20 /* Record */ = { - isa = PBXGroup; - children = ( - 56CEB4F01EAA2EFA00BFAF62 /* FetchableRecord.swift */, - 5674A6F21F307F600095F066 /* FetchableRecord+Decodable.swift */, - 56D51CFF1EA789FA0074638A /* FetchableRecord+TableRecord.swift */, - 31A7787C1C6A4DD600F507F6 /* FetchedRecordsController.swift */, - 560D92441C672C4B00F4F92B /* PersistableRecord.swift */, - 5674A6F31F307F600095F066 /* PersistableRecord+Encodable.swift */, - 56A238A11B9C753B0082EB20 /* Record.swift */, - 560D92461C672C4B00F4F92B /* TableRecord.swift */, - ); - path = Record; - sourceTree = ""; - }; - 56BF6D2B1DEF47DA006039A3 /* Legacy */ = { - isa = PBXGroup; - children = ( - 56BF6D2E1DEF47DA006039A3 /* Fixits-Swift2.swift */, - 56BF6D2C1DEF47DA006039A3 /* Fixits-0-84-0.swift */, - 56BF6D2D1DEF47DA006039A3 /* Fixits-0-90-1.swift */, - 56F3E7621E67F8C100BF0F01 /* Fixits-0.101.1.swift */, - 56E06F051E859064008AE2A4 /* Fixits-0.102.0.swift */, - 56D121591ED34978001347D2 /* Fixits-0.109.0.swift */, - 56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */, - 569A98FA2039B72C008D7DBF /* Fixits-3.0.swift */, - ); - path = Legacy; - sourceTree = ""; - }; - 56DAA2C41DE99D8D006E10C8 /* Cursor */ = { - isa = PBXGroup; - children = ( - 5623932F1DEDFC5700A6B01F /* AnyCursorTests.swift */, - 5623935F1DEE06D300A6B01F /* CursorTests.swift */, - 56DAA2D11DE99DAB006E10C8 /* DatabaseCursorTests.swift */, - 56CC924B201E059100CB597E /* DropFirstCursorTests.swift */, - 56CC922E201DFFE200CB597E /* DropWhileCursorTests.swift */, - 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */, - 562393561DEE013C00A6B01F /* FilterCursorTests.swift */, - 562393681DEE0CD200A6B01F /* FlattenCursorTests.swift */, - 562393711DEE104400A6B01F /* MapCursorTests.swift */, - 56CC9256201E094E00CB597E /* PrefixCursorTests.swift */, - 56CC923D201E034200CB597E /* PrefixWhileCursorTests.swift */, - ); - name = Cursor; - sourceTree = ""; - }; - 56F0B98C1B6001C600A2F135 /* Foundation */ = { - isa = PBXGroup; - children = ( - 5657AB2F1D108BA9006283EF /* FoundationDataTests.swift */, - 5690C3251D23E6D800E59934 /* FoundationDateComponentsTests.swift */, - 5690C3361D23E7D200E59934 /* FoundationDateTests.swift */, - 5657AB301D108BA9006283EF /* FoundationNSDataTests.swift */, - 56F0B98E1B6001C600A2F135 /* FoundationNSDateTests.swift */, - 561667001D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift */, - 5657AB311D108BA9006283EF /* FoundationNSNullTests.swift */, - 5657AB321D108BA9006283EF /* FoundationNSNumberTests.swift */, - 5657AB331D108BA9006283EF /* FoundationNSStringTests.swift */, - 5657AB341D108BA9006283EF /* FoundationNSURLTests.swift */, - 56A8C2361D1914790096E9D4 /* FoundationNSUUIDTests.swift */, - 5657AB351D108BA9006283EF /* FoundationURLTests.swift */, - 56A8C21E1D1914110096E9D4 /* FoundationUUIDTests.swift */, - 565D5D701BBC694D00DC9BD4 /* Row+FoundationTests.swift */, - 565D5D731BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift */, - ); - name = Foundation; - sourceTree = ""; - }; - DC10500F19C904DD00D8CA30 /* Tests */ = { - isa = PBXGroup; - children = ( - 56176C581EACC2D8000F3F2B /* GRDBTests */, - DC37740319C8CBB3004FCF85 /* Supporting Files */, - ); - path = Tests; - sourceTree = ""; - }; - DC3773E919C8CBB3004FCF85 = { - isa = PBXGroup; - children = ( - DC37742D19C8CC90004FCF85 /* GRDB */, - 560FC54F1CB0047D0014AA8E /* GRDBCipher */, - DC10500F19C904DD00D8CA30 /* Tests */, - DC3773F419C8CBB3004FCF85 /* Products */, - ); - indentWidth = 4; - sourceTree = ""; - tabWidth = 4; - usesTabs = 0; - }; - DC3773F419C8CBB3004FCF85 /* Products */ = { - isa = PBXGroup; - children = ( - 560FC54D1CB003810014AA8E /* GRDBCipher.framework */, - 560FC5B01CB00B880014AA8E /* GRDBCipherOSXTests.xctest */, - 5671566C1CB16729007DC145 /* GRDBCipherOSXEncryptedTests.xctest */, - 56AFCA231CB1A8BB00F48B96 /* GRDBCipher.framework */, - 56AFCA7F1CB1AA9900F48B96 /* GRDBCipheriOSTests.xctest */, - 56AFCAD71CB1ABC800F48B96 /* GRDBCipheriOSEncryptedTests.xctest */, - ); - name = Products; - sourceTree = ""; - }; - DC37740319C8CBB3004FCF85 /* Supporting Files */ = { - isa = PBXGroup; - children = ( - DC37740419C8CBB3004FCF85 /* Info.plist */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; - DC37742D19C8CC90004FCF85 /* GRDB */ = { - isa = PBXGroup; - children = ( - 56A2386F1B9C75030082EB20 /* Core */, - 5698AC291D9E5A480056AF8C /* FTS */, - 56BF6D2B1DEF47DA006039A3 /* Legacy */, - 56A238911B9C750B0082EB20 /* Migration */, - 56300B6D1C53F592005A543B /* QueryInterface */, - 56A2389F1B9C753B0082EB20 /* Record */, - DC37743319C8CFCE004FCF85 /* Supporting Files */, - 5659F4861EA8D94E004A4992 /* Utils */, - 5613ED7221A95E8400DC7A68 /* ValueObservation */, - ); - path = GRDB; - sourceTree = ""; - }; - DC37743319C8CFCE004FCF85 /* Supporting Files */ = { - isa = PBXGroup; - children = ( - 567DAF141EAB61ED00FC0928 /* grdb_config.h */, - DC2393C61ABE35F8003FF113 /* GRDB-Bridging.h */, - DC3773F819C8CBB3004FCF85 /* GRDB.h */, - 56B8F49A1B4E2F3600C24296 /* GRDB.xcconfig */, - 56C494401ED7255500CC72AF /* GRDBDeploymentTarget.xcconfig */, - DC3773F719C8CBB3004FCF85 /* Info.plist */, - 56C48E731C9A9923005DF1D9 /* module.modulemap */, - ); - name = "Supporting Files"; - path = ../Support; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXHeadersBuildPhase section */ - 560FC5461CB003810014AA8E /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 567DAF1D1EAB61ED00FC0928 /* grdb_config.h in Headers */, - 568E1CBA1CB03847008D97A6 /* GRDBCipher.h in Headers */, - 568E1CB21CB037BA008D97A6 /* sqlite3.h in Headers */, - 568E1CB91CB03847008D97A6 /* GRDBCipher-Bridging.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 56AFCA1C1CB1A8BB00F48B96 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 567DAF201EAB61ED00FC0928 /* grdb_config.h in Headers */, - 56AFCA291CB1A98D00F48B96 /* GRDBCipher.h in Headers */, - 56AFCA2A1CB1A98D00F48B96 /* GRDBCipher-Bridging.h in Headers */, - 56AFCA281CB1A98D00F48B96 /* sqlite3.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXHeadersBuildPhase section */ - -/* Begin PBXNativeTarget section */ - 560FC5191CB003810014AA8E /* GRDBCipherOSX */ = { - isa = PBXNativeTarget; - buildConfigurationList = 560FC54A1CB003810014AA8E /* Build configuration list for PBXNativeTarget "GRDBCipherOSX" */; - buildPhases = ( - 560FC51A1CB003810014AA8E /* Sources */, - 560FC5441CB003810014AA8E /* Frameworks */, - 560FC5461CB003810014AA8E /* Headers */, - 560FC5491CB003810014AA8E /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - 56AFC9781CB1A3E200F48B96 /* PBXTargetDependency */, - ); - name = GRDBCipherOSX; - productName = GRDB; - productReference = 560FC54D1CB003810014AA8E /* GRDBCipher.framework */; - productType = "com.apple.product-type.framework"; - }; - 560FC55D1CB00B880014AA8E /* GRDBCipherOSXTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 560FC5AD1CB00B880014AA8E /* Build configuration list for PBXNativeTarget "GRDBCipherOSXTests" */; - buildPhases = ( - 560FC5601CB00B880014AA8E /* Sources */, - 560FC5A91CB00B880014AA8E /* Frameworks */, - 560FC5AC1CB00B880014AA8E /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - 568BE5221CB0371000270F93 /* PBXTargetDependency */, - ); - name = GRDBCipherOSXTests; - productName = GRDBOSXTests; - productReference = 560FC5B01CB00B880014AA8E /* GRDBCipherOSXTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; - 567156191CB16729007DC145 /* GRDBCipherOSXEncryptedTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 567156691CB16729007DC145 /* Build configuration list for PBXNativeTarget "GRDBCipherOSXEncryptedTests" */; - buildPhases = ( - 5671561C1CB16729007DC145 /* Sources */, - 567156661CB16729007DC145 /* Frameworks */, - 567156681CB16729007DC145 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - 5671561A1CB16729007DC145 /* PBXTargetDependency */, - ); - name = GRDBCipherOSXEncryptedTests; - productName = GRDBOSXTests; - productReference = 5671566C1CB16729007DC145 /* GRDBCipherOSXEncryptedTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; - 56AFC9EE1CB1A8BB00F48B96 /* GRDBCipheriOS */ = { - isa = PBXNativeTarget; - buildConfigurationList = 56AFCA201CB1A8BB00F48B96 /* Build configuration list for PBXNativeTarget "GRDBCipheriOS" */; - buildPhases = ( - 56AFC9EF1CB1A8BB00F48B96 /* Sources */, - 56AFCA1A1CB1A8BB00F48B96 /* Frameworks */, - 56AFCA1C1CB1A8BB00F48B96 /* Headers */, - 56AFCA1F1CB1A8BB00F48B96 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - 56AFCA261CB1A96A00F48B96 /* PBXTargetDependency */, - ); - name = GRDBCipheriOS; - productName = GRDBiOS; - productReference = 56AFCA231CB1A8BB00F48B96 /* GRDBCipher.framework */; - productType = "com.apple.product-type.framework"; - }; - 56AFCA2B1CB1AA9900F48B96 /* GRDBCipheriOSTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 56AFCA7C1CB1AA9900F48B96 /* Build configuration list for PBXNativeTarget "GRDBCipheriOSTests" */; - buildPhases = ( - 56AFCA2E1CB1AA9900F48B96 /* Sources */, - 56AFCA781CB1AA9900F48B96 /* Frameworks */, - 56AFCA7B1CB1AA9900F48B96 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - 56AFCA821CB1AAB400F48B96 /* PBXTargetDependency */, - ); - name = GRDBCipheriOSTests; - productName = GRDBiOSTests; - productReference = 56AFCA7F1CB1AA9900F48B96 /* GRDBCipheriOSTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; - 56AFCA841CB1ABC800F48B96 /* GRDBCipheriOSEncryptedTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 56AFCAD41CB1ABC800F48B96 /* Build configuration list for PBXNativeTarget "GRDBCipheriOSEncryptedTests" */; - buildPhases = ( - 56AFCA871CB1ABC800F48B96 /* Sources */, - 56AFCAD11CB1ABC800F48B96 /* Frameworks */, - 56AFCAD31CB1ABC800F48B96 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - 56AFCA851CB1ABC800F48B96 /* PBXTargetDependency */, - ); - name = GRDBCipheriOSEncryptedTests; - productName = GRDBiOSTests; - productReference = 56AFCAD71CB1ABC800F48B96 /* GRDBCipheriOSEncryptedTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - DC3773EA19C8CBB3004FCF85 /* Project object */ = { - isa = PBXProject; - attributes = { - LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0930; - ORGANIZATIONNAME = "Gwendal Roué"; - TargetAttributes = { - 560FC5191CB003810014AA8E = { - LastSwiftMigration = 0830; - }; - 56AFC9EE1CB1A8BB00F48B96 = { - LastSwiftMigration = 0830; - }; - }; - }; - buildConfigurationList = DC3773ED19C8CBB3004FCF85 /* Build configuration list for PBXProject "GRDBCipher" */; - compatibilityVersion = "Xcode 6.3"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = DC3773E919C8CBB3004FCF85; - productRefGroup = DC3773F419C8CBB3004FCF85 /* Products */; - projectDirPath = ""; - projectReferences = ( - { - ProductGroup = 560FC5511CB004AD0014AA8E /* Products */; - ProjectRef = 560FC5501CB004AD0014AA8E /* sqlcipher.xcodeproj */; - }, - ); - projectRoot = ""; - targets = ( - 560FC5191CB003810014AA8E /* GRDBCipherOSX */, - 560FC55D1CB00B880014AA8E /* GRDBCipherOSXTests */, - 567156191CB16729007DC145 /* GRDBCipherOSXEncryptedTests */, - 56AFC9EE1CB1A8BB00F48B96 /* GRDBCipheriOS */, - 56AFCA2B1CB1AA9900F48B96 /* GRDBCipheriOSTests */, - 56AFCA841CB1ABC800F48B96 /* GRDBCipheriOSEncryptedTests */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXReferenceProxy section */ - 560FC5561CB004AD0014AA8E /* libsqlcipher.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libsqlcipher.a; - remoteRef = 560FC5551CB004AD0014AA8E /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; -/* End PBXReferenceProxy section */ - -/* Begin PBXResourcesBuildPhase section */ - 560FC5491CB003810014AA8E /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 560FC5AC1CB00B880014AA8E /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 568735A01CEDE16C009B9116 /* Betty.jpeg in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 567156681CB16729007DC145 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 568735A11CEDE16C009B9116 /* Betty.jpeg in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 56AFCA1F1CB1A8BB00F48B96 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 56AFCA7B1CB1AA9900F48B96 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 568735A31CEDE16C009B9116 /* Betty.jpeg in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 56AFCAD31CB1ABC800F48B96 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 568735A41CEDE16C009B9116 /* Betty.jpeg in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 560FC51A1CB003810014AA8E /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 56873BED1F2CB400004D24B4 /* Fixits-1.2.swift in Sources */, - 563EF43C2161183E007DAACD /* AssociationAggregate.swift in Sources */, - 56D91AB42205F8C000770D8D /* SQLSelectQuery.swift in Sources */, - 56BF6D3E1DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */, - 5616AAF9207CD5A900AC3664 /* RequestProtocols.swift in Sources */, - 5636E9BD1D22574100B9B05F /* FetchRequest.swift in Sources */, - 56BB6EAA1D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */, - 563EF4502161F1A8007DAACD /* Inflections.swift in Sources */, - 566B910A1FA4C3970012D5B0 /* Database+Statements.swift in Sources */, - 566B91241FA4CF810012D5B0 /* Database+Schema.swift in Sources */, - 56CEB5121EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */, - 5659F4911EA8D964004A4992 /* ReadWriteBox.swift in Sources */, - 566A842920413D6F00E50BFD /* DatabaseSnapshot.swift in Sources */, - 56CEB4F21EAA2EFA00BFAF62 /* FetchableRecord.swift in Sources */, - 560FC51C1CB003810014AA8E /* QueryInterfaceRequest.swift in Sources */, - 560FC51D1CB003810014AA8E /* SQLCollatedExpression.swift in Sources */, - 5653EB9920961FC000F46237 /* ForeignKeyRequest.swift in Sources */, - 5613ED8121A95E8400DC7A68 /* ValueObservation+Row.swift in Sources */, - 566B91341FA4D3810012D5B0 /* TransactionObserver.swift in Sources */, - 56D91A9C2205DD5200770D8D /* SQLRelation.swift in Sources */, - 56D1215B1ED34978001347D2 /* Fixits-0.109.0.swift in Sources */, - 5613ED8921A95E8400DC7A68 /* ValueObservation+Count.swift in Sources */, - 566475D41D981D5E00FF74B8 /* SQLOperators.swift in Sources */, - 5653EB9120961FC000F46237 /* HasOneAssociation.swift in Sources */, - 56CEB5621EAA359A00BFAF62 /* SQLSelectable.swift in Sources */, - 56CEB4FB1EAA2F4D00BFAF62 /* FTS3.swift in Sources */, - 5698AD361DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */, - 564CE5A621B7A9D600652B19 /* ValueObservation+DistinctUntilChanged.swift in Sources */, - 566B91141FA4C3F50012D5B0 /* DatabaseCollation.swift in Sources */, - 560FC51F1CB003810014AA8E /* CGFloat.swift in Sources */, - 5674A7091F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift in Sources */, - 5653EC17209873A400F46237 /* SQLExpression+QueryInterface.swift in Sources */, - 564CE52621B312B500652B19 /* ValueObservation+MapReducer.swift in Sources */, - 5659F4A11EA8D997004A4992 /* Result.swift in Sources */, - 560FC5201CB003810014AA8E /* Date.swift in Sources */, - 560FC5221CB003810014AA8E /* DatabaseValueConvertible+RawRepresentable.swift in Sources */, - 563EF424215F8A88007DAACD /* OrderedDictionary.swift in Sources */, - 560FC5231CB003810014AA8E /* Configuration.swift in Sources */, - 566475CD1D981D5E00FF74B8 /* SQLFunctions.swift in Sources */, - 569EF0E9200D387000A9FA45 /* DatabaseRegion.swift in Sources */, - 5698AC381D9E5A590056AF8C /* FTS3Pattern.swift in Sources */, - 564F9C2F1F07611400877A00 /* DatabaseFunction.swift in Sources */, - 5659F4991EA8D989004A4992 /* Pool.swift in Sources */, - 5653EB8F20961FC000F46237 /* BelongsToAssociation.swift in Sources */, - 5674A6FA1F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */, - 56CEB54D1EAA359A00BFAF62 /* SQLExpressible.swift in Sources */, - 5664759B1D97D8A000FF74B8 /* SQLCollection.swift in Sources */, - 567404891CEF84C8003ED5CC /* RowAdapter.swift in Sources */, - 56E06F131E859068008AE2A4 /* Fixits-0.102.0.swift in Sources */, - 560FC5241CB003810014AA8E /* DatabaseWriter.swift in Sources */, - 5653EBA220961FCA00F46237 /* QueryInterfaceRequest+Association.swift in Sources */, - 5698AD191DAAD17B0056AF8C /* FTS5Tokenizer.swift in Sources */, - 56F3E7641E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */, - 56B964B21DA51D010002DA19 /* FTS5TokenizerDescriptor.swift in Sources */, - 560FC5261CB003810014AA8E /* SerializedDatabase.swift in Sources */, - 560FC5271CB003810014AA8E /* NSString.swift in Sources */, - 564CE4DD21B2DEF700652B19 /* ValueObservation+CompactMap.swift in Sources */, - 560FC5291CB003810014AA8E /* DatabaseValueConvertible.swift in Sources */, - 56A8C2311D1914540096E9D4 /* UUID.swift in Sources */, - 56CEB5021EAA2F4D00BFAF62 /* FTS4.swift in Sources */, - 56CEB55B1EAA359A00BFAF62 /* SQLOrdering.swift in Sources */, - 56BF6D301DEF47DA006039A3 /* Fixits-0-84-0.swift in Sources */, - 560FC52A1CB003810014AA8E /* DatabaseError.swift in Sources */, - 56D51D011EA789FA0074638A /* FetchableRecord+TableRecord.swift in Sources */, - 566475BB1D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift in Sources */, - 5613ED8721A95E8400DC7A68 /* ValueReducer.swift in Sources */, - 560FC52B1CB003810014AA8E /* DatabaseValue.swift in Sources */, - 5671FC211DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift in Sources */, - 560FC52E1CB003810014AA8E /* Record.swift in Sources */, - 56CEB5461EAA359A00BFAF62 /* Column.swift in Sources */, - 5657AB101D10899D006283EF /* URL.swift in Sources */, - 560FC5311CB003810014AA8E /* TableRecord.swift in Sources */, - 56DAA2DC1DE9C827006E10C8 /* Cursor.swift in Sources */, - 5674A6F11F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */, - 5613ED8321A95E8400DC7A68 /* ValueObservation+FetchableRecord.swift in Sources */, - 5644DE7C20F8C903001FFDDE /* DatabaseValueConversion.swift in Sources */, - 560FC5321CB003810014AA8E /* DatabasePool.swift in Sources */, - 56D91AAD2205F30200770D8D /* DatabasePromise.swift in Sources */, - 560FC5331CB003810014AA8E /* Migration.swift in Sources */, - 566B912C1FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */, - 560FC5351CB003810014AA8E /* Statement.swift in Sources */, - 5690C3411D23E82A00E59934 /* Data.swift in Sources */, - 5659F4891EA8D94E004A4992 /* Utils.swift in Sources */, - 560FC5361CB003810014AA8E /* DatabaseMigrator.swift in Sources */, - 560FC5371CB003810014AA8E /* DatabaseSchemaCache.swift in Sources */, - 560FC5381CB003810014AA8E /* DatabaseDateComponents.swift in Sources */, - 56BF6D371DEF47DA006039A3 /* Fixits-0-90-1.swift in Sources */, - 56193E961CD8A3E300F95862 /* FetchedRecordsController.swift in Sources */, - 568D13242207214D00674B58 /* SQLSelectQueryGenerator.swift in Sources */, - 56B964BA1DA51D0A0002DA19 /* FTS5Pattern.swift in Sources */, - 560FC5391CB003810014AA8E /* DatabaseReader.swift in Sources */, - 560FC53A1CB003810014AA8E /* NSNull.swift in Sources */, - 56CEB51A1EAA328900BFAF62 /* FTS5+QueryInterface.swift in Sources */, - 564CE44021AA957000652B19 /* ValueObserver.swift in Sources */, - 5674A7011F307F600095F066 /* FetchableRecord+Decodable.swift in Sources */, - 5698AC791DA37DCB0056AF8C /* VirtualTableModule.swift in Sources */, - 560FC53B1CB003810014AA8E /* Database.swift in Sources */, - 566AD8B31D5318F4002EC1A8 /* TableDefinition.swift in Sources */, - 5613ED7F21A95E8400DC7A68 /* ValueObservation+Map.swift in Sources */, - 5698AD221DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */, - 564CE5BB21B8FBFD00652B19 /* DatabaseRegionObservation.swift in Sources */, - 560FC53C1CB003810014AA8E /* DatabaseQueue.swift in Sources */, - 5653EB9720961FC000F46237 /* ForeignKey.swift in Sources */, - 569A98FC2039B72D008D7DBF /* Fixits-3.0.swift in Sources */, - 5613ED8521A95E8400DC7A68 /* ValueObservation+DatabaseValueConvertible.swift in Sources */, - 5653EB9520961FC000F46237 /* HasManyAssociation.swift in Sources */, - 560FC53D1CB003810014AA8E /* NSNumber.swift in Sources */, - 5613ED7B21A95E8400DC7A68 /* ValueObservation.swift in Sources */, - 567071F8208A00D4006AD95A /* SQLiteDateParser.swift in Sources */, - 560FC53F1CB003810014AA8E /* Row.swift in Sources */, - 560FC5401CB003810014AA8E /* StandardLibrary.swift in Sources */, - 5613ED7D21A95E8400DC7A68 /* ValueObservation+Combine.swift in Sources */, - 5653EC1A209873E600F46237 /* SQLGenerationContext.swift in Sources */, - 560FC5411CB003810014AA8E /* PersistableRecord.swift in Sources */, - 566475A31D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift in Sources */, - 5674A6EA1F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */, - 5653EB9D20961FC000F46237 /* Association.swift in Sources */, - 5657AABA1D107001006283EF /* NSData.swift in Sources */, - 560FC5421CB003810014AA8E /* StatementColumnConvertible.swift in Sources */, - 56CEB5541EAA359A00BFAF62 /* SQLExpression.swift in Sources */, - 56B9649E1DA51B4C0002DA19 /* FTS5.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 560FC5601CB00B880014AA8E /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 560FC5611CB00B880014AA8E /* DatabaseValueConversionTests.swift in Sources */, - 560FC5B31CB031EA0014AA8E /* DataMemoryTests.swift in Sources */, - 56FF45411D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift in Sources */, - 560FC5621CB00B880014AA8E /* Record+QueryInterfaceRequestTests.swift in Sources */, - 5698ACD81DA925420056AF8C /* RowTestCase.swift in Sources */, - 56A8C2411D1918EE0096E9D4 /* FoundationNSUUIDTests.swift in Sources */, - 562EA8301F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */, - 5653EBC020961FE800F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */, - 563EF45921631E51007DAACD /* QueryInterfacePromiseTests.swift in Sources */, - 562206031E420EA3005860AC /* DatabasePoolBackupTests.swift in Sources */, - 5657AB571D108BA9006283EF /* FoundationNSStringTests.swift in Sources */, - 564448841EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */, - 560FC5B21CB031E30014AA8E /* StatementColumnConvertibleFetchTests.swift in Sources */, - 561667021D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift in Sources */, - 562EA8271F17B2AC00FA528C /* CompilationProtocolTests.swift in Sources */, - 569C1EB31CF07DDD0042627B /* SchedulingWatchdogTests.swift in Sources */, - 560FC5651CB00B880014AA8E /* RecordPrimaryKeyNoneTests.swift in Sources */, - 560FC5661CB00B880014AA8E /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */, - 560FC5671CB00B880014AA8E /* RowFromDictionaryTests.swift in Sources */, - 56A8C2421D1918EE0096E9D4 /* FoundationUUIDTests.swift in Sources */, - 560FC5681CB00B880014AA8E /* SelectStatementTests.swift in Sources */, - 5698AC811DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */, - 56CC923E201E034200CB597E /* PrefixWhileCursorTests.swift in Sources */, - 560FC56A1CB00B880014AA8E /* QueryInterfaceExpressionsTests.swift in Sources */, - 562393191DECC02000A6B01F /* RowFetchTests.swift in Sources */, - 560FC56B1CB00B880014AA8E /* DatabaseCollationTests.swift in Sources */, - 560FC56C1CB00B880014AA8E /* UpdateStatementTests.swift in Sources */, - 5653EBE020961FE800F46237 /* AssociationBelongsToSQLTests.swift in Sources */, - 563B06FA21861D8B00B38F35 /* ValueObservationCountTests.swift in Sources */, - 560FC56D1CB00B880014AA8E /* DatabaseMigratorTests.swift in Sources */, - 56EA63CC209C7F31009715B8 /* DerivableRequestTests.swift in Sources */, - 560FC5701CB00B880014AA8E /* DatabasePoolCollationTests.swift in Sources */, - 560FC5711CB00B880014AA8E /* RecordPrimaryKeySingleTests.swift in Sources */, - 5674A7191F3087710095F066 /* DatabaseValueConvertibleDecodableTests.swift in Sources */, - 56B021CA1D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */, - 563B07082186280600B38F35 /* ValueObservationRowTests.swift in Sources */, - 562205F61E420E48005860AC /* DatabaseQueueReleaseMemoryTests.swift in Sources */, - 560FC5741CB00B880014AA8E /* DatabasePoolFunctionTests.swift in Sources */, - 5653EBDC20961FE800F46237 /* AssociationParallelRowScopesTests.swift in Sources */, - 560FC5761CB00B880014AA8E /* RowCopiedFromStatementTests.swift in Sources */, - 560FC5771CB00B880014AA8E /* DatabaseQueueSchemaCacheTests.swift in Sources */, - 5653EBCC20961FE800F46237 /* AssociationHasOneSQLTests.swift in Sources */, - 562756441E963AAC0035B653 /* DatabaseWriterTests.swift in Sources */, - 56AF746C1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */, - 56B14E801D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift in Sources */, - 5653EBE420961FE800F46237 /* AssociationChainSQLTests.swift in Sources */, - 562206051E420EA3005860AC /* DatabasePoolReadOnlyTests.swift in Sources */, - 562206041E420EA3005860AC /* DatabasePoolConcurrencyTests.swift in Sources */, - 56176C611EACCCC7000F3F2B /* FTS5RecordTests.swift in Sources */, - 567DAF361EAB789800FC0928 /* DatabaseLogErrorTests.swift in Sources */, - 566AD8C71D531BEA002EC1A8 /* TableDefinitionTests.swift in Sources */, - 5665FA222129D81F004D8612 /* DatabaseDateDecodingStrategyTests.swift in Sources */, - 560FC5781CB00B880014AA8E /* RowFromStatementTests.swift in Sources */, - 560FC5791CB00B880014AA8E /* RecordPrimaryKeyMultipleTests.swift in Sources */, - 56CC9257201E094F00CB597E /* PrefixCursorTests.swift in Sources */, - 5698AC971DA4B0430056AF8C /* FTS4RecordTests.swift in Sources */, - 5657AB4F1D108BA9006283EF /* FoundationNSNumberTests.swift in Sources */, - 56CC9236201E009700CB597E /* DropWhileCursorTests.swift in Sources */, - 56D5075F1F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift in Sources */, - 56176C631EACCCC7000F3F2B /* FTS5TokenizerTests.swift in Sources */, - 5623934F1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */, - 563B06ED2185E07300B38F35 /* ValueObservationReducerTests.swift in Sources */, - 560FC57C1CB00B880014AA8E /* StatementArgumentsTests.swift in Sources */, - 563B06E52185E07300B38F35 /* ValueObservationReadonlyTests.swift in Sources */, - 567F45A91F888B2600030B59 /* TruncateOptimizationTests.swift in Sources */, - 5634B1081CF9B970005360B9 /* TransactionObserverSavepointsTests.swift in Sources */, - 560FC57D1CB00B880014AA8E /* RecordInitializersTests.swift in Sources */, - 56176C5F1EACCCC7000F3F2B /* FTS5CustomTokenizerTests.swift in Sources */, - 565F03C31CE5D3AA00DE108F /* RowAdapterTests.swift in Sources */, - 563B070D21862C3600B38F35 /* ValueObservationRecordTests.swift in Sources */, - 56B6EF64208CB762002F0ACB /* ColumnExpressionTests.swift in Sources */, - 5657AB3F1D108BA9006283EF /* FoundationNSDataTests.swift in Sources */, - 560FC57E1CB00B880014AA8E /* MutablePersistableRecordTests.swift in Sources */, - 5657AB5F1D108BA9006283EF /* FoundationNSURLTests.swift in Sources */, - 560FC57F1CB00B880014AA8E /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */, - 5698ACB71DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */, - 5672DE5A1CDB72520022BA81 /* DatabaseQueueBackupTests.swift in Sources */, - 5653EBE820961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */, - 56176C601EACCCC7000F3F2B /* FTS5PatternTests.swift in Sources */, - 564E73EF203DA2A2000C443C /* JoinSupportTests.swift in Sources */, - 563B071E21862F5D00B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift in Sources */, - 5674A7111F3087710095F066 /* DatabaseValueConvertibleEncodableTests.swift in Sources */, - 5657AB471D108BA9006283EF /* FoundationNSNullTests.swift in Sources */, - 5665F86C203EF47D0084C6C0 /* ColumnInfoTests.swift in Sources */, - 560FC5811CB00B880014AA8E /* RecordCopyTests.swift in Sources */, - 560FC5821CB00B880014AA8E /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */, - 567E55ED1D2BDD3D00CC6F79 /* EncryptionTests.swift in Sources */, - 56741EA91E66A8B3003E422D /* FetchRequestTests.swift in Sources */, - 56176C641EACCCC7000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */, - 5653EBB820961FE800F46237 /* AssociationParallelSQLTests.swift in Sources */, - 560FC5841CB00B880014AA8E /* PersistableRecordTests.swift in Sources */, - 560FC5871CB00B880014AA8E /* RecordSubClassTests.swift in Sources */, - 5613ED9E21A96A6F00DC7A68 /* ValueObservationCombineTests.swift in Sources */, - 5653EBBC20961FE800F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */, - 560FC5891CB00B880014AA8E /* TransactionObserverTests.swift in Sources */, - 5674A72C1F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */, - 56C3F7541CF9F12400F6A361 /* DatabaseSavepointTests.swift in Sources */, - 56FEE7FC1F47253700D930EA /* TableRecordTests.swift in Sources */, - 56F3E74A1E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */, - 567A80541D41350C00C7DCEC /* IndexInfoTests.swift in Sources */, - 560FC58B1CB00B880014AA8E /* DatabaseValueTests.swift in Sources */, - 567156171CB142AA007DC145 /* DatabaseQueueReadOnlyTests.swift in Sources */, - 560FC58D1CB00B880014AA8E /* Row+FoundationTests.swift in Sources */, - 56071A4E1DB54ED200CA6E47 /* FetchedRecordsControllerTests.swift in Sources */, - 56A4CDB11D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift in Sources */, - 567156141CB141D0007DC145 /* DatabaseQueueInMemoryTests.swift in Sources */, - 5653EBEC20961FE800F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */, - 560FC58E1CB00B880014AA8E /* RecordPrimaryKeyRowIDTests.swift in Sources */, - 560FC58F1CB00B880014AA8E /* DatabaseReaderTests.swift in Sources */, - 5653EBD020961FE800F46237 /* AssociationRowScopeSearchTests.swift in Sources */, - 563B06E12185E07200B38F35 /* ValueObservationExtentTests.swift in Sources */, - 560FC5901CB00B880014AA8E /* RecordEditedTests.swift in Sources */, - 5665FA412129EEEF004D8612 /* DatabaseDateEncodingStrategyTests.swift in Sources */, - 563B06F12185E07300B38F35 /* ValueObservationSchedulingTests.swift in Sources */, - 5644DE8220F8D1E4001FFDDE /* DatabaseValueConversionErrorTests.swift in Sources */, - 560FC5911CB00B880014AA8E /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */, - 56CC924C201E059100CB597E /* DropFirstCursorTests.swift in Sources */, - 562393311DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */, - 560FC5921CB00B880014AA8E /* FetchableRecordTests.swift in Sources */, - 56A5EF101EF7F20B00F03071 /* ForeignKeyInfoTests.swift in Sources */, - 5657AB371D108BA9006283EF /* FoundationDataTests.swift in Sources */, - 563EF44521613213007DAACD /* AssociationAggregateTests.swift in Sources */, - 5653EBD820961FE800F46237 /* AssociationChainRowScopesTests.swift in Sources */, - 560FC5941CB00B880014AA8E /* DatabaseValueConvertibleSubclassTests.swift in Sources */, - 5653EBC820961FE800F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */, - 565EFAEF1D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */, - 560FC5961CB00B880014AA8E /* DatabaseValueConvertibleFetchTests.swift in Sources */, - 5653EBC420961FE800F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */, - 564CE5C121B8FFD800652B19 /* DatabaseRegionObservationTests.swift in Sources */, - 560FC5971CB00B880014AA8E /* DatabaseErrorTests.swift in Sources */, - 564CE4EC21B2E08300652B19 /* ValueObservationCompactMapTests.swift in Sources */, - 560FC5991CB00B880014AA8E /* RecordMinimalPrimaryKeySingleTests.swift in Sources */, - 564F9C1F1F069B4E00877A00 /* DatabaseAggregateTests.swift in Sources */, - 562393731DEE104400A6B01F /* MapCursorTests.swift in Sources */, - 5698AC9F1DA4B0430056AF8C /* FTS4TableBuilderTests.swift in Sources */, - 56176C621EACCCC7000F3F2B /* FTS5TableBuilderTests.swift in Sources */, - 5698AC4A1DA2D48A0056AF8C /* FTS3RecordTests.swift in Sources */, - 560FC59B1CB00B880014AA8E /* DatabaseTimestampTests.swift in Sources */, - 5698AC411DA2BED90056AF8C /* FTS3PatternTests.swift in Sources */, - 5623936A1DEE0CD200A6B01F /* FlattenCursorTests.swift in Sources */, - 563B06E92185E07300B38F35 /* ValueObservationFetchTests.swift in Sources */, - 560FC59C1CB00B880014AA8E /* StatementArguments+FoundationTests.swift in Sources */, - 5657AB671D108BA9006283EF /* FoundationURLTests.swift in Sources */, - 560FC59D1CB00B880014AA8E /* TableRecord+QueryInterfaceRequestTests.swift in Sources */, - 562205F51E420E48005860AC /* DatabasePoolSchemaCacheTests.swift in Sources */, - 566A84462041AB3900E50BFD /* MutablePersistableRecordChangesTests.swift in Sources */, - 562393581DEE013C00A6B01F /* FilterCursorTests.swift in Sources */, - 5670329F212B546E007D270F /* DatabaseUUIDEncodingStrategyTests.swift in Sources */, - 560FC59E1CB00B880014AA8E /* FoundationNSDateTests.swift in Sources */, - 568068321EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */, - 560FC59F1CB00B880014AA8E /* DatabaseTests.swift in Sources */, - 560FC5A01CB00B880014AA8E /* QueryInterfaceRequestTests.swift in Sources */, - 5698ACCF1DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */, - 560FC5A21CB00B880014AA8E /* DatabaseFunctionTests.swift in Sources */, - 560FC5A41CB00B880014AA8E /* RecordWithColumnNameManglingTests.swift in Sources */, - 5674A7221F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift in Sources */, - 564CE4F121B2E08A00652B19 /* ValueObservationMapTests.swift in Sources */, - 5690C3271D23E6D800E59934 /* FoundationDateComponentsTests.swift in Sources */, - 560FC5A51CB00B880014AA8E /* CGFloatTests.swift in Sources */, - 56FF45571D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift in Sources */, - 560FC5A61CB00B880014AA8E /* DatabaseRegionTests.swift in Sources */, - 5698AC8A1DA389380056AF8C /* FTS3TableBuilderTests.swift in Sources */, - 5698AC041D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */, - 5690C3381D23E7D200E59934 /* FoundationDateTests.swift in Sources */, - 5653EBD420961FE800F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */, - 6340BF811E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift in Sources */, - 5622060B1E420EB3005860AC /* DatabaseQueueConcurrencyTests.swift in Sources */, - 562205F41E420E48005860AC /* DatabasePoolReleaseMemoryTests.swift in Sources */, - 56DAA2D31DE99DAB006E10C8 /* DatabaseCursorTests.swift in Sources */, - 560FC5A71CB00B880014AA8E /* GRDBTestCase.swift in Sources */, - 562393611DEE06D300A6B01F /* CursorTests.swift in Sources */, - 566A843020413DD000E50BFD /* DatabaseSnapshotTests.swift in Sources */, - 569178471CED9B6000E179EA /* DatabaseQueueTests.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 5671561C1CB16729007DC145 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 5671561D1CB16729007DC145 /* DatabaseValueConversionTests.swift in Sources */, - 5671561E1CB16729007DC145 /* DataMemoryTests.swift in Sources */, - 56FF45421D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift in Sources */, - 5671561F1CB16729007DC145 /* Record+QueryInterfaceRequestTests.swift in Sources */, - 5698ACD91DA925420056AF8C /* RowTestCase.swift in Sources */, - 567156221CB16729007DC145 /* StatementColumnConvertibleFetchTests.swift in Sources */, - 562EA8311F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */, - 5653EBC120961FE800F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */, - 563EF45A21631E51007DAACD /* QueryInterfacePromiseTests.swift in Sources */, - 562206001E420EA3005860AC /* DatabasePoolBackupTests.swift in Sources */, - 567156231CB16729007DC145 /* RecordPrimaryKeyNoneTests.swift in Sources */, - 564448851EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */, - 567156241CB16729007DC145 /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */, - 567156251CB16729007DC145 /* RowFromDictionaryTests.swift in Sources */, - 562EA8281F17B2AC00FA528C /* CompilationProtocolTests.swift in Sources */, - 565F03C41CE5D3AA00DE108F /* RowAdapterTests.swift in Sources */, - 567156261CB16729007DC145 /* SelectStatementTests.swift in Sources */, - 567156281CB16729007DC145 /* QueryInterfaceExpressionsTests.swift in Sources */, - 567156291CB16729007DC145 /* DatabaseCollationTests.swift in Sources */, - 5671562A1CB16729007DC145 /* UpdateStatementTests.swift in Sources */, - 5698AC821DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */, - 5657AB481D108BA9006283EF /* FoundationNSNullTests.swift in Sources */, - 56CC923F201E034200CB597E /* PrefixWhileCursorTests.swift in Sources */, - 5671562B1CB16729007DC145 /* DatabaseMigratorTests.swift in Sources */, - 5623931A1DECC02000A6B01F /* RowFetchTests.swift in Sources */, - 5671562E1CB16729007DC145 /* DatabasePoolCollationTests.swift in Sources */, - 5671562F1CB16729007DC145 /* RecordPrimaryKeySingleTests.swift in Sources */, - 5653EBE120961FE800F46237 /* AssociationBelongsToSQLTests.swift in Sources */, - 563B06FB21861D8B00B38F35 /* ValueObservationCountTests.swift in Sources */, - 56EA63CD209C7F31009715B8 /* DerivableRequestTests.swift in Sources */, - 56C3F7551CF9F12400F6A361 /* DatabaseSavepointTests.swift in Sources */, - 5672DE5B1CDB72520022BA81 /* DatabaseQueueBackupTests.swift in Sources */, - 56B021CB1D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */, - 5674A71B1F3087710095F066 /* DatabaseValueConvertibleDecodableTests.swift in Sources */, - 56B14E811D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift in Sources */, - 563B07092186280600B38F35 /* ValueObservationRowTests.swift in Sources */, - 562205F91E420E49005860AC /* DatabaseQueueReleaseMemoryTests.swift in Sources */, - 566AD8C81D531BEB002EC1A8 /* TableDefinitionTests.swift in Sources */, - 5653EBDD20961FE800F46237 /* AssociationParallelRowScopesTests.swift in Sources */, - 567156321CB16729007DC145 /* DatabasePoolFunctionTests.swift in Sources */, - 567156341CB16729007DC145 /* RowCopiedFromStatementTests.swift in Sources */, - 5653EBCD20961FE800F46237 /* AssociationHasOneSQLTests.swift in Sources */, - 562756451E963AAC0035B653 /* DatabaseWriterTests.swift in Sources */, - 569C1EB41CF07DDD0042627B /* SchedulingWatchdogTests.swift in Sources */, - 56AF746D1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */, - 5653EBE520961FE800F46237 /* AssociationChainSQLTests.swift in Sources */, - 562206021E420EA3005860AC /* DatabasePoolReadOnlyTests.swift in Sources */, - 562206011E420EA3005860AC /* DatabasePoolConcurrencyTests.swift in Sources */, - 56176C671EACCCC8000F3F2B /* FTS5RecordTests.swift in Sources */, - 567DAF371EAB789800FC0928 /* DatabaseLogErrorTests.swift in Sources */, - 567156351CB16729007DC145 /* DatabaseQueueSchemaCacheTests.swift in Sources */, - 5665FA232129D81F004D8612 /* DatabaseDateDecodingStrategyTests.swift in Sources */, - 567156361CB16729007DC145 /* RowFromStatementTests.swift in Sources */, - 567156371CB16729007DC145 /* RecordPrimaryKeyMultipleTests.swift in Sources */, - 5657AB401D108BA9006283EF /* FoundationNSDataTests.swift in Sources */, - 56CC9258201E094F00CB597E /* PrefixCursorTests.swift in Sources */, - 5698AC981DA4B0430056AF8C /* FTS4RecordTests.swift in Sources */, - 56CC9237201E009800CB597E /* DropWhileCursorTests.swift in Sources */, - 56D507601F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift in Sources */, - 56176C691EACCCC8000F3F2B /* FTS5TokenizerTests.swift in Sources */, - 562393501DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */, - 563B06EE2185E07300B38F35 /* ValueObservationReducerTests.swift in Sources */, - 5671563A1CB16729007DC145 /* StatementArgumentsTests.swift in Sources */, - 563B06E62185E07300B38F35 /* ValueObservationReadonlyTests.swift in Sources */, - 567F45AA1F888B2600030B59 /* TruncateOptimizationTests.swift in Sources */, - 5657AB601D108BA9006283EF /* FoundationNSURLTests.swift in Sources */, - 5671563B1CB16729007DC145 /* RecordInitializersTests.swift in Sources */, - 56176C651EACCCC8000F3F2B /* FTS5CustomTokenizerTests.swift in Sources */, - 5657AB681D108BA9006283EF /* FoundationURLTests.swift in Sources */, - 563B070E21862C3600B38F35 /* ValueObservationRecordTests.swift in Sources */, - 56B6EF65208CB762002F0ACB /* ColumnExpressionTests.swift in Sources */, - 5671563C1CB16729007DC145 /* MutablePersistableRecordTests.swift in Sources */, - 5671563D1CB16729007DC145 /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */, - 567E55F31D2BDDFE00CC6F79 /* EncryptionTests.swift in Sources */, - 5671563F1CB16729007DC145 /* RecordCopyTests.swift in Sources */, - 5698ACB81DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */, - 567156401CB16729007DC145 /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */, - 5653EBE920961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */, - 56176C661EACCCC8000F3F2B /* FTS5PatternTests.swift in Sources */, - 564E73F0203DA2A3000C443C /* JoinSupportTests.swift in Sources */, - 563B071F21862F5D00B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift in Sources */, - 5674A7131F3087710095F066 /* DatabaseValueConvertibleEncodableTests.swift in Sources */, - 567156411CB16729007DC145 /* PersistableRecordTests.swift in Sources */, - 5665F86D203EF47D0084C6C0 /* ColumnInfoTests.swift in Sources */, - 5657AB501D108BA9006283EF /* FoundationNSNumberTests.swift in Sources */, - 567156441CB16729007DC145 /* RecordSubClassTests.swift in Sources */, - 5690C3391D23E7D200E59934 /* FoundationDateTests.swift in Sources */, - 56741EAA1E66A8B3003E422D /* FetchRequestTests.swift in Sources */, - 56176C6A1EACCCC8000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */, - 5653EBB920961FE800F46237 /* AssociationParallelSQLTests.swift in Sources */, - 567156461CB16729007DC145 /* TransactionObserverTests.swift in Sources */, - 567A80551D41350C00C7DCEC /* IndexInfoTests.swift in Sources */, - 5613ED9F21A96A6F00DC7A68 /* ValueObservationCombineTests.swift in Sources */, - 5653EBBD20961FE800F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */, - 567156481CB16729007DC145 /* DatabaseValueTests.swift in Sources */, - 5674A72E1F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */, - 5671564A1CB16729007DC145 /* DatabaseQueueReadOnlyTests.swift in Sources */, - 56FEE7FD1F47253700D930EA /* TableRecordTests.swift in Sources */, - 56F3E74B1E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */, - 5671564B1CB16729007DC145 /* Row+FoundationTests.swift in Sources */, - 56A8C2431D1918EE0096E9D4 /* FoundationNSUUIDTests.swift in Sources */, - 5671564C1CB16729007DC145 /* DatabaseQueueInMemoryTests.swift in Sources */, - 56A4CDB21D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift in Sources */, - 56071A4F1DB54ED300CA6E47 /* FetchedRecordsControllerTests.swift in Sources */, - 5671564D1CB16729007DC145 /* RecordPrimaryKeyRowIDTests.swift in Sources */, - 5671564E1CB16729007DC145 /* DatabaseReaderTests.swift in Sources */, - 5653EBED20961FE800F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */, - 5671564F1CB16729007DC145 /* RecordEditedTests.swift in Sources */, - 567156501CB16729007DC145 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */, - 5653EBD120961FE800F46237 /* AssociationRowScopeSearchTests.swift in Sources */, - 563B06E22185E07200B38F35 /* ValueObservationExtentTests.swift in Sources */, - 567156511CB16729007DC145 /* FetchableRecordTests.swift in Sources */, - 5665FA422129EEEF004D8612 /* DatabaseDateEncodingStrategyTests.swift in Sources */, - 563B06F22185E07300B38F35 /* ValueObservationSchedulingTests.swift in Sources */, - 5644DE8320F8D1E4001FFDDE /* DatabaseValueConversionErrorTests.swift in Sources */, - 56A8C2441D1918EE0096E9D4 /* FoundationUUIDTests.swift in Sources */, - 56CC924D201E059100CB597E /* DropFirstCursorTests.swift in Sources */, - 562393321DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */, - 567156531CB16729007DC145 /* DatabaseValueConvertibleSubclassTests.swift in Sources */, - 56A5EF111EF7F20B00F03071 /* ForeignKeyInfoTests.swift in Sources */, - 5690C3281D23E6D800E59934 /* FoundationDateComponentsTests.swift in Sources */, - 563EF44621613213007DAACD /* AssociationAggregateTests.swift in Sources */, - 5653EBD920961FE800F46237 /* AssociationChainRowScopesTests.swift in Sources */, - 5657AB381D108BA9006283EF /* FoundationDataTests.swift in Sources */, - 5653EBC920961FE800F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */, - 561667031D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift in Sources */, - 565EFAF01D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */, - 5653EBC520961FE800F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */, - 564CE5C221B8FFD800652B19 /* DatabaseRegionObservationTests.swift in Sources */, - 567156551CB16729007DC145 /* DatabaseValueConvertibleFetchTests.swift in Sources */, - 564CE4ED21B2E08300652B19 /* ValueObservationCompactMapTests.swift in Sources */, - 567156561CB16729007DC145 /* DatabaseErrorTests.swift in Sources */, - 564F9C201F069B4E00877A00 /* DatabaseAggregateTests.swift in Sources */, - 562393741DEE104400A6B01F /* MapCursorTests.swift in Sources */, - 5698ACA01DA4B0430056AF8C /* FTS4TableBuilderTests.swift in Sources */, - 56176C681EACCCC8000F3F2B /* FTS5TableBuilderTests.swift in Sources */, - 5698AC4B1DA2D48A0056AF8C /* FTS3RecordTests.swift in Sources */, - 567156571CB16729007DC145 /* RecordMinimalPrimaryKeySingleTests.swift in Sources */, - 5698AC421DA2BED90056AF8C /* FTS3PatternTests.swift in Sources */, - 5623936B1DEE0CD200A6B01F /* FlattenCursorTests.swift in Sources */, - 563B06EA2185E07300B38F35 /* ValueObservationFetchTests.swift in Sources */, - 567156591CB16729007DC145 /* DatabaseTimestampTests.swift in Sources */, - 5671565A1CB16729007DC145 /* StatementArguments+FoundationTests.swift in Sources */, - 5657AB581D108BA9006283EF /* FoundationNSStringTests.swift in Sources */, - 562205F81E420E49005860AC /* DatabasePoolSchemaCacheTests.swift in Sources */, - 566A84472041AB3900E50BFD /* MutablePersistableRecordChangesTests.swift in Sources */, - 562393591DEE013C00A6B01F /* FilterCursorTests.swift in Sources */, - 567032A0212B546E007D270F /* DatabaseUUIDEncodingStrategyTests.swift in Sources */, - 5671565B1CB16729007DC145 /* TableRecord+QueryInterfaceRequestTests.swift in Sources */, - 568068331EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */, - 5671565C1CB16729007DC145 /* FoundationNSDateTests.swift in Sources */, - 5671565D1CB16729007DC145 /* DatabaseTests.swift in Sources */, - 5671565E1CB16729007DC145 /* QueryInterfaceRequestTests.swift in Sources */, - 5698ACD01DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */, - 569178481CED9B6000E179EA /* DatabaseQueueTests.swift in Sources */, - 5674A7241F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift in Sources */, - 564CE4F221B2E08A00652B19 /* ValueObservationMapTests.swift in Sources */, - 5634B1091CF9B970005360B9 /* TransactionObserverSavepointsTests.swift in Sources */, - 567156601CB16729007DC145 /* DatabaseFunctionTests.swift in Sources */, - 567156611CB16729007DC145 /* RecordWithColumnNameManglingTests.swift in Sources */, - 56FF45581D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift in Sources */, - 5698AC8B1DA389380056AF8C /* FTS3TableBuilderTests.swift in Sources */, - 5698AC051D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */, - 567156621CB16729007DC145 /* CGFloatTests.swift in Sources */, - 5653EBD520961FE800F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */, - 6340BF821E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift in Sources */, - 5622060A1E420EB2005860AC /* DatabaseQueueConcurrencyTests.swift in Sources */, - 562205F71E420E49005860AC /* DatabasePoolReleaseMemoryTests.swift in Sources */, - 56DAA2D41DE99DAB006E10C8 /* DatabaseCursorTests.swift in Sources */, - 567156631CB16729007DC145 /* DatabaseRegionTests.swift in Sources */, - 562393621DEE06D300A6B01F /* CursorTests.swift in Sources */, - 566A843120413DD000E50BFD /* DatabaseSnapshotTests.swift in Sources */, - 567156641CB16729007DC145 /* GRDBTestCase.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 56AFC9EF1CB1A8BB00F48B96 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 56873BF01F2CB400004D24B4 /* Fixits-1.2.swift in Sources */, - 563EF43D2161183E007DAACD /* AssociationAggregate.swift in Sources */, - 56D91AB52205F8C000770D8D /* SQLSelectQuery.swift in Sources */, - 56BF6D411DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */, - 5616AAFA207CD5A900AC3664 /* RequestProtocols.swift in Sources */, - 5636E9C01D22574100B9B05F /* FetchRequest.swift in Sources */, - 56BB6EAD1D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */, - 563EF4512161F1A8007DAACD /* Inflections.swift in Sources */, - 566B910D1FA4C3970012D5B0 /* Database+Statements.swift in Sources */, - 566B91271FA4CF810012D5B0 /* Database+Schema.swift in Sources */, - 56CEB5151EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */, - 5659F4941EA8D964004A4992 /* ReadWriteBox.swift in Sources */, - 566A842A20413D8500E50BFD /* DatabaseSnapshot.swift in Sources */, - 56CEB4F51EAA2EFA00BFAF62 /* FetchableRecord.swift in Sources */, - 56AFC9F11CB1A8BB00F48B96 /* QueryInterfaceRequest.swift in Sources */, - 56AFC9F21CB1A8BB00F48B96 /* SQLCollatedExpression.swift in Sources */, - 5653EB9A20961FC000F46237 /* ForeignKeyRequest.swift in Sources */, - 5613ED8221A95E8400DC7A68 /* ValueObservation+Row.swift in Sources */, - 566B91371FA4D3810012D5B0 /* TransactionObserver.swift in Sources */, - 56D91A9D2205DD5200770D8D /* SQLRelation.swift in Sources */, - 56D1215E1ED34978001347D2 /* Fixits-0.109.0.swift in Sources */, - 5613ED8A21A95E8400DC7A68 /* ValueObservation+Count.swift in Sources */, - 566475D71D981D5E00FF74B8 /* SQLOperators.swift in Sources */, - 5653EB9220961FC000F46237 /* HasOneAssociation.swift in Sources */, - 56CEB5651EAA359A00BFAF62 /* SQLSelectable.swift in Sources */, - 56CEB4FE1EAA2F4D00BFAF62 /* FTS3.swift in Sources */, - 5698AD391DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */, - 564CE5A721B7A9D600652B19 /* ValueObservation+DistinctUntilChanged.swift in Sources */, - 566B91171FA4C3F50012D5B0 /* DatabaseCollation.swift in Sources */, - 56AFC9F31CB1A8BB00F48B96 /* Database.swift in Sources */, - 5674A7061F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift in Sources */, - 5653EC18209873A400F46237 /* SQLExpression+QueryInterface.swift in Sources */, - 564CE52721B312B700652B19 /* ValueObservation+MapReducer.swift in Sources */, - 5659F4A41EA8D997004A4992 /* Result.swift in Sources */, - 56AFC9F41CB1A8BB00F48B96 /* CGFloat.swift in Sources */, - 56AFC9F51CB1A8BB00F48B96 /* Date.swift in Sources */, - 563EF425215F8A88007DAACD /* OrderedDictionary.swift in Sources */, - 56AFC9F71CB1A8BB00F48B96 /* DatabaseValueConvertible+RawRepresentable.swift in Sources */, - 566475D01D981D5E00FF74B8 /* SQLFunctions.swift in Sources */, - 569EF0EA200D387000A9FA45 /* DatabaseRegion.swift in Sources */, - 5698AC3B1D9E5A590056AF8C /* FTS3Pattern.swift in Sources */, - 564F9C321F07611700877A00 /* DatabaseFunction.swift in Sources */, - 5659F49C1EA8D989004A4992 /* Pool.swift in Sources */, - 5653EB9020961FC000F46237 /* BelongsToAssociation.swift in Sources */, - 5674A6F71F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */, - 56CEB5501EAA359A00BFAF62 /* SQLExpressible.swift in Sources */, - 5664759E1D97D8A000FF74B8 /* SQLCollection.swift in Sources */, - 5674048B1CEF84C8003ED5CC /* RowAdapter.swift in Sources */, - 56E06F161E85906C008AE2A4 /* Fixits-0.102.0.swift in Sources */, - 56AFC9F91CB1A8BB00F48B96 /* DatabaseWriter.swift in Sources */, - 5653EBA320961FCA00F46237 /* QueryInterfaceRequest+Association.swift in Sources */, - 5698AD1A1DAAD17C0056AF8C /* FTS5Tokenizer.swift in Sources */, - 56F3E7671E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */, - 56B964B51DA51D010002DA19 /* FTS5TokenizerDescriptor.swift in Sources */, - 56AFC9FB1CB1A8BB00F48B96 /* SerializedDatabase.swift in Sources */, - 56AFC9FC1CB1A8BB00F48B96 /* DatabaseMigrator.swift in Sources */, - 564CE4DE21B2DEF700652B19 /* ValueObservation+CompactMap.swift in Sources */, - 56AFC9FD1CB1A8BB00F48B96 /* NSString.swift in Sources */, - 56A8C2341D1914540096E9D4 /* UUID.swift in Sources */, - 56CEB5051EAA2F4D00BFAF62 /* FTS4.swift in Sources */, - 56CEB55E1EAA359A00BFAF62 /* SQLOrdering.swift in Sources */, - 56BF6D331DEF47DA006039A3 /* Fixits-0-84-0.swift in Sources */, - 56AFC9FF1CB1A8BB00F48B96 /* DatabaseValueConvertible.swift in Sources */, - 56D51D041EA789FA0074638A /* FetchableRecord+TableRecord.swift in Sources */, - 566475BE1D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift in Sources */, - 5613ED8821A95E8400DC7A68 /* ValueReducer.swift in Sources */, - 56AFCA001CB1A8BB00F48B96 /* Record.swift in Sources */, - 5671FC241DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift in Sources */, - 56AFCA031CB1A8BB00F48B96 /* TableRecord.swift in Sources */, - 56CEB5491EAA359A00BFAF62 /* Column.swift in Sources */, - 5657AB131D10899D006283EF /* URL.swift in Sources */, - 56AFCA061CB1A8BB00F48B96 /* Configuration.swift in Sources */, - 56DAA2DF1DE9C827006E10C8 /* Cursor.swift in Sources */, - 5674A6EE1F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */, - 5613ED8421A95E8400DC7A68 /* ValueObservation+FetchableRecord.swift in Sources */, - 5644DE7D20F8C903001FFDDE /* DatabaseValueConversion.swift in Sources */, - 56AFCA071CB1A8BB00F48B96 /* DatabasePool.swift in Sources */, - 56D91AAE2205F30200770D8D /* DatabasePromise.swift in Sources */, - 56AFCA081CB1A8BB00F48B96 /* Statement.swift in Sources */, - 566B912F1FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */, - 56AFCA0A1CB1A8BB00F48B96 /* Migration.swift in Sources */, - 5690C3441D23E82A00E59934 /* Data.swift in Sources */, - 5659F48C1EA8D94E004A4992 /* Utils.swift in Sources */, - 56AFCA0B1CB1A8BB00F48B96 /* Row.swift in Sources */, - 56AFCA0C1CB1A8BB00F48B96 /* DatabaseSchemaCache.swift in Sources */, - 56AFCA0D1CB1A8BB00F48B96 /* DatabaseDateComponents.swift in Sources */, - 56BF6D3A1DEF47DA006039A3 /* Fixits-0-90-1.swift in Sources */, - 56AFCA0E1CB1A8BB00F48B96 /* DatabaseReader.swift in Sources */, - 568D13252207214D00674B58 /* SQLSelectQueryGenerator.swift in Sources */, - 56B964BD1DA51D0A0002DA19 /* FTS5Pattern.swift in Sources */, - 56AFCA0F1CB1A8BB00F48B96 /* NSNull.swift in Sources */, - 56AFCA101CB1A8BB00F48B96 /* DatabaseQueue.swift in Sources */, - 56CEB51D1EAA328900BFAF62 /* FTS5+QueryInterface.swift in Sources */, - 564CE44121AA957000652B19 /* ValueObserver.swift in Sources */, - 5674A6FE1F307F600095F066 /* FetchableRecord+Decodable.swift in Sources */, - 5698AC7C1DA37DCB0056AF8C /* VirtualTableModule.swift in Sources */, - 56AFCA111CB1A8BB00F48B96 /* DatabaseError.swift in Sources */, - 566AD8B61D5318F4002EC1A8 /* TableDefinition.swift in Sources */, - 5613ED8021A95E8400DC7A68 /* ValueObservation+Map.swift in Sources */, - 5698AD251DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */, - 564CE5BC21B8FBFD00652B19 /* DatabaseRegionObservation.swift in Sources */, - 56AFCA121CB1A8BB00F48B96 /* NSNumber.swift in Sources */, - 5653EB9820961FC000F46237 /* ForeignKey.swift in Sources */, - 569A98FD2039B72D008D7DBF /* Fixits-3.0.swift in Sources */, - 5613ED8621A95E8400DC7A68 /* ValueObservation+DatabaseValueConvertible.swift in Sources */, - 5653EB9620961FC000F46237 /* HasManyAssociation.swift in Sources */, - 56AFCA141CB1A8BB00F48B96 /* StandardLibrary.swift in Sources */, - 5613ED7C21A95E8400DC7A68 /* ValueObservation.swift in Sources */, - 56AFCA151CB1A8BB00F48B96 /* PersistableRecord.swift in Sources */, - 567071F9208A00D4006AD95A /* SQLiteDateParser.swift in Sources */, - 56AFCA161CB1A8BB00F48B96 /* StatementColumnConvertible.swift in Sources */, - 5613ED7E21A95E8400DC7A68 /* ValueObservation+Combine.swift in Sources */, - 5653EC1B209873E600F46237 /* SQLGenerationContext.swift in Sources */, - 566475A61D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift in Sources */, - 5657AABD1D107001006283EF /* NSData.swift in Sources */, - 5674A6E71F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */, - 5653EB9E20961FC000F46237 /* Association.swift in Sources */, - 56AFCA181CB1A8BB00F48B96 /* FetchedRecordsController.swift in Sources */, - 56AFCA191CB1A8BB00F48B96 /* DatabaseValue.swift in Sources */, - 56CEB5571EAA359A00BFAF62 /* SQLExpression.swift in Sources */, - 56B964A11DA51B4C0002DA19 /* FTS5.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 56AFCA2E1CB1AA9900F48B96 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 56AFCA301CB1AA9900F48B96 /* Record+QueryInterfaceRequestTests.swift in Sources */, - 562393771DEE104400A6B01F /* MapCursorTests.swift in Sources */, - 56B021CE1D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */, - 56F26C241CEE3F34007969C4 /* RowAdapterTests.swift in Sources */, - 56AFCA311CB1AA9900F48B96 /* RecordPrimaryKeyNoneTests.swift in Sources */, - 56AFCA321CB1AA9900F48B96 /* DatabaseQueueConcurrencyTests.swift in Sources */, - 562EA8341F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */, - 5653EBC220961FE800F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */, - 563EF45B21631E51007DAACD /* QueryInterfacePromiseTests.swift in Sources */, - 5698ACD31DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */, - 56AFCA331CB1AA9900F48B96 /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */, - 564448881EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */, - 56AFCA341CB1AA9900F48B96 /* RowFromDictionaryTests.swift in Sources */, - 569C1EB61CF07DDD0042627B /* SchedulingWatchdogTests.swift in Sources */, - 562EA82B1F17B2AC00FA528C /* CompilationProtocolTests.swift in Sources */, - 56DAA2D71DE99DAB006E10C8 /* DatabaseCursorTests.swift in Sources */, - 5698AC4E1DA2D48A0056AF8C /* FTS3RecordTests.swift in Sources */, - 567E55EE1D2BDD3F00CC6F79 /* EncryptionTests.swift in Sources */, - 56AFCA361CB1AA9900F48B96 /* DatabaseCollationTests.swift in Sources */, - 56AFCA371CB1AA9900F48B96 /* StatementColumnConvertibleFetchTests.swift in Sources */, - 56AFCA381CB1AA9900F48B96 /* QueryInterfaceExpressionsTests.swift in Sources */, - 56AFCA391CB1AA9900F48B96 /* SelectStatementTests.swift in Sources */, - 56CC9240201E034200CB597E /* PrefixWhileCursorTests.swift in Sources */, - 56AFCA3A1CB1AA9900F48B96 /* UpdateStatementTests.swift in Sources */, - 56AFCA3B1CB1AA9900F48B96 /* DatabaseMigratorTests.swift in Sources */, - 5657AB4B1D108BA9006283EF /* FoundationNSNullTests.swift in Sources */, - 56AFCA3E1CB1AA9900F48B96 /* DatabasePoolCollationTests.swift in Sources */, - 5653EBE220961FE800F46237 /* AssociationBelongsToSQLTests.swift in Sources */, - 563B06FC21861D8B00B38F35 /* ValueObservationCountTests.swift in Sources */, - 56FF455B1D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift in Sources */, - 56EA63CE209C7F31009715B8 /* DerivableRequestTests.swift in Sources */, - 56AFCA3F1CB1AA9900F48B96 /* RecordPrimaryKeySingleTests.swift in Sources */, - 56AFCA421CB1AA9900F48B96 /* DatabasePoolFunctionTests.swift in Sources */, - 5674A7181F3087710095F066 /* DatabaseValueConvertibleDecodableTests.swift in Sources */, - 56AFCA441CB1AA9900F48B96 /* RowCopiedFromStatementTests.swift in Sources */, - 563B070A2186280600B38F35 /* ValueObservationRowTests.swift in Sources */, - 56C3F7571CF9F12400F6A361 /* DatabaseSavepointTests.swift in Sources */, - 562393351DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */, - 5653EBDE20961FE800F46237 /* AssociationParallelRowScopesTests.swift in Sources */, - 5698ACDC1DA925430056AF8C /* RowTestCase.swift in Sources */, - 56AFCA451CB1AA9900F48B96 /* DatabaseQueueSchemaCacheTests.swift in Sources */, - 5653EBCE20961FE800F46237 /* AssociationHasOneSQLTests.swift in Sources */, - 562756481E963AAC0035B653 /* DatabaseWriterTests.swift in Sources */, - 56AFCA461CB1AA9900F48B96 /* RecordPrimaryKeyMultipleTests.swift in Sources */, - 56AFCA471CB1AA9900F48B96 /* RowFromStatementTests.swift in Sources */, - 5653EBE620961FE800F46237 /* AssociationChainSQLTests.swift in Sources */, - 56AFCA491CB1AA9900F48B96 /* StatementArgumentsTests.swift in Sources */, - 5672DE6B1CDB751D0022BA81 /* DatabasePoolBackupTests.swift in Sources */, - 56176C731EACCCCA000F3F2B /* FTS5RecordTests.swift in Sources */, - 567DAF3A1EAB789800FC0928 /* DatabaseLogErrorTests.swift in Sources */, - 56B15D0C1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift in Sources */, - 5665FA242129D81F004D8612 /* DatabaseDateDecodingStrategyTests.swift in Sources */, - 56AFCA4A1CB1AA9900F48B96 /* RecordInitializersTests.swift in Sources */, - 566AD8CB1D531BED002EC1A8 /* TableDefinitionTests.swift in Sources */, - 56AFCA4B1CB1AA9900F48B96 /* MutablePersistableRecordTests.swift in Sources */, - 56CC9259201E094F00CB597E /* PrefixCursorTests.swift in Sources */, - 5657AB431D108BA9006283EF /* FoundationNSDataTests.swift in Sources */, - 56AFCA4C1CB1AA9900F48B96 /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */, - 56CC9238201E009900CB597E /* DropWhileCursorTests.swift in Sources */, - 56D507631F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift in Sources */, - 56176C751EACCCCA000F3F2B /* FTS5TokenizerTests.swift in Sources */, - 563B06EF2185E07300B38F35 /* ValueObservationReducerTests.swift in Sources */, - 56AFCA4D1CB1AA9900F48B96 /* DatabasePoolReadOnlyTests.swift in Sources */, - 563B06E72185E07300B38F35 /* ValueObservationReadonlyTests.swift in Sources */, - 5657AB631D108BA9006283EF /* FoundationNSURLTests.swift in Sources */, - 567F45AD1F888B2600030B59 /* TruncateOptimizationTests.swift in Sources */, - 5657AB6B1D108BA9006283EF /* FoundationURLTests.swift in Sources */, - 56AFCA4F1CB1AA9900F48B96 /* DataMemoryTests.swift in Sources */, - 56176C711EACCCCA000F3F2B /* FTS5CustomTokenizerTests.swift in Sources */, - 563B070F21862C3600B38F35 /* ValueObservationRecordTests.swift in Sources */, - 56B6EF66208CB762002F0ACB /* ColumnExpressionTests.swift in Sources */, - 5672DE5D1CDB72520022BA81 /* DatabaseQueueBackupTests.swift in Sources */, - 56AFCA501CB1AA9900F48B96 /* RecordCopyTests.swift in Sources */, - 56FF45451D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift in Sources */, - 56AFCA521CB1AA9900F48B96 /* PersistableRecordTests.swift in Sources */, - 56AFCA531CB1AA9900F48B96 /* DatabaseValueConversionTests.swift in Sources */, - 5657AB531D108BA9006283EF /* FoundationNSNumberTests.swift in Sources */, - 5653EBEA20961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */, - 5698AC9B1DA4B0430056AF8C /* FTS4RecordTests.swift in Sources */, - 56176C721EACCCCA000F3F2B /* FTS5PatternTests.swift in Sources */, - 563B072021862F5D00B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift in Sources */, - 564E73F1203DA2A3000C443C /* JoinSupportTests.swift in Sources */, - 5674A7101F3087710095F066 /* DatabaseValueConvertibleEncodableTests.swift in Sources */, - 56AFCA551CB1AA9900F48B96 /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */, - 5665F86E203EF47D0084C6C0 /* ColumnInfoTests.swift in Sources */, - 5698ACBB1DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */, - 56AFCA561CB1AA9900F48B96 /* DatabasePoolConcurrencyTests.swift in Sources */, - 56AFCA571CB1AA9900F48B96 /* TransactionObserverTests.swift in Sources */, - 56741EAD1E66A8B3003E422D /* FetchRequestTests.swift in Sources */, - 5653EBBA20961FE800F46237 /* AssociationParallelSQLTests.swift in Sources */, - 56176C761EACCCCA000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */, - 5623935C1DEE013C00A6B01F /* FilterCursorTests.swift in Sources */, - 5613EDA021A96A6F00DC7A68 /* ValueObservationCombineTests.swift in Sources */, - 5653EBBE20961FE800F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */, - 5698AC851DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */, - 5698AC451DA2BED90056AF8C /* FTS3PatternTests.swift in Sources */, - 5674A72B1F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */, - 56AF74701D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */, - 56FEE8001F47253700D930EA /* TableRecordTests.swift in Sources */, - 56F3E74E1E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */, - 5690C33C1D23E7D200E59934 /* FoundationDateTests.swift in Sources */, - 56AFCA581CB1AA9900F48B96 /* Row+FoundationTests.swift in Sources */, - 56AFCA5A1CB1AA9900F48B96 /* RecordSubClassTests.swift in Sources */, - 56A4CDB51D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift in Sources */, - 56AFCA5B1CB1AA9900F48B96 /* DatabaseValueTests.swift in Sources */, - 56AFCA5C1CB1AA9900F48B96 /* DatabaseQueueReadOnlyTests.swift in Sources */, - 5653EBEE20961FE800F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */, - 56AFCA5D1CB1AA9900F48B96 /* DatabaseReaderTests.swift in Sources */, - 56A8C2491D1918F10096E9D4 /* FoundationNSUUIDTests.swift in Sources */, - 5653EBD220961FE800F46237 /* AssociationRowScopeSearchTests.swift in Sources */, - 563B06E32185E07300B38F35 /* ValueObservationExtentTests.swift in Sources */, - 56AFCA5E1CB1AA9900F48B96 /* FetchableRecordTests.swift in Sources */, - 5665FA432129EEEF004D8612 /* DatabaseDateEncodingStrategyTests.swift in Sources */, - 563B06F32185E07300B38F35 /* ValueObservationSchedulingTests.swift in Sources */, - 5644DE8420F8D1E4001FFDDE /* DatabaseValueConversionErrorTests.swift in Sources */, - 56AFCA5F1CB1AA9900F48B96 /* DatabaseValueConvertibleFetchTests.swift in Sources */, - 56AFCA601CB1AA9900F48B96 /* RecordPrimaryKeyRowIDTests.swift in Sources */, - 56CC924E201E059100CB597E /* DropFirstCursorTests.swift in Sources */, - 56AFCA611CB1AA9900F48B96 /* RecordEditedTests.swift in Sources */, - 56AFCA621CB1AA9900F48B96 /* DatabasePoolSchemaCacheTests.swift in Sources */, - 56A5EF141EF7F20B00F03071 /* ForeignKeyInfoTests.swift in Sources */, - 563EF44721613213007DAACD /* AssociationAggregateTests.swift in Sources */, - 5653EBDA20961FE800F46237 /* AssociationChainRowScopesTests.swift in Sources */, - 5623931D1DECC02000A6B01F /* RowFetchTests.swift in Sources */, - 5653EBCA20961FE800F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */, - 56AFCA631CB1AA9900F48B96 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */, - 5698AC8E1DA389380056AF8C /* FTS3TableBuilderTests.swift in Sources */, - 5653EBC620961FE800F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */, - 564CE5C321B8FFD800652B19 /* DatabaseRegionObservationTests.swift in Sources */, - 56AFCA641CB1AA9900F48B96 /* DatabaseValueConvertibleSubclassTests.swift in Sources */, - 564CE4EE21B2E08300652B19 /* ValueObservationCompactMapTests.swift in Sources */, - 56A8C24A1D1918F10096E9D4 /* FoundationUUIDTests.swift in Sources */, - 56AFCA651CB1AA9900F48B96 /* DatabaseErrorTests.swift in Sources */, - 564F9C231F069B4E00877A00 /* DatabaseAggregateTests.swift in Sources */, - 5690C32B1D23E6D800E59934 /* FoundationDateComponentsTests.swift in Sources */, - 5623936E1DEE0CD200A6B01F /* FlattenCursorTests.swift in Sources */, - 56176C741EACCCCA000F3F2B /* FTS5TableBuilderTests.swift in Sources */, - 5657AB3B1D108BA9006283EF /* FoundationDataTests.swift in Sources */, - 5698AC081D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */, - 56AFCA661CB1AA9900F48B96 /* DatabaseQueueReleaseMemoryTests.swift in Sources */, - 563B06EB2185E07300B38F35 /* ValueObservationFetchTests.swift in Sources */, - 561667061D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift in Sources */, - 565EFAF31D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */, - 56AFCA671CB1AA9900F48B96 /* DatabasePoolReleaseMemoryTests.swift in Sources */, - 56AFCA681CB1AA9900F48B96 /* RecordMinimalPrimaryKeySingleTests.swift in Sources */, - 566A84482041AB3900E50BFD /* MutablePersistableRecordChangesTests.swift in Sources */, - 56B14E841D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift in Sources */, - 567032A1212B546E007D270F /* DatabaseUUIDEncodingStrategyTests.swift in Sources */, - 56AFCA6B1CB1AA9900F48B96 /* DatabaseTimestampTests.swift in Sources */, - 568068361EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */, - 56AFCA6C1CB1AA9900F48B96 /* StatementArguments+FoundationTests.swift in Sources */, - 562393651DEE06D300A6B01F /* CursorTests.swift in Sources */, - 5657AB5B1D108BA9006283EF /* FoundationNSStringTests.swift in Sources */, - 56AFCA6D1CB1AA9900F48B96 /* TableRecord+QueryInterfaceRequestTests.swift in Sources */, - 56AFCA6E1CB1AA9900F48B96 /* FoundationNSDateTests.swift in Sources */, - 5674A7211F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift in Sources */, - 564CE4F321B2E08A00652B19 /* ValueObservationMapTests.swift in Sources */, - 56AFCA6F1CB1AA9900F48B96 /* DatabaseTests.swift in Sources */, - 56AFCA701CB1AA9900F48B96 /* QueryInterfaceRequestTests.swift in Sources */, - 5634B10B1CF9B970005360B9 /* TransactionObserverSavepointsTests.swift in Sources */, - 56AFCA721CB1AA9900F48B96 /* DatabaseFunctionTests.swift in Sources */, - 56AFCA731CB1AA9900F48B96 /* DatabaseQueueInMemoryTests.swift in Sources */, - 56AFCA741CB1AA9900F48B96 /* RecordWithColumnNameManglingTests.swift in Sources */, - 567A80581D41350C00C7DCEC /* IndexInfoTests.swift in Sources */, - 5653EBD620961FE800F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */, - 6340BF851E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift in Sources */, - 56AFCA751CB1AA9900F48B96 /* CGFloatTests.swift in Sources */, - 562393531DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */, - 56AFCA761CB1AA9900F48B96 /* DatabaseRegionTests.swift in Sources */, - 5698ACA31DA4B0430056AF8C /* FTS4TableBuilderTests.swift in Sources */, - 5691784A1CED9B6000E179EA /* DatabaseQueueTests.swift in Sources */, - 566A843220413DD000E50BFD /* DatabaseSnapshotTests.swift in Sources */, - 56AFCA771CB1AA9900F48B96 /* GRDBTestCase.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 56AFCA871CB1ABC800F48B96 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 56C3F7581CF9F12400F6A361 /* DatabaseSavepointTests.swift in Sources */, - 562393781DEE104400A6B01F /* MapCursorTests.swift in Sources */, - 56B021CF1D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */, - 56AFCA891CB1ABC800F48B96 /* Record+QueryInterfaceRequestTests.swift in Sources */, - 56AFCA8A1CB1ABC800F48B96 /* RecordPrimaryKeyNoneTests.swift in Sources */, - 56AFCA8B1CB1ABC800F48B96 /* DatabaseQueueConcurrencyTests.swift in Sources */, - 562EA8351F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */, - 5653EBC320961FE800F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */, - 563EF45C21631E51007DAACD /* QueryInterfacePromiseTests.swift in Sources */, - 5698ACD41DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */, - 56AFCA8C1CB1ABC800F48B96 /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */, - 564448891EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */, - 56AFCA8D1CB1ABC800F48B96 /* RowFromDictionaryTests.swift in Sources */, - 5657AB541D108BA9006283EF /* FoundationNSNumberTests.swift in Sources */, - 562EA82C1F17B2AC00FA528C /* CompilationProtocolTests.swift in Sources */, - 56DAA2D81DE99DAB006E10C8 /* DatabaseCursorTests.swift in Sources */, - 5698AC4F1DA2D48A0056AF8C /* FTS3RecordTests.swift in Sources */, - 56AFCA8F1CB1ABC800F48B96 /* DatabaseCollationTests.swift in Sources */, - 567E55F41D2BDDFF00CC6F79 /* EncryptionTests.swift in Sources */, - 56AFCA901CB1ABC800F48B96 /* StatementColumnConvertibleFetchTests.swift in Sources */, - 5690C33D1D23E7D200E59934 /* FoundationDateTests.swift in Sources */, - 5672DE6C1CDB751D0022BA81 /* DatabasePoolBackupTests.swift in Sources */, - 56CC9241201E034200CB597E /* PrefixWhileCursorTests.swift in Sources */, - 565F03C71CE5D3AA00DE108F /* RowAdapterTests.swift in Sources */, - 56AFCA911CB1ABC800F48B96 /* QueryInterfaceExpressionsTests.swift in Sources */, - 56AFCA921CB1ABC800F48B96 /* SelectStatementTests.swift in Sources */, - 56AFCA931CB1ABC800F48B96 /* UpdateStatementTests.swift in Sources */, - 5653EBE320961FE800F46237 /* AssociationBelongsToSQLTests.swift in Sources */, - 563B06FD21861D8B00B38F35 /* ValueObservationCountTests.swift in Sources */, - 56AFCA941CB1ABC800F48B96 /* DatabaseMigratorTests.swift in Sources */, - 56EA63CF209C7F31009715B8 /* DerivableRequestTests.swift in Sources */, - 5657AB641D108BA9006283EF /* FoundationNSURLTests.swift in Sources */, - 56FF455C1D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift in Sources */, - 56AFCA971CB1ABC800F48B96 /* DatabasePoolCollationTests.swift in Sources */, - 5674A7151F3087710095F066 /* DatabaseValueConvertibleDecodableTests.swift in Sources */, - 563B070B2186280600B38F35 /* ValueObservationRowTests.swift in Sources */, - 5657AB5C1D108BA9006283EF /* FoundationNSStringTests.swift in Sources */, - 56AFCA981CB1ABC800F48B96 /* RecordPrimaryKeySingleTests.swift in Sources */, - 562393361DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */, - 5653EBDF20961FE800F46237 /* AssociationParallelRowScopesTests.swift in Sources */, - 5698ACDD1DA925430056AF8C /* RowTestCase.swift in Sources */, - 5653EBCF20961FE800F46237 /* AssociationHasOneSQLTests.swift in Sources */, - 562756491E963AAC0035B653 /* DatabaseWriterTests.swift in Sources */, - 56AFCA9B1CB1ABC800F48B96 /* DatabasePoolFunctionTests.swift in Sources */, - 5672DE5E1CDB72520022BA81 /* DatabaseQueueBackupTests.swift in Sources */, - 5653EBE720961FE800F46237 /* AssociationChainSQLTests.swift in Sources */, - 56AFCA9D1CB1ABC800F48B96 /* RowCopiedFromStatementTests.swift in Sources */, - 56AFCA9E1CB1ABC800F48B96 /* DatabaseQueueSchemaCacheTests.swift in Sources */, - 56176C791EACCCCB000F3F2B /* FTS5RecordTests.swift in Sources */, - 567DAF3B1EAB789800FC0928 /* DatabaseLogErrorTests.swift in Sources */, - 56AFCA9F1CB1ABC800F48B96 /* RecordPrimaryKeyMultipleTests.swift in Sources */, - 5665FA252129D81F004D8612 /* DatabaseDateDecodingStrategyTests.swift in Sources */, - 569C1EB71CF07DDD0042627B /* SchedulingWatchdogTests.swift in Sources */, - 56AFCAA01CB1ABC800F48B96 /* RowFromStatementTests.swift in Sources */, - 5690C32C1D23E6D800E59934 /* FoundationDateComponentsTests.swift in Sources */, - 56CC925A201E094F00CB597E /* PrefixCursorTests.swift in Sources */, - 56AFCAA21CB1ABC800F48B96 /* StatementArgumentsTests.swift in Sources */, - 56AFCAA31CB1ABC800F48B96 /* RecordInitializersTests.swift in Sources */, - 56CC9239201E009A00CB597E /* DropWhileCursorTests.swift in Sources */, - 56D507641F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift in Sources */, - 56176C7B1EACCCCB000F3F2B /* FTS5TokenizerTests.swift in Sources */, - 563B06F02185E07300B38F35 /* ValueObservationReducerTests.swift in Sources */, - 566AD8CC1D531BEE002EC1A8 /* TableDefinitionTests.swift in Sources */, - 563B06E82185E07300B38F35 /* ValueObservationReadonlyTests.swift in Sources */, - 56AFCAA41CB1ABC800F48B96 /* MutablePersistableRecordTests.swift in Sources */, - 567F45AE1F888B2600030B59 /* TruncateOptimizationTests.swift in Sources */, - 56AFCAA51CB1ABC800F48B96 /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */, - 56AFCAA61CB1ABC800F48B96 /* DatabasePoolReadOnlyTests.swift in Sources */, - 56176C771EACCCCB000F3F2B /* FTS5CustomTokenizerTests.swift in Sources */, - 563B071021862C3600B38F35 /* ValueObservationRecordTests.swift in Sources */, - 56B6EF67208CB762002F0ACB /* ColumnExpressionTests.swift in Sources */, - 5657AB6C1D108BA9006283EF /* FoundationURLTests.swift in Sources */, - 56AFCAA81CB1ABC800F48B96 /* DataMemoryTests.swift in Sources */, - 56AFCAA91CB1ABC800F48B96 /* RecordCopyTests.swift in Sources */, - 56A8C24B1D1918F10096E9D4 /* FoundationNSUUIDTests.swift in Sources */, - 56AFCAAB1CB1ABC800F48B96 /* PersistableRecordTests.swift in Sources */, - 56FF45461D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift in Sources */, - 5653EBEB20961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */, - 5698AC9C1DA4B0430056AF8C /* FTS4RecordTests.swift in Sources */, - 56176C781EACCCCB000F3F2B /* FTS5PatternTests.swift in Sources */, - 563B072121862F5D00B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift in Sources */, - 564E73F2203DA2A4000C443C /* JoinSupportTests.swift in Sources */, - 5674A70D1F3087710095F066 /* DatabaseValueConvertibleEncodableTests.swift in Sources */, - 56AFCAAC1CB1ABC800F48B96 /* DatabaseValueConversionTests.swift in Sources */, - 5665F86F203EF47D0084C6C0 /* ColumnInfoTests.swift in Sources */, - 5698ACBC1DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */, - 5657AB441D108BA9006283EF /* FoundationNSDataTests.swift in Sources */, - 5623935D1DEE013C00A6B01F /* FilterCursorTests.swift in Sources */, - 56741EAE1E66A8B3003E422D /* FetchRequestTests.swift in Sources */, - 5653EBBB20961FE800F46237 /* AssociationParallelSQLTests.swift in Sources */, - 56176C7C1EACCCCB000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */, - 5698AC861DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */, - 5613EDA121A96A6F00DC7A68 /* ValueObservationCombineTests.swift in Sources */, - 5653EBBF20961FE800F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */, - 5698AC461DA2BED90056AF8C /* FTS3PatternTests.swift in Sources */, - 56AF74711D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */, - 5674A7281F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */, - 56AFCAAE1CB1ABC800F48B96 /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */, - 56FEE8011F47253700D930EA /* TableRecordTests.swift in Sources */, - 56F3E74F1E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */, - 56AFCAAF1CB1ABC800F48B96 /* DatabasePoolConcurrencyTests.swift in Sources */, - 56AFCAB01CB1ABC800F48B96 /* TransactionObserverTests.swift in Sources */, - 56AFCAB11CB1ABC800F48B96 /* Row+FoundationTests.swift in Sources */, - 56A4CDB61D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift in Sources */, - 5657AB4C1D108BA9006283EF /* FoundationNSNullTests.swift in Sources */, - 56AFCAB31CB1ABC800F48B96 /* RecordSubClassTests.swift in Sources */, - 5653EBEF20961FE800F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */, - 56AFCAB41CB1ABC800F48B96 /* DatabaseValueTests.swift in Sources */, - 5657AB3C1D108BA9006283EF /* FoundationDataTests.swift in Sources */, - 5653EBD320961FE800F46237 /* AssociationRowScopeSearchTests.swift in Sources */, - 563B06E42185E07300B38F35 /* ValueObservationExtentTests.swift in Sources */, - 5634B10C1CF9B970005360B9 /* TransactionObserverSavepointsTests.swift in Sources */, - 5665FA442129EEEF004D8612 /* DatabaseDateEncodingStrategyTests.swift in Sources */, - 563B06F42185E07300B38F35 /* ValueObservationSchedulingTests.swift in Sources */, - 5644DE8520F8D1E4001FFDDE /* DatabaseValueConversionErrorTests.swift in Sources */, - 56AFCAB51CB1ABC800F48B96 /* DatabaseQueueReadOnlyTests.swift in Sources */, - 56AFCAB61CB1ABC800F48B96 /* DatabaseReaderTests.swift in Sources */, - 56CC924F201E059100CB597E /* DropFirstCursorTests.swift in Sources */, - 56AFCAB71CB1ABC800F48B96 /* FetchableRecordTests.swift in Sources */, - 56B15D0D1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift in Sources */, - 56A5EF151EF7F20B00F03071 /* ForeignKeyInfoTests.swift in Sources */, - 563EF44821613213007DAACD /* AssociationAggregateTests.swift in Sources */, - 5653EBDB20961FE800F46237 /* AssociationChainRowScopesTests.swift in Sources */, - 5623931E1DECC02000A6B01F /* RowFetchTests.swift in Sources */, - 5653EBCB20961FE800F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */, - 56AFCAB81CB1ABC800F48B96 /* DatabaseValueConvertibleFetchTests.swift in Sources */, - 5698AC8F1DA389380056AF8C /* FTS3TableBuilderTests.swift in Sources */, - 5653EBC720961FE800F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */, - 564CE5C421B8FFD800652B19 /* DatabaseRegionObservationTests.swift in Sources */, - 56AFCAB91CB1ABC800F48B96 /* RecordPrimaryKeyRowIDTests.swift in Sources */, - 564CE4EF21B2E08300652B19 /* ValueObservationCompactMapTests.swift in Sources */, - 56AFCABA1CB1ABC800F48B96 /* RecordEditedTests.swift in Sources */, - 56AFCABB1CB1ABC800F48B96 /* DatabasePoolSchemaCacheTests.swift in Sources */, - 564F9C241F069B4E00877A00 /* DatabaseAggregateTests.swift in Sources */, - 56AFCABC1CB1ABC800F48B96 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */, - 5623936F1DEE0CD200A6B01F /* FlattenCursorTests.swift in Sources */, - 56176C7A1EACCCCB000F3F2B /* FTS5TableBuilderTests.swift in Sources */, - 561667071D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift in Sources */, - 5698AC091D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */, - 56AFCABD1CB1ABC800F48B96 /* DatabaseValueConvertibleSubclassTests.swift in Sources */, - 563B06EC2185E07300B38F35 /* ValueObservationFetchTests.swift in Sources */, - 56AFCABE1CB1ABC800F48B96 /* DatabaseErrorTests.swift in Sources */, - 56AFCABF1CB1ABC800F48B96 /* DatabaseQueueReleaseMemoryTests.swift in Sources */, - 56AFCAC01CB1ABC800F48B96 /* DatabasePoolReleaseMemoryTests.swift in Sources */, - 56AFCAC11CB1ABC800F48B96 /* RecordMinimalPrimaryKeySingleTests.swift in Sources */, - 566A84492041AB3900E50BFD /* MutablePersistableRecordChangesTests.swift in Sources */, - 56B14E851D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift in Sources */, - 567032A2212B546E007D270F /* DatabaseUUIDEncodingStrategyTests.swift in Sources */, - 56AFCAC41CB1ABC800F48B96 /* DatabaseTimestampTests.swift in Sources */, - 568068371EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */, - 56AFCAC51CB1ABC800F48B96 /* StatementArguments+FoundationTests.swift in Sources */, - 562393661DEE06D300A6B01F /* CursorTests.swift in Sources */, - 56AFCAC61CB1ABC800F48B96 /* TableRecord+QueryInterfaceRequestTests.swift in Sources */, - 56AFCAC71CB1ABC800F48B96 /* FoundationNSDateTests.swift in Sources */, - 56AFCAC81CB1ABC800F48B96 /* DatabaseTests.swift in Sources */, - 5674A71E1F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift in Sources */, - 564CE4F421B2E08A00652B19 /* ValueObservationMapTests.swift in Sources */, - 56AFCAC91CB1ABC800F48B96 /* QueryInterfaceRequestTests.swift in Sources */, - 5691784B1CED9B6000E179EA /* DatabaseQueueTests.swift in Sources */, - 56AFCACB1CB1ABC800F48B96 /* DatabaseFunctionTests.swift in Sources */, - 56A8C24C1D1918F10096E9D4 /* FoundationUUIDTests.swift in Sources */, - 56AFCACC1CB1ABC800F48B96 /* DatabaseQueueInMemoryTests.swift in Sources */, - 56AFCACD1CB1ABC800F48B96 /* RecordWithColumnNameManglingTests.swift in Sources */, - 56AFCACE1CB1ABC800F48B96 /* CGFloatTests.swift in Sources */, - 5653EBD720961FE800F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */, - 6340BF861E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift in Sources */, - 567A80591D41350C00C7DCEC /* IndexInfoTests.swift in Sources */, - 562393541DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */, - 56AFCACF1CB1ABC800F48B96 /* DatabaseRegionTests.swift in Sources */, - 56AFCAD01CB1ABC800F48B96 /* GRDBTestCase.swift in Sources */, - 5698ACA41DA4B0430056AF8C /* FTS4TableBuilderTests.swift in Sources */, - 566A843320413DD000E50BFD /* DatabaseSnapshotTests.swift in Sources */, - 565EFAF41D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXTargetDependency section */ - 5671561A1CB16729007DC145 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 560FC5191CB003810014AA8E /* GRDBCipherOSX */; - targetProxy = 5671561B1CB16729007DC145 /* PBXContainerItemProxy */; - }; - 568BE5221CB0371000270F93 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 560FC5191CB003810014AA8E /* GRDBCipherOSX */; - targetProxy = 568BE5211CB0371000270F93 /* PBXContainerItemProxy */; - }; - 56AFC9781CB1A3E200F48B96 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = sqlcipher; - targetProxy = 56AFC9771CB1A3E200F48B96 /* PBXContainerItemProxy */; - }; - 56AFCA261CB1A96A00F48B96 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = sqlcipher; - targetProxy = 56AFCA251CB1A96A00F48B96 /* PBXContainerItemProxy */; - }; - 56AFCA821CB1AAB400F48B96 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 56AFC9EE1CB1A8BB00F48B96 /* GRDBCipheriOS */; - targetProxy = 56AFCA811CB1AAB400F48B96 /* PBXContainerItemProxy */; - }; - 56AFCA851CB1ABC800F48B96 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 56AFC9EE1CB1A8BB00F48B96 /* GRDBCipheriOS */; - targetProxy = 56AFCA861CB1ABC800F48B96 /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - -/* Begin XCBuildConfiguration section */ - 560FC54B1CB003810014AA8E /* Debug */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 568BE51F1CB0360500270F93 /* GRDBCipher.xcconfig */; - buildSettings = { - APPLICATION_EXTENSION_API_ONLY = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - COMBINE_HIDPI_IMAGES = YES; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - SKIP_INSTALL = YES; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - }; - name = Debug; - }; - 560FC54C1CB003810014AA8E /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 568BE51F1CB0360500270F93 /* GRDBCipher.xcconfig */; - buildSettings = { - APPLICATION_EXTENSION_API_ONLY = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - COMBINE_HIDPI_IMAGES = YES; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - SKIP_INSTALL = YES; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - }; - name = Release; - }; - 560FC5AE1CB00B880014AA8E /* Debug */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 56C494411ED7269800CC72AF /* GRDBDeploymentTarget.xcconfig */; - buildSettings = { - CLANG_ENABLE_OBJC_WEAK = YES; - COMBINE_HIDPI_IMAGES = YES; - DEBUG_INFORMATION_FORMAT = dwarf; - GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - OTHER_SWIFT_FLAGS = "-D USING_BUILTIN_SQLITE -D GRDBCIPHER -D SQLITE_HAS_CODEC -D SQLITE_ENABLE_FTS5"; - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBCipherOSXTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - }; - name = Debug; - }; - 560FC5AF1CB00B880014AA8E /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 56C494411ED7269800CC72AF /* GRDBDeploymentTarget.xcconfig */; - buildSettings = { - CLANG_ENABLE_OBJC_WEAK = YES; - COMBINE_HIDPI_IMAGES = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - OTHER_SWIFT_FLAGS = "-D USING_BUILTIN_SQLITE -D GRDBCIPHER -D SQLITE_HAS_CODEC -D SQLITE_ENABLE_FTS5"; - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBCipherOSXTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - }; - name = Release; - }; - 5671566A1CB16729007DC145 /* Debug */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 56C494411ED7269800CC72AF /* GRDBDeploymentTarget.xcconfig */; - buildSettings = { - CLANG_ENABLE_OBJC_WEAK = YES; - COMBINE_HIDPI_IMAGES = YES; - DEBUG_INFORMATION_FORMAT = dwarf; - GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - OTHER_SWIFT_FLAGS = "-D USING_BUILTIN_SQLITE -D GRDBCIPHER -D GRDBCIPHER_USE_ENCRYPTION -D SQLITE_HAS_CODEC -D SQLITE_ENABLE_FTS5"; - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBCipherOSXTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - }; - name = Debug; - }; - 5671566B1CB16729007DC145 /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 56C494411ED7269800CC72AF /* GRDBDeploymentTarget.xcconfig */; - buildSettings = { - CLANG_ENABLE_OBJC_WEAK = YES; - COMBINE_HIDPI_IMAGES = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - OTHER_SWIFT_FLAGS = "-D USING_BUILTIN_SQLITE -D GRDBCIPHER -D GRDBCIPHER_USE_ENCRYPTION -D SQLITE_HAS_CODEC -D SQLITE_ENABLE_FTS5"; - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBCipherOSXTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - }; - name = Release; - }; - 56AFCA211CB1A8BB00F48B96 /* Debug */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 568BE51F1CB0360500270F93 /* GRDBCipher.xcconfig */; - buildSettings = { - APPLICATION_EXTENSION_API_ONLY = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; - DEBUG_INFORMATION_FORMAT = dwarf; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - GCC_NO_COMMON_BLOCKS = YES; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - SDKROOT = iphoneos; - SKIP_INSTALL = YES; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; - 56AFCA221CB1A8BB00F48B96 /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 568BE51F1CB0360500270F93 /* GRDBCipher.xcconfig */; - buildSettings = { - APPLICATION_EXTENSION_API_ONLY = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - GCC_NO_COMMON_BLOCKS = YES; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - SDKROOT = iphoneos; - SKIP_INSTALL = YES; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Release; - }; - 56AFCA7D1CB1AA9900F48B96 /* Debug */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 56C494411ED7269800CC72AF /* GRDBDeploymentTarget.xcconfig */; - buildSettings = { - CLANG_ENABLE_OBJC_WEAK = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - DEBUG_INFORMATION_FORMAT = dwarf; - GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - OTHER_SWIFT_FLAGS = "-D USING_BUILTIN_SQLITE -D GRDBCIPHER -D SQLITE_HAS_CODEC -D SQLITE_ENABLE_FTS5"; - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBCipheriOSTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = iphoneos; - }; - name = Debug; - }; - 56AFCA7E1CB1AA9900F48B96 /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 56C494411ED7269800CC72AF /* GRDBDeploymentTarget.xcconfig */; - buildSettings = { - CLANG_ENABLE_OBJC_WEAK = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - OTHER_SWIFT_FLAGS = "-D USING_BUILTIN_SQLITE -D GRDBCIPHER -D SQLITE_HAS_CODEC -D SQLITE_ENABLE_FTS5"; - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBCipheriOSTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = iphoneos; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - }; - name = Release; - }; - 56AFCAD51CB1ABC800F48B96 /* Debug */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 56C494411ED7269800CC72AF /* GRDBDeploymentTarget.xcconfig */; - buildSettings = { - CLANG_ENABLE_OBJC_WEAK = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - DEBUG_INFORMATION_FORMAT = dwarf; - GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - OTHER_SWIFT_FLAGS = "-D USING_BUILTIN_SQLITE -D GRDBCIPHER -D SQLITE_HAS_CODEC -D GRDBCIPHER_USE_ENCRYPTION -D SQLITE_ENABLE_FTS5"; - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBCipheriOSEncryptedTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = iphoneos; - }; - name = Debug; - }; - 56AFCAD61CB1ABC800F48B96 /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 56C494411ED7269800CC72AF /* GRDBDeploymentTarget.xcconfig */; - buildSettings = { - CLANG_ENABLE_OBJC_WEAK = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - OTHER_SWIFT_FLAGS = "-D USING_BUILTIN_SQLITE -D GRDBCIPHER -D SQLITE_HAS_CODEC -D GRDBCIPHER_USE_ENCRYPTION -D SQLITE_ENABLE_FTS5"; - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBCipheriOSEncryptedTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = iphoneos; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - }; - name = Release; - }; - DC37740719C8CBB3004FCF85 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Debug; - }; - DC37740819C8CBB3004FCF85 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = YES; - CURRENT_PROJECT_VERSION = 1; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MTL_ENABLE_DEBUG_INFO = NO; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.0; - VALIDATE_PRODUCT = YES; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 560FC54A1CB003810014AA8E /* Build configuration list for PBXNativeTarget "GRDBCipherOSX" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 560FC54B1CB003810014AA8E /* Debug */, - 560FC54C1CB003810014AA8E /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 560FC5AD1CB00B880014AA8E /* Build configuration list for PBXNativeTarget "GRDBCipherOSXTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 560FC5AE1CB00B880014AA8E /* Debug */, - 560FC5AF1CB00B880014AA8E /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 567156691CB16729007DC145 /* Build configuration list for PBXNativeTarget "GRDBCipherOSXEncryptedTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 5671566A1CB16729007DC145 /* Debug */, - 5671566B1CB16729007DC145 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 56AFCA201CB1A8BB00F48B96 /* Build configuration list for PBXNativeTarget "GRDBCipheriOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 56AFCA211CB1A8BB00F48B96 /* Debug */, - 56AFCA221CB1A8BB00F48B96 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 56AFCA7C1CB1AA9900F48B96 /* Build configuration list for PBXNativeTarget "GRDBCipheriOSTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 56AFCA7D1CB1AA9900F48B96 /* Debug */, - 56AFCA7E1CB1AA9900F48B96 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 56AFCAD41CB1ABC800F48B96 /* Build configuration list for PBXNativeTarget "GRDBCipheriOSEncryptedTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 56AFCAD51CB1ABC800F48B96 /* Debug */, - 56AFCAD61CB1ABC800F48B96 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - DC3773ED19C8CBB3004FCF85 /* Build configuration list for PBXProject "GRDBCipher" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - DC37740719C8CBB3004FCF85 /* Debug */, - DC37740819C8CBB3004FCF85 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = DC3773EA19C8CBB3004FCF85 /* Project object */; -} diff --git a/GRDBCustom.xcodeproj/project.pbxproj b/GRDBCustom.xcodeproj/project.pbxproj index 3fc2177d0..3a9f1b1bf 100755 --- a/GRDBCustom.xcodeproj/project.pbxproj +++ b/GRDBCustom.xcodeproj/project.pbxproj @@ -7,6 +7,16 @@ objects = { /* Begin PBXBuildFile section */ + 56043296228F00A9009D3FE2 /* OrderedDictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56043295228F00A9009D3FE2 /* OrderedDictionaryTests.swift */; }; + 56043297228F00A9009D3FE2 /* OrderedDictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56043295228F00A9009D3FE2 /* OrderedDictionaryTests.swift */; }; + 560432A6228F167A009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560432A5228F167A009D3FE2 /* AssociationPrefetchingObservationTests.swift */; }; + 560432A7228F167A009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560432A5228F167A009D3FE2 /* AssociationPrefetchingObservationTests.swift */; }; + 56057C592291B18E00A7CB10 /* AssociationHasManyRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56057C572291B18E00A7CB10 /* AssociationHasManyRowScopeTests.swift */; }; + 56057C5A2291B18E00A7CB10 /* AssociationHasManyRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56057C572291B18E00A7CB10 /* AssociationHasManyRowScopeTests.swift */; }; + 56057C652291C7E500A7CB10 /* AssociationHasManyThroughRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56057C642291C7E500A7CB10 /* AssociationHasManyThroughRowScopeTests.swift */; }; + 56057C662291C7E500A7CB10 /* AssociationHasManyThroughRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56057C642291C7E500A7CB10 /* AssociationHasManyThroughRowScopeTests.swift */; }; + 560714ED227DD10F0091BB10 /* AssociationPrefetchingSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560714EB227DD10F0091BB10 /* AssociationPrefetchingSQLTests.swift */; }; + 560714EE227DD10F0091BB10 /* AssociationPrefetchingSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560714EB227DD10F0091BB10 /* AssociationPrefetchingSQLTests.swift */; }; 56071A501DB54ED300CA6E47 /* FetchedRecordsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B15D0A1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift */; }; 5613ED6121A95E6100DC7A68 /* ValueObservation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED5921A95E6100DC7A68 /* ValueObservation.swift */; }; 5613ED6221A95E6100DC7A68 /* ValueObservation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED5921A95E6100DC7A68 /* ValueObservation.swift */; }; @@ -26,10 +36,20 @@ 5613ED7021A95E6100DC7A68 /* ValueObservation+Count.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED6021A95E6100DC7A68 /* ValueObservation+Count.swift */; }; 5613EDA321A96A8100DC7A68 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613EDA221A96A8000DC7A68 /* ValueObservationCombineTests.swift */; }; 5613EDA421A96A8100DC7A68 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613EDA221A96A8000DC7A68 /* ValueObservationCombineTests.swift */; }; + 561408A0221596A100DAD589 /* GRDB-4.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5614089E221596A100DAD589 /* GRDB-4.0.swift */; }; + 561408A1221596A100DAD589 /* GRDB-4.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5614089E221596A100DAD589 /* GRDB-4.0.swift */; }; + 5615B258222AE19100061C1C /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B256222AE19100061C1C /* AssociationHasOneThroughSQLDerivationTests.swift */; }; + 5615B259222AE19100061C1C /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B256222AE19100061C1C /* AssociationHasOneThroughSQLDerivationTests.swift */; }; + 5615B26D222AFEB300061C1C /* AssociationHasOneThroughRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B26C222AFEB300061C1C /* AssociationHasOneThroughRowScopeTests.swift */; }; + 5615B26E222AFEB300061C1C /* AssociationHasOneThroughRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B26C222AFEB300061C1C /* AssociationHasOneThroughRowScopeTests.swift */; }; + 5615B278222B109600061C1C /* AssociationHasOneThroughFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B277222B109500061C1C /* AssociationHasOneThroughFetchableRecordTests.swift */; }; + 5615B279222B109600061C1C /* AssociationHasOneThroughFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B277222B109500061C1C /* AssociationHasOneThroughFetchableRecordTests.swift */; }; + 5615B285222B17BA00061C1C /* AssociationHasOneThroughDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B284222B17B900061C1C /* AssociationHasOneThroughDecodableRecordTests.swift */; }; + 5615B286222B17BA00061C1C /* AssociationHasOneThroughDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B284222B17B900061C1C /* AssociationHasOneThroughDecodableRecordTests.swift */; }; 561667041D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 561667001D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift */; }; 561667081D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 561667001D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift */; }; - 5616AAF6207CD59400AC3664 /* RequestProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5616AAF4207CD59300AC3664 /* RequestProtocols.swift */; }; - 5616AAF7207CD59400AC3664 /* RequestProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5616AAF4207CD59300AC3664 /* RequestProtocols.swift */; }; + 561729552235340E0006E219 /* EncodableRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 561729532235340E0006E219 /* EncodableRecord.swift */; }; + 561729562235340E0006E219 /* EncodableRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 561729532235340E0006E219 /* EncodableRecord.swift */; }; 56176C7E1EACCD2F000F3F2B /* EncryptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567156701CB18050007DC145 /* EncryptionTests.swift */; }; 56176C801EACCD31000F3F2B /* EncryptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567156701CB18050007DC145 /* EncryptionTests.swift */; }; 562205FA1E420E49005860AC /* DatabasePoolReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363CF1C943D13000BE133 /* DatabasePoolReleaseMemoryTests.swift */; }; @@ -81,8 +101,6 @@ 563B071C21862F5600B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B071A21862F5600B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift */; }; 563EF420215F8A76007DAACD /* OrderedDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF41E215F8A76007DAACD /* OrderedDictionary.swift */; }; 563EF421215F8A76007DAACD /* OrderedDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF41E215F8A76007DAACD /* OrderedDictionary.swift */; }; - 563EF4382161182C007DAACD /* AssociationAggregate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF4362161182C007DAACD /* AssociationAggregate.swift */; }; - 563EF4392161182C007DAACD /* AssociationAggregate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF4362161182C007DAACD /* AssociationAggregate.swift */; }; 563EF442216131F5007DAACD /* AssociationAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF441216131F5007DAACD /* AssociationAggregateTests.swift */; }; 563EF443216131F5007DAACD /* AssociationAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF441216131F5007DAACD /* AssociationAggregateTests.swift */; }; 563EF44D2161F196007DAACD /* Inflections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563EF44C2161F196007DAACD /* Inflections.swift */; }; @@ -117,20 +135,6 @@ 564F9C251F069B4E00877A00 /* DatabaseAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C1D1F069B4E00877A00 /* DatabaseAggregateTests.swift */; }; 564F9C301F07611500877A00 /* DatabaseFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */; }; 564F9C331F07611800877A00 /* DatabaseFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */; }; - 5653EB4120961F6100F46237 /* BelongsToAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3720961F6000F46237 /* BelongsToAssociation.swift */; }; - 5653EB4220961F6100F46237 /* BelongsToAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3720961F6000F46237 /* BelongsToAssociation.swift */; }; - 5653EB4320961F6100F46237 /* HasOneAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3820961F6000F46237 /* HasOneAssociation.swift */; }; - 5653EB4420961F6100F46237 /* HasOneAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3820961F6000F46237 /* HasOneAssociation.swift */; }; - 5653EB4720961F6100F46237 /* HasManyAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3A20961F6000F46237 /* HasManyAssociation.swift */; }; - 5653EB4820961F6100F46237 /* HasManyAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3A20961F6000F46237 /* HasManyAssociation.swift */; }; - 5653EB4920961F6100F46237 /* ForeignKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3B20961F6000F46237 /* ForeignKey.swift */; }; - 5653EB4A20961F6100F46237 /* ForeignKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3B20961F6000F46237 /* ForeignKey.swift */; }; - 5653EB4B20961F6100F46237 /* ForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3C20961F6000F46237 /* ForeignKeyRequest.swift */; }; - 5653EB4C20961F6100F46237 /* ForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3C20961F6000F46237 /* ForeignKeyRequest.swift */; }; - 5653EB4F20961F6100F46237 /* Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3E20961F6100F46237 /* Association.swift */; }; - 5653EB5020961F6100F46237 /* Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3E20961F6100F46237 /* Association.swift */; }; - 5653EB5420961F7D00F46237 /* QueryInterfaceRequest+Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5320961F7D00F46237 /* QueryInterfaceRequest+Association.swift */; }; - 5653EB5520961F7D00F46237 /* QueryInterfaceRequest+Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5320961F7D00F46237 /* QueryInterfaceRequest+Association.swift */; }; 5653EB6820961FB200F46237 /* AssociationParallelSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5820961FB000F46237 /* AssociationParallelSQLTests.swift */; }; 5653EB6920961FB200F46237 /* AssociationParallelSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5820961FB000F46237 /* AssociationParallelSQLTests.swift */; }; 5653EB6A20961FB200F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5920961FB100F46237 /* AssociationBelongsToFetchableRecordTests.swift */; }; @@ -159,8 +163,84 @@ 5653EB8120961FB200F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB6420961FB200F46237 /* AssociationBelongsToDecodableRecordTests.swift */; }; 5653EB8220961FB200F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB6520961FB200F46237 /* AssociationBelongsToRowScopeTests.swift */; }; 5653EB8320961FB200F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB6520961FB200F46237 /* AssociationBelongsToRowScopeTests.swift */; }; - 5653EC082098737400F46237 /* SQLGenerationContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EC072098737400F46237 /* SQLGenerationContext.swift */; }; - 5653EC092098737400F46237 /* SQLGenerationContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EC072098737400F46237 /* SQLGenerationContext.swift */; }; + 5656A7F622946B1B001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A7F422946B1B001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */; }; + 5656A7F722946B1B001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A7F422946B1B001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */; }; + 5656A8512295BD56001FF3FF /* SQLInterpolation+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8262295BD56001FF3FF /* SQLInterpolation+QueryInterface.swift */; }; + 5656A8522295BD56001FF3FF /* SQLInterpolation+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8262295BD56001FF3FF /* SQLInterpolation+QueryInterface.swift */; }; + 5656A8552295BD56001FF3FF /* FTS5+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8282295BD56001FF3FF /* FTS5+QueryInterface.swift */; }; + 5656A8562295BD56001FF3FF /* FTS5+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8282295BD56001FF3FF /* FTS5+QueryInterface.swift */; }; + 5656A8572295BD56001FF3FF /* SQLQueryGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A82A2295BD56001FF3FF /* SQLQueryGenerator.swift */; }; + 5656A8582295BD56001FF3FF /* SQLQueryGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A82A2295BD56001FF3FF /* SQLQueryGenerator.swift */; }; + 5656A8592295BD56001FF3FF /* SQLGenerationContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A82B2295BD56001FF3FF /* SQLGenerationContext.swift */; }; + 5656A85A2295BD56001FF3FF /* SQLGenerationContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A82B2295BD56001FF3FF /* SQLGenerationContext.swift */; }; + 5656A85B2295BD56001FF3FF /* TableDefinition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A82D2295BD56001FF3FF /* TableDefinition.swift */; }; + 5656A85C2295BD56001FF3FF /* TableDefinition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A82D2295BD56001FF3FF /* TableDefinition.swift */; }; + 5656A85D2295BD56001FF3FF /* VirtualTableModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A82E2295BD56001FF3FF /* VirtualTableModule.swift */; }; + 5656A85E2295BD56001FF3FF /* VirtualTableModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A82E2295BD56001FF3FF /* VirtualTableModule.swift */; }; + 5656A85F2295BD56001FF3FF /* FTS3+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A82F2295BD56001FF3FF /* FTS3+QueryInterface.swift */; }; + 5656A8602295BD56001FF3FF /* FTS3+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A82F2295BD56001FF3FF /* FTS3+QueryInterface.swift */; }; + 5656A8612295BD56001FF3FF /* TableRecord+Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8312295BD56001FF3FF /* TableRecord+Association.swift */; }; + 5656A8622295BD56001FF3FF /* TableRecord+Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8312295BD56001FF3FF /* TableRecord+Association.swift */; }; + 5656A8632295BD56001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8322295BD56001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift */; }; + 5656A8642295BD56001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8322295BD56001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift */; }; + 5656A8652295BD56001FF3FF /* BelongsToAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8342295BD56001FF3FF /* BelongsToAssociation.swift */; }; + 5656A8662295BD56001FF3FF /* BelongsToAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8342295BD56001FF3FF /* BelongsToAssociation.swift */; }; + 5656A8672295BD56001FF3FF /* HasOneAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8352295BD56001FF3FF /* HasOneAssociation.swift */; }; + 5656A8682295BD56001FF3FF /* HasOneAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8352295BD56001FF3FF /* HasOneAssociation.swift */; }; + 5656A8692295BD56001FF3FF /* AssociationAggregate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8362295BD56001FF3FF /* AssociationAggregate.swift */; }; + 5656A86A2295BD56001FF3FF /* AssociationAggregate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8362295BD56001FF3FF /* AssociationAggregate.swift */; }; + 5656A86B2295BD56001FF3FF /* HasManyAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8372295BD56001FF3FF /* HasManyAssociation.swift */; }; + 5656A86C2295BD56001FF3FF /* HasManyAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8372295BD56001FF3FF /* HasManyAssociation.swift */; }; + 5656A86D2295BD56001FF3FF /* HasManyThroughAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8382295BD56001FF3FF /* HasManyThroughAssociation.swift */; }; + 5656A86E2295BD56001FF3FF /* HasManyThroughAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8382295BD56001FF3FF /* HasManyThroughAssociation.swift */; }; + 5656A86F2295BD56001FF3FF /* Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8392295BD56001FF3FF /* Association.swift */; }; + 5656A8702295BD56001FF3FF /* Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8392295BD56001FF3FF /* Association.swift */; }; + 5656A8712295BD56001FF3FF /* HasOneThroughAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A83A2295BD56001FF3FF /* HasOneThroughAssociation.swift */; }; + 5656A8722295BD56001FF3FF /* HasOneThroughAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A83A2295BD56001FF3FF /* HasOneThroughAssociation.swift */; }; + 5656A8732295BD56001FF3FF /* QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A83B2295BD56001FF3FF /* QueryInterfaceRequest.swift */; }; + 5656A8742295BD56001FF3FF /* QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A83B2295BD56001FF3FF /* QueryInterfaceRequest.swift */; }; + 5656A8752295BD56001FF3FF /* RequestProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A83C2295BD56001FF3FF /* RequestProtocols.swift */; }; + 5656A8762295BD56001FF3FF /* RequestProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A83C2295BD56001FF3FF /* RequestProtocols.swift */; }; + 5656A8772295BD56001FF3FF /* TableRecord+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A83D2295BD56001FF3FF /* TableRecord+QueryInterfaceRequest.swift */; }; + 5656A8782295BD56001FF3FF /* TableRecord+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A83D2295BD56001FF3FF /* TableRecord+QueryInterfaceRequest.swift */; }; + 5656A8792295BD56001FF3FF /* Row+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A83E2295BD56001FF3FF /* Row+QueryInterfaceRequest.swift */; }; + 5656A87A2295BD56001FF3FF /* Row+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A83E2295BD56001FF3FF /* Row+QueryInterfaceRequest.swift */; }; + 5656A87B2295BD56001FF3FF /* QueryInterfaceRequest+Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A83F2295BD56001FF3FF /* QueryInterfaceRequest+Association.swift */; }; + 5656A87C2295BD56001FF3FF /* QueryInterfaceRequest+Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A83F2295BD56001FF3FF /* QueryInterfaceRequest+Association.swift */; }; + 5656A87D2295BD56001FF3FF /* SQLAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8412295BD56001FF3FF /* SQLAssociation.swift */; }; + 5656A87E2295BD56001FF3FF /* SQLAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8412295BD56001FF3FF /* SQLAssociation.swift */; }; + 5656A87F2295BD56001FF3FF /* SQLForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8422295BD56001FF3FF /* SQLForeignKeyRequest.swift */; }; + 5656A8802295BD56001FF3FF /* SQLForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8422295BD56001FF3FF /* SQLForeignKeyRequest.swift */; }; + 5656A8812295BD56001FF3FF /* SQLCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8432295BD56001FF3FF /* SQLCollection.swift */; }; + 5656A8822295BD56001FF3FF /* SQLCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8432295BD56001FF3FF /* SQLCollection.swift */; }; + 5656A8832295BD56001FF3FF /* SQLExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8442295BD56001FF3FF /* SQLExpression.swift */; }; + 5656A8842295BD56001FF3FF /* SQLExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8442295BD56001FF3FF /* SQLExpression.swift */; }; + 5656A8852295BD56001FF3FF /* SQLOrdering.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8452295BD56001FF3FF /* SQLOrdering.swift */; }; + 5656A8862295BD56001FF3FF /* SQLOrdering.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8452295BD56001FF3FF /* SQLOrdering.swift */; }; + 5656A8872295BD56001FF3FF /* SQLOperators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8462295BD56001FF3FF /* SQLOperators.swift */; }; + 5656A8882295BD56001FF3FF /* SQLOperators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8462295BD56001FF3FF /* SQLOperators.swift */; }; + 5656A8892295BD56001FF3FF /* SQLExpressible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8472295BD56001FF3FF /* SQLExpressible.swift */; }; + 5656A88A2295BD56001FF3FF /* SQLExpressible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8472295BD56001FF3FF /* SQLExpressible.swift */; }; + 5656A88B2295BD56001FF3FF /* SQLExpression+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8482295BD56001FF3FF /* SQLExpression+QueryInterface.swift */; }; + 5656A88C2295BD56001FF3FF /* SQLExpression+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8482295BD56001FF3FF /* SQLExpression+QueryInterface.swift */; }; + 5656A88D2295BD56001FF3FF /* SQLSelectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8492295BD56001FF3FF /* SQLSelectable.swift */; }; + 5656A88E2295BD56001FF3FF /* SQLSelectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8492295BD56001FF3FF /* SQLSelectable.swift */; }; + 5656A88F2295BD56001FF3FF /* Column.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A84A2295BD56001FF3FF /* Column.swift */; }; + 5656A8902295BD56001FF3FF /* Column.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A84A2295BD56001FF3FF /* Column.swift */; }; + 5656A8912295BD56001FF3FF /* SQLSpecificExpressible+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A84B2295BD56001FF3FF /* SQLSpecificExpressible+QueryInterface.swift */; }; + 5656A8922295BD56001FF3FF /* SQLSpecificExpressible+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A84B2295BD56001FF3FF /* SQLSpecificExpressible+QueryInterface.swift */; }; + 5656A8932295BD56001FF3FF /* SQLFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A84C2295BD56001FF3FF /* SQLFunctions.swift */; }; + 5656A8942295BD56001FF3FF /* SQLFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A84C2295BD56001FF3FF /* SQLFunctions.swift */; }; + 5656A8952295BD56001FF3FF /* SQLCollatedExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A84D2295BD56001FF3FF /* SQLCollatedExpression.swift */; }; + 5656A8962295BD56001FF3FF /* SQLCollatedExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A84D2295BD56001FF3FF /* SQLCollatedExpression.swift */; }; + 5656A8972295BD56001FF3FF /* SQLRelation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A84E2295BD56001FF3FF /* SQLRelation.swift */; }; + 5656A8982295BD56001FF3FF /* SQLRelation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A84E2295BD56001FF3FF /* SQLRelation.swift */; }; + 5656A8992295BD56001FF3FF /* SQLSelectable+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A84F2295BD56001FF3FF /* SQLSelectable+QueryInterface.swift */; }; + 5656A89A2295BD56001FF3FF /* SQLSelectable+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A84F2295BD56001FF3FF /* SQLSelectable+QueryInterface.swift */; }; + 5656A89B2295BD56001FF3FF /* SQLQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8502295BD56001FF3FF /* SQLQuery.swift */; }; + 5656A89C2295BD56001FF3FF /* SQLQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8502295BD56001FF3FF /* SQLQuery.swift */; }; + 5656A8A72295BF44001FF3FF /* DatabasePromise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8A52295BF44001FF3FF /* DatabasePromise.swift */; }; + 5656A8A82295BF44001FF3FF /* DatabasePromise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A8A52295BF44001FF3FF /* DatabasePromise.swift */; }; 5657AABB1D107001006283EF /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AAB81D107001006283EF /* NSData.swift */; }; 5657AABE1D107001006283EF /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AAB81D107001006283EF /* NSData.swift */; }; 5657AB111D10899D006283EF /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB0E1D10899D006283EF /* URL.swift */; }; @@ -189,16 +269,6 @@ 5659F4A51EA8D997004A4992 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5659F49F1EA8D997004A4992 /* Result.swift */; }; 565EFAF11D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */; }; 565EFAF51D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */; }; - 5664759C1D97D8A000FF74B8 /* SQLCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475991D97D8A000FF74B8 /* SQLCollection.swift */; }; - 5664759F1D97D8A000FF74B8 /* SQLCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475991D97D8A000FF74B8 /* SQLCollection.swift */; }; - 566475A41D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475A11D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift */; }; - 566475A71D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475A11D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift */; }; - 566475BC1D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475B91D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift */; }; - 566475BF1D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475B91D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift */; }; - 566475CE1D981D5E00FF74B8 /* SQLFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475CA1D981D5E00FF74B8 /* SQLFunctions.swift */; }; - 566475D11D981D5E00FF74B8 /* SQLFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475CA1D981D5E00FF74B8 /* SQLFunctions.swift */; }; - 566475D51D981D5E00FF74B8 /* SQLOperators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475CB1D981D5E00FF74B8 /* SQLOperators.swift */; }; - 566475D81D981D5E00FF74B8 /* SQLOperators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566475CB1D981D5E00FF74B8 /* SQLOperators.swift */; }; 5665F868203EF4640084C6C0 /* ColumnInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5665F865203EF4590084C6C0 /* ColumnInfoTests.swift */; }; 5665F869203EF4650084C6C0 /* ColumnInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5665F865203EF4590084C6C0 /* ColumnInfoTests.swift */; }; 5665FA1E2129D807004D8612 /* DatabaseDateDecodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5665FA1C2129D807004D8612 /* DatabaseDateDecodingStrategyTests.swift */; }; @@ -211,8 +281,6 @@ 566A843620413DE400E50BFD /* DatabaseSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566A843420413DE400E50BFD /* DatabaseSnapshotTests.swift */; }; 566A84432041AB2D00E50BFD /* MutablePersistableRecordChangesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566A84422041AB2D00E50BFD /* MutablePersistableRecordChangesTests.swift */; }; 566A84442041AB2D00E50BFD /* MutablePersistableRecordChangesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566A84422041AB2D00E50BFD /* MutablePersistableRecordChangesTests.swift */; }; - 566AD8B41D5318F4002EC1A8 /* TableDefinition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566AD8B11D5318F4002EC1A8 /* TableDefinition.swift */; }; - 566AD8B71D5318F4002EC1A8 /* TableDefinition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566AD8B11D5318F4002EC1A8 /* TableDefinition.swift */; }; 566AD8C91D531BEB002EC1A8 /* TableDefinitionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566AD8C51D531BE4002EC1A8 /* TableDefinitionTests.swift */; }; 566AD8CD1D531BEE002EC1A8 /* TableDefinitionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566AD8C51D531BE4002EC1A8 /* TableDefinitionTests.swift */; }; 566B910B1FA4C3970012D5B0 /* Database+Statements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566B91081FA4C3960012D5B0 /* Database+Statements.swift */; }; @@ -237,8 +305,8 @@ 5674A6E61F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E31F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift */; }; 5674A6EC1F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E21F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift */; }; 5674A6ED1F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E21F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift */; }; - 5674A6F51F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F31F307F600095F066 /* PersistableRecord+Encodable.swift */; }; - 5674A6F61F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F31F307F600095F066 /* PersistableRecord+Encodable.swift */; }; + 5674A6F51F307F600095F066 /* EncodableRecord+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F31F307F600095F066 /* EncodableRecord+Encodable.swift */; }; + 5674A6F61F307F600095F066 /* EncodableRecord+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F31F307F600095F066 /* EncodableRecord+Encodable.swift */; }; 5674A6FC1F307F600095F066 /* FetchableRecord+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F21F307F600095F066 /* FetchableRecord+Decodable.swift */; }; 5674A6FD1F307F600095F066 /* FetchableRecord+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6F21F307F600095F066 /* FetchableRecord+Decodable.swift */; }; 5674A7041F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A7021F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift */; }; @@ -257,20 +325,22 @@ 567DAF211EAB61ED00FC0928 /* grdb_config.h in Headers */ = {isa = PBXBuildFile; fileRef = 567DAF141EAB61ED00FC0928 /* grdb_config.h */; settings = {ATTRIBUTES = (Private, ); }; }; 567DAF381EAB789800FC0928 /* DatabaseLogErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567DAF341EAB789800FC0928 /* DatabaseLogErrorTests.swift */; }; 567DAF3C1EAB789800FC0928 /* DatabaseLogErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567DAF341EAB789800FC0928 /* DatabaseLogErrorTests.swift */; }; + 567F0B30220F196400D111FB /* SQLInterpolationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567F0B2F220F196300D111FB /* SQLInterpolationTests.swift */; }; + 567F0B31220F196400D111FB /* SQLInterpolationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567F0B2F220F196300D111FB /* SQLInterpolationTests.swift */; }; 567F45AB1F888B2600030B59 /* TruncateOptimizationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567F45A71F888B2600030B59 /* TruncateOptimizationTests.swift */; }; 567F45AF1F888B2600030B59 /* TruncateOptimizationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567F45A71F888B2600030B59 /* TruncateOptimizationTests.swift */; }; 568068341EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 568068301EBBA26100EFB8AA /* SQLRequestTests.swift */; }; 568068381EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 568068301EBBA26100EFB8AA /* SQLRequestTests.swift */; }; - 56873BEE1F2CB400004D24B4 /* Fixits-1.2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */; }; - 56873BF11F2CB400004D24B4 /* Fixits-1.2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */; }; - 568D13152207210400674B58 /* SQLSelectQueryGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 568D13142207210400674B58 /* SQLSelectQueryGenerator.swift */; }; - 568D13162207210400674B58 /* SQLSelectQueryGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 568D13142207210400674B58 /* SQLSelectQueryGenerator.swift */; }; 5690C3291D23E6D800E59934 /* FoundationDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690C3251D23E6D800E59934 /* FoundationDateComponentsTests.swift */; }; 5690C32D1D23E6D800E59934 /* FoundationDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690C3251D23E6D800E59934 /* FoundationDateComponentsTests.swift */; }; 5690C33A1D23E7D200E59934 /* FoundationDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690C3361D23E7D200E59934 /* FoundationDateTests.swift */; }; 5690C33E1D23E7D200E59934 /* FoundationDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690C3361D23E7D200E59934 /* FoundationDateTests.swift */; }; 5690C3421D23E82A00E59934 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690C33F1D23E82A00E59934 /* Data.swift */; }; 5690C3451D23E82A00E59934 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5690C33F1D23E82A00E59934 /* Data.swift */; }; + 56959620222C458A002CB7C9 /* AssociationHasManyThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5695961E222C4589002CB7C9 /* AssociationHasManyThroughSQLTests.swift */; }; + 56959621222C458A002CB7C9 /* AssociationHasManyThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5695961E222C4589002CB7C9 /* AssociationHasManyThroughSQLTests.swift */; }; + 56959636222D058B002CB7C9 /* AssociationHasManySQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56959635222D058B002CB7C9 /* AssociationHasManySQLTests.swift */; }; + 56959637222D058B002CB7C9 /* AssociationHasManySQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56959635222D058B002CB7C9 /* AssociationHasManySQLTests.swift */; }; 5698AC061D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC021D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift */; }; 5698AC0A1D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC021D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift */; }; 5698AC391D9E5A590056AF8C /* FTS3Pattern.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC361D9E5A590056AF8C /* FTS3Pattern.swift */; }; @@ -279,8 +349,6 @@ 5698AC471DA2BED90056AF8C /* FTS3PatternTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC3F1DA2BED90056AF8C /* FTS3PatternTests.swift */; }; 5698AC4C1DA2D48A0056AF8C /* FTS3RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC481DA2D48A0056AF8C /* FTS3RecordTests.swift */; }; 5698AC501DA2D48A0056AF8C /* FTS3RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC481DA2D48A0056AF8C /* FTS3RecordTests.swift */; }; - 5698AC7A1DA37DCB0056AF8C /* VirtualTableModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC771DA37DCB0056AF8C /* VirtualTableModule.swift */; }; - 5698AC7D1DA37DCB0056AF8C /* VirtualTableModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC771DA37DCB0056AF8C /* VirtualTableModule.swift */; }; 5698AC831DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC7F1DA380A20056AF8C /* VirtualTableModuleTests.swift */; }; 5698AC871DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC7F1DA380A20056AF8C /* VirtualTableModuleTests.swift */; }; 5698AC8C1DA389380056AF8C /* FTS3TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AC881DA389380056AF8C /* FTS3TableBuilderTests.swift */; }; @@ -305,8 +373,14 @@ 5698AD261DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD201DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift */; }; 5698AD371DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */; }; 5698AD3A1DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */; }; - 569A98F82039B716008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98F62039B716008D7DBF /* Fixits-3.0.swift */; }; - 569A98F92039B716008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98F62039B716008D7DBF /* Fixits-3.0.swift */; }; + 569BBA2B228DE53200478429 /* AssociationPrefetchingFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569BBA29228DE53200478429 /* AssociationPrefetchingFetchableRecordTests.swift */; }; + 569BBA2C228DE53200478429 /* AssociationPrefetchingFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569BBA29228DE53200478429 /* AssociationPrefetchingFetchableRecordTests.swift */; }; + 569BBA40229065CF00478429 /* InflectionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569BBA3E229065CF00478429 /* InflectionsTests.swift */; }; + 569BBA41229065CF00478429 /* InflectionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569BBA3E229065CF00478429 /* InflectionsTests.swift */; }; + 569BBA43229066CB00478429 /* InflectionsTests.json in Resources */ = {isa = PBXBuildFile; fileRef = 569BBA42229066CB00478429 /* InflectionsTests.json */; }; + 569BBA44229066CB00478429 /* InflectionsTests.json in Resources */ = {isa = PBXBuildFile; fileRef = 569BBA42229066CB00478429 /* InflectionsTests.json */; }; + 569BBA4C229170B300478429 /* Inflections+English.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569BBA4B229170B300478429 /* Inflections+English.swift */; }; + 569BBA4D229170B300478429 /* Inflections+English.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569BBA4B229170B300478429 /* Inflections+English.swift */; }; 569EF0E6200D37FD00A9FA45 /* DatabaseRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569EF0E5200D37FC00A9FA45 /* DatabaseRegion.swift */; }; 569EF0E7200D37FD00A9FA45 /* DatabaseRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569EF0E5200D37FC00A9FA45 /* DatabaseRegion.swift */; }; 56A4CDB31D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A4CDAF1D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift */; }; @@ -319,6 +393,8 @@ 56A8C2461D1918EF0096E9D4 /* FoundationUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A8C21E1D1914110096E9D4 /* FoundationUUIDTests.swift */; }; 56A8C24D1D1918F30096E9D4 /* FoundationNSUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A8C2361D1914790096E9D4 /* FoundationNSUUIDTests.swift */; }; 56A8C24E1D1918F30096E9D4 /* FoundationUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A8C21E1D1914110096E9D4 /* FoundationUUIDTests.swift */; }; + 56AE6427222AACE300AD1B0B /* AssociationHasOneThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE6426222AACE300AD1B0B /* AssociationHasOneThroughSQLTests.swift */; }; + 56AE6428222AACE300AD1B0B /* AssociationHasOneThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE6426222AACE300AD1B0B /* AssociationHasOneThroughSQLTests.swift */; }; 56AF746E1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AF746A1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift */; }; 56AF74721D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AF746A1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift */; }; 56B021CC1D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */; }; @@ -327,6 +403,8 @@ 56B14E861D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B14E7E1D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift */; }; 56B6EF60208CB746002F0ACB /* ColumnExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B6EF5E208CB746002F0ACB /* ColumnExpressionTests.swift */; }; 56B6EF61208CB746002F0ACB /* ColumnExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B6EF5E208CB746002F0ACB /* ColumnExpressionTests.swift */; }; + 56B86E70220FF4C900524C16 /* SQLLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B86E6E220FF4C800524C16 /* SQLLiteralTests.swift */; }; + 56B86E71220FF4C900524C16 /* SQLLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B86E6E220FF4C800524C16 /* SQLLiteralTests.swift */; }; 56B9649F1DA51B4C0002DA19 /* FTS5.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B9649C1DA51B4C0002DA19 /* FTS5.swift */; }; 56B964A21DA51B4C0002DA19 /* FTS5.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B9649C1DA51B4C0002DA19 /* FTS5.swift */; }; 56B964B31DA51D010002DA19 /* FTS5TokenizerDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964B01DA51D010002DA19 /* FTS5TokenizerDescriptor.swift */; }; @@ -341,12 +419,6 @@ 56B964DB1DA5216B0002DA19 /* FTS5RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B964C11DA521450002DA19 /* FTS5RecordTests.swift */; }; 56BB6EAB1D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BB6EA81D3009B100A1CA52 /* SchedulingWatchdog.swift */; }; 56BB6EAE1D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BB6EA81D3009B100A1CA52 /* SchedulingWatchdog.swift */; }; - 56BF6D311DEF47DA006039A3 /* Fixits-0-84-0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2C1DEF47DA006039A3 /* Fixits-0-84-0.swift */; }; - 56BF6D341DEF47DA006039A3 /* Fixits-0-84-0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2C1DEF47DA006039A3 /* Fixits-0-84-0.swift */; }; - 56BF6D381DEF47DA006039A3 /* Fixits-0-90-1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2D1DEF47DA006039A3 /* Fixits-0-90-1.swift */; }; - 56BF6D3B1DEF47DA006039A3 /* Fixits-0-90-1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2D1DEF47DA006039A3 /* Fixits-0-90-1.swift */; }; - 56BF6D3F1DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2E1DEF47DA006039A3 /* Fixits-Swift2.swift */; }; - 56BF6D421DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BF6D2E1DEF47DA006039A3 /* Fixits-Swift2.swift */; }; 56C7A6AE1D2DFF6100EFB0C2 /* FoundationNSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* FoundationNSDateTests.swift */; }; 56CC9234201E009000CB597E /* DropWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC9231201DFFF600CB597E /* DropWhileCursorTests.swift */; }; 56CC9235201E009100CB597E /* DropWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC9231201DFFF600CB597E /* DropWhileCursorTests.swift */; }; @@ -362,46 +434,30 @@ 56CEB4FF1EAA2F4D00BFAF62 /* FTS3.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB4F81EAA2F4D00BFAF62 /* FTS3.swift */; }; 56CEB5031EAA2F4D00BFAF62 /* FTS4.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB4F91EAA2F4D00BFAF62 /* FTS4.swift */; }; 56CEB5061EAA2F4D00BFAF62 /* FTS4.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB4F91EAA2F4D00BFAF62 /* FTS4.swift */; }; - 56CEB5131EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */; }; - 56CEB5161EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */; }; - 56CEB51B1EAA328900BFAF62 /* FTS5+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */; }; - 56CEB51E1EAA328900BFAF62 /* FTS5+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */; }; - 56CEB5471EAA359A00BFAF62 /* Column.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5401EAA359A00BFAF62 /* Column.swift */; }; - 56CEB54A1EAA359A00BFAF62 /* Column.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5401EAA359A00BFAF62 /* Column.swift */; }; - 56CEB54E1EAA359A00BFAF62 /* SQLExpressible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5411EAA359A00BFAF62 /* SQLExpressible.swift */; }; - 56CEB5511EAA359A00BFAF62 /* SQLExpressible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5411EAA359A00BFAF62 /* SQLExpressible.swift */; }; - 56CEB5551EAA359A00BFAF62 /* SQLExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5421EAA359A00BFAF62 /* SQLExpression.swift */; }; - 56CEB5581EAA359A00BFAF62 /* SQLExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5421EAA359A00BFAF62 /* SQLExpression.swift */; }; - 56CEB55C1EAA359A00BFAF62 /* SQLOrdering.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5431EAA359A00BFAF62 /* SQLOrdering.swift */; }; - 56CEB55F1EAA359A00BFAF62 /* SQLOrdering.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5431EAA359A00BFAF62 /* SQLOrdering.swift */; }; - 56CEB5631EAA359A00BFAF62 /* SQLSelectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5441EAA359A00BFAF62 /* SQLSelectable.swift */; }; - 56CEB5661EAA359A00BFAF62 /* SQLSelectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5441EAA359A00BFAF62 /* SQLSelectable.swift */; }; - 56D1215C1ED34978001347D2 /* Fixits-0.109.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D121591ED34978001347D2 /* Fixits-0.109.0.swift */; }; - 56D1215F1ED34978001347D2 /* Fixits-0.109.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D121591ED34978001347D2 /* Fixits-0.109.0.swift */; }; 56D507611F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D5075D1F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift */; }; 56D507651F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D5075D1F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift */; }; 56D51D021EA789FA0074638A /* FetchableRecord+TableRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D51CFF1EA789FA0074638A /* FetchableRecord+TableRecord.swift */; }; 56D51D051EA789FA0074638A /* FetchableRecord+TableRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D51CFF1EA789FA0074638A /* FetchableRecord+TableRecord.swift */; }; - 56D91A9F2205E02300770D8D /* SQLRelation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91A9E2205E02300770D8D /* SQLRelation.swift */; }; - 56D91AA02205E02300770D8D /* SQLRelation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91A9E2205E02300770D8D /* SQLRelation.swift */; }; - 56D91AA62205F2CF00770D8D /* DatabasePromise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91AA52205F2CF00770D8D /* DatabasePromise.swift */; }; - 56D91AA72205F2CF00770D8D /* DatabasePromise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D91AA52205F2CF00770D8D /* DatabasePromise.swift */; }; 56DAA2D51DE99DAB006E10C8 /* DatabaseCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DAA2D11DE99DAB006E10C8 /* DatabaseCursorTests.swift */; }; 56DAA2D91DE99DAB006E10C8 /* DatabaseCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DAA2D11DE99DAB006E10C8 /* DatabaseCursorTests.swift */; }; 56DAA2DD1DE9C827006E10C8 /* Cursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DAA2DA1DE9C827006E10C8 /* Cursor.swift */; }; 56DAA2E01DE9C827006E10C8 /* Cursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DAA2DA1DE9C827006E10C8 /* Cursor.swift */; }; - 56E06F141E859069008AE2A4 /* Fixits-0.102.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E06F051E859064008AE2A4 /* Fixits-0.102.0.swift */; }; - 56E06F171E85906D008AE2A4 /* Fixits-0.102.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E06F051E859064008AE2A4 /* Fixits-0.102.0.swift */; }; + 56DF0015228DDB8300D611F3 /* AssociationPrefetchingCodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DF0013228DDB8200D611F3 /* AssociationPrefetchingCodableRecordTests.swift */; }; + 56DF0016228DDB8300D611F3 /* AssociationPrefetchingCodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DF0013228DDB8200D611F3 /* AssociationPrefetchingCodableRecordTests.swift */; }; + 56DF0017228DDB8300D611F3 /* AssociationPrefetchingRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DF0014228DDB8200D611F3 /* AssociationPrefetchingRowTests.swift */; }; + 56DF0018228DDB8300D611F3 /* AssociationPrefetchingRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DF0014228DDB8200D611F3 /* AssociationPrefetchingRowTests.swift */; }; + 56E9FAC42210468500C703A8 /* SQLInterpolation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E9FAC32210468500C703A8 /* SQLInterpolation.swift */; }; + 56E9FAC52210468500C703A8 /* SQLInterpolation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E9FAC32210468500C703A8 /* SQLInterpolation.swift */; }; + 56E9FAD52210538400C703A8 /* SQLLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E9FAD42210538400C703A8 /* SQLLiteral.swift */; }; + 56E9FAD62210538400C703A8 /* SQLLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E9FAD42210538400C703A8 /* SQLLiteral.swift */; }; 56EA63C9209C7F1E009715B8 /* DerivableRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA63C7209C7F1E009715B8 /* DerivableRequestTests.swift */; }; 56EA63CA209C7F1E009715B8 /* DerivableRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EA63C7209C7F1E009715B8 /* DerivableRequestTests.swift */; }; 56ED8A7F1DAB8D6800BD0ABC /* FTS5WrapperTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56ED8A7E1DAB8D6800BD0ABC /* FTS5WrapperTokenizerTests.swift */; }; 56ED8A801DAB8D6800BD0ABC /* FTS5WrapperTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56ED8A7E1DAB8D6800BD0ABC /* FTS5WrapperTokenizerTests.swift */; }; 56F3E74C1E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */; }; 56F3E7501E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */; }; - 56F3E7651E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F3E7621E67F8C100BF0F01 /* Fixits-0.101.1.swift */; }; - 56F3E7681E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F3E7621E67F8C100BF0F01 /* Fixits-0.101.1.swift */; }; - 56FC987A1D969DEF00E3C842 /* SQLExpression+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FC98771D969DEF00E3C842 /* SQLExpression+QueryInterface.swift */; }; - 56FC987D1D969DEF00E3C842 /* SQLExpression+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FC98771D969DEF00E3C842 /* SQLExpression+QueryInterface.swift */; }; + 56FBFED62210731100945324 /* SQLRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FBFED52210731000945324 /* SQLRequest.swift */; }; + 56FBFED72210731100945324 /* SQLRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FBFED52210731000945324 /* SQLRequest.swift */; }; 56FEE7FE1F47253700D930EA /* TableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FEE7FA1F47253700D930EA /* TableRecordTests.swift */; }; 56FEE8021F47253700D930EA /* TableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FEE7FA1F47253700D930EA /* TableRecordTests.swift */; }; 56FF45431D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FF453F1D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift */; }; @@ -435,9 +491,6 @@ F3BA80231CFB288C003DC1BA /* NSString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1521C672E4000235C62 /* NSString.swift */; }; F3BA80271CFB2891003DC1BA /* DatabaseValueConvertible+RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1571C672E4000235C62 /* DatabaseValueConvertible+RawRepresentable.swift */; }; F3BA80281CFB2891003DC1BA /* StandardLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1581C672E4000235C62 /* StandardLibrary.swift */; }; - F3BA802B1CFB289B003DC1BA /* QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */; }; - F3BA802C1CFB289B003DC1BA /* SQLCollatedExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */; }; - F3BA802F1CFB289B003DC1BA /* SQLSelectQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F18C1C6B1A8700235C62 /* SQLSelectQuery.swift */; }; F3BA80301CFB289F003DC1BA /* DatabaseMigrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238921B9C750B0082EB20 /* DatabaseMigrator.swift */; }; F3BA80311CFB289F003DC1BA /* Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4391BEB42D500E39BBF /* Migration.swift */; }; F3BA80321CFB28A4003DC1BA /* FetchedRecordsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31A7787C1C6A4DD600F507F6 /* FetchedRecordsController.swift */; }; @@ -479,9 +532,6 @@ F3BA807F1CFB2E61003DC1BA /* NSString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1521C672E4000235C62 /* NSString.swift */; }; F3BA80831CFB2E67003DC1BA /* DatabaseValueConvertible+RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1571C672E4000235C62 /* DatabaseValueConvertible+RawRepresentable.swift */; }; F3BA80841CFB2E67003DC1BA /* StandardLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1581C672E4000235C62 /* StandardLibrary.swift */; }; - F3BA80871CFB2E70003DC1BA /* QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */; }; - F3BA80881CFB2E70003DC1BA /* SQLCollatedExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */; }; - F3BA808B1CFB2E70003DC1BA /* SQLSelectQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F18C1C6B1A8700235C62 /* SQLSelectQuery.swift */; }; F3BA808C1CFB2E75003DC1BA /* DatabaseMigrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238921B9C750B0082EB20 /* DatabaseMigrator.swift */; }; F3BA808D1CFB2E75003DC1BA /* Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4391BEB42D500E39BBF /* Migration.swift */; }; F3BA808E1CFB2E7A003DC1BA /* FetchedRecordsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31A7787C1C6A4DD600F507F6 /* FetchedRecordsController.swift */; }; @@ -653,6 +703,10 @@ /* Begin PBXFileReference section */ 31A7787C1C6A4DD600F507F6 /* FetchedRecordsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedRecordsController.swift; sourceTree = ""; }; + 56043295228F00A9009D3FE2 /* OrderedDictionaryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderedDictionaryTests.swift; sourceTree = ""; }; + 560432A5228F167A009D3FE2 /* AssociationPrefetchingObservationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingObservationTests.swift; sourceTree = ""; }; + 56057C572291B18E00A7CB10 /* AssociationHasManyRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManyRowScopeTests.swift; sourceTree = ""; }; + 56057C642291C7E500A7CB10 /* AssociationHasManyThroughRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManyThroughRowScopeTests.swift; sourceTree = ""; }; 5605F1491C672E4000235C62 /* CGFloat.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGFloat.swift; sourceTree = ""; }; 5605F14C1C672E4000235C62 /* DatabaseDateComponents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseDateComponents.swift; sourceTree = ""; }; 5605F14F1C672E4000235C62 /* Date.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = ""; }; @@ -662,8 +716,7 @@ 5605F1571C672E4000235C62 /* DatabaseValueConvertible+RawRepresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DatabaseValueConvertible+RawRepresentable.swift"; sourceTree = ""; }; 5605F1581C672E4000235C62 /* StandardLibrary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StandardLibrary.swift; sourceTree = ""; }; 5605F1861C69111300235C62 /* DatabaseRegionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegionTests.swift; sourceTree = ""; }; - 5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLCollatedExpression.swift; sourceTree = ""; }; - 5605F18C1C6B1A8700235C62 /* SQLSelectQuery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLSelectQuery.swift; sourceTree = ""; }; + 560714EB227DD10F0091BB10 /* AssociationPrefetchingSQLTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingSQLTests.swift; sourceTree = ""; }; 5607EFD21BB8254800605DE3 /* TransactionObserverTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionObserverTests.swift; sourceTree = ""; }; 560A37A31C8F625000949E71 /* DatabasePool.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePool.swift; sourceTree = ""; }; 560A37A61C8FF6E500949E71 /* SerializedDatabase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SerializedDatabase.swift; sourceTree = ""; }; @@ -682,8 +735,13 @@ 5613ED5F21A95E6100DC7A68 /* ValueReducer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueReducer.swift; sourceTree = ""; }; 5613ED6021A95E6100DC7A68 /* ValueObservation+Count.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ValueObservation+Count.swift"; sourceTree = ""; }; 5613EDA221A96A8000DC7A68 /* ValueObservationCombineTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationCombineTests.swift; sourceTree = ""; }; + 5614089E221596A100DAD589 /* GRDB-4.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "GRDB-4.0.swift"; sourceTree = ""; }; + 5615B256222AE19100061C1C /* AssociationHasOneThroughSQLDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughSQLDerivationTests.swift; sourceTree = ""; }; + 5615B26C222AFEB300061C1C /* AssociationHasOneThroughRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughRowScopeTests.swift; sourceTree = ""; }; + 5615B277222B109500061C1C /* AssociationHasOneThroughFetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughFetchableRecordTests.swift; sourceTree = ""; }; + 5615B284222B17B900061C1C /* AssociationHasOneThroughDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughDecodableRecordTests.swift; sourceTree = ""; }; 561667001D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSDecimalNumberTests.swift; sourceTree = ""; }; - 5616AAF4207CD59300AC3664 /* RequestProtocols.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestProtocols.swift; sourceTree = ""; }; + 561729532235340E0006E219 /* EncodableRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EncodableRecord.swift; sourceTree = ""; }; 562393171DECC02000A6B01F /* RowFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFetchTests.swift; sourceTree = ""; }; 5623932F1DEDFC5700A6B01F /* AnyCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyCursorTests.swift; sourceTree = ""; }; 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnumeratedCursorTests.swift; sourceTree = ""; }; @@ -699,7 +757,6 @@ 56300B601C53C42C005A543B /* FetchableRecord+QueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FetchableRecord+QueryInterfaceRequestTests.swift"; sourceTree = ""; }; 56300B671C53D25E005A543B /* QueryInterfaceExpressionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceExpressionsTests.swift; sourceTree = ""; }; 56300B6A1C53D3E8005A543B /* TableRecord+QueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TableRecord+QueryInterfaceRequestTests.swift"; sourceTree = ""; }; - 56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceRequest.swift; sourceTree = ""; }; 56300B841C54DC95005A543B /* Record+QueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Record+QueryInterfaceRequestTests.swift"; sourceTree = ""; }; 563363A91C933FF8000BE133 /* MutablePersistableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordTests.swift; sourceTree = ""; }; 563363AA1C933FF8000BE133 /* PersistableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersistableRecordTests.swift; sourceTree = ""; }; @@ -720,7 +777,6 @@ 563B071121862C3E00B38F35 /* ValueObservationRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationRecordTests.swift; sourceTree = ""; }; 563B071A21862F5600B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationDatabaseValueConvertibleTests.swift; sourceTree = ""; }; 563EF41E215F8A76007DAACD /* OrderedDictionary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OrderedDictionary.swift; sourceTree = ""; }; - 563EF4362161182C007DAACD /* AssociationAggregate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationAggregate.swift; sourceTree = ""; }; 563EF441216131F5007DAACD /* AssociationAggregateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationAggregateTests.swift; sourceTree = ""; }; 563EF44C2161F196007DAACD /* Inflections.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Inflections.swift; sourceTree = ""; }; 563EF45521631E3E007DAACD /* QueryInterfacePromiseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfacePromiseTests.swift; sourceTree = ""; }; @@ -739,13 +795,6 @@ 564E73E7203DA278000C443C /* JoinSupportTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JoinSupportTests.swift; sourceTree = ""; }; 564F9C1D1F069B4E00877A00 /* DatabaseAggregateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseAggregateTests.swift; sourceTree = ""; }; 564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseFunction.swift; sourceTree = ""; }; - 5653EB3720961F6000F46237 /* BelongsToAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BelongsToAssociation.swift; sourceTree = ""; }; - 5653EB3820961F6000F46237 /* HasOneAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HasOneAssociation.swift; sourceTree = ""; }; - 5653EB3A20961F6000F46237 /* HasManyAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HasManyAssociation.swift; sourceTree = ""; }; - 5653EB3B20961F6000F46237 /* ForeignKey.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForeignKey.swift; sourceTree = ""; }; - 5653EB3C20961F6000F46237 /* ForeignKeyRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForeignKeyRequest.swift; sourceTree = ""; }; - 5653EB3E20961F6100F46237 /* Association.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Association.swift; sourceTree = ""; }; - 5653EB5320961F7D00F46237 /* QueryInterfaceRequest+Association.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "QueryInterfaceRequest+Association.swift"; sourceTree = ""; }; 5653EB5820961FB000F46237 /* AssociationParallelSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelSQLTests.swift; sourceTree = ""; }; 5653EB5920961FB100F46237 /* AssociationBelongsToFetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToFetchableRecordTests.swift; sourceTree = ""; }; 5653EB5A20961FB100F46237 /* AssociationParallelDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelDecodableRecordTests.swift; sourceTree = ""; }; @@ -760,7 +809,45 @@ 5653EB6320961FB200F46237 /* AssociationChainSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationChainSQLTests.swift; sourceTree = ""; }; 5653EB6420961FB200F46237 /* AssociationBelongsToDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToDecodableRecordTests.swift; sourceTree = ""; }; 5653EB6520961FB200F46237 /* AssociationBelongsToRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToRowScopeTests.swift; sourceTree = ""; }; - 5653EC072098737400F46237 /* SQLGenerationContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SQLGenerationContext.swift; sourceTree = ""; }; + 5656A7F422946B1B001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationQueryInterfaceRequestTests.swift; sourceTree = ""; }; + 5656A8262295BD56001FF3FF /* SQLInterpolation+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SQLInterpolation+QueryInterface.swift"; sourceTree = ""; }; + 5656A8282295BD56001FF3FF /* FTS5+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FTS5+QueryInterface.swift"; sourceTree = ""; }; + 5656A82A2295BD56001FF3FF /* SQLQueryGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLQueryGenerator.swift; sourceTree = ""; }; + 5656A82B2295BD56001FF3FF /* SQLGenerationContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLGenerationContext.swift; sourceTree = ""; }; + 5656A82D2295BD56001FF3FF /* TableDefinition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableDefinition.swift; sourceTree = ""; }; + 5656A82E2295BD56001FF3FF /* VirtualTableModule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VirtualTableModule.swift; sourceTree = ""; }; + 5656A82F2295BD56001FF3FF /* FTS3+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FTS3+QueryInterface.swift"; sourceTree = ""; }; + 5656A8312295BD56001FF3FF /* TableRecord+Association.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TableRecord+Association.swift"; sourceTree = ""; }; + 5656A8322295BD56001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FetchableRecord+QueryInterfaceRequest.swift"; sourceTree = ""; }; + 5656A8342295BD56001FF3FF /* BelongsToAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BelongsToAssociation.swift; sourceTree = ""; }; + 5656A8352295BD56001FF3FF /* HasOneAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HasOneAssociation.swift; sourceTree = ""; }; + 5656A8362295BD56001FF3FF /* AssociationAggregate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationAggregate.swift; sourceTree = ""; }; + 5656A8372295BD56001FF3FF /* HasManyAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HasManyAssociation.swift; sourceTree = ""; }; + 5656A8382295BD56001FF3FF /* HasManyThroughAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HasManyThroughAssociation.swift; sourceTree = ""; }; + 5656A8392295BD56001FF3FF /* Association.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Association.swift; sourceTree = ""; }; + 5656A83A2295BD56001FF3FF /* HasOneThroughAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HasOneThroughAssociation.swift; sourceTree = ""; }; + 5656A83B2295BD56001FF3FF /* QueryInterfaceRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceRequest.swift; sourceTree = ""; }; + 5656A83C2295BD56001FF3FF /* RequestProtocols.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestProtocols.swift; sourceTree = ""; }; + 5656A83D2295BD56001FF3FF /* TableRecord+QueryInterfaceRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TableRecord+QueryInterfaceRequest.swift"; sourceTree = ""; }; + 5656A83E2295BD56001FF3FF /* Row+QueryInterfaceRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Row+QueryInterfaceRequest.swift"; sourceTree = ""; }; + 5656A83F2295BD56001FF3FF /* QueryInterfaceRequest+Association.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "QueryInterfaceRequest+Association.swift"; sourceTree = ""; }; + 5656A8412295BD56001FF3FF /* SQLAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLAssociation.swift; sourceTree = ""; }; + 5656A8422295BD56001FF3FF /* SQLForeignKeyRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLForeignKeyRequest.swift; sourceTree = ""; }; + 5656A8432295BD56001FF3FF /* SQLCollection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLCollection.swift; sourceTree = ""; }; + 5656A8442295BD56001FF3FF /* SQLExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLExpression.swift; sourceTree = ""; }; + 5656A8452295BD56001FF3FF /* SQLOrdering.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLOrdering.swift; sourceTree = ""; }; + 5656A8462295BD56001FF3FF /* SQLOperators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLOperators.swift; sourceTree = ""; }; + 5656A8472295BD56001FF3FF /* SQLExpressible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLExpressible.swift; sourceTree = ""; }; + 5656A8482295BD56001FF3FF /* SQLExpression+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SQLExpression+QueryInterface.swift"; sourceTree = ""; }; + 5656A8492295BD56001FF3FF /* SQLSelectable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLSelectable.swift; sourceTree = ""; }; + 5656A84A2295BD56001FF3FF /* Column.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Column.swift; sourceTree = ""; }; + 5656A84B2295BD56001FF3FF /* SQLSpecificExpressible+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SQLSpecificExpressible+QueryInterface.swift"; sourceTree = ""; }; + 5656A84C2295BD56001FF3FF /* SQLFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLFunctions.swift; sourceTree = ""; }; + 5656A84D2295BD56001FF3FF /* SQLCollatedExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLCollatedExpression.swift; sourceTree = ""; }; + 5656A84E2295BD56001FF3FF /* SQLRelation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLRelation.swift; sourceTree = ""; }; + 5656A84F2295BD56001FF3FF /* SQLSelectable+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SQLSelectable+QueryInterface.swift"; sourceTree = ""; }; + 5656A8502295BD56001FF3FF /* SQLQuery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLQuery.swift; sourceTree = ""; }; + 5656A8A52295BF44001FF3FF /* DatabasePromise.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePromise.swift; sourceTree = ""; }; 5657AAB81D107001006283EF /* NSData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSData.swift; sourceTree = ""; }; 5657AB0E1D10899D006283EF /* URL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URL.swift; sourceTree = ""; }; 5657AB2F1D108BA9006283EF /* FoundationDataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationDataTests.swift; sourceTree = ""; }; @@ -779,18 +866,12 @@ 565D5D731BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StatementArguments+FoundationTests.swift"; sourceTree = ""; }; 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumericOverflowTests.swift; sourceTree = ""; }; 565F03C11CE5D3AA00DE108F /* RowAdapterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowAdapterTests.swift; sourceTree = ""; }; - 566475991D97D8A000FF74B8 /* SQLCollection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLCollection.swift; sourceTree = ""; }; - 566475A11D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SQLSelectable+QueryInterface.swift"; sourceTree = ""; }; - 566475B91D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SQLSpecificExpressible+QueryInterface.swift"; sourceTree = ""; }; - 566475CA1D981D5E00FF74B8 /* SQLFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLFunctions.swift; sourceTree = ""; }; - 566475CB1D981D5E00FF74B8 /* SQLOperators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLOperators.swift; sourceTree = ""; }; 5665F865203EF4590084C6C0 /* ColumnInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColumnInfoTests.swift; sourceTree = ""; }; 5665FA1C2129D807004D8612 /* DatabaseDateDecodingStrategyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseDateDecodingStrategyTests.swift; sourceTree = ""; }; 5665FA3B2129EED8004D8612 /* DatabaseDateEncodingStrategyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseDateEncodingStrategyTests.swift; sourceTree = ""; }; 566A842B20413D9A00E50BFD /* DatabaseSnapshot.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseSnapshot.swift; sourceTree = ""; }; 566A843420413DE400E50BFD /* DatabaseSnapshotTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseSnapshotTests.swift; sourceTree = ""; }; 566A84422041AB2D00E50BFD /* MutablePersistableRecordChangesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordChangesTests.swift; sourceTree = ""; }; - 566AD8B11D5318F4002EC1A8 /* TableDefinition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableDefinition.swift; sourceTree = ""; }; 566AD8C51D531BE4002EC1A8 /* TableDefinitionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableDefinitionTests.swift; sourceTree = ""; }; 566B91081FA4C3960012D5B0 /* Database+Statements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Database+Statements.swift"; sourceTree = ""; }; 566B91121FA4C3F50012D5B0 /* DatabaseCollation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseCollation.swift; sourceTree = ""; }; @@ -809,7 +890,7 @@ 5674A6E21F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DatabaseValueConvertible+Encodable.swift"; sourceTree = ""; }; 5674A6E31F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DatabaseValueConvertible+Decodable.swift"; sourceTree = ""; }; 5674A6F21F307F600095F066 /* FetchableRecord+Decodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FetchableRecord+Decodable.swift"; sourceTree = ""; }; - 5674A6F31F307F600095F066 /* PersistableRecord+Encodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PersistableRecord+Encodable.swift"; sourceTree = ""; }; + 5674A6F31F307F600095F066 /* EncodableRecord+Encodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "EncodableRecord+Encodable.swift"; sourceTree = ""; }; 5674A7021F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DatabaseValueConvertible+ReferenceConvertible.swift"; sourceTree = ""; }; 5674A70A1F3087700095F066 /* DatabaseValueConvertibleDecodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleDecodableTests.swift; sourceTree = ""; }; 5674A70B1F3087700095F066 /* DatabaseValueConvertibleEncodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleEncodableTests.swift; sourceTree = ""; }; @@ -818,11 +899,10 @@ 567A80521D41350C00C7DCEC /* IndexInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IndexInfoTests.swift; sourceTree = ""; }; 567DAF141EAB61ED00FC0928 /* grdb_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = grdb_config.h; sourceTree = ""; }; 567DAF341EAB789800FC0928 /* DatabaseLogErrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseLogErrorTests.swift; sourceTree = ""; }; + 567F0B2F220F196300D111FB /* SQLInterpolationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLInterpolationTests.swift; sourceTree = ""; }; 567F45A71F888B2600030B59 /* TruncateOptimizationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TruncateOptimizationTests.swift; sourceTree = ""; }; 568068301EBBA26100EFB8AA /* SQLRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLRequestTests.swift; sourceTree = ""; }; 5687359E1CEDE16C009B9116 /* Betty.jpeg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Betty.jpeg; sourceTree = ""; }; - 56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Fixits-1.2.swift"; sourceTree = ""; }; - 568D13142207210400674B58 /* SQLSelectQueryGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SQLSelectQueryGenerator.swift; sourceTree = ""; }; 5690C3251D23E6D800E59934 /* FoundationDateComponentsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationDateComponentsTests.swift; sourceTree = ""; }; 5690C3361D23E7D200E59934 /* FoundationDateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationDateTests.swift; sourceTree = ""; }; 5690C33F1D23E82A00E59934 /* Data.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; @@ -832,11 +912,12 @@ 569531281C908A5B00CF1A2B /* DatabasePoolSchemaCacheTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolSchemaCacheTests.swift; sourceTree = ""; }; 569531331C919DF200CF1A2B /* DatabasePoolCollationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolCollationTests.swift; sourceTree = ""; }; 569531361C919DF700CF1A2B /* DatabasePoolFunctionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolFunctionTests.swift; sourceTree = ""; }; + 5695961E222C4589002CB7C9 /* AssociationHasManyThroughSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManyThroughSQLTests.swift; sourceTree = ""; }; + 56959635222D058B002CB7C9 /* AssociationHasManySQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManySQLTests.swift; sourceTree = ""; }; 5698AC021D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceExtensibilityTests.swift; sourceTree = ""; }; 5698AC361D9E5A590056AF8C /* FTS3Pattern.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3Pattern.swift; sourceTree = ""; }; 5698AC3F1DA2BED90056AF8C /* FTS3PatternTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3PatternTests.swift; sourceTree = ""; }; 5698AC481DA2D48A0056AF8C /* FTS3RecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3RecordTests.swift; sourceTree = ""; }; - 5698AC771DA37DCB0056AF8C /* VirtualTableModule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VirtualTableModule.swift; sourceTree = ""; }; 5698AC7F1DA380A20056AF8C /* VirtualTableModuleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VirtualTableModuleTests.swift; sourceTree = ""; }; 5698AC881DA389380056AF8C /* FTS3TableBuilderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3TableBuilderTests.swift; sourceTree = ""; }; 5698AC941DA4B0430056AF8C /* FTS4RecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS4RecordTests.swift; sourceTree = ""; }; @@ -849,7 +930,10 @@ 5698AD151DAAD16F0056AF8C /* FTS5Tokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5Tokenizer.swift; sourceTree = ""; }; 5698AD201DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5WrapperTokenizer.swift; sourceTree = ""; }; 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5CustomTokenizer.swift; sourceTree = ""; }; - 569A98F62039B716008D7DBF /* Fixits-3.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-3.0.swift"; sourceTree = ""; }; + 569BBA29228DE53200478429 /* AssociationPrefetchingFetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingFetchableRecordTests.swift; sourceTree = ""; }; + 569BBA3E229065CF00478429 /* InflectionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InflectionsTests.swift; sourceTree = ""; }; + 569BBA42229066CB00478429 /* InflectionsTests.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = InflectionsTests.json; sourceTree = ""; }; + 569BBA4B229170B300478429 /* Inflections+English.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Inflections+English.swift"; sourceTree = ""; }; 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SchedulingWatchdogTests.swift; sourceTree = ""; }; 569EF0E5200D37FC00A9FA45 /* DatabaseRegion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegion.swift; sourceTree = ""; }; 56A238131B9C74A90082EB20 /* DatabaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseTests.swift; sourceTree = ""; }; @@ -891,6 +975,7 @@ 56A8C21E1D1914110096E9D4 /* FoundationUUIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationUUIDTests.swift; sourceTree = ""; }; 56A8C22F1D1914540096E9D4 /* UUID.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UUID.swift; sourceTree = ""; }; 56A8C2361D1914790096E9D4 /* FoundationNSUUIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSUUIDTests.swift; sourceTree = ""; }; + 56AE6426222AACE300AD1B0B /* AssociationHasOneThroughSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughSQLTests.swift; sourceTree = ""; }; 56AF746A1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleEscapingTests.swift; sourceTree = ""; }; 56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordPersistenceConflictPolicyTests.swift; sourceTree = ""; }; 56B14E7E1D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFromDictionaryLiteralTests.swift; sourceTree = ""; }; @@ -898,6 +983,7 @@ 56B6EF5E208CB746002F0ACB /* ColumnExpressionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColumnExpressionTests.swift; sourceTree = ""; }; 56B7F4291BE14A1900E39BBF /* CGFloatTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGFloatTests.swift; sourceTree = ""; }; 56B7F4391BEB42D500E39BBF /* Migration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Migration.swift; sourceTree = ""; }; + 56B86E6E220FF4C800524C16 /* SQLLiteralTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLLiteralTests.swift; sourceTree = ""; }; 56B8F49A1B4E2F3600C24296 /* GRDB.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = GRDB.xcconfig; sourceTree = ""; }; 56B9649C1DA51B4C0002DA19 /* FTS5.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5.swift; sourceTree = ""; }; 56B964B01DA51D010002DA19 /* FTS5TokenizerDescriptor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5TokenizerDescriptor.swift; sourceTree = ""; }; @@ -906,9 +992,6 @@ 56B964C11DA521450002DA19 /* FTS5RecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5RecordTests.swift; sourceTree = ""; }; 56B964C21DA521450002DA19 /* FTS5TableBuilderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5TableBuilderTests.swift; sourceTree = ""; }; 56BB6EA81D3009B100A1CA52 /* SchedulingWatchdog.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SchedulingWatchdog.swift; sourceTree = ""; }; - 56BF6D2C1DEF47DA006039A3 /* Fixits-0-84-0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0-84-0.swift"; sourceTree = ""; }; - 56BF6D2D1DEF47DA006039A3 /* Fixits-0-90-1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0-90-1.swift"; sourceTree = ""; }; - 56BF6D2E1DEF47DA006039A3 /* Fixits-Swift2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-Swift2.swift"; sourceTree = ""; }; 56C3F7521CF9F12400F6A361 /* DatabaseSavepointTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseSavepointTests.swift; sourceTree = ""; }; 56C48E731C9A9923005DF1D9 /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = ""; }; 56C494401ED7255500CC72AF /* GRDBDeploymentTarget.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = GRDBDeploymentTarget.xcconfig; sourceTree = ""; }; @@ -920,24 +1003,17 @@ 56CEB4F01EAA2EFA00BFAF62 /* FetchableRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchableRecord.swift; sourceTree = ""; }; 56CEB4F81EAA2F4D00BFAF62 /* FTS3.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3.swift; sourceTree = ""; }; 56CEB4F91EAA2F4D00BFAF62 /* FTS4.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS4.swift; sourceTree = ""; }; - 56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FTS3+QueryInterfaceRequest.swift"; sourceTree = ""; }; - 56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FTS5+QueryInterface.swift"; sourceTree = ""; }; - 56CEB5401EAA359A00BFAF62 /* Column.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Column.swift; sourceTree = ""; }; - 56CEB5411EAA359A00BFAF62 /* SQLExpressible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLExpressible.swift; sourceTree = ""; }; - 56CEB5421EAA359A00BFAF62 /* SQLExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLExpression.swift; sourceTree = ""; }; - 56CEB5431EAA359A00BFAF62 /* SQLOrdering.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLOrdering.swift; sourceTree = ""; }; - 56CEB5441EAA359A00BFAF62 /* SQLSelectable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLSelectable.swift; sourceTree = ""; }; - 56D121591ED34978001347D2 /* Fixits-0.109.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0.109.0.swift"; sourceTree = ""; }; 56D5075D1F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrimaryKeyInfoTests.swift; sourceTree = ""; }; 56D51CFF1EA789FA0074638A /* FetchableRecord+TableRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FetchableRecord+TableRecord.swift"; sourceTree = ""; }; - 56D91A9E2205E02300770D8D /* SQLRelation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLRelation.swift; sourceTree = ""; }; - 56D91AA52205F2CF00770D8D /* DatabasePromise.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabasePromise.swift; sourceTree = ""; }; 56DAA2D11DE99DAB006E10C8 /* DatabaseCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseCursorTests.swift; sourceTree = ""; }; 56DAA2DA1DE9C827006E10C8 /* Cursor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cursor.swift; sourceTree = ""; }; 56DE7B101C3D93ED00861EB8 /* StatementArgumentsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementArgumentsTests.swift; sourceTree = ""; }; - 56E06F051E859064008AE2A4 /* Fixits-0.102.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0.102.0.swift"; sourceTree = ""; }; + 56DF0013228DDB8200D611F3 /* AssociationPrefetchingCodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingCodableRecordTests.swift; sourceTree = ""; }; + 56DF0014228DDB8200D611F3 /* AssociationPrefetchingRowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingRowTests.swift; sourceTree = ""; }; 56E8CE0C1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleFetchTests.swift; sourceTree = ""; }; 56E8CE0F1BB4FE5B00828BEC /* StatementColumnConvertibleFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementColumnConvertibleFetchTests.swift; sourceTree = ""; }; + 56E9FAC32210468500C703A8 /* SQLInterpolation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLInterpolation.swift; sourceTree = ""; }; + 56E9FAD42210538400C703A8 /* SQLLiteral.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLLiteral.swift; sourceTree = ""; }; 56EA63C7209C7F1E009715B8 /* DerivableRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DerivableRequestTests.swift; sourceTree = ""; }; 56EA86931C91DFE7002BB4DF /* DatabaseReaderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseReaderTests.swift; sourceTree = ""; }; 56EA869D1C932597002BB4DF /* DatabasePoolReadOnlyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolReadOnlyTests.swift; sourceTree = ""; }; @@ -945,8 +1021,7 @@ 56ED8A7E1DAB8D6800BD0ABC /* FTS5WrapperTokenizerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5WrapperTokenizerTests.swift; sourceTree = ""; }; 56F0B98E1B6001C600A2F135 /* FoundationNSDateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSDateTests.swift; sourceTree = ""; }; 56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResultCodeTests.swift; sourceTree = ""; }; - 56F3E7621E67F8C100BF0F01 /* Fixits-0.101.1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0.101.1.swift"; sourceTree = ""; }; - 56FC98771D969DEF00E3C842 /* SQLExpression+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SQLExpression+QueryInterface.swift"; sourceTree = ""; }; + 56FBFED52210731000945324 /* SQLRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SQLRequest.swift; sourceTree = ""; }; 56FDECE11BB32DFD009AD709 /* RowFromStatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFromStatementTests.swift; sourceTree = ""; }; 56FEE7FA1F47253700D930EA /* TableRecordTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableRecordTests.swift; sourceTree = ""; }; 56FF453F1D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordDeleteTests.swift; sourceTree = ""; }; @@ -1110,6 +1185,14 @@ path = ValueObservation; sourceTree = ""; }; + 5614089D221596A100DAD589 /* Fixit */ = { + isa = PBXGroup; + children = ( + 5614089E221596A100DAD589 /* GRDB-4.0.swift */, + ); + path = Fixit; + sourceTree = ""; + }; 5614DEEE1BA9D6F9003163B3 /* Frameworks */ = { isa = PBXGroup; children = ( @@ -1209,37 +1292,6 @@ name = QueryInterface; sourceTree = ""; }; - 56300B6D1C53F592005A543B /* QueryInterface */ = { - isa = PBXGroup; - children = ( - 5653EB3620961F6000F46237 /* Association */, - 56CEB5401EAA359A00BFAF62 /* Column.swift */, - 56D91AA52205F2CF00770D8D /* DatabasePromise.swift */, - 56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */, - 56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */, - 56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */, - 5653EB5320961F7D00F46237 /* QueryInterfaceRequest+Association.swift */, - 5616AAF4207CD59300AC3664 /* RequestProtocols.swift */, - 5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */, - 566475991D97D8A000FF74B8 /* SQLCollection.swift */, - 56CEB5411EAA359A00BFAF62 /* SQLExpressible.swift */, - 56CEB5421EAA359A00BFAF62 /* SQLExpression.swift */, - 56FC98771D969DEF00E3C842 /* SQLExpression+QueryInterface.swift */, - 5653EC072098737400F46237 /* SQLGenerationContext.swift */, - 56CEB5431EAA359A00BFAF62 /* SQLOrdering.swift */, - 56D91A9E2205E02300770D8D /* SQLRelation.swift */, - 56CEB5441EAA359A00BFAF62 /* SQLSelectable.swift */, - 566475A11D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift */, - 5605F18C1C6B1A8700235C62 /* SQLSelectQuery.swift */, - 568D13142207210400674B58 /* SQLSelectQueryGenerator.swift */, - 566475B91D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift */, - 566475C91D981D5E00FF74B8 /* Support */, - 566AD8B11D5318F4002EC1A8 /* TableDefinition.swift */, - 5698AC771DA37DCB0056AF8C /* VirtualTableModule.swift */, - ); - path = QueryInterface; - sourceTree = ""; - }; 563363BB1C93FD32000BE133 /* DatabaseQueue */ = { isa = PBXGroup; children = ( @@ -1263,6 +1315,7 @@ 563B06CC2185E04500B38F35 /* ValueObservationExtentTests.swift */, 563B06CE2185E04600B38F35 /* ValueObservationFetchTests.swift */, 564CE4E221B2E05400652B19 /* ValueObservationMapTests.swift */, + 5656A7F422946B1B001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */, 563B06CD2185E04600B38F35 /* ValueObservationReadonlyTests.swift */, 563B071121862C3E00B38F35 /* ValueObservationRecordTests.swift */, 563B06CF2185E04600B38F35 /* ValueObservationReducerTests.swift */, @@ -1272,20 +1325,6 @@ name = ValueObservation; sourceTree = ""; }; - 5653EB3620961F6000F46237 /* Association */ = { - isa = PBXGroup; - children = ( - 5653EB3E20961F6100F46237 /* Association.swift */, - 563EF4362161182C007DAACD /* AssociationAggregate.swift */, - 5653EB3720961F6000F46237 /* BelongsToAssociation.swift */, - 5653EB3B20961F6000F46237 /* ForeignKey.swift */, - 5653EB3C20961F6000F46237 /* ForeignKeyRequest.swift */, - 5653EB3A20961F6000F46237 /* HasManyAssociation.swift */, - 5653EB3820961F6000F46237 /* HasOneAssociation.swift */, - ); - path = Association; - sourceTree = ""; - }; 5653EB5620961F8900F46237 /* Association */ = { isa = PBXGroup; children = ( @@ -1297,21 +1336,121 @@ 5653EB6220961FB200F46237 /* AssociationBelongsToSQLTests.swift */, 5653EB6020961FB100F46237 /* AssociationChainRowScopesTests.swift */, 5653EB6320961FB200F46237 /* AssociationChainSQLTests.swift */, + 56057C572291B18E00A7CB10 /* AssociationHasManyRowScopeTests.swift */, + 56959635222D058B002CB7C9 /* AssociationHasManySQLTests.swift */, + 56057C642291C7E500A7CB10 /* AssociationHasManyThroughRowScopeTests.swift */, + 5695961E222C4589002CB7C9 /* AssociationHasManyThroughSQLTests.swift */, 5653EB5F20961FB100F46237 /* AssociationHasOneSQLDerivationTests.swift */, 5653EB5D20961FB100F46237 /* AssociationHasOneSQLTests.swift */, + 5615B284222B17B900061C1C /* AssociationHasOneThroughDecodableRecordTests.swift */, + 5615B277222B109500061C1C /* AssociationHasOneThroughFetchableRecordTests.swift */, + 5615B26C222AFEB300061C1C /* AssociationHasOneThroughRowScopeTests.swift */, + 5615B256222AE19100061C1C /* AssociationHasOneThroughSQLDerivationTests.swift */, + 56AE6426222AACE300AD1B0B /* AssociationHasOneThroughSQLTests.swift */, 5653EB5A20961FB100F46237 /* AssociationParallelDecodableRecordTests.swift */, 5653EB6120961FB100F46237 /* AssociationParallelRowScopesTests.swift */, 5653EB5820961FB000F46237 /* AssociationParallelSQLTests.swift */, + 56DF0013228DDB8200D611F3 /* AssociationPrefetchingCodableRecordTests.swift */, + 569BBA29228DE53200478429 /* AssociationPrefetchingFetchableRecordTests.swift */, + 560432A5228F167A009D3FE2 /* AssociationPrefetchingObservationTests.swift */, + 56DF0014228DDB8200D611F3 /* AssociationPrefetchingRowTests.swift */, + 560714EB227DD10F0091BB10 /* AssociationPrefetchingSQLTests.swift */, 5653EB5E20961FB100F46237 /* AssociationRowScopeSearchTests.swift */, 5653EB5C20961FB100F46237 /* AssociationTableAliasTestsSQLTests.swift */, ); name = Association; sourceTree = ""; }; + 5656A8252295BD56001FF3FF /* QueryInterface */ = { + isa = PBXGroup; + children = ( + 5656A8322295BD56001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift */, + 5656A82F2295BD56001FF3FF /* FTS3+QueryInterface.swift */, + 5656A8282295BD56001FF3FF /* FTS5+QueryInterface.swift */, + 5656A8302295BD56001FF3FF /* Request */, + 5656A83E2295BD56001FF3FF /* Row+QueryInterfaceRequest.swift */, + 5656A82C2295BD56001FF3FF /* Schema */, + 5656A8402295BD56001FF3FF /* SQL */, + 5656A8292295BD56001FF3FF /* SQLGeneration */, + 5656A8262295BD56001FF3FF /* SQLInterpolation+QueryInterface.swift */, + 5656A8312295BD56001FF3FF /* TableRecord+Association.swift */, + 5656A83D2295BD56001FF3FF /* TableRecord+QueryInterfaceRequest.swift */, + ); + path = QueryInterface; + sourceTree = ""; + }; + 5656A8292295BD56001FF3FF /* SQLGeneration */ = { + isa = PBXGroup; + children = ( + 5656A82B2295BD56001FF3FF /* SQLGenerationContext.swift */, + 5656A82A2295BD56001FF3FF /* SQLQueryGenerator.swift */, + ); + path = SQLGeneration; + sourceTree = ""; + }; + 5656A82C2295BD56001FF3FF /* Schema */ = { + isa = PBXGroup; + children = ( + 5656A82D2295BD56001FF3FF /* TableDefinition.swift */, + 5656A82E2295BD56001FF3FF /* VirtualTableModule.swift */, + ); + path = Schema; + sourceTree = ""; + }; + 5656A8302295BD56001FF3FF /* Request */ = { + isa = PBXGroup; + children = ( + 5656A8332295BD56001FF3FF /* Association */, + 5656A83B2295BD56001FF3FF /* QueryInterfaceRequest.swift */, + 5656A83F2295BD56001FF3FF /* QueryInterfaceRequest+Association.swift */, + 5656A83C2295BD56001FF3FF /* RequestProtocols.swift */, + ); + path = Request; + sourceTree = ""; + }; + 5656A8332295BD56001FF3FF /* Association */ = { + isa = PBXGroup; + children = ( + 5656A8392295BD56001FF3FF /* Association.swift */, + 5656A8362295BD56001FF3FF /* AssociationAggregate.swift */, + 5656A8342295BD56001FF3FF /* BelongsToAssociation.swift */, + 5656A8372295BD56001FF3FF /* HasManyAssociation.swift */, + 5656A8382295BD56001FF3FF /* HasManyThroughAssociation.swift */, + 5656A8352295BD56001FF3FF /* HasOneAssociation.swift */, + 5656A83A2295BD56001FF3FF /* HasOneThroughAssociation.swift */, + ); + path = Association; + sourceTree = ""; + }; + 5656A8402295BD56001FF3FF /* SQL */ = { + isa = PBXGroup; + children = ( + 5656A84A2295BD56001FF3FF /* Column.swift */, + 5656A8A52295BF44001FF3FF /* DatabasePromise.swift */, + 5656A8412295BD56001FF3FF /* SQLAssociation.swift */, + 5656A84D2295BD56001FF3FF /* SQLCollatedExpression.swift */, + 5656A8432295BD56001FF3FF /* SQLCollection.swift */, + 5656A8472295BD56001FF3FF /* SQLExpressible.swift */, + 5656A8442295BD56001FF3FF /* SQLExpression.swift */, + 5656A8482295BD56001FF3FF /* SQLExpression+QueryInterface.swift */, + 5656A8422295BD56001FF3FF /* SQLForeignKeyRequest.swift */, + 5656A84C2295BD56001FF3FF /* SQLFunctions.swift */, + 5656A8462295BD56001FF3FF /* SQLOperators.swift */, + 5656A8452295BD56001FF3FF /* SQLOrdering.swift */, + 5656A8502295BD56001FF3FF /* SQLQuery.swift */, + 5656A84E2295BD56001FF3FF /* SQLRelation.swift */, + 5656A8492295BD56001FF3FF /* SQLSelectable.swift */, + 5656A84F2295BD56001FF3FF /* SQLSelectable+QueryInterface.swift */, + 5656A84B2295BD56001FF3FF /* SQLSpecificExpressible+QueryInterface.swift */, + ); + path = SQL; + sourceTree = ""; + }; 5659F4861EA8D94E004A4992 /* Utils */ = { isa = PBXGroup; children = ( 563EF44C2161F196007DAACD /* Inflections.swift */, + 569BBA4B229170B300478429 /* Inflections+English.swift */, 563EF41E215F8A76007DAACD /* OrderedDictionary.swift */, 5659F4971EA8D989004A4992 /* Pool.swift */, 5659F48F1EA8D964004A4992 /* ReadWriteBox.swift */, @@ -1321,15 +1460,6 @@ path = Utils; sourceTree = ""; }; - 566475C91D981D5E00FF74B8 /* Support */ = { - isa = PBXGroup; - children = ( - 566475CA1D981D5E00FF74B8 /* SQLFunctions.swift */, - 566475CB1D981D5E00FF74B8 /* SQLOperators.swift */, - ); - path = Support; - sourceTree = ""; - }; 5674A7251F30A8EF0095F066 /* FetchableRecord */ = { isa = PBXGroup; children = ( @@ -1386,6 +1516,9 @@ 5605F1861C69111300235C62 /* DatabaseRegionTests.swift */, 56AF746A1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift */, 56EB0AB11BCD787300A3DC55 /* DataMemoryTests.swift */, + 569BBA42229066CB00478429 /* InflectionsTests.json */, + 569BBA3E229065CF00478429 /* InflectionsTests.swift */, + 56043295228F00A9009D3FE2 /* OrderedDictionaryTests.swift */, 56FF45551D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift */, 56A4CDAF1D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift */, ); @@ -1423,6 +1556,8 @@ 56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */, 56A2381D1B9C74A90082EB20 /* Row */, 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */, + 567F0B2F220F196300D111FB /* SQLInterpolationTests.swift */, + 56B86E6E220FF4C800524C16 /* SQLLiteralTests.swift */, 568068301EBBA26100EFB8AA /* SQLRequestTests.swift */, 56A238201B9C74A90082EB20 /* Statement */, 56E8CE0F1BB4FE5B00828BEC /* StatementColumnConvertibleFetchTests.swift */, @@ -1516,6 +1651,9 @@ 567404871CEF84C8003ED5CC /* RowAdapter.swift */, 56BB6EA81D3009B100A1CA52 /* SchedulingWatchdog.swift */, 560A37A61C8FF6E500949E71 /* SerializedDatabase.swift */, + 56E9FAC32210468500C703A8 /* SQLInterpolation.swift */, + 56E9FAD42210538400C703A8 /* SQLLiteral.swift */, + 56FBFED52210731000945324 /* SQLRequest.swift */, 56A238781B9C75030082EB20 /* Statement.swift */, 566B912A1FA4D0CC0012D5B0 /* StatementAuthorizer.swift */, 560D923F1C672C3E00F4F92B /* StatementColumnConvertible.swift */, @@ -1537,33 +1675,19 @@ 56A2389F1B9C753B0082EB20 /* Record */ = { isa = PBXGroup; children = ( + 561729532235340E0006E219 /* EncodableRecord.swift */, + 5674A6F31F307F600095F066 /* EncodableRecord+Encodable.swift */, 56CEB4F01EAA2EFA00BFAF62 /* FetchableRecord.swift */, 5674A6F21F307F600095F066 /* FetchableRecord+Decodable.swift */, 56D51CFF1EA789FA0074638A /* FetchableRecord+TableRecord.swift */, 31A7787C1C6A4DD600F507F6 /* FetchedRecordsController.swift */, 560D92441C672C4B00F4F92B /* PersistableRecord.swift */, - 5674A6F31F307F600095F066 /* PersistableRecord+Encodable.swift */, 56A238A11B9C753B0082EB20 /* Record.swift */, 560D92461C672C4B00F4F92B /* TableRecord.swift */, ); path = Record; sourceTree = ""; }; - 56BF6D2B1DEF47DA006039A3 /* Legacy */ = { - isa = PBXGroup; - children = ( - 56BF6D2E1DEF47DA006039A3 /* Fixits-Swift2.swift */, - 56BF6D2C1DEF47DA006039A3 /* Fixits-0-84-0.swift */, - 56BF6D2D1DEF47DA006039A3 /* Fixits-0-90-1.swift */, - 56F3E7621E67F8C100BF0F01 /* Fixits-0.101.1.swift */, - 56E06F051E859064008AE2A4 /* Fixits-0.102.0.swift */, - 56D121591ED34978001347D2 /* Fixits-0.109.0.swift */, - 56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */, - 569A98F62039B716008D7DBF /* Fixits-3.0.swift */, - ); - path = Legacy; - sourceTree = ""; - }; 56DAA2C41DE99D8D006E10C8 /* Cursor */ = { isa = PBXGroup; children = ( @@ -1650,10 +1774,10 @@ isa = PBXGroup; children = ( 56A2386F1B9C75030082EB20 /* Core */, + 5614089D221596A100DAD589 /* Fixit */, 5698AC291D9E5A480056AF8C /* FTS */, - 56BF6D2B1DEF47DA006039A3 /* Legacy */, 56A238911B9C750B0082EB20 /* Migration */, - 56300B6D1C53F592005A543B /* QueryInterface */, + 5656A8252295BD56001FF3FF /* QueryInterface */, 56A2389F1B9C753B0082EB20 /* Record */, DC37743319C8CFCE004FCF85 /* Supporting Files */, 5659F4861EA8D94E004A4992 /* Utils */, @@ -1823,7 +1947,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0930; + LastUpgradeCheck = 1020; ORGANIZATIONNAME = "Gwendal Roué"; TargetAttributes = { F3BA7FFD1CFB25E4003DC1BA = { @@ -1846,7 +1970,7 @@ }; buildConfigurationList = DC3773ED19C8CBB3004FCF85 /* Build configuration list for PBXProject "GRDBCustom" */; compatibilityVersion = "Xcode 6.3"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, @@ -1893,6 +2017,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 569BBA44229066CB00478429 /* InflectionsTests.json in Resources */, F3BA80CE1CFB2FDE003DC1BA /* Betty.jpeg in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1908,6 +2033,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 569BBA43229066CB00478429 /* InflectionsTests.json in Resources */, F3BA80CD1CFB2FDD003DC1BA /* Betty.jpeg in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1956,31 +2082,30 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 56873BF11F2CB400004D24B4 /* Fixits-1.2.swift in Sources */, - 563EF4392161182C007DAACD /* AssociationAggregate.swift in Sources */, - 56BF6D421DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */, - 5616AAF7207CD59400AC3664 /* RequestProtocols.swift in Sources */, + 5656A8722295BD56001FF3FF /* HasOneThroughAssociation.swift in Sources */, 5636E9C11D22574100B9B05F /* FetchRequest.swift in Sources */, F3BA801B1CFB2886003DC1BA /* CGFloat.swift in Sources */, + 5656A85E2295BD56001FF3FF /* VirtualTableModule.swift in Sources */, + 5656A8882295BD56001FF3FF /* SQLOperators.swift in Sources */, 563EF44E2161F196007DAACD /* Inflections.swift in Sources */, 566B910E1FA4C3970012D5B0 /* Database+Statements.swift in Sources */, + 5656A8682295BD56001FF3FF /* HasOneAssociation.swift in Sources */, 566B91281FA4CF810012D5B0 /* Database+Schema.swift in Sources */, - 56CEB5161EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */, + 5656A8602295BD56001FF3FF /* FTS3+QueryInterface.swift in Sources */, + 5656A8982295BD56001FF3FF /* SQLRelation.swift in Sources */, 5659F4951EA8D964004A4992 /* ReadWriteBox.swift in Sources */, 566A842E20413D9A00E50BFD /* DatabaseSnapshot.swift in Sources */, 56CEB4F61EAA2EFA00BFAF62 /* FetchableRecord.swift in Sources */, + 5656A8522295BD56001FF3FF /* SQLInterpolation+QueryInterface.swift in Sources */, 56BB6EAE1D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */, F3BA801A1CFB2876003DC1BA /* StatementColumnConvertible.swift in Sources */, - 5653EB4C20961F6100F46237 /* ForeignKeyRequest.swift in Sources */, 5613ED6821A95E6100DC7A68 /* ValueObservation+Row.swift in Sources */, 566B91381FA4D3810012D5B0 /* TransactionObserver.swift in Sources */, - 56D1215F1ED34978001347D2 /* Fixits-0.109.0.swift in Sources */, 5613ED7021A95E6100DC7A68 /* ValueObservation+Count.swift in Sources */, - 566475D81D981D5E00FF74B8 /* SQLOperators.swift in Sources */, - 5653EB4420961F6100F46237 /* HasOneAssociation.swift in Sources */, - 56CEB5661EAA359A00BFAF62 /* SQLSelectable.swift in Sources */, 56CEB4FF1EAA2F4D00BFAF62 /* FTS3.swift in Sources */, + 5656A8922295BD56001FF3FF /* SQLSpecificExpressible+QueryInterface.swift in Sources */, 5698AD3A1DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */, + 5656A8742295BD56001FF3FF /* QueryInterfaceRequest.swift in Sources */, 564CE5A321B7A9C700652B19 /* ValueObservation+DistinctUntilChanged.swift in Sources */, 566B91181FA4C3F50012D5B0 /* DatabaseCollation.swift in Sources */, F3BA80181CFB2876003DC1BA /* SerializedDatabase.swift in Sources */, @@ -1988,94 +2113,100 @@ 5659F4A51EA8D997004A4992 /* Result.swift in Sources */, 564CE52521B312AD00652B19 /* ValueObservation+MapReducer.swift in Sources */, F3BA800D1CFB2871003DC1BA /* DatabasePool.swift in Sources */, + 5656A87C2295BD56001FF3FF /* QueryInterfaceRequest+Association.swift in Sources */, F3BA800B1CFB286D003DC1BA /* Database.swift in Sources */, F3BA80341CFB28A4003DC1BA /* Record.swift in Sources */, + 5656A87A2295BD56001FF3FF /* Row+QueryInterfaceRequest.swift in Sources */, + 56E9FAC52210468500C703A8 /* SQLInterpolation.swift in Sources */, 563EF421215F8A76007DAACD /* OrderedDictionary.swift in Sources */, F3BA80161CFB2876003DC1BA /* Row.swift in Sources */, 569EF0E7200D37FD00A9FA45 /* DatabaseRegion.swift in Sources */, F3BA80101CFB2876003DC1BA /* DatabaseReader.swift in Sources */, 564F9C331F07611800877A00 /* DatabaseFunction.swift in Sources */, + 5656A8942295BD56001FF3FF /* SQLFunctions.swift in Sources */, 5659F49D1EA8D989004A4992 /* Pool.swift in Sources */, - 5653EB4220961F6100F46237 /* BelongsToAssociation.swift in Sources */, - 5674A6F61F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */, - 56CEB5511EAA359A00BFAF62 /* SQLExpressible.swift in Sources */, + 5674A6F61F307F600095F066 /* EncodableRecord+Encodable.swift in Sources */, + 5656A88A2295BD56001FF3FF /* SQLExpressible.swift in Sources */, 5698AC3C1D9E5A590056AF8C /* FTS3Pattern.swift in Sources */, - 566475D11D981D5E00FF74B8 /* SQLFunctions.swift in Sources */, - 5664759F1D97D8A000FF74B8 /* SQLCollection.swift in Sources */, - 56E06F171E85906D008AE2A4 /* Fixits-0.102.0.swift in Sources */, - 5653EB5520961F7D00F46237 /* QueryInterfaceRequest+Association.swift in Sources */, - F3BA802B1CFB289B003DC1BA /* QueryInterfaceRequest.swift in Sources */, 5698AD171DAAD16F0056AF8C /* FTS5Tokenizer.swift in Sources */, - 56F3E7681E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */, + 569BBA4C229170B300478429 /* Inflections+English.swift in Sources */, + 5656A8762295BD56001FF3FF /* RequestProtocols.swift in Sources */, + 561729552235340E0006E219 /* EncodableRecord.swift in Sources */, + 5656A87E2295BD56001FF3FF /* SQLAssociation.swift in Sources */, F3BA80131CFB2876003DC1BA /* DatabaseValue.swift in Sources */, 56B964B61DA51D010002DA19 /* FTS5TokenizerDescriptor.swift in Sources */, F3BA80171CFB2876003DC1BA /* RowAdapter.swift in Sources */, 564CE4DB21B2DEEB00652B19 /* ValueObservation+CompactMap.swift in Sources */, - F3BA802F1CFB289B003DC1BA /* SQLSelectQuery.swift in Sources */, 56CEB5061EAA2F4D00BFAF62 /* FTS4.swift in Sources */, - 56CEB55F1EAA359A00BFAF62 /* SQLOrdering.swift in Sources */, F3BA80201CFB288C003DC1BA /* Date.swift in Sources */, 56A8C2351D1914540096E9D4 /* UUID.swift in Sources */, - 56BF6D341DEF47DA006039A3 /* Fixits-0-84-0.swift in Sources */, + 5656A8822295BD56001FF3FF /* SQLCollection.swift in Sources */, 56D51D051EA789FA0074638A /* FetchableRecord+TableRecord.swift in Sources */, F3BA80151CFB2876003DC1BA /* DatabaseWriter.swift in Sources */, 5613ED6E21A95E6100DC7A68 /* ValueReducer.swift in Sources */, F3BA800A1CFB286A003DC1BA /* Configuration.swift in Sources */, - 566475BF1D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift in Sources */, + 5656A86C2295BD56001FF3FF /* HasManyAssociation.swift in Sources */, + 5656A88E2295BD56001FF3FF /* SQLSelectable.swift in Sources */, 5671FC251DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift in Sources */, - 56CEB54A1EAA359A00BFAF62 /* Column.swift in Sources */, + 5656A8862295BD56001FF3FF /* SQLOrdering.swift in Sources */, F3BA80311CFB289F003DC1BA /* Migration.swift in Sources */, F3BA801D1CFB288C003DC1BA /* DatabaseDateComponents.swift in Sources */, 5674A6ED1F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */, 5657AB141D10899D006283EF /* URL.swift in Sources */, 5613ED6A21A95E6100DC7A68 /* ValueObservation+FetchableRecord.swift in Sources */, - 56D91AA02205E02300770D8D /* SQLRelation.swift in Sources */, 5644DE7920F8C8EA001FFDDE /* DatabaseValueConversion.swift in Sources */, 56DAA2E01DE9C827006E10C8 /* Cursor.swift in Sources */, - 56D91AA72205F2CF00770D8D /* DatabasePromise.swift in Sources */, F3BA800C1CFB286F003DC1BA /* DatabaseError.swift in Sources */, + 5656A8782295BD56001FF3FF /* TableRecord+QueryInterfaceRequest.swift in Sources */, 566B91301FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */, + 5656A86A2295BD56001FF3FF /* AssociationAggregate.swift in Sources */, F3BA80221CFB288C003DC1BA /* NSNumber.swift in Sources */, + 5656A8582295BD56001FF3FF /* SQLQueryGenerator.swift in Sources */, F3BA80321CFB28A4003DC1BA /* FetchedRecordsController.swift in Sources */, + 5656A8842295BD56001FF3FF /* SQLExpression.swift in Sources */, 5659F48D1EA8D94E004A4992 /* Utils.swift in Sources */, F3BA80231CFB288C003DC1BA /* NSString.swift in Sources */, + 5656A85A2295BD56001FF3FF /* SQLGenerationContext.swift in Sources */, 5690C3451D23E82A00E59934 /* Data.swift in Sources */, - 56FC987D1D969DEF00E3C842 /* SQLExpression+QueryInterface.swift in Sources */, + 5656A8A82295BF44001FF3FF /* DatabasePromise.swift in Sources */, + 5656A86E2295BD56001FF3FF /* HasManyThroughAssociation.swift in Sources */, F3BA80111CFB2876003DC1BA /* DatabaseSchemaCache.swift in Sources */, F3BA80281CFB2891003DC1BA /* StandardLibrary.swift in Sources */, F3BA80331CFB28A4003DC1BA /* PersistableRecord.swift in Sources */, - 568D13162207210400674B58 /* SQLSelectQueryGenerator.swift in Sources */, - 56BF6D3B1DEF47DA006039A3 /* Fixits-0-90-1.swift in Sources */, + 5656A8802295BD56001FF3FF /* SQLForeignKeyRequest.swift in Sources */, 56B964BE1DA51D0A0002DA19 /* FTS5Pattern.swift in Sources */, + 561408A1221596A100DAD589 /* GRDB-4.0.swift in Sources */, F3BA80211CFB288C003DC1BA /* NSNull.swift in Sources */, - 56CEB51E1EAA328900BFAF62 /* FTS5+QueryInterface.swift in Sources */, + 56FBFED72210731100945324 /* SQLRequest.swift in Sources */, 564CE43D21AA955B00652B19 /* ValueObserver.swift in Sources */, 5674A6FD1F307F600095F066 /* FetchableRecord+Decodable.swift in Sources */, F3BA80141CFB2876003DC1BA /* DatabaseValueConvertible.swift in Sources */, - 5698AC7D1DA37DCB0056AF8C /* VirtualTableModule.swift in Sources */, - 566AD8B71D5318F4002EC1A8 /* TableDefinition.swift in Sources */, + 5656A8702295BD56001FF3FF /* Association.swift in Sources */, + 5656A89C2295BD56001FF3FF /* SQLQuery.swift in Sources */, + 5656A88C2295BD56001FF3FF /* SQLExpression+QueryInterface.swift in Sources */, 5613ED6621A95E6100DC7A68 /* ValueObservation+Map.swift in Sources */, 5698AD261DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */, + 5656A85C2295BD56001FF3FF /* TableDefinition.swift in Sources */, + 5656A8562295BD56001FF3FF /* FTS5+QueryInterface.swift in Sources */, + 5656A8902295BD56001FF3FF /* Column.swift in Sources */, 564CE5B821B8FBEB00652B19 /* DatabaseRegionObservation.swift in Sources */, - F3BA802C1CFB289B003DC1BA /* SQLCollatedExpression.swift in Sources */, - 5653EB4A20961F6100F46237 /* ForeignKey.swift in Sources */, - 569A98F92039B716008D7DBF /* Fixits-3.0.swift in Sources */, 5613ED6C21A95E6100DC7A68 /* ValueObservation+DatabaseValueConvertible.swift in Sources */, - 5653EB4820961F6100F46237 /* HasManyAssociation.swift in Sources */, + 5656A8622295BD56001FF3FF /* TableRecord+Association.swift in Sources */, F3BA80301CFB289F003DC1BA /* DatabaseMigrator.swift in Sources */, + 56E9FAD62210538400C703A8 /* SQLLiteral.swift in Sources */, 5613ED6221A95E6100DC7A68 /* ValueObservation.swift in Sources */, F3BA80361CFB28A4003DC1BA /* TableRecord.swift in Sources */, 567071F5208A00BE006AD95A /* SQLiteDateParser.swift in Sources */, + 5656A89A2295BD56001FF3FF /* SQLSelectable+QueryInterface.swift in Sources */, F3BA80271CFB2891003DC1BA /* DatabaseValueConvertible+RawRepresentable.swift in Sources */, 5613ED6421A95E6100DC7A68 /* ValueObservation+Combine.swift in Sources */, - 5653EC092098737400F46237 /* SQLGenerationContext.swift in Sources */, - 566475A71D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift in Sources */, 5657AABE1D107001006283EF /* NSData.swift in Sources */, 5674A6E61F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */, - 5653EB5020961F6100F46237 /* Association.swift in Sources */, + 5656A8662295BD56001FF3FF /* BelongsToAssociation.swift in Sources */, F3BA800E1CFB2876003DC1BA /* DatabaseQueue.swift in Sources */, F3BA80191CFB2876003DC1BA /* Statement.swift in Sources */, - 56CEB5581EAA359A00BFAF62 /* SQLExpression.swift in Sources */, + 5656A8962295BD56001FF3FF /* SQLCollatedExpression.swift in Sources */, + 5656A8642295BD56001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift in Sources */, 56B964A21DA51B4C0002DA19 /* FTS5.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -2093,6 +2224,7 @@ 562EA8361F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */, 5653EB6D20961FB200F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */, 563EF45721631E3F007DAACD /* QueryInterfacePromiseTests.swift in Sources */, + 56DF0016228DDB8300D611F3 /* AssociationPrefetchingCodableRecordTests.swift in Sources */, F3BA80DD1CFB300E003DC1BA /* DatabaseValueConvertibleSubclassTests.swift in Sources */, 5644488A1EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */, F3BA80521CFB2B59003DC1BA /* DatabaseQueueSchemaCacheTests.swift in Sources */, @@ -2107,6 +2239,7 @@ 5627564A1E963AAC0035B653 /* DatabaseWriterTests.swift in Sources */, 56CC923C201E033400CB597E /* PrefixWhileCursorTests.swift in Sources */, F3BA80E51CFB3011003DC1BA /* DatabaseFunctionTests.swift in Sources */, + 560714EE227DD10F0091BB10 /* AssociationPrefetchingSQLTests.swift in Sources */, F3BA80531CFB2B59003DC1BA /* DataMemoryTests.swift in Sources */, F3BA80511CFB2B59003DC1BA /* DatabaseQueueReleaseMemoryTests.swift in Sources */, F3BA81221CFB3063003DC1BA /* RecordPrimaryKeyRowIDTests.swift in Sources */, @@ -2117,6 +2250,7 @@ 56EA63CA209C7F1E009715B8 /* DerivableRequestTests.swift in Sources */, F3BA80E91CFB3016003DC1BA /* RowAdapterTests.swift in Sources */, 562393371DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */, + 567F0B31220F196400D111FB /* SQLInterpolationTests.swift in Sources */, 5674A7161F3087710095F066 /* DatabaseValueConvertibleDecodableTests.swift in Sources */, 56B021D01D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */, 563B0703218627DF00B38F35 /* ValueObservationRowTests.swift in Sources */, @@ -2130,10 +2264,14 @@ F3BA80CF1CFB2FEA003DC1BA /* SchedulingWatchdogTests.swift in Sources */, F3BA80E71CFB3016003DC1BA /* RowCopiedFromStatementTests.swift in Sources */, F3BA812A1CFB3063003DC1BA /* RecordSubClassTests.swift in Sources */, + 569BBA40229065CF00478429 /* InflectionsTests.swift in Sources */, 5653EB7F20961FB200F46237 /* AssociationChainSQLTests.swift in Sources */, 6340BF871E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift in Sources */, + 56057C662291C7E500A7CB10 /* AssociationHasManyThroughRowScopeTests.swift in Sources */, 56AF74721D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */, F3BA80D21CFB2FF3003DC1BA /* PersistableRecordTests.swift in Sources */, + 5656A7F722946B1B001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift in Sources */, + 5615B259222AE19100061C1C /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */, 5698AC501DA2D48A0056AF8C /* FTS3RecordTests.swift in Sources */, 5665FA1F2129D807004D8612 /* DatabaseDateDecodingStrategyTests.swift in Sources */, F3BA80FD1CFB3024003DC1BA /* TransactionObserverSavepointsTests.swift in Sources */, @@ -2144,12 +2282,14 @@ F3BA80AF1CFB2FB1003DC1BA /* DatabaseCollationTests.swift in Sources */, 56CC9235201E009100CB597E /* DropWhileCursorTests.swift in Sources */, 56D507651F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift in Sources */, + 5615B286222B17BA00061C1C /* AssociationHasOneThroughDecodableRecordTests.swift in Sources */, 5657AB651D108BA9006283EF /* FoundationNSURLTests.swift in Sources */, 563B06D82185E04600B38F35 /* ValueObservationReducerTests.swift in Sources */, 5657AB6D1D108BA9006283EF /* FoundationURLTests.swift in Sources */, 563B06D42185E04600B38F35 /* ValueObservationReadonlyTests.swift in Sources */, 567F45AF1F888B2600030B59 /* TruncateOptimizationTests.swift in Sources */, F3BA804C1CFB2B24003DC1BA /* GRDBTestCase.swift in Sources */, + 56959620222C458A002CB7C9 /* AssociationHasManyThroughSQLTests.swift in Sources */, 5698ACBD1DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */, 5623931F1DECC02000A6B01F /* RowFetchTests.swift in Sources */, 562393701DEE0CD200A6B01F /* FlattenCursorTests.swift in Sources */, @@ -2158,8 +2298,10 @@ F3BA81121CFB3059003DC1BA /* DatabaseMigratorTests.swift in Sources */, 56176C801EACCD31000F3F2B /* EncryptionTests.swift in Sources */, F3BA80EB1CFB3016003DC1BA /* FetchableRecordTests.swift in Sources */, + 56B86E71220FF4C900524C16 /* SQLLiteralTests.swift in Sources */, F3BA81151CFB305E003DC1BA /* Record+QueryInterfaceRequestTests.swift in Sources */, F3BA80DC1CFB300E003DC1BA /* DatabaseValueConvertibleFetchTests.swift in Sources */, + 5615B26E222AFEB300061C1C /* AssociationHasOneThroughRowScopeTests.swift in Sources */, 5698AD021DAA8ACB0056AF8C /* FTS5CustomTokenizerTests.swift in Sources */, 5653EB8120961FB200F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */, 56B964CA1DA521450002DA19 /* FTS5PatternTests.swift in Sources */, @@ -2178,9 +2320,11 @@ 5698ACCC1DA62A2D0056AF8C /* FTS5TokenizerTests.swift in Sources */, 5613EDA421A96A8100DC7A68 /* ValueObservationCombineTests.swift in Sources */, 5653EB6B20961FB200F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */, + 560432A7228F167A009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */, 5690C33E1D23E7D200E59934 /* FoundationDateTests.swift in Sources */, 567A805A1D41350C00C7DCEC /* IndexInfoTests.swift in Sources */, 5674A7291F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */, + 56057C5A2291B18E00A7CB10 /* AssociationHasManyRowScopeTests.swift in Sources */, 56FEE8021F47253700D930EA /* TableRecordTests.swift in Sources */, F3BA81211CFB3063003DC1BA /* RecordPrimaryKeyNoneTests.swift in Sources */, F3BA80F71CFB3021003DC1BA /* SelectStatementTests.swift in Sources */, @@ -2188,6 +2332,7 @@ F3BA80FE1CFB3024003DC1BA /* TransactionObserverTests.swift in Sources */, F3BA80BA1CFB2FD1003DC1BA /* DatabasePoolCollationTests.swift in Sources */, F3BA80BD1CFB2FD1003DC1BA /* DatabasePoolFunctionTests.swift in Sources */, + 5615B279222B109600061C1C /* AssociationHasOneThroughFetchableRecordTests.swift in Sources */, F3BA81261CFB3063003DC1BA /* RecordCopyTests.swift in Sources */, 56A8C24D1D1918F30096E9D4 /* FoundationNSUUIDTests.swift in Sources */, 5653EB8320961FB200F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */, @@ -2227,13 +2372,16 @@ 563B06D62185E04600B38F35 /* ValueObservationFetchTests.swift in Sources */, 565EFAF51D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */, F3BA81231CFB3063003DC1BA /* RecordPrimaryKeySingleTests.swift in Sources */, + 56DF0018228DDB8300D611F3 /* AssociationPrefetchingRowTests.swift in Sources */, F3BA80541CFB2B59003DC1BA /* DatabaseRegionTests.swift in Sources */, 567DAF3C1EAB789800FC0928 /* DatabaseLogErrorTests.swift in Sources */, 566A84442041AB2D00E50BFD /* MutablePersistableRecordChangesTests.swift in Sources */, F3BA81171CFB305E003DC1BA /* QueryInterfaceExpressionsTests.swift in Sources */, + 569BBA2C228DE53200478429 /* AssociationPrefetchingFetchableRecordTests.swift in Sources */, 5670329C212B5462007D270F /* DatabaseUUIDEncodingStrategyTests.swift in Sources */, F3BA810B1CFB3056003DC1BA /* Row+FoundationTests.swift in Sources */, 5698AC901DA389380056AF8C /* FTS3TableBuilderTests.swift in Sources */, + 56043297228F00A9009D3FE2 /* OrderedDictionaryTests.swift in Sources */, 568068381EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */, F3BA80DB1CFB300E003DC1BA /* DatabaseValueConversionTests.swift in Sources */, 56741EAF1E66A8B3003E422D /* FetchRequestTests.swift in Sources */, @@ -2241,7 +2389,9 @@ F3BA81241CFB3063003DC1BA /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */, 5674A71F1F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift in Sources */, 564CE4E421B2E05400652B19 /* ValueObservationMapTests.swift in Sources */, + 56959636222D058B002CB7C9 /* AssociationHasManySQLTests.swift in Sources */, F3BA80E81CFB3016003DC1BA /* RowFromDictionaryTests.swift in Sources */, + 56AE6427222AACE300AD1B0B /* AssociationHasOneThroughSQLTests.swift in Sources */, 562393671DEE06D300A6B01F /* CursorTests.swift in Sources */, F3BA80B41CFB2FC9003DC1BA /* DatabaseQueueReadOnlyTests.swift in Sources */, F3BA81011CFB3032003DC1BA /* CGFloatTests.swift in Sources */, @@ -2264,31 +2414,30 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 56873BEE1F2CB400004D24B4 /* Fixits-1.2.swift in Sources */, - 563EF4382161182C007DAACD /* AssociationAggregate.swift in Sources */, - 56BF6D3F1DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */, - 5616AAF6207CD59400AC3664 /* RequestProtocols.swift in Sources */, + 5656A8712295BD56001FF3FF /* HasOneThroughAssociation.swift in Sources */, 5636E9BE1D22574100B9B05F /* FetchRequest.swift in Sources */, F3BA80771CFB2E5C003DC1BA /* CGFloat.swift in Sources */, + 5656A85D2295BD56001FF3FF /* VirtualTableModule.swift in Sources */, + 5656A8872295BD56001FF3FF /* SQLOperators.swift in Sources */, 563EF44D2161F196007DAACD /* Inflections.swift in Sources */, 566B910B1FA4C3970012D5B0 /* Database+Statements.swift in Sources */, + 5656A8672295BD56001FF3FF /* HasOneAssociation.swift in Sources */, 566B91251FA4CF810012D5B0 /* Database+Schema.swift in Sources */, - 56CEB5131EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */, + 5656A85F2295BD56001FF3FF /* FTS3+QueryInterface.swift in Sources */, + 5656A8972295BD56001FF3FF /* SQLRelation.swift in Sources */, 5659F4921EA8D964004A4992 /* ReadWriteBox.swift in Sources */, 566A842D20413D9A00E50BFD /* DatabaseSnapshot.swift in Sources */, 56CEB4F31EAA2EFA00BFAF62 /* FetchableRecord.swift in Sources */, + 5656A8512295BD56001FF3FF /* SQLInterpolation+QueryInterface.swift in Sources */, 56BB6EAB1D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */, F3BA80761CFB2E55003DC1BA /* StatementColumnConvertible.swift in Sources */, - 5653EB4B20961F6100F46237 /* ForeignKeyRequest.swift in Sources */, 5613ED6721A95E6100DC7A68 /* ValueObservation+Row.swift in Sources */, 566B91351FA4D3810012D5B0 /* TransactionObserver.swift in Sources */, - 56D1215C1ED34978001347D2 /* Fixits-0.109.0.swift in Sources */, 5613ED6F21A95E6100DC7A68 /* ValueObservation+Count.swift in Sources */, - 566475D51D981D5E00FF74B8 /* SQLOperators.swift in Sources */, - 5653EB4320961F6100F46237 /* HasOneAssociation.swift in Sources */, - 56CEB5631EAA359A00BFAF62 /* SQLSelectable.swift in Sources */, 56CEB4FC1EAA2F4D00BFAF62 /* FTS3.swift in Sources */, + 5656A8912295BD56001FF3FF /* SQLSpecificExpressible+QueryInterface.swift in Sources */, 5698AD371DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */, + 5656A8732295BD56001FF3FF /* QueryInterfaceRequest.swift in Sources */, 564CE5A221B7A9C700652B19 /* ValueObservation+DistinctUntilChanged.swift in Sources */, 566B91151FA4C3F50012D5B0 /* DatabaseCollation.swift in Sources */, F3BA80741CFB2E55003DC1BA /* SerializedDatabase.swift in Sources */, @@ -2296,94 +2445,100 @@ 5659F4A21EA8D997004A4992 /* Result.swift in Sources */, 564CE52421B312AD00652B19 /* ValueObservation+MapReducer.swift in Sources */, F3BA80691CFB2E55003DC1BA /* DatabasePool.swift in Sources */, + 5656A87B2295BD56001FF3FF /* QueryInterfaceRequest+Association.swift in Sources */, F3BA80671CFB2E55003DC1BA /* Database.swift in Sources */, F3BA80901CFB2E7A003DC1BA /* Record.swift in Sources */, + 5656A8792295BD56001FF3FF /* Row+QueryInterfaceRequest.swift in Sources */, + 56E9FAC42210468500C703A8 /* SQLInterpolation.swift in Sources */, 563EF420215F8A76007DAACD /* OrderedDictionary.swift in Sources */, F3BA80721CFB2E55003DC1BA /* Row.swift in Sources */, 569EF0E6200D37FD00A9FA45 /* DatabaseRegion.swift in Sources */, F3BA806C1CFB2E55003DC1BA /* DatabaseReader.swift in Sources */, 564F9C301F07611500877A00 /* DatabaseFunction.swift in Sources */, + 5656A8932295BD56001FF3FF /* SQLFunctions.swift in Sources */, 5659F49A1EA8D989004A4992 /* Pool.swift in Sources */, - 5653EB4120961F6100F46237 /* BelongsToAssociation.swift in Sources */, - 5674A6F51F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */, - 56CEB54E1EAA359A00BFAF62 /* SQLExpressible.swift in Sources */, + 5674A6F51F307F600095F066 /* EncodableRecord+Encodable.swift in Sources */, + 5656A8892295BD56001FF3FF /* SQLExpressible.swift in Sources */, 5698AC391D9E5A590056AF8C /* FTS3Pattern.swift in Sources */, - 566475CE1D981D5E00FF74B8 /* SQLFunctions.swift in Sources */, - 5664759C1D97D8A000FF74B8 /* SQLCollection.swift in Sources */, - 56E06F141E859069008AE2A4 /* Fixits-0.102.0.swift in Sources */, - 5653EB5420961F7D00F46237 /* QueryInterfaceRequest+Association.swift in Sources */, - F3BA80871CFB2E70003DC1BA /* QueryInterfaceRequest.swift in Sources */, 5698AD161DAAD16F0056AF8C /* FTS5Tokenizer.swift in Sources */, - 56F3E7651E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */, + 569BBA4D229170B300478429 /* Inflections+English.swift in Sources */, + 5656A8752295BD56001FF3FF /* RequestProtocols.swift in Sources */, + 561729562235340E0006E219 /* EncodableRecord.swift in Sources */, + 5656A87D2295BD56001FF3FF /* SQLAssociation.swift in Sources */, F3BA806F1CFB2E55003DC1BA /* DatabaseValue.swift in Sources */, 56B964B31DA51D010002DA19 /* FTS5TokenizerDescriptor.swift in Sources */, F3BA80731CFB2E55003DC1BA /* RowAdapter.swift in Sources */, 564CE4DA21B2DEEB00652B19 /* ValueObservation+CompactMap.swift in Sources */, - F3BA808B1CFB2E70003DC1BA /* SQLSelectQuery.swift in Sources */, 56CEB5031EAA2F4D00BFAF62 /* FTS4.swift in Sources */, - 56CEB55C1EAA359A00BFAF62 /* SQLOrdering.swift in Sources */, F3BA807C1CFB2E61003DC1BA /* Date.swift in Sources */, 56A8C2321D1914540096E9D4 /* UUID.swift in Sources */, - 56BF6D311DEF47DA006039A3 /* Fixits-0-84-0.swift in Sources */, + 5656A8812295BD56001FF3FF /* SQLCollection.swift in Sources */, 56D51D021EA789FA0074638A /* FetchableRecord+TableRecord.swift in Sources */, F3BA80711CFB2E55003DC1BA /* DatabaseWriter.swift in Sources */, 5613ED6D21A95E6100DC7A68 /* ValueReducer.swift in Sources */, F3BA80661CFB2E55003DC1BA /* Configuration.swift in Sources */, - 566475BC1D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift in Sources */, + 5656A86B2295BD56001FF3FF /* HasManyAssociation.swift in Sources */, + 5656A88D2295BD56001FF3FF /* SQLSelectable.swift in Sources */, 5671FC221DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift in Sources */, - 56CEB5471EAA359A00BFAF62 /* Column.swift in Sources */, + 5656A8852295BD56001FF3FF /* SQLOrdering.swift in Sources */, F3BA808D1CFB2E75003DC1BA /* Migration.swift in Sources */, F3BA80791CFB2E61003DC1BA /* DatabaseDateComponents.swift in Sources */, 5674A6EC1F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */, 5657AB111D10899D006283EF /* URL.swift in Sources */, 5613ED6921A95E6100DC7A68 /* ValueObservation+FetchableRecord.swift in Sources */, - 56D91A9F2205E02300770D8D /* SQLRelation.swift in Sources */, 5644DE7820F8C8EA001FFDDE /* DatabaseValueConversion.swift in Sources */, 56DAA2DD1DE9C827006E10C8 /* Cursor.swift in Sources */, - 56D91AA62205F2CF00770D8D /* DatabasePromise.swift in Sources */, F3BA80681CFB2E55003DC1BA /* DatabaseError.swift in Sources */, + 5656A8772295BD56001FF3FF /* TableRecord+QueryInterfaceRequest.swift in Sources */, 566B912D1FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */, + 5656A8692295BD56001FF3FF /* AssociationAggregate.swift in Sources */, F3BA807E1CFB2E61003DC1BA /* NSNumber.swift in Sources */, + 5656A8572295BD56001FF3FF /* SQLQueryGenerator.swift in Sources */, F3BA808E1CFB2E7A003DC1BA /* FetchedRecordsController.swift in Sources */, + 5656A8832295BD56001FF3FF /* SQLExpression.swift in Sources */, 5659F48A1EA8D94E004A4992 /* Utils.swift in Sources */, F3BA807F1CFB2E61003DC1BA /* NSString.swift in Sources */, + 5656A8592295BD56001FF3FF /* SQLGenerationContext.swift in Sources */, 5690C3421D23E82A00E59934 /* Data.swift in Sources */, - 56FC987A1D969DEF00E3C842 /* SQLExpression+QueryInterface.swift in Sources */, + 5656A8A72295BF44001FF3FF /* DatabasePromise.swift in Sources */, + 5656A86D2295BD56001FF3FF /* HasManyThroughAssociation.swift in Sources */, F3BA806D1CFB2E55003DC1BA /* DatabaseSchemaCache.swift in Sources */, F3BA80841CFB2E67003DC1BA /* StandardLibrary.swift in Sources */, F3BA808F1CFB2E7A003DC1BA /* PersistableRecord.swift in Sources */, - 568D13152207210400674B58 /* SQLSelectQueryGenerator.swift in Sources */, - 56BF6D381DEF47DA006039A3 /* Fixits-0-90-1.swift in Sources */, + 5656A87F2295BD56001FF3FF /* SQLForeignKeyRequest.swift in Sources */, 56B964BB1DA51D0A0002DA19 /* FTS5Pattern.swift in Sources */, + 561408A0221596A100DAD589 /* GRDB-4.0.swift in Sources */, F3BA807D1CFB2E61003DC1BA /* NSNull.swift in Sources */, - 56CEB51B1EAA328900BFAF62 /* FTS5+QueryInterface.swift in Sources */, + 56FBFED62210731100945324 /* SQLRequest.swift in Sources */, 564CE43C21AA955B00652B19 /* ValueObserver.swift in Sources */, 5674A6FC1F307F600095F066 /* FetchableRecord+Decodable.swift in Sources */, F3BA80701CFB2E55003DC1BA /* DatabaseValueConvertible.swift in Sources */, - 5698AC7A1DA37DCB0056AF8C /* VirtualTableModule.swift in Sources */, - 566AD8B41D5318F4002EC1A8 /* TableDefinition.swift in Sources */, + 5656A86F2295BD56001FF3FF /* Association.swift in Sources */, + 5656A89B2295BD56001FF3FF /* SQLQuery.swift in Sources */, + 5656A88B2295BD56001FF3FF /* SQLExpression+QueryInterface.swift in Sources */, 5613ED6521A95E6100DC7A68 /* ValueObservation+Map.swift in Sources */, 5698AD231DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */, + 5656A85B2295BD56001FF3FF /* TableDefinition.swift in Sources */, + 5656A8552295BD56001FF3FF /* FTS5+QueryInterface.swift in Sources */, + 5656A88F2295BD56001FF3FF /* Column.swift in Sources */, 564CE5B721B8FBEB00652B19 /* DatabaseRegionObservation.swift in Sources */, - F3BA80881CFB2E70003DC1BA /* SQLCollatedExpression.swift in Sources */, - 5653EB4920961F6100F46237 /* ForeignKey.swift in Sources */, - 569A98F82039B716008D7DBF /* Fixits-3.0.swift in Sources */, 5613ED6B21A95E6100DC7A68 /* ValueObservation+DatabaseValueConvertible.swift in Sources */, - 5653EB4720961F6100F46237 /* HasManyAssociation.swift in Sources */, + 5656A8612295BD56001FF3FF /* TableRecord+Association.swift in Sources */, F3BA808C1CFB2E75003DC1BA /* DatabaseMigrator.swift in Sources */, + 56E9FAD52210538400C703A8 /* SQLLiteral.swift in Sources */, 5613ED6121A95E6100DC7A68 /* ValueObservation.swift in Sources */, F3BA80921CFB2E7A003DC1BA /* TableRecord.swift in Sources */, 567071F4208A00BE006AD95A /* SQLiteDateParser.swift in Sources */, + 5656A8992295BD56001FF3FF /* SQLSelectable+QueryInterface.swift in Sources */, F3BA80831CFB2E67003DC1BA /* DatabaseValueConvertible+RawRepresentable.swift in Sources */, 5613ED6321A95E6100DC7A68 /* ValueObservation+Combine.swift in Sources */, - 5653EC082098737400F46237 /* SQLGenerationContext.swift in Sources */, - 566475A41D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift in Sources */, 5657AABB1D107001006283EF /* NSData.swift in Sources */, 5674A6E51F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */, - 5653EB4F20961F6100F46237 /* Association.swift in Sources */, + 5656A8652295BD56001FF3FF /* BelongsToAssociation.swift in Sources */, F3BA806A1CFB2E55003DC1BA /* DatabaseQueue.swift in Sources */, F3BA80751CFB2E55003DC1BA /* Statement.swift in Sources */, - 56CEB5551EAA359A00BFAF62 /* SQLExpression.swift in Sources */, + 5656A8952295BD56001FF3FF /* SQLCollatedExpression.swift in Sources */, + 5656A8632295BD56001FF3FF /* FetchableRecord+QueryInterfaceRequest.swift in Sources */, 56B9649F1DA51B4C0002DA19 /* FTS5.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -2401,6 +2556,7 @@ 562EA8321F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */, 5653EB6C20961FB200F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */, 563EF45621631E3F007DAACD /* QueryInterfacePromiseTests.swift in Sources */, + 56DF0015228DDB8300D611F3 /* AssociationPrefetchingCodableRecordTests.swift in Sources */, 56A8C2451D1918EF0096E9D4 /* FoundationNSUUIDTests.swift in Sources */, 5657AB591D108BA9006283EF /* FoundationNSStringTests.swift in Sources */, 564448861EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */, @@ -2415,6 +2571,7 @@ 56071A501DB54ED300CA6E47 /* FetchedRecordsControllerTests.swift in Sources */, F3BA80AC1CFB2FA6003DC1BA /* DatabaseQueueSchemaCacheTests.swift in Sources */, 56CC923B201E033400CB597E /* PrefixWhileCursorTests.swift in Sources */, + 560714ED227DD10F0091BB10 /* AssociationPrefetchingSQLTests.swift in Sources */, 562756461E963AAC0035B653 /* DatabaseWriterTests.swift in Sources */, 56A8C2461D1918EF0096E9D4 /* FoundationUUIDTests.swift in Sources */, F3BA80F61CFB301E003DC1BA /* StatementColumnConvertibleFetchTests.swift in Sources */, @@ -2425,6 +2582,7 @@ 56EA63C9209C7F1E009715B8 /* DerivableRequestTests.swift in Sources */, F3BA811D1CFB305F003DC1BA /* TableRecord+QueryInterfaceRequestTests.swift in Sources */, F3BA80AD1CFB2FA6003DC1BA /* DataMemoryTests.swift in Sources */, + 567F0B30220F196400D111FB /* SQLInterpolationTests.swift in Sources */, 5698ACB91DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */, 5674A7141F3087710095F066 /* DatabaseValueConvertibleDecodableTests.swift in Sources */, 563B0702218627DF00B38F35 /* ValueObservationRowTests.swift in Sources */, @@ -2438,10 +2596,14 @@ F3BA80D31CFB2FF4003DC1BA /* MutablePersistableRecordTests.swift in Sources */, 562393751DEE104400A6B01F /* MapCursorTests.swift in Sources */, F3BA80D01CFB2FEC003DC1BA /* SchedulingWatchdogTests.swift in Sources */, + 569BBA41229065CF00478429 /* InflectionsTests.swift in Sources */, 5653EB7E20961FB200F46237 /* AssociationChainSQLTests.swift in Sources */, F3BA80EC1CFB3017003DC1BA /* RowCopiedFromStatementTests.swift in Sources */, + 56057C652291C7E500A7CB10 /* AssociationHasManyThroughRowScopeTests.swift in Sources */, F3BA80D41CFB2FF4003DC1BA /* PersistableRecordTests.swift in Sources */, 6340BF831E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift in Sources */, + 5656A7F622946B1B001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift in Sources */, + 5615B258222AE19100061C1C /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */, F3BA80FF1CFB3025003DC1BA /* TransactionObserverSavepointsTests.swift in Sources */, 5665FA1E2129D807004D8612 /* DatabaseDateDecodingStrategyTests.swift in Sources */, 5698AC4C1DA2D48A0056AF8C /* FTS3RecordTests.swift in Sources */, @@ -2452,12 +2614,14 @@ 56B964DB1DA5216B0002DA19 /* FTS5RecordTests.swift in Sources */, 56CC9234201E009000CB597E /* DropWhileCursorTests.swift in Sources */, 56D507611F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift in Sources */, + 5615B285222B17BA00061C1C /* AssociationHasOneThroughDecodableRecordTests.swift in Sources */, F3BA80B01CFB2FB2003DC1BA /* DatabaseCollationTests.swift in Sources */, 563B06D72185E04600B38F35 /* ValueObservationReducerTests.swift in Sources */, 56C7A6AE1D2DFF6100EFB0C2 /* FoundationNSDateTests.swift in Sources */, 563B06D32185E04600B38F35 /* ValueObservationReadonlyTests.swift in Sources */, 567F45AB1F888B2600030B59 /* TruncateOptimizationTests.swift in Sources */, F3BA80A61CFB2F91003DC1BA /* GRDBTestCase.swift in Sources */, + 56959621222C458A002CB7C9 /* AssociationHasManyThroughSQLTests.swift in Sources */, 5657AB411D108BA9006283EF /* FoundationNSDataTests.swift in Sources */, 56B964C61DA521450002DA19 /* FTS5PatternTests.swift in Sources */, 562205FA1E420E49005860AC /* DatabasePoolReleaseMemoryTests.swift in Sources */, @@ -2466,8 +2630,10 @@ 562205FD1E420EA2005860AC /* DatabasePoolBackupTests.swift in Sources */, 562206091E420EB2005860AC /* DatabaseQueueConcurrencyTests.swift in Sources */, 56176C7E1EACCD2F000F3F2B /* EncryptionTests.swift in Sources */, + 56B86E70220FF4C900524C16 /* SQLLiteralTests.swift in Sources */, F3BA811C1CFB305F003DC1BA /* QueryInterfaceExpressionsTests.swift in Sources */, 5698ACD11DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */, + 5615B26D222AFEB300061C1C /* AssociationHasOneThroughRowScopeTests.swift in Sources */, 562205FB1E420E49005860AC /* DatabasePoolSchemaCacheTests.swift in Sources */, 5653EB8020961FB200F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */, 5657AB611D108BA9006283EF /* FoundationNSURLTests.swift in Sources */, @@ -2486,9 +2652,11 @@ F3BA80B81CFB2FCD003DC1BA /* DatabaseErrorTests.swift in Sources */, 5613EDA321A96A8100DC7A68 /* ValueObservationCombineTests.swift in Sources */, 5653EB6A20961FB200F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */, + 560432A6228F167A009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */, 5698AC061D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */, F3BA80FA1CFB3021003DC1BA /* SelectStatementTests.swift in Sources */, 5674A7271F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */, + 56057C592291B18E00A7CB10 /* AssociationHasManyRowScopeTests.swift in Sources */, 56FEE7FE1F47253700D930EA /* TableRecordTests.swift in Sources */, F3BA81191CFB305F003DC1BA /* QueryInterfaceRequestTests.swift in Sources */, F3BA812F1CFB3064003DC1BA /* RecordPrimaryKeyNoneTests.swift in Sources */, @@ -2496,6 +2664,7 @@ 56F3E74C1E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */, F3BA81001CFB3025003DC1BA /* TransactionObserverTests.swift in Sources */, F3BA80C01CFB2FD2003DC1BA /* DatabasePoolCollationTests.swift in Sources */, + 5615B278222B109600061C1C /* AssociationHasOneThroughFetchableRecordTests.swift in Sources */, 5698ACA11DA4B0430056AF8C /* FTS4TableBuilderTests.swift in Sources */, F3BA80C31CFB2FD2003DC1BA /* DatabasePoolFunctionTests.swift in Sources */, 5653EB8220961FB200F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */, @@ -2535,13 +2704,16 @@ 563B06D52185E04600B38F35 /* ValueObservationFetchTests.swift in Sources */, 562205FE1E420EA2005860AC /* DatabasePoolConcurrencyTests.swift in Sources */, 565EFAF11D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */, + 56DF0017228DDB8300D611F3 /* AssociationPrefetchingRowTests.swift in Sources */, F3BA812E1CFB3064003DC1BA /* RecordPrimaryKeyMultipleTests.swift in Sources */, F3BA81021CFB3032003DC1BA /* CGFloatTests.swift in Sources */, 566A84432041AB2D00E50BFD /* MutablePersistableRecordChangesTests.swift in Sources */, 567DAF381EAB789800FC0928 /* DatabaseLogErrorTests.swift in Sources */, + 569BBA2B228DE53200478429 /* AssociationPrefetchingFetchableRecordTests.swift in Sources */, 5670329B212B5462007D270F /* DatabaseUUIDEncodingStrategyTests.swift in Sources */, F3BA81131CFB305B003DC1BA /* DatabaseMigratorTests.swift in Sources */, F3BA81381CFB3064003DC1BA /* RecordSubClassTests.swift in Sources */, + 56043296228F00A9009D3FE2 /* OrderedDictionaryTests.swift in Sources */, F3BA81351CFB3064003DC1BA /* RecordEditedTests.swift in Sources */, 568068341EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */, 5657AB691D108BA9006283EF /* FoundationURLTests.swift in Sources */, @@ -2549,7 +2721,9 @@ 56B964D61DA521450002DA19 /* FTS5TableBuilderTests.swift in Sources */, 5674A71D1F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift in Sources */, 564CE4E321B2E05400652B19 /* ValueObservationMapTests.swift in Sources */, + 56959637222D058B002CB7C9 /* AssociationHasManySQLTests.swift in Sources */, 562393511DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */, + 56AE6428222AACE300AD1B0B /* AssociationHasOneThroughSQLTests.swift in Sources */, F3BA812D1CFB3064003DC1BA /* RecordMinimalPrimaryKeySingleTests.swift in Sources */, 5698AC831DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */, F3BA811B1CFB305F003DC1BA /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */, @@ -2598,6 +2772,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -2643,7 +2818,7 @@ MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -2653,6 +2828,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -2690,7 +2866,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; MTL_ENABLE_DEBUG_INFO = NO; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; diff --git a/GRDBCustom.xcodeproj/xcshareddata/xcschemes/GRDBCustomSQLiteOSX.xcscheme b/GRDBCustom.xcodeproj/xcshareddata/xcschemes/GRDBCustomSQLiteOSX.xcscheme index e8bbdd0c6..4682c9c62 100644 --- a/GRDBCustom.xcodeproj/xcshareddata/xcschemes/GRDBCustomSQLiteOSX.xcscheme +++ b/GRDBCustom.xcodeproj/xcshareddata/xcschemes/GRDBCustomSQLiteOSX.xcscheme @@ -1,6 +1,6 @@ = 9.0, with iOS8.1 Simulator installed -# CocoaPods ~> 1.2.0 - https://cocoapods.org -# Carthage ~> 0.20.1 - https://github.com/carthage/carthage +# CocoaPods ~> 1.6.0 - https://cocoapods.org # Jazzy ~> 0.7.4 - https://github.com/realm/jazzy -CARTHAGE := $(shell command -v carthage) GIT := $(shell command -v git) JAZZY := $(shell command -v jazzy) POD := $(shell command -v pod) @@ -51,26 +49,19 @@ endif TEST_ACTIONS = clean build build-for-testing test-without-building # When adding support for an Xcode version, look for available devices with `instruments -s devices` -ifeq ($(XCODEVERSION),10.1) - MIN_SWIFT_VERSION = 4.0 +ifeq ($(XCODEVERSION),10.2) + MAX_SWIFT_VERSION = 5 + MIN_SWIFT_VERSION = 4.2 + MAX_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone XS,OS=12.2" + MIN_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 4s,OS=9.0" +else ifeq ($(XCODEVERSION),10.1) MAX_SWIFT_VERSION = 4.2 MAX_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone XS,OS=12.1" MIN_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 4s,OS=9.0" else ifeq ($(XCODEVERSION),10.0) - MIN_SWIFT_VERSION = 4.0 MAX_SWIFT_VERSION = 4.2 MAX_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 8,OS=12.0" MIN_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 4s,OS=9.0" -else ifeq ($(XCODEVERSION),9.4) - # MIN_SWIFT_VERSION undefined: only check MAX_SWIFT_VERSION - MAX_SWIFT_VERSION = 4.0 - MAX_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 8,OS=11.4" - MIN_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 4s,OS=9.0" -else ifeq ($(XCODEVERSION),9.3) - # MIN_SWIFT_VERSION undefined: only check MAX_SWIFT_VERSION - MAX_SWIFT_VERSION = 4.0 - MAX_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 8,OS=11.3" - MIN_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 4s,OS=9.0" else # Swift 4.1 required: Xcode < 9.3 is not supported endif @@ -108,12 +99,12 @@ endif test: test_framework test_install test_framework: test_framework_darwin -test_framework_darwin: test_framework_GRDB test_framework_GRDBCustom test_framework_GRDBCipher test_SPM +test_framework_darwin: test_framework_GRDB test_framework_GRDBCustom test_framework_SQLCipher test_SPM test_framework_GRDB: test_framework_GRDBOSX test_framework_GRDBWatchOS test_framework_GRDBiOS test_framework_GRDBCustom: test_framework_GRDBCustomSQLiteOSX test_framework_GRDBCustomSQLiteiOS -test_framework_GRDBCipher: test_framework_GRDBCipherOSX test_framework_GRDBCipheriOS -test_install: test_install_manual test_install_GRDBCipher test_install_SPM test_install_GRDB_CocoaPods test_install_GRDBCipher_CocoaPods test_CocoaPodsLint -test_CocoaPodsLint: test_CocoaPodsLint_GRDB test_CocoaPodsLint_GRDBCipher +test_framework_SQLCipher: test_framework_SQLCipher3 test_framework_SQLCipher4 +test_install: test_install_manual test_install_SPM test_install_GRDB_CocoaPods test_CocoaPodsLint +test_CocoaPodsLint: test_CocoaPodsLint_GRDB test_framework_GRDBOSX: test_framework_GRDBOSX_maxSwift test_framework_GRDBOSX_minSwift @@ -224,33 +215,35 @@ test_framework_GRDBCustomSQLiteiOS_minTarget: SQLiteCustom $(TEST_ACTIONS) \ $(XCPRETTY) -test_framework_GRDBCipherOSX: SQLCipher +test_framework_SQLCipher3: +ifdef POD + cd Tests/CocoaPods/SQLCipher3 && \ + $(POD) install && \ $(XCODEBUILD) \ - -project GRDBCipher.xcodeproj \ - -scheme GRDBCipherOSX \ + -workspace GRDBTests.xcworkspace \ + -scheme GRDBTests \ SWIFT_VERSION=$(MAX_SWIFT_VERSION) \ - $(TEST_ACTIONS) \ + build-for-testing test-without-building \ $(XCPRETTY) +else + @echo CocoaPods must be installed for test_framework_SQLCipher3 + @exit 1 +endif -test_framework_GRDBCipheriOS: test_framework_GRDBCipheriOS_maxTarget test_framework_GRDBCipheriOS_minTarget - -test_framework_GRDBCipheriOS_maxTarget: SQLCipher +test_framework_SQLCipher4: +ifdef POD + cd Tests/CocoaPods/SQLCipher4 && \ + $(POD) install && \ $(XCODEBUILD) \ - -project GRDBCipher.xcodeproj \ - -scheme GRDBCipheriOS \ - -destination $(MAX_IOS_DESTINATION) \ + -workspace GRDBTests.xcworkspace \ + -scheme GRDBTests \ SWIFT_VERSION=$(MAX_SWIFT_VERSION) \ - $(TEST_ACTIONS) \ - $(XCPRETTY) - -test_framework_GRDBCipheriOS_minTarget: SQLCipher - $(XCODEBUILD) \ - -project GRDBCipher.xcodeproj \ - -scheme GRDBCipheriOS \ - -destination $(MIN_IOS_DESTINATION) \ - SWIFT_VERSION=$(MAX_SWIFT_VERSION) \ - $(TEST_ACTIONS) \ + build-for-testing test-without-building \ $(XCPRETTY) +else + @echo CocoaPods must be installed for test_framework_SQLCipher4 + @exit 1 +endif test_SPM: # Add sanitizers when available: https://twitter.com/simjp/status/929140877540278272 @@ -268,15 +261,6 @@ test_install_manual: clean build \ $(XCPRETTY) -test_install_GRDBCipher: SQLCipher - $(XCODEBUILD) \ - -project Tests/GRDBCipher/GRDBiOS/GRDBiOS.xcodeproj \ - -scheme GRDBiOS \ - -configuration Release \ - -destination $(MAX_IOS_DESTINATION) \ - clean build \ - $(XCPRETTY) - test_install_SPM: cd Tests/SPM && \ ( if [ -a .build ] && [ -a Package.resolved ]; then $(SWIFT) package reset; fi ) && \ @@ -291,9 +275,6 @@ test_install_SPM: test_install_GRDB_CocoaPods: ifdef POD cd Tests/CocoaPods/GRDBiOS && \ - rm -rf iOS.xcworkspace && \ - rm -rf Pods && \ - rm -rf Podfile.lock && \ $(POD) install && \ $(XCODEBUILD) \ -workspace iOS.xcworkspace \ @@ -307,24 +288,6 @@ else @exit 1 endif -test_install_GRDBCipher_CocoaPods: -ifdef POD - cd Tests/CocoaPods/GRDBCipherMacOS && \ - rm -rf GRDBCipherMacOS.xcworkspace && \ - rm -rf Pods && \ - rm -rf Podfile.lock && \ - $(POD) install && \ - $(XCODEBUILD) \ - -workspace GRDBCipherMacOS.xcworkspace \ - -scheme GRDBCipherMacOS \ - -configuration Release \ - clean build \ - $(XCPRETTY) -else - @echo CocoaPods must be installed for test_install_GRDBCipher_CocoaPods - @exit 1 -endif - test_CocoaPodsLint_GRDB: ifdef POD $(POD) lib lint GRDB.swift.podspec --allow-warnings $(COCOAPODS_EXTRA_TIME) @@ -333,44 +296,20 @@ else @exit 1 endif -test_CocoaPodsLint_GRDBCipher: -ifdef POD - $(POD) lib lint GRDBCipher.podspec --allow-warnings $(COCOAPODS_EXTRA_TIME) -else - @echo CocoaPods must be installed for test_CocoaPodsLint_GRDBCipher - @exit 1 -endif - -test_CarthageBuild: SQLiteCustom SQLCipher -ifdef CARTHAGE - rm -rf Carthage - $(CARTHAGE) build --no-skip-current - $(XCODEBUILD) \ - -project Tests/Carthage/GRDBiOS/iOS.xcodeproj \ - -scheme iOS \ - -configuration Release \ - -destination $(MAX_IOS_DESTINATION) \ - clean build \ - $(XCPRETTY) -else - @echo Carthage must be installed for test_CarthageBuild - @exit 1 -endif - test_performance: Realm FMDB SQLite.swift $(XCODEBUILD) \ -project GRDB.xcodeproj \ -scheme GRDBOSXPerformanceComparisonTests \ build-for-testing test-without-building -Realm: Tests/Performance/Realm/build/osx/swift-4.2.1/RealmSwift.framework +Realm: Tests/Performance/Realm/build/osx/swift-10.2.1/RealmSwift.framework # Makes sure the Tests/Performance/Realm submodule has been downloaded, and Realm framework has been built. -Tests/Performance/Realm/build/osx/swift-4.2.1/RealmSwift.framework: +Tests/Performance/Realm/build/osx/swift-10.2.1/RealmSwift.framework: $(GIT) submodule update --init --recursive Tests/Performance/Realm cd Tests/Performance/Realm && sh build.sh osx-swift -FMDB: Tests/Performance/fmdb/FMDatabase.h +FMDB: Tests/Performance/fmdb/src/fmdb/FMDatabase.h # Makes sure the Tests/Performance/fmdb submodule has been downloaded Tests/Performance/fmdb/FMDatabase.h: @@ -397,13 +336,6 @@ SQLiteCustom: SQLiteCustom/src/sqlite3.h SQLiteCustom/src/sqlite3.h: $(GIT) submodule update --init SQLiteCustom/src -# Target that setups SQLCipher -SQLCipher: SQLCipher/src/sqlite3.h - -# Makes sure the SQLCipher/src submodule has been downloaded -SQLCipher/src/sqlite3.h: - $(GIT) submodule update --init SQLCipher/src - # Documentation # ============= @@ -415,10 +347,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/v3.7.0 \ - --module-version 3.7 \ + --github-file-prefix https://github.com/groue/GRDB.swift/tree/v4.0.0 \ + --module-version 4.0 \ --module GRDB \ - --root-url http://groue.github.io/GRDB.swift/docs/3.7/ \ + --root-url http://groue.github.io/GRDB.swift/docs/4.0/ \ --output Documentation/Reference \ --xcodebuild-arguments -project,GRDB.xcodeproj,-scheme,GRDBiOS else @@ -436,15 +368,13 @@ distclean: rm -rf Tests/Performance/fmdb && $(GIT) checkout -- Tests/Performance/fmdb rm -rf Tests/Performance/SQLite.swift && $(GIT) checkout -- Tests/Performance/SQLite.swift rm -rf Tests/Performance/Realm && $(GIT) checkout -- Tests/Performance/Realm - rm -rf SQLCipher/src && $(GIT) checkout -- SQLCipher/src rm -rf SQLiteCustom/src && $(GIT) checkout -- SQLiteCustom/src clean: $(SWIFT) package reset cd Tests/SPM && $(SWIFT) package reset rm -rf Documentation/Reference - if [ -d SQLCipher/src ]; then cd SQLCipher/src && $(GIT) clean -f; fi if [ -a Tests/Performance/Realm/build.sh ]; then cd Tests/Performance/Realm && sh build.sh clean; fi find . -name Package.resolved | xargs rm -f -.PHONY: distclean clean doc test SQLCipher SQLiteCustom +.PHONY: distclean clean doc test SQLiteCustom diff --git a/Package.swift b/Package.swift index 76aa827c5..a7589da8d 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.1 +// swift-tools-version:4.2 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -18,12 +18,11 @@ let package = Package( dependencies: ["GRDB"], path: "Tests", exclude: [ - "Carthage", "CocoaPods", "Crash", - "GRDBCipher", "Performance", "SPM" ]) - ] + ], + swiftLanguageVersions: [.v4_2, .version("5")] ) diff --git a/Playgrounds/CustomizedDecodingOfDatabaseRows.playground/Contents.swift b/Playgrounds/CustomizedDecodingOfDatabaseRows.playground/Contents.swift index 2b1a387ba..d5a9e4acb 100644 --- a/Playgrounds/CustomizedDecodingOfDatabaseRows.playground/Contents.swift +++ b/Playgrounds/CustomizedDecodingOfDatabaseRows.playground/Contents.swift @@ -83,15 +83,17 @@ try dbQueue.write { db in } // Demo values: two Foo and one Bar - try db.execute(""" - INSERT INTO base (type, fooName, barScore) VALUES (?, ?, ?); - INSERT INTO base (type, fooName, barScore) VALUES (?, ?, ?); - INSERT INTO base (type, fooName, barScore) VALUES (?, ?, ?); - """, arguments: [ + try db.execute( + sql: """ + INSERT INTO base (type, fooName, barScore) VALUES (?, ?, ?); + INSERT INTO base (type, fooName, barScore) VALUES (?, ?, ?); + INSERT INTO base (type, fooName, barScore) VALUES (?, ?, ?); + """, + arguments: [ "Foo", "Arthur", nil, "Bar", nil, 100, "Foo", "Barbara", nil, - ]) + ]) } //: We also need a method that decodes database rows into `Foo` or `Bar` @@ -140,7 +142,7 @@ extension Base { try dbQueue.read { db in print("> KISS: Fetch from SQL") - let rows = try Row.fetchAll(db, "SELECT * FROM base") // Fetch database rows + let rows = try Row.fetchAll(db, sql: "SELECT * FROM base") // Fetch database rows let bases = rows.map { row in // Decode database rows Base.decode(row: row) } @@ -210,13 +212,15 @@ extension Base: MyDatabaseDecoder { //: **prepared statement**: //: //: try dbQueue.read { db in -//: let statement = try db.makeSelectStatement("SELECT ...") +//: let statement = try db.makeSelectStatement(sql: "SELECT ...") //: try Base.fetchCursor(statement) // Cursor of Base //: try Base.fetchAll(statement) // [Base] //: try Base.fetchOne(statement) // Base? //: } extension MyDatabaseDecoder { + // MARK: - Fetch from SelectStatement + // SelectStatement, StatementArguments, and RowAdapter are the fundamental // fetching parameters of GRDB. Make sure to accept them all: static func fetchCursor(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> MapCursor { @@ -239,7 +243,7 @@ extension MyDatabaseDecoder { try dbQueue.read { db in print("> Fetch from prepared statement") - let statement = try db.makeSelectStatement("SELECT * FROM base") + let statement = try db.makeSelectStatement(sql: "SELECT * FROM base") let bases = try Base.fetchAll(statement) for base in bases { print(base.description) @@ -258,6 +262,8 @@ try dbQueue.read { db in //: try Base.fetchOne(db, request) // Base? //: } extension MyDatabaseDecoder { + // MARK: - Fetch from FetchRequest + static func fetchCursor(_ db: Database, _ request: R) throws -> MapCursor { let (statement, adapter) = try request.prepare(db) return try fetchCursor(statement, adapter: adapter) @@ -293,6 +299,8 @@ try dbQueue.read { db in //: try request.fetchOne(db) // Base? //: } extension FetchRequest where RowDecoder: MyDatabaseDecoder { + // MARK: - FetchRequest fetching methods + func fetchCursor(_ db: Database) throws -> MapCursor { return try RowDecoder.fetchCursor(db, self) } @@ -324,6 +332,8 @@ try dbQueue.read { db in //: try Base.fetchOne(db) // Base? //: } extension MyDatabaseDecoder where Self: TableRecord { + // MARK: - Static fetching methods + static func fetchCursor(_ db: Database) throws -> MapCursor { return try all().fetchCursor(db) } @@ -345,31 +355,32 @@ try dbQueue.read { db in } } -//: Finally, you don't have a true GRDB record unless it allows fetching from -//: raw SQL: +//: Finally, you can support raw SQL as well: //: //: try dbQueue.read { db in -//: try Base.fetchCursor(db, "SELECT ...") // Cursor of Base -//: try Base.fetchAll(db, "SELECT ...") // [Base] -//: try Base.fetchOne(db, "SELECT ...") // Base? +//: try Base.fetchAll(db, +//: sql: "SELECT ... WHERE name = ?", +//: arguments: ["O'Brien"]) // [Base] //: } extension MyDatabaseDecoder { - static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> MapCursor { - return try fetchCursor(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + // MARK: - Fetch from SQL + + static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> MapCursor { + return try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } - static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [DecodedType] { - return try fetchAll(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [DecodedType] { + return try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } - static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DecodedType? { - return try fetchOne(db, SQLRequest(sql, arguments: arguments, adapter: adapter)) + static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> DecodedType? { + return try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } try dbQueue.read { db in print("> Fetch from SQL") - let bases = try Base.fetchAll(db, "SELECT * FROM base") + let bases = try Base.fetchAll(db, sql: "SELECT * FROM base") for base in bases { print(base.description) } diff --git a/Playgrounds/JSONSynchronization.playground/Contents.swift b/Playgrounds/JSONSynchronization.playground/Contents.swift index b791ff876..553c57dd8 100644 --- a/Playgrounds/JSONSynchronization.playground/Contents.swift +++ b/Playgrounds/JSONSynchronization.playground/Contents.swift @@ -40,16 +40,14 @@ struct Player: Codable, FetchableRecord, MutablePersistableRecord { var id: Int64 var name: String var score: Int - - // Add ColumnExpression to Codable's CodingKeys so that we can use them - // as database columns. - // - // See https://developer.apple.com/documentation/foundation/archives_and_serialization/encoding_and_decoding_custom_types - // for more information about CodingKeys. - private enum CodingKeys: String, CodingKey, ColumnExpression { - case id, name, score + + // Define database columns from CodingKeys + private enum Columns { + static let id = Column(CodingKeys.id) + static let name = Column(CodingKeys.name) + static let score = Column(CodingKeys.score) } - + // Update a player id after it has been inserted in the database. mutating func didInsert(with rowID: Int64, for column: String?) { id = rowID @@ -58,7 +56,7 @@ struct Player: Codable, FetchableRecord, MutablePersistableRecord { extension Player { static func orderedById() -> QueryInterfaceRequest { - return order(CodingKeys.id) + return order(Columns.id) } } diff --git a/Playgrounds/MyPlayground.playground/Contents.swift b/Playgrounds/MyPlayground.playground/Contents.swift index 31c58b913..067ff1a12 100644 --- a/Playgrounds/MyPlayground.playground/Contents.swift +++ b/Playgrounds/MyPlayground.playground/Contents.swift @@ -13,9 +13,9 @@ try! dbQueue.inDatabase { db in t.column("name", .text) } - try db.execute("INSERT INTO persons (name) VALUES (?)", arguments: ["Arthur"]) - try db.execute("INSERT INTO persons (name) VALUES (?)", arguments: ["Barbara"]) + try db.execute(sql: "INSERT INTO persons (name) VALUES (?)", arguments: ["Arthur"]) + try db.execute(sql: "INSERT INTO persons (name) VALUES (?)", arguments: ["Barbara"]) - let names = try String.fetchAll(db, "SELECT name FROM persons") + let names = try String.fetchAll(db, sql: "SELECT name FROM persons") print(names) } diff --git a/Playgrounds/Record.playground/Contents.swift b/Playgrounds/Record.playground/Contents.swift deleted file mode 100644 index bb8ad7265..000000000 --- a/Playgrounds/Record.playground/Contents.swift +++ /dev/null @@ -1,136 +0,0 @@ -//: To run this playground: -//: -//: - Open GRDB.xcworkspace -//: - Select the GRDBOSX scheme: menu Product > Scheme > GRDBOSX -//: - Build: menu Product > Build -//: - Select the playground in the Playgrounds Group -//: - Run the playground -//: -//: Record -//: ====== -//: -//: This playground is a demo of the Record class, the type that provides fetching methods, persistence methods, and change tracking. - -import GRDB - - -//: ## Setup -//: -//: First open an in-memory database, with a trace function that prints all SQL statements. - -var configuration = Configuration() -configuration.trace = { print($0) } -let dbQueue = DatabaseQueue(configuration: configuration) - -//: Create a database table which stores persons. - -try dbQueue.inDatabase { db in - try db.execute( - "CREATE TABLE persons (" + - "id INTEGER PRIMARY KEY, " + - "firstName TEXT, " + - "lastName TEXT" + - ")") -} - - -//: ## Subclassing Record -//: -//: The Person class is a subclass of Record, with regular properties, and a regular initializer: - -class Person : Record { - var id: Int64? - var firstName: String? - var lastName: String? - - var fullName: String { - return [firstName, lastName].flatMap { $0 }.joined(separator: " ") - } - - init(firstName: String?, lastName: String?) { - self.id = nil - self.firstName = firstName - self.lastName = lastName - super.init() - } - - -//: Subclasses of Record have to override the methods that define how they interact with the database. -//: -//: 1. The table name: - - override class var databaseTableName: String { - return "persons" - } - -//: 2. How to build a Person from a database row: - - required init(row: Row) { - id = row["id"] - firstName = row["firstName"] - lastName = row["lastName"] - super.init(row: row) - } - -//: 3. The dictionary of values that are stored in the database: - - override func encode(to container: inout PersistenceContainer) { - container["id"] = id - container["firstName"] = firstName - container["lastName"] = lastName - } - -//: 4. When relevant, update the person's id after a database row has been inserted: - - override func didInsert(with rowID: Int64, for column: String?) { - id = rowID - } -} - - -//: ## Insert Records -//: -//: Persons are regular objects, that you can freely create: - -let arthur = Person(firstName: "Arthur", lastName: "Miller") -let barbra = Person(firstName: "Barbra", lastName: "Streisand") -let cinderella = Person(firstName: "Cinderella", lastName: nil) - -//: They are not stored in the database yet. Insert them: - -try dbQueue.inDatabase { db in - try arthur.insert(db) - try barbra.insert(db) - try cinderella.insert(db) -} - - -//: ## Fetching Records - -try dbQueue.inDatabase { db in - - //: Fetch records from the database: - let allPersons = try Person.fetchAll(db) - - //: Fetch record by primary key: - let person = try Person.fetchOne(db, key: arthur.id)! - person.fullName - - //: Fetch persons with an SQL query: - let millers = try Person.fetchAll(db, "SELECT * FROM persons WHERE lastName = ?", arguments: ["Miller"]) - millers.first!.fullName - - - //: To fetch persons using the query interface, you need some colums that can filter or sort: - - struct Col { - static let firstName = Column("firstName") - static let lastName = Column("lastName") - } - - //: Sort - let personsSortedByName = try Person.order(Col.firstName, Col.lastName).fetchAll(db) - - //: Filter - let streisands = try Person.filter(Col.lastName == "Streisand").fetchAll(db) -} diff --git a/Playgrounds/Record.playground/contents.xcplayground b/Playgrounds/Record.playground/contents.xcplayground deleted file mode 100644 index fd676d5b4..000000000 --- a/Playgrounds/Record.playground/contents.xcplayground +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/Playgrounds/Tour.playground/Contents.swift b/Playgrounds/Tour.playground/Contents.swift index a87fe0aff..32ec34a03 100644 --- a/Playgrounds/Tour.playground/Contents.swift +++ b/Playgrounds/Tour.playground/Contents.swift @@ -9,7 +9,7 @@ //: Tour //: ====== //: -//: This playground is a tour of GRDB. +//: This playground is a quick tour of GRDB. import GRDB import CoreLocation @@ -26,44 +26,45 @@ let dbQueue = DatabaseQueue(configuration: configuration) //: Execute SQL queries try dbQueue.inDatabase { db in - try db.execute( - "CREATE TABLE pointOfInterests (" + - "id INTEGER PRIMARY KEY, " + - "title TEXT, " + - "favorite BOOLEAN NOT NULL, " + - "latitude DOUBLE NOT NULL, " + - "longitude DOUBLE NOT NULL" + - ")") + try db.execute(sql: """ + CREATE TABLE place ( + id INTEGER PRIMARY KEY, + title TEXT, + favorite BOOLEAN NOT NULL, + latitude DOUBLE NOT NULL, + longitude DOUBLE NOT NULL + ) + """) - try db.execute( - "INSERT INTO pointOfInterests (title, favorite, latitude, longitude) " + - "VALUES (?, ?, ?, ?)", - arguments: ["Paris", true, 48.85341, 2.3488]) + try db.execute(sql: """ + INSERT INTO place (title, favorite, latitude, longitude) + VALUES (?, ?, ?, ?) + """, arguments: ["Paris", true, 48.85341, 2.3488]) let parisId = db.lastInsertedRowID } //: Fetch database rows and values -try dbQueue.inDatabase { db in - let rows = try Row.fetchCursor(db, "SELECT * FROM pointOfInterests") +try! dbQueue.inDatabase { db in + let rows = try Row.fetchCursor(db, sql: "SELECT * FROM place") while let row = try rows.next() { let title: String = row["title"] let favorite: Bool = row["favorite"] - let coordinate = CLLocationCoordinate2DMake( - row["latitude"], - row["longitude"]) + let coordinate = CLLocationCoordinate2D( + latitude: row["latitude"], + longitude: row["longitude"]) print("Fetched", title, favorite, coordinate) } - let poiCount = try Int.fetchOne(db, "SELECT COUNT(*) FROM pointOfInterests")! // Int - let poiTitles = try String.fetchAll(db, "SELECT title FROM pointOfInterests") // [String] + let placeCount = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM place")! // Int + let placeTitles = try String.fetchAll(db, sql: "SELECT title FROM place") // [String] } //: Insert and fetch records -struct PointOfInterest { +struct Place { var id: Int64? var title: String? var favorite: Bool @@ -71,7 +72,7 @@ struct PointOfInterest { } // Adopt FetchableRecord -extension PointOfInterest : FetchableRecord { +extension Place : FetchableRecord { init(row: Row) { id = row["id"] title = row["title"] @@ -83,12 +84,12 @@ extension PointOfInterest : FetchableRecord { } // Adopt TableRecord -extension PointOfInterest : TableRecord { - static let databaseTableName = "pointOfInterests" +extension Place : TableRecord { + static let databaseTableName = "place" } // Adopt MutablePersistableRecord -extension PointOfInterest : MutablePersistableRecord { +extension Place : MutablePersistableRecord { func encode(to container: inout PersistenceContainer) { container["id"] = id container["title"] = title @@ -103,7 +104,7 @@ extension PointOfInterest : MutablePersistableRecord { } try dbQueue.inDatabase { db in - var berlin = PointOfInterest( + var berlin = Place( id: nil, title: "Berlin", favorite: false, @@ -116,7 +117,7 @@ try dbQueue.inDatabase { db in try berlin.update(db) // Fetch from SQL - let pois = try PointOfInterest.fetchAll(db, "SELECT * FROM pointOfInterests") // [PointOfInterest] + let places = try Place.fetchAll(db, sql: "SELECT * FROM place") // [Place] //: Avoid SQL with the query interface: @@ -124,10 +125,10 @@ try dbQueue.inDatabase { db in let title = Column("title") let favorite = Column("favorite") - berlin = try PointOfInterest.filter(title == "Berlin").fetchOne(db)! // PointOfInterest - let paris = try PointOfInterest.fetchOne(db, key: 1) // PointOfInterest? - let favoritePois = try PointOfInterest // [PointOfInterest] - .filter(favorite) + berlin = try Place.filter(title == "Berlin").fetchOne(db)! // Place + let paris = try Place.fetchOne(db, key: 1) // Place? + let favoritePlaces = try Place // [Place] + .filter(favorite == true) .order(title) .fetchAll(db) } diff --git a/Playgrounds/TransactionObserver.playground/Contents.swift b/Playgrounds/TransactionObserver.playground/Contents.swift index 05553a55e..e5aa0429a 100644 --- a/Playgrounds/TransactionObserver.playground/Contents.swift +++ b/Playgrounds/TransactionObserver.playground/Contents.swift @@ -13,26 +13,24 @@ import GRDB let dbQueue = DatabaseQueue() // Memory database var migrator = DatabaseMigrator() -migrator.registerMigration("createPersons") { db in - try db.execute( - "CREATE TABLE persons (" + - "id INTEGER PRIMARY KEY, " + - "name TEXT NOT NULL " + - ")") +migrator.registerMigration("createPerson") { db in + try db.create(table: "person") { t in + t.autoIncrementedPrimaryKey("id") + t.column("name", .text).notNull() + } } -migrator.registerMigration("createPets") { db in - try db.execute( - "CREATE TABLE pets (" + - "id INTEGER PRIMARY KEY, " + - "name TEXT, " + - "ownerId INTEGER NOT NULL REFERENCES persons(id) ON DELETE CASCADE" + - ")") +migrator.registerMigration("createPet") { db in + try db.create(table: "pet") { t in + t.autoIncrementedPrimaryKey("id") + t.column("name", .text).notNull() + t.column("ownerId", .integer).references("person", onDelete: .cascade) + } } try! migrator.migrate(dbQueue) +// -/// TableChangeObserver prints on the main thread the changes database tables. class TableChangeObserver : NSObject, TransactionObserver { private var changedTableNames: Set = [] @@ -44,9 +42,6 @@ class TableChangeObserver : NSObject, TransactionObserver { changedTableNames.insert(event.tableName) } - func databaseWillCommit() throws { - } - func databaseDidCommit(_ db: Database) { print("Changed table(s): \(changedTableNames.joined(separator: ", "))") changedTableNames = [] @@ -57,34 +52,35 @@ class TableChangeObserver : NSObject, TransactionObserver { } } - - -// Register observer - let observer = TableChangeObserver() dbQueue.add(transactionObserver: observer) // -print("-- Changes 1") -try! dbQueue.inDatabase { db in - try db.execute("INSERT INTO persons (name) VALUES (?)", arguments: ["Arthur"]) +print("-- Changes without transaction") +try dbQueue.inDatabase { db in + try db.execute(sql: "INSERT INTO person (name) VALUES (?)", arguments: ["Arthur"]) let arthurId = db.lastInsertedRowID - try db.execute("INSERT INTO persons (name) VALUES (?)", arguments: ["Barbara"]) - try db.execute("INSERT INTO pets (ownerId, name) VALUES (?, ?)", arguments: [arthurId, "Barbara"]) + try db.execute(sql: "INSERT INTO person (name) VALUES (?)", arguments: ["Barbara"]) + try db.execute(sql: "INSERT INTO pet (ownerId, name) VALUES (?, ?)", arguments: [arthurId, "Barbara"]) + try db.execute(sql: "DELETE FROM person WHERE id = ?", arguments: [arthurId]) } -print("-- Changes 2") +print("-- Rollbacked changes") try dbQueue.inTransaction { db in - try db.execute("INSERT INTO persons (name) VALUES ('Arthur')") - try db.execute("INSERT INTO persons (name) VALUES ('Barbara')") + try db.execute(sql: "INSERT INTO person (name) VALUES ('Arthur')") + try db.execute(sql: "INSERT INTO person (name) VALUES ('Barbara')") return .rollback } -print("-- Changes 3") +print("-- Changes wrapped in a transaction") try dbQueue.write { db in - try db.execute("DELETE FROM persons") - try db.execute("DELETE FROM pets") + try db.execute(sql: "DELETE FROM person") + try db.execute(sql: "INSERT INTO person (name) VALUES (?)", arguments: ["Arthur"]) + let arthurId = db.lastInsertedRowID + try db.execute(sql: "INSERT INTO person (name) VALUES (?)", arguments: ["Barbara"]) + try db.execute(sql: "INSERT INTO pet (ownerId, name) VALUES (?, ?)", arguments: [arthurId, "Barbara"]) + try db.execute(sql: "DELETE FROM person WHERE id = ?", arguments: [arthurId]) } diff --git a/README.md b/README.md index 571354a9c..a5522f00d 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,19 @@ -GRDB 3 [![Swift](https://img.shields.io/badge/swift-4.1-orange.svg?style=flat)](https://developer.apple.com/swift/) [![Swift](https://img.shields.io/badge/swift-4.2-orange.svg?style=flat)](https://developer.apple.com/swift/) [![Platforms](https://img.shields.io/cocoapods/p/GRDB.swift.svg)](https://developer.apple.com/swift/) [![License](https://img.shields.io/github/license/groue/GRDB.swift.svg?maxAge=2592000)](/LICENSE) [![Build Status](https://travis-ci.org/groue/GRDB.swift.svg?branch=master)](https://travis-ci.org/groue/GRDB.swift) +GRDB 4 [![Swift 4.2](https://img.shields.io/badge/swift-4.2-orange.svg?style=flat)](https://developer.apple.com/swift/) [![Swift 5](https://img.shields.io/badge/swift-5-orange.svg?style=flat)](https://developer.apple.com/swift/) [![Platforms](https://img.shields.io/cocoapods/p/GRDB.swift.svg)](https://developer.apple.com/swift/) [![License](https://img.shields.io/github/license/groue/GRDB.swift.svg?maxAge=2592000)](/LICENSE) [![Build Status](https://travis-ci.org/groue/GRDB.swift.svg?branch=master)](https://travis-ci.org/groue/GRDB.swift) ========== ### A toolkit for SQLite databases, with a focus on application development -**Latest release**: March 9, 2019 • version 3.7.0 • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 2 to GRDB 3](Documentation/GRDB2MigrationGuide.md) +--- -**Requirements**: iOS 8.0+ / macOS 10.9+ / watchOS 2.0+ • Swift 4.1+ / Xcode 9.3+ +**Latest release**: May 23, 2019 • version 4.0.0 • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 3 to GRDB 4](Documentation/GRDB3MigrationGuide.md) + +**Requirements**: iOS 9.0+ / macOS 10.9+ / watchOS 2.0+ • Swift 4.2+ / Xcode 10.0+ | Swift version | GRDB version | | ------------- | ----------------------------------------------------------- | -| Swift 5 | [v4.0.0](https://github.com/groue/GRDB.swift/tree/GRDB-4.0) :construction: in development | -| **Swift 4.2** | **v3.7.0** | -| **Swift 4.1** | **v3.7.0** | +| **Swift 5** | **v4.0.0** | +| **Swift 4.2** | **v4.0.0** | +| Swift 4.1 | [v3.7.0](https://github.com/groue/GRDB.swift/tree/v3.7.0) | | Swift 4 | [v2.10.0](https://github.com/groue/GRDB.swift/tree/v2.10.0) | | Swift 3.2 | [v1.3.0](https://github.com/groue/GRDB.swift/tree/v1.3.0) | | Swift 3.1 | [v1.3.0](https://github.com/groue/GRDB.swift/tree/v1.3.0) | @@ -96,7 +98,7 @@ See [Database Connections](#database-connections) ```swift try dbQueue.write { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE place ( id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, @@ -105,12 +107,18 @@ try dbQueue.write { db in longitude DOUBLE NOT NULL) """) - try db.execute(""" + try db.execute(sql: """ INSERT INTO place (title, favorite, latitude, longitude) VALUES (?, ?, ?, ?) """, arguments: ["Paris", true, 48.85341, 2.3488]) let parisId = db.lastInsertedRowID + + // Swift 5 only + try db.execute(literal: """ + INSERT INTO place (title, favorite, latitude, longitude) + VALUES (\("Madrid"), \(true), \(40.41678), \(-3.70379)) + """) } ``` @@ -124,7 +132,7 @@ See [Executing Updates](#executing-updates) ```swift try dbQueue.read { db in // Fetch database rows - let rows = try Row.fetchCursor(db, "SELECT * FROM place") + let rows = try Row.fetchCursor(db, sql: "SELECT * FROM place") while let row = try rows.next() { let title: String = row["title"] let isFavorite: Bool = row["favorite"] @@ -134,12 +142,12 @@ try dbQueue.read { db in } // Fetch values - let placeCount = try Int.fetchOne(db, "SELECT COUNT(*) FROM place")! // Int - let placeTitles = try String.fetchAll(db, "SELECT title FROM place") // [String] + let placeCount = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM place")! // Int + let placeTitles = try String.fetchAll(db, sql: "SELECT title FROM place") // [String] } let placeCount = try dbQueue.read { db in - try Int.fetchOne(db, "SELECT COUNT(*) FROM place")! + try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM place")! } ``` @@ -193,7 +201,7 @@ See [Records](#records) Fetch records and values with the Swift query interface ```swift -try dbQueue.write { db in +try dbQueue.read { db in // Place? let paris = try Place.fetchOne(db, key: 1) @@ -210,7 +218,7 @@ try dbQueue.write { db in let favoriteCount = try Place.filter(Column("favorite")).fetchCount(db) // SQL is always welcome - let places = try Place.fetchAll(db, "SELECT * FROM place") + let places = try Place.fetchAll(db, sql: "SELECT * FROM place") } ``` @@ -225,7 +233,7 @@ See the [Query Interface](#the-query-interface) let request = Place.order(Column("title")) try ValueObservation .trackingAll(request) - .start(in: dbQueue) { places: [Place] in + .start(in: dbQueue) { (places: [Place]) in print("Places have changed.") } ``` @@ -242,7 +250,7 @@ Documentation #### Reference -- [GRDB Reference](http://groue.github.io/GRDB.swift/docs/3.7/index.html) (generated by [Jazzy](https://github.com/realm/jazzy)) +- [GRDB Reference](http://groue.github.io/GRDB.swift/docs/4.0/index.html) (generated by [Jazzy](https://github.com/realm/jazzy)) #### Getting Started @@ -252,7 +260,7 @@ Documentation #### SQLite and SQL -- [SQLite API](#sqlite-api): The low-level SQLite API • [executing updates](#executing-updates) • [fetch queries](#fetch-queries) +- [SQLite API](#sqlite-api): The low-level SQLite API • [executing updates](#executing-updates) • [fetch queries](#fetch-queries) • [SQL Interpolation] #### Records and the Query Interface @@ -302,7 +310,7 @@ Installation See [Encryption](#encryption) for the installation procedure of GRDB with SQLCipher. -See [Custom SQLite builds](Documentation/CustomSQLiteBuilds.md) for the installation procedure of GRDB with a customized build of SQLite 3.25.2. +See [Custom SQLite builds](Documentation/CustomSQLiteBuilds.md) for the installation procedure of GRDB with a customized build of SQLite 3.27.2. See [Enabling FTS5 Support](#enabling-fts5-support) for the installation procedure of GRDB with support for the FTS5 full-text engine. @@ -324,7 +332,7 @@ The [Swift Package Manager](https://swift.org/package-manager/) automates the di ```swift let package = Package( dependencies: [ - .package(url: "https://github.com/groue/GRDB.swift.git", from: "3.7.0") + .package(url: "https://github.com/groue/GRDB.swift.git", from: "4.0.0") ] ) ``` @@ -334,14 +342,12 @@ Note that Linux is not currently supported. ## Carthage -Carthage can build GRDB frameworks, but it can also inexplicably fail. This installation method is thus *unsupported*. - -If you decide to use Carthage despite this warning, and get any Carthage-related error, please open an issue in the [Carthage repo](https://github.com/Carthage/Carthage/issues), ask [Stack Overflow](http://stackoverflow.com), summon your local Xcode guru, or submit a pull request that has the `make test_CarthageBuild` command succeed 100% of the time (one time is not enough). See [#262](https://github.com/groue/GRDB.swift/pull/262) for more information. +[Carthage](https://github.com/Carthage/Carthage) is **unsupported**. For some context about this decision, see [#433](https://github.com/groue/GRDB.swift/issues/433). ## Manually -1. [Download](https://github.com/groue/GRDB.swift/releases/tag/v3.7.0) a copy of GRDB, or clone its repository and make sure you use the latest tagged version with the `git checkout v3.7.0` command. +1. [Download](https://github.com/groue/GRDB.swift/releases/tag/v4.0.0) a copy of GRDB, or clone its repository and make sure you use the latest tagged version with the `git checkout v4.0.0` command. 2. Embed the `GRDB.xcodeproj` project in your own project. @@ -456,7 +462,7 @@ let dbQueue = try DatabaseQueue( configuration: config) ``` -See [Configuration](http://groue.github.io/GRDB.swift/docs/3.7/Structs/Configuration.html) for more details. +See [Configuration](http://groue.github.io/GRDB.swift/docs/4.0/Structs/Configuration.html) for more details. ## Database Pools @@ -537,7 +543,7 @@ let dbPool = try DatabasePool( configuration: config) ``` -See [Configuration](http://groue.github.io/GRDB.swift/docs/3.7/Structs/Configuration.html) for more details. +See [Configuration](http://groue.github.io/GRDB.swift/docs/4.0/Structs/Configuration.html) for more details. Database pools are more memory-hungry than database queues. See [Memory Management](#memory-management) for more information. @@ -560,6 +566,7 @@ SQLite API - [Swift enums](#swift-enums) - [Custom Value Types](#custom-value-types) - [Transactions and Savepoints](#transactions-and-savepoints) +- [SQL Interpolation] Advanced topics: @@ -578,7 +585,7 @@ For example: ```swift try dbQueue.write { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE player ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, @@ -586,39 +593,67 @@ try dbQueue.write { db in """) try db.execute( - "INSERT INTO player (name, score) VALUES (?, ?)", + sql: "INSERT INTO player (name, score) VALUES (?, ?)", arguments: ["Barbara", 1000]) try db.execute( - "UPDATE player SET score = :score WHERE id = :id", + sql: "UPDATE player SET score = :score WHERE id = :id", arguments: ["score": 1000, "id": 1]) } } ``` -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/3.7/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/4.0/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. -**Never ever embed values directly in your SQL strings**, and always use arguments instead. See [Avoiding SQL Injection](#avoiding-sql-injection) for more information: +In Swift 5, you can embed query arguments right into your SQL queries, with the `literal` argument label, as in the example below. See [SQL Interpolation] for more details. ```swift -// WRONG +// Swift 5 +try dbQueue.write { db in + try db.execute(literal: """ + INSERT INTO player (name, score) + VALUES (\("O'Brien"), \(550)) + """) +} +``` + +**Never ever embed values directly in your raw SQL strings**. See [Avoiding SQL Injection](#avoiding-sql-injection) for more information: + +```swift +// WRONG: don't embed values in raw SQL strings let id = 123 let name = textField.text -try db.execute("UPDATE player SET name = '\(name)' WHERE id = \(id)") - -// CORRECT try db.execute( - "UPDATE player SET name = :name WHERE id = :id", + sql: "UPDATE player SET name = '\(name)' WHERE id = \(id)") + +// CORRECT: use SQL Interpolation (Swift 5) +try db.execute( + literal: "UPDATE player SET name = \(name) WHERE id = \(id)") + +// CORRECT: use arguments dictionary +try db.execute( + sql: "UPDATE player SET name = :name WHERE id = :id", arguments: ["name": name, "id": id]) + +// CORRECT: use arguments array +try db.execute( + sql: "UPDATE player SET name = ? WHERE id = ?", + arguments: [name, id]) ``` **Join multiple statements with a semicolon**: ```swift -try db.execute(""" +try db.execute(sql: """ + INSERT INTO player (name, score) VALUES (?, ?); INSERT INTO player (name, score) VALUES (?, ?); - INSERT INTO player (name, score) VALUES (?, ?) """, arguments: ["Arthur", 750, "Barbara", 1000]) + +// Swift 5 +try db.execute(literal: """ + INSERT INTO player (name, score) VALUES (\("Arthur"), \(750)); + INSERT INTO player (name, score) VALUES (\("Barbara"), \(1000)); + """) ``` When you want to make sure that a single statement is executed, use [Prepared Statements](#prepared-statements). @@ -627,7 +662,7 @@ When you want to make sure that a single statement is executed, use [Prepared St ```swift try db.execute( - "INSERT INTO player (name, score) VALUES (?, ?)", + sql: "INSERT INTO player (name, score) VALUES (?, ?)", arguments: ["Arthur", 1000]) let playerId = db.lastInsertedRowID ``` @@ -635,7 +670,7 @@ let playerId = db.lastInsertedRowID Don't miss [Records](#records), that provide classic **persistence methods**: ```swift -let player = Player(name: "Arthur", score: 1000) +var player = Player(name: "Arthur", score: 1000) try player.insert(db) let playerId = player.id ``` @@ -649,7 +684,7 @@ let playerId = player.id ```swift try dbQueue.read { db in - if let row = try Row.fetchOne(db, "SELECT * FROM wine WHERE id = ?", arguments: [1]) { + if let row = try Row.fetchOne(db, sql: "SELECT * FROM wine WHERE id = ?", arguments: [1]) { let name: String = row["name"] let color: Color = row["color"] print(name, color) @@ -662,7 +697,7 @@ try dbQueue.read { db in ```swift try dbQueue.read { db in - let urls = try URL.fetchCursor(db, "SELECT url FROM wine") + let urls = try URL.fetchCursor(db, sql: "SELECT url FROM wine") while let url = try urls.next() { print(url) } @@ -674,7 +709,7 @@ try dbQueue.read { db in ```swift let wines = try dbQueue.read { db in - try Wine.fetchAll(db, "SELECT * FROM wine") + try Wine.fetchAll(db, sql: "SELECT * FROM wine") } ``` @@ -697,19 +732,19 @@ try Row.fetchOne(...) // Row? - `fetchCursor` returns a **[cursor](#cursors)** over fetched values: ```swift - let rows = try Row.fetchCursor(db, "SELECT ...") // A Cursor of Row + let rows = try Row.fetchCursor(db, sql: "SELECT ...") // A Cursor of Row ``` - `fetchAll` returns an **array**: ```swift - let players = try Player.fetchAll(db, "SELECT ...") // [Player] + let players = try Player.fetchAll(db, sql: "SELECT ...") // [Player] ``` - `fetchOne` returns a **single optional value**, and consumes a single database row (if any). ```swift - let count = try Int.fetchOne(db, "SELECT COUNT(*) ...") // Int? + let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) ...") // Int? ``` @@ -722,7 +757,7 @@ The `fetchAll()` method returns a regular Swift array, that you iterate like all ```swift try dbQueue.read { db in // [Player] - let players = try Player.fetchAll(db, "SELECT ...") + let players = try Player.fetchAll(db, sql: "SELECT ...") for player in players { // use player } @@ -734,7 +769,7 @@ Unlike arrays, cursors returned by `fetchCursor()` load their results step after ```swift try dbQueue.read { db in // Cursor of Player - let players = try Player.fetchCursor(db, "SELECT ...") + let players = try Player.fetchCursor(db, sql: "SELECT ...") while let player = try players.next() { // use player } @@ -769,18 +804,18 @@ Both arrays and cursors can iterate over database results. How do you choose one - **Cursors are granted with direct access to SQLite,** unlike arrays that have to take the time to copy database values. If you look after extra performance, you may prefer cursors over arrays. -- **Cursors adopt the [Cursor](http://groue.github.io/GRDB.swift/docs/3.7/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/4.0/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 try URL - .fetchCursor(db, "SELECT url FROM link") + .fetchCursor(db, sql: "SELECT url FROM link") .filter { url in url.host == "github.com" } .forEach { url in print(url) } // An efficient cursor of coordinates: let locations = try Row. - .fetchCursor(db, "SELECT latitude, longitude FROM place") + .fetchCursor(db, sql: "SELECT latitude, longitude FROM place") .map { row in CLLocationCoordinate2D(latitude: row[0], longitude: row[1]) } @@ -799,7 +834,7 @@ Both arrays and cursors can iterate over database results. How do you choose one ```swift // Undefined behavior while let player = try players.next() { - try db.execute("DELETE ...") + try db.execute(sql: "DELETE ...") } ``` @@ -822,11 +857,11 @@ Fetch **cursors** of rows, **arrays**, or **single** rows (see [fetching methods ```swift try dbQueue.read { db in - try Row.fetchCursor(db, "SELECT ...", arguments: ...) // A Cursor of Row - try Row.fetchAll(db, "SELECT ...", arguments: ...) // [Row] - try Row.fetchOne(db, "SELECT ...", arguments: ...) // Row? + try Row.fetchCursor(db, sql: "SELECT ...", arguments: ...) // A Cursor of Row + try Row.fetchAll(db, sql: "SELECT ...", arguments: ...) // [Row] + try Row.fetchOne(db, sql: "SELECT ...", arguments: ...) // Row? - let rows = try Row.fetchCursor(db, "SELECT * FROM wine") + let rows = try Row.fetchCursor(db, sql: "SELECT * FROM wine") while let row = try rows.next() { let name: String = row["name"] let color: Color = row["color"] @@ -835,7 +870,7 @@ try dbQueue.read { db in } let rows = try dbQueue.read { db in - try Row.fetchAll(db, "SELECT * FROM player") + try Row.fetchAll(db, sql: "SELECT * FROM player") } ``` @@ -843,15 +878,15 @@ Arguments are optional arrays or dictionaries that fill the positional `?` and c ```swift let rows = try Row.fetchAll(db, - "SELECT * FROM player WHERE name = ?", + sql: "SELECT * FROM player WHERE name = ?", arguments: ["Arthur"]) let rows = try Row.fetchAll(db, - "SELECT * FROM player WHERE name = :name", + sql: "SELECT * FROM player WHERE name = :name", 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/3.7/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/4.0/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: @@ -913,7 +948,7 @@ Generally speaking, you can extract the type you need, provided it can be conver - **NULL returns nil.** ```swift - let row = try Row.fetchOne(db, "SELECT NULL")! + let row = try Row.fetchOne(db, sql: "SELECT NULL")! row[0] as Int? // nil row[0] as Int // fatal error: could not convert NULL to Int. ``` @@ -927,7 +962,7 @@ Generally speaking, you can extract the type you need, provided it can be conver - **Missing columns return nil.** ```swift - let row = try Row.fetchOne(db, "SELECT 'foo' AS foo")! + let row = try Row.fetchOne(db, sql: "SELECT 'foo' AS foo")! row["missing"] as String? // nil row["missing"] as String // fatal error: no such column: missing ``` @@ -937,12 +972,12 @@ Generally speaking, you can extract the type you need, provided it can be conver - **Invalid conversions throw a fatal error.** ```swift - let row = try Row.fetchOne(db, "SELECT 'Mom’s birthday'")! + let row = try Row.fetchOne(db, sql: "SELECT 'Mom’s birthday'")! row[0] as String // "Mom’s birthday" row[0] as Date? // fatal error: could not convert "Mom’s birthday" to Date. row[0] as Date // fatal error: could not convert "Mom’s birthday" to Date. - let row = try Row.fetchOne(db, "SELECT 256")! + let row = try Row.fetchOne(db, sql: "SELECT 256")! row[0] as Int // 256 row[0] as UInt8? // fatal error: could not convert 256 to UInt8. row[0] as UInt8 // fatal error: could not convert 256 to UInt8. @@ -951,7 +986,7 @@ Generally speaking, you can extract the type you need, provided it can be conver Those conversion fatal errors can be avoided with the [DatabaseValue](#databasevalue) type: ```swift - let row = try Row.fetchOne(db, "SELECT 'Mom’s birthday'")! + let row = try Row.fetchOne(db, sql: "SELECT 'Mom’s birthday'")! let dbValue: DatabaseValue = row[0] if dbValue.isNull { // Handle NULL @@ -969,7 +1004,7 @@ Generally speaking, you can extract the type you need, provided it can be conver GRDB will sometimes let those conversions go through: ```swift - let rows = try Row.fetchCursor(db, "SELECT '20 small cigars'") + let rows = try Row.fetchCursor(db, sql: "SELECT '20 small cigars'") while let row = try rows.next() { row[0] as Int // 20 } @@ -1020,7 +1055,7 @@ let date = Date.fromDatabaseValue(dbValue) // Date? `fromDatabaseValue` returns nil for invalid conversions: ```swift -let row = try Row.fetchOne(db, "SELECT 'Mom’s birthday'")! +let row = try Row.fetchOne(db, sql: "SELECT 'Mom’s birthday'")! let dbValue: DatabaseValue = row[0] let string = String.fromDatabaseValue(dbValue) // "Mom’s birthday" let int = Int.fromDatabaseValue(dbValue) // nil @@ -1050,7 +1085,7 @@ let row = Row(/* [AnyHashable: Any] */) // nil if invalid dictionary Yet rows are not real dictionaries: they may contain duplicate columns: ```swift -let row = try Row.fetchOne(db, "SELECT 1 AS foo, 2 AS foo")! +let row = try Row.fetchOne(db, sql: "SELECT 1 AS foo, 2 AS foo")! row.columnNames // ["foo", "foo"] row.databaseValues // [1, 2] row["foo"] // 1 (leftmost matching column) @@ -1094,17 +1129,17 @@ Instead of rows, you can directly fetch **[values](#values)**. Like rows, fetch ```swift try dbQueue.read { db in - try Int.fetchCursor(db, "SELECT ...", arguments: ...) // A Cursor of Int - try Int.fetchAll(db, "SELECT ...", arguments: ...) // [Int] - try Int.fetchOne(db, "SELECT ...", arguments: ...) // Int? + try Int.fetchCursor(db, sql: "SELECT ...", arguments: ...) // A Cursor of Int + try Int.fetchAll(db, sql: "SELECT ...", arguments: ...) // [Int] + try Int.fetchOne(db, sql: "SELECT ...", arguments: ...) // Int? // When database may contain NULL: - try Optional.fetchCursor(db, "SELECT ...", arguments: ...) // A Cursor of Int? - try Optional.fetchAll(db, "SELECT ...", arguments: ...) // [Int?] + try Optional.fetchCursor(db, sql: "SELECT ...", arguments: ...) // A Cursor of Int? + try Optional.fetchAll(db, sql: "SELECT ...", arguments: ...) // [Int?] } let playerCount = try dbQueue.read { db in - try Int.fetchOne(db, "SELECT COUNT(*) FROM player")! + try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM player")! } ``` @@ -1113,8 +1148,8 @@ let playerCount = try dbQueue.read { db in There are many supported value types (Bool, Int, String, Date, Swift enums, etc.). See [Values](#values) for more information: ```swift -let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM player")! // Int -let urls = try URL.fetchAll(db, "SELECT url FROM link") // [URL] +let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM player")! // Int +let urls = try URL.fetchAll(db, sql: "SELECT url FROM link") // [URL] ``` @@ -1134,20 +1169,20 @@ 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/3.7/Structs/StatementArguments.html): +Values can be used as [statement arguments](http://groue.github.io/GRDB.swift/docs/4.0/Structs/StatementArguments.html): ```swift let url: URL = ... let verified: Bool = ... try db.execute( - "INSERT INTO link (url, verified) VALUES (?, ?)", + sql: "INSERT INTO link (url, verified) VALUES (?, ?)", arguments: [url, verified]) ``` Values can be [extracted from rows](#column-values): ```swift -let rows = try Row.fetchCursor(db, "SELECT * FROM link") +let rows = try Row.fetchCursor(db, sql: "SELECT * FROM link") while let row = try rows.next() { let url: URL = row["url"] let verified: Bool = row["verified"] @@ -1157,7 +1192,7 @@ while let row = try rows.next() { Values can be [directly fetched](#value-queries): ```swift -let urls = try URL.fetchAll(db, "SELECT url FROM link") // [URL] +let urls = try URL.fetchAll(db, sql: "SELECT url FROM link") // [URL] ``` Use values in [Records](#records): @@ -1187,7 +1222,7 @@ let link = try Link.filter(Column("url") == url).fetchOne(db) **Data** suits the BLOB SQLite columns. It can be stored and fetched from the database just like other [values](#values): ```swift -let rows = try Row.fetchCursor(db, "SELECT data, ...") +let rows = try Row.fetchCursor(db, sql: "SELECT data, ...") while let row = try rows.next() { let data: Data = row["data"] } @@ -1238,7 +1273,7 @@ Here is how GRDB supports the various [date formats](https://www.sqlite.org/lang ```swift try db.execute( - "INSERT INTO player (creationDate, ...) VALUES (?, ...)", + sql: "INSERT INTO player (creationDate, ...) VALUES (?, ...)", arguments: [Date(), ...]) let row = try Row.fetchOne(db, ...)! @@ -1258,7 +1293,7 @@ When the default format does not fit your needs, customize date conversions. For ```swift try db.execute( - "INSERT INTO player (creationDate, ...) VALUES (?, ...)", + sql: "INSERT INTO player (creationDate, ...) VALUES (?, ...)", arguments: [Date().timeIntervalSinceReferenceDate, ...]) let row = try Row.fetchOne(db, ...)! @@ -1285,11 +1320,11 @@ components.day = 18 // Store "1973-09-18" let dbComponents = DatabaseDateComponents(components, format: .YMD) try db.execute( - "INSERT INTO player (birthDate, ...) VALUES (?, ...)", + sql: "INSERT INTO player (birthDate, ...) VALUES (?, ...)", arguments: [dbComponents, ...]) // Read "1973-09-18" -let row = try Row.fetchOne(db, "SELECT birthDate ...")! +let row = try Row.fetchOne(db, sql: "SELECT birthDate ...")! let dbComponents: DatabaseDateComponents = row["birthDate"] dbComponents.format // .YMD (the actual format found in the database) dbComponents.dateComponents // DateComponents @@ -1313,9 +1348,9 @@ CREATE TABLE transfer ( This means that computations will not be exact: ```swift -try db.execute("INSERT INTO transfer (amount) VALUES (0.1)") -try db.execute("INSERT INTO transfer (amount) VALUES (0.2)") -let sum = try NSDecimalNumber.fetchOne(db, "SELECT SUM(amount) FROM transfer")! +try db.execute(sql: "INSERT INTO transfer (amount) VALUES (0.1)") +try db.execute(sql: "INSERT INTO transfer (amount) VALUES (0.2)") +let sum = try NSDecimalNumber.fetchOne(db, sql: "SELECT SUM(amount) FROM transfer")! // Yikes! 0.3000000000000000512 print(sum) @@ -1329,10 +1364,10 @@ A classic technique is to store *integers* instead, since SQLite performs exact // Write let amount = NSDecimalNumber(string: "0.10") let integerAmount = amount.multiplying(byPowerOf10: 2).int64Value -try db.execute("INSERT INTO transfer (amount) VALUES (?)", arguments: [integerAmount]) +try db.execute(sql: "INSERT INTO transfer (amount) VALUES (?)", arguments: [integerAmount]) // Read -let integerAmount = try Int64.fetchOne(db, "SELECT SUM(amount) FROM transfer")! +let integerAmount = try Int64.fetchOne(db, sql: "SELECT SUM(amount) FROM transfer")! let amount = NSDecimalNumber(value: integerAmount).multiplying(byPowerOf10: -2) // 0.10 ``` @@ -1363,11 +1398,11 @@ extension Grape : DatabaseValueConvertible { } // Store try db.execute( - "INSERT INTO wine (grape, color) VALUES (?, ?)", + sql: "INSERT INTO wine (grape, color) VALUES (?, ?)", arguments: [Grape.merlot, Color.red]) // Read -let rows = try Row.fetchCursor(db, "SELECT * FROM wine") +let rows = try Row.fetchCursor(db, sql: "SELECT * FROM wine") while let row = try rows.next() { let grape: Grape = row["grape"] let color: Color = row["color"] @@ -1377,7 +1412,7 @@ while let row = try rows.next() { **When a database value does not match any enum case**, you get a fatal error. This fatal error can be avoided with the [DatabaseValue](#databasevalue) type: ```swift -let row = try Row.fetchOne(db, "SELECT 'syrah'")! +let row = try Row.fetchOne(db, sql: "SELECT 'syrah'")! row[0] as String // "syrah" row[0] as Grape? // fatal error: could not convert "syrah" to Grape. @@ -1535,18 +1570,18 @@ try dbQueue.inDatabase { db in // or dbPool.writeWithoutTransaction ... try db.commit() - try db.execute("BEGIN TRANSACTION") + try db.execute(sql: "BEGIN TRANSACTION") ... - try db.execute("ROLLBACK") + try db.execute(sql: "ROLLBACK") } ``` -Transactions can't be left opened unless you set the [allowsUnsafeTransactions](http://groue.github.io/GRDB.swift/docs/3.7/Structs/Configuration.html) configuration flag: +Transactions can't be left opened unless you set the [allowsUnsafeTransactions](http://groue.github.io/GRDB.swift/docs/4.0/Structs/Configuration.html) configuration flag: ```swift // fatal error: A transaction has been left opened at the end of a database access try dbQueue.inDatabase { db in - try db.execute("BEGIN TRANSACTION") + try db.execute(sql: "BEGIN TRANSACTION") // <- no commit or rollback } ``` @@ -1648,14 +1683,14 @@ There are two kinds of prepared statements: **select statements**, and **update ```swift try dbQueue.write { db in let updateSQL = "INSERT INTO player (name, score) VALUES (:name, :score)" - let updateStatement = try db.makeUpdateStatement(updateSQL) + let updateStatement = try db.makeUpdateStatement(sql: updateSQL) let selectSQL = "SELECT * FROM player WHERE name = ?" - let selectStatement = try db.makeSelectStatement(selectSQL) + let selectStatement = try db.makeSelectStatement(sql: selectSQL) } ``` -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/3.7/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/4.0/Structs/StatementArguments.html), which happens to adopt the ExpressibleByArrayLiteral and ExpressibleByDictionaryLiteral protocols). ```swift updateStatement.arguments = ["name": "Arthur", "score": 1000] @@ -1694,13 +1729,13 @@ When the same query will be used several times in the lifetime of your applicati **Don't cache statements yourself.** -> :point_up: **Note**: This is because you don't have the necessary tools. Statements are tied to specific SQLite connections and dispatch queues which you don't manage yourself, especially when you use [database pools](#database-pools). A change in the database schema [may, or may not](https://www.sqlite.org/compile.html#max_schema_retry) invalidate a statement. On systems earlier than iOS 8.2 and OSX 10.10 that don't have the [sqlite3_close_v2 function](https://www.sqlite.org/c3ref/close.html), SQLite connections won't close properly if statements have been kept alive. +> :point_up: **Note**: This is because you don't have the necessary tools. Statements are tied to specific SQLite connections and dispatch queues which you don't manage yourself, especially when you use [database pools](#database-pools). A change in the database schema [may, or may not](https://www.sqlite.org/compile.html#max_schema_retry) invalidate a statement. On systems earlier than OSX 10.10 that don't have the [sqlite3_close_v2 function](https://www.sqlite.org/c3ref/close.html), SQLite connections won't close properly if statements have been kept alive. Instead, use the `cachedUpdateStatement` and `cachedSelectStatement` methods. GRDB does all the hard caching and [memory management](#memory-management) stuff for you: ```swift -let updateStatement = try db.cachedUpdateStatement(sql) -let selectStatement = try db.cachedSelectStatement(sql) +let updateStatement = try db.cachedUpdateStatement(sql: sql) +let selectStatement = try db.cachedSelectStatement(sql: sql) ``` Should a cached prepared statement throw an error, don't reuse it (it is a programmer error). Instead, reload it from the cache. @@ -1736,7 +1771,7 @@ dbQueue.add(function: reverse) // Or dbPool.add(function: ...) try dbQueue.read { db in // "oof" - try String.fetchOne(db, "SELECT reverse('foo')")! + try String.fetchOne(db, sql: "SELECT reverse('foo')")! } ``` @@ -1758,7 +1793,7 @@ dbQueue.add(function: averageOf) try dbQueue.read { db in // 2.0 - try Double.fetchOne(db, "SELECT averageOf(1, 2, 3)")! + try Double.fetchOne(db, sql: "SELECT averageOf(1, 2, 3)")! } ``` @@ -1779,7 +1814,7 @@ dbQueue.add(function: sqrt) // SQLite error 1 with statement `SELECT sqrt(-1)`: invalid negative number try dbQueue.read { db in - try Double.fetchOne(db, "SELECT sqrt(-1)")! + try Double.fetchOne(db, sql: "SELECT sqrt(-1)")! } ``` @@ -1845,7 +1880,7 @@ dbQueue.add(function: maxLength) // Or dbPool.add(function: ...) try dbQueue.read { db in // Some Int - try Int.fetchOne(db, "SELECT maxLength(name) FROM player")! + try Int.fetchOne(db, sql: "SELECT maxLength(name) FROM player")! } ``` @@ -1909,12 +1944,12 @@ In this case, the `ColumnMapping` row adapter comes in handy: ```swift // Fetch a 'produced' column, and consume a 'consumed' column: let adapter = ColumnMapping(["consumed": "produced"]) -let row = try Row.fetchOne(db, "SELECT 'Hello' AS produced", adapter: adapter)! +let row = try Row.fetchOne(db, sql: "SELECT 'Hello' AS produced", adapter: adapter)! row["consumed"] // "Hello" row["produced"] // nil ``` -Row adapters are values that adopt the [RowAdapter](http://groue.github.io/GRDB.swift/docs/3.7/Protocols/RowAdapter.html) protocol. You can implement your own custom adapters ([**:fire: EXPERIMENTAL**](#what-are-experimental-features)), or use one of the four built-in adapters, described below. +Row adapters are values that adopt the [RowAdapter](http://groue.github.io/GRDB.swift/docs/4.0/Protocols/RowAdapter.html) protocol. You can implement your own custom adapters ([**:fire: EXPERIMENTAL**](#what-are-experimental-features)), or use one of the four built-in adapters, described below. To see how row adapters can be used, see [Joined Queries Support](#joined-queries-support). @@ -1926,7 +1961,7 @@ ColumnMapping renames columns. Build one with a dictionary whose keys are adapte ```swift // [newName:"Hello"] let adapter = ColumnMapping(["newName": "oldName"]) -let row = try Row.fetchOne(db, "SELECT 'Hello' AS oldName", adapter: adapter)! +let row = try Row.fetchOne(db, sql: "SELECT 'Hello' AS oldName", adapter: adapter)! ``` ### SuffixRowAdapter @@ -1936,7 +1971,7 @@ let row = try Row.fetchOne(db, "SELECT 'Hello' AS oldName", adapter: adapter)! ```swift // [b:1 c:2] let adapter = SuffixRowAdapter(fromIndex: 1) -let row = try Row.fetchOne(db, "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter)! +let row = try Row.fetchOne(db, sql: "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter)! ``` ### RangeRowAdapter @@ -1946,7 +1981,7 @@ let row = try Row.fetchOne(db, "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter ```swift // [b:1] let adapter = RangeRowAdapter(1..<2) -let row = try Row.fetchOne(db, "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter)! +let row = try Row.fetchOne(db, sql: "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter)! ``` ### EmptyRowAdapter @@ -1955,7 +1990,7 @@ let row = try Row.fetchOne(db, "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter ```swift let adapter = EmptyRowAdapter() -let row = try Row.fetchOne(db, "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter)! +let row = try Row.fetchOne(db, sql: "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter)! row.isEmpty // true ``` @@ -1970,7 +2005,7 @@ This limit adapter may turn out useful in some narrow use cases. You'll be happy let adapter = ScopeAdapter([ "left": RangeRowAdapter(0..<2), "right": RangeRowAdapter(2..<4)]) -let row = try Row.fetchOne(db, "SELECT 0 AS a, 1 AS b, 2 AS c, 3 AS d", adapter: adapter)! +let row = try Row.fetchOne(db, sql: "SELECT 0 AS a, 1 AS b, 2 AS c, 3 AS d", adapter: adapter)! ``` ScopeAdapter does not change the columns and values of the fetched row. Instead, it defines *scopes*, which you access through the `Row.scopes` property: @@ -1993,7 +2028,7 @@ let adapter = ScopeAdapter([ "left": RangeRowAdapter(2..<3), "right": RangeRowAdapter(3..<4)]) ]) -let row = try Row.fetchOne(db, "SELECT 0 AS a, 1 AS b, 2 AS c, 3 AS d", adapter: adapter)! +let row = try Row.fetchOne(db, sql: "SELECT 0 AS a, 1 AS b, 2 AS c, 3 AS d", adapter: adapter)! let leftRow = row.scopes["left"]! leftRow.scopes["left"] // [a:0] @@ -2010,7 +2045,7 @@ Any adapter can be extended with scopes: let baseAdapter = RangeRowAdapter(0..<2) let adapter = ScopeAdapter(base: baseAdapter, scopes: [ "remainder": SuffixRowAdapter(fromIndex: 2)]) -let row = try Row.fetchOne(db, "SELECT 0 AS a, 1 AS b, 2 AS c, 3 AS d", adapter: adapter)! +let row = try Row.fetchOne(db, sql: "SELECT 0 AS a, 1 AS b, 2 AS c, 3 AS d", adapter: adapter)! row // [a:0 b:1] row.scopes["remainder"] // [c:2 d:3] @@ -2021,14 +2056,17 @@ row.scopes["remainder"] // [c:2 d:3] **If not all SQLite APIs are exposed in GRDB, you can still use the [SQLite C Interface](https://www.sqlite.org/c3ref/intro.html) and call [SQLite C functions](https://www.sqlite.org/c3ref/funclist.html).** -Those functions are embedded right into the GRDBCustom and GRCBCipher modules. For the "regular" GRDB framework: you'll need to import `SQLite3`, or `CSQLite`, depending on whether you use the Swift Package Manager or not: +Those functions are embedded right into the [GRDBCustom](Documentation/CustomSQLiteBuilds.md) module. Otherwise, you'll need to import `SQLite3`, `SQLCipher`, or `CSQLite`, depending on the GRDB flavor you are using: ```swift -#if SWIFT_PACKAGE - import CSQLite // For Swift Package Manager -#else - import SQLite3 // Otherwise -#endif +// Swift Package Manager +import CSQLite + +// SQLCipher +import SQLCipher + +// System SQLite +import SQLite3 let sqliteVersion = String(cString: sqlite3_libversion()) ``` @@ -2041,7 +2079,7 @@ try dbQueue.read { db in let sqliteConnection = db.sqliteConnection // The raw pointer to a statement: - let statement = try db.makeSelectStatement("SELECT ...") + let statement = try db.makeSelectStatement(sql: "SELECT ...") let sqliteStatement = statement.sqliteStatement } ``` @@ -2057,8 +2095,8 @@ Before jumping in the low-level wagon, here is the list of all SQLite APIs used - `sqlite3_aggregate_context`, `sqlite3_create_function_v2`, `sqlite3_result_blob`, `sqlite3_result_double`, `sqlite3_result_error`, `sqlite3_result_error_code`, `sqlite3_result_int64`, `sqlite3_result_null`, `sqlite3_result_text`, `sqlite3_user_data`, `sqlite3_value_blob`, `sqlite3_value_bytes`, `sqlite3_value_double`, `sqlite3_value_int64`, `sqlite3_value_text`, `sqlite3_value_type`: see [Custom SQL Functions and Aggregates](#custom-sql-functions-and-aggregates) - `sqlite3_backup_finish`, `sqlite3_backup_init`, `sqlite3_backup_step`: see [Backup](#backup) - `sqlite3_bind_blob`, `sqlite3_bind_double`, `sqlite3_bind_int64`, `sqlite3_bind_null`, `sqlite3_bind_parameter_count`, `sqlite3_bind_parameter_name`, `sqlite3_bind_text`, `sqlite3_clear_bindings`, `sqlite3_column_blob`, `sqlite3_column_bytes`, `sqlite3_column_count`, `sqlite3_column_double`, `sqlite3_column_int64`, `sqlite3_column_name`, `sqlite3_column_text`, `sqlite3_column_type`, `sqlite3_exec`, `sqlite3_finalize`, `sqlite3_prepare_v2`, `sqlite3_reset`, `sqlite3_step`: see [Executing Updates](#executing-updates), [Fetch Queries](#fetch-queries), [Prepared Statements](#prepared-statements), [Values](#values) -- `sqlite3_busy_handler`, `sqlite3_busy_timeout`: see [Configuration.busyMode](http://groue.github.io/GRDB.swift/docs/3.7/Structs/Configuration.html) -- `sqlite3_changes`, `sqlite3_total_changes`: see [Database.changesCount and Database.totalChangesCount](http://groue.github.io/GRDB.swift/docs/3.7/Classes/Database.html) +- `sqlite3_busy_handler`, `sqlite3_busy_timeout`: see [Configuration.busyMode](http://groue.github.io/GRDB.swift/docs/4.0/Structs/Configuration.html) +- `sqlite3_changes`, `sqlite3_total_changes`: see [Database.changesCount and Database.totalChangesCount](http://groue.github.io/GRDB.swift/docs/4.0/Classes/Database.html) - `sqlite3_close`, `sqlite3_close_v2`, `sqlite3_next_stmt`, `sqlite3_open_v2`: see [Database Connections](#database-connections) - `sqlite3_commit_hook`, `sqlite3_rollback_hook`, `sqlite3_update_hook`: see [TransactionObserver Protocol](#transactionobserver-protocol), [DatabaseRegionObservation], [ValueObservation], [FetchedRecordsController] - `sqlite3_config`: see [Error Log](#error-log) @@ -2069,9 +2107,9 @@ Before jumping in the low-level wagon, here is the list of all SQLite APIs used - `sqlite3_last_insert_rowid`: see [Executing Updates](#executing-updates) - `sqlite3_preupdate_count`, `sqlite3_preupdate_depth`, `sqlite3_preupdate_hook`, `sqlite3_preupdate_new`, `sqlite3_preupdate_old`: see [Support for SQLite Pre-Update Hooks](#support-for-sqlite-pre-update-hooks) - `sqlite3_set_authorizer`: **reserved by GRDB** -- `sqlite3_sql`: see [Statement.sql](http://groue.github.io/GRDB.swift/docs/3.7/Classes/Statement.html) -- `sqlite3_trace`: see [Configuration.trace](http://groue.github.io/GRDB.swift/docs/3.7/Structs/Configuration.html) -- `sqlite3_wal_checkpoint_v2`: see [DatabasePool.checkpoint](http://groue.github.io/GRDB.swift/docs/3.7/Classes/DatabasePool.html) +- `sqlite3_sql`: see [Statement.sql](http://groue.github.io/GRDB.swift/docs/4.0/Classes/Statement.html) +- `sqlite3_trace`: see [Configuration.trace](http://groue.github.io/GRDB.swift/docs/4.0/Structs/Configuration.html) +- `sqlite3_wal_checkpoint_v2`: see [DatabasePool.checkpoint](http://groue.github.io/GRDB.swift/docs/4.0/Classes/DatabasePool.html) Records @@ -2145,7 +2183,7 @@ To fetch records from the database, call a [fetching method](#fetching-methods): ```swift let arthur = try Player.fetchOne(db, // Player? - "SELECT * FROM players WHERE name = ?", + sql: "SELECT * FROM players WHERE name = ?", arguments: ["Arthur"]) let bestPlayers = try Player // [Player] @@ -2186,7 +2224,7 @@ if let player = try Player.fetchOne(db, key: 1) { For batch updates, execute an [SQL query](#executing-updates): ```swift -try db.execute("UPDATE player SET synchronized = 1") +try db.execute(sql: "UPDATE player SET synchronized = 1") ``` :point_right: update methods are available for subclasses of the [Record](#record-class) class, and types that adopt the [PersistableRecord] protocol. @@ -2261,7 +2299,7 @@ Details follow: ```swift struct Place { ... } try dbQueue.read { db in - let rows = try Row.fetchAll(db, "SELECT * FROM place") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM place") let places: [Place] = rows.map { row in return Place( id: row["id"], @@ -2279,7 +2317,7 @@ Details follow: ```swift struct Place: FetchableRecord { ... } try dbQueue.read { db in - let places = try Place.fetchAll(db, "SELECT * FROM place") + let places = try Place.fetchAll(db, sql: "SELECT * FROM place") } ``` @@ -2385,12 +2423,12 @@ struct Player: Decodable, FetchableRecord { FetchableRecord allows adopting types to be fetched from SQL queries: ```swift -try Place.fetchCursor(db, "SELECT ...", arguments:...) // A Cursor of Place -try Place.fetchAll(db, "SELECT ...", arguments:...) // [Place] -try Place.fetchOne(db, "SELECT ...", arguments:...) // Place? +try Place.fetchCursor(db, sql: "SELECT ...", arguments:...) // A Cursor of Place +try Place.fetchAll(db, sql: "SELECT ...", arguments:...) // [Place] +try Place.fetchOne(db, sql: "SELECT ...", arguments:...) // Place? ``` -See [fetching methods](#fetching-methods) for information about the `fetchCursor`, `fetchAll` and `fetchOne` methods. See [StatementArguments](http://groue.github.io/GRDB.swift/docs/3.7/Structs/StatementArguments.html) for more information about the query arguments. +See [fetching methods](#fetching-methods) for information about the `fetchCursor`, `fetchAll` and `fetchOne` methods. See [StatementArguments](http://groue.github.io/GRDB.swift/docs/4.0/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()`. @@ -2479,27 +2517,32 @@ try Citizenship.fetchOne(db, key: ["citizenId": 1, "countryCode": "FR"]) // Citi ## PersistableRecord Protocol -**GRDB provides two protocols that let adopting types create, update, and delete rows in the database:** +**GRDB record types can create, update, and delete rows in the database.** + +Those abilities are granted by three protocols: ```swift -protocol MutablePersistableRecord : TableRecord { +// Defines how a record encodes itself into the database +protocol EncodableRecord { /// Defines the values persisted in the database func encode(to container: inout PersistenceContainer) - +} + +// Adds persistence methods +protocol MutablePersistableRecord: TableRecord, EncodableRecord { /// Optional method that lets your adopting type store its rowID upon /// successful insertion. Don't call it directly: it is called for you. mutating func didInsert(with rowID: Int64, for column: String?) } -``` -```swift -protocol PersistableRecord : MutablePersistableRecord { +// Adds immutability +protocol PersistableRecord: MutablePersistableRecord { /// Non-mutating version of the optional didInsert(with:for:) func didInsert(with rowID: Int64, for column: String?) } ``` -Yes, two protocols instead of one. Both grant exactly the same advantages. Here is how you pick one or the other: +Yes, three protocols instead of one. Here is how you pick one or the other: - **If your type is a class**, choose `PersistableRecord`. On top of that, implement `didInsert(with:for:)` if the database table has an auto-incremented primary key. @@ -2689,7 +2732,7 @@ For more information about Codable records, see: - [JSON Columns] - [Date and UUID Coding Strategies] - [The userInfo Dictionary] -- [Tip: Use Coding Keys as Columns](#tip-use-coding-keys-as-columns) +- [Tip: Derive Columns from Coding Keys](#tip-derive-columns-from-coding-keys) > :bulb: **Tip**: see the [Demo Application](DemoApps/GRDBDemoiOS/README.md) for a sample app that uses Codable records. @@ -2762,7 +2805,7 @@ protocol MutablePersistableRecord { } ``` -See [DatabaseDateDecodingStrategy](https://groue.github.io/GRDB.swift/docs/3.7/Enums/DatabaseDateDecodingStrategy.html), [DatabaseDateEncodingStrategy](https://groue.github.io/GRDB.swift/docs/3.7/Enums/DatabaseDateEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/3.7/Enums/DatabaseUUIDEncodingStrategy.html) to learn about all available strategies. +See [DatabaseDateDecodingStrategy](https://groue.github.io/GRDB.swift/docs/4.0/Enums/DatabaseDateDecodingStrategy.html), [DatabaseDateEncodingStrategy](https://groue.github.io/GRDB.swift/docs/4.0/Enums/DatabaseDateEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/4.0/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). @@ -2822,32 +2865,36 @@ let player = try Player.fetchOne(db, ...) > :point_up: **Note**: make sure the `databaseDecodingUserInfo` and `databaseEncodingUserInfo` properties are explicitly declared as `[CodingUserInfoKey: Any]`. If they are not, the Swift compiler may silently miss the protocol requirement, resulting in sticky empty userInfo. -### Tip: Use Coding Keys as Columns +### Tip: Derive Columns from Coding Keys -If you declare an explicit `CodingKeys` enum ([what is this?](https://developer.apple.com/documentation/foundation/archives_and_serialization/encoding_and_decoding_custom_types)), you can instruct GRDB to use those coding keys as database columns: +Codable types are granted with a [CodingKeys](https://developer.apple.com/documentation/foundation/archives_and_serialization/encoding_and_decoding_custom_types) enum. You can use them to safely define database columns: ```swift -struct Player: Codable, FetchableRecord, PersistableRecord { +struct Player: Codable { + var id: Int64 var name: String var score: Int - - // Add ColumnExpression conformance - private enum CodingKeys: String, CodingKey, ColumnExpression { - case name, score +} + +extension Player: FetchableRecord, PersistableRecord { + enum Columns { + static let id = Column(CodingKeys.id) + static let name = Column(CodingKeys.name) + static let score = Column(CodingKeys.score) } } ``` -This allows your record to build requests with the [query interface](#the-query-interface): +Those columns let you build requests with the [query interface](#the-query-interface): ```swift extension Player { static func filter(name: String) -> QueryInterfaceRequest { - return filter(CodingKeys.name == name) + return filter(Columns.name == name) } static var maximumScore: QueryInterfaceRequest { - return select(max(CodingKeys.score), as: Int.self) + return select(max(Columns.score), as: Int.self) } } ``` @@ -2871,7 +2918,7 @@ try dbQueue.read { db in // Observe changes try ValueObservation .trackingOne(Player.maximumScore) - .start(in: dbQueue) { maxScore: Int? in + .start(in: dbQueue) { (maxScore: Int?) in print("The maximum score has changed") } ``` @@ -2938,7 +2985,7 @@ class Place: Record { ## Record Comparison -**Records that adopt a [PersistableRecord] protocol can compare against other records, or against previous versions of themselves.** +**Records that adopt the [EncodableRecord] protocol can compare against other records, or against previous versions of themselves.** This helps avoiding costly UPDATE statements when a record has not been edited. @@ -2973,7 +3020,7 @@ The `updateChanges` methods perform a database update of the changed columns onl ```swift if var player = try Player.fetchOne(db, key: 42) { - let modified = player.updateChanges(db) { + let modified = try player.updateChanges(db) { $0.score = 100 } if modified { @@ -3113,8 +3160,8 @@ The [five different policies](https://www.sqlite.org/lang_conflict.html) are: ab // Despite the unique index on email, both inserts succeed. // The second insert replaces the first row: - try db.execute("INSERT INTO player (email) VALUES (?)", arguments: ["arthur@example.com"]) - try db.execute("INSERT INTO player (email) VALUES (?)", arguments: ["arthur@example.com"]) + try db.execute(sql: "INSERT INTO player (email) VALUES (?)", arguments: ["arthur@example.com"]) + try db.execute(sql: "INSERT INTO player (email) VALUES (?)", arguments: ["arthur@example.com"]) ``` - In each modification query: @@ -3130,8 +3177,8 @@ The [five different policies](https://www.sqlite.org/lang_conflict.html) are: ab } // Again, despite the unique index on email, both inserts succeed. - try db.execute("INSERT OR REPLACE INTO player (email) VALUES (?)", arguments: ["arthur@example.com"]) - try db.execute("INSERT OR REPLACE INTO player (email) VALUES (?)", arguments: ["arthur@example.com"]) + try db.execute(sql: "INSERT OR REPLACE INTO player (email) VALUES (?)", arguments: ["arthur@example.com"]) + try db.execute(sql: "INSERT OR REPLACE INTO player (email) VALUES (?)", arguments: ["arthur@example.com"]) ``` When you want to handle conflicts at the query level, specify a custom `persistenceConflictPolicy` in your type that adopts the PersistableRecord protocol. It will alter the INSERT and UPDATE queries run by the `insert`, `update` and `save` [persistence methods](#persistence-methods): @@ -3511,19 +3558,19 @@ This is the list of record methods, along with their required protocols. The [Re | **Fetch Record [Cursors](#cursors)** | | | | `Type.fetchCursor(db)` | [FetchableRecord] & [TableRecord] | | | `Type.fetchCursor(db, keys:...)` | [FetchableRecord] & [TableRecord] | ¹ | -| `Type.fetchCursor(db, sql)` | [FetchableRecord] | ³ | +| `Type.fetchCursor(db, sql: sql)` | [FetchableRecord] | ³ | | `Type.fetchCursor(statement)` | [FetchableRecord] | ⁴ | | `Type.filter(...).fetchCursor(db)` | [FetchableRecord] & [TableRecord] | ² | | **Fetch Record Arrays** | | | | `Type.fetchAll(db)` | [FetchableRecord] & [TableRecord] | | | `Type.fetchAll(db, keys:...)` | [FetchableRecord] & [TableRecord] | ¹ | -| `Type.fetchAll(db, sql)` | [FetchableRecord] | ³ | +| `Type.fetchAll(db, sql: sql)` | [FetchableRecord] | ³ | | `Type.fetchAll(statement)` | [FetchableRecord] | ⁴ | | `Type.filter(...).fetchAll(db)` | [FetchableRecord] & [TableRecord] | ² | | **Fetch Individual Records** | | | | `Type.fetchOne(db)` | [FetchableRecord] & [TableRecord] | | | `Type.fetchOne(db, key:...)` | [FetchableRecord] & [TableRecord] | ¹ | -| `Type.fetchOne(db, sql)` | [FetchableRecord] | ³ | +| `Type.fetchOne(db, sql: sql)` | [FetchableRecord] | ³ | | `Type.fetchOne(statement)` | [FetchableRecord] | ⁴ | | `Type.filter(...).fetchOne(db)` | [FetchableRecord] & [TableRecord] | ² | | **[Record Comparison]** | | | @@ -3554,13 +3601,13 @@ let count = try request.fetchCount(db) // Int ³ See [SQL queries](#fetch-queries): ```swift -let player = try Player.fetchOne("SELECT * FROM player WHERE id = ?", arguments: [1]) // Player? +let player = try Player.fetchOne(db, sql: "SELECT * FROM player WHERE id = ?", arguments: [1]) // Player? ``` ⁴ See [Prepared Statements](#prepared-statements): ```swift -let statement = try db.makeSelectStatement("SELECT * FROM player WHERE id = ?") +let statement = try db.makeSelectStatement(sql: "SELECT * FROM player WHERE id = ?") let player = try Player.fetchOne(statement, arguments: [1]) // Player? ``` @@ -3593,11 +3640,11 @@ Please bear in mind that the query interface can not generate all possible SQL q ```swift try dbQueue.write { db in // Update database schema (with SQL) - try db.execute("CREATE TABLE wine (...)") + try db.execute(sql: "CREATE TABLE wine (...)") // Fetch records (with SQL) let wines = try Wine.fetchAll(db, - "SELECT * FROM wine WHERE origin = ? ORDER BY price", + sql: "SELECT * FROM wine WHERE origin = ? ORDER BY price", arguments: ["Burgundy"]) // Count (with an SQL snippet) @@ -3606,7 +3653,7 @@ try dbQueue.write { db in .fetchCount(db) // Delete (with SQL) - try db.execute("DELETE FROM wine WHERE corked") + try db.execute(sql: "DELETE FROM wine WHERE corked") } ``` @@ -4019,7 +4066,7 @@ Player // SELECT * FROM player ``` -Raw SQL snippets are also accepted, with eventual [arguments](http://groue.github.io/GRDB.swift/docs/3.7/Structs/StatementArguments.html): +Raw SQL snippets are also accepted, with eventual [arguments](http://groue.github.io/GRDB.swift/docs/4.0/Structs/StatementArguments.html): ```swift // SELECT DATE(creationDate), COUNT(*) FROM player WHERE name = 'Arthur' GROUP BY date(creationDate) @@ -4320,7 +4367,7 @@ When you also want to use database observation tools such as [ValueObservation], // Observe with ValueObservation try ValueObservation .trackingOne(request) - .start(in: dbQueue) { maxScore: Int? in + .start(in: dbQueue) { (maxScore: Int?) in print("The maximum score has changed") } ``` @@ -4346,7 +4393,7 @@ When you also want to use database observation tools such as [ValueObservation], // Observe with ValueObservation try ValueObservation .trackingAll(request) - .start(in: dbQueue) { bookInfos: [BookInfo] in + .start(in: dbQueue) { (bookInfos: [BookInfo]) in print("Books have changed") } ``` @@ -4420,7 +4467,7 @@ Those requests can feed [ValueObservation]: ```swift try ValueObservation. .trackingOne(Player.filter(key: 1)) - .start(in: dbQueue) { player: Player? in + .start(in: dbQueue) { (player: Player?) in print("Player 1 has changed") } ``` @@ -4525,7 +4572,7 @@ try request.fetchCount(db) // Int ```swift // Custom SQL is always welcome -try Player.fetchAll(db, "SELECT ...") // [Player] +try Player.fetchAll(db, sql: "SELECT ...") // [Player] ``` But you may prefer to bring some elegance back in, and build custom requests: @@ -4540,7 +4587,7 @@ Custom requests can also feed [ValueObservation]: ```swift try ValueObservation. .trackingAll(Player.customRequest(...)) - .start(in: dbQueue) { players: [Player] in + .start(in: dbQueue) { (players: [Player]) in print("Players have changed") } ``` @@ -4560,7 +4607,7 @@ protocol FetchRequest: DatabaseRegionConvertible { associatedtype RowDecoder /// A tuple that contains a prepared statement, and an eventual row adapter. - func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) + func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) /// The number of rows fetched by the request. func fetchCount(_ db: Database) throws -> Int @@ -4569,7 +4616,7 @@ protocol FetchRequest: DatabaseRegionConvertible { When the `RowDecoder` associated type is [Row](#fetching-rows), or a [value](#value-queries), or a type that conforms to [FetchableRecord], the request can fetch: see [Fetching From Custom Requests](#fetching-from-custom-requests) below. -The `prepare` method returns a prepared statement and an optional row adapter. The [prepared statement](#prepared-statements) tells which SQL query should be executed. The row adapter helps presenting the fetched rows in the way expected by the row decoders (see [row adapter](#row-adapters)). +The `prepare(_:forSingleResult:)` method accepts a database connection, a `singleResult` hint, and returns a prepared statement and an optional row adapter. Conforming types can use the `singleResult` hint as an optimization opportunity, and return a [prepared statement](#prepared-statements) that fetches at most one row, with a `LIMIT` SQL clause, when possible. The optional row adapter helps presenting the fetched rows in the way expected by the row decoders (see [row adapters](#row-adapters)). The `fetchCount` method has a default implementation that builds a correct but naive SQL query from the statement returned by `prepare`: `SELECT COUNT(*) FROM (...)`. Adopting types can refine the counting SQL by customizing their `fetchCount` implementation. @@ -4587,13 +4634,13 @@ let request = Player.all() **To build custom requests**, you can use one of the built-in requests, derive requests from other requests, or create your own request type that adopts the [FetchRequest](#fetchrequest-protocol) protocol. -- [SQLRequest](http://groue.github.io/GRDB.swift/docs/3.7/Structs/SQLRequest.html) is a fetch request built from raw SQL. For example: +- [SQLRequest](http://groue.github.io/GRDB.swift/docs/4.0/Structs/SQLRequest.html) is a fetch request built from raw SQL. For example: ```swift extension Player { static func filter(color: Color) -> SQLRequest { return SQLRequest( - "SELECT * FROM player WHERE color = ?" + sql: "SELECT * FROM player WHERE color = ?" arguments: [color]) } } @@ -4602,6 +4649,17 @@ let request = Player.all() try Player.filter(color: .red).fetchAll(db) ``` + In Swift 5, you can build SQLRequest with [SQL Interpolation]: + + ```swift + // Swift 5 + extension Player { + static func filter(color: Color) -> SQLRequest { + return "SELECT * FROM player WHERE color = \(color)" + } + } + ``` + - The `asRequest(of:)` method changes the type fetched by the request. It is useful, for example, when you use [Associations]: ```swift @@ -4620,7 +4678,7 @@ let request = Player.all() - 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/3.7/Structs/AnyFetchRequest.html): a [type-erased](http://chris.eidhof.nl/post/type-erasers-in-swift/) request. +- [AnyFetchRequest](http://groue.github.io/GRDB.swift/docs/4.0/Structs/AnyFetchRequest.html): a [type-erased](http://chris.eidhof.nl/post/type-erasers-in-swift/) request. ### Fetching From Custom Requests @@ -4642,7 +4700,7 @@ For example: ```swift let playerRequest = SQLRequest( - "SELECT * FROM player WHERE color = ?" + sql: "SELECT * FROM player WHERE color = ?" arguments: [color]) try request.fetchAll(db) // [Player] ``` @@ -4759,7 +4817,7 @@ migrator.registerMigrationWithDeferredForeignKeyCheck("AddNotNullCheckOnName") { t.autoIncrementedPrimaryKey("id") t.column("name", .text).notNull() } - try db.execute("INSERT INTO new_player SELECT * FROM player") + try db.execute(sql: "INSERT INTO new_player SELECT * FROM player") try db.drop(table: "player") try db.rename(table: "new_player", to: "player") } @@ -4783,7 +4841,7 @@ try db.create(virtualTable: "book", using: FTS4()) { t in // or FTS3(), or FTS5( // Populate full-text table with records or SQL try Book(...).insert(db) try db.execute( - "INSERT INTO book (author, title, body) VALUES (?, ?, ?)", + sql: "INSERT INTO book (author, title, body) VALUES (?, ?, ?)", arguments: [...]) // Build search patterns @@ -4792,7 +4850,7 @@ let pattern = FTS3Pattern(matchingPhrase: "Moby-Dick") // Search with the query interface or SQL let books = try Book.matching(pattern).fetchAll(db) let books = try Book.fetchAll(db, - "SELECT * FROM book WHERE book MATCH ?", + sql: "SELECT * FROM book WHERE book MATCH ?", arguments: [pattern]) ``` @@ -4986,7 +5044,7 @@ See below some examples of matches: ```swift try db.create(virtualTable: "book", using: FTS4()) { t in t.tokenizer = .unicode61() - t.tokenizer = .unicode61(removeDiacritics: false) + t.tokenizer = .unicode61(diacritics: .keep) } ``` @@ -5050,11 +5108,11 @@ let pattern = FTS3Pattern(matchingAnyTokenIn: "") // nil let pattern = FTS3Pattern(matchingAnyTokenIn: "*") // nil ``` -FTS3Pattern are regular [values](#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/3.7/Structs/StatementArguments.html): +FTS3Pattern are regular [values](#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/4.0/Structs/StatementArguments.html): ```swift let documents = try Document.fetchAll(db, - "SELECT * FROM document WHERE content MATCH ?", + sql: "SELECT * FROM document WHERE content MATCH ?", arguments: [pattern]) ``` @@ -5094,20 +5152,20 @@ The version of SQLite that ships with iOS, macOS and watchOS does not always sup > :point_up: **Note**: there used to be a GRDBPlus CocoaPod with pre-enabled FTS5 support. This CocoaPod is deprecated: please switch to the above technique. -2. Use the GRDBCipher CocoaPod. It uses SQLCipher (see [encryption](#encryption)), and requires iOS 8.0+ / macOS 10.9+ / watchOS 2.0+: +2. Use the GRDB.swift/SQLCipher CocoaPod subspec (see [encryption](#encryption)): ```ruby - pod 'GRDBCipher' + pod 'GRDB.swift/SQLCipher' ``` -3. Use a [custom SQLite build](Documentation/CustomSQLiteBuilds.md) and activate the `SQLITE_ENABLE_FTS5` compilation option. +3. Use a [custom SQLite build] and activate the `SQLITE_ENABLE_FTS5` compilation option. ### Create FTS5 Virtual Tables **FTS5 full-text tables store and index textual content.** -To use FTS5, you'll need a [custom SQLite build](Documentation/CustomSQLiteBuilds.md) that activates the `SQLITE_ENABLE_FTS5` compilation option. +To use FTS5, you'll need a [custom SQLite build] that activates the `SQLITE_ENABLE_FTS5` compilation option. Create FTS5 tables with the `create(virtualTable:using:)` method: @@ -5200,7 +5258,7 @@ See below some examples of matches: ```swift try db.create(virtualTable: "book", using: FTS5()) { t in t.tokenizer = .unicode61() - t.tokenizer = .unicode61(removeDiacritics: false) + t.tokenizer = .unicode61(diacritics: .keep) } ``` @@ -5230,7 +5288,7 @@ See below some examples of matches: try db.create(virtualTable: "book", using: FTS5()) { t in t.tokenizer = .porter() // porter wrapping unicode61 (the default) t.tokenizer = .porter(.ascii) // porter wrapping ascii - t.tokenizer = .porter(.unicode61(removeDiacritics: false)) // porter wrapping unicode61 without diacritics stripping + t.tokenizer = .porter(.unicode61(diacritics: .keep)) // porter wrapping unicode61 without diacritics stripping } ``` @@ -5299,11 +5357,11 @@ let pattern = FTS5Pattern(matchingAnyTokenIn: "") // nil let pattern = FTS5Pattern(matchingAnyTokenIn: "*") // nil ``` -FTS5Pattern are regular [values](#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/3.7/Structs/StatementArguments.html): +FTS5Pattern are regular [values](#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/4.0/Structs/StatementArguments.html): ```swift let documents = try Document.fetchAll(db, - "SELECT * FROM document WHERE document MATCH ?", + sql: "SELECT * FROM document WHERE document MATCH ?", arguments: [pattern]) ``` @@ -5321,7 +5379,7 @@ let documents = try Document.matching(pattern).fetchAll(db) ```swift // SQL let documents = try Document.fetchAll(db, - "SELECT * FROM document WHERE document MATCH ? ORDER BY rank", + sql: "SELECT * FROM document WHERE document MATCH ? ORDER BY rank", arguments: [pattern]) // Query Interface @@ -5426,7 +5484,7 @@ let sql = """ ON book_ft.rowid = book.rowid AND book_ft MATCH ? """ -let books = Book.fetchAll(db, sql, arguments: [pattern]) +let books = Book.fetchAll(db, sql: sql, arguments: [pattern]) ``` @@ -5558,7 +5616,7 @@ We merge those two adapters in a single [ScopeAdapter](#scopeadapter) that will And now we can fetch, and start consuming our rows. You already know [row cursors](#fetching-rows): ```swift - let rows = try Row.fetchCursor(db, sql, adapter: adapter) + let rows = try Row.fetchCursor(db, sql: sql, adapter: adapter) while let row = try rows.next() { ``` @@ -5684,7 +5742,7 @@ Now is the time to build adapters (taking in account the customized selection of And finally, we can fetch player infos: ```swift - return try PlayerInfo.fetchAll(db, sql, adapter: adapter) + return try PlayerInfo.fetchAll(db, sql: sql, adapter: adapter) } } ``` @@ -5751,7 +5809,7 @@ extension PlayerInfo { LEFT JOIN round ON ... GROUP BY ... """ - return SQLRequest(sql).adapted { db in + return SQLRequest(sql: sql).adapted { db in let adapters = try splittingRowAdapters(columnCounts: [ Player.numberOfSelectedColumns(db), Team.numberOfSelectedColumns(db)]) @@ -5779,7 +5837,7 @@ let playerInfos = try dbQueue.read { db in // Track player infos with RxRGDB: PlayerInfo.all() .rx.fetchAll(in: dbQueue) - .subscribe(onNext: { playerInfos: [PlayerInfo] in + .subscribe(onNext: { (playerInfos: [PlayerInfo]) in print("Player infos have changed") }) ``` @@ -5822,7 +5880,7 @@ extension PlayerInfo { LEFT JOIN round ON ... GROUP BY ... """ - return SQLRequest(sql).adapted { db in + return SQLRequest(sql: sql).adapted { db in let adapters = try splittingRowAdapters(columnCounts: [ Player.numberOfSelectedColumns(db), Team.numberOfSelectedColumns(db)]) @@ -5846,7 +5904,7 @@ let playerInfos = try dbQueue.read { db in // Track player infos with RxRGDB: PlayerInfo.all() .rx.fetchAll(in: dbQueue) - .subscribe(onNext: { playerInfos: [PlayerInfo] in + .subscribe(onNext: { (playerInfos: [PlayerInfo]) in print("Player infos have changed") }) ``` @@ -5942,7 +6000,7 @@ let request = Player.all() ```swift let observation = ValueObservation.trackingAll(request) -let observer = observation.start(in: dbQueue) { players: [Player] in +let observer = observation.start(in: dbQueue) { (players: [Player]) in let names = players.map { $0.name }.joined(separator: ", ") print("Fresh players: \(names)") } @@ -5957,7 +6015,7 @@ try dbQueue.write { db in ```swift let observation = DatabaseRegionObservation(tracking: request) -let observer = observation.start(in: dbQueue) { db: Database in +let observer = observation.start(in: dbQueue) { (db: Database) in print("Players have changed.") } @@ -6006,8 +6064,8 @@ class PlayerViewController: UIViewController { // Start observing the database observer = try! observation.start( in: dbQueue, - onChange: { [unowned self] player: Player? in - // Player has changed: update view + onChange: { [unowned self] (player: Player?) in + // Player has been refreshed: update view self.nameLabel.text = player?.name }) } @@ -6023,12 +6081,41 @@ class PlayerViewController: UIViewController { By default, all values are notified on the main queue. Views can be updated right from the `onChange` callback. -An initial fetch is performed as soon as the observation starts: the view is set up and ready when the `viewWillAppear` method returns. +By default, an initial fetch is performed as soon as the observation starts: the view is set up and ready when the `viewWillAppear` method returns. The observer returned by the `start` method is stored in a property of the view controller. This allows the view controller to control the duration of the observation. When the observer is deallocated, the observation stops. Meanwhile, all transactions that modify the observed player are notified, and the `nameLabel` is kept up-to-date. > :bulb: **Tip**: see the [Demo Application](DemoApps/GRDBDemoiOS/README.md) for a sample app that uses ValueObservation. - +> +> :bulb: **Tip**: When fetching values is slow, and should never ever block the main queue, opt in for async notifications: +> +> ```swift +> override func viewWillAppear(_ animated: Bool) { +> super.viewWillAppear(animated) +> +> // Define a ValueObservation which tracks a player +> let request = Player.filter(key: 42) +> var observation = ValueObservation.trackingOne(request) +> +> // Observation is asynchronous +> observation.scheduling = .async(onQueue: .main, startImmediately: true) +> +> // Start observing the database +> observer = try! observation.start( +> in: dbQueue, +> onChange: { [unowned self] (player: Player?) in +> // Player has been refreshed: update view +> self.activityIndicator.stopAnimating() +> self.nameLabel.text = player?.name +> }) +> +> // Wait for player +> activityIndicator.startAnimating() +> nameLabel.text = nil +> } +> ``` +> +> See [ValueObservation.scheduling](#valueobservationscheduling) for more information. ### ValueObservation.trackingCount, trackingOne, trackingAll @@ -6048,7 +6135,7 @@ Those observations match the `fetchCount`, `fetchOne`, and `fetchAll` request me // Observe number of players let observer = ValueObservation .trackingCount(Player.all()) - .start(in: dbQueue) { count: Int in + .start(in: dbQueue) { (count: Int) in print("Number of players have changed: \(count)") } ``` @@ -6059,7 +6146,7 @@ Those observations match the `fetchCount`, `fetchOne`, and `fetchAll` request me // Observe a single player let observer = ValueObservation .trackingOne(Player.filter(key: 1)) - .start(in: dbQueue) { player: Player? in + .start(in: dbQueue) { (player: Player?) in print("Player has changed: \(player)") } @@ -6067,7 +6154,7 @@ Those observations match the `fetchCount`, `fetchOne`, and `fetchAll` request me let request = Player.select(max(Column("score")), as: Int.self) let observer = ValueObservation .trackingOne(request) - .start(in: dbQueue) { maximumScore: Int? in + .start(in: dbQueue) { (maximumScore: Int?) in print("Maximum score has changed: \(maximumScore)") } ``` @@ -6078,15 +6165,15 @@ Those observations match the `fetchCount`, `fetchOne`, and `fetchAll` request me // Observe all players let observer = ValueObservation .trackingAll(Player.all()) - .start(in: dbQueue) { players: [Player] in + .start(in: dbQueue) { (players: [Player]) in print("Players have changed: \(players)") } // Observe all player names - let request = SQLRequest("SELECT name FROM player") + let request = SQLRequest(sql: "SELECT name FROM player") let observer = ValueObservation .trackingAll(request) - .start(in: dbQueue) { names: [String] in + .start(in: dbQueue) { (names: [String]) in print("Player names have changed: \(names)") } ``` @@ -6137,7 +6224,7 @@ let observation = ValueObservation.tracking(Player.all(), fetch: { db in try HallOfFame.fetch(db) }) -let observer = observation.start(in: dbQueue) { hallOfFame: HallOfFame in +let observer = observation.start(in: dbQueue) { (hallOfFame: HallOfFame) in print(""" Best players out of \(hallOfFame.totalPlayerCount): \(hallOfFame.bestPlayers) @@ -6161,7 +6248,7 @@ let observation = ValueObservation .tracking(Player.all(), fetch: HallOfFame.fetch) .distinctUntilChanged() -let observer = observation.start(in: dbQueue) { hallOfFame: HallOfFame in +let observer = observation.start(in: dbQueue) { (hallOfFame: HallOfFame) in print(""" Best players out of \(hallOfFame.totalPlayerCount): \(hallOfFame.bestPlayers) @@ -6225,7 +6312,7 @@ let teamInfo: TeamInfo? = try dbQueue.read(request.fetch) // Observation let observer = ValueObservation .tracking(request, fetch: request.fetch) - .start(in: dbQueue) { teamInfo: TeamInfo? in + .start(in: dbQueue) { (teamInfo: TeamInfo?) in print("Team and its players have hanged.") } ``` @@ -6251,7 +6338,7 @@ let observation = ValueObservation .trackingOne(Player.filter(key: 42)) .map { player in player?.loadBigProfileImage() } -let observer = observation.start(in: dbQueue) { image: UIImage? in +let observer = observation.start(in: dbQueue) { (image: UIImage?) in print("Player picture has changed") } ``` @@ -6271,7 +6358,7 @@ let observation = ValueObservation .trackingOne(Player.filter(key: 42)) .compactMap { $0 } -let observer = observation.start(in: dbQueue) { player: Player in +let observer = observation.start(in: dbQueue) { (player: Player) in print("Player name: \(player.name)") } ``` @@ -6291,7 +6378,7 @@ let observation = ValueObservation .map { player in player != nil } // existence test .distinctUntilChanged() -let observer = observation.start(in: dbQueue) { exists: Bool in +let observer = observation.start(in: dbQueue) { (exists: Bool) in if exists { print("Player 42 exists.") } else { @@ -6354,29 +6441,10 @@ let observer = try observation.start( Some behaviors of value observations can be configured: -- [ValueObservation.extent](#valueobservationextent): Precise control of the observation duration. - [ValueObservation.scheduling](#valueobservationscheduling): Control the dispatching of notified values. - [ValueObservation.requiresWriteAccess](#valueobservationrequireswriteaccess): Allow observations to write in the database. -#### ValueObservation.extent - -The `extent` property lets you specify the duration of the observation. - -The default extent is `.observerLifetime`: the observation stops when the observer returned by `start` is deallocated. - -You can use the `.databaseLifetime` extent to specify that the observation lasts until the database connection is closed: - -```swift -// No need to retain the observer returned by the start method: -var observation = ValueObservation... -observation.extent = .databaseLifetime -_ = observation.start(in: dbQueue) { newValue in ... } -``` - -> :warning: **Warning**: Don't use the `.nextTransaction` lifetime, because it produces unreliable results. A future version of GRDB will deprecate `ValueObservation.extent`, and provide a better API. - - #### ValueObservation.scheduling The `scheduling` property lets you control how fresh values are notified: @@ -6389,7 +6457,7 @@ The `scheduling` property lets you control how fresh values are notified: // On main queue let observer = ValueObservation .trackingAll(Player.all()) - .start(in: dbQueue) { players: [Player] in + .start(in: dbQueue) { (players: [Player]) in // On main queue print("fresh players: \(players)") } @@ -6402,7 +6470,7 @@ The `scheduling` property lets you control how fresh values are notified: // Not on the main queue let observer = ValueObservation .trackingAll(Player.all()) - .start(in: dbQueue) { players: [Player] in + .start(in: dbQueue) { (players: [Player]) in // On main queue print("fresh players: \(players)") } @@ -6417,18 +6485,21 @@ The `scheduling` property lets you control how fresh values are notified: } ``` -- `.onQueue(_:startImmediately:)`: all values are asychronously notified on the specified queue. +- `.async(onQueue:startImmediately:)`: all values are asychronously notified on the specified queue. An initial value is fetched and notified if `startImmediately` is true. + For example: + ```swift - let customQueue = DispatchQueue(label: "customQueue") + // On main queue var observation = ValueObservation.trackingAll(Player.all()) - observation.scheduling = .onQueue(customQueue, startImmediately: true) - let observer = try observation.start(in: dbQueue) { players: [Player] in - // On customQueue + observation.scheduling = .async(onQueue: .main, startImmediately: true) + let observer = try observation.start(in: dbQueue) { (players: [Player]) in + // On main queue print("fresh players: \(players)")s } + // <- here "fresh players" is not printed yet. ``` - `unsafe(startImmediately:)`: values are not all notified on the same dispatch queue. @@ -6439,7 +6510,7 @@ The `scheduling` property lets you control how fresh values are notified: // On any queue var observation = ValueObservation.trackingAll(Player.all()) observation.scheduling = .unsafe(startImmediately: true) - let observer = try observation.start(in: dbQueue) { players: [Player] in + let observer = try observation.start(in: dbQueue) { (players: [Player]) in print("fresh players: \(players)") } // <- here "fresh players" is already printed. @@ -6495,7 +6566,7 @@ let reducer = AnyValueReducer( defer { count += 1 } return count }) let observation = ValueObservation.tracking(Player.all(), reducer: { _ in reducer }) -let observer = observation.start(in: dbQueue) { count: Int in +let observer = observation.start(in: dbQueue) { (count: Int) in print("Number of transactions that have modified players: \(count)") } // Prints "Number of transactions that have modified players: 0" @@ -6528,7 +6599,7 @@ let observation = DatabaseRegionObservation(tracking: Player.all()) Then start the observation from a [database queue](#database-queues) or [pool](#database-pools): ```swift -let observer = observation.start(in: dbQueue) { db: Database in +let observer = observation.start(in: dbQueue) { (db: Database) in print("Players were changed") } ``` @@ -6549,7 +6620,7 @@ You can also feed DatabaseRegionObservation with [DatabaseRegion], or any type w ```swift // Observe the full database let observation = DatabaseRegionObservation(tracking: DatabaseRegion.fullDatabase) -let observer = observation.start(in: dbQueue) { db: Database in +let observer = observation.start(in: dbQueue) { (db: Database) in print("Database was changed") } ``` @@ -6997,28 +7068,28 @@ Notified changes are not actually written to disk until the [transaction](#trans ```swift try dbQueue.write { db in - try db.execute("INSERT ...") // 1. didChange - try db.execute("UPDATE ...") // 2. didChange -} // 3. willCommit, 4. didCommit + try db.execute(sql: "INSERT ...") // 1. didChange + try db.execute(sql: "UPDATE ...") // 2. didChange +} // 3. willCommit, 4. didCommit try dbQueue.inTransaction { db in - try db.execute("INSERT ...") // 1. didChange - try db.execute("UPDATE ...") // 2. didChange - return .rollback // 3. didRollback + try db.execute(sql: "INSERT ...") // 1. didChange + try db.execute(sql: "UPDATE ...") // 2. didChange + return .rollback // 3. didRollback } try dbQueue.write { db in - try db.execute("INSERT ...") // 1. didChange + try db.execute(sql: "INSERT ...") // 1. didChange throw SomeError() -} // 2. didRollback +} // 2. didRollback ``` Database statements that are executed outside of any transaction do not drop off the radar: ```swift try dbQueue.inDatabase { db in - try db.execute("INSERT ...") // 1. didChange, 2. willCommit, 3. didCommit - try db.execute("UPDATE ...") // 4. didChange, 5. willCommit, 6. didCommit + try db.execute(sql: "INSERT ...") // 1. didChange, 2. willCommit, 3. didCommit + try db.execute(sql: "UPDATE ...") // 4. didChange, 5. willCommit, 6. didCommit } ``` @@ -7026,18 +7097,18 @@ Changes that are on hold because of a [savepoint](https://www.sqlite.org/lang_sa ```swift try dbQueue.inTransaction { db in - try db.execute("INSERT ...") // 1. didChange + try db.execute(sql: "INSERT ...") // 1. didChange - try db.execute("SAVEPOINT foo") - try db.execute("UPDATE ...") // delayed - try db.execute("UPDATE ...") // delayed - try db.execute("RELEASE SAVEPOINT foo") // 2. didChange, 3. didChange + try db.execute(sql: "SAVEPOINT foo") + try db.execute(sql: "UPDATE ...") // delayed + try db.execute(sql: "UPDATE ...") // delayed + try db.execute(sql: "RELEASE SAVEPOINT foo") // 2. didChange, 3. didChange - try db.execute("SAVEPOINT foo") - try db.execute("UPDATE ...") // not notified - try db.execute("ROLLBACK TO SAVEPOINT foo") + try db.execute(sql: "SAVEPOINT foo") + try db.execute(sql: "UPDATE ...") // not notified + try db.execute(sql: "ROLLBACK TO SAVEPOINT foo") - return .commit // 4. willCommit, 5. didCommit + return .commit // 4. willCommit, 5. didCommit } ``` @@ -7138,8 +7209,6 @@ dbQueue.inDatabase { db in } ``` -> :point_up: **Note**: removing a transaction observer makes it sure it won't be notified of any future transaction - there is no race condition. However, this does not stop eventual concurrent processing of previous transactions. For example, `remove(transactionObserver:)` is not a correct way to stop observers started by [ValueObservation]. In this case, the correct way is deallocating the observer. - Alternatively, use the `extent` parameter of the `add(transactionObserver:extent:)` method: ```swift @@ -7187,7 +7256,7 @@ After `stopObservingDatabaseChangesUntilNextTransaction()`, the `databaseDidChan ### DatabaseRegion -**[DatabaseRegion](https://groue.github.io/GRDB.swift/docs/3.7/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/4.0/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. @@ -7197,9 +7266,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. -Similarly, observing the region of `Country.filter(key: "FR")` will notify all changes that happen to the whole `country` table. That is because SQLite only notifies the numerical [rowid](https://www.sqlite.org/rowidtable.html) of changed rows, and we can't check if it is the row "FR" that has been changed, or another. This limitation does not apply to tables whose primary key is the rowid: `Player.filter(key: 42)` will only notify of changes performed on the row with id 42. - -For more details, see the [reference](http://groue.github.io/GRDB.swift/docs/3.7/Structs/DatabaseRegion.html#/s:4GRDB14DatabaseRegionV10isModified2bySbAA0B5EventV_tF). +For more details, see the [reference](http://groue.github.io/GRDB.swift/docs/4.0/Structs/DatabaseRegion.html#/s:4GRDB14DatabaseRegionV10isModified2bySbAA0B5EventV_tF). #### The DatabaseRegionConvertible Protocol @@ -7219,7 +7286,7 @@ Use this protocol when you want to encapsulate your complex requests in a dedica ### Support for SQLite Pre-Update Hooks -A [custom SQLite build](Documentation/CustomSQLiteBuilds.md) can activate [SQLite "preupdate hooks"](https://sqlite.org/c3ref/preupdate_count.html). In this case, TransactionObserverType gets an extra callback which lets you observe individual column values in the rows modified by a transaction: +A [custom SQLite build] can activate [SQLite "preupdate hooks"](https://sqlite.org/c3ref/preupdate_count.html). In this case, TransactionObserverType gets an extra callback which lets you observe individual column values in the rows modified by a transaction: ```swift protocol TransactionObserverType : class { @@ -7239,37 +7306,39 @@ protocol TransactionObserverType : class { Encryption ========== -**GRDB can encrypt your database with [SQLCipher](http://sqlcipher.net) v3.4.2.** +**GRDB can encrypt your database with [SQLCipher](http://sqlcipher.net) v3.4+.** -You can use [CocoaPods](http://cocoapods.org/) (version 1.2 or higher), and specify in your `Podfile`: +Use [CocoaPods](http://cocoapods.org/), and specify in your `Podfile`: ```ruby -use_frameworks! -pod 'GRDBCipher' +# GRDB with SQLCipher 4 +pod 'GRDB.swift/SQLCipher' +pod 'SQLCipher', '~> 4.0' + +# GRDB with SQLCipher 3 +pod 'GRDB.swift/SQLCipher' +pod 'SQLCipher', '~> 3.4' ``` -Alternatively, perform a manual installation of GRDB and SQLCipher: - -1. Clone the GRDB git repository, checkout the latest tagged version, and download SQLCipher sources: - - ```sh - cd [GRDB directory] - git checkout v3.7.0 - git submodule update --init SQLCipher/src - ``` - -2. Embed the `GRDBCipher.xcodeproj` project in your own project. - -3. Add the `GRDBCipherOSX` or `GRDBCipheriOS` target in the **Target Dependencies** section of the **Build Phases** tab of your application target. - -4. Add the `GRDBCipher.framework` from the targetted platform to the **Embedded Binaries** section of the **General** tab of your target. - +> :warning: **Warning**: SQLCipher 4 is *not compatible** with SQLCipher 3. +> +> When you want to open your existing SQLCipher 3 database with SQLCipher 4, you may want to run the `cipher_compatibility` pragma: +> +> ```swift +> // Open an SQLCipher 3 database with SQLCipher 4 +> var configuration = Configuration() +> configuration.passphrase = "..." +> configuration.prepareDatabase = { db in +> try db.execute(sql: "PRAGMA cipher_compatibility = 3") +> } +> let dbQueue = try DatabaseQueue(path: dbPath, configuration: configuration) +> ``` +> +> See [SQLCipher 4.0.0 Release](https://www.zetetic.net/blog/2018/11/30/sqlcipher-400-release/) and [Upgrading to SQLCipher 4](https://discuss.zetetic.net/t/upgrading-to-sqlcipher-4/3283) for more information. See also [Advanced configuration options for SQLCipher](#advanced-configuration-options-for-sqlcipher) below. **You create and open an encrypted database** by providing a passphrase to your [database connection](#database-connections): ```swift -import GRDBCipher - var configuration = Configuration() configuration.passphrase = "secret" let dbQueue = try DatabaseQueue(path: "...", configuration: configuration) @@ -7295,9 +7364,9 @@ configuration.passphrase = "secret" let encryptedDBQueue = try DatabaseQueue(path: "/path/to/encrypted.db", configuration: config) try clearDBQueue.inDatabase { db in - try db.execute("ATTACH DATABASE ? AS encrypted KEY ?", arguments: [encryptedDBQueue.path, "secret"]) - try db.execute("SELECT sqlcipher_export('encrypted')") - try db.execute("DETACH DATABASE encrypted") + try db.execute(sql: "ATTACH DATABASE ? AS encrypted KEY ?", arguments: [encryptedDBQueue.path, "secret"]) + try db.execute(sql: "SELECT sqlcipher_export('encrypted')") + try db.execute(sql: "DETACH DATABASE encrypted") } // Now the copy is done, and the clear-text database can be deleted. @@ -7305,31 +7374,19 @@ try clearDBQueue.inDatabase { db in ## Advanced configuration options for SQLCipher -There are two advanced configuration options that you can set for configuring SQLCipher that control aspects of the encryption and key generation process. +Some advanced SQLCipher configuration steps must happen very early in the database lifetime, and you will have to use the `configuration.prepareDatabase` property in order to run them correctly: ```swift var configuration = Configuration() configuration.passphrase = "secret" -configuration.cipherPageSize = .pageSize4K -configuration.kdfIterations = 128000 +configuration.prepareDatabase = { db in + try db.execute(sql: "PRAGMA cipher_page_size = 4096") + try db.execute(sql: "PRAGMA kdf_iter = 128000") +} let dbQueue = try DatabaseQueue(path: "...", configuration: configuration) ``` -### cipherPageSize - -The `cipherPageSize` is used to adjust the page size for the encrypted database (this corresponds to the [SQLCipher `PRAGMA cipher_page_size`](https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_page_size) configuration option). Increasing the page size can noticeably improve performance for certain queries that access large numbers of pages. - -The default `cipherPageSize` in the current version of SQLCipher used in GRDB.swift is `1024`. - -> :point_up: **Note**: the same `cipherPageSize` must be supplied every time that the database file is open; attempting to access the database without setting the proper `cipherPageSize` will result in the `SQLite error 26: file is encrypted or is not a database` error being thrown. - -### kdfIterations - -The `kdfIterations` value is used to adjust the number of iterations that the PBKDF2 key derivation is run to derive the key from the `passphrase` supplied (this corresponds to the [SQLCipher `PRAGMA kdf_iter`](https://www.zetetic.net/sqlcipher/sqlcipher-api/#kdf_iter) configuration option). - -The default `kdfIterations` in the current version of SQLCipher used in GRDB.swift is `64000`. It is not recommend to reduce the number of iterations used from the default. - -> :point_up: **Note**: the same `kdfIterations` must be supplied every time that the database file is open; attempting to access the database without setting the proper `kdfIterations` will result in the `SQLite error 26: file is encrypted or is not a database` error being thrown. +See [PRAGMA cipher_page_size](https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_page_size) and [PRAGMA kdf_iter](https://www.zetetic.net/sqlcipher/sqlcipher-api/#kdf_iter) for more information. ## Backup @@ -7364,7 +7421,7 @@ Here is an example of code that is vulnerable to SQL injection: let id = 1 let name = textField.text try dbQueue.write { db in - try db.execute("UPDATE students SET name = '\(name)' WHERE id = \(id)") + try db.execute(sql: "UPDATE students SET name = '\(name)' WHERE id = \(id)") } ``` @@ -7383,12 +7440,12 @@ let name = textField.text try dbQueue.write { db in // Good try db.execute( - "UPDATE students SET name = ? WHERE id = ?", + sql: "UPDATE students SET name = ? WHERE id = ?", arguments: [name, id]) // Just as good try db.execute( - "UPDATE students SET name = :name WHERE id = :id", + sql: "UPDATE students SET name = :name WHERE id = :id", arguments: ["name": name, "id": id]) } ``` @@ -7427,7 +7484,7 @@ Considering that a local database is not some JSON loaded from a remote server, ```swift do { try db.execute( - "INSERT INTO pet (masterId, name) VALUES (?, ?)", + sql: "INSERT INTO pet (masterId, name) VALUES (?, ?)", arguments: [1, "Bobby"]) } catch let error as DatabaseError { // The SQLite error code: 19 (SQLITE_CONSTRAINT) @@ -7483,7 +7540,7 @@ do { } ``` -> :warning: **Warning**: SQLite has progressively introduced extended result codes accross its versions. For example, `SQLITE_CONSTRAINT_FOREIGNKEY` wasn't introduced yet on iOS 8.1. The [SQLite release notes](http://www.sqlite.org/changes.html) are unfortunately not quite clear about that: write your handling of extended result codes with care. +> :warning: **Warning**: SQLite has progressively introduced extended result codes accross its versions. The [SQLite release notes](http://www.sqlite.org/changes.html) are unfortunately not quite clear about that: write your handling of extended result codes with care. ### PersistenceError @@ -7493,8 +7550,8 @@ do { ```swift do { try player.update(db) -} catch PersistenceError.recordNotFound { - // There was nothing to update +} catch let PersistenceError.recordNotFound(databaseTableName: table, key: key) { + print("Key \(key) was not found in table \(table).") } ``` @@ -7577,7 +7634,7 @@ let sql = "SELECT ..." // Some untrusted arguments for the query let arguments: [String: Any] = ... -let rows = try Row.fetchCursor(db, sql, arguments: StatementArguments(arguments)) +let rows = try Row.fetchCursor(db, sql: sql, arguments: StatementArguments(arguments)) while let row = try rows.next() { // Some untrusted database value: @@ -7595,7 +7652,7 @@ In such a situation, you can still avoid fatal errors by exposing and handling e ```swift // Untrusted arguments if let arguments = StatementArguments(arguments) { - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) try statement.validate(arguments: arguments) statement.unsafeSetArguments(arguments) @@ -7647,7 +7704,7 @@ The `UPPER` and `LOWER` built-in SQLite functions are not unicode-aware: ```swift // "JéRôME" -try String.fetchOne(db, "SELECT UPPER('Jérôme')") +try String.fetchOne(db, sql: "SELECT UPPER('Jérôme')") ``` GRDB extends SQLite with [SQL functions](#custom-sql-functions-and-aggregates) that call the Swift built-in string functions `capitalized`, `lowercased`, `uppercased`, `localizedCapitalized`, `localizedLowercased` and `localizedUppercased`: @@ -7655,7 +7712,7 @@ GRDB extends SQLite with [SQL functions](#custom-sql-functions-and-aggregates) t ```swift // "JÉRÔME" let uppercased = DatabaseFunction.uppercase -try String.fetchOne(db, "SELECT \(uppercased.name)('Jérôme')") +try String.fetchOne(db, sql: "SELECT \(uppercased.name)('Jérôme')") ``` Those unicode-aware string functions are also readily available in the [query interface](#sql-functions): @@ -7701,7 +7758,7 @@ If you can't or don't want to define the comparison behavior of a column (see wa ```swift let collation = DatabaseCollation.localizedCaseInsensitiveCompare let players = try Player.fetchAll(db, - "SELECT * FROM player ORDER BY name COLLATE \(collation.name))") + sql: "SELECT * FROM player ORDER BY name COLLATE \(collation.name))") let players = try Player.order(nameColumn.collating(collation)).fetchAll(db) ``` @@ -7975,7 +8032,7 @@ The correct solution is the `concurrentRead` method, which must be called from w ```swift // CORRECT -let futureCount: Future = try dbPool.writeWithoutTransaction { db in +let futureCount: DatabaseFuture = try dbPool.writeWithoutTransaction { db in // increment the number of players try Player(...).insert(db) @@ -8073,7 +8130,7 @@ try snapshot2.read { db in ### DatabaseWriter and DatabaseReader Protocols -Both DatabaseQueue and DatabasePool adopt the [DatabaseReader](http://groue.github.io/GRDB.swift/docs/3.7/Protocols/DatabaseReader.html) and [DatabaseWriter](http://groue.github.io/GRDB.swift/docs/3.7/Protocols/DatabaseWriter.html) protocols. DatabaseSnapshot adopts DatabaseReader only. +Both DatabaseQueue and DatabasePool adopt the [DatabaseReader](http://groue.github.io/GRDB.swift/docs/4.0/Protocols/DatabaseReader.html) and [DatabaseWriter](http://groue.github.io/GRDB.swift/docs/4.0/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: @@ -8188,7 +8245,7 @@ If you absolutely need multiple connections, then: - Read about [isolation in SQLite](https://www.sqlite.org/isolation.html) - Learn about [locks and transactions](https://www.sqlite.org/lang_transaction.html) - Become a master of the [WAL mode](https://www.sqlite.org/wal.html) -- Prepare to setup a [busy handler](https://www.sqlite.org/c3ref/busy_handler.html) with [Configuration.busyMode](http://groue.github.io/GRDB.swift/docs/3.7/Structs/Configuration.html) +- Prepare to setup a [busy handler](https://www.sqlite.org/c3ref/busy_handler.html) with [Configuration.busyMode](http://groue.github.io/GRDB.swift/docs/4.0/Structs/Configuration.html) - [Ask questions](https://github.com/groue/GRDB.swift/issues) @@ -8352,7 +8409,7 @@ let sql = """ LEFT JOIN book ON book.authorId = author.id GROUP BY author.id """ -let authors = try Author.fetchAll(db, sql) +let authors = try Author.fetchAll(db, sql: sql) ``` In the example above, consider extending your Author with an extra bookCount property, or define and use a different type. @@ -8597,7 +8654,7 @@ Sample Code **Thanks** - [Pierlis](http://pierlis.com), where we write great software. -- [@bellebethcooper](https://github.com/bellebethcooper), [@bfad](https://github.com/bfad), [@cfilipov](https://github.com/cfilipov), [@Chiliec](https://github.com/Chiliec), [@darrenclark](https://github.com/darrenclark), [@davidkraus](https://github.com/davidkraus), [@fpillet](http://github.com/fpillet), [@gusrota](https://github.com/gusrota), [@hartbit](https://github.com/hartbit), [@kdubb](https://github.com/kdubb), [@kluufger](https://github.com/kluufger), [@KyleLeneau](https://github.com/KyleLeneau), [@Marus](https://github.com/Marus), [@pakko972](https://github.com/pakko972), [@peter-ss](https://github.com/peter-ss), [@pierlo](https://github.com/pierlo), [@pocketpixels](https://github.com/pocketpixels), [@schveiguy](https://github.com/schveiguy), [@SD10](https://github.com/SD10), [@sobri909](https://github.com/sobri909), [@sroddy](https://github.com/sroddy), [@swiftlyfalling](https://github.com/swiftlyfalling), [@valexa](https://github.com/valexa), and [@zmeyc](https://github.com/zmeyc) for their contributions, help, and feedback on GRDB. +- [@alextrob](https://github.com/alextrob), [@bellebethcooper](https://github.com/bellebethcooper), [@bfad](https://github.com/bfad), [@cfilipov](https://github.com/cfilipov), [@charlesmchen-signal](https://github.com/charlesmchen-signal), [@Chiliec](https://github.com/Chiliec), [@darrenclark](https://github.com/darrenclark), [@davidkraus](https://github.com/davidkraus), [@fpillet](http://github.com/fpillet), [@gusrota](https://github.com/gusrota), [@hartbit](https://github.com/hartbit), [@kdubb](https://github.com/kdubb), [@kluufger](https://github.com/kluufger), [@KyleLeneau](https://github.com/KyleLeneau), [@Marus](https://github.com/Marus), [@michaelkirk-signal](https://github.com/michaelkirk-signal), [@pakko972](https://github.com/pakko972), [@peter-ss](https://github.com/peter-ss), [@pierlo](https://github.com/pierlo), [@pocketpixels](https://github.com/pocketpixels), [@schveiguy](https://github.com/schveiguy), [@SD10](https://github.com/SD10), [@sobri909](https://github.com/sobri909), [@sroddy](https://github.com/sroddy), [@swiftlyfalling](https://github.com/swiftlyfalling), [@valexa](https://github.com/valexa), and [@zmeyc](https://github.com/zmeyc) for their contributions, help, and feedback on GRDB. - [@aymerick](https://github.com/aymerick) and [@kali](https://github.com/kali) because SQL. - [ccgus/fmdb](https://github.com/ccgus/fmdb) for its excellency. @@ -8636,6 +8693,7 @@ This chapter has been renamed [Beyond FetchableRecord]. [The userInfo Dictionary]: #the-userinfo-dictionary [JSON Columns]: #json-columns [FetchableRecord]: #fetchablerecord-protocol +[EncodableRecord]: #persistablerecord-protocol [PersistableRecord]: #persistablerecord-protocol [Record Comparison]: #record-comparison [Record Customization Options]: #record-customization-options @@ -8647,3 +8705,5 @@ This chapter has been renamed [Beyond FetchableRecord]. [DatabaseRegionConvertible]: #the-databaseregionconvertible-protocol [ValueObservation and DatabaseRegionObservation]: #valueobservation-and-databaseregionobservation [DatabaseRegion]: #databaseregion +[SQL Interpolation]: Documentation/SQLInterpolation.md +[custom SQLite build]: Documentation/CustomSQLiteBuilds.md diff --git a/SQLCipher/GRDBCipher-Bridging.h b/SQLCipher/GRDBCipher-Bridging.h deleted file mode 100644 index e69de29bb..000000000 diff --git a/SQLCipher/GRDBCipher.h b/SQLCipher/GRDBCipher.h deleted file mode 100644 index ef8d798b7..000000000 --- a/SQLCipher/GRDBCipher.h +++ /dev/null @@ -1,18 +0,0 @@ -@import Foundation; - -//! Project version number for GRDB. -FOUNDATION_EXPORT double GRDB_VersionNumber; - -//! Project version string for GRDB. -FOUNDATION_EXPORT const unsigned char GRDB_VersionString[]; - -#ifndef SQLITE_HAS_CODEC -#define SQLITE_HAS_CODEC -#endif - -#import -#ifdef COCOAPODS - #import -#else - #import -#endif diff --git a/SQLCipher/GRDBCipher.xcconfig b/SQLCipher/GRDBCipher.xcconfig deleted file mode 100644 index 981ab91d5..000000000 --- a/SQLCipher/GRDBCipher.xcconfig +++ /dev/null @@ -1,8 +0,0 @@ -#include "GRDBDeploymentTarget.xcconfig" -INFOPLIST_FILE = Support/Info.plist -PRODUCT_NAME = GRDBCipher -PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.$(PRODUCT_NAME:rfc1034identifier) -MODULEMAP_FILE = $(SRCROOT)/SQLCipher/module.modulemap -OTHER_CFLAGS = -DSQLITE_HAS_CODEC -OTHER_SWIFT_FLAGS = -D SQLITE_HAS_CODEC -D USING_BUILTIN_SQLITE -D GRDBCIPHER -D SQLITE_ENABLE_FTS5 -HEADER_SEARCH_PATHS = $(SRCROOT)/SQLCipher/src diff --git a/SQLCipher/GRDBDeploymentTarget.xcconfig b/SQLCipher/GRDBDeploymentTarget.xcconfig deleted file mode 100644 index 49665c9cc..000000000 --- a/SQLCipher/GRDBDeploymentTarget.xcconfig +++ /dev/null @@ -1,3 +0,0 @@ -IPHONEOS_DEPLOYMENT_TARGET = 8.0 -MACOSX_DEPLOYMENT_TARGET = 10.9 -WATCHOS_DEPLOYMENT_TARGET = 2.2 diff --git a/SQLCipher/README.md b/SQLCipher/README.md deleted file mode 100644 index 99be631f1..000000000 --- a/SQLCipher/README.md +++ /dev/null @@ -1,46 +0,0 @@ -General doc: https://www.zetetic.net/sqlcipher/ios-tutorial/ - -TODO: Look for "verification" in https://www.zetetic.net/sqlcipher/design/ - -Compilation options used of the stock SQLite shipped with Apple Operating systems (String.fetchAll(dbQueue, "PRAGMA compile_options")): - -- MacOSX SDK - - ENABLE_API_ARMOR - - ENABLE_FTS3 - - ENABLE_FTS3_PARENTHESIS - - ENABLE_LOCKING_STYLE=1 - - ENABLE_RTREE - - ENABLE_UPDATE_DELETE_LIMIT - - OMIT_AUTORESET - - OMIT_BUILTIN_TEST - - OMIT_LOAD_EXTENSION - - SYSTEM_MALLOC - - THREADSAFE=2 - -- iPhoneSimulator SDK - - ENABLE_API_ARMOR - - ENABLE_FTS3 - - ENABLE_FTS3_PARENTHESIS - - ENABLE_LOCKING_STYLE=1 - - ENABLE_RTREE - - ENABLE_UPDATE_DELETE_LIMIT - - MAX_MMAP_SIZE=0 - - OMIT_AUTORESET - - OMIT_BUILTIN_TEST - - OMIT_LOAD_EXTENSION - - SYSTEM_MALLOC - - THREADSAFE=2 - -- iPhoneOS SDK - - ENABLE_API_ARMOR - - ENABLE_FTS3 - - ENABLE_FTS3_PARENTHESIS - - ENABLE_LOCKING_STYLE=1 - - ENABLE_RTREE - - ENABLE_UPDATE_DELETE_LIMIT - - MAX_MMAP_SIZE=0 - - OMIT_AUTORESET - - OMIT_BUILTIN_TEST - - OMIT_LOAD_EXTENSION - - SYSTEM_MALLOC - - THREADSAFE=2 diff --git a/SQLCipher/module.modulemap b/SQLCipher/module.modulemap deleted file mode 100644 index f4d682804..000000000 --- a/SQLCipher/module.modulemap +++ /dev/null @@ -1,8 +0,0 @@ -framework module GRDBCipher { - umbrella header "GRDBCipher.h" - - export * - module * { export * } - - header "grdb_config.h" -} diff --git a/SQLCipher/src b/SQLCipher/src deleted file mode 160000 index e8720c0d0..000000000 --- a/SQLCipher/src +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e8720c0d00e82017469e11dd9b25fc8ca15c7236 diff --git a/SQLiteCustom/GRDBDeploymentTarget.xcconfig b/SQLiteCustom/GRDBDeploymentTarget.xcconfig index 49665c9cc..aa41852a7 100644 --- a/SQLiteCustom/GRDBDeploymentTarget.xcconfig +++ b/SQLiteCustom/GRDBDeploymentTarget.xcconfig @@ -1,3 +1,3 @@ -IPHONEOS_DEPLOYMENT_TARGET = 8.0 +IPHONEOS_DEPLOYMENT_TARGET = 9.0 MACOSX_DEPLOYMENT_TARGET = 10.9 WATCHOS_DEPLOYMENT_TARGET = 2.2 diff --git a/SQLiteCustom/src b/SQLiteCustom/src index 9d6566834..254086eb5 160000 --- a/SQLiteCustom/src +++ b/SQLiteCustom/src @@ -1 +1 @@ -Subproject commit 9d6566834cfe99c85ea8afb742081a4152c47842 +Subproject commit 254086eb5273637bf5267cc9858a795d0eeb88cb diff --git a/Support/GRDBDeploymentTarget.xcconfig b/Support/GRDBDeploymentTarget.xcconfig index 49665c9cc..aa41852a7 100644 --- a/Support/GRDBDeploymentTarget.xcconfig +++ b/Support/GRDBDeploymentTarget.xcconfig @@ -1,3 +1,3 @@ -IPHONEOS_DEPLOYMENT_TARGET = 8.0 +IPHONEOS_DEPLOYMENT_TARGET = 9.0 MACOSX_DEPLOYMENT_TARGET = 10.9 WATCHOS_DEPLOYMENT_TARGET = 2.2 diff --git a/Support/Info.plist b/Support/Info.plist index 767108022..75b0cb742 100644 --- a/Support/Info.plist +++ b/Support/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 3.7.0 + 4.0.0 CFBundleSignature ???? CFBundleVersion diff --git a/Support/grdb_config.h b/Support/grdb_config.h index 63d3d1d3d..641560fe6 100644 --- a/Support/grdb_config.h +++ b/Support/grdb_config.h @@ -8,9 +8,7 @@ #include #endif #else - #if defined(GRDBCIPHER) - #include - #elsif defined(GRDBCUSTOMSQLITE) + #if defined(GRDBCUSTOMSQLITE) #include #else #include diff --git a/TODO.md b/TODO.md index 521d04099..bff48778b 100644 --- a/TODO.md +++ b/TODO.md @@ -24,7 +24,6 @@ - [ ] Allow joining methods on DerivableRequest - [ ] DatabaseWriter.assertWriteAccess() - [ ] Configuration.crashOnError = true -- [ ] Remove associated record from PersistenceError.recordNotFound. It should be possible, in userland, to write a method that throws this error without having a fully constructed record. - [ ] Support for "INSERT INTO ... SELECT ...". For example: ```swift @@ -41,16 +40,21 @@ ``` - [ ] Consider renaming dbQueue.inDatabase, dbPool.writeWithoutTransaction -> dbQueue/Pool.exclusive - [ ] FetchedRecordsController diff algorithm: check https://github.com/RxSwiftCommunity/RxDataSources/issues/256 +- [ ] https://github.com/groue/GRDB.swift/issues/514 +- [ ] Look at the jazzy configuration of https://github.com/bignerdranch/Deferred +- [ ] FTS: prefix queries +- [ ] Test NOT TESTED methods +- [ ] Update RxGRDB: https://github.com/RxSwiftCommunity/RxGRDB/pull/51 +- [ ] Update [GRDBObjc](https://github.com/groue/GRDBObjc) + +GRDB 4.0 + +- [ ] Review @inlinable stuff Swift 4.2 -- [ ] https://github.com/apple/swift-evolution/blob/master/proposals/0210-key-path-offset.md - [ ] https://github.com/apple/swift-evolution/blob/master/proposals/0208-package-manager-system-library-targets.md -- [ ] https://github.com/apple/swift-evolution/blob/master/proposals/0207-containsOnly.md -- [ ] https://github.com/apple/swift-evolution/blob/master/proposals/0206-hashable-enhancements.md -- [ ] https://github.com/apple/swift-evolution/blob/master/proposals/0202-random-unification.md - [ ] https://github.com/apple/swift-evolution/blob/master/proposals/0201-package-manager-local-dependencies.md -- [ ] https://github.com/apple/swift-evolution/blob/master/proposals/0193-cross-module-inlining-and-specialization.md Not sure diff --git a/Tests/Carthage/GRDBiOS/iOS.xcodeproj/project.pbxproj b/Tests/Carthage/GRDBiOS/iOS.xcodeproj/project.pbxproj deleted file mode 100644 index 6649a87c8..000000000 --- a/Tests/Carthage/GRDBiOS/iOS.xcodeproj/project.pbxproj +++ /dev/null @@ -1,363 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 277479482141D92B00FCD661 /* PlayerEditionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 277479452141D92B00FCD661 /* PlayerEditionViewController.swift */; }; - 277479492141D92B00FCD661 /* PlayersViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 277479462141D92B00FCD661 /* PlayersViewController.swift */; }; - 2774794A2141D92B00FCD661 /* Player.swift in Sources */ = {isa = PBXBuildFile; fileRef = 277479472141D92B00FCD661 /* Player.swift */; }; - 5644E4041C1072A30090716E /* GRDB.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5644E4031C1072A30090716E /* GRDB.framework */; }; - 5644E4061C1072CA0090716E /* GRDB.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 5644E4031C1072A30090716E /* GRDB.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 567374431B4D46600089DE44 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 567374411B4D46600089DE44 /* Main.storyboard */; }; - 567374451B4D46600089DE44 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 567374441B4D46600089DE44 /* Assets.xcassets */; }; - 567374481B4D46600089DE44 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 567374461B4D46600089DE44 /* LaunchScreen.storyboard */; }; - 56AEC9D91CAA985700452D96 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AEC9D21CAA985700452D96 /* AppDelegate.swift */; }; - 56AEC9DA1CAA985700452D96 /* AppDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AEC9D31CAA985700452D96 /* AppDatabase.swift */; }; -/* End PBXBuildFile section */ - -/* Begin PBXCopyFilesBuildPhase section */ - 5644E4071C1072CA0090716E /* Embed Frameworks */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = ""; - dstSubfolderSpec = 10; - files = ( - 5644E4061C1072CA0090716E /* GRDB.framework in Embed Frameworks */, - ); - name = "Embed Frameworks"; - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXCopyFilesBuildPhase section */ - -/* Begin PBXFileReference section */ - 277479452141D92B00FCD661 /* PlayerEditionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlayerEditionViewController.swift; sourceTree = ""; }; - 277479462141D92B00FCD661 /* PlayersViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlayersViewController.swift; sourceTree = ""; }; - 277479472141D92B00FCD661 /* Player.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Player.swift; sourceTree = ""; }; - 5644E4031C1072A30090716E /* GRDB.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GRDB.framework; path = ../../../Carthage/Build/iOS/GRDB.framework; sourceTree = ""; }; - 567374381B4D46600089DE44 /* iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 567374421B4D46600089DE44 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; - 567374441B4D46600089DE44 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 567374471B4D46600089DE44 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; - 567374491B4D46600089DE44 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 56AEC9D21CAA985700452D96 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; - 56AEC9D31CAA985700452D96 /* AppDatabase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDatabase.swift; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 567374351B4D46600089DE44 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 5644E4041C1072A30090716E /* GRDB.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 5673742F1B4D46600089DE44 = { - isa = PBXGroup; - children = ( - 5644E4031C1072A30090716E /* GRDB.framework */, - 5673743A1B4D46600089DE44 /* GRDBDemoiOS */, - 567374391B4D46600089DE44 /* Products */, - ); - sourceTree = ""; - }; - 567374391B4D46600089DE44 /* Products */ = { - isa = PBXGroup; - children = ( - 567374381B4D46600089DE44 /* iOS.app */, - ); - name = Products; - sourceTree = ""; - }; - 5673743A1B4D46600089DE44 /* GRDBDemoiOS */ = { - isa = PBXGroup; - children = ( - 56AEC9D21CAA985700452D96 /* AppDelegate.swift */, - 56AEC9D31CAA985700452D96 /* AppDatabase.swift */, - 277479472141D92B00FCD661 /* Player.swift */, - 277479452141D92B00FCD661 /* PlayerEditionViewController.swift */, - 277479462141D92B00FCD661 /* PlayersViewController.swift */, - 567374441B4D46600089DE44 /* Assets.xcassets */, - 567374491B4D46600089DE44 /* Info.plist */, - 567374461B4D46600089DE44 /* LaunchScreen.storyboard */, - 567374411B4D46600089DE44 /* Main.storyboard */, - ); - name = GRDBDemoiOS; - path = ../../../DemoApps/GRDBDemoiOS/GRDBDemoiOS; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 567374371B4D46600089DE44 /* iOS */ = { - isa = PBXNativeTarget; - buildConfigurationList = 567374621B4D46600089DE44 /* Build configuration list for PBXNativeTarget "iOS" */; - buildPhases = ( - 567374341B4D46600089DE44 /* Sources */, - 567374351B4D46600089DE44 /* Frameworks */, - 567374361B4D46600089DE44 /* Resources */, - 567374741B4D7A3B0089DE44 /* ShellScript */, - 5644E4071C1072CA0090716E /* Embed Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = iOS; - productName = iOS; - productReference = 567374381B4D46600089DE44 /* iOS.app */; - productType = "com.apple.product-type.application"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 567374301B4D46600089DE44 /* Project object */ = { - isa = PBXProject; - attributes = { - LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0700; - ORGANIZATIONNAME = "Gwendal Roué"; - TargetAttributes = { - 567374371B4D46600089DE44 = { - CreatedOnToolsVersion = 7.0; - DevelopmentTeam = AMD8W895CT; - }; - }; - }; - buildConfigurationList = 567374331B4D46600089DE44 /* Build configuration list for PBXProject "iOS" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = 5673742F1B4D46600089DE44; - productRefGroup = 567374391B4D46600089DE44 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 567374371B4D46600089DE44 /* iOS */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 567374361B4D46600089DE44 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 567374481B4D46600089DE44 /* LaunchScreen.storyboard in Resources */, - 567374451B4D46600089DE44 /* Assets.xcassets in Resources */, - 567374431B4D46600089DE44 /* Main.storyboard in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXShellScriptBuildPhase section */ - 567374741B4D7A3B0089DE44 /* ShellScript */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "$(SRCROOT)/../../../Carthage/Build/iOS/GRDB.framework", - ); - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "/usr/local/bin/carthage copy-frameworks"; - }; -/* End PBXShellScriptBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 567374341B4D46600089DE44 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 277479482141D92B00FCD661 /* PlayerEditionViewController.swift in Sources */, - 56AEC9DA1CAA985700452D96 /* AppDatabase.swift in Sources */, - 277479492141D92B00FCD661 /* PlayersViewController.swift in Sources */, - 2774794A2141D92B00FCD661 /* Player.swift in Sources */, - 56AEC9D91CAA985700452D96 /* AppDelegate.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXVariantGroup section */ - 567374411B4D46600089DE44 /* Main.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 567374421B4D46600089DE44 /* Base */, - ); - name = Main.storyboard; - sourceTree = ""; - }; - 567374461B4D46600089DE44 /* LaunchScreen.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 567374471B4D46600089DE44 /* Base */, - ); - name = LaunchScreen.storyboard; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - -/* Begin XCBuildConfiguration section */ - 567374601B4D46600089DE44 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; - }; - name = Debug; - }; - 567374611B4D46600089DE44 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = iphoneos; - SWIFT_VERSION = 4.2; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; - 567374631B4D46600089DE44 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CLANG_ENABLE_MODULES = YES; - CODE_SIGN_IDENTITY = "iPhone Developer"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(SRCROOT)/../../../Carthage/Build/iOS", - ); - INFOPLIST_FILE = ../../../DemoApps/GRDBDemoiOS/GRDBDemoiOS/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = GRDB.CarthageTest; - PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE = ""; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - }; - name = Debug; - }; - 567374641B4D46600089DE44 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CLANG_ENABLE_MODULES = YES; - CODE_SIGN_IDENTITY = "iPhone Developer"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(SRCROOT)/../../../Carthage/Build/iOS", - ); - INFOPLIST_FILE = ../../../DemoApps/GRDBDemoiOS/GRDBDemoiOS/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = GRDB.CarthageTest; - PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE = ""; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 567374331B4D46600089DE44 /* Build configuration list for PBXProject "iOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 567374601B4D46600089DE44 /* Debug */, - 567374611B4D46600089DE44 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 567374621B4D46600089DE44 /* Build configuration list for PBXNativeTarget "iOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 567374631B4D46600089DE44 /* Debug */, - 567374641B4D46600089DE44 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 567374301B4D46600089DE44 /* Project object */; -} diff --git a/Tests/Carthage/GRDBiOS/iOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Tests/Carthage/GRDBiOS/iOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 92a930669..000000000 --- a/Tests/Carthage/GRDBiOS/iOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS.xcodeproj/project.pbxproj b/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS.xcodeproj/project.pbxproj deleted file mode 100644 index 2c37b257b..000000000 --- a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS.xcodeproj/project.pbxproj +++ /dev/null @@ -1,400 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 50; - objects = { - -/* Begin PBXBuildFile section */ - 56269776211036C10066800A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56269775211036C10066800A /* AppDelegate.swift */; }; - 56269778211036C30066800A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 56269777211036C30066800A /* Assets.xcassets */; }; - 5626977B211036C30066800A /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 56269779211036C30066800A /* MainMenu.xib */; }; - A32FEE3772DAB0501EE4369C /* Pods_GRDBCipherMacOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7FC038F3B5C9412A5DFDB72 /* Pods_GRDBCipherMacOS.framework */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - 2AB57EA4305B77469C9A4267 /* Pods-GRDBCipherMacOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GRDBCipherMacOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-GRDBCipherMacOS/Pods-GRDBCipherMacOS.release.xcconfig"; sourceTree = ""; }; - 56269772211036C10066800A /* GRDBCipherMacOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GRDBCipherMacOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 56269775211036C10066800A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; - 56269777211036C30066800A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 5626977A211036C30066800A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; - 5626977C211036C30066800A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 5626977D211036C30066800A /* GRDBCipherMacOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GRDBCipherMacOS.entitlements; sourceTree = ""; }; - A3F8791E6F512575865AC37C /* Pods-GRDBCipherMacOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GRDBCipherMacOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-GRDBCipherMacOS/Pods-GRDBCipherMacOS.debug.xcconfig"; sourceTree = ""; }; - E7FC038F3B5C9412A5DFDB72 /* Pods_GRDBCipherMacOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_GRDBCipherMacOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 5626976F211036C10066800A /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - A32FEE3772DAB0501EE4369C /* Pods_GRDBCipherMacOS.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 37312FDE6F3590F7D4DA75E3 /* Pods */ = { - isa = PBXGroup; - children = ( - A3F8791E6F512575865AC37C /* Pods-GRDBCipherMacOS.debug.xcconfig */, - 2AB57EA4305B77469C9A4267 /* Pods-GRDBCipherMacOS.release.xcconfig */, - ); - name = Pods; - sourceTree = ""; - }; - 56269769211036C10066800A = { - isa = PBXGroup; - children = ( - 56269774211036C10066800A /* GRDBCipherMacOS */, - 56269773211036C10066800A /* Products */, - 37312FDE6F3590F7D4DA75E3 /* Pods */, - 86105FE752FB45E05465BA44 /* Frameworks */, - ); - sourceTree = ""; - }; - 56269773211036C10066800A /* Products */ = { - isa = PBXGroup; - children = ( - 56269772211036C10066800A /* GRDBCipherMacOS.app */, - ); - name = Products; - sourceTree = ""; - }; - 56269774211036C10066800A /* GRDBCipherMacOS */ = { - isa = PBXGroup; - children = ( - 56269775211036C10066800A /* AppDelegate.swift */, - 56269777211036C30066800A /* Assets.xcassets */, - 56269779211036C30066800A /* MainMenu.xib */, - 5626977C211036C30066800A /* Info.plist */, - 5626977D211036C30066800A /* GRDBCipherMacOS.entitlements */, - ); - path = GRDBCipherMacOS; - sourceTree = ""; - }; - 86105FE752FB45E05465BA44 /* Frameworks */ = { - isa = PBXGroup; - children = ( - E7FC038F3B5C9412A5DFDB72 /* Pods_GRDBCipherMacOS.framework */, - ); - name = Frameworks; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 56269771211036C10066800A /* GRDBCipherMacOS */ = { - isa = PBXNativeTarget; - buildConfigurationList = 56269780211036C30066800A /* Build configuration list for PBXNativeTarget "GRDBCipherMacOS" */; - buildPhases = ( - 7B68FB6434FA20203C21B0A7 /* [CP] Check Pods Manifest.lock */, - 5626976E211036C10066800A /* Sources */, - 5626976F211036C10066800A /* Frameworks */, - 56269770211036C10066800A /* Resources */, - D151C0BABC336CE195E1761D /* [CP] Embed Pods Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = GRDBCipherMacOS; - productName = GRDBCipherMacOS; - productReference = 56269772211036C10066800A /* GRDBCipherMacOS.app */; - productType = "com.apple.product-type.application"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 5626976A211036C10066800A /* Project object */ = { - isa = PBXProject; - attributes = { - LastSwiftUpdateCheck = 0940; - LastUpgradeCheck = 0940; - ORGANIZATIONNAME = "Gwendal Roué"; - TargetAttributes = { - 56269771211036C10066800A = { - CreatedOnToolsVersion = 9.4.1; - SystemCapabilities = { - com.apple.Sandbox = { - enabled = 0; - }; - }; - }; - }; - }; - buildConfigurationList = 5626976D211036C10066800A /* Build configuration list for PBXProject "GRDBCipherMacOS" */; - compatibilityVersion = "Xcode 9.3"; - developmentRegion = en; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = 56269769211036C10066800A; - productRefGroup = 56269773211036C10066800A /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 56269771211036C10066800A /* GRDBCipherMacOS */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 56269770211036C10066800A /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 56269778211036C30066800A /* Assets.xcassets in Resources */, - 5626977B211036C30066800A /* MainMenu.xib in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXShellScriptBuildPhase section */ - 7B68FB6434FA20203C21B0A7 /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-GRDBCipherMacOS-checkManifestLockResult.txt", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; - }; - D151C0BABC336CE195E1761D /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-GRDBCipherMacOS/Pods-GRDBCipherMacOS-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/GRDBCipher/GRDBCipher.framework", - "${BUILT_PRODUCTS_DIR}/SQLCipher/SQLCipher.framework", - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GRDBCipher.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SQLCipher.framework", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-GRDBCipherMacOS/Pods-GRDBCipherMacOS-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; -/* End PBXShellScriptBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 5626976E211036C10066800A /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 56269776211036C10066800A /* AppDelegate.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXVariantGroup section */ - 56269779211036C30066800A /* MainMenu.xib */ = { - isa = PBXVariantGroup; - children = ( - 5626977A211036C30066800A /* Base */, - ); - name = MainMenu.xib; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - -/* Begin XCBuildConfiguration section */ - 5626977E211036C30066800A /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "Mac Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.13; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = macosx; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - }; - name = Debug; - }; - 5626977F211036C30066800A /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "Mac Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.13; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = macosx; - SWIFT_COMPILATION_MODE = wholemodule; - SWIFT_OPTIMIZATION_LEVEL = "-O"; - }; - name = Release; - }; - 56269781211036C30066800A /* Debug */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = A3F8791E6F512575865AC37C /* Pods-GRDBCipherMacOS.debug.xcconfig */; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_STYLE = Manual; - COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = ""; - INFOPLIST_FILE = GRDBCipherMacOS/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBCipherMacOS; - PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE_SPECIFIER = ""; - SWIFT_VERSION = 4.2; - }; - name = Debug; - }; - 56269782211036C30066800A /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 2AB57EA4305B77469C9A4267 /* Pods-GRDBCipherMacOS.release.xcconfig */; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_STYLE = Manual; - COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = ""; - INFOPLIST_FILE = GRDBCipherMacOS/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBCipherMacOS; - PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE_SPECIFIER = ""; - SWIFT_VERSION = 4.2; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 5626976D211036C10066800A /* Build configuration list for PBXProject "GRDBCipherMacOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 5626977E211036C30066800A /* Debug */, - 5626977F211036C30066800A /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 56269780211036C30066800A /* Build configuration list for PBXNativeTarget "GRDBCipherMacOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 56269781211036C30066800A /* Debug */, - 56269782211036C30066800A /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 5626976A211036C10066800A /* Project object */; -} diff --git a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 946b0d62f..000000000 --- a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/AppDelegate.swift b/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/AppDelegate.swift deleted file mode 100644 index f8f8ff94c..000000000 --- a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/AppDelegate.swift +++ /dev/null @@ -1,18 +0,0 @@ -import Cocoa -import GRDBCipher - -@NSApplicationMain -class AppDelegate: NSObject, NSApplicationDelegate { - @IBOutlet weak var window: NSWindow! - - func applicationDidFinishLaunching(_ aNotification: Notification) { - let dbQueue = DatabaseQueue() - - // Make sure FTS5 is enabled - try! dbQueue.write { db in - try db.create(virtualTable: "document", using: FTS5()) { t in - t.column("content") - } - } - } -} diff --git a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/Assets.xcassets/AppIcon.appiconset/Contents.json b/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/Assets.xcassets/AppIcon.appiconset/Contents.json deleted file mode 100644 index 2db2b1c7c..000000000 --- a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/Assets.xcassets/AppIcon.appiconset/Contents.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "images" : [ - { - "idiom" : "mac", - "size" : "16x16", - "scale" : "1x" - }, - { - "idiom" : "mac", - "size" : "16x16", - "scale" : "2x" - }, - { - "idiom" : "mac", - "size" : "32x32", - "scale" : "1x" - }, - { - "idiom" : "mac", - "size" : "32x32", - "scale" : "2x" - }, - { - "idiom" : "mac", - "size" : "128x128", - "scale" : "1x" - }, - { - "idiom" : "mac", - "size" : "128x128", - "scale" : "2x" - }, - { - "idiom" : "mac", - "size" : "256x256", - "scale" : "1x" - }, - { - "idiom" : "mac", - "size" : "256x256", - "scale" : "2x" - }, - { - "idiom" : "mac", - "size" : "512x512", - "scale" : "1x" - }, - { - "idiom" : "mac", - "size" : "512x512", - "scale" : "2x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/Assets.xcassets/Contents.json b/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/Assets.xcassets/Contents.json deleted file mode 100644 index da4a164c9..000000000 --- a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/Assets.xcassets/Contents.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/Base.lproj/MainMenu.xib b/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/Base.lproj/MainMenu.xib deleted file mode 100644 index 1d819d508..000000000 --- a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/Base.lproj/MainMenu.xib +++ /dev/null @@ -1,692 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Tests/CocoaPods/GRDBCipherMacOS/Podfile b/Tests/CocoaPods/GRDBCipherMacOS/Podfile deleted file mode 100644 index e13cee895..000000000 --- a/Tests/CocoaPods/GRDBCipherMacOS/Podfile +++ /dev/null @@ -1,4 +0,0 @@ -target 'GRDBCipherMacOS' -platform :macos, '10.13' -use_frameworks! -pod 'GRDBCipher', :path => '../../..' diff --git a/Tests/CocoaPods/GRDBiOS/Podfile.lock b/Tests/CocoaPods/GRDBiOS/Podfile.lock new file mode 100644 index 000000000..1ecf66947 --- /dev/null +++ b/Tests/CocoaPods/GRDBiOS/Podfile.lock @@ -0,0 +1,18 @@ +PODS: + - GRDB.swift (3.7.0): + - GRDB.swift/standard (= 3.7.0) + - GRDB.swift/standard (3.7.0) + +DEPENDENCIES: + - GRDB.swift (from `../../..`) + +EXTERNAL SOURCES: + GRDB.swift: + :path: "../../.." + +SPEC CHECKSUMS: + GRDB.swift: 71ab04a6e727e34c034513c4d15901ea35eb1f0d + +PODFILE CHECKSUM: d66514ed217e119cf7e4e06fcd5d17b8c57b1f0b + +COCOAPODS: 1.6.1 diff --git a/Tests/CocoaPods/GRDBiOS/iOS.xcworkspace/contents.xcworkspacedata b/Tests/CocoaPods/GRDBiOS/iOS.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..7f03e784a --- /dev/null +++ b/Tests/CocoaPods/GRDBiOS/iOS.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/project.pbxproj b/Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/project.pbxproj new file mode 100644 index 000000000..d8d456f31 --- /dev/null +++ b/Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/project.pbxproj @@ -0,0 +1,1761 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 560432A9228F1752009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560432A8228F1752009D3FE2 /* AssociationPrefetchingObservationTests.swift */; }; + 560432AA228F1752009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560432A8228F1752009D3FE2 /* AssociationPrefetchingObservationTests.swift */; }; + 56057C5F2291B8E400A7CB10 /* AssociationHasManyRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56057C5E2291B8E400A7CB10 /* AssociationHasManyRowScopeTests.swift */; }; + 56057C602291B8E400A7CB10 /* AssociationHasManyRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56057C5E2291B8E400A7CB10 /* AssociationHasManyRowScopeTests.swift */; }; + 56057C682291D0AC00A7CB10 /* AssociationHasManyThroughRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56057C672291D0AB00A7CB10 /* AssociationHasManyThroughRowScopeTests.swift */; }; + 56057C692291D0AC00A7CB10 /* AssociationHasManyThroughRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56057C672291D0AB00A7CB10 /* AssociationHasManyThroughRowScopeTests.swift */; }; + 560714F0227DD1810091BB10 /* AssociationPrefetchingSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560714EF227DD1810091BB10 /* AssociationPrefetchingSQLTests.swift */; }; + 560714F1227DD1810091BB10 /* AssociationPrefetchingSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560714EF227DD1810091BB10 /* AssociationPrefetchingSQLTests.swift */; }; + 564A1FDE226B89E1001F64F1 /* MutablePersistableRecordDeleteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F27226B89CE001F64F1 /* MutablePersistableRecordDeleteTests.swift */; }; + 564A1FDF226B89E1001F64F1 /* AssociationHasOneThroughRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F28226B89CE001F64F1 /* AssociationHasOneThroughRowScopeTests.swift */; }; + 564A1FE0226B89E1001F64F1 /* RowCopiedFromStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F29226B89CF001F64F1 /* RowCopiedFromStatementTests.swift */; }; + 564A1FE1226B89E1001F64F1 /* SelectStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2A226B89CF001F64F1 /* SelectStatementTests.swift */; }; + 564A1FE2226B89E1001F64F1 /* DatabaseQueueBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2B226B89CF001F64F1 /* DatabaseQueueBackupTests.swift */; }; + 564A1FE3226B89E1001F64F1 /* DatabaseValueConvertibleEncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2C226B89CF001F64F1 /* DatabaseValueConvertibleEncodableTests.swift */; }; + 564A1FE4226B89E1001F64F1 /* RecordPrimaryKeyMultipleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2D226B89CF001F64F1 /* RecordPrimaryKeyMultipleTests.swift */; }; + 564A1FE5226B89E1001F64F1 /* NumericOverflowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2E226B89CF001F64F1 /* NumericOverflowTests.swift */; }; + 564A1FE6226B89E1001F64F1 /* DatabaseQueueInMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2F226B89CF001F64F1 /* DatabaseQueueInMemoryTests.swift */; }; + 564A1FE7226B89E1001F64F1 /* FoundationURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F30226B89CF001F64F1 /* FoundationURLTests.swift */; }; + 564A1FE8226B89E1001F64F1 /* DatabaseAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F31226B89CF001F64F1 /* DatabaseAggregateTests.swift */; }; + 564A1FE9226B89E1001F64F1 /* MutablePersistableRecordEncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F32226B89CF001F64F1 /* MutablePersistableRecordEncodableTests.swift */; }; + 564A1FEA226B89E1001F64F1 /* AssociationChainRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F33226B89CF001F64F1 /* AssociationChainRowScopesTests.swift */; }; + 564A1FEB226B89E1001F64F1 /* FoundationNSUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F34226B89CF001F64F1 /* FoundationNSUUIDTests.swift */; }; + 564A1FEC226B89E1001F64F1 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F35226B89CF001F64F1 /* AssociationBelongsToDecodableRecordTests.swift */; }; + 564A1FED226B89E1001F64F1 /* CompilationProtocolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F36226B89CF001F64F1 /* CompilationProtocolTests.swift */; }; + 564A1FEE226B89E1001F64F1 /* DatabaseFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F37226B89CF001F64F1 /* DatabaseFunctionTests.swift */; }; + 564A1FEF226B89E1001F64F1 /* FetchedRecordsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F38226B89CF001F64F1 /* FetchedRecordsControllerTests.swift */; }; + 564A1FF0226B89E1001F64F1 /* AssociationHasOneThroughDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F39226B89CF001F64F1 /* AssociationHasOneThroughDecodableRecordTests.swift */; }; + 564A1FF1226B89E1001F64F1 /* DatabaseValueConvertibleSubclassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3A226B89D0001F64F1 /* DatabaseValueConvertibleSubclassTests.swift */; }; + 564A1FF2226B89E1001F64F1 /* RecordPersistenceConflictPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3B226B89D0001F64F1 /* RecordPersistenceConflictPolicy.swift */; }; + 564A1FF3226B89E1001F64F1 /* TruncateOptimizationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3C226B89D0001F64F1 /* TruncateOptimizationTests.swift */; }; + 564A1FF4226B89E1001F64F1 /* DatabasePoolCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3D226B89D0001F64F1 /* DatabasePoolCollationTests.swift */; }; + 564A1FF5226B89E1001F64F1 /* AssociationRowScopeSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3E226B89D0001F64F1 /* AssociationRowScopeSearchTests.swift */; }; + 564A1FF6226B89E1001F64F1 /* DatabaseSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3F226B89D0001F64F1 /* DatabaseSnapshotTests.swift */; }; + 564A1FF7226B89E1001F64F1 /* DatabaseValueConvertibleDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F40226B89D0001F64F1 /* DatabaseValueConvertibleDecodableTests.swift */; }; + 564A1FF8226B89E1001F64F1 /* QueryInterfaceExpressionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F41226B89D0001F64F1 /* QueryInterfaceExpressionsTests.swift */; }; + 564A1FF9226B89E1001F64F1 /* SQLRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F42226B89D0001F64F1 /* SQLRequestTests.swift */; }; + 564A1FFA226B89E1001F64F1 /* FTS5WrapperTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F43226B89D0001F64F1 /* FTS5WrapperTokenizerTests.swift */; }; + 564A1FFB226B89E1001F64F1 /* ValueObservationRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F44226B89D0001F64F1 /* ValueObservationRecordTests.swift */; }; + 564A1FFC226B89E1001F64F1 /* DatabaseValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F45226B89D0001F64F1 /* DatabaseValueTests.swift */; }; + 564A1FFD226B89E1001F64F1 /* PrefixWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F46226B89D1001F64F1 /* PrefixWhileCursorTests.swift */; }; + 564A1FFE226B89E1001F64F1 /* FilterCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F47226B89D1001F64F1 /* FilterCursorTests.swift */; }; + 564A1FFF226B89E1001F64F1 /* ValueObservationSchedulingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F48226B89D1001F64F1 /* ValueObservationSchedulingTests.swift */; }; + 564A2000226B89E1001F64F1 /* PrefixCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F49226B89D1001F64F1 /* PrefixCursorTests.swift */; }; + 564A2001226B89E1001F64F1 /* RecordPrimaryKeyNoneTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4A226B89D1001F64F1 /* RecordPrimaryKeyNoneTests.swift */; }; + 564A2002226B89E1001F64F1 /* DerivableRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4B226B89D1001F64F1 /* DerivableRequestTests.swift */; }; + 564A2003226B89E1001F64F1 /* DatabaseValueConvertibleFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4C226B89D1001F64F1 /* DatabaseValueConvertibleFetchTests.swift */; }; + 564A2004226B89E1001F64F1 /* AssociationChainSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4D226B89D2001F64F1 /* AssociationChainSQLTests.swift */; }; + 564A2005226B89E1001F64F1 /* SQLExpressionLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4E226B89D2001F64F1 /* SQLExpressionLiteralTests.swift */; }; + 564A2006226B89E1001F64F1 /* SQLInterpolationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4F226B89D2001F64F1 /* SQLInterpolationTests.swift */; }; + 564A2007226B89E1001F64F1 /* FoundationDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F50226B89D2001F64F1 /* FoundationDataTests.swift */; }; + 564A2008226B89E1001F64F1 /* RecordInitializersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F51226B89D2001F64F1 /* RecordInitializersTests.swift */; }; + 564A2009226B89E1001F64F1 /* AssociationHasOneThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F52226B89D2001F64F1 /* AssociationHasOneThroughSQLTests.swift */; }; + 564A200A226B89E1001F64F1 /* DatabaseCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F53226B89D2001F64F1 /* DatabaseCollationTests.swift */; }; + 564A200B226B89E1001F64F1 /* DatabaseDateEncodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F54226B89D2001F64F1 /* DatabaseDateEncodingStrategyTests.swift */; }; + 564A200C226B89E1001F64F1 /* DatabaseRegionObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F55226B89D2001F64F1 /* DatabaseRegionObservationTests.swift */; }; + 564A200D226B89E1001F64F1 /* RowFromDictionaryLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F56226B89D2001F64F1 /* RowFromDictionaryLiteralTests.swift */; }; + 564A200E226B89E1001F64F1 /* RowFromStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F57226B89D3001F64F1 /* RowFromStatementTests.swift */; }; + 564A200F226B89E1001F64F1 /* StatementArguments+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F58226B89D3001F64F1 /* StatementArguments+FoundationTests.swift */; }; + 564A2010226B89E1001F64F1 /* ValueObservationMapTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F59226B89D3001F64F1 /* ValueObservationMapTests.swift */; }; + 564A2011226B89E1001F64F1 /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5A226B89D3001F64F1 /* FetchRequestTests.swift */; }; + 564A2012226B89E1001F64F1 /* TransactionObserverSavepointsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5B226B89D3001F64F1 /* TransactionObserverSavepointsTests.swift */; }; + 564A2013226B89E1001F64F1 /* DatabaseLogErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5C226B89D3001F64F1 /* DatabaseLogErrorTests.swift */; }; + 564A2014226B89E1001F64F1 /* RecordSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5D226B89D3001F64F1 /* RecordSubClassTests.swift */; }; + 564A2015226B89E1001F64F1 /* EncryptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5E226B89D3001F64F1 /* EncryptionTests.swift */; }; + 564A2016226B89E1001F64F1 /* QueryInterfacePromiseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5F226B89D3001F64F1 /* QueryInterfacePromiseTests.swift */; }; + 564A2017226B89E1001F64F1 /* AssociationAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F60226B89D4001F64F1 /* AssociationAggregateTests.swift */; }; + 564A2018226B89E1001F64F1 /* ColumnExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F61226B89D4001F64F1 /* ColumnExpressionTests.swift */; }; + 564A2019226B89E1001F64F1 /* DatabasePoolReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F62226B89D4001F64F1 /* DatabasePoolReleaseMemoryTests.swift */; }; + 564A201A226B89E1001F64F1 /* FTS4TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F63226B89D5001F64F1 /* FTS4TableBuilderTests.swift */; }; + 564A201B226B89E1001F64F1 /* TableDefinitionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F64226B89D5001F64F1 /* TableDefinitionTests.swift */; }; + 564A201C226B89E1001F64F1 /* DatabaseErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F65226B89D5001F64F1 /* DatabaseErrorTests.swift */; }; + 564A201D226B89E1001F64F1 /* FTS3RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F66226B89D5001F64F1 /* FTS3RecordTests.swift */; }; + 564A201E226B89E1001F64F1 /* DatabaseCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F67226B89D5001F64F1 /* DatabaseCursorTests.swift */; }; + 564A201F226B89E1001F64F1 /* DatabaseQueueReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F68226B89D5001F64F1 /* DatabaseQueueReleaseMemoryTests.swift */; }; + 564A2020226B89E1001F64F1 /* DatabaseRegionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F69226B89D5001F64F1 /* DatabaseRegionTests.swift */; }; + 564A2021226B89E1001F64F1 /* DatabasePoolBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6A226B89D5001F64F1 /* DatabasePoolBackupTests.swift */; }; + 564A2022226B89E1001F64F1 /* CursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6B226B89D5001F64F1 /* CursorTests.swift */; }; + 564A2023226B89E1001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6C226B89D5001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift */; }; + 564A2024226B89E1001F64F1 /* DropWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6D226B89D5001F64F1 /* DropWhileCursorTests.swift */; }; + 564A2025226B89E1001F64F1 /* QueryInterfaceExtensibilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6E226B89D6001F64F1 /* QueryInterfaceExtensibilityTests.swift */; }; + 564A2026226B89E1001F64F1 /* Betty.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = 564A1F6F226B89D6001F64F1 /* Betty.jpeg */; }; + 564A2027226B89E1001F64F1 /* AssociationParallelDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F70226B89D6001F64F1 /* AssociationParallelDecodableRecordTests.swift */; }; + 564A2028226B89E1001F64F1 /* FoundationNSNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F71226B89D6001F64F1 /* FoundationNSNumberTests.swift */; }; + 564A2029226B89E1001F64F1 /* FTS3TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F72226B89D6001F64F1 /* FTS3TableBuilderTests.swift */; }; + 564A202A226B89E1001F64F1 /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F73226B89D6001F64F1 /* AssociationHasOneThroughSQLDerivationTests.swift */; }; + 564A202B226B89E1001F64F1 /* CompilationSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F74226B89D6001F64F1 /* CompilationSubClassTests.swift */; }; + 564A202C226B89E1001F64F1 /* RecordEditedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F75226B89D6001F64F1 /* RecordEditedTests.swift */; }; + 564A202D226B89E1001F64F1 /* Record+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F76226B89D6001F64F1 /* Record+QueryInterfaceRequestTests.swift */; }; + 564A202E226B89E1001F64F1 /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F77226B89D6001F64F1 /* RecordMinimalPrimaryKeyRowIDTests.swift */; }; + 564A202F226B89E1001F64F1 /* DatabasePoolSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F78226B89D6001F64F1 /* DatabasePoolSchemaCacheTests.swift */; }; + 564A2030226B89E1001F64F1 /* DatabaseSavepointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F79226B89D7001F64F1 /* DatabaseSavepointTests.swift */; }; + 564A2031226B89E1001F64F1 /* RowFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7A226B89D7001F64F1 /* RowFetchTests.swift */; }; + 564A2032226B89E1001F64F1 /* AssociationBelongsToFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7B226B89D7001F64F1 /* AssociationBelongsToFetchableRecordTests.swift */; }; + 564A2033226B89E1001F64F1 /* AssociationHasManySQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7C226B89D7001F64F1 /* AssociationHasManySQLTests.swift */; }; + 564A2034226B89E1001F64F1 /* FoundationNSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7D226B89D7001F64F1 /* FoundationNSDateTests.swift */; }; + 564A2035226B89E1001F64F1 /* Row+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7E226B89D7001F64F1 /* Row+FoundationTests.swift */; }; + 564A2036226B89E1001F64F1 /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7F226B89D7001F64F1 /* SchedulingWatchdogTests.swift */; }; + 564A2037226B89E1001F64F1 /* AssociationBelongsToSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F80226B89D7001F64F1 /* AssociationBelongsToSQLDerivationTests.swift */; }; + 564A2038226B89E1001F64F1 /* RowFromDictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F81226B89D7001F64F1 /* RowFromDictionaryTests.swift */; }; + 564A2039226B89E1001F64F1 /* DatabasePoolReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F82226B89D7001F64F1 /* DatabasePoolReadOnlyTests.swift */; }; + 564A203A226B89E1001F64F1 /* DatabaseDateDecodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F83226B89D8001F64F1 /* DatabaseDateDecodingStrategyTests.swift */; }; + 564A203B226B89E1001F64F1 /* ValueObservationCountTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F84226B89D8001F64F1 /* ValueObservationCountTests.swift */; }; + 564A203C226B89E1001F64F1 /* ValueObservationReadonlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F85226B89D8001F64F1 /* ValueObservationReadonlyTests.swift */; }; + 564A203D226B89E1001F64F1 /* IndexInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F86226B89D8001F64F1 /* IndexInfoTests.swift */; }; + 564A203E226B89E1001F64F1 /* ValueObservationReducerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F87226B89D8001F64F1 /* ValueObservationReducerTests.swift */; }; + 564A203F226B89E1001F64F1 /* AssociationBelongsToRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F88226B89D8001F64F1 /* AssociationBelongsToRowScopeTests.swift */; }; + 564A2040226B89E1001F64F1 /* StatementColumnConvertibleFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F89226B89D8001F64F1 /* StatementColumnConvertibleFetchTests.swift */; }; + 564A2041226B89E1001F64F1 /* CGFloatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8A226B89D9001F64F1 /* CGFloatTests.swift */; }; + 564A2042226B89E1001F64F1 /* FTS5TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8B226B89D9001F64F1 /* FTS5TableBuilderTests.swift */; }; + 564A2043226B89E1001F64F1 /* DatabasePoolFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8C226B89D9001F64F1 /* DatabasePoolFunctionTests.swift */; }; + 564A2044226B89E1001F64F1 /* FTS4RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8D226B89D9001F64F1 /* FTS4RecordTests.swift */; }; + 564A2045226B89E1001F64F1 /* FetchableRecordDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8E226B89D9001F64F1 /* FetchableRecordDecodableTests.swift */; }; + 564A2046226B89E1001F64F1 /* FTS5PatternTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8F226B89D9001F64F1 /* FTS5PatternTests.swift */; }; + 564A2047226B89E1001F64F1 /* AnyCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F90226B89D9001F64F1 /* AnyCursorTests.swift */; }; + 564A2048226B89E1001F64F1 /* RowAdapterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F91226B89D9001F64F1 /* RowAdapterTests.swift */; }; + 564A2049226B89E1001F64F1 /* DatabaseQueueReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F92226B89D9001F64F1 /* DatabaseQueueReadOnlyTests.swift */; }; + 564A204A226B89E1001F64F1 /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F93226B89D9001F64F1 /* RawRepresentable+DatabaseValueConvertibleTests.swift */; }; + 564A204B226B89E1001F64F1 /* FoundationNSDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F94226B89D9001F64F1 /* FoundationNSDataTests.swift */; }; + 564A204C226B89E1001F64F1 /* AssociationBelongsToSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F95226B89DA001F64F1 /* AssociationBelongsToSQLTests.swift */; }; + 564A204D226B89E1001F64F1 /* DatabaseQueueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F96226B89DA001F64F1 /* DatabaseQueueTests.swift */; }; + 564A204E226B89E1001F64F1 /* PrimaryKeyInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F97226B89DA001F64F1 /* PrimaryKeyInfoTests.swift */; }; + 564A204F226B89E1001F64F1 /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F98226B89DA001F64F1 /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */; }; + 564A2050226B89E1001F64F1 /* RecordPrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F99226B89DA001F64F1 /* RecordPrimaryKeySingleTests.swift */; }; + 564A2051226B89E1001F64F1 /* RecordWithColumnNameManglingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9A226B89DA001F64F1 /* RecordWithColumnNameManglingTests.swift */; }; + 564A2052226B89E1001F64F1 /* RowTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9B226B89DA001F64F1 /* RowTestCase.swift */; }; + 564A2053226B89E1001F64F1 /* ValueObservationRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9C226B89DA001F64F1 /* ValueObservationRowTests.swift */; }; + 564A2054226B89E1001F64F1 /* AssociationHasOneSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9D226B89DA001F64F1 /* AssociationHasOneSQLTests.swift */; }; + 564A2055226B89E1001F64F1 /* FoundationNSURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9E226B89DA001F64F1 /* FoundationNSURLTests.swift */; }; + 564A2056226B89E1001F64F1 /* TableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9F226B89DA001F64F1 /* TableRecordTests.swift */; }; + 564A2057226B89E1001F64F1 /* FoundationDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA0226B89DA001F64F1 /* FoundationDateTests.swift */; }; + 564A2058226B89E1001F64F1 /* FoundationUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA1226B89DB001F64F1 /* FoundationUUIDTests.swift */; }; + 564A2059226B89E1001F64F1 /* DatabaseValueConversionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA2226B89DB001F64F1 /* DatabaseValueConversionTests.swift */; }; + 564A205A226B89E1001F64F1 /* QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA3226B89DB001F64F1 /* QueryInterfaceRequestTests.swift */; }; + 564A205B226B89E1001F64F1 /* RecordCopyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA4226B89DB001F64F1 /* RecordCopyTests.swift */; }; + 564A205C226B89E1001F64F1 /* ResultCodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA5226B89DB001F64F1 /* ResultCodeTests.swift */; }; + 564A205D226B89E1001F64F1 /* DatabaseValueConvertibleEscapingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA6226B89DB001F64F1 /* DatabaseValueConvertibleEscapingTests.swift */; }; + 564A205E226B89E1001F64F1 /* FoundationNSNullTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA7226B89DB001F64F1 /* FoundationNSNullTests.swift */; }; + 564A205F226B89E1001F64F1 /* SQLLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA8226B89DB001F64F1 /* SQLLiteralTests.swift */; }; + 564A2060226B89E1001F64F1 /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA9226B89DB001F64F1 /* RecordPrimaryKeyHiddenRowIDTests.swift */; }; + 564A2061226B89E1001F64F1 /* TableRecord+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAA226B89DC001F64F1 /* TableRecord+QueryInterfaceRequestTests.swift */; }; + 564A2062226B89E1001F64F1 /* RecordMinimalPrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAB226B89DC001F64F1 /* RecordMinimalPrimaryKeySingleTests.swift */; }; + 564A2063226B89E1001F64F1 /* ColumnInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAC226B89DC001F64F1 /* ColumnInfoTests.swift */; }; + 564A2064226B89E1001F64F1 /* AssociationHasOneThroughFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAD226B89DC001F64F1 /* AssociationHasOneThroughFetchableRecordTests.swift */; }; + 564A2065226B89E1001F64F1 /* AssociationHasOneSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAE226B89DC001F64F1 /* AssociationHasOneSQLDerivationTests.swift */; }; + 564A2066226B89E1001F64F1 /* DatabaseTimestampTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAF226B89DC001F64F1 /* DatabaseTimestampTests.swift */; }; + 564A2067226B89E1001F64F1 /* EnumeratedCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB0226B89DC001F64F1 /* EnumeratedCursorTests.swift */; }; + 564A2068226B89E1001F64F1 /* DatabaseQueueConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB1226B89DC001F64F1 /* DatabaseQueueConcurrencyTests.swift */; }; + 564A2069226B89E1001F64F1 /* FlattenCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB2226B89DC001F64F1 /* FlattenCursorTests.swift */; }; + 564A206A226B89E1001F64F1 /* FoundationNSStringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB3226B89DC001F64F1 /* FoundationNSStringTests.swift */; }; + 564A206B226B89E1001F64F1 /* AssociationHasManyThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB4226B89DD001F64F1 /* AssociationHasManyThroughSQLTests.swift */; }; + 564A206C226B89E1001F64F1 /* FTS5CustomTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB5226B89DD001F64F1 /* FTS5CustomTokenizerTests.swift */; }; + 564A206D226B89E1001F64F1 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB6226B89DD001F64F1 /* ValueObservationCombineTests.swift */; }; + 564A206E226B89E1001F64F1 /* ValueObservationExtentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB7226B89DD001F64F1 /* ValueObservationExtentTests.swift */; }; + 564A206F226B89E1001F64F1 /* MapCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB8226B89DD001F64F1 /* MapCursorTests.swift */; }; + 564A2070226B89E1001F64F1 /* ValueObservationCompactMapTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB9226B89DD001F64F1 /* ValueObservationCompactMapTests.swift */; }; + 564A2071226B89E1001F64F1 /* VirtualTableModuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBA226B89DD001F64F1 /* VirtualTableModuleTests.swift */; }; + 564A2072226B89E1001F64F1 /* DropFirstCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBB226B89DD001F64F1 /* DropFirstCursorTests.swift */; }; + 564A2073226B89E1001F64F1 /* FetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBC226B89DE001F64F1 /* FetchableRecordTests.swift */; }; + 564A2074226B89E1001F64F1 /* UpdateStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBD226B89DE001F64F1 /* UpdateStatementTests.swift */; }; + 564A2075226B89E1001F64F1 /* RecordUniqueIndexTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBE226B89DE001F64F1 /* RecordUniqueIndexTests.swift */; }; + 564A2076226B89E1001F64F1 /* DatabaseReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBF226B89DE001F64F1 /* DatabaseReaderTests.swift */; }; + 564A2077226B89E1001F64F1 /* DatabaseWriterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC0226B89DE001F64F1 /* DatabaseWriterTests.swift */; }; + 564A2078226B89E1001F64F1 /* ForeignKeyInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC1226B89DE001F64F1 /* ForeignKeyInfoTests.swift */; }; + 564A2079226B89E1001F64F1 /* FoundationNSDecimalNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC2226B89DE001F64F1 /* FoundationNSDecimalNumberTests.swift */; }; + 564A207A226B89E1001F64F1 /* FoundationDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC3226B89DE001F64F1 /* FoundationDateComponentsTests.swift */; }; + 564A207B226B89E1001F64F1 /* FTS5TokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC4226B89DE001F64F1 /* FTS5TokenizerTests.swift */; }; + 564A207C226B89E1001F64F1 /* RecordPrimaryKeyRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC5226B89DE001F64F1 /* RecordPrimaryKeyRowIDTests.swift */; }; + 564A207D226B89E1001F64F1 /* ValueObservationFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC6226B89DF001F64F1 /* ValueObservationFetchTests.swift */; }; + 564A207E226B89E1001F64F1 /* DatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC7226B89DF001F64F1 /* DatabaseTests.swift */; }; + 564A207F226B89E1001F64F1 /* DatabaseQueueSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC8226B89DF001F64F1 /* DatabaseQueueSchemaCacheTests.swift */; }; + 564A2080226B89E1001F64F1 /* StatementArgumentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC9226B89DF001F64F1 /* StatementArgumentsTests.swift */; }; + 564A2081226B89E1001F64F1 /* TransactionObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCA226B89DF001F64F1 /* TransactionObserverTests.swift */; }; + 564A2082226B89E1001F64F1 /* PersistableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCB226B89DF001F64F1 /* PersistableRecordTests.swift */; }; + 564A2083226B89E1001F64F1 /* DataMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCC226B89DF001F64F1 /* DataMemoryTests.swift */; }; + 564A2084226B89E1001F64F1 /* JoinSupportTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCD226B89DF001F64F1 /* JoinSupportTests.swift */; }; + 564A2085226B89E1001F64F1 /* MutablePersistableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCE226B89DF001F64F1 /* MutablePersistableRecordTests.swift */; }; + 564A2086226B89E1001F64F1 /* AssociationTableAliasTestsSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCF226B89E0001F64F1 /* AssociationTableAliasTestsSQLTests.swift */; }; + 564A2087226B89E1001F64F1 /* FTS3PatternTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD0226B89E0001F64F1 /* FTS3PatternTests.swift */; }; + 564A2088226B89E1001F64F1 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD1226B89E0001F64F1 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift */; }; + 564A2089226B89E1001F64F1 /* DatabaseValueConversionErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD2226B89E0001F64F1 /* DatabaseValueConversionErrorTests.swift */; }; + 564A208A226B89E1001F64F1 /* MutablePersistableRecordChangesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD3226B89E0001F64F1 /* MutablePersistableRecordChangesTests.swift */; }; + 564A208B226B89E1001F64F1 /* DatabaseMigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD4226B89E0001F64F1 /* DatabaseMigratorTests.swift */; }; + 564A208C226B89E1001F64F1 /* GRDBTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD5226B89E0001F64F1 /* GRDBTestCase.swift */; }; + 564A208D226B89E1001F64F1 /* DatabaseUUIDEncodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD6226B89E0001F64F1 /* DatabaseUUIDEncodingStrategyTests.swift */; }; + 564A208E226B89E1001F64F1 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD7226B89E0001F64F1 /* DatabaseAfterNextTransactionCommitTests.swift */; }; + 564A208F226B89E1001F64F1 /* AssociationParallelRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD8226B89E0001F64F1 /* AssociationParallelRowScopesTests.swift */; }; + 564A2090226B89E1001F64F1 /* FTS3TokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD9226B89E0001F64F1 /* FTS3TokenizerTests.swift */; }; + 564A2091226B89E1001F64F1 /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FDA226B89E1001F64F1 /* FetchableRecord+QueryInterfaceRequestTests.swift */; }; + 564A2092226B89E1001F64F1 /* DatabasePoolConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FDB226B89E1001F64F1 /* DatabasePoolConcurrencyTests.swift */; }; + 564A2093226B89E1001F64F1 /* AssociationParallelSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FDC226B89E1001F64F1 /* AssociationParallelSQLTests.swift */; }; + 564A2094226B89E1001F64F1 /* FTS5RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FDD226B89E1001F64F1 /* FTS5RecordTests.swift */; }; + 564A2098226B8E18001F64F1 /* DropWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6D226B89D5001F64F1 /* DropWhileCursorTests.swift */; }; + 564A2099226B8E18001F64F1 /* DatabasePoolBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6A226B89D5001F64F1 /* DatabasePoolBackupTests.swift */; }; + 564A209A226B8E18001F64F1 /* DatabaseAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F31226B89CF001F64F1 /* DatabaseAggregateTests.swift */; }; + 564A209B226B8E18001F64F1 /* DatabaseFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F37226B89CF001F64F1 /* DatabaseFunctionTests.swift */; }; + 564A209C226B8E18001F64F1 /* DataMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCC226B89DF001F64F1 /* DataMemoryTests.swift */; }; + 564A209D226B8E18001F64F1 /* DatabaseQueueSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC8226B89DF001F64F1 /* DatabaseQueueSchemaCacheTests.swift */; }; + 564A209E226B8E18001F64F1 /* FTS3RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F66226B89D5001F64F1 /* FTS3RecordTests.swift */; }; + 564A209F226B8E18001F64F1 /* ResultCodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA5226B89DB001F64F1 /* ResultCodeTests.swift */; }; + 564A20A0226B8E18001F64F1 /* RecordPersistenceConflictPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3B226B89D0001F64F1 /* RecordPersistenceConflictPolicy.swift */; }; + 564A20A1226B8E18001F64F1 /* FetchedRecordsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F38226B89CF001F64F1 /* FetchedRecordsControllerTests.swift */; }; + 564A20A2226B8E18001F64F1 /* RecordUniqueIndexTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBE226B89DE001F64F1 /* RecordUniqueIndexTests.swift */; }; + 564A20A3226B8E18001F64F1 /* FoundationUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA1226B89DB001F64F1 /* FoundationUUIDTests.swift */; }; + 564A20A4226B8E18001F64F1 /* DatabaseQueueReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F92226B89D9001F64F1 /* DatabaseQueueReadOnlyTests.swift */; }; + 564A20A5226B8E18001F64F1 /* AssociationHasOneThroughDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F39226B89CF001F64F1 /* AssociationHasOneThroughDecodableRecordTests.swift */; }; + 564A20A6226B8E18001F64F1 /* AssociationChainRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F33226B89CF001F64F1 /* AssociationChainRowScopesTests.swift */; }; + 564A20A7226B8E18001F64F1 /* ValueObservationSchedulingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F48226B89D1001F64F1 /* ValueObservationSchedulingTests.swift */; }; + 564A20A8226B8E18001F64F1 /* ValueObservationFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC6226B89DF001F64F1 /* ValueObservationFetchTests.swift */; }; + 564A20A9226B8E18001F64F1 /* ValueObservationReadonlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F85226B89D8001F64F1 /* ValueObservationReadonlyTests.swift */; }; + 564A20AA226B8E18001F64F1 /* ValueObservationCountTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F84226B89D8001F64F1 /* ValueObservationCountTests.swift */; }; + 564A20AB226B8E18001F64F1 /* ValueObservationRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9C226B89DA001F64F1 /* ValueObservationRowTests.swift */; }; + 564A20AC226B8E18001F64F1 /* RowAdapterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F91226B89D9001F64F1 /* RowAdapterTests.swift */; }; + 564A20AD226B8E18001F64F1 /* StatementColumnConvertibleFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F89226B89D8001F64F1 /* StatementColumnConvertibleFetchTests.swift */; }; + 564A20AE226B8E18001F64F1 /* DatabasePoolReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F62226B89D4001F64F1 /* DatabasePoolReleaseMemoryTests.swift */; }; + 564A20AF226B8E18001F64F1 /* StatementArgumentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC9226B89DF001F64F1 /* StatementArgumentsTests.swift */; }; + 564A20B0226B8E18001F64F1 /* PersistableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCB226B89DF001F64F1 /* PersistableRecordTests.swift */; }; + 564A20B1226B8E18001F64F1 /* QueryInterfacePromiseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5F226B89D3001F64F1 /* QueryInterfacePromiseTests.swift */; }; + 564A20B2226B8E18001F64F1 /* DatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC7226B89DF001F64F1 /* DatabaseTests.swift */; }; + 564A20B3226B8E18001F64F1 /* AssociationHasManySQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7C226B89D7001F64F1 /* AssociationHasManySQLTests.swift */; }; + 564A20B4226B8E18001F64F1 /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F93226B89D9001F64F1 /* RawRepresentable+DatabaseValueConvertibleTests.swift */; }; + 564A20B5226B8E18001F64F1 /* FTS5TokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC4226B89DE001F64F1 /* FTS5TokenizerTests.swift */; }; + 564A20B6226B8E18001F64F1 /* Record+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F76226B89D6001F64F1 /* Record+QueryInterfaceRequestTests.swift */; }; + 564A20B7226B8E18001F64F1 /* FTS4RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8D226B89D9001F64F1 /* FTS4RecordTests.swift */; }; + 564A20B8226B8E18001F64F1 /* AssociationTableAliasTestsSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCF226B89E0001F64F1 /* AssociationTableAliasTestsSQLTests.swift */; }; + 564A20B9226B8E18001F64F1 /* TransactionObserverSavepointsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5B226B89D3001F64F1 /* TransactionObserverSavepointsTests.swift */; }; + 564A20BA226B8E18001F64F1 /* DatabaseRegionObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F55226B89D2001F64F1 /* DatabaseRegionObservationTests.swift */; }; + 564A20BB226B8E18001F64F1 /* MutablePersistableRecordDeleteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F27226B89CE001F64F1 /* MutablePersistableRecordDeleteTests.swift */; }; + 564A20BC226B8E18001F64F1 /* DropFirstCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBB226B89DD001F64F1 /* DropFirstCursorTests.swift */; }; + 564A20BD226B8E18001F64F1 /* MutablePersistableRecordEncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F32226B89CF001F64F1 /* MutablePersistableRecordEncodableTests.swift */; }; + 564A20BE226B8E18001F64F1 /* DatabaseValueConvertibleFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4C226B89D1001F64F1 /* DatabaseValueConvertibleFetchTests.swift */; }; + 564A20BF226B8E18001F64F1 /* CGFloatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8A226B89D9001F64F1 /* CGFloatTests.swift */; }; + 564A20C0226B8E18001F64F1 /* DatabaseCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F67226B89D5001F64F1 /* DatabaseCursorTests.swift */; }; + 564A20C1226B8E18001F64F1 /* SQLRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F42226B89D0001F64F1 /* SQLRequestTests.swift */; }; + 564A20C2226B8E18001F64F1 /* TableDefinitionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F64226B89D5001F64F1 /* TableDefinitionTests.swift */; }; + 564A20C3226B8E18001F64F1 /* CompilationSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F74226B89D6001F64F1 /* CompilationSubClassTests.swift */; }; + 564A20C4226B8E18001F64F1 /* FTS5PatternTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8F226B89D9001F64F1 /* FTS5PatternTests.swift */; }; + 564A20C5226B8E18001F64F1 /* DatabasePoolSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F78226B89D6001F64F1 /* DatabasePoolSchemaCacheTests.swift */; }; + 564A20C6226B8E18001F64F1 /* RecordEditedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F75226B89D6001F64F1 /* RecordEditedTests.swift */; }; + 564A20C7226B8E18001F64F1 /* ValueObservationRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F44226B89D0001F64F1 /* ValueObservationRecordTests.swift */; }; + 564A20C8226B8E18001F64F1 /* DatabaseRegionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F69226B89D5001F64F1 /* DatabaseRegionTests.swift */; }; + 564A20C9226B8E18001F64F1 /* DatabaseQueueReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F68226B89D5001F64F1 /* DatabaseQueueReleaseMemoryTests.swift */; }; + 564A20CA226B8E18001F64F1 /* PrefixCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F49226B89D1001F64F1 /* PrefixCursorTests.swift */; }; + 564A20CB226B8E18001F64F1 /* SelectStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2A226B89CF001F64F1 /* SelectStatementTests.swift */; }; + 564A20CC226B8E18001F64F1 /* QueryInterfaceExpressionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F41226B89D0001F64F1 /* QueryInterfaceExpressionsTests.swift */; }; + 564A20CD226B8E18001F64F1 /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F77226B89D6001F64F1 /* RecordMinimalPrimaryKeyRowIDTests.swift */; }; + 564A20CE226B8E18001F64F1 /* ForeignKeyInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC1226B89DE001F64F1 /* ForeignKeyInfoTests.swift */; }; + 564A20CF226B8E18001F64F1 /* RecordPrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F99226B89DA001F64F1 /* RecordPrimaryKeySingleTests.swift */; }; + 564A20D0226B8E18001F64F1 /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FDA226B89E1001F64F1 /* FetchableRecord+QueryInterfaceRequestTests.swift */; }; + 564A20D1226B8E18001F64F1 /* AssociationParallelRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD8226B89E0001F64F1 /* AssociationParallelRowScopesTests.swift */; }; + 564A20D2226B8E18001F64F1 /* AnyCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F90226B89D9001F64F1 /* AnyCursorTests.swift */; }; + 564A20D3226B8E18001F64F1 /* DatabaseValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F45226B89D0001F64F1 /* DatabaseValueTests.swift */; }; + 564A20D4226B8E18001F64F1 /* RowFromStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F57226B89D3001F64F1 /* RowFromStatementTests.swift */; }; + 564A20D5226B8E18001F64F1 /* FlattenCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB2226B89DC001F64F1 /* FlattenCursorTests.swift */; }; + 564A20D6226B8E18001F64F1 /* RecordInitializersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F51226B89D2001F64F1 /* RecordInitializersTests.swift */; }; + 564A20D7226B8E18001F64F1 /* ColumnExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F61226B89D4001F64F1 /* ColumnExpressionTests.swift */; }; + 564A20D8226B8E18001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6C226B89D5001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift */; }; + 564A20D9226B8E18001F64F1 /* ValueObservationMapTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F59226B89D3001F64F1 /* ValueObservationMapTests.swift */; }; + 564A20DA226B8E18001F64F1 /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F98226B89DA001F64F1 /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */; }; + 564A20DB226B8E18001F64F1 /* AssociationHasManyThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB4226B89DD001F64F1 /* AssociationHasManyThroughSQLTests.swift */; }; + 564A20DC226B8E18001F64F1 /* FTS3PatternTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD0226B89E0001F64F1 /* FTS3PatternTests.swift */; }; + 564A20DD226B8E18001F64F1 /* EnumeratedCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB0226B89DC001F64F1 /* EnumeratedCursorTests.swift */; }; + 564A20DE226B8E18001F64F1 /* DatabaseValueConvertibleSubclassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3A226B89D0001F64F1 /* DatabaseValueConvertibleSubclassTests.swift */; }; + 564A20DF226B8E18001F64F1 /* EncryptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5E226B89D3001F64F1 /* EncryptionTests.swift */; }; + 564A20E0226B8E18001F64F1 /* AssociationBelongsToFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7B226B89D7001F64F1 /* AssociationBelongsToFetchableRecordTests.swift */; }; + 564A20E1226B8E18001F64F1 /* FoundationURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F30226B89CF001F64F1 /* FoundationURLTests.swift */; }; + 564A20E2226B8E18001F64F1 /* PrefixWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F46226B89D1001F64F1 /* PrefixWhileCursorTests.swift */; }; + 564A20E3226B8E18001F64F1 /* FoundationNSDecimalNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC2226B89DE001F64F1 /* FoundationNSDecimalNumberTests.swift */; }; + 564A20E4226B8E18001F64F1 /* DatabaseCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F53226B89D2001F64F1 /* DatabaseCollationTests.swift */; }; + 564A20E5226B8E18001F64F1 /* TableRecord+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAA226B89DC001F64F1 /* TableRecord+QueryInterfaceRequestTests.swift */; }; + 564A20E6226B8E18001F64F1 /* DatabaseWriterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC0226B89DE001F64F1 /* DatabaseWriterTests.swift */; }; + 564A20E7226B8E18001F64F1 /* DatabaseQueueInMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2F226B89CF001F64F1 /* DatabaseQueueInMemoryTests.swift */; }; + 564A20E8226B8E18001F64F1 /* AssociationHasOneThroughFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAD226B89DC001F64F1 /* AssociationHasOneThroughFetchableRecordTests.swift */; }; + 564A20E9226B8E18001F64F1 /* FTS5WrapperTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F43226B89D0001F64F1 /* FTS5WrapperTokenizerTests.swift */; }; + 564A20EA226B8E18001F64F1 /* TableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9F226B89DA001F64F1 /* TableRecordTests.swift */; }; + 564A20EB226B8E18001F64F1 /* FTS5TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8B226B89D9001F64F1 /* FTS5TableBuilderTests.swift */; }; + 564A20EC226B8E18001F64F1 /* DatabaseValueConversionErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD2226B89E0001F64F1 /* DatabaseValueConversionErrorTests.swift */; }; + 564A20ED226B8E18001F64F1 /* TransactionObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCA226B89DF001F64F1 /* TransactionObserverTests.swift */; }; + 564A20EE226B8E18001F64F1 /* FetchableRecordDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8E226B89D9001F64F1 /* FetchableRecordDecodableTests.swift */; }; + 564A20EF226B8E18001F64F1 /* DatabasePoolCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3D226B89D0001F64F1 /* DatabasePoolCollationTests.swift */; }; + 564A20F0226B8E18001F64F1 /* QueryInterfaceExtensibilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6E226B89D6001F64F1 /* QueryInterfaceExtensibilityTests.swift */; }; + 564A20F1226B8E18001F64F1 /* RowFromDictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F81226B89D7001F64F1 /* RowFromDictionaryTests.swift */; }; + 564A20F2226B8E18001F64F1 /* DatabaseDateEncodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F54226B89D2001F64F1 /* DatabaseDateEncodingStrategyTests.swift */; }; + 564A20F3226B8E18001F64F1 /* ValueObservationCompactMapTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB9226B89DD001F64F1 /* ValueObservationCompactMapTests.swift */; }; + 564A20F4226B8E18001F64F1 /* DatabaseValueConvertibleEscapingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA6226B89DB001F64F1 /* DatabaseValueConvertibleEscapingTests.swift */; }; + 564A20F5226B8E18001F64F1 /* DatabaseQueueConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB1226B89DC001F64F1 /* DatabaseQueueConcurrencyTests.swift */; }; + 564A20F6226B8E18001F64F1 /* AssociationAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F60226B89D4001F64F1 /* AssociationAggregateTests.swift */; }; + 564A20F7226B8E18001F64F1 /* AssociationHasOneSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAE226B89DC001F64F1 /* AssociationHasOneSQLDerivationTests.swift */; }; + 564A20F8226B8E18001F64F1 /* StatementArguments+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F58226B89D3001F64F1 /* StatementArguments+FoundationTests.swift */; }; + 564A20F9226B8E18001F64F1 /* FoundationDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC3226B89DE001F64F1 /* FoundationDateComponentsTests.swift */; }; + 564A20FA226B8E18001F64F1 /* PrimaryKeyInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F97226B89DA001F64F1 /* PrimaryKeyInfoTests.swift */; }; + 564A20FB226B8E18001F64F1 /* MutablePersistableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCE226B89DF001F64F1 /* MutablePersistableRecordTests.swift */; }; + 564A20FC226B8E18001F64F1 /* AssociationBelongsToSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F80226B89D7001F64F1 /* AssociationBelongsToSQLDerivationTests.swift */; }; + 564A20FD226B8E18001F64F1 /* DatabaseErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F65226B89D5001F64F1 /* DatabaseErrorTests.swift */; }; + 564A20FE226B8E18001F64F1 /* DatabaseUUIDEncodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD6226B89E0001F64F1 /* DatabaseUUIDEncodingStrategyTests.swift */; }; + 564A20FF226B8E18001F64F1 /* DatabaseQueueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F96226B89DA001F64F1 /* DatabaseQueueTests.swift */; }; + 564A2100226B8E18001F64F1 /* DatabaseLogErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5C226B89D3001F64F1 /* DatabaseLogErrorTests.swift */; }; + 564A2101226B8E18001F64F1 /* RecordPrimaryKeyMultipleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2D226B89CF001F64F1 /* RecordPrimaryKeyMultipleTests.swift */; }; + 564A2102226B8E18001F64F1 /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F73226B89D6001F64F1 /* AssociationHasOneThroughSQLDerivationTests.swift */; }; + 564A2103226B8E18001F64F1 /* AssociationParallelSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FDC226B89E1001F64F1 /* AssociationParallelSQLTests.swift */; }; + 564A2104226B8E18001F64F1 /* ColumnInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAC226B89DC001F64F1 /* ColumnInfoTests.swift */; }; + 564A2105226B8E18001F64F1 /* DatabaseValueConvertibleEncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2C226B89CF001F64F1 /* DatabaseValueConvertibleEncodableTests.swift */; }; + 564A2106226B8E18001F64F1 /* AssociationRowScopeSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3E226B89D0001F64F1 /* AssociationRowScopeSearchTests.swift */; }; + 564A2107226B8E18001F64F1 /* FoundationNSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7D226B89D7001F64F1 /* FoundationNSDateTests.swift */; }; + 564A2108226B8E18001F64F1 /* AssociationHasOneThroughRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F28226B89CE001F64F1 /* AssociationHasOneThroughRowScopeTests.swift */; }; + 564A2109226B8E18001F64F1 /* AssociationHasOneSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9D226B89DA001F64F1 /* AssociationHasOneSQLTests.swift */; }; + 564A210A226B8E18001F64F1 /* FoundationNSNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F71226B89D6001F64F1 /* FoundationNSNumberTests.swift */; }; + 564A210B226B8E18001F64F1 /* SQLExpressionLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4E226B89D2001F64F1 /* SQLExpressionLiteralTests.swift */; }; + 564A210C226B8E18001F64F1 /* AssociationBelongsToRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F88226B89D8001F64F1 /* AssociationBelongsToRowScopeTests.swift */; }; + 564A210D226B8E18001F64F1 /* DatabaseSavepointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F79226B89D7001F64F1 /* DatabaseSavepointTests.swift */; }; + 564A210E226B8E18001F64F1 /* FoundationNSStringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB3226B89DC001F64F1 /* FoundationNSStringTests.swift */; }; + 564A210F226B8E18001F64F1 /* ValueObservationExtentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB7226B89DD001F64F1 /* ValueObservationExtentTests.swift */; }; + 564A2110226B8E18001F64F1 /* DatabaseTimestampTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAF226B89DC001F64F1 /* DatabaseTimestampTests.swift */; }; + 564A2111226B8E18001F64F1 /* FoundationNSDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F94226B89D9001F64F1 /* FoundationNSDataTests.swift */; }; + 564A2112226B8E18001F64F1 /* AssociationHasOneThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F52226B89D2001F64F1 /* AssociationHasOneThroughSQLTests.swift */; }; + 564A2113226B8E18001F64F1 /* FTS3TokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD9226B89E0001F64F1 /* FTS3TokenizerTests.swift */; }; + 564A2114226B8E18001F64F1 /* DatabaseReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBF226B89DE001F64F1 /* DatabaseReaderTests.swift */; }; + 564A2115226B8E18001F64F1 /* VirtualTableModuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBA226B89DD001F64F1 /* VirtualTableModuleTests.swift */; }; + 564A2116226B8E18001F64F1 /* JoinSupportTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCD226B89DF001F64F1 /* JoinSupportTests.swift */; }; + 564A2117226B8E18001F64F1 /* RecordPrimaryKeyRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC5226B89DE001F64F1 /* RecordPrimaryKeyRowIDTests.swift */; }; + 564A2118226B8E18001F64F1 /* FTS5RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FDD226B89E1001F64F1 /* FTS5RecordTests.swift */; }; + 564A2119226B8E18001F64F1 /* IndexInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F86226B89D8001F64F1 /* IndexInfoTests.swift */; }; + 564A211A226B8E18001F64F1 /* AssociationBelongsToSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F95226B89DA001F64F1 /* AssociationBelongsToSQLTests.swift */; }; + 564A211B226B8E18001F64F1 /* RowFromDictionaryLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F56226B89D2001F64F1 /* RowFromDictionaryLiteralTests.swift */; }; + 564A211C226B8E18001F64F1 /* FoundationNSNullTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA7226B89DB001F64F1 /* FoundationNSNullTests.swift */; }; + 564A211D226B8E18001F64F1 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD7226B89E0001F64F1 /* DatabaseAfterNextTransactionCommitTests.swift */; }; + 564A211E226B8E18001F64F1 /* FTS3TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F72226B89D6001F64F1 /* FTS3TableBuilderTests.swift */; }; + 564A211F226B8E18001F64F1 /* RecordPrimaryKeyNoneTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4A226B89D1001F64F1 /* RecordPrimaryKeyNoneTests.swift */; }; + 564A2120226B8E18001F64F1 /* RecordWithColumnNameManglingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9A226B89DA001F64F1 /* RecordWithColumnNameManglingTests.swift */; }; + 564A2121226B8E18001F64F1 /* RecordCopyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA4226B89DB001F64F1 /* RecordCopyTests.swift */; }; + 564A2122226B8E18001F64F1 /* SQLLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA8226B89DB001F64F1 /* SQLLiteralTests.swift */; }; + 564A2123226B8E18001F64F1 /* FTS5CustomTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB5226B89DD001F64F1 /* FTS5CustomTokenizerTests.swift */; }; + 564A2124226B8E18001F64F1 /* DerivableRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4B226B89D1001F64F1 /* DerivableRequestTests.swift */; }; + 564A2125226B8E18001F64F1 /* FoundationNSUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F34226B89CF001F64F1 /* FoundationNSUUIDTests.swift */; }; + 564A2126226B8E18001F64F1 /* FilterCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F47226B89D1001F64F1 /* FilterCursorTests.swift */; }; + 564A2127226B8E18001F64F1 /* MutablePersistableRecordChangesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD3226B89E0001F64F1 /* MutablePersistableRecordChangesTests.swift */; }; + 564A2128226B8E18001F64F1 /* DatabasePoolConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FDB226B89E1001F64F1 /* DatabasePoolConcurrencyTests.swift */; }; + 564A2129226B8E18001F64F1 /* RowCopiedFromStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F29226B89CF001F64F1 /* RowCopiedFromStatementTests.swift */; }; + 564A212A226B8E18001F64F1 /* FoundationDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F50226B89D2001F64F1 /* FoundationDataTests.swift */; }; + 564A212B226B8E18001F64F1 /* FTS4TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F63226B89D5001F64F1 /* FTS4TableBuilderTests.swift */; }; + 564A212C226B8E18001F64F1 /* DatabaseValueConversionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA2226B89DB001F64F1 /* DatabaseValueConversionTests.swift */; }; + 564A212D226B8E18001F64F1 /* DatabaseQueueBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2B226B89CF001F64F1 /* DatabaseQueueBackupTests.swift */; }; + 564A212E226B8E18001F64F1 /* DatabaseValueConvertibleDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F40226B89D0001F64F1 /* DatabaseValueConvertibleDecodableTests.swift */; }; + 564A212F226B8E18001F64F1 /* UpdateStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBD226B89DE001F64F1 /* UpdateStatementTests.swift */; }; + 564A2130226B8E18001F64F1 /* ValueObservationReducerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F87226B89D8001F64F1 /* ValueObservationReducerTests.swift */; }; + 564A2131226B8E18001F64F1 /* Row+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7E226B89D7001F64F1 /* Row+FoundationTests.swift */; }; + 564A2132226B8E18001F64F1 /* QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA3226B89DB001F64F1 /* QueryInterfaceRequestTests.swift */; }; + 564A2133226B8E18001F64F1 /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5A226B89D3001F64F1 /* FetchRequestTests.swift */; }; + 564A2134226B8E18001F64F1 /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA9226B89DB001F64F1 /* RecordPrimaryKeyHiddenRowIDTests.swift */; }; + 564A2135226B8E18001F64F1 /* AssociationChainSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4D226B89D2001F64F1 /* AssociationChainSQLTests.swift */; }; + 564A2136226B8E18001F64F1 /* GRDBTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD5226B89E0001F64F1 /* GRDBTestCase.swift */; }; + 564A2137226B8E18001F64F1 /* CompilationProtocolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F36226B89CF001F64F1 /* CompilationProtocolTests.swift */; }; + 564A2138226B8E18001F64F1 /* RecordSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5D226B89D3001F64F1 /* RecordSubClassTests.swift */; }; + 564A2139226B8E18001F64F1 /* AssociationParallelDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F70226B89D6001F64F1 /* AssociationParallelDecodableRecordTests.swift */; }; + 564A213A226B8E18001F64F1 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F35226B89CF001F64F1 /* AssociationBelongsToDecodableRecordTests.swift */; }; + 564A213B226B8E18001F64F1 /* DatabaseMigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD4226B89E0001F64F1 /* DatabaseMigratorTests.swift */; }; + 564A213C226B8E18001F64F1 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB6226B89DD001F64F1 /* ValueObservationCombineTests.swift */; }; + 564A213D226B8E18001F64F1 /* CursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6B226B89D5001F64F1 /* CursorTests.swift */; }; + 564A213E226B8E18001F64F1 /* DatabaseDateDecodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F83226B89D8001F64F1 /* DatabaseDateDecodingStrategyTests.swift */; }; + 564A213F226B8E18001F64F1 /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7F226B89D7001F64F1 /* SchedulingWatchdogTests.swift */; }; + 564A2140226B8E18001F64F1 /* RowTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9B226B89DA001F64F1 /* RowTestCase.swift */; }; + 564A2141226B8E18001F64F1 /* TruncateOptimizationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3C226B89D0001F64F1 /* TruncateOptimizationTests.swift */; }; + 564A2142226B8E18001F64F1 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD1226B89E0001F64F1 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift */; }; + 564A2143226B8E18001F64F1 /* DatabasePoolReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F82226B89D7001F64F1 /* DatabasePoolReadOnlyTests.swift */; }; + 564A2144226B8E18001F64F1 /* FoundationNSURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9E226B89DA001F64F1 /* FoundationNSURLTests.swift */; }; + 564A2145226B8E18001F64F1 /* FetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBC226B89DE001F64F1 /* FetchableRecordTests.swift */; }; + 564A2146226B8E18001F64F1 /* RowFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7A226B89D7001F64F1 /* RowFetchTests.swift */; }; + 564A2147226B8E18001F64F1 /* DatabaseSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3F226B89D0001F64F1 /* DatabaseSnapshotTests.swift */; }; + 564A2148226B8E18001F64F1 /* FoundationDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA0226B89DA001F64F1 /* FoundationDateTests.swift */; }; + 564A2149226B8E18001F64F1 /* DatabasePoolFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8C226B89D9001F64F1 /* DatabasePoolFunctionTests.swift */; }; + 564A214A226B8E18001F64F1 /* SQLInterpolationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4F226B89D2001F64F1 /* SQLInterpolationTests.swift */; }; + 564A214B226B8E18001F64F1 /* MapCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB8226B89DD001F64F1 /* MapCursorTests.swift */; }; + 564A214C226B8E18001F64F1 /* NumericOverflowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2E226B89CF001F64F1 /* NumericOverflowTests.swift */; }; + 564A214D226B8E18001F64F1 /* RecordMinimalPrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAB226B89DC001F64F1 /* RecordMinimalPrimaryKeySingleTests.swift */; }; + 564A214F226B8E18001F64F1 /* Pods_GRDBTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BEFDC53B1F7A33C242013A38 /* Pods_GRDBTests.framework */; }; + 564A2151226B8E18001F64F1 /* Betty.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = 564A1F6F226B89D6001F64F1 /* Betty.jpeg */; }; + 5656A802229474DD001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A801229474DC001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */; }; + 5656A803229474DD001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A801229474DC001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */; }; + 569BBA31228DF91000478429 /* AssociationPrefetchingFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569BBA30228DF91000478429 /* AssociationPrefetchingFetchableRecordTests.swift */; }; + 569BBA32228DF91000478429 /* AssociationPrefetchingFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569BBA30228DF91000478429 /* AssociationPrefetchingFetchableRecordTests.swift */; }; + 56DF0027228DE00900D611F3 /* AssociationPrefetchingCodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DF0025228DE00900D611F3 /* AssociationPrefetchingCodableRecordTests.swift */; }; + 56DF0028228DE00900D611F3 /* AssociationPrefetchingCodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DF0025228DE00900D611F3 /* AssociationPrefetchingCodableRecordTests.swift */; }; + 56DF0029228DE00900D611F3 /* AssociationPrefetchingRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DF0026228DE00900D611F3 /* AssociationPrefetchingRowTests.swift */; }; + 56DF002A228DE00900D611F3 /* AssociationPrefetchingRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DF0026228DE00900D611F3 /* AssociationPrefetchingRowTests.swift */; }; + 5B33E6E34F941B4C839A714F /* Pods_GRDBTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BEFDC53B1F7A33C242013A38 /* Pods_GRDBTests.framework */; }; + F2B3C4250D67969FF3948955 /* Pods_GRDBTestsEncrypted.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7D5C7999E7D9CE7145687F5D /* Pods_GRDBTestsEncrypted.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 04298D834C818285823558AB /* Pods-GRDBTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GRDBTests.release.xcconfig"; path = "Target Support Files/Pods-GRDBTests/Pods-GRDBTests.release.xcconfig"; sourceTree = ""; }; + 47C5D1B9AFFE795AA1D6EA5D /* Pods-GRDBTestsEncrypted.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GRDBTestsEncrypted.release.xcconfig"; path = "Target Support Files/Pods-GRDBTestsEncrypted/Pods-GRDBTestsEncrypted.release.xcconfig"; sourceTree = ""; }; + 560432A8228F1752009D3FE2 /* AssociationPrefetchingObservationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingObservationTests.swift; sourceTree = ""; }; + 56057C5E2291B8E400A7CB10 /* AssociationHasManyRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManyRowScopeTests.swift; sourceTree = ""; }; + 56057C672291D0AB00A7CB10 /* AssociationHasManyThroughRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManyThroughRowScopeTests.swift; sourceTree = ""; }; + 560714EF227DD1810091BB10 /* AssociationPrefetchingSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingSQLTests.swift; sourceTree = ""; }; + 564A1F1D226B876D001F64F1 /* GRDBTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 564A1F22226B876D001F64F1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 564A1F26226B89CD001F64F1 /* GRDBTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "GRDBTests-Bridging-Header.h"; sourceTree = ""; }; + 564A1F27226B89CE001F64F1 /* MutablePersistableRecordDeleteTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordDeleteTests.swift; sourceTree = ""; }; + 564A1F28226B89CE001F64F1 /* AssociationHasOneThroughRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughRowScopeTests.swift; sourceTree = ""; }; + 564A1F29226B89CF001F64F1 /* RowCopiedFromStatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowCopiedFromStatementTests.swift; sourceTree = ""; }; + 564A1F2A226B89CF001F64F1 /* SelectStatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectStatementTests.swift; sourceTree = ""; }; + 564A1F2B226B89CF001F64F1 /* DatabaseQueueBackupTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueBackupTests.swift; sourceTree = ""; }; + 564A1F2C226B89CF001F64F1 /* DatabaseValueConvertibleEncodableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleEncodableTests.swift; sourceTree = ""; }; + 564A1F2D226B89CF001F64F1 /* RecordPrimaryKeyMultipleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPrimaryKeyMultipleTests.swift; sourceTree = ""; }; + 564A1F2E226B89CF001F64F1 /* NumericOverflowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumericOverflowTests.swift; sourceTree = ""; }; + 564A1F2F226B89CF001F64F1 /* DatabaseQueueInMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueInMemoryTests.swift; sourceTree = ""; }; + 564A1F30226B89CF001F64F1 /* FoundationURLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationURLTests.swift; sourceTree = ""; }; + 564A1F31226B89CF001F64F1 /* DatabaseAggregateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseAggregateTests.swift; sourceTree = ""; }; + 564A1F32226B89CF001F64F1 /* MutablePersistableRecordEncodableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordEncodableTests.swift; sourceTree = ""; }; + 564A1F33226B89CF001F64F1 /* AssociationChainRowScopesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationChainRowScopesTests.swift; sourceTree = ""; }; + 564A1F34226B89CF001F64F1 /* FoundationNSUUIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSUUIDTests.swift; sourceTree = ""; }; + 564A1F35226B89CF001F64F1 /* AssociationBelongsToDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToDecodableRecordTests.swift; sourceTree = ""; }; + 564A1F36226B89CF001F64F1 /* CompilationProtocolTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompilationProtocolTests.swift; sourceTree = ""; }; + 564A1F37226B89CF001F64F1 /* DatabaseFunctionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseFunctionTests.swift; sourceTree = ""; }; + 564A1F38226B89CF001F64F1 /* FetchedRecordsControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedRecordsControllerTests.swift; sourceTree = ""; }; + 564A1F39226B89CF001F64F1 /* AssociationHasOneThroughDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughDecodableRecordTests.swift; sourceTree = ""; }; + 564A1F3A226B89D0001F64F1 /* DatabaseValueConvertibleSubclassTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleSubclassTests.swift; sourceTree = ""; }; + 564A1F3B226B89D0001F64F1 /* RecordPersistenceConflictPolicy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPersistenceConflictPolicy.swift; sourceTree = ""; }; + 564A1F3C226B89D0001F64F1 /* TruncateOptimizationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TruncateOptimizationTests.swift; sourceTree = ""; }; + 564A1F3D226B89D0001F64F1 /* DatabasePoolCollationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolCollationTests.swift; sourceTree = ""; }; + 564A1F3E226B89D0001F64F1 /* AssociationRowScopeSearchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationRowScopeSearchTests.swift; sourceTree = ""; }; + 564A1F3F226B89D0001F64F1 /* DatabaseSnapshotTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseSnapshotTests.swift; sourceTree = ""; }; + 564A1F40226B89D0001F64F1 /* DatabaseValueConvertibleDecodableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleDecodableTests.swift; sourceTree = ""; }; + 564A1F41226B89D0001F64F1 /* QueryInterfaceExpressionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceExpressionsTests.swift; sourceTree = ""; }; + 564A1F42226B89D0001F64F1 /* SQLRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLRequestTests.swift; sourceTree = ""; }; + 564A1F43226B89D0001F64F1 /* FTS5WrapperTokenizerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5WrapperTokenizerTests.swift; sourceTree = ""; }; + 564A1F44226B89D0001F64F1 /* ValueObservationRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationRecordTests.swift; sourceTree = ""; }; + 564A1F45226B89D0001F64F1 /* DatabaseValueTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueTests.swift; sourceTree = ""; }; + 564A1F46226B89D1001F64F1 /* PrefixWhileCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrefixWhileCursorTests.swift; sourceTree = ""; }; + 564A1F47226B89D1001F64F1 /* FilterCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FilterCursorTests.swift; sourceTree = ""; }; + 564A1F48226B89D1001F64F1 /* ValueObservationSchedulingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationSchedulingTests.swift; sourceTree = ""; }; + 564A1F49226B89D1001F64F1 /* PrefixCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrefixCursorTests.swift; sourceTree = ""; }; + 564A1F4A226B89D1001F64F1 /* RecordPrimaryKeyNoneTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPrimaryKeyNoneTests.swift; sourceTree = ""; }; + 564A1F4B226B89D1001F64F1 /* DerivableRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DerivableRequestTests.swift; sourceTree = ""; }; + 564A1F4C226B89D1001F64F1 /* DatabaseValueConvertibleFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleFetchTests.swift; sourceTree = ""; }; + 564A1F4D226B89D2001F64F1 /* AssociationChainSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationChainSQLTests.swift; sourceTree = ""; }; + 564A1F4E226B89D2001F64F1 /* SQLExpressionLiteralTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLExpressionLiteralTests.swift; sourceTree = ""; }; + 564A1F4F226B89D2001F64F1 /* SQLInterpolationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLInterpolationTests.swift; sourceTree = ""; }; + 564A1F50226B89D2001F64F1 /* FoundationDataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationDataTests.swift; sourceTree = ""; }; + 564A1F51226B89D2001F64F1 /* RecordInitializersTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordInitializersTests.swift; sourceTree = ""; }; + 564A1F52226B89D2001F64F1 /* AssociationHasOneThroughSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughSQLTests.swift; sourceTree = ""; }; + 564A1F53226B89D2001F64F1 /* DatabaseCollationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseCollationTests.swift; sourceTree = ""; }; + 564A1F54226B89D2001F64F1 /* DatabaseDateEncodingStrategyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseDateEncodingStrategyTests.swift; sourceTree = ""; }; + 564A1F55226B89D2001F64F1 /* DatabaseRegionObservationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegionObservationTests.swift; sourceTree = ""; }; + 564A1F56226B89D2001F64F1 /* RowFromDictionaryLiteralTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFromDictionaryLiteralTests.swift; sourceTree = ""; }; + 564A1F57226B89D3001F64F1 /* RowFromStatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFromStatementTests.swift; sourceTree = ""; }; + 564A1F58226B89D3001F64F1 /* StatementArguments+FoundationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StatementArguments+FoundationTests.swift"; sourceTree = ""; }; + 564A1F59226B89D3001F64F1 /* ValueObservationMapTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationMapTests.swift; sourceTree = ""; }; + 564A1F5A226B89D3001F64F1 /* FetchRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchRequestTests.swift; sourceTree = ""; }; + 564A1F5B226B89D3001F64F1 /* TransactionObserverSavepointsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionObserverSavepointsTests.swift; sourceTree = ""; }; + 564A1F5C226B89D3001F64F1 /* DatabaseLogErrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseLogErrorTests.swift; sourceTree = ""; }; + 564A1F5D226B89D3001F64F1 /* RecordSubClassTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordSubClassTests.swift; sourceTree = ""; }; + 564A1F5E226B89D3001F64F1 /* EncryptionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EncryptionTests.swift; sourceTree = ""; }; + 564A1F5F226B89D3001F64F1 /* QueryInterfacePromiseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfacePromiseTests.swift; sourceTree = ""; }; + 564A1F60226B89D4001F64F1 /* AssociationAggregateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationAggregateTests.swift; sourceTree = ""; }; + 564A1F61226B89D4001F64F1 /* ColumnExpressionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColumnExpressionTests.swift; sourceTree = ""; }; + 564A1F62226B89D4001F64F1 /* DatabasePoolReleaseMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolReleaseMemoryTests.swift; sourceTree = ""; }; + 564A1F63226B89D5001F64F1 /* FTS4TableBuilderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS4TableBuilderTests.swift; sourceTree = ""; }; + 564A1F64226B89D5001F64F1 /* TableDefinitionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableDefinitionTests.swift; sourceTree = ""; }; + 564A1F65226B89D5001F64F1 /* DatabaseErrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseErrorTests.swift; sourceTree = ""; }; + 564A1F66226B89D5001F64F1 /* FTS3RecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3RecordTests.swift; sourceTree = ""; }; + 564A1F67226B89D5001F64F1 /* DatabaseCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseCursorTests.swift; sourceTree = ""; }; + 564A1F68226B89D5001F64F1 /* DatabaseQueueReleaseMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueReleaseMemoryTests.swift; sourceTree = ""; }; + 564A1F69226B89D5001F64F1 /* DatabaseRegionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegionTests.swift; sourceTree = ""; }; + 564A1F6A226B89D5001F64F1 /* DatabasePoolBackupTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolBackupTests.swift; sourceTree = ""; }; + 564A1F6B226B89D5001F64F1 /* CursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CursorTests.swift; sourceTree = ""; }; + 564A1F6C226B89D5001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationDatabaseValueConvertibleTests.swift; sourceTree = ""; }; + 564A1F6D226B89D5001F64F1 /* DropWhileCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropWhileCursorTests.swift; sourceTree = ""; }; + 564A1F6E226B89D6001F64F1 /* QueryInterfaceExtensibilityTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceExtensibilityTests.swift; sourceTree = ""; }; + 564A1F6F226B89D6001F64F1 /* Betty.jpeg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Betty.jpeg; sourceTree = ""; }; + 564A1F70226B89D6001F64F1 /* AssociationParallelDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelDecodableRecordTests.swift; sourceTree = ""; }; + 564A1F71226B89D6001F64F1 /* FoundationNSNumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSNumberTests.swift; sourceTree = ""; }; + 564A1F72226B89D6001F64F1 /* FTS3TableBuilderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3TableBuilderTests.swift; sourceTree = ""; }; + 564A1F73226B89D6001F64F1 /* AssociationHasOneThroughSQLDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughSQLDerivationTests.swift; sourceTree = ""; }; + 564A1F74226B89D6001F64F1 /* CompilationSubClassTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompilationSubClassTests.swift; sourceTree = ""; }; + 564A1F75226B89D6001F64F1 /* RecordEditedTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordEditedTests.swift; sourceTree = ""; }; + 564A1F76226B89D6001F64F1 /* Record+QueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Record+QueryInterfaceRequestTests.swift"; sourceTree = ""; }; + 564A1F77226B89D6001F64F1 /* RecordMinimalPrimaryKeyRowIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordMinimalPrimaryKeyRowIDTests.swift; sourceTree = ""; }; + 564A1F78226B89D6001F64F1 /* DatabasePoolSchemaCacheTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolSchemaCacheTests.swift; sourceTree = ""; }; + 564A1F79226B89D7001F64F1 /* DatabaseSavepointTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseSavepointTests.swift; sourceTree = ""; }; + 564A1F7A226B89D7001F64F1 /* RowFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFetchTests.swift; sourceTree = ""; }; + 564A1F7B226B89D7001F64F1 /* AssociationBelongsToFetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToFetchableRecordTests.swift; sourceTree = ""; }; + 564A1F7C226B89D7001F64F1 /* AssociationHasManySQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManySQLTests.swift; sourceTree = ""; }; + 564A1F7D226B89D7001F64F1 /* FoundationNSDateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSDateTests.swift; sourceTree = ""; }; + 564A1F7E226B89D7001F64F1 /* Row+FoundationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Row+FoundationTests.swift"; sourceTree = ""; }; + 564A1F7F226B89D7001F64F1 /* SchedulingWatchdogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SchedulingWatchdogTests.swift; sourceTree = ""; }; + 564A1F80226B89D7001F64F1 /* AssociationBelongsToSQLDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToSQLDerivationTests.swift; sourceTree = ""; }; + 564A1F81226B89D7001F64F1 /* RowFromDictionaryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFromDictionaryTests.swift; sourceTree = ""; }; + 564A1F82226B89D7001F64F1 /* DatabasePoolReadOnlyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolReadOnlyTests.swift; sourceTree = ""; }; + 564A1F83226B89D8001F64F1 /* DatabaseDateDecodingStrategyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseDateDecodingStrategyTests.swift; sourceTree = ""; }; + 564A1F84226B89D8001F64F1 /* ValueObservationCountTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationCountTests.swift; sourceTree = ""; }; + 564A1F85226B89D8001F64F1 /* ValueObservationReadonlyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationReadonlyTests.swift; sourceTree = ""; }; + 564A1F86226B89D8001F64F1 /* IndexInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IndexInfoTests.swift; sourceTree = ""; }; + 564A1F87226B89D8001F64F1 /* ValueObservationReducerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationReducerTests.swift; sourceTree = ""; }; + 564A1F88226B89D8001F64F1 /* AssociationBelongsToRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToRowScopeTests.swift; sourceTree = ""; }; + 564A1F89226B89D8001F64F1 /* StatementColumnConvertibleFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementColumnConvertibleFetchTests.swift; sourceTree = ""; }; + 564A1F8A226B89D9001F64F1 /* CGFloatTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGFloatTests.swift; sourceTree = ""; }; + 564A1F8B226B89D9001F64F1 /* FTS5TableBuilderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5TableBuilderTests.swift; sourceTree = ""; }; + 564A1F8C226B89D9001F64F1 /* DatabasePoolFunctionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolFunctionTests.swift; sourceTree = ""; }; + 564A1F8D226B89D9001F64F1 /* FTS4RecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS4RecordTests.swift; sourceTree = ""; }; + 564A1F8E226B89D9001F64F1 /* FetchableRecordDecodableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchableRecordDecodableTests.swift; sourceTree = ""; }; + 564A1F8F226B89D9001F64F1 /* FTS5PatternTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5PatternTests.swift; sourceTree = ""; }; + 564A1F90226B89D9001F64F1 /* AnyCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyCursorTests.swift; sourceTree = ""; }; + 564A1F91226B89D9001F64F1 /* RowAdapterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowAdapterTests.swift; sourceTree = ""; }; + 564A1F92226B89D9001F64F1 /* DatabaseQueueReadOnlyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueReadOnlyTests.swift; sourceTree = ""; }; + 564A1F93226B89D9001F64F1 /* RawRepresentable+DatabaseValueConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "RawRepresentable+DatabaseValueConvertibleTests.swift"; sourceTree = ""; }; + 564A1F94226B89D9001F64F1 /* FoundationNSDataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSDataTests.swift; sourceTree = ""; }; + 564A1F95226B89DA001F64F1 /* AssociationBelongsToSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToSQLTests.swift; sourceTree = ""; }; + 564A1F96226B89DA001F64F1 /* DatabaseQueueTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueTests.swift; sourceTree = ""; }; + 564A1F97226B89DA001F64F1 /* PrimaryKeyInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrimaryKeyInfoTests.swift; sourceTree = ""; }; + 564A1F98226B89DA001F64F1 /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordPersistenceConflictPolicyTests.swift; sourceTree = ""; }; + 564A1F99226B89DA001F64F1 /* RecordPrimaryKeySingleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPrimaryKeySingleTests.swift; sourceTree = ""; }; + 564A1F9A226B89DA001F64F1 /* RecordWithColumnNameManglingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordWithColumnNameManglingTests.swift; sourceTree = ""; }; + 564A1F9B226B89DA001F64F1 /* RowTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowTestCase.swift; sourceTree = ""; }; + 564A1F9C226B89DA001F64F1 /* ValueObservationRowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationRowTests.swift; sourceTree = ""; }; + 564A1F9D226B89DA001F64F1 /* AssociationHasOneSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneSQLTests.swift; sourceTree = ""; }; + 564A1F9E226B89DA001F64F1 /* FoundationNSURLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSURLTests.swift; sourceTree = ""; }; + 564A1F9F226B89DA001F64F1 /* TableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableRecordTests.swift; sourceTree = ""; }; + 564A1FA0226B89DA001F64F1 /* FoundationDateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationDateTests.swift; sourceTree = ""; }; + 564A1FA1226B89DB001F64F1 /* FoundationUUIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationUUIDTests.swift; sourceTree = ""; }; + 564A1FA2226B89DB001F64F1 /* DatabaseValueConversionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConversionTests.swift; sourceTree = ""; }; + 564A1FA3226B89DB001F64F1 /* QueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceRequestTests.swift; sourceTree = ""; }; + 564A1FA4226B89DB001F64F1 /* RecordCopyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordCopyTests.swift; sourceTree = ""; }; + 564A1FA5226B89DB001F64F1 /* ResultCodeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResultCodeTests.swift; sourceTree = ""; }; + 564A1FA6226B89DB001F64F1 /* DatabaseValueConvertibleEscapingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleEscapingTests.swift; sourceTree = ""; }; + 564A1FA7226B89DB001F64F1 /* FoundationNSNullTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSNullTests.swift; sourceTree = ""; }; + 564A1FA8226B89DB001F64F1 /* SQLLiteralTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLLiteralTests.swift; sourceTree = ""; }; + 564A1FA9226B89DB001F64F1 /* RecordPrimaryKeyHiddenRowIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPrimaryKeyHiddenRowIDTests.swift; sourceTree = ""; }; + 564A1FAA226B89DC001F64F1 /* TableRecord+QueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TableRecord+QueryInterfaceRequestTests.swift"; sourceTree = ""; }; + 564A1FAB226B89DC001F64F1 /* RecordMinimalPrimaryKeySingleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordMinimalPrimaryKeySingleTests.swift; sourceTree = ""; }; + 564A1FAC226B89DC001F64F1 /* ColumnInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColumnInfoTests.swift; sourceTree = ""; }; + 564A1FAD226B89DC001F64F1 /* AssociationHasOneThroughFetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughFetchableRecordTests.swift; sourceTree = ""; }; + 564A1FAE226B89DC001F64F1 /* AssociationHasOneSQLDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneSQLDerivationTests.swift; sourceTree = ""; }; + 564A1FAF226B89DC001F64F1 /* DatabaseTimestampTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseTimestampTests.swift; sourceTree = ""; }; + 564A1FB0226B89DC001F64F1 /* EnumeratedCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnumeratedCursorTests.swift; sourceTree = ""; }; + 564A1FB1226B89DC001F64F1 /* DatabaseQueueConcurrencyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueConcurrencyTests.swift; sourceTree = ""; }; + 564A1FB2226B89DC001F64F1 /* FlattenCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlattenCursorTests.swift; sourceTree = ""; }; + 564A1FB3226B89DC001F64F1 /* FoundationNSStringTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSStringTests.swift; sourceTree = ""; }; + 564A1FB4226B89DD001F64F1 /* AssociationHasManyThroughSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManyThroughSQLTests.swift; sourceTree = ""; }; + 564A1FB5226B89DD001F64F1 /* FTS5CustomTokenizerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5CustomTokenizerTests.swift; sourceTree = ""; }; + 564A1FB6226B89DD001F64F1 /* ValueObservationCombineTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationCombineTests.swift; sourceTree = ""; }; + 564A1FB7226B89DD001F64F1 /* ValueObservationExtentTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationExtentTests.swift; sourceTree = ""; }; + 564A1FB8226B89DD001F64F1 /* MapCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapCursorTests.swift; sourceTree = ""; }; + 564A1FB9226B89DD001F64F1 /* ValueObservationCompactMapTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationCompactMapTests.swift; sourceTree = ""; }; + 564A1FBA226B89DD001F64F1 /* VirtualTableModuleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VirtualTableModuleTests.swift; sourceTree = ""; }; + 564A1FBB226B89DD001F64F1 /* DropFirstCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropFirstCursorTests.swift; sourceTree = ""; }; + 564A1FBC226B89DE001F64F1 /* FetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchableRecordTests.swift; sourceTree = ""; }; + 564A1FBD226B89DE001F64F1 /* UpdateStatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateStatementTests.swift; sourceTree = ""; }; + 564A1FBE226B89DE001F64F1 /* RecordUniqueIndexTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordUniqueIndexTests.swift; sourceTree = ""; }; + 564A1FBF226B89DE001F64F1 /* DatabaseReaderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseReaderTests.swift; sourceTree = ""; }; + 564A1FC0226B89DE001F64F1 /* DatabaseWriterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseWriterTests.swift; sourceTree = ""; }; + 564A1FC1226B89DE001F64F1 /* ForeignKeyInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForeignKeyInfoTests.swift; sourceTree = ""; }; + 564A1FC2226B89DE001F64F1 /* FoundationNSDecimalNumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSDecimalNumberTests.swift; sourceTree = ""; }; + 564A1FC3226B89DE001F64F1 /* FoundationDateComponentsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationDateComponentsTests.swift; sourceTree = ""; }; + 564A1FC4226B89DE001F64F1 /* FTS5TokenizerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5TokenizerTests.swift; sourceTree = ""; }; + 564A1FC5226B89DE001F64F1 /* RecordPrimaryKeyRowIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPrimaryKeyRowIDTests.swift; sourceTree = ""; }; + 564A1FC6226B89DF001F64F1 /* ValueObservationFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationFetchTests.swift; sourceTree = ""; }; + 564A1FC7226B89DF001F64F1 /* DatabaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseTests.swift; sourceTree = ""; }; + 564A1FC8226B89DF001F64F1 /* DatabaseQueueSchemaCacheTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueSchemaCacheTests.swift; sourceTree = ""; }; + 564A1FC9226B89DF001F64F1 /* StatementArgumentsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementArgumentsTests.swift; sourceTree = ""; }; + 564A1FCA226B89DF001F64F1 /* TransactionObserverTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionObserverTests.swift; sourceTree = ""; }; + 564A1FCB226B89DF001F64F1 /* PersistableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersistableRecordTests.swift; sourceTree = ""; }; + 564A1FCC226B89DF001F64F1 /* DataMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataMemoryTests.swift; sourceTree = ""; }; + 564A1FCD226B89DF001F64F1 /* JoinSupportTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JoinSupportTests.swift; sourceTree = ""; }; + 564A1FCE226B89DF001F64F1 /* MutablePersistableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordTests.swift; sourceTree = ""; }; + 564A1FCF226B89E0001F64F1 /* AssociationTableAliasTestsSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationTableAliasTestsSQLTests.swift; sourceTree = ""; }; + 564A1FD0226B89E0001F64F1 /* FTS3PatternTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3PatternTests.swift; sourceTree = ""; }; + 564A1FD1226B89E0001F64F1 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift; sourceTree = ""; }; + 564A1FD2226B89E0001F64F1 /* DatabaseValueConversionErrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConversionErrorTests.swift; sourceTree = ""; }; + 564A1FD3226B89E0001F64F1 /* MutablePersistableRecordChangesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordChangesTests.swift; sourceTree = ""; }; + 564A1FD4226B89E0001F64F1 /* DatabaseMigratorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseMigratorTests.swift; sourceTree = ""; }; + 564A1FD5226B89E0001F64F1 /* GRDBTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GRDBTestCase.swift; sourceTree = ""; }; + 564A1FD6226B89E0001F64F1 /* DatabaseUUIDEncodingStrategyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseUUIDEncodingStrategyTests.swift; sourceTree = ""; }; + 564A1FD7226B89E0001F64F1 /* DatabaseAfterNextTransactionCommitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseAfterNextTransactionCommitTests.swift; sourceTree = ""; }; + 564A1FD8226B89E0001F64F1 /* AssociationParallelRowScopesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelRowScopesTests.swift; sourceTree = ""; }; + 564A1FD9226B89E0001F64F1 /* FTS3TokenizerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3TokenizerTests.swift; sourceTree = ""; }; + 564A1FDA226B89E1001F64F1 /* FetchableRecord+QueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FetchableRecord+QueryInterfaceRequestTests.swift"; sourceTree = ""; }; + 564A1FDB226B89E1001F64F1 /* DatabasePoolConcurrencyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolConcurrencyTests.swift; sourceTree = ""; }; + 564A1FDC226B89E1001F64F1 /* AssociationParallelSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelSQLTests.swift; sourceTree = ""; }; + 564A1FDD226B89E1001F64F1 /* FTS5RecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5RecordTests.swift; sourceTree = ""; }; + 564A2156226B8E18001F64F1 /* GRDBTestsEncrypted.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBTestsEncrypted.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 5656A801229474DC001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationQueryInterfaceRequestTests.swift; sourceTree = ""; }; + 569BBA30228DF91000478429 /* AssociationPrefetchingFetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingFetchableRecordTests.swift; sourceTree = ""; }; + 56DF0025228DE00900D611F3 /* AssociationPrefetchingCodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingCodableRecordTests.swift; sourceTree = ""; }; + 56DF0026228DE00900D611F3 /* AssociationPrefetchingRowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingRowTests.swift; sourceTree = ""; }; + 6A4788C0F815F6C5E4EBDE12 /* Pods-GRDBTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GRDBTests.debug.xcconfig"; path = "Target Support Files/Pods-GRDBTests/Pods-GRDBTests.debug.xcconfig"; sourceTree = ""; }; + 7D5C7999E7D9CE7145687F5D /* Pods_GRDBTestsEncrypted.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_GRDBTestsEncrypted.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 83BFB5733A86DAA3D0BEE684 /* Pods-GRDBTestsEncrypted.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GRDBTestsEncrypted.debug.xcconfig"; path = "Target Support Files/Pods-GRDBTestsEncrypted/Pods-GRDBTestsEncrypted.debug.xcconfig"; sourceTree = ""; }; + BEFDC53B1F7A33C242013A38 /* Pods_GRDBTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_GRDBTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 564A1F1A226B876D001F64F1 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 5B33E6E34F941B4C839A714F /* Pods_GRDBTests.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 564A214E226B8E18001F64F1 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 564A214F226B8E18001F64F1 /* Pods_GRDBTests.framework in Frameworks */, + F2B3C4250D67969FF3948955 /* Pods_GRDBTestsEncrypted.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 564A1F12226B8750001F64F1 = { + isa = PBXGroup; + children = ( + 564A1F22226B876D001F64F1 /* Info.plist */, + 564A1F1F226B876D001F64F1 /* GRDBTests */, + 564A1F1E226B876D001F64F1 /* Products */, + A39D84C3D9EF90DA939D10D7 /* Pods */, + EAA416B3A072FCB835929FD9 /* Frameworks */, + ); + sourceTree = ""; + }; + 564A1F1E226B876D001F64F1 /* Products */ = { + isa = PBXGroup; + children = ( + 564A1F1D226B876D001F64F1 /* GRDBTests.xctest */, + 564A2156226B8E18001F64F1 /* GRDBTestsEncrypted.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 564A1F1F226B876D001F64F1 /* GRDBTests */ = { + isa = PBXGroup; + children = ( + 564A1F90226B89D9001F64F1 /* AnyCursorTests.swift */, + 564A1F60226B89D4001F64F1 /* AssociationAggregateTests.swift */, + 564A1F35226B89CF001F64F1 /* AssociationBelongsToDecodableRecordTests.swift */, + 564A1F7B226B89D7001F64F1 /* AssociationBelongsToFetchableRecordTests.swift */, + 564A1F88226B89D8001F64F1 /* AssociationBelongsToRowScopeTests.swift */, + 564A1F80226B89D7001F64F1 /* AssociationBelongsToSQLDerivationTests.swift */, + 564A1F95226B89DA001F64F1 /* AssociationBelongsToSQLTests.swift */, + 564A1F33226B89CF001F64F1 /* AssociationChainRowScopesTests.swift */, + 564A1F4D226B89D2001F64F1 /* AssociationChainSQLTests.swift */, + 56057C5E2291B8E400A7CB10 /* AssociationHasManyRowScopeTests.swift */, + 564A1F7C226B89D7001F64F1 /* AssociationHasManySQLTests.swift */, + 56057C672291D0AB00A7CB10 /* AssociationHasManyThroughRowScopeTests.swift */, + 564A1FB4226B89DD001F64F1 /* AssociationHasManyThroughSQLTests.swift */, + 564A1FAE226B89DC001F64F1 /* AssociationHasOneSQLDerivationTests.swift */, + 564A1F9D226B89DA001F64F1 /* AssociationHasOneSQLTests.swift */, + 564A1F39226B89CF001F64F1 /* AssociationHasOneThroughDecodableRecordTests.swift */, + 564A1FAD226B89DC001F64F1 /* AssociationHasOneThroughFetchableRecordTests.swift */, + 564A1F28226B89CE001F64F1 /* AssociationHasOneThroughRowScopeTests.swift */, + 564A1F73226B89D6001F64F1 /* AssociationHasOneThroughSQLDerivationTests.swift */, + 564A1F52226B89D2001F64F1 /* AssociationHasOneThroughSQLTests.swift */, + 564A1F70226B89D6001F64F1 /* AssociationParallelDecodableRecordTests.swift */, + 564A1FD8226B89E0001F64F1 /* AssociationParallelRowScopesTests.swift */, + 564A1FDC226B89E1001F64F1 /* AssociationParallelSQLTests.swift */, + 56DF0025228DE00900D611F3 /* AssociationPrefetchingCodableRecordTests.swift */, + 569BBA30228DF91000478429 /* AssociationPrefetchingFetchableRecordTests.swift */, + 560432A8228F1752009D3FE2 /* AssociationPrefetchingObservationTests.swift */, + 56DF0026228DE00900D611F3 /* AssociationPrefetchingRowTests.swift */, + 560714EF227DD1810091BB10 /* AssociationPrefetchingSQLTests.swift */, + 564A1F3E226B89D0001F64F1 /* AssociationRowScopeSearchTests.swift */, + 564A1FCF226B89E0001F64F1 /* AssociationTableAliasTestsSQLTests.swift */, + 564A1F6F226B89D6001F64F1 /* Betty.jpeg */, + 564A1F8A226B89D9001F64F1 /* CGFloatTests.swift */, + 564A1F61226B89D4001F64F1 /* ColumnExpressionTests.swift */, + 564A1FAC226B89DC001F64F1 /* ColumnInfoTests.swift */, + 564A1F36226B89CF001F64F1 /* CompilationProtocolTests.swift */, + 564A1F74226B89D6001F64F1 /* CompilationSubClassTests.swift */, + 564A1F6B226B89D5001F64F1 /* CursorTests.swift */, + 564A1FD7226B89E0001F64F1 /* DatabaseAfterNextTransactionCommitTests.swift */, + 564A1F31226B89CF001F64F1 /* DatabaseAggregateTests.swift */, + 564A1F53226B89D2001F64F1 /* DatabaseCollationTests.swift */, + 564A1F67226B89D5001F64F1 /* DatabaseCursorTests.swift */, + 564A1F83226B89D8001F64F1 /* DatabaseDateDecodingStrategyTests.swift */, + 564A1F54226B89D2001F64F1 /* DatabaseDateEncodingStrategyTests.swift */, + 564A1F65226B89D5001F64F1 /* DatabaseErrorTests.swift */, + 564A1F37226B89CF001F64F1 /* DatabaseFunctionTests.swift */, + 564A1F5C226B89D3001F64F1 /* DatabaseLogErrorTests.swift */, + 564A1FD4226B89E0001F64F1 /* DatabaseMigratorTests.swift */, + 564A1F6A226B89D5001F64F1 /* DatabasePoolBackupTests.swift */, + 564A1F3D226B89D0001F64F1 /* DatabasePoolCollationTests.swift */, + 564A1FDB226B89E1001F64F1 /* DatabasePoolConcurrencyTests.swift */, + 564A1F8C226B89D9001F64F1 /* DatabasePoolFunctionTests.swift */, + 564A1F82226B89D7001F64F1 /* DatabasePoolReadOnlyTests.swift */, + 564A1F62226B89D4001F64F1 /* DatabasePoolReleaseMemoryTests.swift */, + 564A1F78226B89D6001F64F1 /* DatabasePoolSchemaCacheTests.swift */, + 564A1F2B226B89CF001F64F1 /* DatabaseQueueBackupTests.swift */, + 564A1FB1226B89DC001F64F1 /* DatabaseQueueConcurrencyTests.swift */, + 564A1F2F226B89CF001F64F1 /* DatabaseQueueInMemoryTests.swift */, + 564A1F92226B89D9001F64F1 /* DatabaseQueueReadOnlyTests.swift */, + 564A1F68226B89D5001F64F1 /* DatabaseQueueReleaseMemoryTests.swift */, + 564A1FC8226B89DF001F64F1 /* DatabaseQueueSchemaCacheTests.swift */, + 564A1F96226B89DA001F64F1 /* DatabaseQueueTests.swift */, + 564A1FBF226B89DE001F64F1 /* DatabaseReaderTests.swift */, + 564A1F55226B89D2001F64F1 /* DatabaseRegionObservationTests.swift */, + 564A1F69226B89D5001F64F1 /* DatabaseRegionTests.swift */, + 564A1F79226B89D7001F64F1 /* DatabaseSavepointTests.swift */, + 564A1F3F226B89D0001F64F1 /* DatabaseSnapshotTests.swift */, + 564A1FC7226B89DF001F64F1 /* DatabaseTests.swift */, + 564A1FAF226B89DC001F64F1 /* DatabaseTimestampTests.swift */, + 564A1FD6226B89E0001F64F1 /* DatabaseUUIDEncodingStrategyTests.swift */, + 564A1FD2226B89E0001F64F1 /* DatabaseValueConversionErrorTests.swift */, + 564A1FA2226B89DB001F64F1 /* DatabaseValueConversionTests.swift */, + 564A1F40226B89D0001F64F1 /* DatabaseValueConvertibleDecodableTests.swift */, + 564A1F2C226B89CF001F64F1 /* DatabaseValueConvertibleEncodableTests.swift */, + 564A1FA6226B89DB001F64F1 /* DatabaseValueConvertibleEscapingTests.swift */, + 564A1F4C226B89D1001F64F1 /* DatabaseValueConvertibleFetchTests.swift */, + 564A1F3A226B89D0001F64F1 /* DatabaseValueConvertibleSubclassTests.swift */, + 564A1F45226B89D0001F64F1 /* DatabaseValueTests.swift */, + 564A1FC0226B89DE001F64F1 /* DatabaseWriterTests.swift */, + 564A1FCC226B89DF001F64F1 /* DataMemoryTests.swift */, + 564A1F4B226B89D1001F64F1 /* DerivableRequestTests.swift */, + 564A1FBB226B89DD001F64F1 /* DropFirstCursorTests.swift */, + 564A1F6D226B89D5001F64F1 /* DropWhileCursorTests.swift */, + 564A1F5E226B89D3001F64F1 /* EncryptionTests.swift */, + 564A1FB0226B89DC001F64F1 /* EnumeratedCursorTests.swift */, + 564A1FDA226B89E1001F64F1 /* FetchableRecord+QueryInterfaceRequestTests.swift */, + 564A1F8E226B89D9001F64F1 /* FetchableRecordDecodableTests.swift */, + 564A1FBC226B89DE001F64F1 /* FetchableRecordTests.swift */, + 564A1F38226B89CF001F64F1 /* FetchedRecordsControllerTests.swift */, + 564A1F5A226B89D3001F64F1 /* FetchRequestTests.swift */, + 564A1F47226B89D1001F64F1 /* FilterCursorTests.swift */, + 564A1FB2226B89DC001F64F1 /* FlattenCursorTests.swift */, + 564A1FC1226B89DE001F64F1 /* ForeignKeyInfoTests.swift */, + 564A1F50226B89D2001F64F1 /* FoundationDataTests.swift */, + 564A1FC3226B89DE001F64F1 /* FoundationDateComponentsTests.swift */, + 564A1FA0226B89DA001F64F1 /* FoundationDateTests.swift */, + 564A1F94226B89D9001F64F1 /* FoundationNSDataTests.swift */, + 564A1F7D226B89D7001F64F1 /* FoundationNSDateTests.swift */, + 564A1FC2226B89DE001F64F1 /* FoundationNSDecimalNumberTests.swift */, + 564A1FA7226B89DB001F64F1 /* FoundationNSNullTests.swift */, + 564A1F71226B89D6001F64F1 /* FoundationNSNumberTests.swift */, + 564A1FB3226B89DC001F64F1 /* FoundationNSStringTests.swift */, + 564A1F9E226B89DA001F64F1 /* FoundationNSURLTests.swift */, + 564A1F34226B89CF001F64F1 /* FoundationNSUUIDTests.swift */, + 564A1F30226B89CF001F64F1 /* FoundationURLTests.swift */, + 564A1FA1226B89DB001F64F1 /* FoundationUUIDTests.swift */, + 564A1FD0226B89E0001F64F1 /* FTS3PatternTests.swift */, + 564A1F66226B89D5001F64F1 /* FTS3RecordTests.swift */, + 564A1F72226B89D6001F64F1 /* FTS3TableBuilderTests.swift */, + 564A1FD9226B89E0001F64F1 /* FTS3TokenizerTests.swift */, + 564A1F8D226B89D9001F64F1 /* FTS4RecordTests.swift */, + 564A1F63226B89D5001F64F1 /* FTS4TableBuilderTests.swift */, + 564A1FB5226B89DD001F64F1 /* FTS5CustomTokenizerTests.swift */, + 564A1F8F226B89D9001F64F1 /* FTS5PatternTests.swift */, + 564A1FDD226B89E1001F64F1 /* FTS5RecordTests.swift */, + 564A1F8B226B89D9001F64F1 /* FTS5TableBuilderTests.swift */, + 564A1FC4226B89DE001F64F1 /* FTS5TokenizerTests.swift */, + 564A1F43226B89D0001F64F1 /* FTS5WrapperTokenizerTests.swift */, + 564A1FD5226B89E0001F64F1 /* GRDBTestCase.swift */, + 564A1F26226B89CD001F64F1 /* GRDBTests-Bridging-Header.h */, + 564A1F86226B89D8001F64F1 /* IndexInfoTests.swift */, + 564A1FCD226B89DF001F64F1 /* JoinSupportTests.swift */, + 564A1FB8226B89DD001F64F1 /* MapCursorTests.swift */, + 564A1FD3226B89E0001F64F1 /* MutablePersistableRecordChangesTests.swift */, + 564A1F27226B89CE001F64F1 /* MutablePersistableRecordDeleteTests.swift */, + 564A1F32226B89CF001F64F1 /* MutablePersistableRecordEncodableTests.swift */, + 564A1F98226B89DA001F64F1 /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */, + 564A1FCE226B89DF001F64F1 /* MutablePersistableRecordTests.swift */, + 564A1F2E226B89CF001F64F1 /* NumericOverflowTests.swift */, + 564A1FCB226B89DF001F64F1 /* PersistableRecordTests.swift */, + 564A1F49226B89D1001F64F1 /* PrefixCursorTests.swift */, + 564A1F46226B89D1001F64F1 /* PrefixWhileCursorTests.swift */, + 564A1F97226B89DA001F64F1 /* PrimaryKeyInfoTests.swift */, + 564A1F41226B89D0001F64F1 /* QueryInterfaceExpressionsTests.swift */, + 564A1F6E226B89D6001F64F1 /* QueryInterfaceExtensibilityTests.swift */, + 564A1F5F226B89D3001F64F1 /* QueryInterfacePromiseTests.swift */, + 564A1FA3226B89DB001F64F1 /* QueryInterfaceRequestTests.swift */, + 564A1F93226B89D9001F64F1 /* RawRepresentable+DatabaseValueConvertibleTests.swift */, + 564A1F76226B89D6001F64F1 /* Record+QueryInterfaceRequestTests.swift */, + 564A1FA4226B89DB001F64F1 /* RecordCopyTests.swift */, + 564A1F75226B89D6001F64F1 /* RecordEditedTests.swift */, + 564A1F51226B89D2001F64F1 /* RecordInitializersTests.swift */, + 564A1F77226B89D6001F64F1 /* RecordMinimalPrimaryKeyRowIDTests.swift */, + 564A1FAB226B89DC001F64F1 /* RecordMinimalPrimaryKeySingleTests.swift */, + 564A1F3B226B89D0001F64F1 /* RecordPersistenceConflictPolicy.swift */, + 564A1FA9226B89DB001F64F1 /* RecordPrimaryKeyHiddenRowIDTests.swift */, + 564A1F2D226B89CF001F64F1 /* RecordPrimaryKeyMultipleTests.swift */, + 564A1F4A226B89D1001F64F1 /* RecordPrimaryKeyNoneTests.swift */, + 564A1FC5226B89DE001F64F1 /* RecordPrimaryKeyRowIDTests.swift */, + 564A1F99226B89DA001F64F1 /* RecordPrimaryKeySingleTests.swift */, + 564A1FD1226B89E0001F64F1 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift */, + 564A1F5D226B89D3001F64F1 /* RecordSubClassTests.swift */, + 564A1FBE226B89DE001F64F1 /* RecordUniqueIndexTests.swift */, + 564A1F9A226B89DA001F64F1 /* RecordWithColumnNameManglingTests.swift */, + 564A1FA5226B89DB001F64F1 /* ResultCodeTests.swift */, + 564A1F7E226B89D7001F64F1 /* Row+FoundationTests.swift */, + 564A1F91226B89D9001F64F1 /* RowAdapterTests.swift */, + 564A1F29226B89CF001F64F1 /* RowCopiedFromStatementTests.swift */, + 564A1F7A226B89D7001F64F1 /* RowFetchTests.swift */, + 564A1F56226B89D2001F64F1 /* RowFromDictionaryLiteralTests.swift */, + 564A1F81226B89D7001F64F1 /* RowFromDictionaryTests.swift */, + 564A1F57226B89D3001F64F1 /* RowFromStatementTests.swift */, + 564A1F9B226B89DA001F64F1 /* RowTestCase.swift */, + 564A1F7F226B89D7001F64F1 /* SchedulingWatchdogTests.swift */, + 564A1F2A226B89CF001F64F1 /* SelectStatementTests.swift */, + 564A1F4E226B89D2001F64F1 /* SQLExpressionLiteralTests.swift */, + 564A1F4F226B89D2001F64F1 /* SQLInterpolationTests.swift */, + 564A1FA8226B89DB001F64F1 /* SQLLiteralTests.swift */, + 564A1F42226B89D0001F64F1 /* SQLRequestTests.swift */, + 564A1F58226B89D3001F64F1 /* StatementArguments+FoundationTests.swift */, + 564A1FC9226B89DF001F64F1 /* StatementArgumentsTests.swift */, + 564A1F89226B89D8001F64F1 /* StatementColumnConvertibleFetchTests.swift */, + 564A1F64226B89D5001F64F1 /* TableDefinitionTests.swift */, + 564A1FAA226B89DC001F64F1 /* TableRecord+QueryInterfaceRequestTests.swift */, + 564A1F9F226B89DA001F64F1 /* TableRecordTests.swift */, + 564A1F5B226B89D3001F64F1 /* TransactionObserverSavepointsTests.swift */, + 564A1FCA226B89DF001F64F1 /* TransactionObserverTests.swift */, + 564A1F3C226B89D0001F64F1 /* TruncateOptimizationTests.swift */, + 564A1FBD226B89DE001F64F1 /* UpdateStatementTests.swift */, + 564A1FB6226B89DD001F64F1 /* ValueObservationCombineTests.swift */, + 564A1FB9226B89DD001F64F1 /* ValueObservationCompactMapTests.swift */, + 564A1F84226B89D8001F64F1 /* ValueObservationCountTests.swift */, + 564A1F6C226B89D5001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift */, + 564A1FB7226B89DD001F64F1 /* ValueObservationExtentTests.swift */, + 564A1FC6226B89DF001F64F1 /* ValueObservationFetchTests.swift */, + 564A1F59226B89D3001F64F1 /* ValueObservationMapTests.swift */, + 5656A801229474DC001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */, + 564A1F85226B89D8001F64F1 /* ValueObservationReadonlyTests.swift */, + 564A1F44226B89D0001F64F1 /* ValueObservationRecordTests.swift */, + 564A1F87226B89D8001F64F1 /* ValueObservationReducerTests.swift */, + 564A1F9C226B89DA001F64F1 /* ValueObservationRowTests.swift */, + 564A1F48226B89D1001F64F1 /* ValueObservationSchedulingTests.swift */, + 564A1FBA226B89DD001F64F1 /* VirtualTableModuleTests.swift */, + ); + name = GRDBTests; + path = ../../GRDBTests; + sourceTree = ""; + }; + A39D84C3D9EF90DA939D10D7 /* Pods */ = { + isa = PBXGroup; + children = ( + 6A4788C0F815F6C5E4EBDE12 /* Pods-GRDBTests.debug.xcconfig */, + 04298D834C818285823558AB /* Pods-GRDBTests.release.xcconfig */, + 83BFB5733A86DAA3D0BEE684 /* Pods-GRDBTestsEncrypted.debug.xcconfig */, + 47C5D1B9AFFE795AA1D6EA5D /* Pods-GRDBTestsEncrypted.release.xcconfig */, + ); + path = Pods; + sourceTree = ""; + }; + EAA416B3A072FCB835929FD9 /* Frameworks */ = { + isa = PBXGroup; + children = ( + BEFDC53B1F7A33C242013A38 /* Pods_GRDBTests.framework */, + 7D5C7999E7D9CE7145687F5D /* Pods_GRDBTestsEncrypted.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 564A1F1C226B876D001F64F1 /* GRDBTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 564A1F23226B876D001F64F1 /* Build configuration list for PBXNativeTarget "GRDBTests" */; + buildPhases = ( + ED302FF19B64F1E73F967816 /* [CP] Check Pods Manifest.lock */, + 564A1F19226B876D001F64F1 /* Sources */, + 564A1F1A226B876D001F64F1 /* Frameworks */, + 564A1F1B226B876D001F64F1 /* Resources */, + 4B0FE810DCA4C7A83E571F34 /* [CP] Embed Pods Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = GRDBTests; + productName = GRDBTests; + productReference = 564A1F1D226B876D001F64F1 /* GRDBTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + 564A2095226B8E18001F64F1 /* GRDBTestsEncrypted */ = { + isa = PBXNativeTarget; + buildConfigurationList = 564A2153226B8E18001F64F1 /* Build configuration list for PBXNativeTarget "GRDBTestsEncrypted" */; + buildPhases = ( + 564A2096226B8E18001F64F1 /* [CP] Check Pods Manifest.lock */, + 564A2097226B8E18001F64F1 /* Sources */, + 564A214E226B8E18001F64F1 /* Frameworks */, + 564A2150226B8E18001F64F1 /* Resources */, + 564A2152226B8E18001F64F1 /* [CP] Embed Pods Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = GRDBTestsEncrypted; + productName = GRDBTests; + productReference = 564A2156226B8E18001F64F1 /* GRDBTestsEncrypted.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 564A1F13226B8750001F64F1 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1020; + LastUpgradeCheck = 1020; + TargetAttributes = { + 564A1F1C226B876D001F64F1 = { + CreatedOnToolsVersion = 10.2.1; + LastSwiftMigration = 1020; + }; + }; + }; + buildConfigurationList = 564A1F16226B8750001F64F1 /* Build configuration list for PBXProject "GRDBTests" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 564A1F12226B8750001F64F1; + productRefGroup = 564A1F1E226B876D001F64F1 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 564A1F1C226B876D001F64F1 /* GRDBTests */, + 564A2095226B8E18001F64F1 /* GRDBTestsEncrypted */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 564A1F1B226B876D001F64F1 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 564A2026226B89E1001F64F1 /* Betty.jpeg in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 564A2150226B8E18001F64F1 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 564A2151226B8E18001F64F1 /* Betty.jpeg in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 4B0FE810DCA4C7A83E571F34 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-GRDBTests/Pods-GRDBTests-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/GRDB.swift/GRDB.framework", + "${BUILT_PRODUCTS_DIR}/SQLCipher/SQLCipher.framework", + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + ); + outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GRDB.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SQLCipher.framework", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-GRDBTests/Pods-GRDBTests-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + 564A2096226B8E18001F64F1 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-GRDBTestsEncrypted-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + 564A2152226B8E18001F64F1 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-GRDBTestsEncrypted/Pods-GRDBTestsEncrypted-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/GRDB.swift/GRDB.framework", + "${BUILT_PRODUCTS_DIR}/SQLCipher/SQLCipher.framework", + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + ); + outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GRDB.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SQLCipher.framework", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-GRDBTestsEncrypted/Pods-GRDBTestsEncrypted-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + ED302FF19B64F1E73F967816 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-GRDBTests-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 564A1F19226B876D001F64F1 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 564A2024226B89E1001F64F1 /* DropWhileCursorTests.swift in Sources */, + 564A2021226B89E1001F64F1 /* DatabasePoolBackupTests.swift in Sources */, + 564A1FE8226B89E1001F64F1 /* DatabaseAggregateTests.swift in Sources */, + 564A1FEE226B89E1001F64F1 /* DatabaseFunctionTests.swift in Sources */, + 564A2083226B89E1001F64F1 /* DataMemoryTests.swift in Sources */, + 564A207F226B89E1001F64F1 /* DatabaseQueueSchemaCacheTests.swift in Sources */, + 564A201D226B89E1001F64F1 /* FTS3RecordTests.swift in Sources */, + 564A205C226B89E1001F64F1 /* ResultCodeTests.swift in Sources */, + 564A1FF2226B89E1001F64F1 /* RecordPersistenceConflictPolicy.swift in Sources */, + 56DF0027228DE00900D611F3 /* AssociationPrefetchingCodableRecordTests.swift in Sources */, + 564A1FEF226B89E1001F64F1 /* FetchedRecordsControllerTests.swift in Sources */, + 564A2075226B89E1001F64F1 /* RecordUniqueIndexTests.swift in Sources */, + 564A2058226B89E1001F64F1 /* FoundationUUIDTests.swift in Sources */, + 564A2049226B89E1001F64F1 /* DatabaseQueueReadOnlyTests.swift in Sources */, + 564A1FF0226B89E1001F64F1 /* AssociationHasOneThroughDecodableRecordTests.swift in Sources */, + 564A1FEA226B89E1001F64F1 /* AssociationChainRowScopesTests.swift in Sources */, + 564A1FFF226B89E1001F64F1 /* ValueObservationSchedulingTests.swift in Sources */, + 564A207D226B89E1001F64F1 /* ValueObservationFetchTests.swift in Sources */, + 564A203C226B89E1001F64F1 /* ValueObservationReadonlyTests.swift in Sources */, + 564A203B226B89E1001F64F1 /* ValueObservationCountTests.swift in Sources */, + 564A2053226B89E1001F64F1 /* ValueObservationRowTests.swift in Sources */, + 564A2048226B89E1001F64F1 /* RowAdapterTests.swift in Sources */, + 564A2040226B89E1001F64F1 /* StatementColumnConvertibleFetchTests.swift in Sources */, + 564A2019226B89E1001F64F1 /* DatabasePoolReleaseMemoryTests.swift in Sources */, + 560714F0227DD1810091BB10 /* AssociationPrefetchingSQLTests.swift in Sources */, + 564A2080226B89E1001F64F1 /* StatementArgumentsTests.swift in Sources */, + 564A2082226B89E1001F64F1 /* PersistableRecordTests.swift in Sources */, + 564A2016226B89E1001F64F1 /* QueryInterfacePromiseTests.swift in Sources */, + 564A207E226B89E1001F64F1 /* DatabaseTests.swift in Sources */, + 564A2033226B89E1001F64F1 /* AssociationHasManySQLTests.swift in Sources */, + 564A204A226B89E1001F64F1 /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */, + 564A207B226B89E1001F64F1 /* FTS5TokenizerTests.swift in Sources */, + 564A202D226B89E1001F64F1 /* Record+QueryInterfaceRequestTests.swift in Sources */, + 564A2044226B89E1001F64F1 /* FTS4RecordTests.swift in Sources */, + 564A2086226B89E1001F64F1 /* AssociationTableAliasTestsSQLTests.swift in Sources */, + 564A2012226B89E1001F64F1 /* TransactionObserverSavepointsTests.swift in Sources */, + 564A200C226B89E1001F64F1 /* DatabaseRegionObservationTests.swift in Sources */, + 564A1FDE226B89E1001F64F1 /* MutablePersistableRecordDeleteTests.swift in Sources */, + 564A2072226B89E1001F64F1 /* DropFirstCursorTests.swift in Sources */, + 564A1FE9226B89E1001F64F1 /* MutablePersistableRecordEncodableTests.swift in Sources */, + 564A2003226B89E1001F64F1 /* DatabaseValueConvertibleFetchTests.swift in Sources */, + 564A2041226B89E1001F64F1 /* CGFloatTests.swift in Sources */, + 564A201E226B89E1001F64F1 /* DatabaseCursorTests.swift in Sources */, + 564A1FF9226B89E1001F64F1 /* SQLRequestTests.swift in Sources */, + 564A201B226B89E1001F64F1 /* TableDefinitionTests.swift in Sources */, + 564A202B226B89E1001F64F1 /* CompilationSubClassTests.swift in Sources */, + 564A2046226B89E1001F64F1 /* FTS5PatternTests.swift in Sources */, + 564A202F226B89E1001F64F1 /* DatabasePoolSchemaCacheTests.swift in Sources */, + 564A202C226B89E1001F64F1 /* RecordEditedTests.swift in Sources */, + 564A1FFB226B89E1001F64F1 /* ValueObservationRecordTests.swift in Sources */, + 564A2020226B89E1001F64F1 /* DatabaseRegionTests.swift in Sources */, + 564A201F226B89E1001F64F1 /* DatabaseQueueReleaseMemoryTests.swift in Sources */, + 564A2000226B89E1001F64F1 /* PrefixCursorTests.swift in Sources */, + 564A1FE1226B89E1001F64F1 /* SelectStatementTests.swift in Sources */, + 564A1FF8226B89E1001F64F1 /* QueryInterfaceExpressionsTests.swift in Sources */, + 564A202E226B89E1001F64F1 /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */, + 564A2078226B89E1001F64F1 /* ForeignKeyInfoTests.swift in Sources */, + 564A2050226B89E1001F64F1 /* RecordPrimaryKeySingleTests.swift in Sources */, + 564A2091226B89E1001F64F1 /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */, + 564A208F226B89E1001F64F1 /* AssociationParallelRowScopesTests.swift in Sources */, + 564A2047226B89E1001F64F1 /* AnyCursorTests.swift in Sources */, + 564A1FFC226B89E1001F64F1 /* DatabaseValueTests.swift in Sources */, + 564A200E226B89E1001F64F1 /* RowFromStatementTests.swift in Sources */, + 564A2069226B89E1001F64F1 /* FlattenCursorTests.swift in Sources */, + 564A2008226B89E1001F64F1 /* RecordInitializersTests.swift in Sources */, + 564A2018226B89E1001F64F1 /* ColumnExpressionTests.swift in Sources */, + 564A2023226B89E1001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift in Sources */, + 564A2010226B89E1001F64F1 /* ValueObservationMapTests.swift in Sources */, + 564A204F226B89E1001F64F1 /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */, + 564A206B226B89E1001F64F1 /* AssociationHasManyThroughSQLTests.swift in Sources */, + 564A2087226B89E1001F64F1 /* FTS3PatternTests.swift in Sources */, + 564A2067226B89E1001F64F1 /* EnumeratedCursorTests.swift in Sources */, + 564A1FF1226B89E1001F64F1 /* DatabaseValueConvertibleSubclassTests.swift in Sources */, + 564A2015226B89E1001F64F1 /* EncryptionTests.swift in Sources */, + 564A2032226B89E1001F64F1 /* AssociationBelongsToFetchableRecordTests.swift in Sources */, + 56057C5F2291B8E400A7CB10 /* AssociationHasManyRowScopeTests.swift in Sources */, + 564A1FE7226B89E1001F64F1 /* FoundationURLTests.swift in Sources */, + 564A1FFD226B89E1001F64F1 /* PrefixWhileCursorTests.swift in Sources */, + 564A2079226B89E1001F64F1 /* FoundationNSDecimalNumberTests.swift in Sources */, + 564A200A226B89E1001F64F1 /* DatabaseCollationTests.swift in Sources */, + 564A2061226B89E1001F64F1 /* TableRecord+QueryInterfaceRequestTests.swift in Sources */, + 564A2077226B89E1001F64F1 /* DatabaseWriterTests.swift in Sources */, + 564A1FE6226B89E1001F64F1 /* DatabaseQueueInMemoryTests.swift in Sources */, + 564A2064226B89E1001F64F1 /* AssociationHasOneThroughFetchableRecordTests.swift in Sources */, + 564A1FFA226B89E1001F64F1 /* FTS5WrapperTokenizerTests.swift in Sources */, + 564A2056226B89E1001F64F1 /* TableRecordTests.swift in Sources */, + 564A2042226B89E1001F64F1 /* FTS5TableBuilderTests.swift in Sources */, + 564A2089226B89E1001F64F1 /* DatabaseValueConversionErrorTests.swift in Sources */, + 564A2081226B89E1001F64F1 /* TransactionObserverTests.swift in Sources */, + 564A2045226B89E1001F64F1 /* FetchableRecordDecodableTests.swift in Sources */, + 564A1FF4226B89E1001F64F1 /* DatabasePoolCollationTests.swift in Sources */, + 564A2025226B89E1001F64F1 /* QueryInterfaceExtensibilityTests.swift in Sources */, + 564A2038226B89E1001F64F1 /* RowFromDictionaryTests.swift in Sources */, + 564A200B226B89E1001F64F1 /* DatabaseDateEncodingStrategyTests.swift in Sources */, + 564A2070226B89E1001F64F1 /* ValueObservationCompactMapTests.swift in Sources */, + 564A205D226B89E1001F64F1 /* DatabaseValueConvertibleEscapingTests.swift in Sources */, + 564A2068226B89E1001F64F1 /* DatabaseQueueConcurrencyTests.swift in Sources */, + 564A2017226B89E1001F64F1 /* AssociationAggregateTests.swift in Sources */, + 564A2065226B89E1001F64F1 /* AssociationHasOneSQLDerivationTests.swift in Sources */, + 564A200F226B89E1001F64F1 /* StatementArguments+FoundationTests.swift in Sources */, + 564A207A226B89E1001F64F1 /* FoundationDateComponentsTests.swift in Sources */, + 564A204E226B89E1001F64F1 /* PrimaryKeyInfoTests.swift in Sources */, + 564A2085226B89E1001F64F1 /* MutablePersistableRecordTests.swift in Sources */, + 564A2037226B89E1001F64F1 /* AssociationBelongsToSQLDerivationTests.swift in Sources */, + 564A201C226B89E1001F64F1 /* DatabaseErrorTests.swift in Sources */, + 564A208D226B89E1001F64F1 /* DatabaseUUIDEncodingStrategyTests.swift in Sources */, + 564A204D226B89E1001F64F1 /* DatabaseQueueTests.swift in Sources */, + 564A2013226B89E1001F64F1 /* DatabaseLogErrorTests.swift in Sources */, + 564A1FE4226B89E1001F64F1 /* RecordPrimaryKeyMultipleTests.swift in Sources */, + 564A202A226B89E1001F64F1 /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */, + 564A2093226B89E1001F64F1 /* AssociationParallelSQLTests.swift in Sources */, + 564A2063226B89E1001F64F1 /* ColumnInfoTests.swift in Sources */, + 564A1FE3226B89E1001F64F1 /* DatabaseValueConvertibleEncodableTests.swift in Sources */, + 564A1FF5226B89E1001F64F1 /* AssociationRowScopeSearchTests.swift in Sources */, + 564A2034226B89E1001F64F1 /* FoundationNSDateTests.swift in Sources */, + 564A1FDF226B89E1001F64F1 /* AssociationHasOneThroughRowScopeTests.swift in Sources */, + 564A2054226B89E1001F64F1 /* AssociationHasOneSQLTests.swift in Sources */, + 564A2028226B89E1001F64F1 /* FoundationNSNumberTests.swift in Sources */, + 564A2005226B89E1001F64F1 /* SQLExpressionLiteralTests.swift in Sources */, + 564A203F226B89E1001F64F1 /* AssociationBelongsToRowScopeTests.swift in Sources */, + 564A2030226B89E1001F64F1 /* DatabaseSavepointTests.swift in Sources */, + 564A206A226B89E1001F64F1 /* FoundationNSStringTests.swift in Sources */, + 564A206E226B89E1001F64F1 /* ValueObservationExtentTests.swift in Sources */, + 5656A802229474DD001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift in Sources */, + 564A2066226B89E1001F64F1 /* DatabaseTimestampTests.swift in Sources */, + 564A204B226B89E1001F64F1 /* FoundationNSDataTests.swift in Sources */, + 564A2009226B89E1001F64F1 /* AssociationHasOneThroughSQLTests.swift in Sources */, + 564A2090226B89E1001F64F1 /* FTS3TokenizerTests.swift in Sources */, + 564A2076226B89E1001F64F1 /* DatabaseReaderTests.swift in Sources */, + 564A2071226B89E1001F64F1 /* VirtualTableModuleTests.swift in Sources */, + 564A2084226B89E1001F64F1 /* JoinSupportTests.swift in Sources */, + 564A207C226B89E1001F64F1 /* RecordPrimaryKeyRowIDTests.swift in Sources */, + 564A2094226B89E1001F64F1 /* FTS5RecordTests.swift in Sources */, + 564A203D226B89E1001F64F1 /* IndexInfoTests.swift in Sources */, + 564A204C226B89E1001F64F1 /* AssociationBelongsToSQLTests.swift in Sources */, + 564A200D226B89E1001F64F1 /* RowFromDictionaryLiteralTests.swift in Sources */, + 564A205E226B89E1001F64F1 /* FoundationNSNullTests.swift in Sources */, + 564A208E226B89E1001F64F1 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */, + 564A2029226B89E1001F64F1 /* FTS3TableBuilderTests.swift in Sources */, + 564A2001226B89E1001F64F1 /* RecordPrimaryKeyNoneTests.swift in Sources */, + 564A2051226B89E1001F64F1 /* RecordWithColumnNameManglingTests.swift in Sources */, + 564A205B226B89E1001F64F1 /* RecordCopyTests.swift in Sources */, + 564A205F226B89E1001F64F1 /* SQLLiteralTests.swift in Sources */, + 564A206C226B89E1001F64F1 /* FTS5CustomTokenizerTests.swift in Sources */, + 564A2002226B89E1001F64F1 /* DerivableRequestTests.swift in Sources */, + 56057C682291D0AC00A7CB10 /* AssociationHasManyThroughRowScopeTests.swift in Sources */, + 564A1FEB226B89E1001F64F1 /* FoundationNSUUIDTests.swift in Sources */, + 564A1FFE226B89E1001F64F1 /* FilterCursorTests.swift in Sources */, + 564A208A226B89E1001F64F1 /* MutablePersistableRecordChangesTests.swift in Sources */, + 564A2092226B89E1001F64F1 /* DatabasePoolConcurrencyTests.swift in Sources */, + 564A1FE0226B89E1001F64F1 /* RowCopiedFromStatementTests.swift in Sources */, + 564A2007226B89E1001F64F1 /* FoundationDataTests.swift in Sources */, + 564A201A226B89E1001F64F1 /* FTS4TableBuilderTests.swift in Sources */, + 564A2059226B89E1001F64F1 /* DatabaseValueConversionTests.swift in Sources */, + 564A1FE2226B89E1001F64F1 /* DatabaseQueueBackupTests.swift in Sources */, + 56DF0029228DE00900D611F3 /* AssociationPrefetchingRowTests.swift in Sources */, + 564A1FF7226B89E1001F64F1 /* DatabaseValueConvertibleDecodableTests.swift in Sources */, + 564A2074226B89E1001F64F1 /* UpdateStatementTests.swift in Sources */, + 564A203E226B89E1001F64F1 /* ValueObservationReducerTests.swift in Sources */, + 564A2035226B89E1001F64F1 /* Row+FoundationTests.swift in Sources */, + 569BBA31228DF91000478429 /* AssociationPrefetchingFetchableRecordTests.swift in Sources */, + 564A205A226B89E1001F64F1 /* QueryInterfaceRequestTests.swift in Sources */, + 564A2011226B89E1001F64F1 /* FetchRequestTests.swift in Sources */, + 564A2060226B89E1001F64F1 /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */, + 564A2004226B89E1001F64F1 /* AssociationChainSQLTests.swift in Sources */, + 564A208C226B89E1001F64F1 /* GRDBTestCase.swift in Sources */, + 564A1FED226B89E1001F64F1 /* CompilationProtocolTests.swift in Sources */, + 564A2014226B89E1001F64F1 /* RecordSubClassTests.swift in Sources */, + 564A2027226B89E1001F64F1 /* AssociationParallelDecodableRecordTests.swift in Sources */, + 564A1FEC226B89E1001F64F1 /* AssociationBelongsToDecodableRecordTests.swift in Sources */, + 564A208B226B89E1001F64F1 /* DatabaseMigratorTests.swift in Sources */, + 564A206D226B89E1001F64F1 /* ValueObservationCombineTests.swift in Sources */, + 564A2022226B89E1001F64F1 /* CursorTests.swift in Sources */, + 564A203A226B89E1001F64F1 /* DatabaseDateDecodingStrategyTests.swift in Sources */, + 560432A9228F1752009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */, + 564A2036226B89E1001F64F1 /* SchedulingWatchdogTests.swift in Sources */, + 564A2052226B89E1001F64F1 /* RowTestCase.swift in Sources */, + 564A1FF3226B89E1001F64F1 /* TruncateOptimizationTests.swift in Sources */, + 564A2088226B89E1001F64F1 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */, + 564A2039226B89E1001F64F1 /* DatabasePoolReadOnlyTests.swift in Sources */, + 564A2055226B89E1001F64F1 /* FoundationNSURLTests.swift in Sources */, + 564A2073226B89E1001F64F1 /* FetchableRecordTests.swift in Sources */, + 564A2031226B89E1001F64F1 /* RowFetchTests.swift in Sources */, + 564A1FF6226B89E1001F64F1 /* DatabaseSnapshotTests.swift in Sources */, + 564A2057226B89E1001F64F1 /* FoundationDateTests.swift in Sources */, + 564A2043226B89E1001F64F1 /* DatabasePoolFunctionTests.swift in Sources */, + 564A2006226B89E1001F64F1 /* SQLInterpolationTests.swift in Sources */, + 564A206F226B89E1001F64F1 /* MapCursorTests.swift in Sources */, + 564A1FE5226B89E1001F64F1 /* NumericOverflowTests.swift in Sources */, + 564A2062226B89E1001F64F1 /* RecordMinimalPrimaryKeySingleTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 564A2097226B8E18001F64F1 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 564A2098226B8E18001F64F1 /* DropWhileCursorTests.swift in Sources */, + 564A2099226B8E18001F64F1 /* DatabasePoolBackupTests.swift in Sources */, + 564A209A226B8E18001F64F1 /* DatabaseAggregateTests.swift in Sources */, + 564A209B226B8E18001F64F1 /* DatabaseFunctionTests.swift in Sources */, + 564A209C226B8E18001F64F1 /* DataMemoryTests.swift in Sources */, + 564A209D226B8E18001F64F1 /* DatabaseQueueSchemaCacheTests.swift in Sources */, + 564A209E226B8E18001F64F1 /* FTS3RecordTests.swift in Sources */, + 564A209F226B8E18001F64F1 /* ResultCodeTests.swift in Sources */, + 564A20A0226B8E18001F64F1 /* RecordPersistenceConflictPolicy.swift in Sources */, + 56DF0028228DE00900D611F3 /* AssociationPrefetchingCodableRecordTests.swift in Sources */, + 564A20A1226B8E18001F64F1 /* FetchedRecordsControllerTests.swift in Sources */, + 564A20A2226B8E18001F64F1 /* RecordUniqueIndexTests.swift in Sources */, + 564A20A3226B8E18001F64F1 /* FoundationUUIDTests.swift in Sources */, + 564A20A4226B8E18001F64F1 /* DatabaseQueueReadOnlyTests.swift in Sources */, + 564A20A5226B8E18001F64F1 /* AssociationHasOneThroughDecodableRecordTests.swift in Sources */, + 564A20A6226B8E18001F64F1 /* AssociationChainRowScopesTests.swift in Sources */, + 564A20A7226B8E18001F64F1 /* ValueObservationSchedulingTests.swift in Sources */, + 564A20A8226B8E18001F64F1 /* ValueObservationFetchTests.swift in Sources */, + 564A20A9226B8E18001F64F1 /* ValueObservationReadonlyTests.swift in Sources */, + 564A20AA226B8E18001F64F1 /* ValueObservationCountTests.swift in Sources */, + 564A20AB226B8E18001F64F1 /* ValueObservationRowTests.swift in Sources */, + 564A20AC226B8E18001F64F1 /* RowAdapterTests.swift in Sources */, + 564A20AD226B8E18001F64F1 /* StatementColumnConvertibleFetchTests.swift in Sources */, + 564A20AE226B8E18001F64F1 /* DatabasePoolReleaseMemoryTests.swift in Sources */, + 560714F1227DD1810091BB10 /* AssociationPrefetchingSQLTests.swift in Sources */, + 564A20AF226B8E18001F64F1 /* StatementArgumentsTests.swift in Sources */, + 564A20B0226B8E18001F64F1 /* PersistableRecordTests.swift in Sources */, + 564A20B1226B8E18001F64F1 /* QueryInterfacePromiseTests.swift in Sources */, + 564A20B2226B8E18001F64F1 /* DatabaseTests.swift in Sources */, + 564A20B3226B8E18001F64F1 /* AssociationHasManySQLTests.swift in Sources */, + 564A20B4226B8E18001F64F1 /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */, + 564A20B5226B8E18001F64F1 /* FTS5TokenizerTests.swift in Sources */, + 564A20B6226B8E18001F64F1 /* Record+QueryInterfaceRequestTests.swift in Sources */, + 564A20B7226B8E18001F64F1 /* FTS4RecordTests.swift in Sources */, + 564A20B8226B8E18001F64F1 /* AssociationTableAliasTestsSQLTests.swift in Sources */, + 564A20B9226B8E18001F64F1 /* TransactionObserverSavepointsTests.swift in Sources */, + 564A20BA226B8E18001F64F1 /* DatabaseRegionObservationTests.swift in Sources */, + 564A20BB226B8E18001F64F1 /* MutablePersistableRecordDeleteTests.swift in Sources */, + 564A20BC226B8E18001F64F1 /* DropFirstCursorTests.swift in Sources */, + 564A20BD226B8E18001F64F1 /* MutablePersistableRecordEncodableTests.swift in Sources */, + 564A20BE226B8E18001F64F1 /* DatabaseValueConvertibleFetchTests.swift in Sources */, + 564A20BF226B8E18001F64F1 /* CGFloatTests.swift in Sources */, + 564A20C0226B8E18001F64F1 /* DatabaseCursorTests.swift in Sources */, + 564A20C1226B8E18001F64F1 /* SQLRequestTests.swift in Sources */, + 564A20C2226B8E18001F64F1 /* TableDefinitionTests.swift in Sources */, + 564A20C3226B8E18001F64F1 /* CompilationSubClassTests.swift in Sources */, + 564A20C4226B8E18001F64F1 /* FTS5PatternTests.swift in Sources */, + 564A20C5226B8E18001F64F1 /* DatabasePoolSchemaCacheTests.swift in Sources */, + 564A20C6226B8E18001F64F1 /* RecordEditedTests.swift in Sources */, + 564A20C7226B8E18001F64F1 /* ValueObservationRecordTests.swift in Sources */, + 564A20C8226B8E18001F64F1 /* DatabaseRegionTests.swift in Sources */, + 564A20C9226B8E18001F64F1 /* DatabaseQueueReleaseMemoryTests.swift in Sources */, + 564A20CA226B8E18001F64F1 /* PrefixCursorTests.swift in Sources */, + 564A20CB226B8E18001F64F1 /* SelectStatementTests.swift in Sources */, + 564A20CC226B8E18001F64F1 /* QueryInterfaceExpressionsTests.swift in Sources */, + 564A20CD226B8E18001F64F1 /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */, + 564A20CE226B8E18001F64F1 /* ForeignKeyInfoTests.swift in Sources */, + 564A20CF226B8E18001F64F1 /* RecordPrimaryKeySingleTests.swift in Sources */, + 564A20D0226B8E18001F64F1 /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */, + 564A20D1226B8E18001F64F1 /* AssociationParallelRowScopesTests.swift in Sources */, + 564A20D2226B8E18001F64F1 /* AnyCursorTests.swift in Sources */, + 564A20D3226B8E18001F64F1 /* DatabaseValueTests.swift in Sources */, + 564A20D4226B8E18001F64F1 /* RowFromStatementTests.swift in Sources */, + 564A20D5226B8E18001F64F1 /* FlattenCursorTests.swift in Sources */, + 564A20D6226B8E18001F64F1 /* RecordInitializersTests.swift in Sources */, + 564A20D7226B8E18001F64F1 /* ColumnExpressionTests.swift in Sources */, + 564A20D8226B8E18001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift in Sources */, + 564A20D9226B8E18001F64F1 /* ValueObservationMapTests.swift in Sources */, + 564A20DA226B8E18001F64F1 /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */, + 564A20DB226B8E18001F64F1 /* AssociationHasManyThroughSQLTests.swift in Sources */, + 564A20DC226B8E18001F64F1 /* FTS3PatternTests.swift in Sources */, + 564A20DD226B8E18001F64F1 /* EnumeratedCursorTests.swift in Sources */, + 564A20DE226B8E18001F64F1 /* DatabaseValueConvertibleSubclassTests.swift in Sources */, + 564A20DF226B8E18001F64F1 /* EncryptionTests.swift in Sources */, + 564A20E0226B8E18001F64F1 /* AssociationBelongsToFetchableRecordTests.swift in Sources */, + 56057C602291B8E400A7CB10 /* AssociationHasManyRowScopeTests.swift in Sources */, + 564A20E1226B8E18001F64F1 /* FoundationURLTests.swift in Sources */, + 564A20E2226B8E18001F64F1 /* PrefixWhileCursorTests.swift in Sources */, + 564A20E3226B8E18001F64F1 /* FoundationNSDecimalNumberTests.swift in Sources */, + 564A20E4226B8E18001F64F1 /* DatabaseCollationTests.swift in Sources */, + 564A20E5226B8E18001F64F1 /* TableRecord+QueryInterfaceRequestTests.swift in Sources */, + 564A20E6226B8E18001F64F1 /* DatabaseWriterTests.swift in Sources */, + 564A20E7226B8E18001F64F1 /* DatabaseQueueInMemoryTests.swift in Sources */, + 564A20E8226B8E18001F64F1 /* AssociationHasOneThroughFetchableRecordTests.swift in Sources */, + 564A20E9226B8E18001F64F1 /* FTS5WrapperTokenizerTests.swift in Sources */, + 564A20EA226B8E18001F64F1 /* TableRecordTests.swift in Sources */, + 564A20EB226B8E18001F64F1 /* FTS5TableBuilderTests.swift in Sources */, + 564A20EC226B8E18001F64F1 /* DatabaseValueConversionErrorTests.swift in Sources */, + 564A20ED226B8E18001F64F1 /* TransactionObserverTests.swift in Sources */, + 564A20EE226B8E18001F64F1 /* FetchableRecordDecodableTests.swift in Sources */, + 564A20EF226B8E18001F64F1 /* DatabasePoolCollationTests.swift in Sources */, + 564A20F0226B8E18001F64F1 /* QueryInterfaceExtensibilityTests.swift in Sources */, + 564A20F1226B8E18001F64F1 /* RowFromDictionaryTests.swift in Sources */, + 564A20F2226B8E18001F64F1 /* DatabaseDateEncodingStrategyTests.swift in Sources */, + 564A20F3226B8E18001F64F1 /* ValueObservationCompactMapTests.swift in Sources */, + 564A20F4226B8E18001F64F1 /* DatabaseValueConvertibleEscapingTests.swift in Sources */, + 564A20F5226B8E18001F64F1 /* DatabaseQueueConcurrencyTests.swift in Sources */, + 564A20F6226B8E18001F64F1 /* AssociationAggregateTests.swift in Sources */, + 564A20F7226B8E18001F64F1 /* AssociationHasOneSQLDerivationTests.swift in Sources */, + 564A20F8226B8E18001F64F1 /* StatementArguments+FoundationTests.swift in Sources */, + 564A20F9226B8E18001F64F1 /* FoundationDateComponentsTests.swift in Sources */, + 564A20FA226B8E18001F64F1 /* PrimaryKeyInfoTests.swift in Sources */, + 564A20FB226B8E18001F64F1 /* MutablePersistableRecordTests.swift in Sources */, + 564A20FC226B8E18001F64F1 /* AssociationBelongsToSQLDerivationTests.swift in Sources */, + 564A20FD226B8E18001F64F1 /* DatabaseErrorTests.swift in Sources */, + 564A20FE226B8E18001F64F1 /* DatabaseUUIDEncodingStrategyTests.swift in Sources */, + 564A20FF226B8E18001F64F1 /* DatabaseQueueTests.swift in Sources */, + 564A2100226B8E18001F64F1 /* DatabaseLogErrorTests.swift in Sources */, + 564A2101226B8E18001F64F1 /* RecordPrimaryKeyMultipleTests.swift in Sources */, + 564A2102226B8E18001F64F1 /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */, + 564A2103226B8E18001F64F1 /* AssociationParallelSQLTests.swift in Sources */, + 564A2104226B8E18001F64F1 /* ColumnInfoTests.swift in Sources */, + 564A2105226B8E18001F64F1 /* DatabaseValueConvertibleEncodableTests.swift in Sources */, + 564A2106226B8E18001F64F1 /* AssociationRowScopeSearchTests.swift in Sources */, + 564A2107226B8E18001F64F1 /* FoundationNSDateTests.swift in Sources */, + 564A2108226B8E18001F64F1 /* AssociationHasOneThroughRowScopeTests.swift in Sources */, + 564A2109226B8E18001F64F1 /* AssociationHasOneSQLTests.swift in Sources */, + 564A210A226B8E18001F64F1 /* FoundationNSNumberTests.swift in Sources */, + 564A210B226B8E18001F64F1 /* SQLExpressionLiteralTests.swift in Sources */, + 564A210C226B8E18001F64F1 /* AssociationBelongsToRowScopeTests.swift in Sources */, + 564A210D226B8E18001F64F1 /* DatabaseSavepointTests.swift in Sources */, + 564A210E226B8E18001F64F1 /* FoundationNSStringTests.swift in Sources */, + 564A210F226B8E18001F64F1 /* ValueObservationExtentTests.swift in Sources */, + 5656A803229474DD001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift in Sources */, + 564A2110226B8E18001F64F1 /* DatabaseTimestampTests.swift in Sources */, + 564A2111226B8E18001F64F1 /* FoundationNSDataTests.swift in Sources */, + 564A2112226B8E18001F64F1 /* AssociationHasOneThroughSQLTests.swift in Sources */, + 564A2113226B8E18001F64F1 /* FTS3TokenizerTests.swift in Sources */, + 564A2114226B8E18001F64F1 /* DatabaseReaderTests.swift in Sources */, + 564A2115226B8E18001F64F1 /* VirtualTableModuleTests.swift in Sources */, + 564A2116226B8E18001F64F1 /* JoinSupportTests.swift in Sources */, + 564A2117226B8E18001F64F1 /* RecordPrimaryKeyRowIDTests.swift in Sources */, + 564A2118226B8E18001F64F1 /* FTS5RecordTests.swift in Sources */, + 564A2119226B8E18001F64F1 /* IndexInfoTests.swift in Sources */, + 564A211A226B8E18001F64F1 /* AssociationBelongsToSQLTests.swift in Sources */, + 564A211B226B8E18001F64F1 /* RowFromDictionaryLiteralTests.swift in Sources */, + 564A211C226B8E18001F64F1 /* FoundationNSNullTests.swift in Sources */, + 564A211D226B8E18001F64F1 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */, + 564A211E226B8E18001F64F1 /* FTS3TableBuilderTests.swift in Sources */, + 564A211F226B8E18001F64F1 /* RecordPrimaryKeyNoneTests.swift in Sources */, + 564A2120226B8E18001F64F1 /* RecordWithColumnNameManglingTests.swift in Sources */, + 564A2121226B8E18001F64F1 /* RecordCopyTests.swift in Sources */, + 564A2122226B8E18001F64F1 /* SQLLiteralTests.swift in Sources */, + 564A2123226B8E18001F64F1 /* FTS5CustomTokenizerTests.swift in Sources */, + 564A2124226B8E18001F64F1 /* DerivableRequestTests.swift in Sources */, + 56057C692291D0AC00A7CB10 /* AssociationHasManyThroughRowScopeTests.swift in Sources */, + 564A2125226B8E18001F64F1 /* FoundationNSUUIDTests.swift in Sources */, + 564A2126226B8E18001F64F1 /* FilterCursorTests.swift in Sources */, + 564A2127226B8E18001F64F1 /* MutablePersistableRecordChangesTests.swift in Sources */, + 564A2128226B8E18001F64F1 /* DatabasePoolConcurrencyTests.swift in Sources */, + 564A2129226B8E18001F64F1 /* RowCopiedFromStatementTests.swift in Sources */, + 564A212A226B8E18001F64F1 /* FoundationDataTests.swift in Sources */, + 564A212B226B8E18001F64F1 /* FTS4TableBuilderTests.swift in Sources */, + 564A212C226B8E18001F64F1 /* DatabaseValueConversionTests.swift in Sources */, + 564A212D226B8E18001F64F1 /* DatabaseQueueBackupTests.swift in Sources */, + 56DF002A228DE00900D611F3 /* AssociationPrefetchingRowTests.swift in Sources */, + 564A212E226B8E18001F64F1 /* DatabaseValueConvertibleDecodableTests.swift in Sources */, + 564A212F226B8E18001F64F1 /* UpdateStatementTests.swift in Sources */, + 564A2130226B8E18001F64F1 /* ValueObservationReducerTests.swift in Sources */, + 564A2131226B8E18001F64F1 /* Row+FoundationTests.swift in Sources */, + 569BBA32228DF91000478429 /* AssociationPrefetchingFetchableRecordTests.swift in Sources */, + 564A2132226B8E18001F64F1 /* QueryInterfaceRequestTests.swift in Sources */, + 564A2133226B8E18001F64F1 /* FetchRequestTests.swift in Sources */, + 564A2134226B8E18001F64F1 /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */, + 564A2135226B8E18001F64F1 /* AssociationChainSQLTests.swift in Sources */, + 564A2136226B8E18001F64F1 /* GRDBTestCase.swift in Sources */, + 564A2137226B8E18001F64F1 /* CompilationProtocolTests.swift in Sources */, + 564A2138226B8E18001F64F1 /* RecordSubClassTests.swift in Sources */, + 564A2139226B8E18001F64F1 /* AssociationParallelDecodableRecordTests.swift in Sources */, + 564A213A226B8E18001F64F1 /* AssociationBelongsToDecodableRecordTests.swift in Sources */, + 564A213B226B8E18001F64F1 /* DatabaseMigratorTests.swift in Sources */, + 564A213C226B8E18001F64F1 /* ValueObservationCombineTests.swift in Sources */, + 564A213D226B8E18001F64F1 /* CursorTests.swift in Sources */, + 564A213E226B8E18001F64F1 /* DatabaseDateDecodingStrategyTests.swift in Sources */, + 560432AA228F1752009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */, + 564A213F226B8E18001F64F1 /* SchedulingWatchdogTests.swift in Sources */, + 564A2140226B8E18001F64F1 /* RowTestCase.swift in Sources */, + 564A2141226B8E18001F64F1 /* TruncateOptimizationTests.swift in Sources */, + 564A2142226B8E18001F64F1 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */, + 564A2143226B8E18001F64F1 /* DatabasePoolReadOnlyTests.swift in Sources */, + 564A2144226B8E18001F64F1 /* FoundationNSURLTests.swift in Sources */, + 564A2145226B8E18001F64F1 /* FetchableRecordTests.swift in Sources */, + 564A2146226B8E18001F64F1 /* RowFetchTests.swift in Sources */, + 564A2147226B8E18001F64F1 /* DatabaseSnapshotTests.swift in Sources */, + 564A2148226B8E18001F64F1 /* FoundationDateTests.swift in Sources */, + 564A2149226B8E18001F64F1 /* DatabasePoolFunctionTests.swift in Sources */, + 564A214A226B8E18001F64F1 /* SQLInterpolationTests.swift in Sources */, + 564A214B226B8E18001F64F1 /* MapCursorTests.swift in Sources */, + 564A214C226B8E18001F64F1 /* NumericOverflowTests.swift in Sources */, + 564A214D226B8E18001F64F1 /* RecordMinimalPrimaryKeySingleTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 564A1F17226B8750001F64F1 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + MACOSX_DEPLOYMENT_TARGET = 10.9; + SWIFT_VERSION = 4.2; + }; + name = Debug; + }; + 564A1F18226B8750001F64F1 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + MACOSX_DEPLOYMENT_TARGET = 10.9; + SWIFT_VERSION = 4.2; + }; + name = Release; + }; + 564A1F24226B876D001F64F1 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 6A4788C0F815F6C5E4EBDE12 /* Pods-GRDBTests.debug.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COMBINE_HIDPI_IMAGES = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INFOPLIST_FILE = Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 564A1F25226B876D001F64F1 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 04298D834C818285823558AB /* Pods-GRDBTests.release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COMBINE_HIDPI_IMAGES = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INFOPLIST_FILE = Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 564A2154226B8E18001F64F1 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 83BFB5733A86DAA3D0BEE684 /* Pods-GRDBTestsEncrypted.debug.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COMBINE_HIDPI_IMAGES = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INFOPLIST_FILE = Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + OTHER_SWIFT_FLAGS = "$(inherited) -D GRDBCIPHER_USE_ENCRYPTION"; + PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 564A2155226B8E18001F64F1 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 47C5D1B9AFFE795AA1D6EA5D /* Pods-GRDBTestsEncrypted.release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COMBINE_HIDPI_IMAGES = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INFOPLIST_FILE = Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + OTHER_SWIFT_FLAGS = "$(inherited) -D GRDBCIPHER_USE_ENCRYPTION"; + PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 564A1F16226B8750001F64F1 /* Build configuration list for PBXProject "GRDBTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 564A1F17226B8750001F64F1 /* Debug */, + 564A1F18226B8750001F64F1 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 564A1F23226B876D001F64F1 /* Build configuration list for PBXNativeTarget "GRDBTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 564A1F24226B876D001F64F1 /* Debug */, + 564A1F25226B876D001F64F1 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 564A2153226B8E18001F64F1 /* Build configuration list for PBXNativeTarget "GRDBTestsEncrypted" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 564A2154226B8E18001F64F1 /* Debug */, + 564A2155226B8E18001F64F1 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 564A1F13226B8750001F64F1 /* Project object */; +} diff --git a/GRDBCipher.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 70% rename from GRDBCipher.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 735ffb164..696bc4d71 100644 --- a/GRDBCipher.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:SQLCipher4.xcodeproj"> diff --git a/Tests/Carthage/GRDBiOS/iOS.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from Tests/Carthage/GRDBiOS/iOS.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/GRDBCipher.xcodeproj/xcshareddata/xcschemes/GRDBCipheriOS.xcscheme b/Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/xcshareddata/xcschemes/GRDBTests.xcscheme similarity index 54% rename from GRDBCipher.xcodeproj/xcshareddata/xcschemes/GRDBCipheriOS.xcscheme rename to Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/xcshareddata/xcschemes/GRDBTests.xcscheme index ff6589214..81d5a2758 100644 --- a/GRDBCipher.xcodeproj/xcshareddata/xcschemes/GRDBCipheriOS.xcscheme +++ b/Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/xcshareddata/xcschemes/GRDBTests.xcscheme @@ -1,6 +1,6 @@ + buildForRunning = "NO" + buildForProfiling = "NO" + buildForArchiving = "NO" + buildForAnalyzing = "NO"> + BlueprintIdentifier = "564A1F1C226B876D001F64F1" + BuildableName = "GRDBTests.xctest" + BlueprintName = "GRDBTests" + ReferencedContainer = "container:GRDBTests.xcodeproj"> - - - - + BlueprintIdentifier = "564A2095226B8E18001F64F1" + BuildableName = "GRDBTestsEncrypted.xctest" + BlueprintName = "GRDBTestsEncrypted" + ReferencedContainer = "container:GRDBTests.xcodeproj"> @@ -57,33 +43,37 @@ shouldUseLaunchSchemeArgsEnv = "YES"> + skipped = "NO" + parallelizable = "YES" + testExecutionOrdering = "random"> + BlueprintIdentifier = "564A1F1C226B876D001F64F1" + BuildableName = "GRDBTests.xctest" + BlueprintName = "GRDBTests" + ReferencedContainer = "container:GRDBTests.xcodeproj"> + skipped = "NO" + parallelizable = "YES" + testExecutionOrdering = "random"> + BlueprintIdentifier = "564A2095226B8E18001F64F1" + BuildableName = "GRDBTestsEncrypted.xctest" + BlueprintName = "GRDBTestsEncrypted" + ReferencedContainer = "container:GRDBTests.xcodeproj"> + BlueprintIdentifier = "564A1F1C226B876D001F64F1" + BuildableName = "GRDBTests.xctest" + BlueprintName = "GRDBTests" + ReferencedContainer = "container:GRDBTests.xcodeproj"> @@ -99,15 +89,6 @@ debugDocumentVersioning = "YES" debugServiceExtension = "internal" allowLocationSimulation = "YES"> - - - - diff --git a/Tests/CocoaPods/SQLCipher3/GRDBTests.xcworkspace/contents.xcworkspacedata b/Tests/CocoaPods/SQLCipher3/GRDBTests.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..a75bfccf6 --- /dev/null +++ b/Tests/CocoaPods/SQLCipher3/GRDBTests.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Tests/CocoaPods/SQLCipher3/GRDBTests.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to Tests/CocoaPods/SQLCipher3/GRDBTests.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/Info.plist b/Tests/CocoaPods/SQLCipher3/Info.plist similarity index 66% rename from Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/Info.plist rename to Tests/CocoaPods/SQLCipher3/Info.plist index cfde06cd5..b7c017de3 100644 --- a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/Info.plist +++ b/Tests/CocoaPods/SQLCipher3/Info.plist @@ -4,10 +4,10 @@ CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) + LSApplicationCategoryType + CFBundleExecutable $(EXECUTABLE_NAME) - CFBundleIconFile - CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion @@ -15,18 +15,10 @@ CFBundleName $(PRODUCT_NAME) CFBundlePackageType - APPL + BNDL CFBundleShortVersionString 1.0 CFBundleVersion 1 - LSMinimumSystemVersion - $(MACOSX_DEPLOYMENT_TARGET) - NSHumanReadableCopyright - Copyright © 2018 Gwendal Roué. All rights reserved. - NSMainNibFile - MainMenu - NSPrincipalClass - NSApplication diff --git a/Tests/CocoaPods/SQLCipher3/Podfile b/Tests/CocoaPods/SQLCipher3/Podfile new file mode 100644 index 000000000..1cf1af646 --- /dev/null +++ b/Tests/CocoaPods/SQLCipher3/Podfile @@ -0,0 +1,15 @@ +platform :macos, '10.9' +use_frameworks! + +def common + pod 'GRDB.swift/SQLCipher', :path => '../../..' + pod 'SQLCipher', '~> 3.0' +end + +target 'GRDBTests' do + common +end + +target 'GRDBTestsEncrypted' do + common +end diff --git a/Tests/CocoaPods/SQLCipher3/Podfile.lock b/Tests/CocoaPods/SQLCipher3/Podfile.lock new file mode 100644 index 000000000..8a1afeb7f --- /dev/null +++ b/Tests/CocoaPods/SQLCipher3/Podfile.lock @@ -0,0 +1,28 @@ +PODS: + - GRDB.swift/SQLCipher (3.7.0): + - SQLCipher (>= 3.4.0) + - SQLCipher (3.4.2): + - SQLCipher/standard (= 3.4.2) + - SQLCipher/common (3.4.2) + - SQLCipher/standard (3.4.2): + - SQLCipher/common + +DEPENDENCIES: + - GRDB.swift/SQLCipher (from `../../..`) + - SQLCipher (~> 3.0) + +SPEC REPOS: + https://github.com/cocoapods/specs.git: + - SQLCipher + +EXTERNAL SOURCES: + GRDB.swift: + :path: "../../.." + +SPEC CHECKSUMS: + GRDB.swift: 71ab04a6e727e34c034513c4d15901ea35eb1f0d + SQLCipher: f9fcf29b2e59ced7defc2a2bdd0ebe79b40d4990 + +PODFILE CHECKSUM: 3c40378cc007008eab577fee818c46fac6982d5f + +COCOAPODS: 1.6.1 diff --git a/Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/project.pbxproj b/Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/project.pbxproj new file mode 100644 index 000000000..2068c3fba --- /dev/null +++ b/Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/project.pbxproj @@ -0,0 +1,1771 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 560432AC228F1761009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560432AB228F1761009D3FE2 /* AssociationPrefetchingObservationTests.swift */; }; + 560432AD228F1761009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560432AB228F1761009D3FE2 /* AssociationPrefetchingObservationTests.swift */; }; + 56057C5C2291B8D600A7CB10 /* AssociationHasManyRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56057C5B2291B8D600A7CB10 /* AssociationHasManyRowScopeTests.swift */; }; + 56057C5D2291B8D600A7CB10 /* AssociationHasManyRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56057C5B2291B8D600A7CB10 /* AssociationHasManyRowScopeTests.swift */; }; + 56057C6B2291D0C000A7CB10 /* AssociationHasManyThroughRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56057C6A2291D0C000A7CB10 /* AssociationHasManyThroughRowScopeTests.swift */; }; + 56057C6C2291D0C000A7CB10 /* AssociationHasManyThroughRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56057C6A2291D0C000A7CB10 /* AssociationHasManyThroughRowScopeTests.swift */; }; + 560714F3227DD1AE0091BB10 /* AssociationPrefetchingSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560714F2227DD1AD0091BB10 /* AssociationPrefetchingSQLTests.swift */; }; + 560714F4227DD1AE0091BB10 /* AssociationPrefetchingSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560714F2227DD1AD0091BB10 /* AssociationPrefetchingSQLTests.swift */; }; + 564A1FDE226B89E1001F64F1 /* MutablePersistableRecordDeleteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F27226B89CE001F64F1 /* MutablePersistableRecordDeleteTests.swift */; }; + 564A1FDF226B89E1001F64F1 /* AssociationHasOneThroughRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F28226B89CE001F64F1 /* AssociationHasOneThroughRowScopeTests.swift */; }; + 564A1FE0226B89E1001F64F1 /* RowCopiedFromStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F29226B89CF001F64F1 /* RowCopiedFromStatementTests.swift */; }; + 564A1FE1226B89E1001F64F1 /* SelectStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2A226B89CF001F64F1 /* SelectStatementTests.swift */; }; + 564A1FE2226B89E1001F64F1 /* DatabaseQueueBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2B226B89CF001F64F1 /* DatabaseQueueBackupTests.swift */; }; + 564A1FE3226B89E1001F64F1 /* DatabaseValueConvertibleEncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2C226B89CF001F64F1 /* DatabaseValueConvertibleEncodableTests.swift */; }; + 564A1FE4226B89E1001F64F1 /* RecordPrimaryKeyMultipleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2D226B89CF001F64F1 /* RecordPrimaryKeyMultipleTests.swift */; }; + 564A1FE5226B89E1001F64F1 /* NumericOverflowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2E226B89CF001F64F1 /* NumericOverflowTests.swift */; }; + 564A1FE6226B89E1001F64F1 /* DatabaseQueueInMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2F226B89CF001F64F1 /* DatabaseQueueInMemoryTests.swift */; }; + 564A1FE7226B89E1001F64F1 /* FoundationURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F30226B89CF001F64F1 /* FoundationURLTests.swift */; }; + 564A1FE8226B89E1001F64F1 /* DatabaseAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F31226B89CF001F64F1 /* DatabaseAggregateTests.swift */; }; + 564A1FE9226B89E1001F64F1 /* MutablePersistableRecordEncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F32226B89CF001F64F1 /* MutablePersistableRecordEncodableTests.swift */; }; + 564A1FEA226B89E1001F64F1 /* AssociationChainRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F33226B89CF001F64F1 /* AssociationChainRowScopesTests.swift */; }; + 564A1FEB226B89E1001F64F1 /* FoundationNSUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F34226B89CF001F64F1 /* FoundationNSUUIDTests.swift */; }; + 564A1FEC226B89E1001F64F1 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F35226B89CF001F64F1 /* AssociationBelongsToDecodableRecordTests.swift */; }; + 564A1FED226B89E1001F64F1 /* CompilationProtocolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F36226B89CF001F64F1 /* CompilationProtocolTests.swift */; }; + 564A1FEE226B89E1001F64F1 /* DatabaseFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F37226B89CF001F64F1 /* DatabaseFunctionTests.swift */; }; + 564A1FEF226B89E1001F64F1 /* FetchedRecordsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F38226B89CF001F64F1 /* FetchedRecordsControllerTests.swift */; }; + 564A1FF0226B89E1001F64F1 /* AssociationHasOneThroughDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F39226B89CF001F64F1 /* AssociationHasOneThroughDecodableRecordTests.swift */; }; + 564A1FF1226B89E1001F64F1 /* DatabaseValueConvertibleSubclassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3A226B89D0001F64F1 /* DatabaseValueConvertibleSubclassTests.swift */; }; + 564A1FF2226B89E1001F64F1 /* RecordPersistenceConflictPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3B226B89D0001F64F1 /* RecordPersistenceConflictPolicy.swift */; }; + 564A1FF3226B89E1001F64F1 /* TruncateOptimizationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3C226B89D0001F64F1 /* TruncateOptimizationTests.swift */; }; + 564A1FF4226B89E1001F64F1 /* DatabasePoolCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3D226B89D0001F64F1 /* DatabasePoolCollationTests.swift */; }; + 564A1FF5226B89E1001F64F1 /* AssociationRowScopeSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3E226B89D0001F64F1 /* AssociationRowScopeSearchTests.swift */; }; + 564A1FF6226B89E1001F64F1 /* DatabaseSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3F226B89D0001F64F1 /* DatabaseSnapshotTests.swift */; }; + 564A1FF7226B89E1001F64F1 /* DatabaseValueConvertibleDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F40226B89D0001F64F1 /* DatabaseValueConvertibleDecodableTests.swift */; }; + 564A1FF8226B89E1001F64F1 /* QueryInterfaceExpressionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F41226B89D0001F64F1 /* QueryInterfaceExpressionsTests.swift */; }; + 564A1FF9226B89E1001F64F1 /* SQLRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F42226B89D0001F64F1 /* SQLRequestTests.swift */; }; + 564A1FFA226B89E1001F64F1 /* FTS5WrapperTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F43226B89D0001F64F1 /* FTS5WrapperTokenizerTests.swift */; }; + 564A1FFB226B89E1001F64F1 /* ValueObservationRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F44226B89D0001F64F1 /* ValueObservationRecordTests.swift */; }; + 564A1FFC226B89E1001F64F1 /* DatabaseValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F45226B89D0001F64F1 /* DatabaseValueTests.swift */; }; + 564A1FFD226B89E1001F64F1 /* PrefixWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F46226B89D1001F64F1 /* PrefixWhileCursorTests.swift */; }; + 564A1FFE226B89E1001F64F1 /* FilterCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F47226B89D1001F64F1 /* FilterCursorTests.swift */; }; + 564A1FFF226B89E1001F64F1 /* ValueObservationSchedulingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F48226B89D1001F64F1 /* ValueObservationSchedulingTests.swift */; }; + 564A2000226B89E1001F64F1 /* PrefixCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F49226B89D1001F64F1 /* PrefixCursorTests.swift */; }; + 564A2001226B89E1001F64F1 /* RecordPrimaryKeyNoneTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4A226B89D1001F64F1 /* RecordPrimaryKeyNoneTests.swift */; }; + 564A2002226B89E1001F64F1 /* DerivableRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4B226B89D1001F64F1 /* DerivableRequestTests.swift */; }; + 564A2003226B89E1001F64F1 /* DatabaseValueConvertibleFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4C226B89D1001F64F1 /* DatabaseValueConvertibleFetchTests.swift */; }; + 564A2004226B89E1001F64F1 /* AssociationChainSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4D226B89D2001F64F1 /* AssociationChainSQLTests.swift */; }; + 564A2005226B89E1001F64F1 /* SQLExpressionLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4E226B89D2001F64F1 /* SQLExpressionLiteralTests.swift */; }; + 564A2006226B89E1001F64F1 /* SQLInterpolationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4F226B89D2001F64F1 /* SQLInterpolationTests.swift */; }; + 564A2007226B89E1001F64F1 /* FoundationDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F50226B89D2001F64F1 /* FoundationDataTests.swift */; }; + 564A2008226B89E1001F64F1 /* RecordInitializersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F51226B89D2001F64F1 /* RecordInitializersTests.swift */; }; + 564A2009226B89E1001F64F1 /* AssociationHasOneThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F52226B89D2001F64F1 /* AssociationHasOneThroughSQLTests.swift */; }; + 564A200A226B89E1001F64F1 /* DatabaseCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F53226B89D2001F64F1 /* DatabaseCollationTests.swift */; }; + 564A200B226B89E1001F64F1 /* DatabaseDateEncodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F54226B89D2001F64F1 /* DatabaseDateEncodingStrategyTests.swift */; }; + 564A200C226B89E1001F64F1 /* DatabaseRegionObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F55226B89D2001F64F1 /* DatabaseRegionObservationTests.swift */; }; + 564A200D226B89E1001F64F1 /* RowFromDictionaryLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F56226B89D2001F64F1 /* RowFromDictionaryLiteralTests.swift */; }; + 564A200E226B89E1001F64F1 /* RowFromStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F57226B89D3001F64F1 /* RowFromStatementTests.swift */; }; + 564A200F226B89E1001F64F1 /* StatementArguments+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F58226B89D3001F64F1 /* StatementArguments+FoundationTests.swift */; }; + 564A2010226B89E1001F64F1 /* ValueObservationMapTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F59226B89D3001F64F1 /* ValueObservationMapTests.swift */; }; + 564A2011226B89E1001F64F1 /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5A226B89D3001F64F1 /* FetchRequestTests.swift */; }; + 564A2012226B89E1001F64F1 /* TransactionObserverSavepointsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5B226B89D3001F64F1 /* TransactionObserverSavepointsTests.swift */; }; + 564A2013226B89E1001F64F1 /* DatabaseLogErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5C226B89D3001F64F1 /* DatabaseLogErrorTests.swift */; }; + 564A2014226B89E1001F64F1 /* RecordSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5D226B89D3001F64F1 /* RecordSubClassTests.swift */; }; + 564A2015226B89E1001F64F1 /* EncryptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5E226B89D3001F64F1 /* EncryptionTests.swift */; }; + 564A2016226B89E1001F64F1 /* QueryInterfacePromiseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5F226B89D3001F64F1 /* QueryInterfacePromiseTests.swift */; }; + 564A2017226B89E1001F64F1 /* AssociationAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F60226B89D4001F64F1 /* AssociationAggregateTests.swift */; }; + 564A2018226B89E1001F64F1 /* ColumnExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F61226B89D4001F64F1 /* ColumnExpressionTests.swift */; }; + 564A2019226B89E1001F64F1 /* DatabasePoolReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F62226B89D4001F64F1 /* DatabasePoolReleaseMemoryTests.swift */; }; + 564A201A226B89E1001F64F1 /* FTS4TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F63226B89D5001F64F1 /* FTS4TableBuilderTests.swift */; }; + 564A201B226B89E1001F64F1 /* TableDefinitionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F64226B89D5001F64F1 /* TableDefinitionTests.swift */; }; + 564A201C226B89E1001F64F1 /* DatabaseErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F65226B89D5001F64F1 /* DatabaseErrorTests.swift */; }; + 564A201D226B89E1001F64F1 /* FTS3RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F66226B89D5001F64F1 /* FTS3RecordTests.swift */; }; + 564A201E226B89E1001F64F1 /* DatabaseCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F67226B89D5001F64F1 /* DatabaseCursorTests.swift */; }; + 564A201F226B89E1001F64F1 /* DatabaseQueueReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F68226B89D5001F64F1 /* DatabaseQueueReleaseMemoryTests.swift */; }; + 564A2020226B89E1001F64F1 /* DatabaseRegionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F69226B89D5001F64F1 /* DatabaseRegionTests.swift */; }; + 564A2021226B89E1001F64F1 /* DatabasePoolBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6A226B89D5001F64F1 /* DatabasePoolBackupTests.swift */; }; + 564A2022226B89E1001F64F1 /* CursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6B226B89D5001F64F1 /* CursorTests.swift */; }; + 564A2023226B89E1001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6C226B89D5001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift */; }; + 564A2024226B89E1001F64F1 /* DropWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6D226B89D5001F64F1 /* DropWhileCursorTests.swift */; }; + 564A2025226B89E1001F64F1 /* QueryInterfaceExtensibilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6E226B89D6001F64F1 /* QueryInterfaceExtensibilityTests.swift */; }; + 564A2026226B89E1001F64F1 /* Betty.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = 564A1F6F226B89D6001F64F1 /* Betty.jpeg */; }; + 564A2027226B89E1001F64F1 /* AssociationParallelDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F70226B89D6001F64F1 /* AssociationParallelDecodableRecordTests.swift */; }; + 564A2028226B89E1001F64F1 /* FoundationNSNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F71226B89D6001F64F1 /* FoundationNSNumberTests.swift */; }; + 564A2029226B89E1001F64F1 /* FTS3TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F72226B89D6001F64F1 /* FTS3TableBuilderTests.swift */; }; + 564A202A226B89E1001F64F1 /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F73226B89D6001F64F1 /* AssociationHasOneThroughSQLDerivationTests.swift */; }; + 564A202B226B89E1001F64F1 /* CompilationSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F74226B89D6001F64F1 /* CompilationSubClassTests.swift */; }; + 564A202C226B89E1001F64F1 /* RecordEditedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F75226B89D6001F64F1 /* RecordEditedTests.swift */; }; + 564A202D226B89E1001F64F1 /* Record+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F76226B89D6001F64F1 /* Record+QueryInterfaceRequestTests.swift */; }; + 564A202E226B89E1001F64F1 /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F77226B89D6001F64F1 /* RecordMinimalPrimaryKeyRowIDTests.swift */; }; + 564A202F226B89E1001F64F1 /* DatabasePoolSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F78226B89D6001F64F1 /* DatabasePoolSchemaCacheTests.swift */; }; + 564A2030226B89E1001F64F1 /* DatabaseSavepointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F79226B89D7001F64F1 /* DatabaseSavepointTests.swift */; }; + 564A2031226B89E1001F64F1 /* RowFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7A226B89D7001F64F1 /* RowFetchTests.swift */; }; + 564A2032226B89E1001F64F1 /* AssociationBelongsToFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7B226B89D7001F64F1 /* AssociationBelongsToFetchableRecordTests.swift */; }; + 564A2033226B89E1001F64F1 /* AssociationHasManySQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7C226B89D7001F64F1 /* AssociationHasManySQLTests.swift */; }; + 564A2034226B89E1001F64F1 /* FoundationNSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7D226B89D7001F64F1 /* FoundationNSDateTests.swift */; }; + 564A2035226B89E1001F64F1 /* Row+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7E226B89D7001F64F1 /* Row+FoundationTests.swift */; }; + 564A2036226B89E1001F64F1 /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7F226B89D7001F64F1 /* SchedulingWatchdogTests.swift */; }; + 564A2037226B89E1001F64F1 /* AssociationBelongsToSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F80226B89D7001F64F1 /* AssociationBelongsToSQLDerivationTests.swift */; }; + 564A2038226B89E1001F64F1 /* RowFromDictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F81226B89D7001F64F1 /* RowFromDictionaryTests.swift */; }; + 564A2039226B89E1001F64F1 /* DatabasePoolReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F82226B89D7001F64F1 /* DatabasePoolReadOnlyTests.swift */; }; + 564A203A226B89E1001F64F1 /* DatabaseDateDecodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F83226B89D8001F64F1 /* DatabaseDateDecodingStrategyTests.swift */; }; + 564A203B226B89E1001F64F1 /* ValueObservationCountTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F84226B89D8001F64F1 /* ValueObservationCountTests.swift */; }; + 564A203C226B89E1001F64F1 /* ValueObservationReadonlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F85226B89D8001F64F1 /* ValueObservationReadonlyTests.swift */; }; + 564A203D226B89E1001F64F1 /* IndexInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F86226B89D8001F64F1 /* IndexInfoTests.swift */; }; + 564A203E226B89E1001F64F1 /* ValueObservationReducerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F87226B89D8001F64F1 /* ValueObservationReducerTests.swift */; }; + 564A203F226B89E1001F64F1 /* AssociationBelongsToRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F88226B89D8001F64F1 /* AssociationBelongsToRowScopeTests.swift */; }; + 564A2040226B89E1001F64F1 /* StatementColumnConvertibleFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F89226B89D8001F64F1 /* StatementColumnConvertibleFetchTests.swift */; }; + 564A2041226B89E1001F64F1 /* CGFloatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8A226B89D9001F64F1 /* CGFloatTests.swift */; }; + 564A2042226B89E1001F64F1 /* FTS5TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8B226B89D9001F64F1 /* FTS5TableBuilderTests.swift */; }; + 564A2043226B89E1001F64F1 /* DatabasePoolFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8C226B89D9001F64F1 /* DatabasePoolFunctionTests.swift */; }; + 564A2044226B89E1001F64F1 /* FTS4RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8D226B89D9001F64F1 /* FTS4RecordTests.swift */; }; + 564A2045226B89E1001F64F1 /* FetchableRecordDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8E226B89D9001F64F1 /* FetchableRecordDecodableTests.swift */; }; + 564A2046226B89E1001F64F1 /* FTS5PatternTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8F226B89D9001F64F1 /* FTS5PatternTests.swift */; }; + 564A2047226B89E1001F64F1 /* AnyCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F90226B89D9001F64F1 /* AnyCursorTests.swift */; }; + 564A2048226B89E1001F64F1 /* RowAdapterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F91226B89D9001F64F1 /* RowAdapterTests.swift */; }; + 564A2049226B89E1001F64F1 /* DatabaseQueueReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F92226B89D9001F64F1 /* DatabaseQueueReadOnlyTests.swift */; }; + 564A204A226B89E1001F64F1 /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F93226B89D9001F64F1 /* RawRepresentable+DatabaseValueConvertibleTests.swift */; }; + 564A204B226B89E1001F64F1 /* FoundationNSDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F94226B89D9001F64F1 /* FoundationNSDataTests.swift */; }; + 564A204C226B89E1001F64F1 /* AssociationBelongsToSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F95226B89DA001F64F1 /* AssociationBelongsToSQLTests.swift */; }; + 564A204D226B89E1001F64F1 /* DatabaseQueueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F96226B89DA001F64F1 /* DatabaseQueueTests.swift */; }; + 564A204E226B89E1001F64F1 /* PrimaryKeyInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F97226B89DA001F64F1 /* PrimaryKeyInfoTests.swift */; }; + 564A204F226B89E1001F64F1 /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F98226B89DA001F64F1 /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */; }; + 564A2050226B89E1001F64F1 /* RecordPrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F99226B89DA001F64F1 /* RecordPrimaryKeySingleTests.swift */; }; + 564A2051226B89E1001F64F1 /* RecordWithColumnNameManglingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9A226B89DA001F64F1 /* RecordWithColumnNameManglingTests.swift */; }; + 564A2052226B89E1001F64F1 /* RowTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9B226B89DA001F64F1 /* RowTestCase.swift */; }; + 564A2053226B89E1001F64F1 /* ValueObservationRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9C226B89DA001F64F1 /* ValueObservationRowTests.swift */; }; + 564A2054226B89E1001F64F1 /* AssociationHasOneSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9D226B89DA001F64F1 /* AssociationHasOneSQLTests.swift */; }; + 564A2055226B89E1001F64F1 /* FoundationNSURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9E226B89DA001F64F1 /* FoundationNSURLTests.swift */; }; + 564A2056226B89E1001F64F1 /* TableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9F226B89DA001F64F1 /* TableRecordTests.swift */; }; + 564A2057226B89E1001F64F1 /* FoundationDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA0226B89DA001F64F1 /* FoundationDateTests.swift */; }; + 564A2058226B89E1001F64F1 /* FoundationUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA1226B89DB001F64F1 /* FoundationUUIDTests.swift */; }; + 564A2059226B89E1001F64F1 /* DatabaseValueConversionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA2226B89DB001F64F1 /* DatabaseValueConversionTests.swift */; }; + 564A205A226B89E1001F64F1 /* QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA3226B89DB001F64F1 /* QueryInterfaceRequestTests.swift */; }; + 564A205B226B89E1001F64F1 /* RecordCopyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA4226B89DB001F64F1 /* RecordCopyTests.swift */; }; + 564A205C226B89E1001F64F1 /* ResultCodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA5226B89DB001F64F1 /* ResultCodeTests.swift */; }; + 564A205D226B89E1001F64F1 /* DatabaseValueConvertibleEscapingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA6226B89DB001F64F1 /* DatabaseValueConvertibleEscapingTests.swift */; }; + 564A205E226B89E1001F64F1 /* FoundationNSNullTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA7226B89DB001F64F1 /* FoundationNSNullTests.swift */; }; + 564A205F226B89E1001F64F1 /* SQLLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA8226B89DB001F64F1 /* SQLLiteralTests.swift */; }; + 564A2060226B89E1001F64F1 /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA9226B89DB001F64F1 /* RecordPrimaryKeyHiddenRowIDTests.swift */; }; + 564A2061226B89E1001F64F1 /* TableRecord+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAA226B89DC001F64F1 /* TableRecord+QueryInterfaceRequestTests.swift */; }; + 564A2062226B89E1001F64F1 /* RecordMinimalPrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAB226B89DC001F64F1 /* RecordMinimalPrimaryKeySingleTests.swift */; }; + 564A2063226B89E1001F64F1 /* ColumnInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAC226B89DC001F64F1 /* ColumnInfoTests.swift */; }; + 564A2064226B89E1001F64F1 /* AssociationHasOneThroughFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAD226B89DC001F64F1 /* AssociationHasOneThroughFetchableRecordTests.swift */; }; + 564A2065226B89E1001F64F1 /* AssociationHasOneSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAE226B89DC001F64F1 /* AssociationHasOneSQLDerivationTests.swift */; }; + 564A2066226B89E1001F64F1 /* DatabaseTimestampTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAF226B89DC001F64F1 /* DatabaseTimestampTests.swift */; }; + 564A2067226B89E1001F64F1 /* EnumeratedCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB0226B89DC001F64F1 /* EnumeratedCursorTests.swift */; }; + 564A2068226B89E1001F64F1 /* DatabaseQueueConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB1226B89DC001F64F1 /* DatabaseQueueConcurrencyTests.swift */; }; + 564A2069226B89E1001F64F1 /* FlattenCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB2226B89DC001F64F1 /* FlattenCursorTests.swift */; }; + 564A206A226B89E1001F64F1 /* FoundationNSStringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB3226B89DC001F64F1 /* FoundationNSStringTests.swift */; }; + 564A206B226B89E1001F64F1 /* AssociationHasManyThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB4226B89DD001F64F1 /* AssociationHasManyThroughSQLTests.swift */; }; + 564A206C226B89E1001F64F1 /* FTS5CustomTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB5226B89DD001F64F1 /* FTS5CustomTokenizerTests.swift */; }; + 564A206D226B89E1001F64F1 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB6226B89DD001F64F1 /* ValueObservationCombineTests.swift */; }; + 564A206E226B89E1001F64F1 /* ValueObservationExtentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB7226B89DD001F64F1 /* ValueObservationExtentTests.swift */; }; + 564A206F226B89E1001F64F1 /* MapCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB8226B89DD001F64F1 /* MapCursorTests.swift */; }; + 564A2070226B89E1001F64F1 /* ValueObservationCompactMapTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB9226B89DD001F64F1 /* ValueObservationCompactMapTests.swift */; }; + 564A2071226B89E1001F64F1 /* VirtualTableModuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBA226B89DD001F64F1 /* VirtualTableModuleTests.swift */; }; + 564A2072226B89E1001F64F1 /* DropFirstCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBB226B89DD001F64F1 /* DropFirstCursorTests.swift */; }; + 564A2073226B89E1001F64F1 /* FetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBC226B89DE001F64F1 /* FetchableRecordTests.swift */; }; + 564A2074226B89E1001F64F1 /* UpdateStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBD226B89DE001F64F1 /* UpdateStatementTests.swift */; }; + 564A2075226B89E1001F64F1 /* RecordUniqueIndexTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBE226B89DE001F64F1 /* RecordUniqueIndexTests.swift */; }; + 564A2076226B89E1001F64F1 /* DatabaseReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBF226B89DE001F64F1 /* DatabaseReaderTests.swift */; }; + 564A2077226B89E1001F64F1 /* DatabaseWriterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC0226B89DE001F64F1 /* DatabaseWriterTests.swift */; }; + 564A2078226B89E1001F64F1 /* ForeignKeyInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC1226B89DE001F64F1 /* ForeignKeyInfoTests.swift */; }; + 564A2079226B89E1001F64F1 /* FoundationNSDecimalNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC2226B89DE001F64F1 /* FoundationNSDecimalNumberTests.swift */; }; + 564A207A226B89E1001F64F1 /* FoundationDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC3226B89DE001F64F1 /* FoundationDateComponentsTests.swift */; }; + 564A207B226B89E1001F64F1 /* FTS5TokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC4226B89DE001F64F1 /* FTS5TokenizerTests.swift */; }; + 564A207C226B89E1001F64F1 /* RecordPrimaryKeyRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC5226B89DE001F64F1 /* RecordPrimaryKeyRowIDTests.swift */; }; + 564A207D226B89E1001F64F1 /* ValueObservationFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC6226B89DF001F64F1 /* ValueObservationFetchTests.swift */; }; + 564A207E226B89E1001F64F1 /* DatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC7226B89DF001F64F1 /* DatabaseTests.swift */; }; + 564A207F226B89E1001F64F1 /* DatabaseQueueSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC8226B89DF001F64F1 /* DatabaseQueueSchemaCacheTests.swift */; }; + 564A2080226B89E1001F64F1 /* StatementArgumentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC9226B89DF001F64F1 /* StatementArgumentsTests.swift */; }; + 564A2081226B89E1001F64F1 /* TransactionObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCA226B89DF001F64F1 /* TransactionObserverTests.swift */; }; + 564A2082226B89E1001F64F1 /* PersistableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCB226B89DF001F64F1 /* PersistableRecordTests.swift */; }; + 564A2083226B89E1001F64F1 /* DataMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCC226B89DF001F64F1 /* DataMemoryTests.swift */; }; + 564A2084226B89E1001F64F1 /* JoinSupportTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCD226B89DF001F64F1 /* JoinSupportTests.swift */; }; + 564A2085226B89E1001F64F1 /* MutablePersistableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCE226B89DF001F64F1 /* MutablePersistableRecordTests.swift */; }; + 564A2086226B89E1001F64F1 /* AssociationTableAliasTestsSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCF226B89E0001F64F1 /* AssociationTableAliasTestsSQLTests.swift */; }; + 564A2087226B89E1001F64F1 /* FTS3PatternTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD0226B89E0001F64F1 /* FTS3PatternTests.swift */; }; + 564A2088226B89E1001F64F1 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD1226B89E0001F64F1 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift */; }; + 564A2089226B89E1001F64F1 /* DatabaseValueConversionErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD2226B89E0001F64F1 /* DatabaseValueConversionErrorTests.swift */; }; + 564A208A226B89E1001F64F1 /* MutablePersistableRecordChangesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD3226B89E0001F64F1 /* MutablePersistableRecordChangesTests.swift */; }; + 564A208B226B89E1001F64F1 /* DatabaseMigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD4226B89E0001F64F1 /* DatabaseMigratorTests.swift */; }; + 564A208C226B89E1001F64F1 /* GRDBTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD5226B89E0001F64F1 /* GRDBTestCase.swift */; }; + 564A208D226B89E1001F64F1 /* DatabaseUUIDEncodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD6226B89E0001F64F1 /* DatabaseUUIDEncodingStrategyTests.swift */; }; + 564A208E226B89E1001F64F1 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD7226B89E0001F64F1 /* DatabaseAfterNextTransactionCommitTests.swift */; }; + 564A208F226B89E1001F64F1 /* AssociationParallelRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD8226B89E0001F64F1 /* AssociationParallelRowScopesTests.swift */; }; + 564A2090226B89E1001F64F1 /* FTS3TokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD9226B89E0001F64F1 /* FTS3TokenizerTests.swift */; }; + 564A2091226B89E1001F64F1 /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FDA226B89E1001F64F1 /* FetchableRecord+QueryInterfaceRequestTests.swift */; }; + 564A2092226B89E1001F64F1 /* DatabasePoolConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FDB226B89E1001F64F1 /* DatabasePoolConcurrencyTests.swift */; }; + 564A2093226B89E1001F64F1 /* AssociationParallelSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FDC226B89E1001F64F1 /* AssociationParallelSQLTests.swift */; }; + 564A2094226B89E1001F64F1 /* FTS5RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FDD226B89E1001F64F1 /* FTS5RecordTests.swift */; }; + 564A2098226B8E18001F64F1 /* DropWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6D226B89D5001F64F1 /* DropWhileCursorTests.swift */; }; + 564A2099226B8E18001F64F1 /* DatabasePoolBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6A226B89D5001F64F1 /* DatabasePoolBackupTests.swift */; }; + 564A209A226B8E18001F64F1 /* DatabaseAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F31226B89CF001F64F1 /* DatabaseAggregateTests.swift */; }; + 564A209B226B8E18001F64F1 /* DatabaseFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F37226B89CF001F64F1 /* DatabaseFunctionTests.swift */; }; + 564A209C226B8E18001F64F1 /* DataMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCC226B89DF001F64F1 /* DataMemoryTests.swift */; }; + 564A209D226B8E18001F64F1 /* DatabaseQueueSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC8226B89DF001F64F1 /* DatabaseQueueSchemaCacheTests.swift */; }; + 564A209E226B8E18001F64F1 /* FTS3RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F66226B89D5001F64F1 /* FTS3RecordTests.swift */; }; + 564A209F226B8E18001F64F1 /* ResultCodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA5226B89DB001F64F1 /* ResultCodeTests.swift */; }; + 564A20A0226B8E18001F64F1 /* RecordPersistenceConflictPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3B226B89D0001F64F1 /* RecordPersistenceConflictPolicy.swift */; }; + 564A20A1226B8E18001F64F1 /* FetchedRecordsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F38226B89CF001F64F1 /* FetchedRecordsControllerTests.swift */; }; + 564A20A2226B8E18001F64F1 /* RecordUniqueIndexTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBE226B89DE001F64F1 /* RecordUniqueIndexTests.swift */; }; + 564A20A3226B8E18001F64F1 /* FoundationUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA1226B89DB001F64F1 /* FoundationUUIDTests.swift */; }; + 564A20A4226B8E18001F64F1 /* DatabaseQueueReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F92226B89D9001F64F1 /* DatabaseQueueReadOnlyTests.swift */; }; + 564A20A5226B8E18001F64F1 /* AssociationHasOneThroughDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F39226B89CF001F64F1 /* AssociationHasOneThroughDecodableRecordTests.swift */; }; + 564A20A6226B8E18001F64F1 /* AssociationChainRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F33226B89CF001F64F1 /* AssociationChainRowScopesTests.swift */; }; + 564A20A7226B8E18001F64F1 /* ValueObservationSchedulingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F48226B89D1001F64F1 /* ValueObservationSchedulingTests.swift */; }; + 564A20A8226B8E18001F64F1 /* ValueObservationFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC6226B89DF001F64F1 /* ValueObservationFetchTests.swift */; }; + 564A20A9226B8E18001F64F1 /* ValueObservationReadonlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F85226B89D8001F64F1 /* ValueObservationReadonlyTests.swift */; }; + 564A20AA226B8E18001F64F1 /* ValueObservationCountTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F84226B89D8001F64F1 /* ValueObservationCountTests.swift */; }; + 564A20AB226B8E18001F64F1 /* ValueObservationRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9C226B89DA001F64F1 /* ValueObservationRowTests.swift */; }; + 564A20AC226B8E18001F64F1 /* RowAdapterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F91226B89D9001F64F1 /* RowAdapterTests.swift */; }; + 564A20AD226B8E18001F64F1 /* StatementColumnConvertibleFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F89226B89D8001F64F1 /* StatementColumnConvertibleFetchTests.swift */; }; + 564A20AE226B8E18001F64F1 /* DatabasePoolReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F62226B89D4001F64F1 /* DatabasePoolReleaseMemoryTests.swift */; }; + 564A20AF226B8E18001F64F1 /* StatementArgumentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC9226B89DF001F64F1 /* StatementArgumentsTests.swift */; }; + 564A20B0226B8E18001F64F1 /* PersistableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCB226B89DF001F64F1 /* PersistableRecordTests.swift */; }; + 564A20B1226B8E18001F64F1 /* QueryInterfacePromiseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5F226B89D3001F64F1 /* QueryInterfacePromiseTests.swift */; }; + 564A20B2226B8E18001F64F1 /* DatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC7226B89DF001F64F1 /* DatabaseTests.swift */; }; + 564A20B3226B8E18001F64F1 /* AssociationHasManySQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7C226B89D7001F64F1 /* AssociationHasManySQLTests.swift */; }; + 564A20B4226B8E18001F64F1 /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F93226B89D9001F64F1 /* RawRepresentable+DatabaseValueConvertibleTests.swift */; }; + 564A20B5226B8E18001F64F1 /* FTS5TokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC4226B89DE001F64F1 /* FTS5TokenizerTests.swift */; }; + 564A20B6226B8E18001F64F1 /* Record+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F76226B89D6001F64F1 /* Record+QueryInterfaceRequestTests.swift */; }; + 564A20B7226B8E18001F64F1 /* FTS4RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8D226B89D9001F64F1 /* FTS4RecordTests.swift */; }; + 564A20B8226B8E18001F64F1 /* AssociationTableAliasTestsSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCF226B89E0001F64F1 /* AssociationTableAliasTestsSQLTests.swift */; }; + 564A20B9226B8E18001F64F1 /* TransactionObserverSavepointsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5B226B89D3001F64F1 /* TransactionObserverSavepointsTests.swift */; }; + 564A20BA226B8E18001F64F1 /* DatabaseRegionObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F55226B89D2001F64F1 /* DatabaseRegionObservationTests.swift */; }; + 564A20BB226B8E18001F64F1 /* MutablePersistableRecordDeleteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F27226B89CE001F64F1 /* MutablePersistableRecordDeleteTests.swift */; }; + 564A20BC226B8E18001F64F1 /* DropFirstCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBB226B89DD001F64F1 /* DropFirstCursorTests.swift */; }; + 564A20BD226B8E18001F64F1 /* MutablePersistableRecordEncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F32226B89CF001F64F1 /* MutablePersistableRecordEncodableTests.swift */; }; + 564A20BE226B8E18001F64F1 /* DatabaseValueConvertibleFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4C226B89D1001F64F1 /* DatabaseValueConvertibleFetchTests.swift */; }; + 564A20BF226B8E18001F64F1 /* CGFloatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8A226B89D9001F64F1 /* CGFloatTests.swift */; }; + 564A20C0226B8E18001F64F1 /* DatabaseCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F67226B89D5001F64F1 /* DatabaseCursorTests.swift */; }; + 564A20C1226B8E18001F64F1 /* SQLRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F42226B89D0001F64F1 /* SQLRequestTests.swift */; }; + 564A20C2226B8E18001F64F1 /* TableDefinitionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F64226B89D5001F64F1 /* TableDefinitionTests.swift */; }; + 564A20C3226B8E18001F64F1 /* CompilationSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F74226B89D6001F64F1 /* CompilationSubClassTests.swift */; }; + 564A20C4226B8E18001F64F1 /* FTS5PatternTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8F226B89D9001F64F1 /* FTS5PatternTests.swift */; }; + 564A20C5226B8E18001F64F1 /* DatabasePoolSchemaCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F78226B89D6001F64F1 /* DatabasePoolSchemaCacheTests.swift */; }; + 564A20C6226B8E18001F64F1 /* RecordEditedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F75226B89D6001F64F1 /* RecordEditedTests.swift */; }; + 564A20C7226B8E18001F64F1 /* ValueObservationRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F44226B89D0001F64F1 /* ValueObservationRecordTests.swift */; }; + 564A20C8226B8E18001F64F1 /* DatabaseRegionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F69226B89D5001F64F1 /* DatabaseRegionTests.swift */; }; + 564A20C9226B8E18001F64F1 /* DatabaseQueueReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F68226B89D5001F64F1 /* DatabaseQueueReleaseMemoryTests.swift */; }; + 564A20CA226B8E18001F64F1 /* PrefixCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F49226B89D1001F64F1 /* PrefixCursorTests.swift */; }; + 564A20CB226B8E18001F64F1 /* SelectStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2A226B89CF001F64F1 /* SelectStatementTests.swift */; }; + 564A20CC226B8E18001F64F1 /* QueryInterfaceExpressionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F41226B89D0001F64F1 /* QueryInterfaceExpressionsTests.swift */; }; + 564A20CD226B8E18001F64F1 /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F77226B89D6001F64F1 /* RecordMinimalPrimaryKeyRowIDTests.swift */; }; + 564A20CE226B8E18001F64F1 /* ForeignKeyInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC1226B89DE001F64F1 /* ForeignKeyInfoTests.swift */; }; + 564A20CF226B8E18001F64F1 /* RecordPrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F99226B89DA001F64F1 /* RecordPrimaryKeySingleTests.swift */; }; + 564A20D0226B8E18001F64F1 /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FDA226B89E1001F64F1 /* FetchableRecord+QueryInterfaceRequestTests.swift */; }; + 564A20D1226B8E18001F64F1 /* AssociationParallelRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD8226B89E0001F64F1 /* AssociationParallelRowScopesTests.swift */; }; + 564A20D2226B8E18001F64F1 /* AnyCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F90226B89D9001F64F1 /* AnyCursorTests.swift */; }; + 564A20D3226B8E18001F64F1 /* DatabaseValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F45226B89D0001F64F1 /* DatabaseValueTests.swift */; }; + 564A20D4226B8E18001F64F1 /* RowFromStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F57226B89D3001F64F1 /* RowFromStatementTests.swift */; }; + 564A20D5226B8E18001F64F1 /* FlattenCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB2226B89DC001F64F1 /* FlattenCursorTests.swift */; }; + 564A20D6226B8E18001F64F1 /* RecordInitializersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F51226B89D2001F64F1 /* RecordInitializersTests.swift */; }; + 564A20D7226B8E18001F64F1 /* ColumnExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F61226B89D4001F64F1 /* ColumnExpressionTests.swift */; }; + 564A20D8226B8E18001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6C226B89D5001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift */; }; + 564A20D9226B8E18001F64F1 /* ValueObservationMapTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F59226B89D3001F64F1 /* ValueObservationMapTests.swift */; }; + 564A20DA226B8E18001F64F1 /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F98226B89DA001F64F1 /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */; }; + 564A20DB226B8E18001F64F1 /* AssociationHasManyThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB4226B89DD001F64F1 /* AssociationHasManyThroughSQLTests.swift */; }; + 564A20DC226B8E18001F64F1 /* FTS3PatternTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD0226B89E0001F64F1 /* FTS3PatternTests.swift */; }; + 564A20DD226B8E18001F64F1 /* EnumeratedCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB0226B89DC001F64F1 /* EnumeratedCursorTests.swift */; }; + 564A20DE226B8E18001F64F1 /* DatabaseValueConvertibleSubclassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3A226B89D0001F64F1 /* DatabaseValueConvertibleSubclassTests.swift */; }; + 564A20DF226B8E18001F64F1 /* EncryptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5E226B89D3001F64F1 /* EncryptionTests.swift */; }; + 564A20E0226B8E18001F64F1 /* AssociationBelongsToFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7B226B89D7001F64F1 /* AssociationBelongsToFetchableRecordTests.swift */; }; + 564A20E1226B8E18001F64F1 /* FoundationURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F30226B89CF001F64F1 /* FoundationURLTests.swift */; }; + 564A20E2226B8E18001F64F1 /* PrefixWhileCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F46226B89D1001F64F1 /* PrefixWhileCursorTests.swift */; }; + 564A20E3226B8E18001F64F1 /* FoundationNSDecimalNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC2226B89DE001F64F1 /* FoundationNSDecimalNumberTests.swift */; }; + 564A20E4226B8E18001F64F1 /* DatabaseCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F53226B89D2001F64F1 /* DatabaseCollationTests.swift */; }; + 564A20E5226B8E18001F64F1 /* TableRecord+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAA226B89DC001F64F1 /* TableRecord+QueryInterfaceRequestTests.swift */; }; + 564A20E6226B8E18001F64F1 /* DatabaseWriterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC0226B89DE001F64F1 /* DatabaseWriterTests.swift */; }; + 564A20E7226B8E18001F64F1 /* DatabaseQueueInMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2F226B89CF001F64F1 /* DatabaseQueueInMemoryTests.swift */; }; + 564A20E8226B8E18001F64F1 /* AssociationHasOneThroughFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAD226B89DC001F64F1 /* AssociationHasOneThroughFetchableRecordTests.swift */; }; + 564A20E9226B8E18001F64F1 /* FTS5WrapperTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F43226B89D0001F64F1 /* FTS5WrapperTokenizerTests.swift */; }; + 564A20EA226B8E18001F64F1 /* TableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9F226B89DA001F64F1 /* TableRecordTests.swift */; }; + 564A20EB226B8E18001F64F1 /* FTS5TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8B226B89D9001F64F1 /* FTS5TableBuilderTests.swift */; }; + 564A20EC226B8E18001F64F1 /* DatabaseValueConversionErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD2226B89E0001F64F1 /* DatabaseValueConversionErrorTests.swift */; }; + 564A20ED226B8E18001F64F1 /* TransactionObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCA226B89DF001F64F1 /* TransactionObserverTests.swift */; }; + 564A20EE226B8E18001F64F1 /* FetchableRecordDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8E226B89D9001F64F1 /* FetchableRecordDecodableTests.swift */; }; + 564A20EF226B8E18001F64F1 /* DatabasePoolCollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3D226B89D0001F64F1 /* DatabasePoolCollationTests.swift */; }; + 564A20F0226B8E18001F64F1 /* QueryInterfaceExtensibilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6E226B89D6001F64F1 /* QueryInterfaceExtensibilityTests.swift */; }; + 564A20F1226B8E18001F64F1 /* RowFromDictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F81226B89D7001F64F1 /* RowFromDictionaryTests.swift */; }; + 564A20F2226B8E18001F64F1 /* DatabaseDateEncodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F54226B89D2001F64F1 /* DatabaseDateEncodingStrategyTests.swift */; }; + 564A20F3226B8E18001F64F1 /* ValueObservationCompactMapTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB9226B89DD001F64F1 /* ValueObservationCompactMapTests.swift */; }; + 564A20F4226B8E18001F64F1 /* DatabaseValueConvertibleEscapingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA6226B89DB001F64F1 /* DatabaseValueConvertibleEscapingTests.swift */; }; + 564A20F5226B8E18001F64F1 /* DatabaseQueueConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB1226B89DC001F64F1 /* DatabaseQueueConcurrencyTests.swift */; }; + 564A20F6226B8E18001F64F1 /* AssociationAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F60226B89D4001F64F1 /* AssociationAggregateTests.swift */; }; + 564A20F7226B8E18001F64F1 /* AssociationHasOneSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAE226B89DC001F64F1 /* AssociationHasOneSQLDerivationTests.swift */; }; + 564A20F8226B8E18001F64F1 /* StatementArguments+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F58226B89D3001F64F1 /* StatementArguments+FoundationTests.swift */; }; + 564A20F9226B8E18001F64F1 /* FoundationDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC3226B89DE001F64F1 /* FoundationDateComponentsTests.swift */; }; + 564A20FA226B8E18001F64F1 /* PrimaryKeyInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F97226B89DA001F64F1 /* PrimaryKeyInfoTests.swift */; }; + 564A20FB226B8E18001F64F1 /* MutablePersistableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCE226B89DF001F64F1 /* MutablePersistableRecordTests.swift */; }; + 564A20FC226B8E18001F64F1 /* AssociationBelongsToSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F80226B89D7001F64F1 /* AssociationBelongsToSQLDerivationTests.swift */; }; + 564A20FD226B8E18001F64F1 /* DatabaseErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F65226B89D5001F64F1 /* DatabaseErrorTests.swift */; }; + 564A20FE226B8E18001F64F1 /* DatabaseUUIDEncodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD6226B89E0001F64F1 /* DatabaseUUIDEncodingStrategyTests.swift */; }; + 564A20FF226B8E18001F64F1 /* DatabaseQueueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F96226B89DA001F64F1 /* DatabaseQueueTests.swift */; }; + 564A2100226B8E18001F64F1 /* DatabaseLogErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5C226B89D3001F64F1 /* DatabaseLogErrorTests.swift */; }; + 564A2101226B8E18001F64F1 /* RecordPrimaryKeyMultipleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2D226B89CF001F64F1 /* RecordPrimaryKeyMultipleTests.swift */; }; + 564A2102226B8E18001F64F1 /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F73226B89D6001F64F1 /* AssociationHasOneThroughSQLDerivationTests.swift */; }; + 564A2103226B8E18001F64F1 /* AssociationParallelSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FDC226B89E1001F64F1 /* AssociationParallelSQLTests.swift */; }; + 564A2104226B8E18001F64F1 /* ColumnInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAC226B89DC001F64F1 /* ColumnInfoTests.swift */; }; + 564A2105226B8E18001F64F1 /* DatabaseValueConvertibleEncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2C226B89CF001F64F1 /* DatabaseValueConvertibleEncodableTests.swift */; }; + 564A2106226B8E18001F64F1 /* AssociationRowScopeSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3E226B89D0001F64F1 /* AssociationRowScopeSearchTests.swift */; }; + 564A2107226B8E18001F64F1 /* FoundationNSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7D226B89D7001F64F1 /* FoundationNSDateTests.swift */; }; + 564A2108226B8E18001F64F1 /* AssociationHasOneThroughRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F28226B89CE001F64F1 /* AssociationHasOneThroughRowScopeTests.swift */; }; + 564A2109226B8E18001F64F1 /* AssociationHasOneSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9D226B89DA001F64F1 /* AssociationHasOneSQLTests.swift */; }; + 564A210A226B8E18001F64F1 /* FoundationNSNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F71226B89D6001F64F1 /* FoundationNSNumberTests.swift */; }; + 564A210B226B8E18001F64F1 /* SQLExpressionLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4E226B89D2001F64F1 /* SQLExpressionLiteralTests.swift */; }; + 564A210C226B8E18001F64F1 /* AssociationBelongsToRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F88226B89D8001F64F1 /* AssociationBelongsToRowScopeTests.swift */; }; + 564A210D226B8E18001F64F1 /* DatabaseSavepointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F79226B89D7001F64F1 /* DatabaseSavepointTests.swift */; }; + 564A210E226B8E18001F64F1 /* FoundationNSStringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB3226B89DC001F64F1 /* FoundationNSStringTests.swift */; }; + 564A210F226B8E18001F64F1 /* ValueObservationExtentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB7226B89DD001F64F1 /* ValueObservationExtentTests.swift */; }; + 564A2110226B8E18001F64F1 /* DatabaseTimestampTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAF226B89DC001F64F1 /* DatabaseTimestampTests.swift */; }; + 564A2111226B8E18001F64F1 /* FoundationNSDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F94226B89D9001F64F1 /* FoundationNSDataTests.swift */; }; + 564A2112226B8E18001F64F1 /* AssociationHasOneThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F52226B89D2001F64F1 /* AssociationHasOneThroughSQLTests.swift */; }; + 564A2113226B8E18001F64F1 /* FTS3TokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD9226B89E0001F64F1 /* FTS3TokenizerTests.swift */; }; + 564A2114226B8E18001F64F1 /* DatabaseReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBF226B89DE001F64F1 /* DatabaseReaderTests.swift */; }; + 564A2115226B8E18001F64F1 /* VirtualTableModuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBA226B89DD001F64F1 /* VirtualTableModuleTests.swift */; }; + 564A2116226B8E18001F64F1 /* JoinSupportTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FCD226B89DF001F64F1 /* JoinSupportTests.swift */; }; + 564A2117226B8E18001F64F1 /* RecordPrimaryKeyRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FC5226B89DE001F64F1 /* RecordPrimaryKeyRowIDTests.swift */; }; + 564A2118226B8E18001F64F1 /* FTS5RecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FDD226B89E1001F64F1 /* FTS5RecordTests.swift */; }; + 564A2119226B8E18001F64F1 /* IndexInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F86226B89D8001F64F1 /* IndexInfoTests.swift */; }; + 564A211A226B8E18001F64F1 /* AssociationBelongsToSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F95226B89DA001F64F1 /* AssociationBelongsToSQLTests.swift */; }; + 564A211B226B8E18001F64F1 /* RowFromDictionaryLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F56226B89D2001F64F1 /* RowFromDictionaryLiteralTests.swift */; }; + 564A211C226B8E18001F64F1 /* FoundationNSNullTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA7226B89DB001F64F1 /* FoundationNSNullTests.swift */; }; + 564A211D226B8E18001F64F1 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD7226B89E0001F64F1 /* DatabaseAfterNextTransactionCommitTests.swift */; }; + 564A211E226B8E18001F64F1 /* FTS3TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F72226B89D6001F64F1 /* FTS3TableBuilderTests.swift */; }; + 564A211F226B8E18001F64F1 /* RecordPrimaryKeyNoneTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4A226B89D1001F64F1 /* RecordPrimaryKeyNoneTests.swift */; }; + 564A2120226B8E18001F64F1 /* RecordWithColumnNameManglingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9A226B89DA001F64F1 /* RecordWithColumnNameManglingTests.swift */; }; + 564A2121226B8E18001F64F1 /* RecordCopyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA4226B89DB001F64F1 /* RecordCopyTests.swift */; }; + 564A2122226B8E18001F64F1 /* SQLLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA8226B89DB001F64F1 /* SQLLiteralTests.swift */; }; + 564A2123226B8E18001F64F1 /* FTS5CustomTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB5226B89DD001F64F1 /* FTS5CustomTokenizerTests.swift */; }; + 564A2124226B8E18001F64F1 /* DerivableRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4B226B89D1001F64F1 /* DerivableRequestTests.swift */; }; + 564A2125226B8E18001F64F1 /* FoundationNSUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F34226B89CF001F64F1 /* FoundationNSUUIDTests.swift */; }; + 564A2126226B8E18001F64F1 /* FilterCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F47226B89D1001F64F1 /* FilterCursorTests.swift */; }; + 564A2127226B8E18001F64F1 /* MutablePersistableRecordChangesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD3226B89E0001F64F1 /* MutablePersistableRecordChangesTests.swift */; }; + 564A2128226B8E18001F64F1 /* DatabasePoolConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FDB226B89E1001F64F1 /* DatabasePoolConcurrencyTests.swift */; }; + 564A2129226B8E18001F64F1 /* RowCopiedFromStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F29226B89CF001F64F1 /* RowCopiedFromStatementTests.swift */; }; + 564A212A226B8E18001F64F1 /* FoundationDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F50226B89D2001F64F1 /* FoundationDataTests.swift */; }; + 564A212B226B8E18001F64F1 /* FTS4TableBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F63226B89D5001F64F1 /* FTS4TableBuilderTests.swift */; }; + 564A212C226B8E18001F64F1 /* DatabaseValueConversionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA2226B89DB001F64F1 /* DatabaseValueConversionTests.swift */; }; + 564A212D226B8E18001F64F1 /* DatabaseQueueBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2B226B89CF001F64F1 /* DatabaseQueueBackupTests.swift */; }; + 564A212E226B8E18001F64F1 /* DatabaseValueConvertibleDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F40226B89D0001F64F1 /* DatabaseValueConvertibleDecodableTests.swift */; }; + 564A212F226B8E18001F64F1 /* UpdateStatementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBD226B89DE001F64F1 /* UpdateStatementTests.swift */; }; + 564A2130226B8E18001F64F1 /* ValueObservationReducerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F87226B89D8001F64F1 /* ValueObservationReducerTests.swift */; }; + 564A2131226B8E18001F64F1 /* Row+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7E226B89D7001F64F1 /* Row+FoundationTests.swift */; }; + 564A2132226B8E18001F64F1 /* QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA3226B89DB001F64F1 /* QueryInterfaceRequestTests.swift */; }; + 564A2133226B8E18001F64F1 /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5A226B89D3001F64F1 /* FetchRequestTests.swift */; }; + 564A2134226B8E18001F64F1 /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA9226B89DB001F64F1 /* RecordPrimaryKeyHiddenRowIDTests.swift */; }; + 564A2135226B8E18001F64F1 /* AssociationChainSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4D226B89D2001F64F1 /* AssociationChainSQLTests.swift */; }; + 564A2136226B8E18001F64F1 /* GRDBTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD5226B89E0001F64F1 /* GRDBTestCase.swift */; }; + 564A2137226B8E18001F64F1 /* CompilationProtocolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F36226B89CF001F64F1 /* CompilationProtocolTests.swift */; }; + 564A2138226B8E18001F64F1 /* RecordSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F5D226B89D3001F64F1 /* RecordSubClassTests.swift */; }; + 564A2139226B8E18001F64F1 /* AssociationParallelDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F70226B89D6001F64F1 /* AssociationParallelDecodableRecordTests.swift */; }; + 564A213A226B8E18001F64F1 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F35226B89CF001F64F1 /* AssociationBelongsToDecodableRecordTests.swift */; }; + 564A213B226B8E18001F64F1 /* DatabaseMigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD4226B89E0001F64F1 /* DatabaseMigratorTests.swift */; }; + 564A213C226B8E18001F64F1 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB6226B89DD001F64F1 /* ValueObservationCombineTests.swift */; }; + 564A213D226B8E18001F64F1 /* CursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6B226B89D5001F64F1 /* CursorTests.swift */; }; + 564A213E226B8E18001F64F1 /* DatabaseDateDecodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F83226B89D8001F64F1 /* DatabaseDateDecodingStrategyTests.swift */; }; + 564A213F226B8E18001F64F1 /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7F226B89D7001F64F1 /* SchedulingWatchdogTests.swift */; }; + 564A2140226B8E18001F64F1 /* RowTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9B226B89DA001F64F1 /* RowTestCase.swift */; }; + 564A2141226B8E18001F64F1 /* TruncateOptimizationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3C226B89D0001F64F1 /* TruncateOptimizationTests.swift */; }; + 564A2142226B8E18001F64F1 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD1226B89E0001F64F1 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift */; }; + 564A2143226B8E18001F64F1 /* DatabasePoolReadOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F82226B89D7001F64F1 /* DatabasePoolReadOnlyTests.swift */; }; + 564A2144226B8E18001F64F1 /* FoundationNSURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F9E226B89DA001F64F1 /* FoundationNSURLTests.swift */; }; + 564A2145226B8E18001F64F1 /* FetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBC226B89DE001F64F1 /* FetchableRecordTests.swift */; }; + 564A2146226B8E18001F64F1 /* RowFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7A226B89D7001F64F1 /* RowFetchTests.swift */; }; + 564A2147226B8E18001F64F1 /* DatabaseSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F3F226B89D0001F64F1 /* DatabaseSnapshotTests.swift */; }; + 564A2148226B8E18001F64F1 /* FoundationDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FA0226B89DA001F64F1 /* FoundationDateTests.swift */; }; + 564A2149226B8E18001F64F1 /* DatabasePoolFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F8C226B89D9001F64F1 /* DatabasePoolFunctionTests.swift */; }; + 564A214A226B8E18001F64F1 /* SQLInterpolationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F4F226B89D2001F64F1 /* SQLInterpolationTests.swift */; }; + 564A214B226B8E18001F64F1 /* MapCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB8226B89DD001F64F1 /* MapCursorTests.swift */; }; + 564A214C226B8E18001F64F1 /* NumericOverflowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F2E226B89CF001F64F1 /* NumericOverflowTests.swift */; }; + 564A214D226B8E18001F64F1 /* RecordMinimalPrimaryKeySingleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FAB226B89DC001F64F1 /* RecordMinimalPrimaryKeySingleTests.swift */; }; + 564A214F226B8E18001F64F1 /* Pods_GRDBTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BEFDC53B1F7A33C242013A38 /* Pods_GRDBTests.framework */; }; + 564A2151226B8E18001F64F1 /* Betty.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = 564A1F6F226B89D6001F64F1 /* Betty.jpeg */; }; + 564A2159226C8F25001F64F1 /* db.SQLCipher3 in Resources */ = {isa = PBXBuildFile; fileRef = 564A2158226C8F24001F64F1 /* db.SQLCipher3 */; }; + 564A215A226C8F25001F64F1 /* db.SQLCipher3 in Resources */ = {isa = PBXBuildFile; fileRef = 564A2158226C8F24001F64F1 /* db.SQLCipher3 */; }; + 5656A805229474F4001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A804229474F4001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */; }; + 5656A806229474F4001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5656A804229474F4001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */; }; + 569BBA2E228DF90200478429 /* AssociationPrefetchingFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569BBA2D228DF90200478429 /* AssociationPrefetchingFetchableRecordTests.swift */; }; + 569BBA2F228DF90200478429 /* AssociationPrefetchingFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569BBA2D228DF90200478429 /* AssociationPrefetchingFetchableRecordTests.swift */; }; + 56DF0021228DDFF000D611F3 /* AssociationPrefetchingRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DF001F228DDFF000D611F3 /* AssociationPrefetchingRowTests.swift */; }; + 56DF0022228DDFF000D611F3 /* AssociationPrefetchingRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DF001F228DDFF000D611F3 /* AssociationPrefetchingRowTests.swift */; }; + 56DF0023228DDFF000D611F3 /* AssociationPrefetchingCodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DF0020228DDFF000D611F3 /* AssociationPrefetchingCodableRecordTests.swift */; }; + 56DF0024228DDFF000D611F3 /* AssociationPrefetchingCodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DF0020228DDFF000D611F3 /* AssociationPrefetchingCodableRecordTests.swift */; }; + 5B33E6E34F941B4C839A714F /* Pods_GRDBTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BEFDC53B1F7A33C242013A38 /* Pods_GRDBTests.framework */; }; + F2B3C4250D67969FF3948955 /* Pods_GRDBTestsEncrypted.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7D5C7999E7D9CE7145687F5D /* Pods_GRDBTestsEncrypted.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 04298D834C818285823558AB /* Pods-GRDBTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GRDBTests.release.xcconfig"; path = "Target Support Files/Pods-GRDBTests/Pods-GRDBTests.release.xcconfig"; sourceTree = ""; }; + 47C5D1B9AFFE795AA1D6EA5D /* Pods-GRDBTestsEncrypted.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GRDBTestsEncrypted.release.xcconfig"; path = "Target Support Files/Pods-GRDBTestsEncrypted/Pods-GRDBTestsEncrypted.release.xcconfig"; sourceTree = ""; }; + 560432AB228F1761009D3FE2 /* AssociationPrefetchingObservationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingObservationTests.swift; sourceTree = ""; }; + 56057C5B2291B8D600A7CB10 /* AssociationHasManyRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManyRowScopeTests.swift; sourceTree = ""; }; + 56057C6A2291D0C000A7CB10 /* AssociationHasManyThroughRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManyThroughRowScopeTests.swift; sourceTree = ""; }; + 560714F2227DD1AD0091BB10 /* AssociationPrefetchingSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingSQLTests.swift; sourceTree = ""; }; + 564A1F1D226B876D001F64F1 /* GRDBTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 564A1F22226B876D001F64F1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 564A1F26226B89CD001F64F1 /* GRDBTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "GRDBTests-Bridging-Header.h"; sourceTree = ""; }; + 564A1F27226B89CE001F64F1 /* MutablePersistableRecordDeleteTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordDeleteTests.swift; sourceTree = ""; }; + 564A1F28226B89CE001F64F1 /* AssociationHasOneThroughRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughRowScopeTests.swift; sourceTree = ""; }; + 564A1F29226B89CF001F64F1 /* RowCopiedFromStatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowCopiedFromStatementTests.swift; sourceTree = ""; }; + 564A1F2A226B89CF001F64F1 /* SelectStatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectStatementTests.swift; sourceTree = ""; }; + 564A1F2B226B89CF001F64F1 /* DatabaseQueueBackupTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueBackupTests.swift; sourceTree = ""; }; + 564A1F2C226B89CF001F64F1 /* DatabaseValueConvertibleEncodableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleEncodableTests.swift; sourceTree = ""; }; + 564A1F2D226B89CF001F64F1 /* RecordPrimaryKeyMultipleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPrimaryKeyMultipleTests.swift; sourceTree = ""; }; + 564A1F2E226B89CF001F64F1 /* NumericOverflowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumericOverflowTests.swift; sourceTree = ""; }; + 564A1F2F226B89CF001F64F1 /* DatabaseQueueInMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueInMemoryTests.swift; sourceTree = ""; }; + 564A1F30226B89CF001F64F1 /* FoundationURLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationURLTests.swift; sourceTree = ""; }; + 564A1F31226B89CF001F64F1 /* DatabaseAggregateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseAggregateTests.swift; sourceTree = ""; }; + 564A1F32226B89CF001F64F1 /* MutablePersistableRecordEncodableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordEncodableTests.swift; sourceTree = ""; }; + 564A1F33226B89CF001F64F1 /* AssociationChainRowScopesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationChainRowScopesTests.swift; sourceTree = ""; }; + 564A1F34226B89CF001F64F1 /* FoundationNSUUIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSUUIDTests.swift; sourceTree = ""; }; + 564A1F35226B89CF001F64F1 /* AssociationBelongsToDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToDecodableRecordTests.swift; sourceTree = ""; }; + 564A1F36226B89CF001F64F1 /* CompilationProtocolTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompilationProtocolTests.swift; sourceTree = ""; }; + 564A1F37226B89CF001F64F1 /* DatabaseFunctionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseFunctionTests.swift; sourceTree = ""; }; + 564A1F38226B89CF001F64F1 /* FetchedRecordsControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedRecordsControllerTests.swift; sourceTree = ""; }; + 564A1F39226B89CF001F64F1 /* AssociationHasOneThroughDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughDecodableRecordTests.swift; sourceTree = ""; }; + 564A1F3A226B89D0001F64F1 /* DatabaseValueConvertibleSubclassTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleSubclassTests.swift; sourceTree = ""; }; + 564A1F3B226B89D0001F64F1 /* RecordPersistenceConflictPolicy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPersistenceConflictPolicy.swift; sourceTree = ""; }; + 564A1F3C226B89D0001F64F1 /* TruncateOptimizationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TruncateOptimizationTests.swift; sourceTree = ""; }; + 564A1F3D226B89D0001F64F1 /* DatabasePoolCollationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolCollationTests.swift; sourceTree = ""; }; + 564A1F3E226B89D0001F64F1 /* AssociationRowScopeSearchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationRowScopeSearchTests.swift; sourceTree = ""; }; + 564A1F3F226B89D0001F64F1 /* DatabaseSnapshotTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseSnapshotTests.swift; sourceTree = ""; }; + 564A1F40226B89D0001F64F1 /* DatabaseValueConvertibleDecodableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleDecodableTests.swift; sourceTree = ""; }; + 564A1F41226B89D0001F64F1 /* QueryInterfaceExpressionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceExpressionsTests.swift; sourceTree = ""; }; + 564A1F42226B89D0001F64F1 /* SQLRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLRequestTests.swift; sourceTree = ""; }; + 564A1F43226B89D0001F64F1 /* FTS5WrapperTokenizerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5WrapperTokenizerTests.swift; sourceTree = ""; }; + 564A1F44226B89D0001F64F1 /* ValueObservationRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationRecordTests.swift; sourceTree = ""; }; + 564A1F45226B89D0001F64F1 /* DatabaseValueTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueTests.swift; sourceTree = ""; }; + 564A1F46226B89D1001F64F1 /* PrefixWhileCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrefixWhileCursorTests.swift; sourceTree = ""; }; + 564A1F47226B89D1001F64F1 /* FilterCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FilterCursorTests.swift; sourceTree = ""; }; + 564A1F48226B89D1001F64F1 /* ValueObservationSchedulingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationSchedulingTests.swift; sourceTree = ""; }; + 564A1F49226B89D1001F64F1 /* PrefixCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrefixCursorTests.swift; sourceTree = ""; }; + 564A1F4A226B89D1001F64F1 /* RecordPrimaryKeyNoneTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPrimaryKeyNoneTests.swift; sourceTree = ""; }; + 564A1F4B226B89D1001F64F1 /* DerivableRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DerivableRequestTests.swift; sourceTree = ""; }; + 564A1F4C226B89D1001F64F1 /* DatabaseValueConvertibleFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleFetchTests.swift; sourceTree = ""; }; + 564A1F4D226B89D2001F64F1 /* AssociationChainSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationChainSQLTests.swift; sourceTree = ""; }; + 564A1F4E226B89D2001F64F1 /* SQLExpressionLiteralTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLExpressionLiteralTests.swift; sourceTree = ""; }; + 564A1F4F226B89D2001F64F1 /* SQLInterpolationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLInterpolationTests.swift; sourceTree = ""; }; + 564A1F50226B89D2001F64F1 /* FoundationDataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationDataTests.swift; sourceTree = ""; }; + 564A1F51226B89D2001F64F1 /* RecordInitializersTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordInitializersTests.swift; sourceTree = ""; }; + 564A1F52226B89D2001F64F1 /* AssociationHasOneThroughSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughSQLTests.swift; sourceTree = ""; }; + 564A1F53226B89D2001F64F1 /* DatabaseCollationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseCollationTests.swift; sourceTree = ""; }; + 564A1F54226B89D2001F64F1 /* DatabaseDateEncodingStrategyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseDateEncodingStrategyTests.swift; sourceTree = ""; }; + 564A1F55226B89D2001F64F1 /* DatabaseRegionObservationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegionObservationTests.swift; sourceTree = ""; }; + 564A1F56226B89D2001F64F1 /* RowFromDictionaryLiteralTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFromDictionaryLiteralTests.swift; sourceTree = ""; }; + 564A1F57226B89D3001F64F1 /* RowFromStatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFromStatementTests.swift; sourceTree = ""; }; + 564A1F58226B89D3001F64F1 /* StatementArguments+FoundationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StatementArguments+FoundationTests.swift"; sourceTree = ""; }; + 564A1F59226B89D3001F64F1 /* ValueObservationMapTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationMapTests.swift; sourceTree = ""; }; + 564A1F5A226B89D3001F64F1 /* FetchRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchRequestTests.swift; sourceTree = ""; }; + 564A1F5B226B89D3001F64F1 /* TransactionObserverSavepointsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionObserverSavepointsTests.swift; sourceTree = ""; }; + 564A1F5C226B89D3001F64F1 /* DatabaseLogErrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseLogErrorTests.swift; sourceTree = ""; }; + 564A1F5D226B89D3001F64F1 /* RecordSubClassTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordSubClassTests.swift; sourceTree = ""; }; + 564A1F5E226B89D3001F64F1 /* EncryptionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EncryptionTests.swift; sourceTree = ""; }; + 564A1F5F226B89D3001F64F1 /* QueryInterfacePromiseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfacePromiseTests.swift; sourceTree = ""; }; + 564A1F60226B89D4001F64F1 /* AssociationAggregateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationAggregateTests.swift; sourceTree = ""; }; + 564A1F61226B89D4001F64F1 /* ColumnExpressionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColumnExpressionTests.swift; sourceTree = ""; }; + 564A1F62226B89D4001F64F1 /* DatabasePoolReleaseMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolReleaseMemoryTests.swift; sourceTree = ""; }; + 564A1F63226B89D5001F64F1 /* FTS4TableBuilderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS4TableBuilderTests.swift; sourceTree = ""; }; + 564A1F64226B89D5001F64F1 /* TableDefinitionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableDefinitionTests.swift; sourceTree = ""; }; + 564A1F65226B89D5001F64F1 /* DatabaseErrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseErrorTests.swift; sourceTree = ""; }; + 564A1F66226B89D5001F64F1 /* FTS3RecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3RecordTests.swift; sourceTree = ""; }; + 564A1F67226B89D5001F64F1 /* DatabaseCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseCursorTests.swift; sourceTree = ""; }; + 564A1F68226B89D5001F64F1 /* DatabaseQueueReleaseMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueReleaseMemoryTests.swift; sourceTree = ""; }; + 564A1F69226B89D5001F64F1 /* DatabaseRegionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegionTests.swift; sourceTree = ""; }; + 564A1F6A226B89D5001F64F1 /* DatabasePoolBackupTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolBackupTests.swift; sourceTree = ""; }; + 564A1F6B226B89D5001F64F1 /* CursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CursorTests.swift; sourceTree = ""; }; + 564A1F6C226B89D5001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationDatabaseValueConvertibleTests.swift; sourceTree = ""; }; + 564A1F6D226B89D5001F64F1 /* DropWhileCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropWhileCursorTests.swift; sourceTree = ""; }; + 564A1F6E226B89D6001F64F1 /* QueryInterfaceExtensibilityTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceExtensibilityTests.swift; sourceTree = ""; }; + 564A1F6F226B89D6001F64F1 /* Betty.jpeg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Betty.jpeg; sourceTree = ""; }; + 564A1F70226B89D6001F64F1 /* AssociationParallelDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelDecodableRecordTests.swift; sourceTree = ""; }; + 564A1F71226B89D6001F64F1 /* FoundationNSNumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSNumberTests.swift; sourceTree = ""; }; + 564A1F72226B89D6001F64F1 /* FTS3TableBuilderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3TableBuilderTests.swift; sourceTree = ""; }; + 564A1F73226B89D6001F64F1 /* AssociationHasOneThroughSQLDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughSQLDerivationTests.swift; sourceTree = ""; }; + 564A1F74226B89D6001F64F1 /* CompilationSubClassTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompilationSubClassTests.swift; sourceTree = ""; }; + 564A1F75226B89D6001F64F1 /* RecordEditedTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordEditedTests.swift; sourceTree = ""; }; + 564A1F76226B89D6001F64F1 /* Record+QueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Record+QueryInterfaceRequestTests.swift"; sourceTree = ""; }; + 564A1F77226B89D6001F64F1 /* RecordMinimalPrimaryKeyRowIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordMinimalPrimaryKeyRowIDTests.swift; sourceTree = ""; }; + 564A1F78226B89D6001F64F1 /* DatabasePoolSchemaCacheTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolSchemaCacheTests.swift; sourceTree = ""; }; + 564A1F79226B89D7001F64F1 /* DatabaseSavepointTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseSavepointTests.swift; sourceTree = ""; }; + 564A1F7A226B89D7001F64F1 /* RowFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFetchTests.swift; sourceTree = ""; }; + 564A1F7B226B89D7001F64F1 /* AssociationBelongsToFetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToFetchableRecordTests.swift; sourceTree = ""; }; + 564A1F7C226B89D7001F64F1 /* AssociationHasManySQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManySQLTests.swift; sourceTree = ""; }; + 564A1F7D226B89D7001F64F1 /* FoundationNSDateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSDateTests.swift; sourceTree = ""; }; + 564A1F7E226B89D7001F64F1 /* Row+FoundationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Row+FoundationTests.swift"; sourceTree = ""; }; + 564A1F7F226B89D7001F64F1 /* SchedulingWatchdogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SchedulingWatchdogTests.swift; sourceTree = ""; }; + 564A1F80226B89D7001F64F1 /* AssociationBelongsToSQLDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToSQLDerivationTests.swift; sourceTree = ""; }; + 564A1F81226B89D7001F64F1 /* RowFromDictionaryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFromDictionaryTests.swift; sourceTree = ""; }; + 564A1F82226B89D7001F64F1 /* DatabasePoolReadOnlyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolReadOnlyTests.swift; sourceTree = ""; }; + 564A1F83226B89D8001F64F1 /* DatabaseDateDecodingStrategyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseDateDecodingStrategyTests.swift; sourceTree = ""; }; + 564A1F84226B89D8001F64F1 /* ValueObservationCountTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationCountTests.swift; sourceTree = ""; }; + 564A1F85226B89D8001F64F1 /* ValueObservationReadonlyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationReadonlyTests.swift; sourceTree = ""; }; + 564A1F86226B89D8001F64F1 /* IndexInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IndexInfoTests.swift; sourceTree = ""; }; + 564A1F87226B89D8001F64F1 /* ValueObservationReducerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationReducerTests.swift; sourceTree = ""; }; + 564A1F88226B89D8001F64F1 /* AssociationBelongsToRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToRowScopeTests.swift; sourceTree = ""; }; + 564A1F89226B89D8001F64F1 /* StatementColumnConvertibleFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementColumnConvertibleFetchTests.swift; sourceTree = ""; }; + 564A1F8A226B89D9001F64F1 /* CGFloatTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGFloatTests.swift; sourceTree = ""; }; + 564A1F8B226B89D9001F64F1 /* FTS5TableBuilderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5TableBuilderTests.swift; sourceTree = ""; }; + 564A1F8C226B89D9001F64F1 /* DatabasePoolFunctionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolFunctionTests.swift; sourceTree = ""; }; + 564A1F8D226B89D9001F64F1 /* FTS4RecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS4RecordTests.swift; sourceTree = ""; }; + 564A1F8E226B89D9001F64F1 /* FetchableRecordDecodableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchableRecordDecodableTests.swift; sourceTree = ""; }; + 564A1F8F226B89D9001F64F1 /* FTS5PatternTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5PatternTests.swift; sourceTree = ""; }; + 564A1F90226B89D9001F64F1 /* AnyCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyCursorTests.swift; sourceTree = ""; }; + 564A1F91226B89D9001F64F1 /* RowAdapterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowAdapterTests.swift; sourceTree = ""; }; + 564A1F92226B89D9001F64F1 /* DatabaseQueueReadOnlyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueReadOnlyTests.swift; sourceTree = ""; }; + 564A1F93226B89D9001F64F1 /* RawRepresentable+DatabaseValueConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "RawRepresentable+DatabaseValueConvertibleTests.swift"; sourceTree = ""; }; + 564A1F94226B89D9001F64F1 /* FoundationNSDataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSDataTests.swift; sourceTree = ""; }; + 564A1F95226B89DA001F64F1 /* AssociationBelongsToSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToSQLTests.swift; sourceTree = ""; }; + 564A1F96226B89DA001F64F1 /* DatabaseQueueTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueTests.swift; sourceTree = ""; }; + 564A1F97226B89DA001F64F1 /* PrimaryKeyInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrimaryKeyInfoTests.swift; sourceTree = ""; }; + 564A1F98226B89DA001F64F1 /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordPersistenceConflictPolicyTests.swift; sourceTree = ""; }; + 564A1F99226B89DA001F64F1 /* RecordPrimaryKeySingleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPrimaryKeySingleTests.swift; sourceTree = ""; }; + 564A1F9A226B89DA001F64F1 /* RecordWithColumnNameManglingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordWithColumnNameManglingTests.swift; sourceTree = ""; }; + 564A1F9B226B89DA001F64F1 /* RowTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowTestCase.swift; sourceTree = ""; }; + 564A1F9C226B89DA001F64F1 /* ValueObservationRowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationRowTests.swift; sourceTree = ""; }; + 564A1F9D226B89DA001F64F1 /* AssociationHasOneSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneSQLTests.swift; sourceTree = ""; }; + 564A1F9E226B89DA001F64F1 /* FoundationNSURLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSURLTests.swift; sourceTree = ""; }; + 564A1F9F226B89DA001F64F1 /* TableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableRecordTests.swift; sourceTree = ""; }; + 564A1FA0226B89DA001F64F1 /* FoundationDateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationDateTests.swift; sourceTree = ""; }; + 564A1FA1226B89DB001F64F1 /* FoundationUUIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationUUIDTests.swift; sourceTree = ""; }; + 564A1FA2226B89DB001F64F1 /* DatabaseValueConversionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConversionTests.swift; sourceTree = ""; }; + 564A1FA3226B89DB001F64F1 /* QueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceRequestTests.swift; sourceTree = ""; }; + 564A1FA4226B89DB001F64F1 /* RecordCopyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordCopyTests.swift; sourceTree = ""; }; + 564A1FA5226B89DB001F64F1 /* ResultCodeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResultCodeTests.swift; sourceTree = ""; }; + 564A1FA6226B89DB001F64F1 /* DatabaseValueConvertibleEscapingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleEscapingTests.swift; sourceTree = ""; }; + 564A1FA7226B89DB001F64F1 /* FoundationNSNullTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSNullTests.swift; sourceTree = ""; }; + 564A1FA8226B89DB001F64F1 /* SQLLiteralTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLLiteralTests.swift; sourceTree = ""; }; + 564A1FA9226B89DB001F64F1 /* RecordPrimaryKeyHiddenRowIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPrimaryKeyHiddenRowIDTests.swift; sourceTree = ""; }; + 564A1FAA226B89DC001F64F1 /* TableRecord+QueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TableRecord+QueryInterfaceRequestTests.swift"; sourceTree = ""; }; + 564A1FAB226B89DC001F64F1 /* RecordMinimalPrimaryKeySingleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordMinimalPrimaryKeySingleTests.swift; sourceTree = ""; }; + 564A1FAC226B89DC001F64F1 /* ColumnInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColumnInfoTests.swift; sourceTree = ""; }; + 564A1FAD226B89DC001F64F1 /* AssociationHasOneThroughFetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughFetchableRecordTests.swift; sourceTree = ""; }; + 564A1FAE226B89DC001F64F1 /* AssociationHasOneSQLDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneSQLDerivationTests.swift; sourceTree = ""; }; + 564A1FAF226B89DC001F64F1 /* DatabaseTimestampTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseTimestampTests.swift; sourceTree = ""; }; + 564A1FB0226B89DC001F64F1 /* EnumeratedCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnumeratedCursorTests.swift; sourceTree = ""; }; + 564A1FB1226B89DC001F64F1 /* DatabaseQueueConcurrencyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueConcurrencyTests.swift; sourceTree = ""; }; + 564A1FB2226B89DC001F64F1 /* FlattenCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlattenCursorTests.swift; sourceTree = ""; }; + 564A1FB3226B89DC001F64F1 /* FoundationNSStringTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSStringTests.swift; sourceTree = ""; }; + 564A1FB4226B89DD001F64F1 /* AssociationHasManyThroughSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManyThroughSQLTests.swift; sourceTree = ""; }; + 564A1FB5226B89DD001F64F1 /* FTS5CustomTokenizerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5CustomTokenizerTests.swift; sourceTree = ""; }; + 564A1FB6226B89DD001F64F1 /* ValueObservationCombineTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationCombineTests.swift; sourceTree = ""; }; + 564A1FB7226B89DD001F64F1 /* ValueObservationExtentTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationExtentTests.swift; sourceTree = ""; }; + 564A1FB8226B89DD001F64F1 /* MapCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapCursorTests.swift; sourceTree = ""; }; + 564A1FB9226B89DD001F64F1 /* ValueObservationCompactMapTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationCompactMapTests.swift; sourceTree = ""; }; + 564A1FBA226B89DD001F64F1 /* VirtualTableModuleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VirtualTableModuleTests.swift; sourceTree = ""; }; + 564A1FBB226B89DD001F64F1 /* DropFirstCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropFirstCursorTests.swift; sourceTree = ""; }; + 564A1FBC226B89DE001F64F1 /* FetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchableRecordTests.swift; sourceTree = ""; }; + 564A1FBD226B89DE001F64F1 /* UpdateStatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateStatementTests.swift; sourceTree = ""; }; + 564A1FBE226B89DE001F64F1 /* RecordUniqueIndexTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordUniqueIndexTests.swift; sourceTree = ""; }; + 564A1FBF226B89DE001F64F1 /* DatabaseReaderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseReaderTests.swift; sourceTree = ""; }; + 564A1FC0226B89DE001F64F1 /* DatabaseWriterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseWriterTests.swift; sourceTree = ""; }; + 564A1FC1226B89DE001F64F1 /* ForeignKeyInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForeignKeyInfoTests.swift; sourceTree = ""; }; + 564A1FC2226B89DE001F64F1 /* FoundationNSDecimalNumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSDecimalNumberTests.swift; sourceTree = ""; }; + 564A1FC3226B89DE001F64F1 /* FoundationDateComponentsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationDateComponentsTests.swift; sourceTree = ""; }; + 564A1FC4226B89DE001F64F1 /* FTS5TokenizerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5TokenizerTests.swift; sourceTree = ""; }; + 564A1FC5226B89DE001F64F1 /* RecordPrimaryKeyRowIDTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPrimaryKeyRowIDTests.swift; sourceTree = ""; }; + 564A1FC6226B89DF001F64F1 /* ValueObservationFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationFetchTests.swift; sourceTree = ""; }; + 564A1FC7226B89DF001F64F1 /* DatabaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseTests.swift; sourceTree = ""; }; + 564A1FC8226B89DF001F64F1 /* DatabaseQueueSchemaCacheTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueSchemaCacheTests.swift; sourceTree = ""; }; + 564A1FC9226B89DF001F64F1 /* StatementArgumentsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementArgumentsTests.swift; sourceTree = ""; }; + 564A1FCA226B89DF001F64F1 /* TransactionObserverTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionObserverTests.swift; sourceTree = ""; }; + 564A1FCB226B89DF001F64F1 /* PersistableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersistableRecordTests.swift; sourceTree = ""; }; + 564A1FCC226B89DF001F64F1 /* DataMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataMemoryTests.swift; sourceTree = ""; }; + 564A1FCD226B89DF001F64F1 /* JoinSupportTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JoinSupportTests.swift; sourceTree = ""; }; + 564A1FCE226B89DF001F64F1 /* MutablePersistableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordTests.swift; sourceTree = ""; }; + 564A1FCF226B89E0001F64F1 /* AssociationTableAliasTestsSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationTableAliasTestsSQLTests.swift; sourceTree = ""; }; + 564A1FD0226B89E0001F64F1 /* FTS3PatternTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3PatternTests.swift; sourceTree = ""; }; + 564A1FD1226B89E0001F64F1 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift; sourceTree = ""; }; + 564A1FD2226B89E0001F64F1 /* DatabaseValueConversionErrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConversionErrorTests.swift; sourceTree = ""; }; + 564A1FD3226B89E0001F64F1 /* MutablePersistableRecordChangesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordChangesTests.swift; sourceTree = ""; }; + 564A1FD4226B89E0001F64F1 /* DatabaseMigratorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseMigratorTests.swift; sourceTree = ""; }; + 564A1FD5226B89E0001F64F1 /* GRDBTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GRDBTestCase.swift; sourceTree = ""; }; + 564A1FD6226B89E0001F64F1 /* DatabaseUUIDEncodingStrategyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseUUIDEncodingStrategyTests.swift; sourceTree = ""; }; + 564A1FD7226B89E0001F64F1 /* DatabaseAfterNextTransactionCommitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseAfterNextTransactionCommitTests.swift; sourceTree = ""; }; + 564A1FD8226B89E0001F64F1 /* AssociationParallelRowScopesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelRowScopesTests.swift; sourceTree = ""; }; + 564A1FD9226B89E0001F64F1 /* FTS3TokenizerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS3TokenizerTests.swift; sourceTree = ""; }; + 564A1FDA226B89E1001F64F1 /* FetchableRecord+QueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FetchableRecord+QueryInterfaceRequestTests.swift"; sourceTree = ""; }; + 564A1FDB226B89E1001F64F1 /* DatabasePoolConcurrencyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolConcurrencyTests.swift; sourceTree = ""; }; + 564A1FDC226B89E1001F64F1 /* AssociationParallelSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelSQLTests.swift; sourceTree = ""; }; + 564A1FDD226B89E1001F64F1 /* FTS5RecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5RecordTests.swift; sourceTree = ""; }; + 564A2156226B8E18001F64F1 /* GRDBTestsEncrypted.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBTestsEncrypted.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 564A2158226C8F24001F64F1 /* db.SQLCipher3 */ = {isa = PBXFileReference; lastKnownFileType = file; path = db.SQLCipher3; sourceTree = SOURCE_ROOT; }; + 5656A804229474F4001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationQueryInterfaceRequestTests.swift; sourceTree = ""; }; + 569BBA2D228DF90200478429 /* AssociationPrefetchingFetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingFetchableRecordTests.swift; sourceTree = ""; }; + 56DF001F228DDFF000D611F3 /* AssociationPrefetchingRowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingRowTests.swift; sourceTree = ""; }; + 56DF0020228DDFF000D611F3 /* AssociationPrefetchingCodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationPrefetchingCodableRecordTests.swift; sourceTree = ""; }; + 6A4788C0F815F6C5E4EBDE12 /* Pods-GRDBTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GRDBTests.debug.xcconfig"; path = "Target Support Files/Pods-GRDBTests/Pods-GRDBTests.debug.xcconfig"; sourceTree = ""; }; + 7D5C7999E7D9CE7145687F5D /* Pods_GRDBTestsEncrypted.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_GRDBTestsEncrypted.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 83BFB5733A86DAA3D0BEE684 /* Pods-GRDBTestsEncrypted.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GRDBTestsEncrypted.debug.xcconfig"; path = "Target Support Files/Pods-GRDBTestsEncrypted/Pods-GRDBTestsEncrypted.debug.xcconfig"; sourceTree = ""; }; + BEFDC53B1F7A33C242013A38 /* Pods_GRDBTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_GRDBTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 564A1F1A226B876D001F64F1 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 5B33E6E34F941B4C839A714F /* Pods_GRDBTests.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 564A214E226B8E18001F64F1 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 564A214F226B8E18001F64F1 /* Pods_GRDBTests.framework in Frameworks */, + F2B3C4250D67969FF3948955 /* Pods_GRDBTestsEncrypted.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 564A1F12226B8750001F64F1 = { + isa = PBXGroup; + children = ( + 564A1F22226B876D001F64F1 /* Info.plist */, + 564A1F1F226B876D001F64F1 /* GRDBTests */, + 564A1F1E226B876D001F64F1 /* Products */, + A39D84C3D9EF90DA939D10D7 /* Pods */, + EAA416B3A072FCB835929FD9 /* Frameworks */, + ); + sourceTree = ""; + }; + 564A1F1E226B876D001F64F1 /* Products */ = { + isa = PBXGroup; + children = ( + 564A1F1D226B876D001F64F1 /* GRDBTests.xctest */, + 564A2156226B8E18001F64F1 /* GRDBTestsEncrypted.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 564A1F1F226B876D001F64F1 /* GRDBTests */ = { + isa = PBXGroup; + children = ( + 564A1F90226B89D9001F64F1 /* AnyCursorTests.swift */, + 564A1F60226B89D4001F64F1 /* AssociationAggregateTests.swift */, + 564A1F35226B89CF001F64F1 /* AssociationBelongsToDecodableRecordTests.swift */, + 564A1F7B226B89D7001F64F1 /* AssociationBelongsToFetchableRecordTests.swift */, + 564A1F88226B89D8001F64F1 /* AssociationBelongsToRowScopeTests.swift */, + 564A1F80226B89D7001F64F1 /* AssociationBelongsToSQLDerivationTests.swift */, + 564A1F95226B89DA001F64F1 /* AssociationBelongsToSQLTests.swift */, + 564A1F33226B89CF001F64F1 /* AssociationChainRowScopesTests.swift */, + 564A1F4D226B89D2001F64F1 /* AssociationChainSQLTests.swift */, + 56057C5B2291B8D600A7CB10 /* AssociationHasManyRowScopeTests.swift */, + 564A1F7C226B89D7001F64F1 /* AssociationHasManySQLTests.swift */, + 56057C6A2291D0C000A7CB10 /* AssociationHasManyThroughRowScopeTests.swift */, + 564A1FB4226B89DD001F64F1 /* AssociationHasManyThroughSQLTests.swift */, + 564A1FAE226B89DC001F64F1 /* AssociationHasOneSQLDerivationTests.swift */, + 564A1F9D226B89DA001F64F1 /* AssociationHasOneSQLTests.swift */, + 564A1F39226B89CF001F64F1 /* AssociationHasOneThroughDecodableRecordTests.swift */, + 564A1FAD226B89DC001F64F1 /* AssociationHasOneThroughFetchableRecordTests.swift */, + 564A1F28226B89CE001F64F1 /* AssociationHasOneThroughRowScopeTests.swift */, + 564A1F73226B89D6001F64F1 /* AssociationHasOneThroughSQLDerivationTests.swift */, + 564A1F52226B89D2001F64F1 /* AssociationHasOneThroughSQLTests.swift */, + 564A1F70226B89D6001F64F1 /* AssociationParallelDecodableRecordTests.swift */, + 564A1FD8226B89E0001F64F1 /* AssociationParallelRowScopesTests.swift */, + 564A1FDC226B89E1001F64F1 /* AssociationParallelSQLTests.swift */, + 56DF0020228DDFF000D611F3 /* AssociationPrefetchingCodableRecordTests.swift */, + 569BBA2D228DF90200478429 /* AssociationPrefetchingFetchableRecordTests.swift */, + 560432AB228F1761009D3FE2 /* AssociationPrefetchingObservationTests.swift */, + 56DF001F228DDFF000D611F3 /* AssociationPrefetchingRowTests.swift */, + 560714F2227DD1AD0091BB10 /* AssociationPrefetchingSQLTests.swift */, + 564A1F3E226B89D0001F64F1 /* AssociationRowScopeSearchTests.swift */, + 564A1FCF226B89E0001F64F1 /* AssociationTableAliasTestsSQLTests.swift */, + 564A1F6F226B89D6001F64F1 /* Betty.jpeg */, + 564A1F8A226B89D9001F64F1 /* CGFloatTests.swift */, + 564A1F61226B89D4001F64F1 /* ColumnExpressionTests.swift */, + 564A1FAC226B89DC001F64F1 /* ColumnInfoTests.swift */, + 564A1F36226B89CF001F64F1 /* CompilationProtocolTests.swift */, + 564A1F74226B89D6001F64F1 /* CompilationSubClassTests.swift */, + 564A1F6B226B89D5001F64F1 /* CursorTests.swift */, + 564A1FD7226B89E0001F64F1 /* DatabaseAfterNextTransactionCommitTests.swift */, + 564A1F31226B89CF001F64F1 /* DatabaseAggregateTests.swift */, + 564A1F53226B89D2001F64F1 /* DatabaseCollationTests.swift */, + 564A1F67226B89D5001F64F1 /* DatabaseCursorTests.swift */, + 564A1F83226B89D8001F64F1 /* DatabaseDateDecodingStrategyTests.swift */, + 564A1F54226B89D2001F64F1 /* DatabaseDateEncodingStrategyTests.swift */, + 564A1F65226B89D5001F64F1 /* DatabaseErrorTests.swift */, + 564A1F37226B89CF001F64F1 /* DatabaseFunctionTests.swift */, + 564A1F5C226B89D3001F64F1 /* DatabaseLogErrorTests.swift */, + 564A1FD4226B89E0001F64F1 /* DatabaseMigratorTests.swift */, + 564A1F6A226B89D5001F64F1 /* DatabasePoolBackupTests.swift */, + 564A1F3D226B89D0001F64F1 /* DatabasePoolCollationTests.swift */, + 564A1FDB226B89E1001F64F1 /* DatabasePoolConcurrencyTests.swift */, + 564A1F8C226B89D9001F64F1 /* DatabasePoolFunctionTests.swift */, + 564A1F82226B89D7001F64F1 /* DatabasePoolReadOnlyTests.swift */, + 564A1F62226B89D4001F64F1 /* DatabasePoolReleaseMemoryTests.swift */, + 564A1F78226B89D6001F64F1 /* DatabasePoolSchemaCacheTests.swift */, + 564A1F2B226B89CF001F64F1 /* DatabaseQueueBackupTests.swift */, + 564A1FB1226B89DC001F64F1 /* DatabaseQueueConcurrencyTests.swift */, + 564A1F2F226B89CF001F64F1 /* DatabaseQueueInMemoryTests.swift */, + 564A1F92226B89D9001F64F1 /* DatabaseQueueReadOnlyTests.swift */, + 564A1F68226B89D5001F64F1 /* DatabaseQueueReleaseMemoryTests.swift */, + 564A1FC8226B89DF001F64F1 /* DatabaseQueueSchemaCacheTests.swift */, + 564A1F96226B89DA001F64F1 /* DatabaseQueueTests.swift */, + 564A1FBF226B89DE001F64F1 /* DatabaseReaderTests.swift */, + 564A1F55226B89D2001F64F1 /* DatabaseRegionObservationTests.swift */, + 564A1F69226B89D5001F64F1 /* DatabaseRegionTests.swift */, + 564A1F79226B89D7001F64F1 /* DatabaseSavepointTests.swift */, + 564A1F3F226B89D0001F64F1 /* DatabaseSnapshotTests.swift */, + 564A1FC7226B89DF001F64F1 /* DatabaseTests.swift */, + 564A1FAF226B89DC001F64F1 /* DatabaseTimestampTests.swift */, + 564A1FD6226B89E0001F64F1 /* DatabaseUUIDEncodingStrategyTests.swift */, + 564A1FD2226B89E0001F64F1 /* DatabaseValueConversionErrorTests.swift */, + 564A1FA2226B89DB001F64F1 /* DatabaseValueConversionTests.swift */, + 564A1F40226B89D0001F64F1 /* DatabaseValueConvertibleDecodableTests.swift */, + 564A1F2C226B89CF001F64F1 /* DatabaseValueConvertibleEncodableTests.swift */, + 564A1FA6226B89DB001F64F1 /* DatabaseValueConvertibleEscapingTests.swift */, + 564A1F4C226B89D1001F64F1 /* DatabaseValueConvertibleFetchTests.swift */, + 564A1F3A226B89D0001F64F1 /* DatabaseValueConvertibleSubclassTests.swift */, + 564A1F45226B89D0001F64F1 /* DatabaseValueTests.swift */, + 564A1FC0226B89DE001F64F1 /* DatabaseWriterTests.swift */, + 564A1FCC226B89DF001F64F1 /* DataMemoryTests.swift */, + 564A2158226C8F24001F64F1 /* db.SQLCipher3 */, + 564A1F4B226B89D1001F64F1 /* DerivableRequestTests.swift */, + 564A1FBB226B89DD001F64F1 /* DropFirstCursorTests.swift */, + 564A1F6D226B89D5001F64F1 /* DropWhileCursorTests.swift */, + 564A1F5E226B89D3001F64F1 /* EncryptionTests.swift */, + 564A1FB0226B89DC001F64F1 /* EnumeratedCursorTests.swift */, + 564A1FDA226B89E1001F64F1 /* FetchableRecord+QueryInterfaceRequestTests.swift */, + 564A1F8E226B89D9001F64F1 /* FetchableRecordDecodableTests.swift */, + 564A1FBC226B89DE001F64F1 /* FetchableRecordTests.swift */, + 564A1F38226B89CF001F64F1 /* FetchedRecordsControllerTests.swift */, + 564A1F5A226B89D3001F64F1 /* FetchRequestTests.swift */, + 564A1F47226B89D1001F64F1 /* FilterCursorTests.swift */, + 564A1FB2226B89DC001F64F1 /* FlattenCursorTests.swift */, + 564A1FC1226B89DE001F64F1 /* ForeignKeyInfoTests.swift */, + 564A1F50226B89D2001F64F1 /* FoundationDataTests.swift */, + 564A1FC3226B89DE001F64F1 /* FoundationDateComponentsTests.swift */, + 564A1FA0226B89DA001F64F1 /* FoundationDateTests.swift */, + 564A1F94226B89D9001F64F1 /* FoundationNSDataTests.swift */, + 564A1F7D226B89D7001F64F1 /* FoundationNSDateTests.swift */, + 564A1FC2226B89DE001F64F1 /* FoundationNSDecimalNumberTests.swift */, + 564A1FA7226B89DB001F64F1 /* FoundationNSNullTests.swift */, + 564A1F71226B89D6001F64F1 /* FoundationNSNumberTests.swift */, + 564A1FB3226B89DC001F64F1 /* FoundationNSStringTests.swift */, + 564A1F9E226B89DA001F64F1 /* FoundationNSURLTests.swift */, + 564A1F34226B89CF001F64F1 /* FoundationNSUUIDTests.swift */, + 564A1F30226B89CF001F64F1 /* FoundationURLTests.swift */, + 564A1FA1226B89DB001F64F1 /* FoundationUUIDTests.swift */, + 564A1FD0226B89E0001F64F1 /* FTS3PatternTests.swift */, + 564A1F66226B89D5001F64F1 /* FTS3RecordTests.swift */, + 564A1F72226B89D6001F64F1 /* FTS3TableBuilderTests.swift */, + 564A1FD9226B89E0001F64F1 /* FTS3TokenizerTests.swift */, + 564A1F8D226B89D9001F64F1 /* FTS4RecordTests.swift */, + 564A1F63226B89D5001F64F1 /* FTS4TableBuilderTests.swift */, + 564A1FB5226B89DD001F64F1 /* FTS5CustomTokenizerTests.swift */, + 564A1F8F226B89D9001F64F1 /* FTS5PatternTests.swift */, + 564A1FDD226B89E1001F64F1 /* FTS5RecordTests.swift */, + 564A1F8B226B89D9001F64F1 /* FTS5TableBuilderTests.swift */, + 564A1FC4226B89DE001F64F1 /* FTS5TokenizerTests.swift */, + 564A1F43226B89D0001F64F1 /* FTS5WrapperTokenizerTests.swift */, + 564A1FD5226B89E0001F64F1 /* GRDBTestCase.swift */, + 564A1F26226B89CD001F64F1 /* GRDBTests-Bridging-Header.h */, + 564A1F86226B89D8001F64F1 /* IndexInfoTests.swift */, + 564A1FCD226B89DF001F64F1 /* JoinSupportTests.swift */, + 564A1FB8226B89DD001F64F1 /* MapCursorTests.swift */, + 564A1FD3226B89E0001F64F1 /* MutablePersistableRecordChangesTests.swift */, + 564A1F27226B89CE001F64F1 /* MutablePersistableRecordDeleteTests.swift */, + 564A1F32226B89CF001F64F1 /* MutablePersistableRecordEncodableTests.swift */, + 564A1F98226B89DA001F64F1 /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */, + 564A1FCE226B89DF001F64F1 /* MutablePersistableRecordTests.swift */, + 564A1F2E226B89CF001F64F1 /* NumericOverflowTests.swift */, + 564A1FCB226B89DF001F64F1 /* PersistableRecordTests.swift */, + 564A1F49226B89D1001F64F1 /* PrefixCursorTests.swift */, + 564A1F46226B89D1001F64F1 /* PrefixWhileCursorTests.swift */, + 564A1F97226B89DA001F64F1 /* PrimaryKeyInfoTests.swift */, + 564A1F41226B89D0001F64F1 /* QueryInterfaceExpressionsTests.swift */, + 564A1F6E226B89D6001F64F1 /* QueryInterfaceExtensibilityTests.swift */, + 564A1F5F226B89D3001F64F1 /* QueryInterfacePromiseTests.swift */, + 564A1FA3226B89DB001F64F1 /* QueryInterfaceRequestTests.swift */, + 564A1F93226B89D9001F64F1 /* RawRepresentable+DatabaseValueConvertibleTests.swift */, + 564A1F76226B89D6001F64F1 /* Record+QueryInterfaceRequestTests.swift */, + 564A1FA4226B89DB001F64F1 /* RecordCopyTests.swift */, + 564A1F75226B89D6001F64F1 /* RecordEditedTests.swift */, + 564A1F51226B89D2001F64F1 /* RecordInitializersTests.swift */, + 564A1F77226B89D6001F64F1 /* RecordMinimalPrimaryKeyRowIDTests.swift */, + 564A1FAB226B89DC001F64F1 /* RecordMinimalPrimaryKeySingleTests.swift */, + 564A1F3B226B89D0001F64F1 /* RecordPersistenceConflictPolicy.swift */, + 564A1FA9226B89DB001F64F1 /* RecordPrimaryKeyHiddenRowIDTests.swift */, + 564A1F2D226B89CF001F64F1 /* RecordPrimaryKeyMultipleTests.swift */, + 564A1F4A226B89D1001F64F1 /* RecordPrimaryKeyNoneTests.swift */, + 564A1FC5226B89DE001F64F1 /* RecordPrimaryKeyRowIDTests.swift */, + 564A1F99226B89DA001F64F1 /* RecordPrimaryKeySingleTests.swift */, + 564A1FD1226B89E0001F64F1 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift */, + 564A1F5D226B89D3001F64F1 /* RecordSubClassTests.swift */, + 564A1FBE226B89DE001F64F1 /* RecordUniqueIndexTests.swift */, + 564A1F9A226B89DA001F64F1 /* RecordWithColumnNameManglingTests.swift */, + 564A1FA5226B89DB001F64F1 /* ResultCodeTests.swift */, + 564A1F7E226B89D7001F64F1 /* Row+FoundationTests.swift */, + 564A1F91226B89D9001F64F1 /* RowAdapterTests.swift */, + 564A1F29226B89CF001F64F1 /* RowCopiedFromStatementTests.swift */, + 564A1F7A226B89D7001F64F1 /* RowFetchTests.swift */, + 564A1F56226B89D2001F64F1 /* RowFromDictionaryLiteralTests.swift */, + 564A1F81226B89D7001F64F1 /* RowFromDictionaryTests.swift */, + 564A1F57226B89D3001F64F1 /* RowFromStatementTests.swift */, + 564A1F9B226B89DA001F64F1 /* RowTestCase.swift */, + 564A1F7F226B89D7001F64F1 /* SchedulingWatchdogTests.swift */, + 564A1F2A226B89CF001F64F1 /* SelectStatementTests.swift */, + 564A1F4E226B89D2001F64F1 /* SQLExpressionLiteralTests.swift */, + 564A1F4F226B89D2001F64F1 /* SQLInterpolationTests.swift */, + 564A1FA8226B89DB001F64F1 /* SQLLiteralTests.swift */, + 564A1F42226B89D0001F64F1 /* SQLRequestTests.swift */, + 564A1F58226B89D3001F64F1 /* StatementArguments+FoundationTests.swift */, + 564A1FC9226B89DF001F64F1 /* StatementArgumentsTests.swift */, + 564A1F89226B89D8001F64F1 /* StatementColumnConvertibleFetchTests.swift */, + 564A1F64226B89D5001F64F1 /* TableDefinitionTests.swift */, + 564A1FAA226B89DC001F64F1 /* TableRecord+QueryInterfaceRequestTests.swift */, + 564A1F9F226B89DA001F64F1 /* TableRecordTests.swift */, + 564A1F5B226B89D3001F64F1 /* TransactionObserverSavepointsTests.swift */, + 564A1FCA226B89DF001F64F1 /* TransactionObserverTests.swift */, + 564A1F3C226B89D0001F64F1 /* TruncateOptimizationTests.swift */, + 564A1FBD226B89DE001F64F1 /* UpdateStatementTests.swift */, + 564A1FB6226B89DD001F64F1 /* ValueObservationCombineTests.swift */, + 564A1FB9226B89DD001F64F1 /* ValueObservationCompactMapTests.swift */, + 564A1F84226B89D8001F64F1 /* ValueObservationCountTests.swift */, + 564A1F6C226B89D5001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift */, + 564A1FB7226B89DD001F64F1 /* ValueObservationExtentTests.swift */, + 564A1FC6226B89DF001F64F1 /* ValueObservationFetchTests.swift */, + 564A1F59226B89D3001F64F1 /* ValueObservationMapTests.swift */, + 5656A804229474F4001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */, + 564A1F85226B89D8001F64F1 /* ValueObservationReadonlyTests.swift */, + 564A1F44226B89D0001F64F1 /* ValueObservationRecordTests.swift */, + 564A1F87226B89D8001F64F1 /* ValueObservationReducerTests.swift */, + 564A1F9C226B89DA001F64F1 /* ValueObservationRowTests.swift */, + 564A1F48226B89D1001F64F1 /* ValueObservationSchedulingTests.swift */, + 564A1FBA226B89DD001F64F1 /* VirtualTableModuleTests.swift */, + ); + name = GRDBTests; + path = ../../GRDBTests; + sourceTree = ""; + }; + A39D84C3D9EF90DA939D10D7 /* Pods */ = { + isa = PBXGroup; + children = ( + 6A4788C0F815F6C5E4EBDE12 /* Pods-GRDBTests.debug.xcconfig */, + 04298D834C818285823558AB /* Pods-GRDBTests.release.xcconfig */, + 83BFB5733A86DAA3D0BEE684 /* Pods-GRDBTestsEncrypted.debug.xcconfig */, + 47C5D1B9AFFE795AA1D6EA5D /* Pods-GRDBTestsEncrypted.release.xcconfig */, + ); + path = Pods; + sourceTree = ""; + }; + EAA416B3A072FCB835929FD9 /* Frameworks */ = { + isa = PBXGroup; + children = ( + BEFDC53B1F7A33C242013A38 /* Pods_GRDBTests.framework */, + 7D5C7999E7D9CE7145687F5D /* Pods_GRDBTestsEncrypted.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 564A1F1C226B876D001F64F1 /* GRDBTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 564A1F23226B876D001F64F1 /* Build configuration list for PBXNativeTarget "GRDBTests" */; + buildPhases = ( + ED302FF19B64F1E73F967816 /* [CP] Check Pods Manifest.lock */, + 564A1F19226B876D001F64F1 /* Sources */, + 564A1F1A226B876D001F64F1 /* Frameworks */, + 564A1F1B226B876D001F64F1 /* Resources */, + 4B0FE810DCA4C7A83E571F34 /* [CP] Embed Pods Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = GRDBTests; + productName = GRDBTests; + productReference = 564A1F1D226B876D001F64F1 /* GRDBTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + 564A2095226B8E18001F64F1 /* GRDBTestsEncrypted */ = { + isa = PBXNativeTarget; + buildConfigurationList = 564A2153226B8E18001F64F1 /* Build configuration list for PBXNativeTarget "GRDBTestsEncrypted" */; + buildPhases = ( + 564A2096226B8E18001F64F1 /* [CP] Check Pods Manifest.lock */, + 564A2097226B8E18001F64F1 /* Sources */, + 564A214E226B8E18001F64F1 /* Frameworks */, + 564A2150226B8E18001F64F1 /* Resources */, + 564A2152226B8E18001F64F1 /* [CP] Embed Pods Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = GRDBTestsEncrypted; + productName = GRDBTests; + productReference = 564A2156226B8E18001F64F1 /* GRDBTestsEncrypted.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 564A1F13226B8750001F64F1 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1020; + LastUpgradeCheck = 1020; + TargetAttributes = { + 564A1F1C226B876D001F64F1 = { + CreatedOnToolsVersion = 10.2.1; + LastSwiftMigration = 1020; + }; + }; + }; + buildConfigurationList = 564A1F16226B8750001F64F1 /* Build configuration list for PBXProject "GRDBTests" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 564A1F12226B8750001F64F1; + productRefGroup = 564A1F1E226B876D001F64F1 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 564A1F1C226B876D001F64F1 /* GRDBTests */, + 564A2095226B8E18001F64F1 /* GRDBTestsEncrypted */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 564A1F1B226B876D001F64F1 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 564A2026226B89E1001F64F1 /* Betty.jpeg in Resources */, + 564A2159226C8F25001F64F1 /* db.SQLCipher3 in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 564A2150226B8E18001F64F1 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 564A2151226B8E18001F64F1 /* Betty.jpeg in Resources */, + 564A215A226C8F25001F64F1 /* db.SQLCipher3 in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 4B0FE810DCA4C7A83E571F34 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-GRDBTests/Pods-GRDBTests-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/GRDB.swift/GRDB.framework", + "${BUILT_PRODUCTS_DIR}/SQLCipher/SQLCipher.framework", + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + ); + outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GRDB.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SQLCipher.framework", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-GRDBTests/Pods-GRDBTests-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + 564A2096226B8E18001F64F1 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-GRDBTestsEncrypted-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + 564A2152226B8E18001F64F1 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-GRDBTestsEncrypted/Pods-GRDBTestsEncrypted-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/GRDB.swift/GRDB.framework", + "${BUILT_PRODUCTS_DIR}/SQLCipher/SQLCipher.framework", + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + ); + outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GRDB.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SQLCipher.framework", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-GRDBTestsEncrypted/Pods-GRDBTestsEncrypted-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + ED302FF19B64F1E73F967816 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-GRDBTests-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 564A1F19226B876D001F64F1 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 564A2024226B89E1001F64F1 /* DropWhileCursorTests.swift in Sources */, + 564A2021226B89E1001F64F1 /* DatabasePoolBackupTests.swift in Sources */, + 564A1FE8226B89E1001F64F1 /* DatabaseAggregateTests.swift in Sources */, + 564A1FEE226B89E1001F64F1 /* DatabaseFunctionTests.swift in Sources */, + 564A2083226B89E1001F64F1 /* DataMemoryTests.swift in Sources */, + 564A207F226B89E1001F64F1 /* DatabaseQueueSchemaCacheTests.swift in Sources */, + 564A201D226B89E1001F64F1 /* FTS3RecordTests.swift in Sources */, + 564A205C226B89E1001F64F1 /* ResultCodeTests.swift in Sources */, + 564A1FF2226B89E1001F64F1 /* RecordPersistenceConflictPolicy.swift in Sources */, + 564A1FEF226B89E1001F64F1 /* FetchedRecordsControllerTests.swift in Sources */, + 564A2075226B89E1001F64F1 /* RecordUniqueIndexTests.swift in Sources */, + 564A2058226B89E1001F64F1 /* FoundationUUIDTests.swift in Sources */, + 564A2049226B89E1001F64F1 /* DatabaseQueueReadOnlyTests.swift in Sources */, + 564A1FF0226B89E1001F64F1 /* AssociationHasOneThroughDecodableRecordTests.swift in Sources */, + 564A1FEA226B89E1001F64F1 /* AssociationChainRowScopesTests.swift in Sources */, + 564A1FFF226B89E1001F64F1 /* ValueObservationSchedulingTests.swift in Sources */, + 564A207D226B89E1001F64F1 /* ValueObservationFetchTests.swift in Sources */, + 564A203C226B89E1001F64F1 /* ValueObservationReadonlyTests.swift in Sources */, + 564A203B226B89E1001F64F1 /* ValueObservationCountTests.swift in Sources */, + 564A2053226B89E1001F64F1 /* ValueObservationRowTests.swift in Sources */, + 564A2048226B89E1001F64F1 /* RowAdapterTests.swift in Sources */, + 564A2040226B89E1001F64F1 /* StatementColumnConvertibleFetchTests.swift in Sources */, + 564A2019226B89E1001F64F1 /* DatabasePoolReleaseMemoryTests.swift in Sources */, + 560714F3227DD1AE0091BB10 /* AssociationPrefetchingSQLTests.swift in Sources */, + 564A2080226B89E1001F64F1 /* StatementArgumentsTests.swift in Sources */, + 564A2082226B89E1001F64F1 /* PersistableRecordTests.swift in Sources */, + 564A2016226B89E1001F64F1 /* QueryInterfacePromiseTests.swift in Sources */, + 564A207E226B89E1001F64F1 /* DatabaseTests.swift in Sources */, + 564A2033226B89E1001F64F1 /* AssociationHasManySQLTests.swift in Sources */, + 564A204A226B89E1001F64F1 /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */, + 56DF0021228DDFF000D611F3 /* AssociationPrefetchingRowTests.swift in Sources */, + 564A207B226B89E1001F64F1 /* FTS5TokenizerTests.swift in Sources */, + 564A202D226B89E1001F64F1 /* Record+QueryInterfaceRequestTests.swift in Sources */, + 564A2044226B89E1001F64F1 /* FTS4RecordTests.swift in Sources */, + 564A2086226B89E1001F64F1 /* AssociationTableAliasTestsSQLTests.swift in Sources */, + 564A2012226B89E1001F64F1 /* TransactionObserverSavepointsTests.swift in Sources */, + 564A200C226B89E1001F64F1 /* DatabaseRegionObservationTests.swift in Sources */, + 564A1FDE226B89E1001F64F1 /* MutablePersistableRecordDeleteTests.swift in Sources */, + 564A2072226B89E1001F64F1 /* DropFirstCursorTests.swift in Sources */, + 564A1FE9226B89E1001F64F1 /* MutablePersistableRecordEncodableTests.swift in Sources */, + 564A2003226B89E1001F64F1 /* DatabaseValueConvertibleFetchTests.swift in Sources */, + 564A2041226B89E1001F64F1 /* CGFloatTests.swift in Sources */, + 564A201E226B89E1001F64F1 /* DatabaseCursorTests.swift in Sources */, + 564A1FF9226B89E1001F64F1 /* SQLRequestTests.swift in Sources */, + 564A201B226B89E1001F64F1 /* TableDefinitionTests.swift in Sources */, + 564A202B226B89E1001F64F1 /* CompilationSubClassTests.swift in Sources */, + 564A2046226B89E1001F64F1 /* FTS5PatternTests.swift in Sources */, + 564A202F226B89E1001F64F1 /* DatabasePoolSchemaCacheTests.swift in Sources */, + 564A202C226B89E1001F64F1 /* RecordEditedTests.swift in Sources */, + 564A1FFB226B89E1001F64F1 /* ValueObservationRecordTests.swift in Sources */, + 564A2020226B89E1001F64F1 /* DatabaseRegionTests.swift in Sources */, + 564A201F226B89E1001F64F1 /* DatabaseQueueReleaseMemoryTests.swift in Sources */, + 564A2000226B89E1001F64F1 /* PrefixCursorTests.swift in Sources */, + 564A1FE1226B89E1001F64F1 /* SelectStatementTests.swift in Sources */, + 564A1FF8226B89E1001F64F1 /* QueryInterfaceExpressionsTests.swift in Sources */, + 564A202E226B89E1001F64F1 /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */, + 564A2078226B89E1001F64F1 /* ForeignKeyInfoTests.swift in Sources */, + 564A2050226B89E1001F64F1 /* RecordPrimaryKeySingleTests.swift in Sources */, + 564A2091226B89E1001F64F1 /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */, + 564A208F226B89E1001F64F1 /* AssociationParallelRowScopesTests.swift in Sources */, + 564A2047226B89E1001F64F1 /* AnyCursorTests.swift in Sources */, + 564A1FFC226B89E1001F64F1 /* DatabaseValueTests.swift in Sources */, + 564A200E226B89E1001F64F1 /* RowFromStatementTests.swift in Sources */, + 564A2069226B89E1001F64F1 /* FlattenCursorTests.swift in Sources */, + 564A2008226B89E1001F64F1 /* RecordInitializersTests.swift in Sources */, + 564A2018226B89E1001F64F1 /* ColumnExpressionTests.swift in Sources */, + 564A2023226B89E1001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift in Sources */, + 564A2010226B89E1001F64F1 /* ValueObservationMapTests.swift in Sources */, + 564A204F226B89E1001F64F1 /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */, + 564A206B226B89E1001F64F1 /* AssociationHasManyThroughSQLTests.swift in Sources */, + 564A2087226B89E1001F64F1 /* FTS3PatternTests.swift in Sources */, + 564A2067226B89E1001F64F1 /* EnumeratedCursorTests.swift in Sources */, + 564A1FF1226B89E1001F64F1 /* DatabaseValueConvertibleSubclassTests.swift in Sources */, + 564A2015226B89E1001F64F1 /* EncryptionTests.swift in Sources */, + 564A2032226B89E1001F64F1 /* AssociationBelongsToFetchableRecordTests.swift in Sources */, + 56057C5C2291B8D600A7CB10 /* AssociationHasManyRowScopeTests.swift in Sources */, + 564A1FE7226B89E1001F64F1 /* FoundationURLTests.swift in Sources */, + 564A1FFD226B89E1001F64F1 /* PrefixWhileCursorTests.swift in Sources */, + 564A2079226B89E1001F64F1 /* FoundationNSDecimalNumberTests.swift in Sources */, + 564A200A226B89E1001F64F1 /* DatabaseCollationTests.swift in Sources */, + 564A2061226B89E1001F64F1 /* TableRecord+QueryInterfaceRequestTests.swift in Sources */, + 564A2077226B89E1001F64F1 /* DatabaseWriterTests.swift in Sources */, + 564A1FE6226B89E1001F64F1 /* DatabaseQueueInMemoryTests.swift in Sources */, + 564A2064226B89E1001F64F1 /* AssociationHasOneThroughFetchableRecordTests.swift in Sources */, + 564A1FFA226B89E1001F64F1 /* FTS5WrapperTokenizerTests.swift in Sources */, + 564A2056226B89E1001F64F1 /* TableRecordTests.swift in Sources */, + 564A2042226B89E1001F64F1 /* FTS5TableBuilderTests.swift in Sources */, + 564A2089226B89E1001F64F1 /* DatabaseValueConversionErrorTests.swift in Sources */, + 564A2081226B89E1001F64F1 /* TransactionObserverTests.swift in Sources */, + 564A2045226B89E1001F64F1 /* FetchableRecordDecodableTests.swift in Sources */, + 564A1FF4226B89E1001F64F1 /* DatabasePoolCollationTests.swift in Sources */, + 564A2025226B89E1001F64F1 /* QueryInterfaceExtensibilityTests.swift in Sources */, + 564A2038226B89E1001F64F1 /* RowFromDictionaryTests.swift in Sources */, + 564A200B226B89E1001F64F1 /* DatabaseDateEncodingStrategyTests.swift in Sources */, + 564A2070226B89E1001F64F1 /* ValueObservationCompactMapTests.swift in Sources */, + 564A205D226B89E1001F64F1 /* DatabaseValueConvertibleEscapingTests.swift in Sources */, + 564A2068226B89E1001F64F1 /* DatabaseQueueConcurrencyTests.swift in Sources */, + 564A2017226B89E1001F64F1 /* AssociationAggregateTests.swift in Sources */, + 564A2065226B89E1001F64F1 /* AssociationHasOneSQLDerivationTests.swift in Sources */, + 564A200F226B89E1001F64F1 /* StatementArguments+FoundationTests.swift in Sources */, + 564A207A226B89E1001F64F1 /* FoundationDateComponentsTests.swift in Sources */, + 564A204E226B89E1001F64F1 /* PrimaryKeyInfoTests.swift in Sources */, + 564A2085226B89E1001F64F1 /* MutablePersistableRecordTests.swift in Sources */, + 564A2037226B89E1001F64F1 /* AssociationBelongsToSQLDerivationTests.swift in Sources */, + 564A201C226B89E1001F64F1 /* DatabaseErrorTests.swift in Sources */, + 564A208D226B89E1001F64F1 /* DatabaseUUIDEncodingStrategyTests.swift in Sources */, + 564A204D226B89E1001F64F1 /* DatabaseQueueTests.swift in Sources */, + 564A2013226B89E1001F64F1 /* DatabaseLogErrorTests.swift in Sources */, + 564A1FE4226B89E1001F64F1 /* RecordPrimaryKeyMultipleTests.swift in Sources */, + 564A202A226B89E1001F64F1 /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */, + 564A2093226B89E1001F64F1 /* AssociationParallelSQLTests.swift in Sources */, + 564A2063226B89E1001F64F1 /* ColumnInfoTests.swift in Sources */, + 564A1FE3226B89E1001F64F1 /* DatabaseValueConvertibleEncodableTests.swift in Sources */, + 564A1FF5226B89E1001F64F1 /* AssociationRowScopeSearchTests.swift in Sources */, + 564A2034226B89E1001F64F1 /* FoundationNSDateTests.swift in Sources */, + 564A1FDF226B89E1001F64F1 /* AssociationHasOneThroughRowScopeTests.swift in Sources */, + 564A2054226B89E1001F64F1 /* AssociationHasOneSQLTests.swift in Sources */, + 564A2028226B89E1001F64F1 /* FoundationNSNumberTests.swift in Sources */, + 564A2005226B89E1001F64F1 /* SQLExpressionLiteralTests.swift in Sources */, + 564A203F226B89E1001F64F1 /* AssociationBelongsToRowScopeTests.swift in Sources */, + 564A2030226B89E1001F64F1 /* DatabaseSavepointTests.swift in Sources */, + 564A206A226B89E1001F64F1 /* FoundationNSStringTests.swift in Sources */, + 564A206E226B89E1001F64F1 /* ValueObservationExtentTests.swift in Sources */, + 5656A805229474F4001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift in Sources */, + 564A2066226B89E1001F64F1 /* DatabaseTimestampTests.swift in Sources */, + 564A204B226B89E1001F64F1 /* FoundationNSDataTests.swift in Sources */, + 564A2009226B89E1001F64F1 /* AssociationHasOneThroughSQLTests.swift in Sources */, + 564A2090226B89E1001F64F1 /* FTS3TokenizerTests.swift in Sources */, + 564A2076226B89E1001F64F1 /* DatabaseReaderTests.swift in Sources */, + 564A2071226B89E1001F64F1 /* VirtualTableModuleTests.swift in Sources */, + 564A2084226B89E1001F64F1 /* JoinSupportTests.swift in Sources */, + 564A207C226B89E1001F64F1 /* RecordPrimaryKeyRowIDTests.swift in Sources */, + 564A2094226B89E1001F64F1 /* FTS5RecordTests.swift in Sources */, + 564A203D226B89E1001F64F1 /* IndexInfoTests.swift in Sources */, + 564A204C226B89E1001F64F1 /* AssociationBelongsToSQLTests.swift in Sources */, + 564A200D226B89E1001F64F1 /* RowFromDictionaryLiteralTests.swift in Sources */, + 564A205E226B89E1001F64F1 /* FoundationNSNullTests.swift in Sources */, + 564A208E226B89E1001F64F1 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */, + 564A2029226B89E1001F64F1 /* FTS3TableBuilderTests.swift in Sources */, + 564A2001226B89E1001F64F1 /* RecordPrimaryKeyNoneTests.swift in Sources */, + 564A2051226B89E1001F64F1 /* RecordWithColumnNameManglingTests.swift in Sources */, + 564A205B226B89E1001F64F1 /* RecordCopyTests.swift in Sources */, + 564A205F226B89E1001F64F1 /* SQLLiteralTests.swift in Sources */, + 564A206C226B89E1001F64F1 /* FTS5CustomTokenizerTests.swift in Sources */, + 564A2002226B89E1001F64F1 /* DerivableRequestTests.swift in Sources */, + 56057C6B2291D0C000A7CB10 /* AssociationHasManyThroughRowScopeTests.swift in Sources */, + 564A1FEB226B89E1001F64F1 /* FoundationNSUUIDTests.swift in Sources */, + 564A1FFE226B89E1001F64F1 /* FilterCursorTests.swift in Sources */, + 564A208A226B89E1001F64F1 /* MutablePersistableRecordChangesTests.swift in Sources */, + 564A2092226B89E1001F64F1 /* DatabasePoolConcurrencyTests.swift in Sources */, + 564A1FE0226B89E1001F64F1 /* RowCopiedFromStatementTests.swift in Sources */, + 564A2007226B89E1001F64F1 /* FoundationDataTests.swift in Sources */, + 564A201A226B89E1001F64F1 /* FTS4TableBuilderTests.swift in Sources */, + 564A2059226B89E1001F64F1 /* DatabaseValueConversionTests.swift in Sources */, + 564A1FE2226B89E1001F64F1 /* DatabaseQueueBackupTests.swift in Sources */, + 564A1FF7226B89E1001F64F1 /* DatabaseValueConvertibleDecodableTests.swift in Sources */, + 564A2074226B89E1001F64F1 /* UpdateStatementTests.swift in Sources */, + 564A203E226B89E1001F64F1 /* ValueObservationReducerTests.swift in Sources */, + 564A2035226B89E1001F64F1 /* Row+FoundationTests.swift in Sources */, + 564A205A226B89E1001F64F1 /* QueryInterfaceRequestTests.swift in Sources */, + 569BBA2E228DF90200478429 /* AssociationPrefetchingFetchableRecordTests.swift in Sources */, + 564A2011226B89E1001F64F1 /* FetchRequestTests.swift in Sources */, + 564A2060226B89E1001F64F1 /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */, + 564A2004226B89E1001F64F1 /* AssociationChainSQLTests.swift in Sources */, + 564A208C226B89E1001F64F1 /* GRDBTestCase.swift in Sources */, + 564A1FED226B89E1001F64F1 /* CompilationProtocolTests.swift in Sources */, + 564A2014226B89E1001F64F1 /* RecordSubClassTests.swift in Sources */, + 564A2027226B89E1001F64F1 /* AssociationParallelDecodableRecordTests.swift in Sources */, + 564A1FEC226B89E1001F64F1 /* AssociationBelongsToDecodableRecordTests.swift in Sources */, + 564A208B226B89E1001F64F1 /* DatabaseMigratorTests.swift in Sources */, + 564A206D226B89E1001F64F1 /* ValueObservationCombineTests.swift in Sources */, + 564A2022226B89E1001F64F1 /* CursorTests.swift in Sources */, + 564A203A226B89E1001F64F1 /* DatabaseDateDecodingStrategyTests.swift in Sources */, + 564A2036226B89E1001F64F1 /* SchedulingWatchdogTests.swift in Sources */, + 560432AC228F1761009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */, + 564A2052226B89E1001F64F1 /* RowTestCase.swift in Sources */, + 564A1FF3226B89E1001F64F1 /* TruncateOptimizationTests.swift in Sources */, + 56DF0023228DDFF000D611F3 /* AssociationPrefetchingCodableRecordTests.swift in Sources */, + 564A2088226B89E1001F64F1 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */, + 564A2039226B89E1001F64F1 /* DatabasePoolReadOnlyTests.swift in Sources */, + 564A2055226B89E1001F64F1 /* FoundationNSURLTests.swift in Sources */, + 564A2073226B89E1001F64F1 /* FetchableRecordTests.swift in Sources */, + 564A2031226B89E1001F64F1 /* RowFetchTests.swift in Sources */, + 564A1FF6226B89E1001F64F1 /* DatabaseSnapshotTests.swift in Sources */, + 564A2057226B89E1001F64F1 /* FoundationDateTests.swift in Sources */, + 564A2043226B89E1001F64F1 /* DatabasePoolFunctionTests.swift in Sources */, + 564A2006226B89E1001F64F1 /* SQLInterpolationTests.swift in Sources */, + 564A206F226B89E1001F64F1 /* MapCursorTests.swift in Sources */, + 564A1FE5226B89E1001F64F1 /* NumericOverflowTests.swift in Sources */, + 564A2062226B89E1001F64F1 /* RecordMinimalPrimaryKeySingleTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 564A2097226B8E18001F64F1 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 564A2098226B8E18001F64F1 /* DropWhileCursorTests.swift in Sources */, + 564A2099226B8E18001F64F1 /* DatabasePoolBackupTests.swift in Sources */, + 564A209A226B8E18001F64F1 /* DatabaseAggregateTests.swift in Sources */, + 564A209B226B8E18001F64F1 /* DatabaseFunctionTests.swift in Sources */, + 564A209C226B8E18001F64F1 /* DataMemoryTests.swift in Sources */, + 564A209D226B8E18001F64F1 /* DatabaseQueueSchemaCacheTests.swift in Sources */, + 564A209E226B8E18001F64F1 /* FTS3RecordTests.swift in Sources */, + 564A209F226B8E18001F64F1 /* ResultCodeTests.swift in Sources */, + 564A20A0226B8E18001F64F1 /* RecordPersistenceConflictPolicy.swift in Sources */, + 564A20A1226B8E18001F64F1 /* FetchedRecordsControllerTests.swift in Sources */, + 564A20A2226B8E18001F64F1 /* RecordUniqueIndexTests.swift in Sources */, + 564A20A3226B8E18001F64F1 /* FoundationUUIDTests.swift in Sources */, + 564A20A4226B8E18001F64F1 /* DatabaseQueueReadOnlyTests.swift in Sources */, + 564A20A5226B8E18001F64F1 /* AssociationHasOneThroughDecodableRecordTests.swift in Sources */, + 564A20A6226B8E18001F64F1 /* AssociationChainRowScopesTests.swift in Sources */, + 564A20A7226B8E18001F64F1 /* ValueObservationSchedulingTests.swift in Sources */, + 564A20A8226B8E18001F64F1 /* ValueObservationFetchTests.swift in Sources */, + 564A20A9226B8E18001F64F1 /* ValueObservationReadonlyTests.swift in Sources */, + 564A20AA226B8E18001F64F1 /* ValueObservationCountTests.swift in Sources */, + 564A20AB226B8E18001F64F1 /* ValueObservationRowTests.swift in Sources */, + 564A20AC226B8E18001F64F1 /* RowAdapterTests.swift in Sources */, + 564A20AD226B8E18001F64F1 /* StatementColumnConvertibleFetchTests.swift in Sources */, + 564A20AE226B8E18001F64F1 /* DatabasePoolReleaseMemoryTests.swift in Sources */, + 560714F4227DD1AE0091BB10 /* AssociationPrefetchingSQLTests.swift in Sources */, + 564A20AF226B8E18001F64F1 /* StatementArgumentsTests.swift in Sources */, + 564A20B0226B8E18001F64F1 /* PersistableRecordTests.swift in Sources */, + 564A20B1226B8E18001F64F1 /* QueryInterfacePromiseTests.swift in Sources */, + 564A20B2226B8E18001F64F1 /* DatabaseTests.swift in Sources */, + 564A20B3226B8E18001F64F1 /* AssociationHasManySQLTests.swift in Sources */, + 564A20B4226B8E18001F64F1 /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */, + 56DF0022228DDFF000D611F3 /* AssociationPrefetchingRowTests.swift in Sources */, + 564A20B5226B8E18001F64F1 /* FTS5TokenizerTests.swift in Sources */, + 564A20B6226B8E18001F64F1 /* Record+QueryInterfaceRequestTests.swift in Sources */, + 564A20B7226B8E18001F64F1 /* FTS4RecordTests.swift in Sources */, + 564A20B8226B8E18001F64F1 /* AssociationTableAliasTestsSQLTests.swift in Sources */, + 564A20B9226B8E18001F64F1 /* TransactionObserverSavepointsTests.swift in Sources */, + 564A20BA226B8E18001F64F1 /* DatabaseRegionObservationTests.swift in Sources */, + 564A20BB226B8E18001F64F1 /* MutablePersistableRecordDeleteTests.swift in Sources */, + 564A20BC226B8E18001F64F1 /* DropFirstCursorTests.swift in Sources */, + 564A20BD226B8E18001F64F1 /* MutablePersistableRecordEncodableTests.swift in Sources */, + 564A20BE226B8E18001F64F1 /* DatabaseValueConvertibleFetchTests.swift in Sources */, + 564A20BF226B8E18001F64F1 /* CGFloatTests.swift in Sources */, + 564A20C0226B8E18001F64F1 /* DatabaseCursorTests.swift in Sources */, + 564A20C1226B8E18001F64F1 /* SQLRequestTests.swift in Sources */, + 564A20C2226B8E18001F64F1 /* TableDefinitionTests.swift in Sources */, + 564A20C3226B8E18001F64F1 /* CompilationSubClassTests.swift in Sources */, + 564A20C4226B8E18001F64F1 /* FTS5PatternTests.swift in Sources */, + 564A20C5226B8E18001F64F1 /* DatabasePoolSchemaCacheTests.swift in Sources */, + 564A20C6226B8E18001F64F1 /* RecordEditedTests.swift in Sources */, + 564A20C7226B8E18001F64F1 /* ValueObservationRecordTests.swift in Sources */, + 564A20C8226B8E18001F64F1 /* DatabaseRegionTests.swift in Sources */, + 564A20C9226B8E18001F64F1 /* DatabaseQueueReleaseMemoryTests.swift in Sources */, + 564A20CA226B8E18001F64F1 /* PrefixCursorTests.swift in Sources */, + 564A20CB226B8E18001F64F1 /* SelectStatementTests.swift in Sources */, + 564A20CC226B8E18001F64F1 /* QueryInterfaceExpressionsTests.swift in Sources */, + 564A20CD226B8E18001F64F1 /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */, + 564A20CE226B8E18001F64F1 /* ForeignKeyInfoTests.swift in Sources */, + 564A20CF226B8E18001F64F1 /* RecordPrimaryKeySingleTests.swift in Sources */, + 564A20D0226B8E18001F64F1 /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */, + 564A20D1226B8E18001F64F1 /* AssociationParallelRowScopesTests.swift in Sources */, + 564A20D2226B8E18001F64F1 /* AnyCursorTests.swift in Sources */, + 564A20D3226B8E18001F64F1 /* DatabaseValueTests.swift in Sources */, + 564A20D4226B8E18001F64F1 /* RowFromStatementTests.swift in Sources */, + 564A20D5226B8E18001F64F1 /* FlattenCursorTests.swift in Sources */, + 564A20D6226B8E18001F64F1 /* RecordInitializersTests.swift in Sources */, + 564A20D7226B8E18001F64F1 /* ColumnExpressionTests.swift in Sources */, + 564A20D8226B8E18001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift in Sources */, + 564A20D9226B8E18001F64F1 /* ValueObservationMapTests.swift in Sources */, + 564A20DA226B8E18001F64F1 /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */, + 564A20DB226B8E18001F64F1 /* AssociationHasManyThroughSQLTests.swift in Sources */, + 564A20DC226B8E18001F64F1 /* FTS3PatternTests.swift in Sources */, + 564A20DD226B8E18001F64F1 /* EnumeratedCursorTests.swift in Sources */, + 564A20DE226B8E18001F64F1 /* DatabaseValueConvertibleSubclassTests.swift in Sources */, + 564A20DF226B8E18001F64F1 /* EncryptionTests.swift in Sources */, + 564A20E0226B8E18001F64F1 /* AssociationBelongsToFetchableRecordTests.swift in Sources */, + 56057C5D2291B8D600A7CB10 /* AssociationHasManyRowScopeTests.swift in Sources */, + 564A20E1226B8E18001F64F1 /* FoundationURLTests.swift in Sources */, + 564A20E2226B8E18001F64F1 /* PrefixWhileCursorTests.swift in Sources */, + 564A20E3226B8E18001F64F1 /* FoundationNSDecimalNumberTests.swift in Sources */, + 564A20E4226B8E18001F64F1 /* DatabaseCollationTests.swift in Sources */, + 564A20E5226B8E18001F64F1 /* TableRecord+QueryInterfaceRequestTests.swift in Sources */, + 564A20E6226B8E18001F64F1 /* DatabaseWriterTests.swift in Sources */, + 564A20E7226B8E18001F64F1 /* DatabaseQueueInMemoryTests.swift in Sources */, + 564A20E8226B8E18001F64F1 /* AssociationHasOneThroughFetchableRecordTests.swift in Sources */, + 564A20E9226B8E18001F64F1 /* FTS5WrapperTokenizerTests.swift in Sources */, + 564A20EA226B8E18001F64F1 /* TableRecordTests.swift in Sources */, + 564A20EB226B8E18001F64F1 /* FTS5TableBuilderTests.swift in Sources */, + 564A20EC226B8E18001F64F1 /* DatabaseValueConversionErrorTests.swift in Sources */, + 564A20ED226B8E18001F64F1 /* TransactionObserverTests.swift in Sources */, + 564A20EE226B8E18001F64F1 /* FetchableRecordDecodableTests.swift in Sources */, + 564A20EF226B8E18001F64F1 /* DatabasePoolCollationTests.swift in Sources */, + 564A20F0226B8E18001F64F1 /* QueryInterfaceExtensibilityTests.swift in Sources */, + 564A20F1226B8E18001F64F1 /* RowFromDictionaryTests.swift in Sources */, + 564A20F2226B8E18001F64F1 /* DatabaseDateEncodingStrategyTests.swift in Sources */, + 564A20F3226B8E18001F64F1 /* ValueObservationCompactMapTests.swift in Sources */, + 564A20F4226B8E18001F64F1 /* DatabaseValueConvertibleEscapingTests.swift in Sources */, + 564A20F5226B8E18001F64F1 /* DatabaseQueueConcurrencyTests.swift in Sources */, + 564A20F6226B8E18001F64F1 /* AssociationAggregateTests.swift in Sources */, + 564A20F7226B8E18001F64F1 /* AssociationHasOneSQLDerivationTests.swift in Sources */, + 564A20F8226B8E18001F64F1 /* StatementArguments+FoundationTests.swift in Sources */, + 564A20F9226B8E18001F64F1 /* FoundationDateComponentsTests.swift in Sources */, + 564A20FA226B8E18001F64F1 /* PrimaryKeyInfoTests.swift in Sources */, + 564A20FB226B8E18001F64F1 /* MutablePersistableRecordTests.swift in Sources */, + 564A20FC226B8E18001F64F1 /* AssociationBelongsToSQLDerivationTests.swift in Sources */, + 564A20FD226B8E18001F64F1 /* DatabaseErrorTests.swift in Sources */, + 564A20FE226B8E18001F64F1 /* DatabaseUUIDEncodingStrategyTests.swift in Sources */, + 564A20FF226B8E18001F64F1 /* DatabaseQueueTests.swift in Sources */, + 564A2100226B8E18001F64F1 /* DatabaseLogErrorTests.swift in Sources */, + 564A2101226B8E18001F64F1 /* RecordPrimaryKeyMultipleTests.swift in Sources */, + 564A2102226B8E18001F64F1 /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */, + 564A2103226B8E18001F64F1 /* AssociationParallelSQLTests.swift in Sources */, + 564A2104226B8E18001F64F1 /* ColumnInfoTests.swift in Sources */, + 564A2105226B8E18001F64F1 /* DatabaseValueConvertibleEncodableTests.swift in Sources */, + 564A2106226B8E18001F64F1 /* AssociationRowScopeSearchTests.swift in Sources */, + 564A2107226B8E18001F64F1 /* FoundationNSDateTests.swift in Sources */, + 564A2108226B8E18001F64F1 /* AssociationHasOneThroughRowScopeTests.swift in Sources */, + 564A2109226B8E18001F64F1 /* AssociationHasOneSQLTests.swift in Sources */, + 564A210A226B8E18001F64F1 /* FoundationNSNumberTests.swift in Sources */, + 564A210B226B8E18001F64F1 /* SQLExpressionLiteralTests.swift in Sources */, + 564A210C226B8E18001F64F1 /* AssociationBelongsToRowScopeTests.swift in Sources */, + 564A210D226B8E18001F64F1 /* DatabaseSavepointTests.swift in Sources */, + 564A210E226B8E18001F64F1 /* FoundationNSStringTests.swift in Sources */, + 564A210F226B8E18001F64F1 /* ValueObservationExtentTests.swift in Sources */, + 5656A806229474F4001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift in Sources */, + 564A2110226B8E18001F64F1 /* DatabaseTimestampTests.swift in Sources */, + 564A2111226B8E18001F64F1 /* FoundationNSDataTests.swift in Sources */, + 564A2112226B8E18001F64F1 /* AssociationHasOneThroughSQLTests.swift in Sources */, + 564A2113226B8E18001F64F1 /* FTS3TokenizerTests.swift in Sources */, + 564A2114226B8E18001F64F1 /* DatabaseReaderTests.swift in Sources */, + 564A2115226B8E18001F64F1 /* VirtualTableModuleTests.swift in Sources */, + 564A2116226B8E18001F64F1 /* JoinSupportTests.swift in Sources */, + 564A2117226B8E18001F64F1 /* RecordPrimaryKeyRowIDTests.swift in Sources */, + 564A2118226B8E18001F64F1 /* FTS5RecordTests.swift in Sources */, + 564A2119226B8E18001F64F1 /* IndexInfoTests.swift in Sources */, + 564A211A226B8E18001F64F1 /* AssociationBelongsToSQLTests.swift in Sources */, + 564A211B226B8E18001F64F1 /* RowFromDictionaryLiteralTests.swift in Sources */, + 564A211C226B8E18001F64F1 /* FoundationNSNullTests.swift in Sources */, + 564A211D226B8E18001F64F1 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */, + 564A211E226B8E18001F64F1 /* FTS3TableBuilderTests.swift in Sources */, + 564A211F226B8E18001F64F1 /* RecordPrimaryKeyNoneTests.swift in Sources */, + 564A2120226B8E18001F64F1 /* RecordWithColumnNameManglingTests.swift in Sources */, + 564A2121226B8E18001F64F1 /* RecordCopyTests.swift in Sources */, + 564A2122226B8E18001F64F1 /* SQLLiteralTests.swift in Sources */, + 564A2123226B8E18001F64F1 /* FTS5CustomTokenizerTests.swift in Sources */, + 564A2124226B8E18001F64F1 /* DerivableRequestTests.swift in Sources */, + 56057C6C2291D0C000A7CB10 /* AssociationHasManyThroughRowScopeTests.swift in Sources */, + 564A2125226B8E18001F64F1 /* FoundationNSUUIDTests.swift in Sources */, + 564A2126226B8E18001F64F1 /* FilterCursorTests.swift in Sources */, + 564A2127226B8E18001F64F1 /* MutablePersistableRecordChangesTests.swift in Sources */, + 564A2128226B8E18001F64F1 /* DatabasePoolConcurrencyTests.swift in Sources */, + 564A2129226B8E18001F64F1 /* RowCopiedFromStatementTests.swift in Sources */, + 564A212A226B8E18001F64F1 /* FoundationDataTests.swift in Sources */, + 564A212B226B8E18001F64F1 /* FTS4TableBuilderTests.swift in Sources */, + 564A212C226B8E18001F64F1 /* DatabaseValueConversionTests.swift in Sources */, + 564A212D226B8E18001F64F1 /* DatabaseQueueBackupTests.swift in Sources */, + 564A212E226B8E18001F64F1 /* DatabaseValueConvertibleDecodableTests.swift in Sources */, + 564A212F226B8E18001F64F1 /* UpdateStatementTests.swift in Sources */, + 564A2130226B8E18001F64F1 /* ValueObservationReducerTests.swift in Sources */, + 564A2131226B8E18001F64F1 /* Row+FoundationTests.swift in Sources */, + 564A2132226B8E18001F64F1 /* QueryInterfaceRequestTests.swift in Sources */, + 569BBA2F228DF90200478429 /* AssociationPrefetchingFetchableRecordTests.swift in Sources */, + 564A2133226B8E18001F64F1 /* FetchRequestTests.swift in Sources */, + 564A2134226B8E18001F64F1 /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */, + 564A2135226B8E18001F64F1 /* AssociationChainSQLTests.swift in Sources */, + 564A2136226B8E18001F64F1 /* GRDBTestCase.swift in Sources */, + 564A2137226B8E18001F64F1 /* CompilationProtocolTests.swift in Sources */, + 564A2138226B8E18001F64F1 /* RecordSubClassTests.swift in Sources */, + 564A2139226B8E18001F64F1 /* AssociationParallelDecodableRecordTests.swift in Sources */, + 564A213A226B8E18001F64F1 /* AssociationBelongsToDecodableRecordTests.swift in Sources */, + 564A213B226B8E18001F64F1 /* DatabaseMigratorTests.swift in Sources */, + 564A213C226B8E18001F64F1 /* ValueObservationCombineTests.swift in Sources */, + 564A213D226B8E18001F64F1 /* CursorTests.swift in Sources */, + 564A213E226B8E18001F64F1 /* DatabaseDateDecodingStrategyTests.swift in Sources */, + 564A213F226B8E18001F64F1 /* SchedulingWatchdogTests.swift in Sources */, + 560432AD228F1761009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */, + 564A2140226B8E18001F64F1 /* RowTestCase.swift in Sources */, + 564A2141226B8E18001F64F1 /* TruncateOptimizationTests.swift in Sources */, + 56DF0024228DDFF000D611F3 /* AssociationPrefetchingCodableRecordTests.swift in Sources */, + 564A2142226B8E18001F64F1 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */, + 564A2143226B8E18001F64F1 /* DatabasePoolReadOnlyTests.swift in Sources */, + 564A2144226B8E18001F64F1 /* FoundationNSURLTests.swift in Sources */, + 564A2145226B8E18001F64F1 /* FetchableRecordTests.swift in Sources */, + 564A2146226B8E18001F64F1 /* RowFetchTests.swift in Sources */, + 564A2147226B8E18001F64F1 /* DatabaseSnapshotTests.swift in Sources */, + 564A2148226B8E18001F64F1 /* FoundationDateTests.swift in Sources */, + 564A2149226B8E18001F64F1 /* DatabasePoolFunctionTests.swift in Sources */, + 564A214A226B8E18001F64F1 /* SQLInterpolationTests.swift in Sources */, + 564A214B226B8E18001F64F1 /* MapCursorTests.swift in Sources */, + 564A214C226B8E18001F64F1 /* NumericOverflowTests.swift in Sources */, + 564A214D226B8E18001F64F1 /* RecordMinimalPrimaryKeySingleTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 564A1F17226B8750001F64F1 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + MACOSX_DEPLOYMENT_TARGET = 10.9; + SWIFT_VERSION = 4.2; + }; + name = Debug; + }; + 564A1F18226B8750001F64F1 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + MACOSX_DEPLOYMENT_TARGET = 10.9; + SWIFT_VERSION = 4.2; + }; + name = Release; + }; + 564A1F24226B876D001F64F1 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 6A4788C0F815F6C5E4EBDE12 /* Pods-GRDBTests.debug.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COMBINE_HIDPI_IMAGES = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + DEVELOPMENT_TEAM = AMD8W895CT; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INFOPLIST_FILE = Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 564A1F25226B876D001F64F1 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 04298D834C818285823558AB /* Pods-GRDBTests.release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COMBINE_HIDPI_IMAGES = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = AMD8W895CT; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INFOPLIST_FILE = Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 564A2154226B8E18001F64F1 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 83BFB5733A86DAA3D0BEE684 /* Pods-GRDBTestsEncrypted.debug.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COMBINE_HIDPI_IMAGES = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + DEVELOPMENT_TEAM = AMD8W895CT; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INFOPLIST_FILE = Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + OTHER_SWIFT_FLAGS = "$(inherited) -D GRDBCIPHER_USE_ENCRYPTION"; + PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 564A2155226B8E18001F64F1 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 47C5D1B9AFFE795AA1D6EA5D /* Pods-GRDBTestsEncrypted.release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COMBINE_HIDPI_IMAGES = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = AMD8W895CT; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INFOPLIST_FILE = Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + OTHER_SWIFT_FLAGS = "$(inherited) -D GRDBCIPHER_USE_ENCRYPTION"; + PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 564A1F16226B8750001F64F1 /* Build configuration list for PBXProject "GRDBTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 564A1F17226B8750001F64F1 /* Debug */, + 564A1F18226B8750001F64F1 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 564A1F23226B876D001F64F1 /* Build configuration list for PBXNativeTarget "GRDBTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 564A1F24226B876D001F64F1 /* Debug */, + 564A1F25226B876D001F64F1 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 564A2153226B8E18001F64F1 /* Build configuration list for PBXNativeTarget "GRDBTestsEncrypted" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 564A2154226B8E18001F64F1 /* Debug */, + 564A2155226B8E18001F64F1 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 564A1F13226B8750001F64F1 /* Project object */; +} diff --git a/Tests/GRDBCipher/GRDBiOS/GRDBiOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 70% rename from Tests/GRDBCipher/GRDBiOS/GRDBiOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/project.xcworkspace/contents.xcworkspacedata index e52b6660d..696bc4d71 100644 --- a/Tests/GRDBCipher/GRDBiOS/GRDBiOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:SQLCipher4.xcodeproj"> diff --git a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/GRDBCipherMacOS.entitlements b/Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 72% rename from Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/GRDBCipherMacOS.entitlements rename to Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist index 0c67376eb..18d981003 100644 --- a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/GRDBCipherMacOS.entitlements +++ b/Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -1,5 +1,8 @@ - + + IDEDidComputeMac32BitWarning + + diff --git a/GRDBCipher.xcodeproj/xcshareddata/xcschemes/GRDBCipherOSX.xcscheme b/Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/xcshareddata/xcschemes/GRDBTests.xcscheme similarity index 50% rename from GRDBCipher.xcodeproj/xcshareddata/xcschemes/GRDBCipherOSX.xcscheme rename to Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/xcshareddata/xcschemes/GRDBTests.xcscheme index 1586943d3..81d5a2758 100644 --- a/GRDBCipher.xcodeproj/xcshareddata/xcschemes/GRDBCipherOSX.xcscheme +++ b/Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/xcshareddata/xcschemes/GRDBTests.xcscheme @@ -1,6 +1,6 @@ + buildForRunning = "NO" + buildForProfiling = "NO" + buildForArchiving = "NO" + buildForAnalyzing = "NO"> + BlueprintIdentifier = "564A1F1C226B876D001F64F1" + BuildableName = "GRDBTests.xctest" + BlueprintName = "GRDBTests" + ReferencedContainer = "container:GRDBTests.xcodeproj"> - - - - + BlueprintIdentifier = "564A2095226B8E18001F64F1" + BuildableName = "GRDBTestsEncrypted.xctest" + BlueprintName = "GRDBTestsEncrypted" + ReferencedContainer = "container:GRDBTests.xcodeproj"> @@ -57,33 +43,37 @@ shouldUseLaunchSchemeArgsEnv = "YES"> + skipped = "NO" + parallelizable = "YES" + testExecutionOrdering = "random"> + BlueprintIdentifier = "564A1F1C226B876D001F64F1" + BuildableName = "GRDBTests.xctest" + BlueprintName = "GRDBTests" + ReferencedContainer = "container:GRDBTests.xcodeproj"> + skipped = "NO" + parallelizable = "YES" + testExecutionOrdering = "random"> + BlueprintIdentifier = "564A2095226B8E18001F64F1" + BuildableName = "GRDBTestsEncrypted.xctest" + BlueprintName = "GRDBTestsEncrypted" + ReferencedContainer = "container:GRDBTests.xcodeproj"> + BlueprintIdentifier = "564A1F1C226B876D001F64F1" + BuildableName = "GRDBTests.xctest" + BlueprintName = "GRDBTests" + ReferencedContainer = "container:GRDBTests.xcodeproj"> @@ -99,15 +89,6 @@ debugDocumentVersioning = "YES" debugServiceExtension = "internal" allowLocationSimulation = "YES"> - - - - @@ -117,15 +98,6 @@ savedToolIdentifier = "" useCustomWorkingDirectory = "NO" debugDocumentVersioning = "YES"> - - - - diff --git a/Tests/CocoaPods/SQLCipher4/GRDBTests.xcworkspace/contents.xcworkspacedata b/Tests/CocoaPods/SQLCipher4/GRDBTests.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..a75bfccf6 --- /dev/null +++ b/Tests/CocoaPods/SQLCipher4/GRDBTests.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/GRDBCipher.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/Tests/CocoaPods/SQLCipher4/GRDBTests.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 71% rename from GRDBCipher.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings rename to Tests/CocoaPods/SQLCipher4/GRDBTests.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist index 08de0be8d..18d981003 100644 --- a/GRDBCipher.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +++ b/Tests/CocoaPods/SQLCipher4/GRDBTests.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -2,7 +2,7 @@ - IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded - + IDEDidComputeMac32BitWarning + diff --git a/Tests/GRDBCipher/GRDBiOS/GRDBiOS/Info.plist b/Tests/CocoaPods/SQLCipher4/Info.plist similarity index 55% rename from Tests/GRDBCipher/GRDBiOS/GRDBiOS/Info.plist rename to Tests/CocoaPods/SQLCipher4/Info.plist index 38e98af23..b7c017de3 100644 --- a/Tests/GRDBCipher/GRDBiOS/GRDBiOS/Info.plist +++ b/Tests/CocoaPods/SQLCipher4/Info.plist @@ -3,7 +3,9 @@ CFBundleDevelopmentRegion - en + $(DEVELOPMENT_LANGUAGE) + LSApplicationCategoryType + CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier @@ -13,26 +15,10 @@ CFBundleName $(PRODUCT_NAME) CFBundlePackageType - APPL + BNDL CFBundleShortVersionString 1.0 CFBundleVersion 1 - LSRequiresIPhoneOS - - UILaunchStoryboardName - LaunchScreen - UIMainStoryboardFile - Main - UIRequiredDeviceCapabilities - - armv7 - - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - diff --git a/Tests/CocoaPods/SQLCipher4/Podfile b/Tests/CocoaPods/SQLCipher4/Podfile new file mode 100644 index 000000000..8dfbcd7cd --- /dev/null +++ b/Tests/CocoaPods/SQLCipher4/Podfile @@ -0,0 +1,15 @@ +platform :macos, '10.9' +use_frameworks! + +def common + pod 'GRDB.swift/SQLCipher', :path => '../../..' + pod 'SQLCipher', '~> 4.0' +end + +target 'GRDBTests' do + common +end + +target 'GRDBTestsEncrypted' do + common +end diff --git a/Tests/CocoaPods/SQLCipher4/Podfile.lock b/Tests/CocoaPods/SQLCipher4/Podfile.lock new file mode 100644 index 000000000..9b1e6a6f0 --- /dev/null +++ b/Tests/CocoaPods/SQLCipher4/Podfile.lock @@ -0,0 +1,28 @@ +PODS: + - GRDB.swift/SQLCipher (3.7.0): + - SQLCipher (>= 3.4.0) + - SQLCipher (4.1.0): + - SQLCipher/standard (= 4.1.0) + - SQLCipher/common (4.1.0) + - SQLCipher/standard (4.1.0): + - SQLCipher/common + +DEPENDENCIES: + - GRDB.swift/SQLCipher (from `../../..`) + - SQLCipher (~> 4.0) + +SPEC REPOS: + https://github.com/cocoapods/specs.git: + - SQLCipher + +EXTERNAL SOURCES: + GRDB.swift: + :path: "../../.." + +SPEC CHECKSUMS: + GRDB.swift: 71ab04a6e727e34c034513c4d15901ea35eb1f0d + SQLCipher: efbdb52cdbe340bcd892b1b14297df4e07241b7f + +PODFILE CHECKSUM: 38b242728294578d160432e83323aef60f0e488e + +COCOAPODS: 1.6.1 diff --git a/Tests/CocoaPods/SQLCipher4/db.SQLCipher3 b/Tests/CocoaPods/SQLCipher4/db.SQLCipher3 new file mode 100644 index 000000000..6a6fed7db Binary files /dev/null and b/Tests/CocoaPods/SQLCipher4/db.SQLCipher3 differ diff --git a/Tests/Crash/DatabasePoolCrashTests.swift b/Tests/Crash/DatabasePoolCrashTests.swift index fb19eeb51..d806e24fe 100644 --- a/Tests/Crash/DatabasePoolCrashTests.swift +++ b/Tests/Crash/DatabasePoolCrashTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,7 +10,7 @@ class DatabasePoolCrashTests: GRDBCrashTestCase { func testReaderCanNotStartTransaction() { assertCrash("DatabasePool readers can not start transactions or savepoints.") { try dbPool.read { db in - let statement = try db.makeUpdateStatement("BEGIN TRANSACTION") + let statement = try db.makeUpdateStatement(sql: "BEGIN TRANSACTION") } } } @@ -20,7 +18,7 @@ class DatabasePoolCrashTests: GRDBCrashTestCase { func testReaderCanNotStartSavepoint() { assertCrash("DatabasePool readers can not start transactions or savepoints.") { try dbPool.read { db in - let statement = try db.makeUpdateStatement("SAVEPOINT foo") + let statement = try db.makeUpdateStatement(sql: "SAVEPOINT foo") } } } diff --git a/Tests/Crash/DatabaseQueueCrashTests.swift b/Tests/Crash/DatabaseQueueCrashTests.swift index b2159b5f4..29c27c947 100644 --- a/Tests/Crash/DatabaseQueueCrashTests.swift +++ b/Tests/Crash/DatabaseQueueCrashTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -51,7 +49,7 @@ class DatabaseQueueCrashTests: GRDBCrashTestCase { assertCrash("Database was not used on the correct thread: execute your statements inside DatabaseQueue.inDatabase() or DatabaseQueue.inTransaction(). If you get this error while iterating the result of a fetch() method, consider using the array returned by fetchAll() instead.") { var rows: DatabaseSequence? try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT)") + try db.execute(sql: "CREATE TABLE persons (name TEXT)") rows = try Row.fetch(db, "SELECT * FROM persons") } _ = rows!.makeIterator() @@ -62,7 +60,7 @@ class DatabaseQueueCrashTests: GRDBCrashTestCase { assertCrash("Database was not used on the correct thread: execute your statements inside DatabaseQueue.inDatabase() or DatabaseQueue.inTransaction(). If you get this error while iterating the result of a fetch() method, consider using the array returned by fetchAll() instead.") { var iterator: DatabaseIterator? try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT)") + try db.execute(sql: "CREATE TABLE persons (name TEXT)") iterator = try Row.fetch(db, "SELECT * FROM persons").makeIterator() } _ = iterator!.next() @@ -79,7 +77,7 @@ class DatabaseQueueCrashTests: GRDBCrashTestCase { let dbQueue2 = try! makeDatabaseQueue(path: dbQueuepath, configuration: dbConfiguration) try! dbQueue1.inDatabase { db in - try db.execute("CREATE TABLE stuffs (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE stuffs (id INTEGER PRIMARY KEY)") } let queue = NSOperationQueue() diff --git a/Tests/Crash/DatabaseValueConvertibleCrashTests.swift b/Tests/Crash/DatabaseValueConvertibleCrashTests.swift index af28694c1..213d0cc30 100644 --- a/Tests/Crash/DatabaseValueConvertibleCrashTests.swift +++ b/Tests/Crash/DatabaseValueConvertibleCrashTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -29,11 +27,11 @@ class DatabaseValueConvertibleCrashTests: GRDBCrashTestCase { func testCrashFetchDatabaseValueConvertibleFromStatement() { assertCrash("could not convert NULL to IntConvertible.") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (int Int)") - try db.execute("INSERT INTO ints (int) VALUES (1)") - try db.execute("INSERT INTO ints (int) VALUES (NULL)") + try db.execute(sql: "CREATE TABLE ints (int Int)") + try db.execute(sql: "INSERT INTO ints (int) VALUES (1)") + try db.execute(sql: "INSERT INTO ints (int) VALUES (NULL)") - let statement = try db.makeSelectStatement("SELECT int FROM ints ORDER BY int") + let statement = try db.makeSelectStatement(sql: "SELECT int FROM ints ORDER BY int") let sequence = IntConvertible.fetch(statement) for _ in sequence { } } @@ -43,11 +41,11 @@ class DatabaseValueConvertibleCrashTests: GRDBCrashTestCase { func testCrashFetchAllDatabaseValueConvertibleFromStatement() { assertCrash("could not convert NULL to IntConvertible.") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (int Int)") - try db.execute("INSERT INTO ints (int) VALUES (1)") - try db.execute("INSERT INTO ints (int) VALUES (NULL)") + try db.execute(sql: "CREATE TABLE ints (int Int)") + try db.execute(sql: "INSERT INTO ints (int) VALUES (1)") + try db.execute(sql: "INSERT INTO ints (int) VALUES (NULL)") - let statement = try db.makeSelectStatement("SELECT int FROM ints ORDER BY int") + let statement = try db.makeSelectStatement(sql: "SELECT int FROM ints ORDER BY int") _ = IntConvertible.fetchAll(statement) } } @@ -56,9 +54,9 @@ class DatabaseValueConvertibleCrashTests: GRDBCrashTestCase { func testCrashFetchDatabaseValueConvertibleFromDatabase() { assertCrash("could not convert NULL to IntConvertible.") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (int Int)") - try db.execute("INSERT INTO ints (int) VALUES (1)") - try db.execute("INSERT INTO ints (int) VALUES (NULL)") + try db.execute(sql: "CREATE TABLE ints (int Int)") + try db.execute(sql: "INSERT INTO ints (int) VALUES (1)") + try db.execute(sql: "INSERT INTO ints (int) VALUES (NULL)") let sequence = IntConvertible.fetch(db, "SELECT int FROM ints ORDER BY int") for _ in sequence { } @@ -69,11 +67,11 @@ class DatabaseValueConvertibleCrashTests: GRDBCrashTestCase { func testCrashFetchAllDatabaseValueConvertibleFromDatabase() { assertCrash("could not convert NULL to IntConvertible.") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (int Int)") - try db.execute("INSERT INTO ints (int) VALUES (1)") - try db.execute("INSERT INTO ints (int) VALUES (NULL)") + try db.execute(sql: "CREATE TABLE ints (int Int)") + try db.execute(sql: "INSERT INTO ints (int) VALUES (1)") + try db.execute(sql: "INSERT INTO ints (int) VALUES (NULL)") - _ = IntConvertible.fetchAll(db, "SELECT int FROM ints ORDER BY int") + _ = IntConvertible.fetchAll(db, sql: "SELECT int FROM ints ORDER BY int") } } } diff --git a/Tests/Crash/MigrationCrashTests.swift b/Tests/Crash/MigrationCrashTests.swift index f34dd355a..32ea14e95 100644 --- a/Tests/Crash/MigrationCrashTests.swift +++ b/Tests/Crash/MigrationCrashTests.swift @@ -1,6 +1,4 @@ -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/Crash/RecordCrashTests.swift b/Tests/Crash/RecordCrashTests.swift index 724797267..70ed00929 100644 --- a/Tests/Crash/RecordCrashTests.swift +++ b/Tests/Crash/RecordCrashTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -189,7 +187,7 @@ class RecordCrashTests: GRDBCrashTestCase { func testRecordWithEmptyPersistentDictionaryCanNotBeInserted() { assertCrash("RecordWithEmptyPersistentDictionary.persistentDictionary: invalid empty dictionary") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE records (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE records (id INTEGER PRIMARY KEY)") try RecordWithEmptyPersistentDictionary().insert(db) } } @@ -198,7 +196,7 @@ class RecordCrashTests: GRDBCrashTestCase { func testRecordWithEmptyPersistentDictionaryCanNotBeUpdated() { assertCrash("RecordWithEmptyPersistentDictionary.persistentDictionary: invalid empty dictionary") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE records (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE records (id INTEGER PRIMARY KEY)") try RecordWithEmptyPersistentDictionary().update(db) } } @@ -207,7 +205,7 @@ class RecordCrashTests: GRDBCrashTestCase { func testRecordWithEmptyPersistentDictionaryCanNotBeSaved() { assertCrash("RecordWithEmptyPersistentDictionary.persistentDictionary: invalid empty dictionary") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE records (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE records (id INTEGER PRIMARY KEY)") try RecordWithEmptyPersistentDictionary().save(db) } } @@ -216,7 +214,7 @@ class RecordCrashTests: GRDBCrashTestCase { func testRecordWithEmptyPersistentDictionaryCanNotBeDeleted() { assertCrash("RecordWithEmptyPersistentDictionary.persistentDictionary: invalid empty dictionary") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE records (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE records (id INTEGER PRIMARY KEY)") try RecordWithEmptyPersistentDictionary().delete(db) } } @@ -225,7 +223,7 @@ class RecordCrashTests: GRDBCrashTestCase { func testRecordWithEmptyPersistentDictionaryCanNotBeTestedForExistence() { assertCrash("RecordWithEmptyPersistentDictionary.persistentDictionary: invalid empty dictionary") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE records (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE records (id INTEGER PRIMARY KEY)") RecordWithEmptyPersistentDictionary().exists(db) } } @@ -238,7 +236,7 @@ class RecordCrashTests: GRDBCrashTestCase { func testRecordWithNilPrimaryKeyCanNotBeUpdated() { assertCrash("invalid primary key in ") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE records (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE records (id INTEGER PRIMARY KEY)") try RecordWithNilPrimaryKey().update(db) } } @@ -247,7 +245,7 @@ class RecordCrashTests: GRDBCrashTestCase { func testRecordWithNilPrimaryKeyCanNotBeDeleted() { assertCrash("invalid primary key in ") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE records (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE records (id INTEGER PRIMARY KEY)") try RecordWithNilPrimaryKey().delete(db) } } @@ -256,7 +254,7 @@ class RecordCrashTests: GRDBCrashTestCase { func testRecordWithNilPrimaryKeyCanNotBeTestedForExistence() { assertCrash("invalid primary key in ") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE records (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE records (id INTEGER PRIMARY KEY)") RecordWithNilPrimaryKey().exists(db) } } @@ -269,7 +267,7 @@ class RecordCrashTests: GRDBCrashTestCase { func testRecordForTableWithoutPrimaryKeyCanNotBeFetchedByID() { assertCrash("expected single column primary key in table: records") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE records (name TEXT)") + try db.execute(sql: "CREATE TABLE records (name TEXT)") _ = RecordForTableWithoutPrimaryKey.fetchOne(db, key: 1) } } @@ -278,7 +276,7 @@ class RecordCrashTests: GRDBCrashTestCase { func testRecordForTableWithoutPrimaryKeyCanNotBeUpdated() { assertCrash("invalid primary key in ") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE records (name TEXT)") + try db.execute(sql: "CREATE TABLE records (name TEXT)") try RecordForTableWithoutPrimaryKey().update(db) } } @@ -287,7 +285,7 @@ class RecordCrashTests: GRDBCrashTestCase { func testRecordForTableWithoutPrimaryKeyCanNotBeDeleted() { assertCrash("invalid primary key in ") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE records (name TEXT)") + try db.execute(sql: "CREATE TABLE records (name TEXT)") try RecordForTableWithoutPrimaryKey().delete(db) } } @@ -296,7 +294,7 @@ class RecordCrashTests: GRDBCrashTestCase { func testRecordForTableWithoutPrimaryKeyCanNotBeTestedForExistence() { assertCrash("invalid primary key in ") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE records (name TEXT)") + try db.execute(sql: "CREATE TABLE records (name TEXT)") RecordForTableWithoutPrimaryKey().exists(db) } } @@ -309,7 +307,7 @@ class RecordCrashTests: GRDBCrashTestCase { func testRecordForTableWithMultipleColumnsPrimaryKeyCanNotBeFetchedByID() { assertCrash("expected single column primary key in table: records") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE records (a TEXT, b TEXT, PRIMARY KEY(a,b))") + try db.execute(sql: "CREATE TABLE records (a TEXT, b TEXT, PRIMARY KEY(a,b))") _ = RecordForTableWithMultipleColumnsPrimaryKey.fetchOne(db, key: 1) } } @@ -322,7 +320,7 @@ class RecordCrashTests: GRDBCrashTestCase { func testRecordWithRowIDPrimaryKeyNotExposedInPersistentDictionaryCanNotBeInserted() { assertCrash("invalid primary key in ") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE records (id INTEGER PRIMARY KEY, name TEXT)") + try db.execute(sql: "CREATE TABLE records (id INTEGER PRIMARY KEY, name TEXT)") try RecordWithRowIDPrimaryKeyNotExposedInPersistentDictionary().update(db) } } diff --git a/Tests/Crash/StatementColumnConvertibleCrashTests.swift b/Tests/Crash/StatementColumnConvertibleCrashTests.swift index a1c8ad73c..24e44db00 100644 --- a/Tests/Crash/StatementColumnConvertibleCrashTests.swift +++ b/Tests/Crash/StatementColumnConvertibleCrashTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,11 +10,11 @@ class StatementColumnConvertibleCrashTests: GRDBCrashTestCase { func testCrashFetchStatementColumnConvertibleFromStatement() { assertCrash("could not convert NULL to Int.") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (int Int)") - try db.execute("INSERT INTO ints (int) VALUES (1)") - try db.execute("INSERT INTO ints (int) VALUES (NULL)") + try db.execute(sql: "CREATE TABLE ints (int Int)") + try db.execute(sql: "INSERT INTO ints (int) VALUES (1)") + try db.execute(sql: "INSERT INTO ints (int) VALUES (NULL)") - let statement = try db.makeSelectStatement("SELECT int FROM ints ORDER BY int") + let statement = try db.makeSelectStatement(sql: "SELECT int FROM ints ORDER BY int") let sequence = try Int.fetch(statement) for _ in sequence { } } @@ -26,11 +24,11 @@ class StatementColumnConvertibleCrashTests: GRDBCrashTestCase { func testCrashFetchAllStatementColumnConvertibleFromStatement() { assertCrash("could not convert NULL to Int.") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (int Int)") - try db.execute("INSERT INTO ints (int) VALUES (1)") - try db.execute("INSERT INTO ints (int) VALUES (NULL)") + try db.execute(sql: "CREATE TABLE ints (int Int)") + try db.execute(sql: "INSERT INTO ints (int) VALUES (1)") + try db.execute(sql: "INSERT INTO ints (int) VALUES (NULL)") - let statement = try db.makeSelectStatement("SELECT int FROM ints ORDER BY int") + let statement = try db.makeSelectStatement(sql: "SELECT int FROM ints ORDER BY int") _ = try Int.fetchAll(statement) } } @@ -39,9 +37,9 @@ class StatementColumnConvertibleCrashTests: GRDBCrashTestCase { func testCrashFetchStatementColumnConvertibleFromDatabase() { assertCrash("could not convert NULL to Int.") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (int Int)") - try db.execute("INSERT INTO ints (int) VALUES (1)") - try db.execute("INSERT INTO ints (int) VALUES (NULL)") + try db.execute(sql: "CREATE TABLE ints (int Int)") + try db.execute(sql: "INSERT INTO ints (int) VALUES (1)") + try db.execute(sql: "INSERT INTO ints (int) VALUES (NULL)") let sequence = try Int.fetch(db, "SELECT int FROM ints ORDER BY int") for _ in sequence { } @@ -52,11 +50,11 @@ class StatementColumnConvertibleCrashTests: GRDBCrashTestCase { func testCrashFetchAllStatementColumnConvertibleFromDatabase() { assertCrash("could not convert NULL to Int.") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (int Int)") - try db.execute("INSERT INTO ints (int) VALUES (1)") - try db.execute("INSERT INTO ints (int) VALUES (NULL)") + try db.execute(sql: "CREATE TABLE ints (int Int)") + try db.execute(sql: "INSERT INTO ints (int) VALUES (1)") + try db.execute(sql: "INSERT INTO ints (int) VALUES (NULL)") - _ = try Int.fetchAll(db, "SELECT int FROM ints ORDER BY int") + _ = try Int.fetchAll(db, sql: "SELECT int FROM ints ORDER BY int") } } } diff --git a/Tests/Crash/StatementCrashTests.swift b/Tests/Crash/StatementCrashTests.swift index a086b6599..6f053accd 100644 --- a/Tests/Crash/StatementCrashTests.swift +++ b/Tests/Crash/StatementCrashTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,66 +10,68 @@ class StatementCrashTests: GRDBCrashTestCase { func testInvalidStatementArguments() { assertCrash("SQLite error 1 with statement `INSERT INTO persons (name, age) VALUES (:name, :age)`: missing statement argument(s): age") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT, age INT)") - try! db.execute("INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur"]) + try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)") + try! db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur"]) } } assertCrash("SQLite error 21 with statement `INSERT INTO persons (name, age) VALUES ('Arthur', ?);`: wrong number of statement arguments: 0") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT, age INT)") - try db.execute( - "INSERT INTO persons (name, age) VALUES ('Arthur', ?);" + - "INSERT INTO persons (name, age) VALUES ('Barbara', ?);") + try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)") + try db.execute(sql: """ + INSERT INTO persons (name, age) VALUES ('Arthur', ?); + INSERT INTO persons (name, age) VALUES ('Barbara', ?); + """) } } assertCrash("SQLite error 21 with statement `INSERT INTO persons (name, age) VALUES ('Barbara', ?);`: wrong number of statement arguments: 0") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT, age INT)") - try db.execute( - "INSERT INTO persons (name, age) VALUES ('Arthur', ?);" + - "INSERT INTO persons (name, age) VALUES ('Barbara', ?);", - arguments: [41]) + try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)") + try db.execute(sql: """ + INSERT INTO persons (name, age) VALUES ('Arthur', ?); + INSERT INTO persons (name, age) VALUES ('Barbara', ?); + """, arguments: [41]) } } assertCrash("SQLite error 21 with statement `INSERT INTO persons (name, age) VALUES ('Arthur', :age1);`: missing statement argument(s): age1") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT, age INT)") - try db.execute( - "INSERT INTO persons (name, age) VALUES ('Arthur', :age1);" + - "INSERT INTO persons (name, age) VALUES ('Barbara', :age2);") + try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)") + try db.execute(sql: """ + INSERT INTO persons (name, age) VALUES ('Arthur', :age1); + INSERT INTO persons (name, age) VALUES ('Barbara', :age2); + """) } } assertCrash("SQLite error 21 with statement `INSERT INTO persons (name, age) VALUES ('Barbara', :age2);`: missing statement argument(s): age2") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT, age INT)") - try db.execute( - "INSERT INTO persons (name, age) VALUES ('Arthur', :age1);" + - "INSERT INTO persons (name, age) VALUES ('Barbara', :age2);", - arguments: ["age1": 41]) + try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)") + try db.execute(sql: """ + INSERT INTO persons (name, age) VALUES ('Arthur', :age1); + INSERT INTO persons (name, age) VALUES ('Barbara', :age2); + """, arguments: ["age1": 41]) } } assertCrash("SQLite error 21: wrong number of statement arguments: 3") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT, age INT)") - try db.execute( - "INSERT INTO persons (name, age) VALUES ('Arthur', :age1);" + - "INSERT INTO persons (name, age) VALUES ('Arthur', :age2);", - arguments: [41, 32, 17]) + try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)") + try db.execute(sql: """ + INSERT INTO persons (name, age) VALUES ('Arthur', :age1); + INSERT INTO persons (name, age) VALUES ('Arthur', :age2); + """, arguments: [41, 32, 17]) } } assertCrash("SQLite error 21: wrong number of statement arguments: 3") { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT, age INT)") - try db.execute( - "INSERT INTO persons (name, age) VALUES ('Arthur', ?);" + - "INSERT INTO persons (name, age) VALUES ('Arthur', ?);", - arguments: [41, 32, 17]) + try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)") + try db.execute(sql: """ + INSERT INTO persons (name, age) VALUES ('Arthur', ?); + INSERT INTO persons (name, age) VALUES ('Arthur', ?); + """, arguments: [41, 32, 17]) } } } diff --git a/Tests/GRDBCipher/GRDBiOS/GRDBiOS.xcodeproj/project.pbxproj b/Tests/GRDBCipher/GRDBiOS/GRDBiOS.xcodeproj/project.pbxproj deleted file mode 100644 index 622f6f77e..000000000 --- a/Tests/GRDBCipher/GRDBiOS/GRDBiOS.xcodeproj/project.pbxproj +++ /dev/null @@ -1,490 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 56288F841FD4256C0091310B /* GRDBCipher.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 56288F7D1FD424A40091310B /* GRDBCipher.framework */; }; - 56288F851FD4256C0091310B /* GRDBCipher.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 56288F7D1FD424A40091310B /* GRDBCipher.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 56B0372B1E8E31D0003B6DA4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B0372A1E8E31D0003B6DA4 /* AppDelegate.swift */; }; - 56B0372D1E8E31D0003B6DA4 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B0372C1E8E31D0003B6DA4 /* ViewController.swift */; }; - 56B037301E8E31D0003B6DA4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 56B0372E1E8E31D0003B6DA4 /* Main.storyboard */; }; - 56B037321E8E31D0003B6DA4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 56B037311E8E31D0003B6DA4 /* Assets.xcassets */; }; - 56B037351E8E31D0003B6DA4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 56B037331E8E31D0003B6DA4 /* LaunchScreen.storyboard */; }; - 56B0373D1E8E3219003B6DA4 /* Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B0373C1E8E3219003B6DA4 /* Database.swift */; }; - 56B0377F1E8E32B9003B6DA4 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B0377E1E8E32B9003B6DA4 /* Person.swift */; }; -/* End PBXBuildFile section */ - -/* Begin PBXContainerItemProxy section */ - 56288F761FD424A40091310B /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 56B0373E1E8E3250003B6DA4 /* GRDBCipher.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 560FC54D1CB003810014AA8E; - remoteInfo = GRDBCipherOSX; - }; - 56288F781FD424A40091310B /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 56B0373E1E8E3250003B6DA4 /* GRDBCipher.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 560FC5B01CB00B880014AA8E; - remoteInfo = GRDBCipherOSXTests; - }; - 56288F7A1FD424A40091310B /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 56B0373E1E8E3250003B6DA4 /* GRDBCipher.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 5671566C1CB16729007DC145; - remoteInfo = GRDBCipherOSXEncryptedTests; - }; - 56288F7C1FD424A40091310B /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 56B0373E1E8E3250003B6DA4 /* GRDBCipher.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 56AFCA231CB1A8BB00F48B96; - remoteInfo = GRDBCipheriOS; - }; - 56288F7E1FD424A40091310B /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 56B0373E1E8E3250003B6DA4 /* GRDBCipher.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 56AFCA7F1CB1AA9900F48B96; - remoteInfo = GRDBCipheriOSTests; - }; - 56288F801FD424A40091310B /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 56B0373E1E8E3250003B6DA4 /* GRDBCipher.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 56AFCAD71CB1ABC800F48B96; - remoteInfo = GRDBCipheriOSEncryptedTests; - }; - 56288F821FD424AD0091310B /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 56B0373E1E8E3250003B6DA4 /* GRDBCipher.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 56AFC9EE1CB1A8BB00F48B96; - remoteInfo = GRDBCipheriOS; - }; - 56288F861FD4256C0091310B /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 56B0373E1E8E3250003B6DA4 /* GRDBCipher.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 56AFC9EE1CB1A8BB00F48B96; - remoteInfo = GRDBCipheriOS; - }; -/* End PBXContainerItemProxy section */ - -/* Begin PBXCopyFilesBuildPhase section */ - 56B0377D1E8E328C003B6DA4 /* Embed Frameworks */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = ""; - dstSubfolderSpec = 10; - files = ( - 56288F851FD4256C0091310B /* GRDBCipher.framework in Embed Frameworks */, - ); - name = "Embed Frameworks"; - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXCopyFilesBuildPhase section */ - -/* Begin PBXFileReference section */ - 56B037271E8E31D0003B6DA4 /* GRDBiOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GRDBiOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 56B0372A1E8E31D0003B6DA4 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; - 56B0372C1E8E31D0003B6DA4 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; - 56B0372F1E8E31D0003B6DA4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; - 56B037311E8E31D0003B6DA4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 56B037341E8E31D0003B6DA4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; - 56B037361E8E31D0003B6DA4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 56B0373C1E8E3219003B6DA4 /* Database.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Database.swift; sourceTree = ""; }; - 56B0373E1E8E3250003B6DA4 /* GRDBCipher.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = GRDBCipher.xcodeproj; path = ../../../GRDBCipher.xcodeproj; sourceTree = ""; }; - 56B0377E1E8E32B9003B6DA4 /* Person.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Person.swift; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 56B037241E8E31D0003B6DA4 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 56288F841FD4256C0091310B /* GRDBCipher.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 56288F6E1FD424A40091310B /* Products */ = { - isa = PBXGroup; - children = ( - 56288F771FD424A40091310B /* GRDBCipher.framework */, - 56288F791FD424A40091310B /* GRDBCipherOSXTests.xctest */, - 56288F7B1FD424A40091310B /* GRDBCipherOSXEncryptedTests.xctest */, - 56288F7D1FD424A40091310B /* GRDBCipher.framework */, - 56288F7F1FD424A40091310B /* GRDBCipheriOSTests.xctest */, - 56288F811FD424A40091310B /* GRDBCipheriOSEncryptedTests.xctest */, - ); - name = Products; - sourceTree = ""; - }; - 56B0371E1E8E31D0003B6DA4 = { - isa = PBXGroup; - children = ( - 56B0373E1E8E3250003B6DA4 /* GRDBCipher.xcodeproj */, - 56B037291E8E31D0003B6DA4 /* GRDBiOS */, - 56B037281E8E31D0003B6DA4 /* Products */, - ); - sourceTree = ""; - }; - 56B037281E8E31D0003B6DA4 /* Products */ = { - isa = PBXGroup; - children = ( - 56B037271E8E31D0003B6DA4 /* GRDBiOS.app */, - ); - name = Products; - sourceTree = ""; - }; - 56B037291E8E31D0003B6DA4 /* GRDBiOS */ = { - isa = PBXGroup; - children = ( - 56B0372A1E8E31D0003B6DA4 /* AppDelegate.swift */, - 56B0373C1E8E3219003B6DA4 /* Database.swift */, - 56B0377E1E8E32B9003B6DA4 /* Person.swift */, - 56B0372C1E8E31D0003B6DA4 /* ViewController.swift */, - 56B0372E1E8E31D0003B6DA4 /* Main.storyboard */, - 56B037311E8E31D0003B6DA4 /* Assets.xcassets */, - 56B037331E8E31D0003B6DA4 /* LaunchScreen.storyboard */, - 56B037361E8E31D0003B6DA4 /* Info.plist */, - ); - path = GRDBiOS; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 56B037261E8E31D0003B6DA4 /* GRDBiOS */ = { - isa = PBXNativeTarget; - buildConfigurationList = 56B037391E8E31D0003B6DA4 /* Build configuration list for PBXNativeTarget "GRDBiOS" */; - buildPhases = ( - 56B037231E8E31D0003B6DA4 /* Sources */, - 56B037241E8E31D0003B6DA4 /* Frameworks */, - 56B037251E8E31D0003B6DA4 /* Resources */, - 56B0377D1E8E328C003B6DA4 /* Embed Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - 56288F831FD424AD0091310B /* PBXTargetDependency */, - 56288F871FD4256C0091310B /* PBXTargetDependency */, - ); - name = GRDBiOS; - productName = GRDBiOS; - productReference = 56B037271E8E31D0003B6DA4 /* GRDBiOS.app */; - productType = "com.apple.product-type.application"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 56B0371F1E8E31D0003B6DA4 /* Project object */ = { - isa = PBXProject; - attributes = { - LastSwiftUpdateCheck = 0830; - LastUpgradeCheck = 0910; - ORGANIZATIONNAME = "Gwendal Roué"; - TargetAttributes = { - 56B037261E8E31D0003B6DA4 = { - CreatedOnToolsVersion = 8.3; - DevelopmentTeam = AMD8W895CT; - ProvisioningStyle = Automatic; - }; - }; - }; - buildConfigurationList = 56B037221E8E31D0003B6DA4 /* Build configuration list for PBXProject "GRDBiOS" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = 56B0371E1E8E31D0003B6DA4; - productRefGroup = 56B037281E8E31D0003B6DA4 /* Products */; - projectDirPath = ""; - projectReferences = ( - { - ProductGroup = 56288F6E1FD424A40091310B /* Products */; - ProjectRef = 56B0373E1E8E3250003B6DA4 /* GRDBCipher.xcodeproj */; - }, - ); - projectRoot = ""; - targets = ( - 56B037261E8E31D0003B6DA4 /* GRDBiOS */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXReferenceProxy section */ - 56288F771FD424A40091310B /* GRDBCipher.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = GRDBCipher.framework; - remoteRef = 56288F761FD424A40091310B /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 56288F791FD424A40091310B /* GRDBCipherOSXTests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = GRDBCipherOSXTests.xctest; - remoteRef = 56288F781FD424A40091310B /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 56288F7B1FD424A40091310B /* GRDBCipherOSXEncryptedTests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = GRDBCipherOSXEncryptedTests.xctest; - remoteRef = 56288F7A1FD424A40091310B /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 56288F7D1FD424A40091310B /* GRDBCipher.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = GRDBCipher.framework; - remoteRef = 56288F7C1FD424A40091310B /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 56288F7F1FD424A40091310B /* GRDBCipheriOSTests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = GRDBCipheriOSTests.xctest; - remoteRef = 56288F7E1FD424A40091310B /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 56288F811FD424A40091310B /* GRDBCipheriOSEncryptedTests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = GRDBCipheriOSEncryptedTests.xctest; - remoteRef = 56288F801FD424A40091310B /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; -/* End PBXReferenceProxy section */ - -/* Begin PBXResourcesBuildPhase section */ - 56B037251E8E31D0003B6DA4 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 56B037351E8E31D0003B6DA4 /* LaunchScreen.storyboard in Resources */, - 56B037321E8E31D0003B6DA4 /* Assets.xcassets in Resources */, - 56B037301E8E31D0003B6DA4 /* Main.storyboard in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 56B037231E8E31D0003B6DA4 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 56B0373D1E8E3219003B6DA4 /* Database.swift in Sources */, - 56B0372D1E8E31D0003B6DA4 /* ViewController.swift in Sources */, - 56B0377F1E8E32B9003B6DA4 /* Person.swift in Sources */, - 56B0372B1E8E31D0003B6DA4 /* AppDelegate.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXTargetDependency section */ - 56288F831FD424AD0091310B /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = GRDBCipheriOS; - targetProxy = 56288F821FD424AD0091310B /* PBXContainerItemProxy */; - }; - 56288F871FD4256C0091310B /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = GRDBCipheriOS; - targetProxy = 56288F861FD4256C0091310B /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - -/* Begin PBXVariantGroup section */ - 56B0372E1E8E31D0003B6DA4 /* Main.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 56B0372F1E8E31D0003B6DA4 /* Base */, - ); - name = Main.storyboard; - sourceTree = ""; - }; - 56B037331E8E31D0003B6DA4 /* LaunchScreen.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 56B037341E8E31D0003B6DA4 /* Base */, - ); - name = LaunchScreen.storyboard; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - -/* Begin XCBuildConfiguration section */ - 56B037371E8E31D0003B6DA4 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.1; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - }; - name = Debug; - }; - 56B037381E8E31D0003B6DA4 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.1; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = iphoneos; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; - 56B0373A1E8E31D0003B6DA4 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = AMD8W895CT; - INFOPLIST_FILE = GRDBiOS/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBiOS; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; - }; - name = Debug; - }; - 56B0373B1E8E31D0003B6DA4 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = AMD8W895CT; - INFOPLIST_FILE = GRDBiOS/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBiOS; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 56B037221E8E31D0003B6DA4 /* Build configuration list for PBXProject "GRDBiOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 56B037371E8E31D0003B6DA4 /* Debug */, - 56B037381E8E31D0003B6DA4 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 56B037391E8E31D0003B6DA4 /* Build configuration list for PBXNativeTarget "GRDBiOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 56B0373A1E8E31D0003B6DA4 /* Debug */, - 56B0373B1E8E31D0003B6DA4 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 56B0371F1E8E31D0003B6DA4 /* Project object */; -} diff --git a/Tests/GRDBCipher/GRDBiOS/GRDBiOS.xcodeproj/xcshareddata/xcschemes/GRDBiOS.xcscheme b/Tests/GRDBCipher/GRDBiOS/GRDBiOS.xcodeproj/xcshareddata/xcschemes/GRDBiOS.xcscheme deleted file mode 100644 index 7a8a721af..000000000 --- a/Tests/GRDBCipher/GRDBiOS/GRDBiOS.xcodeproj/xcshareddata/xcschemes/GRDBiOS.xcscheme +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Tests/GRDBCipher/GRDBiOS/GRDBiOS/AppDelegate.swift b/Tests/GRDBCipher/GRDBiOS/GRDBiOS/AppDelegate.swift deleted file mode 100644 index 48602b7f3..000000000 --- a/Tests/GRDBCipher/GRDBiOS/GRDBiOS/AppDelegate.swift +++ /dev/null @@ -1,13 +0,0 @@ -import UIKit - -@UIApplicationMain -class AppDelegate: UIResponder, UIApplicationDelegate { - - var window: UIWindow? - - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { - try! setupDatabase(application) - return true - } -} - diff --git a/Tests/GRDBCipher/GRDBiOS/GRDBiOS/Assets.xcassets/AppIcon.appiconset/Contents.json b/Tests/GRDBCipher/GRDBiOS/GRDBiOS/Assets.xcassets/AppIcon.appiconset/Contents.json deleted file mode 100644 index 118c98f74..000000000 --- a/Tests/GRDBCipher/GRDBiOS/GRDBiOS/Assets.xcassets/AppIcon.appiconset/Contents.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "images" : [ - { - "idiom" : "iphone", - "size" : "29x29", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "29x29", - "scale" : "3x" - }, - { - "idiom" : "iphone", - "size" : "40x40", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "40x40", - "scale" : "3x" - }, - { - "idiom" : "iphone", - "size" : "60x60", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "60x60", - "scale" : "3x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/Tests/GRDBCipher/GRDBiOS/GRDBiOS/Base.lproj/LaunchScreen.storyboard b/Tests/GRDBCipher/GRDBiOS/GRDBiOS/Base.lproj/LaunchScreen.storyboard deleted file mode 100644 index 850202094..000000000 --- a/Tests/GRDBCipher/GRDBiOS/GRDBiOS/Base.lproj/LaunchScreen.storyboard +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Tests/GRDBCipher/GRDBiOS/GRDBiOS/Base.lproj/Main.storyboard b/Tests/GRDBCipher/GRDBiOS/GRDBiOS/Base.lproj/Main.storyboard deleted file mode 100644 index 70db168fd..000000000 --- a/Tests/GRDBCipher/GRDBiOS/GRDBiOS/Base.lproj/Main.storyboard +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Tests/GRDBCipher/GRDBiOS/GRDBiOS/Database.swift b/Tests/GRDBCipher/GRDBiOS/GRDBiOS/Database.swift deleted file mode 100644 index d98d81521..000000000 --- a/Tests/GRDBCipher/GRDBiOS/GRDBiOS/Database.swift +++ /dev/null @@ -1,55 +0,0 @@ -import GRDBCipher -import UIKit - -// The shared database queue -var dbQueue: DatabaseQueue! - -func setupDatabase(_ application: UIApplication) throws { - - // Connect to the database - // See https://github.com/groue/GRDB.swift/#database-connections - - var configuration = Configuration() - configuration.passphrase = "secret" - let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first! as NSString - let databasePath = documentsPath.appendingPathComponent("db.sqlite") - dbQueue = try DatabaseQueue(path: databasePath, configuration: configuration) - - - // Be a nice iOS citizen, and don't consume too much memory - // See https://github.com/groue/GRDB.swift/#memory-management - - dbQueue.setupMemoryManagement(in: application) - - - // Use DatabaseMigrator to setup the database - // See https://github.com/groue/GRDB.swift/#migrations - - var migrator = DatabaseMigrator() - - migrator.registerMigration("createPersons") { db in - - // Create a table - // See https://github.com/groue/GRDB.swift#create-tables - - try db.create(table: "persons") { t in - // An integer primary key auto-generates unique IDs - t.column("id", .integer).primaryKey() - - // Sort person names in a localized case insensitive fashion by default - // See https://github.com/groue/GRDB.swift/#unicode - t.column("name", .text).notNull().collate(.localizedCaseInsensitiveCompare) - - t.column("score", .integer).notNull() - } - } - - migrator.registerMigration("addPersons") { db in - // Populate the persons table with random data - for _ in 0..<8 { - try Person(name: Person.randomName(), score: Person.randomScore()).insert(db) - } - } - - try migrator.migrate(dbQueue) -} diff --git a/Tests/GRDBCipher/GRDBiOS/GRDBiOS/Person.swift b/Tests/GRDBCipher/GRDBiOS/GRDBiOS/Person.swift deleted file mode 100644 index fb26a695e..000000000 --- a/Tests/GRDBCipher/GRDBiOS/GRDBiOS/Person.swift +++ /dev/null @@ -1,49 +0,0 @@ -import GRDBCipher - -class Person: Record { - var id: Int64? - var name: String - var score: Int - - init(name: String, score: Int) { - self.name = name - self.score = score - super.init() - } - - // MARK: Record overrides - - override class var databaseTableName: String { - return "persons" - } - - required init(row: Row) { - id = row["id"] - name = row["name"] - score = row["score"] - super.init(row: row) - } - - override func encode(to container: inout PersistenceContainer) { - container["id"] = id - container["name"] = name - container["score"] = score - } - - override func didInsert(with rowID: Int64, for column: String?) { - id = rowID - } - - // MARK: Random - - private static let names = ["Arthur", "Anita", "Barbara", "Bernard", "Craig", "Chiara", "David", "Dean", "Éric", "Elena", "Fatima", "Frederik", "Gilbert", "Georgette", "Henriette", "Hassan", "Ignacio", "Irene", "Julie", "Jack", "Karl", "Kristel", "Louis", "Liz", "Masashi", "Mary", "Noam", "Nicole", "Ophelie", "Oleg", "Pascal", "Patricia", "Quentin", "Quinn", "Raoul", "Rachel", "Stephan", "Susie", "Tristan", "Tatiana", "Ursule", "Urbain", "Victor", "Violette", "Wilfried", "Wilhelmina", "Yvon", "Yann", "Zazie", "Zoé"] - - class func randomName() -> String { - return names[Int(arc4random_uniform(UInt32(names.count)))] - } - - class func randomScore() -> Int { - return 10 * Int(arc4random_uniform(101)) - } - -} diff --git a/Tests/GRDBCipher/GRDBiOS/GRDBiOS/ViewController.swift b/Tests/GRDBCipher/GRDBiOS/GRDBiOS/ViewController.swift deleted file mode 100644 index 29fd3aa36..000000000 --- a/Tests/GRDBCipher/GRDBiOS/GRDBiOS/ViewController.swift +++ /dev/null @@ -1,22 +0,0 @@ -import UIKit -import GRDBCipher - -class ViewController: UIViewController { - @IBOutlet weak var SQLiteVersionLabel: UILabel! - @IBOutlet weak var personCountLabel: UILabel! - - override func viewDidLoad() { - super.viewDidLoad() - - let sqliteVersion = String(cString: sqlite3_libversion(), encoding: .utf8)! - SQLiteVersionLabel.text = "SQLite version: \(sqliteVersion)" - - let personCount = try! dbQueue.inDatabase { try Person.fetchCount($0) } - personCountLabel.text = "Number of persons: \(personCount)" - } - - override func didReceiveMemoryWarning() { - super.didReceiveMemoryWarning() - // Dispose of any resources that can be recreated. - } -} diff --git a/Tests/GRDBTests/AnyCursorTests.swift b/Tests/GRDBTests/AnyCursorTests.swift index 7a8a86675..9ed9fa3c0 100644 --- a/Tests/GRDBTests/AnyCursorTests.swift +++ b/Tests/GRDBTests/AnyCursorTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/AssociationAggregateTests.swift b/Tests/GRDBTests/AssociationAggregateTests.swift index 08c79ed02..3528ad734 100644 --- a/Tests/GRDBTests/AssociationAggregateTests.swift +++ b/Tests/GRDBTests/AssociationAggregateTests.swift @@ -1,21 +1,20 @@ import XCTest -#if GRDBCIPHER -import GRDBCipher -#elseif GRDBCUSTOMSQLITE -import GRDBCustomSQLite +#if GRDBCUSTOMSQLITE + import GRDBCustomSQLite #else -import GRDB + import GRDB #endif private struct Team: Codable, FetchableRecord, PersistableRecord { static let players = hasMany(Player.self) static let awards = hasMany(Award.self) - static let customPlayers = hasMany(Player.self, key: "custom") + static let customPlayers = hasMany(Player.self, key: "customPlayers") var id: Int64 var name: String } private struct Player: Codable, FetchableRecord, PersistableRecord { + static let awards = hasMany(Award.self, through: belongsTo(Team.self), using: Team.awards) var id: Int64 var teamId: Int64? var name: String @@ -39,11 +38,11 @@ private struct TeamInfo: Decodable, FetchableRecord { private struct CustomTeamInfo: Decodable, FetchableRecord { var team: Team - var averageCustomScore: Double? - var customCount: Int? - var maxCustomScore: Int? - var minCustomScore: Int? - var customScoreSum: Int? + var averageCustomPlayerScore: Double? + var customPlayerCount: Int? + var maxCustomPlayerScore: Int? + var minCustomPlayerScore: Int? + var customPlayerScoreSum: Int? } class AssociationAggregateTests: GRDBTestCase { @@ -79,6 +78,8 @@ class AssociationAggregateTests: GRDBTestCase { try Award(id: 4, teamId: 2, name: "European cup 2036").insert(db) try Team(id: 3, name: "Greens").insert(db) try Award(id: 5, teamId: 3, name: "World cup 2037").insert(db) + try Team(id: 4, name: "Oranges").insert(db) + try Player(id: 6, teamId: 4, name: "Fiona", score: 0).insert(db) } } @@ -116,7 +117,7 @@ class AssociationAggregateTests: GRDBTestCase { } } - func testAnnotatedWithDefaultAverage() throws { + func testAnnotatedWithHasManyDefaultAverage() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in let request = Team @@ -133,7 +134,7 @@ class AssociationAggregateTests: GRDBTestCase { """) let teamInfos = try request.fetchAll(db) - XCTAssertEqual(teamInfos.count, 3) + XCTAssertEqual(teamInfos.count, 4) XCTAssertEqual(teamInfos[0].team.id, 1) XCTAssertEqual(teamInfos[0].team.name, "Reds") @@ -146,10 +147,14 @@ class AssociationAggregateTests: GRDBTestCase { XCTAssertEqual(teamInfos[2].team.id, 3) XCTAssertEqual(teamInfos[2].team.name, "Greens") XCTAssertNil(teamInfos[2].averagePlayerScore) + + XCTAssertEqual(teamInfos[3].team.id, 4) + XCTAssertEqual(teamInfos[3].team.name, "Oranges") + XCTAssertEqual(teamInfos[3].averagePlayerScore, 0) } } - func testAnnotatedWithDefaultCount() throws { + func testAnnotatedWithHasManyDefaultCount() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in let request = Team @@ -166,7 +171,7 @@ class AssociationAggregateTests: GRDBTestCase { """) let teamInfos = try request.fetchAll(db) - XCTAssertEqual(teamInfos.count, 3) + XCTAssertEqual(teamInfos.count, 4) XCTAssertEqual(teamInfos[0].team.id, 1) XCTAssertEqual(teamInfos[0].team.name, "Reds") @@ -179,10 +184,58 @@ class AssociationAggregateTests: GRDBTestCase { XCTAssertEqual(teamInfos[2].team.id, 3) XCTAssertEqual(teamInfos[2].team.name, "Greens") XCTAssertEqual(teamInfos[2].playerCount, 0) + + XCTAssertEqual(teamInfos[3].team.id, 4) + XCTAssertEqual(teamInfos[3].team.name, "Oranges") + XCTAssertEqual(teamInfos[3].playerCount, 1) } } - func testAnnotatedWithDefaultMax() throws { + func testAnnotatedWithHasManyThroughDefaultCount() throws { + struct PlayerInfo: Decodable, FetchableRecord { + var player: Player + var awardCount: Int + } + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + let request = Player + .annotated(with: Player.awards.count) + .orderByPrimaryKey() + .asRequest(of: PlayerInfo.self) + + try assertEqualSQL(db, request, """ + SELECT "player".*, COUNT(DISTINCT "award"."rowid") AS "awardCount" \ + FROM "player" \ + LEFT JOIN "team" ON ("team"."id" = "player"."teamId") \ + LEFT JOIN "award" ON ("award"."teamId" = "team"."id") \ + GROUP BY "player"."id" \ + ORDER BY "player"."id" + """) + + let playerInfos = try request.fetchAll(db) + XCTAssertEqual(playerInfos.count, 6) + + XCTAssertEqual(playerInfos[0].player.id, 1) + XCTAssertEqual(playerInfos[0].awardCount, 3) + + XCTAssertEqual(playerInfos[1].player.id, 2) + XCTAssertEqual(playerInfos[1].awardCount, 3) + + XCTAssertEqual(playerInfos[2].player.id, 3) + XCTAssertEqual(playerInfos[2].awardCount, 1) + + XCTAssertEqual(playerInfos[3].player.id, 4) + XCTAssertEqual(playerInfos[3].awardCount, 1) + + XCTAssertEqual(playerInfos[4].player.id, 5) + XCTAssertEqual(playerInfos[4].awardCount, 1) + + XCTAssertEqual(playerInfos[5].player.id, 6) + XCTAssertEqual(playerInfos[5].awardCount, 0) + } + } + + func testAnnotatedWithHasManyDefaultMax() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in let request = Team @@ -199,7 +252,7 @@ class AssociationAggregateTests: GRDBTestCase { """) let teamInfos = try request.fetchAll(db) - XCTAssertEqual(teamInfos.count, 3) + XCTAssertEqual(teamInfos.count, 4) XCTAssertEqual(teamInfos[0].team.id, 1) XCTAssertEqual(teamInfos[0].team.name, "Reds") @@ -212,10 +265,14 @@ class AssociationAggregateTests: GRDBTestCase { XCTAssertEqual(teamInfos[2].team.id, 3) XCTAssertEqual(teamInfos[2].team.name, "Greens") XCTAssertNil(teamInfos[2].maxPlayerScore) + + XCTAssertEqual(teamInfos[3].team.id, 4) + XCTAssertEqual(teamInfos[3].team.name, "Oranges") + XCTAssertEqual(teamInfos[3].maxPlayerScore, 0) } } - func testAnnotatedWithDefaultMin() throws { + func testAnnotatedWithHasManyDefaultMin() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in let request = Team @@ -232,7 +289,7 @@ class AssociationAggregateTests: GRDBTestCase { """) let teamInfos = try request.fetchAll(db) - XCTAssertEqual(teamInfos.count, 3) + XCTAssertEqual(teamInfos.count, 4) XCTAssertEqual(teamInfos[0].team.id, 1) XCTAssertEqual(teamInfos[0].team.name, "Reds") @@ -245,10 +302,14 @@ class AssociationAggregateTests: GRDBTestCase { XCTAssertEqual(teamInfos[2].team.id, 3) XCTAssertEqual(teamInfos[2].team.name, "Greens") XCTAssertNil(teamInfos[2].minPlayerScore) + + XCTAssertEqual(teamInfos[3].team.id, 4) + XCTAssertEqual(teamInfos[3].team.name, "Oranges") + XCTAssertEqual(teamInfos[3].minPlayerScore, 0) } } - func testAnnotatedWithDefaultSum() throws { + func testAnnotatedWithHasManyDefaultSum() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in let request = Team @@ -265,7 +326,7 @@ class AssociationAggregateTests: GRDBTestCase { """) let teamInfos = try request.fetchAll(db) - XCTAssertEqual(teamInfos.count, 3) + XCTAssertEqual(teamInfos.count, 4) XCTAssertEqual(teamInfos[0].team.id, 1) XCTAssertEqual(teamInfos[0].team.name, "Reds") @@ -278,10 +339,14 @@ class AssociationAggregateTests: GRDBTestCase { XCTAssertEqual(teamInfos[2].team.id, 3) XCTAssertEqual(teamInfos[2].team.name, "Greens") XCTAssertNil(teamInfos[2].playerScoreSum) + + XCTAssertEqual(teamInfos[3].team.id, 4) + XCTAssertEqual(teamInfos[3].team.name, "Oranges") + XCTAssertEqual(teamInfos[3].playerScoreSum, 0) } } - func testAnnotatedWithMultipleDefaultAggregates() throws { + func testAnnotatedWithHasManyMultipleDefaultAggregates() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in let request = Team @@ -306,7 +371,7 @@ class AssociationAggregateTests: GRDBTestCase { """) let teamInfos = try request.fetchAll(db) - XCTAssertEqual(teamInfos.count, 3) + XCTAssertEqual(teamInfos.count, 4) XCTAssertEqual(teamInfos[0].team.id, 1) XCTAssertEqual(teamInfos[0].team.name, "Reds") @@ -331,10 +396,18 @@ class AssociationAggregateTests: GRDBTestCase { XCTAssertNil(teamInfos[2].maxPlayerScore) XCTAssertNil(teamInfos[2].minPlayerScore) XCTAssertNil(teamInfos[2].playerScoreSum) + + XCTAssertEqual(teamInfos[3].team.id, 4) + XCTAssertEqual(teamInfos[3].team.name, "Oranges") + XCTAssertEqual(teamInfos[3].averagePlayerScore, 0) + XCTAssertEqual(teamInfos[3].playerCount, 1) + XCTAssertEqual(teamInfos[3].maxPlayerScore, 0) + XCTAssertEqual(teamInfos[3].minPlayerScore, 0) + XCTAssertEqual(teamInfos[3].playerScoreSum, 0) } } - func testAnnotatedWithCustomAverage() throws { + func testAnnotatedWithHasManyCustomAverage() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in let request = Team @@ -343,7 +416,7 @@ class AssociationAggregateTests: GRDBTestCase { .asRequest(of: CustomTeamInfo.self) try assertEqualSQL(db, request, """ - SELECT "team".*, AVG("player"."score") AS "averageCustomScore" \ + SELECT "team".*, AVG("player"."score") AS "averageCustomPlayerScore" \ FROM "team" \ LEFT JOIN "player" ON ("player"."teamId" = "team"."id") \ GROUP BY "team"."id" \ @@ -351,23 +424,27 @@ class AssociationAggregateTests: GRDBTestCase { """) let teamInfos = try request.fetchAll(db) - XCTAssertEqual(teamInfos.count, 3) + XCTAssertEqual(teamInfos.count, 4) XCTAssertEqual(teamInfos[0].team.id, 1) XCTAssertEqual(teamInfos[0].team.name, "Reds") - XCTAssertEqual(teamInfos[0].averageCustomScore, 550) + XCTAssertEqual(teamInfos[0].averageCustomPlayerScore, 550) XCTAssertEqual(teamInfos[1].team.id, 2) XCTAssertEqual(teamInfos[1].team.name, "Blues") - XCTAssertEqual(teamInfos[1].averageCustomScore, 500) + XCTAssertEqual(teamInfos[1].averageCustomPlayerScore, 500) XCTAssertEqual(teamInfos[2].team.id, 3) XCTAssertEqual(teamInfos[2].team.name, "Greens") - XCTAssertNil(teamInfos[2].averageCustomScore) + XCTAssertNil(teamInfos[2].averageCustomPlayerScore) + + XCTAssertEqual(teamInfos[3].team.id, 4) + XCTAssertEqual(teamInfos[3].team.name, "Oranges") + XCTAssertEqual(teamInfos[3].averageCustomPlayerScore, 0) } } - func testAnnotatedWithCustomCount() throws { + func testAnnotatedWithHasManyCustomCount() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in let request = Team @@ -376,7 +453,7 @@ class AssociationAggregateTests: GRDBTestCase { .asRequest(of: CustomTeamInfo.self) try assertEqualSQL(db, request, """ - SELECT "team".*, COUNT(DISTINCT "player"."rowid") AS "customCount" \ + SELECT "team".*, COUNT(DISTINCT "player"."rowid") AS "customPlayerCount" \ FROM "team" \ LEFT JOIN "player" ON ("player"."teamId" = "team"."id") \ GROUP BY "team"."id" \ @@ -384,23 +461,27 @@ class AssociationAggregateTests: GRDBTestCase { """) let teamInfos = try request.fetchAll(db) - XCTAssertEqual(teamInfos.count, 3) + XCTAssertEqual(teamInfos.count, 4) XCTAssertEqual(teamInfos[0].team.id, 1) XCTAssertEqual(teamInfos[0].team.name, "Reds") - XCTAssertEqual(teamInfos[0].customCount, 2) + XCTAssertEqual(teamInfos[0].customPlayerCount, 2) XCTAssertEqual(teamInfos[1].team.id, 2) XCTAssertEqual(teamInfos[1].team.name, "Blues") - XCTAssertEqual(teamInfos[1].customCount, 3) + XCTAssertEqual(teamInfos[1].customPlayerCount, 3) XCTAssertEqual(teamInfos[2].team.id, 3) XCTAssertEqual(teamInfos[2].team.name, "Greens") - XCTAssertEqual(teamInfos[2].customCount, 0) + XCTAssertEqual(teamInfos[2].customPlayerCount, 0) + + XCTAssertEqual(teamInfos[3].team.id, 4) + XCTAssertEqual(teamInfos[3].team.name, "Oranges") + XCTAssertEqual(teamInfos[3].customPlayerCount, 1) } } - func testAnnotatedWithCustomMax() throws { + func testAnnotatedWithHasManyCustomMax() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in let request = Team @@ -409,7 +490,7 @@ class AssociationAggregateTests: GRDBTestCase { .asRequest(of: CustomTeamInfo.self) try assertEqualSQL(db, request, """ - SELECT "team".*, MAX("player"."score") AS "maxCustomScore" \ + SELECT "team".*, MAX("player"."score") AS "maxCustomPlayerScore" \ FROM "team" \ LEFT JOIN "player" ON ("player"."teamId" = "team"."id") \ GROUP BY "team"."id" \ @@ -417,23 +498,27 @@ class AssociationAggregateTests: GRDBTestCase { """) let teamInfos = try request.fetchAll(db) - XCTAssertEqual(teamInfos.count, 3) + XCTAssertEqual(teamInfos.count, 4) XCTAssertEqual(teamInfos[0].team.id, 1) XCTAssertEqual(teamInfos[0].team.name, "Reds") - XCTAssertEqual(teamInfos[0].maxCustomScore, 1000) + XCTAssertEqual(teamInfos[0].maxCustomPlayerScore, 1000) XCTAssertEqual(teamInfos[1].team.id, 2) XCTAssertEqual(teamInfos[1].team.name, "Blues") - XCTAssertEqual(teamInfos[1].maxCustomScore, 800) + XCTAssertEqual(teamInfos[1].maxCustomPlayerScore, 800) XCTAssertEqual(teamInfos[2].team.id, 3) XCTAssertEqual(teamInfos[2].team.name, "Greens") - XCTAssertNil(teamInfos[2].maxCustomScore) + XCTAssertNil(teamInfos[2].maxCustomPlayerScore) + + XCTAssertEqual(teamInfos[3].team.id, 4) + XCTAssertEqual(teamInfos[3].team.name, "Oranges") + XCTAssertEqual(teamInfos[3].maxCustomPlayerScore, 0) } } - func testAnnotatedWithCustomMin() throws { + func testAnnotatedWithHasManyCustomMin() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in let request = Team @@ -442,7 +527,7 @@ class AssociationAggregateTests: GRDBTestCase { .asRequest(of: CustomTeamInfo.self) try assertEqualSQL(db, request, """ - SELECT "team".*, MIN("player"."score") AS "minCustomScore" \ + SELECT "team".*, MIN("player"."score") AS "minCustomPlayerScore" \ FROM "team" \ LEFT JOIN "player" ON ("player"."teamId" = "team"."id") \ GROUP BY "team"."id" \ @@ -450,23 +535,27 @@ class AssociationAggregateTests: GRDBTestCase { """) let teamInfos = try request.fetchAll(db) - XCTAssertEqual(teamInfos.count, 3) + XCTAssertEqual(teamInfos.count, 4) XCTAssertEqual(teamInfos[0].team.id, 1) XCTAssertEqual(teamInfos[0].team.name, "Reds") - XCTAssertEqual(teamInfos[0].minCustomScore, 100) + XCTAssertEqual(teamInfos[0].minCustomPlayerScore, 100) XCTAssertEqual(teamInfos[1].team.id, 2) XCTAssertEqual(teamInfos[1].team.name, "Blues") - XCTAssertEqual(teamInfos[1].minCustomScore, 200) + XCTAssertEqual(teamInfos[1].minCustomPlayerScore, 200) XCTAssertEqual(teamInfos[2].team.id, 3) XCTAssertEqual(teamInfos[2].team.name, "Greens") - XCTAssertNil(teamInfos[2].minCustomScore) + XCTAssertNil(teamInfos[2].minCustomPlayerScore) + + XCTAssertEqual(teamInfos[3].team.id, 4) + XCTAssertEqual(teamInfos[3].team.name, "Oranges") + XCTAssertEqual(teamInfos[3].minCustomPlayerScore, 0) } } - func testAnnotatedWithCustomSum() throws { + func testAnnotatedWithHasManyCustomSum() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in let request = Team @@ -475,7 +564,7 @@ class AssociationAggregateTests: GRDBTestCase { .asRequest(of: CustomTeamInfo.self) try assertEqualSQL(db, request, """ - SELECT "team".*, SUM("player"."score") AS "customScoreSum" \ + SELECT "team".*, SUM("player"."score") AS "customPlayerScoreSum" \ FROM "team" \ LEFT JOIN "player" ON ("player"."teamId" = "team"."id") \ GROUP BY "team"."id" \ @@ -483,23 +572,27 @@ class AssociationAggregateTests: GRDBTestCase { """) let teamInfos = try request.fetchAll(db) - XCTAssertEqual(teamInfos.count, 3) + XCTAssertEqual(teamInfos.count, 4) XCTAssertEqual(teamInfos[0].team.id, 1) XCTAssertEqual(teamInfos[0].team.name, "Reds") - XCTAssertEqual(teamInfos[0].customScoreSum, 1100) + XCTAssertEqual(teamInfos[0].customPlayerScoreSum, 1100) XCTAssertEqual(teamInfos[1].team.id, 2) XCTAssertEqual(teamInfos[1].team.name, "Blues") - XCTAssertEqual(teamInfos[1].customScoreSum, 1500) + XCTAssertEqual(teamInfos[1].customPlayerScoreSum, 1500) XCTAssertEqual(teamInfos[2].team.id, 3) XCTAssertEqual(teamInfos[2].team.name, "Greens") - XCTAssertNil(teamInfos[2].customScoreSum) + XCTAssertNil(teamInfos[2].customPlayerScoreSum) + + XCTAssertEqual(teamInfos[3].team.id, 4) + XCTAssertEqual(teamInfos[3].team.name, "Oranges") + XCTAssertEqual(teamInfos[3].customPlayerScoreSum, 0) } } - func testAnnotatedWithMultipleCustomAggregates() throws { + func testAnnotatedWithHasManyMultipleCustomAggregates() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in let request = Team @@ -512,11 +605,11 @@ class AssociationAggregateTests: GRDBTestCase { try assertEqualSQL(db, request, """ SELECT "team".*, \ - AVG("player"."score") AS "averageCustomScore", \ - COUNT(DISTINCT "player"."rowid") AS "customCount", \ - MIN("player"."score") AS "minCustomScore", \ - MAX("player"."score") AS "maxCustomScore", \ - SUM("player"."score") AS "customScoreSum" \ + AVG("player"."score") AS "averageCustomPlayerScore", \ + COUNT(DISTINCT "player"."rowid") AS "customPlayerCount", \ + MIN("player"."score") AS "minCustomPlayerScore", \ + MAX("player"."score") AS "maxCustomPlayerScore", \ + SUM("player"."score") AS "customPlayerScoreSum" \ FROM "team" \ LEFT JOIN "player" ON ("player"."teamId" = "team"."id") \ GROUP BY "team"."id" \ @@ -524,35 +617,43 @@ class AssociationAggregateTests: GRDBTestCase { """) let teamInfos = try request.fetchAll(db) - XCTAssertEqual(teamInfos.count, 3) + XCTAssertEqual(teamInfos.count, 4) XCTAssertEqual(teamInfos[0].team.id, 1) XCTAssertEqual(teamInfos[0].team.name, "Reds") - XCTAssertEqual(teamInfos[0].averageCustomScore, 550) - XCTAssertEqual(teamInfos[0].customCount, 2) - XCTAssertEqual(teamInfos[0].maxCustomScore, 1000) - XCTAssertEqual(teamInfos[0].minCustomScore, 100) - XCTAssertEqual(teamInfos[0].customScoreSum, 1100) + XCTAssertEqual(teamInfos[0].averageCustomPlayerScore, 550) + XCTAssertEqual(teamInfos[0].customPlayerCount, 2) + XCTAssertEqual(teamInfos[0].maxCustomPlayerScore, 1000) + XCTAssertEqual(teamInfos[0].minCustomPlayerScore, 100) + XCTAssertEqual(teamInfos[0].customPlayerScoreSum, 1100) XCTAssertEqual(teamInfos[1].team.id, 2) XCTAssertEqual(teamInfos[1].team.name, "Blues") - XCTAssertEqual(teamInfos[1].averageCustomScore, 500) - XCTAssertEqual(teamInfos[1].customCount, 3) - XCTAssertEqual(teamInfos[1].maxCustomScore, 800) - XCTAssertEqual(teamInfos[1].minCustomScore, 200) - XCTAssertEqual(teamInfos[1].customScoreSum, 1500) + XCTAssertEqual(teamInfos[1].averageCustomPlayerScore, 500) + XCTAssertEqual(teamInfos[1].customPlayerCount, 3) + XCTAssertEqual(teamInfos[1].maxCustomPlayerScore, 800) + XCTAssertEqual(teamInfos[1].minCustomPlayerScore, 200) + XCTAssertEqual(teamInfos[1].customPlayerScoreSum, 1500) XCTAssertEqual(teamInfos[2].team.id, 3) XCTAssertEqual(teamInfos[2].team.name, "Greens") - XCTAssertNil(teamInfos[2].averageCustomScore) - XCTAssertEqual(teamInfos[2].customCount, 0) - XCTAssertNil(teamInfos[2].maxCustomScore) - XCTAssertNil(teamInfos[2].minCustomScore) - XCTAssertNil(teamInfos[2].customScoreSum) + XCTAssertNil(teamInfos[2].averageCustomPlayerScore) + XCTAssertEqual(teamInfos[2].customPlayerCount, 0) + XCTAssertNil(teamInfos[2].maxCustomPlayerScore) + XCTAssertNil(teamInfos[2].minCustomPlayerScore) + XCTAssertNil(teamInfos[2].customPlayerScoreSum) + + XCTAssertEqual(teamInfos[3].team.id, 4) + XCTAssertEqual(teamInfos[3].team.name, "Oranges") + XCTAssertEqual(teamInfos[3].averageCustomPlayerScore, 0) + XCTAssertEqual(teamInfos[3].customPlayerCount, 1) + XCTAssertEqual(teamInfos[3].maxCustomPlayerScore, 0) + XCTAssertEqual(teamInfos[3].minCustomPlayerScore, 0) + XCTAssertEqual(teamInfos[3].customPlayerScoreSum, 0) } } - func testAnnotatedWithAggregateAlias() throws { + func testAnnotatedWithHasManyAggregateAlias() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in let request = Team @@ -576,7 +677,7 @@ class AssociationAggregateTests: GRDBTestCase { } } - func testAnnotatedWithAggregateExpression() throws { + func testAnnotatedWithHasManyAggregateExpression() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in let request = Team @@ -597,7 +698,7 @@ class AssociationAggregateTests: GRDBTestCase { } } - func testAnnotatedWithMultipleCount() throws { + func testAnnotatedWithHasManyMultipleCount() throws { struct TeamInfo: Decodable, FetchableRecord { var team: Team var lowPlayerCount: Int @@ -606,8 +707,8 @@ class AssociationAggregateTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in let request = Team - .annotated(with: Team.players.filter(Column("score") < 500).forKey("lowPlayer").count) - .annotated(with: Team.players.filter(Column("score") >= 500).forKey("highPlayer").count) + .annotated(with: Team.players.filter(Column("score") < 500).forKey("lowPlayers").count) + .annotated(with: Team.players.filter(Column("score") >= 500).forKey("highPlayers").count) .orderByPrimaryKey() .asRequest(of: TeamInfo.self) @@ -623,7 +724,7 @@ class AssociationAggregateTests: GRDBTestCase { """) let teamInfos = try request.fetchAll(db) - XCTAssertEqual(teamInfos.count, 3) + XCTAssertEqual(teamInfos.count, 4) XCTAssertEqual(teamInfos[0].team.id, 1) XCTAssertEqual(teamInfos[0].team.name, "Reds") @@ -639,15 +740,41 @@ class AssociationAggregateTests: GRDBTestCase { XCTAssertEqual(teamInfos[2].team.name, "Greens") XCTAssertEqual(teamInfos[2].lowPlayerCount, 0) XCTAssertEqual(teamInfos[2].highPlayerCount, 0) + + XCTAssertEqual(teamInfos[3].team.id, 4) + XCTAssertEqual(teamInfos[3].team.name, "Oranges") + XCTAssertEqual(teamInfos[3].lowPlayerCount, 1) + XCTAssertEqual(teamInfos[3].highPlayerCount, 0) } } - func testIsEmpty() throws { + func testHasManyIsEmpty() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in + do { + let request = Team.annotated(with: Team.players.isEmpty) + try assertEqualSQL(db, request, """ + SELECT "team".*, (COUNT(DISTINCT "player"."rowid") = 0) AS "hasNoPlayer" \ + FROM "team" \ + LEFT JOIN "player" ON ("player"."teamId" = "team"."id") \ + GROUP BY "team"."id" + """) + try XCTAssertEqual(request.fetchAll(db).count, 4) + try XCTAssertEqual(request.fetchCount(db), 4) + } + do { + let request = Team.annotated(with: !Team.players.isEmpty) + try assertEqualSQL(db, request, """ + SELECT "team".*, (COUNT(DISTINCT "player"."rowid") > 0) \ + FROM "team" \ + LEFT JOIN "player" ON ("player"."teamId" = "team"."id") \ + GROUP BY "team"."id" + """) + try XCTAssertEqual(request.fetchAll(db).count, 4) + try XCTAssertEqual(request.fetchCount(db), 4) + } do { let request = Team.having(Team.players.isEmpty) - try assertEqualSQL(db, request, """ SELECT "team".* \ FROM "team" \ @@ -655,10 +782,11 @@ class AssociationAggregateTests: GRDBTestCase { GROUP BY "team"."id" \ HAVING (COUNT(DISTINCT "player"."rowid") = 0) """) + try XCTAssertEqual(request.fetchAll(db).count, 1) + try XCTAssertEqual(request.fetchCount(db), 1) } do { let request = Team.having(!Team.players.isEmpty) - try assertEqualSQL(db, request, """ SELECT "team".* \ FROM "team" \ @@ -666,10 +794,11 @@ class AssociationAggregateTests: GRDBTestCase { GROUP BY "team"."id" \ HAVING (COUNT(DISTINCT "player"."rowid") > 0) """) + try XCTAssertEqual(request.fetchAll(db).count, 3) + try XCTAssertEqual(request.fetchCount(db), 3) } do { let request = Team.having(Team.players.isEmpty == false) - try assertEqualSQL(db, request, """ SELECT "team".* \ FROM "team" \ @@ -677,10 +806,11 @@ class AssociationAggregateTests: GRDBTestCase { GROUP BY "team"."id" \ HAVING (COUNT(DISTINCT "player"."rowid") > 0) """) + try XCTAssertEqual(request.fetchAll(db).count, 3) + try XCTAssertEqual(request.fetchCount(db), 3) } do { let request = Team.having(Team.players.isEmpty == true) - try assertEqualSQL(db, request, """ SELECT "team".* \ FROM "team" \ @@ -688,10 +818,70 @@ class AssociationAggregateTests: GRDBTestCase { GROUP BY "team"."id" \ HAVING (COUNT(DISTINCT "player"."rowid") = 0) """) + try XCTAssertEqual(request.fetchAll(db).count, 1) + try XCTAssertEqual(request.fetchCount(db), 1) } } } + func testHasManyThroughIsEmpty() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + do { + let request = Player.having(Player.awards.isEmpty) + try assertEqualSQL(db, request, """ + SELECT "player".* \ + FROM "player" \ + LEFT JOIN "team" ON ("team"."id" = "player"."teamId") \ + LEFT JOIN "award" ON ("award"."teamId" = "team"."id") \ + GROUP BY "player"."id" \ + HAVING (COUNT(DISTINCT "award"."rowid") = 0) + """) + try XCTAssertEqual(request.fetchAll(db).count, 1) + try XCTAssertEqual(request.fetchCount(db), 1) + } + do { + let request = Player.having(!Player.awards.isEmpty) + try assertEqualSQL(db, request, """ + SELECT "player".* \ + FROM "player" \ + LEFT JOIN "team" ON ("team"."id" = "player"."teamId") \ + LEFT JOIN "award" ON ("award"."teamId" = "team"."id") \ + GROUP BY "player"."id" \ + HAVING (COUNT(DISTINCT "award"."rowid") > 0) + """) + try XCTAssertEqual(request.fetchAll(db).count, 5) + try XCTAssertEqual(request.fetchCount(db), 5) + } + do { + let request = Player.having(Player.awards.isEmpty == false) + try assertEqualSQL(db, request, """ + SELECT "player".* \ + FROM "player" \ + LEFT JOIN "team" ON ("team"."id" = "player"."teamId") \ + LEFT JOIN "award" ON ("award"."teamId" = "team"."id") \ + GROUP BY "player"."id" \ + HAVING (COUNT(DISTINCT "award"."rowid") > 0) + """) + try XCTAssertEqual(request.fetchAll(db).count, 5) + try XCTAssertEqual(request.fetchCount(db), 5) + } + do { + let request = Player.having(Player.awards.isEmpty == true) + try assertEqualSQL(db, request, """ + SELECT "player".* \ + FROM "player" \ + LEFT JOIN "team" ON ("team"."id" = "player"."teamId") \ + LEFT JOIN "award" ON ("award"."teamId" = "team"."id") \ + GROUP BY "player"."id" \ + HAVING (COUNT(DISTINCT "award"."rowid") = 0) + """) + try XCTAssertEqual(request.fetchAll(db).count, 1) + try XCTAssertEqual(request.fetchCount(db), 1) + } + } + } + func testEqualOperator() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in @@ -1137,4 +1327,41 @@ class AssociationAggregateTests: GRDBTestCase { } } } + + func testIfNullOperator() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + let request = Team + .annotated(with: Team.players.min(Column("score")) ?? 0) + .orderByPrimaryKey() + .asRequest(of: TeamInfo.self) + + try assertEqualSQL(db, request, """ + SELECT "team".*, IFNULL(MIN("player"."score"), 0) AS "minPlayerScore" \ + FROM "team" \ + LEFT JOIN "player" ON ("player"."teamId" = "team"."id") \ + GROUP BY "team"."id" \ + ORDER BY "team"."id" + """) + + let teamInfos = try request.fetchAll(db) + XCTAssertEqual(teamInfos.count, 4) + + XCTAssertEqual(teamInfos[0].team.id, 1) + XCTAssertEqual(teamInfos[0].team.name, "Reds") + XCTAssertEqual(teamInfos[0].minPlayerScore, 100) + + XCTAssertEqual(teamInfos[1].team.id, 2) + XCTAssertEqual(teamInfos[1].team.name, "Blues") + XCTAssertEqual(teamInfos[1].minPlayerScore, 200) + + XCTAssertEqual(teamInfos[2].team.id, 3) + XCTAssertEqual(teamInfos[2].team.name, "Greens") + XCTAssertEqual(teamInfos[2].minPlayerScore, 0) + + XCTAssertEqual(teamInfos[3].team.id, 4) + XCTAssertEqual(teamInfos[3].team.name, "Oranges") + XCTAssertEqual(teamInfos[3].minPlayerScore, 0) + } + } } diff --git a/Tests/GRDBTests/AssociationBelongsToDecodableRecordTests.swift b/Tests/GRDBTests/AssociationBelongsToDecodableRecordTests.swift index 9279a24ec..6b4438fe1 100644 --- a/Tests/GRDBTests/AssociationBelongsToDecodableRecordTests.swift +++ b/Tests/GRDBTests/AssociationBelongsToDecodableRecordTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/AssociationBelongsToFetchableRecordTests.swift b/Tests/GRDBTests/AssociationBelongsToFetchableRecordTests.swift index db5411021..ec626f595 100644 --- a/Tests/GRDBTests/AssociationBelongsToFetchableRecordTests.swift +++ b/Tests/GRDBTests/AssociationBelongsToFetchableRecordTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/AssociationBelongsToRowScopeTests.swift b/Tests/GRDBTests/AssociationBelongsToRowScopeTests.swift index a0ffcf846..7b0ae1bb3 100644 --- a/Tests/GRDBTests/AssociationBelongsToRowScopeTests.swift +++ b/Tests/GRDBTests/AssociationBelongsToRowScopeTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -47,7 +45,7 @@ class AssociationBelongsToRowScopeTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let request = Player.joining(required: Player.defaultTeam) - let (_, adapter) = try request.prepare(db) + let (_, adapter) = try request.prepare(db, forSingleResult: false) XCTAssertNil(adapter) } } @@ -55,30 +53,30 @@ class AssociationBelongsToRowScopeTests: GRDBTestCase { func testDefaultScopeIncludingRequired() throws { let dbQueue = try makeDatabaseQueue() let request = Player.including(required: Player.defaultTeam) - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"]) - XCTAssertEqual(Set(rows[0].scopes.names), ["teams"]) - XCTAssertEqual(rows[0].scopes["teams"]!, ["id":1, "name":"Reds"]) + XCTAssertEqual(Set(rows[0].scopes.names), ["team"]) + XCTAssertEqual(rows[0].scopes["team"]!, ["id":1, "name":"Reds"]) } func testDefaultScopeIncludingOptional() throws { let dbQueue = try makeDatabaseQueue() let request = Player.including(optional: Player.defaultTeam) - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"]) - XCTAssertEqual(Set(rows[0].scopes.names), ["teams"]) - XCTAssertEqual(rows[0].scopes["teams"]!, ["id":1, "name":"Reds"]) + XCTAssertEqual(Set(rows[0].scopes.names), ["team"]) + XCTAssertEqual(rows[0].scopes["team"]!, ["id":1, "name":"Reds"]) XCTAssertEqual(rows[1].unscoped, ["id":2, "teamId":nil, "name":"Barbara"]) - XCTAssertEqual(Set(rows[1].scopes.names), ["teams"]) - XCTAssertEqual(rows[1].scopes["teams"]!, ["id":nil, "name":nil]) + XCTAssertEqual(Set(rows[1].scopes.names), ["team"]) + XCTAssertEqual(rows[1].scopes["team"]!, ["id":nil, "name":nil]) } func testDefaultScopeJoiningRequired() throws { let dbQueue = try makeDatabaseQueue() let request = Player.joining(required: Player.defaultTeam) - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"]) XCTAssertTrue(rows[0].scopes.names.isEmpty) @@ -87,18 +85,18 @@ class AssociationBelongsToRowScopeTests: GRDBTestCase { func testDefaultScopeJoiningOptional() throws { let dbQueue = try makeDatabaseQueue() let request = Player.joining(optional: Player.defaultTeam) - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"]) XCTAssertTrue(rows[0].scopes.names.isEmpty) XCTAssertEqual(rows[1].unscoped, ["id":2, "teamId":nil, "name":"Barbara"]) XCTAssertTrue(rows[0].scopes.names.isEmpty) } - + func testCustomScopeIncludingRequired() throws { let dbQueue = try makeDatabaseQueue() let request = Player.including(required: Player.customTeam) - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"]) XCTAssertEqual(Set(rows[0].scopes.names), ["customTeam"]) @@ -108,7 +106,7 @@ class AssociationBelongsToRowScopeTests: GRDBTestCase { func testCustomScopeIncludingOptional() throws { let dbQueue = try makeDatabaseQueue() let request = Player.including(optional: Player.customTeam) - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"]) XCTAssertEqual(Set(rows[0].scopes.names), ["customTeam"]) @@ -118,10 +116,58 @@ class AssociationBelongsToRowScopeTests: GRDBTestCase { XCTAssertEqual(rows[1].scopes["customTeam"]!, ["id":nil, "name":nil]) } + func testCustomPluralScopeIncludingRequired() throws { + // Make sure explicit plural keys are preserved + let dbQueue = try makeDatabaseQueue() + do { + let request = Player.including(required: Player.belongsTo(Team.self, key: "teams")) + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } + XCTAssertEqual(rows.count, 1) + XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"]) + XCTAssertEqual(Set(rows[0].scopes.names), ["teams"]) + XCTAssertEqual(rows[0].scopes["teams"]!, ["id":1, "name":"Reds"]) + } + do { + let request = Player.including(required: Player.defaultTeam.forKey("teams")) + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } + XCTAssertEqual(rows.count, 1) + XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"]) + XCTAssertEqual(Set(rows[0].scopes.names), ["teams"]) + XCTAssertEqual(rows[0].scopes["teams"]!, ["id":1, "name":"Reds"]) + } + } + + func testCustomPluralScopeIncludingOptional() throws { + // Make sure explicit plural keys are preserved + let dbQueue = try makeDatabaseQueue() + do { + let request = Player.including(optional: Player.belongsTo(Team.self, key: "teams")) + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } + XCTAssertEqual(rows.count, 2) + XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"]) + XCTAssertEqual(Set(rows[0].scopes.names), ["teams"]) + XCTAssertEqual(rows[0].scopes["teams"]!, ["id":1, "name":"Reds"]) + XCTAssertEqual(rows[1].unscoped, ["id":2, "teamId":nil, "name":"Barbara"]) + XCTAssertEqual(Set(rows[1].scopes.names), ["teams"]) + XCTAssertEqual(rows[1].scopes["teams"]!, ["id":nil, "name":nil]) + } + do { + let request = Player.including(optional: Player.defaultTeam.forKey("teams")) + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } + XCTAssertEqual(rows.count, 2) + XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"]) + XCTAssertEqual(Set(rows[0].scopes.names), ["teams"]) + XCTAssertEqual(rows[0].scopes["teams"]!, ["id":1, "name":"Reds"]) + XCTAssertEqual(rows[1].unscoped, ["id":2, "teamId":nil, "name":"Barbara"]) + XCTAssertEqual(Set(rows[1].scopes.names), ["teams"]) + XCTAssertEqual(rows[1].scopes["teams"]!, ["id":nil, "name":nil]) + } + } + func testCustomScopeJoiningRequired() throws { let dbQueue = try makeDatabaseQueue() let request = Player.joining(required: Player.customTeam) - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"]) XCTAssertTrue(rows[0].scopes.names.isEmpty) @@ -130,7 +176,7 @@ class AssociationBelongsToRowScopeTests: GRDBTestCase { func testCustomScopeJoiningOptional() throws { let dbQueue = try makeDatabaseQueue() let request = Player.joining(optional: Player.customTeam) - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"]) XCTAssertTrue(rows[0].scopes.names.isEmpty) diff --git a/Tests/GRDBTests/AssociationBelongsToSQLDerivationTests.swift b/Tests/GRDBTests/AssociationBelongsToSQLDerivationTests.swift index 4bf1c848f..5dd7db262 100644 --- a/Tests/GRDBTests/AssociationBelongsToSQLDerivationTests.swift +++ b/Tests/GRDBTests/AssociationBelongsToSQLDerivationTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/AssociationBelongsToSQLTests.swift b/Tests/GRDBTests/AssociationBelongsToSQLTests.swift index 97af38506..47a4be990 100644 --- a/Tests/GRDBTests/AssociationBelongsToSQLTests.swift +++ b/Tests/GRDBTests/AssociationBelongsToSQLTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -11,7 +9,7 @@ import XCTest class AssociationBelongsToSQLTests: GRDBTestCase { func testSingleColumnNoForeignKeyNoPrimaryKey() throws { - struct Child : TableRecord, MutablePersistableRecord { + struct Child : TableRecord, EncodableRecord { static let databaseTableName = "children" func encode(to container: inout PersistenceContainer) { container["parentId"] = 1 @@ -95,7 +93,7 @@ class AssociationBelongsToSQLTests: GRDBTestCase { } func testSingleColumnNoForeignKey() throws { - struct Child : TableRecord, MutablePersistableRecord { + struct Child : TableRecord, EncodableRecord { static let databaseTableName = "children" func encode(to container: inout PersistenceContainer) { container["parentId"] = 1 @@ -179,7 +177,7 @@ class AssociationBelongsToSQLTests: GRDBTestCase { } func testSingleColumnSingleForeignKey() throws { - struct Child : TableRecord, MutablePersistableRecord { + struct Child : TableRecord, EncodableRecord { static let databaseTableName = "children" func encode(to container: inout PersistenceContainer) { container["parentId"] = 1 @@ -292,7 +290,7 @@ class AssociationBelongsToSQLTests: GRDBTestCase { } func testSingleColumnSeveralForeignKeys() throws { - struct Child : TableRecord, MutablePersistableRecord { + struct Child : TableRecord, EncodableRecord { static let databaseTableName = "children" func encode(to container: inout PersistenceContainer) { container["parent1Id"] = 1 @@ -436,7 +434,7 @@ class AssociationBelongsToSQLTests: GRDBTestCase { } func testCompoundColumnNoForeignKeyNoPrimaryKey() throws { - struct Child : TableRecord, MutablePersistableRecord { + struct Child : TableRecord, EncodableRecord { static let databaseTableName = "children" func encode(to container: inout PersistenceContainer) { container["parentA"] = 1 @@ -494,7 +492,7 @@ class AssociationBelongsToSQLTests: GRDBTestCase { } func testCompoundColumnNoForeignKey() throws { - struct Child : TableRecord, MutablePersistableRecord { + struct Child : TableRecord, EncodableRecord { static let databaseTableName = "children" func encode(to container: inout PersistenceContainer) { container["parentA"] = 1 @@ -582,7 +580,7 @@ class AssociationBelongsToSQLTests: GRDBTestCase { } func testCompoundColumnSingleForeignKey() throws { - struct Child : TableRecord, MutablePersistableRecord { + struct Child : TableRecord, EncodableRecord { static let databaseTableName = "children" func encode(to container: inout PersistenceContainer) { container["parentA"] = 1 @@ -700,7 +698,7 @@ class AssociationBelongsToSQLTests: GRDBTestCase { } func testCompoundColumnSeveralForeignKeys() throws { - struct Child : TableRecord, MutablePersistableRecord { + struct Child : TableRecord, EncodableRecord { static let databaseTableName = "children" func encode(to container: inout PersistenceContainer) { container["parent1A"] = 1 diff --git a/Tests/GRDBTests/AssociationChainRowScopesTests.swift b/Tests/GRDBTests/AssociationChainRowScopesTests.swift index a05e58cdb..6d19b9078 100644 --- a/Tests/GRDBTests/AssociationChainRowScopesTests.swift +++ b/Tests/GRDBTests/AssociationChainRowScopesTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -78,7 +76,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.including(required: A.defaultB.including(required: B.defaultC)).order(sql: "a.id, b.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -96,7 +94,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { } do { let request = A.including(required: A.defaultB.including(optional: B.defaultC)).order(sql: "a.id, b.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 3) @@ -121,11 +119,11 @@ class AssociationChainRowScopesTests: GRDBTestCase { do { // TODO: chainOptionalRequired // let request = A.including(optional: A.defaultB.including(required: B.defaultC)).order(sql: "a.id, b.id, c.id") -// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } +// let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } } do { let request = A.including(optional: A.defaultB.including(optional: B.defaultC)).order(sql: "a.id, b.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -155,7 +153,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.defaultC.including(required: C.defaultD)).order(sql: "b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 1) @@ -167,7 +165,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.defaultC.including(optional: C.defaultD)).order(sql: "b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -186,11 +184,11 @@ class AssociationChainRowScopesTests: GRDBTestCase { do { // TODO: chainOptionalRequired // let request = B.including(optional: B.defaultC.including(required: C.defaultD)).order(sql: "b.id, c.id, d.id") -// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } +// let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } } do { let request = B.including(optional: B.defaultC.including(optional: C.defaultD)).order(sql: "b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 3) @@ -218,7 +216,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.including(required: A.defaultB.joining(required: B.defaultC)).order(sql: "a.id, b.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -234,7 +232,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { } do { let request = A.including(required: A.defaultB.joining(optional: B.defaultC)).order(sql: "a.id, b.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 3) @@ -256,11 +254,11 @@ class AssociationChainRowScopesTests: GRDBTestCase { do { // TODO: chainOptionalRequired // let request = A.including(optional: A.defaultB.joining(required: B.defaultC)).order(sql: "a.id, b.id, c.id") -// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } +// let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } } do { let request = A.including(optional: A.defaultB.joining(optional: B.defaultC)).order(sql: "a.id, b.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -286,7 +284,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.defaultC.joining(required: C.defaultD)).order(sql: "b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 1) @@ -297,7 +295,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.defaultC.joining(optional: C.defaultD)).order(sql: "b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -314,11 +312,11 @@ class AssociationChainRowScopesTests: GRDBTestCase { do { // TODO: chainOptionalRequired // let request = B.including(optional: B.defaultC.joining(required: C.defaultD)).order(sql: "b.id, c.id, d.id") -// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } +// let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } } do { let request = B.including(optional: B.defaultC.joining(optional: C.defaultD)).order(sql: "b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 3) @@ -343,7 +341,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.joining(required: A.defaultB.including(required: B.defaultC)).order(sql: "a.id, b.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -361,7 +359,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { } do { let request = A.joining(required: A.defaultB.including(optional: B.defaultC)).order(sql: "a.id, b.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 3) @@ -386,11 +384,11 @@ class AssociationChainRowScopesTests: GRDBTestCase { do { // TODO: chainOptionalRequired // let request = A.joining(optional: A.defaultB.including(required: B.defaultC)).order(sql: "a.id, b.id, c.id") -// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } +// let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } } do { let request = A.joining(optional: A.defaultB.including(optional: B.defaultC)).order(sql: "a.id, b.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -420,7 +418,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.defaultC.including(required: C.defaultD)).order(sql: "b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 1) @@ -432,7 +430,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.defaultC.including(optional: C.defaultD)).order(sql: "b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -451,11 +449,11 @@ class AssociationChainRowScopesTests: GRDBTestCase { do { // TODO: chainOptionalRequired // let request = B.joining(optional: B.defaultC.including(required: C.defaultD)).order(sql: "b.id, c.id, d.id") -// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } +// let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } } do { let request = B.joining(optional: B.defaultC.including(optional: C.defaultD)).order(sql: "b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 3) @@ -483,7 +481,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.joining(required: A.defaultB.joining(required: B.defaultC)).order(sql: "a.id, b.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -495,7 +493,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { } do { let request = A.joining(required: A.defaultB.joining(optional: B.defaultC)).order(sql: "a.id, b.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 3) @@ -511,11 +509,11 @@ class AssociationChainRowScopesTests: GRDBTestCase { do { // TODO: chainOptionalRequired // let request = A.joining(optional: A.defaultB.joining(required: B.defaultC)).order(sql: "a.id, b.id, c.id") -// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } +// let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } } do { let request = A.joining(optional: A.defaultB.joining(optional: B.defaultC)).order(sql: "a.id, b.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -533,7 +531,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.defaultC.joining(required: C.defaultD)).order(sql: "b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 1) @@ -542,7 +540,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.defaultC.joining(optional: C.defaultD)).order(sql: "b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -555,11 +553,11 @@ class AssociationChainRowScopesTests: GRDBTestCase { do { // TODO: chainOptionalRequired // let request = B.joining(optional: B.defaultC.joining(required: C.defaultD)).order(sql: "b.id, c.id, d.id") -// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } +// let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } } do { let request = B.joining(optional: B.defaultC.joining(optional: C.defaultD)).order(sql: "b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 3) @@ -577,7 +575,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { func testChainOfThreeIncludingIncludingIncluding() throws { let dbQueue = try makeDatabaseQueue() let request = A.including(required: A.defaultB.including(required: B.defaultC.including(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 1) @@ -593,7 +591,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { func testChainOfThreeIncludingIncludingJoining() throws { let dbQueue = try makeDatabaseQueue() let request = A.including(required: A.defaultB.including(required: B.defaultC.joining(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 1) @@ -608,7 +606,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { func testChainOfThreeIncludingJoiningIncluding() throws { let dbQueue = try makeDatabaseQueue() let request = A.including(required: A.defaultB.joining(required: B.defaultC.including(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 1) @@ -624,7 +622,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { func testChainOfThreeIncludingJoiningJoining() throws { let dbQueue = try makeDatabaseQueue() let request = A.including(required: A.defaultB.joining(required: B.defaultC.joining(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 1) @@ -637,7 +635,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { func testChainOfThreeJoiningIncludingIncluding() throws { let dbQueue = try makeDatabaseQueue() let request = A.joining(required: A.defaultB.including(required: B.defaultC.including(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 1) @@ -653,7 +651,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { func testChainOfThreeJoiningIncludingJoining() throws { let dbQueue = try makeDatabaseQueue() let request = A.joining(required: A.defaultB.including(required: B.defaultC.joining(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 1) @@ -668,7 +666,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { func testChainOfThreeJoiningJoiningIncluding() throws { let dbQueue = try makeDatabaseQueue() let request = A.joining(required: A.defaultB.joining(required: B.defaultC.including(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 1) @@ -684,7 +682,7 @@ class AssociationChainRowScopesTests: GRDBTestCase { func testChainOfThreeJoiningJoiningJoining() throws { let dbQueue = try makeDatabaseQueue() let request = A.joining(required: A.defaultB.joining(required: B.defaultC.joining(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 1) diff --git a/Tests/GRDBTests/AssociationChainSQLTests.swift b/Tests/GRDBTests/AssociationChainSQLTests.swift index 839bba933..a6ebb1631 100644 --- a/Tests/GRDBTests/AssociationChainSQLTests.swift +++ b/Tests/GRDBTests/AssociationChainSQLTests.swift @@ -1,20 +1,23 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB #endif // A -> B <- C -> D -private struct A: TableRecord { +private struct A: TableRecord, EncodableRecord { static let databaseTableName = "a" static let b = belongsTo(B.self) + static let c = hasOne(C.self, through: b, using: B.c) + func encode(to container: inout PersistenceContainer) { + container["bid"] = 1 + } } private struct B: TableRecord { static let c = hasOne(C.self) + static let d = hasOne(D.self, through: c, using: C.d) static let databaseTableName = "b" } @@ -51,6 +54,55 @@ class AssociationChainSQLTests: GRDBTestCase { } } + func testChainOfTwoRequestForIncluding() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + // Direct, Direct + try assertEqualSQL(db, A().request(for: A.b.including(required: B.c)), """ + SELECT "b".*, "c".* \ + FROM "b" \ + JOIN "c" ON ("c"."bid" = "b"."id") \ + WHERE ("b"."id" = 1) + """) + try assertEqualSQL(db, A().request(for: A.b.including(optional: B.c)), """ + SELECT "b".*, "c".* \ + FROM "b" \ + LEFT JOIN "c" ON ("c"."bid" = "b"."id") \ + WHERE ("b"."id" = 1) + """) + + // Direct, Through + try assertEqualSQL(db, A().request(for: A.b.including(required: B.d)), """ + SELECT "b".*, "d".* \ + FROM "b" \ + JOIN "c" ON ("c"."bid" = "b"."id") \ + JOIN "d" ON ("d"."id" = "c"."did") \ + WHERE ("b"."id" = 1) + """) + try assertEqualSQL(db, A().request(for: A.b.including(optional: B.d)), """ + SELECT "b".*, "d".* \ + FROM "b" \ + LEFT JOIN "c" ON ("c"."bid" = "b"."id") \ + LEFT JOIN "d" ON ("d"."id" = "c"."did") \ + WHERE ("b"."id" = 1) + """) + + // Through, Through + try assertEqualSQL(db, A().request(for: A.c.including(required: C.d)), """ + SELECT "c".*, "d".* \ + FROM "c" \ + JOIN "d" ON ("d"."id" = "c"."did") \ + JOIN "b" ON (("b"."id" = "c"."bid") AND ("b"."id" = 1)) + """) + try assertEqualSQL(db, A().request(for: A.c.including(optional: C.d)), """ + SELECT "c".*, "d".* \ + FROM "c" \ + LEFT JOIN "d" ON ("d"."id" = "c"."did") \ + JOIN "b" ON (("b"."id" = "c"."bid") AND ("b"."id" = 1)) + """) + } + } + func testChainOfTwoIncludingIncluding() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in @@ -245,6 +297,55 @@ class AssociationChainSQLTests: GRDBTestCase { } } + func testChainOfTwoRequestForJoining() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + // Direct, Direct + try assertEqualSQL(db, A().request(for: A.b.joining(required: B.c)), """ + SELECT "b".* \ + FROM "b" \ + JOIN "c" ON ("c"."bid" = "b"."id") \ + WHERE ("b"."id" = 1) + """) + try assertEqualSQL(db, A().request(for: A.b.joining(optional: B.c)), """ + SELECT "b".* \ + FROM "b" \ + LEFT JOIN "c" ON ("c"."bid" = "b"."id") \ + WHERE ("b"."id" = 1) + """) + + // Direct, Through + try assertEqualSQL(db, A().request(for: A.b.joining(required: B.d)), """ + SELECT "b".* \ + FROM "b" \ + JOIN "c" ON ("c"."bid" = "b"."id") \ + JOIN "d" ON ("d"."id" = "c"."did") \ + WHERE ("b"."id" = 1) + """) + try assertEqualSQL(db, A().request(for: A.b.joining(optional: B.d)), """ + SELECT "b".* \ + FROM "b" \ + LEFT JOIN "c" ON ("c"."bid" = "b"."id") \ + LEFT JOIN "d" ON ("d"."id" = "c"."did") \ + WHERE ("b"."id" = 1) + """) + + // Through, Through + try assertEqualSQL(db, A().request(for: A.c.joining(required: C.d)), """ + SELECT "c".* \ + FROM "c" \ + JOIN "d" ON ("d"."id" = "c"."did") \ + JOIN "b" ON (("b"."id" = "c"."bid") AND ("b"."id" = 1)) + """) + try assertEqualSQL(db, A().request(for: A.c.joining(optional: C.d)), """ + SELECT "c".* \ + FROM "c" \ + LEFT JOIN "d" ON ("d"."id" = "c"."did") \ + JOIN "b" ON (("b"."id" = "c"."bid") AND ("b"."id" = 1)) + """) + } + } + func testChainOfTwoIncludingJoining() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in @@ -826,7 +927,36 @@ class AssociationChainSQLTests: GRDBTestCase { """) } } - + + func testChainOfThreeRequestForIncludingIncluding() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try assertEqualSQL(db, A().request(for: A.b.including(required: B.c.including(required: C.d))), """ + SELECT "b".*, "c".*, "d".* \ + FROM "b" \ + JOIN "c" ON ("c"."bid" = "b"."id") \ + JOIN "d" ON ("d"."id" = "c"."did") \ + WHERE ("b"."id" = 1) + """) + try assertEqualSQL(db, A().request(for: A.b.including(required: B.c.including(optional: C.d))), """ + SELECT "b".*, "c".*, "d".* \ + FROM "b" \ + JOIN "c" ON ("c"."bid" = "b"."id") \ + LEFT JOIN "d" ON ("d"."id" = "c"."did") \ + WHERE ("b"."id" = 1) + """) + // TODO: chainOptionalRequired + // try assertEqualSQL(db, A().request(for: A.b.including(optional: B.c.including(required: C.d))), "TODO") + try assertEqualSQL(db, A().request(for: A.b.including(optional: B.c.including(optional: C.d))), """ + SELECT "b".*, "c".*, "d".* \ + FROM "b" \ + LEFT JOIN "c" ON ("c"."bid" = "b"."id") \ + LEFT JOIN "d" ON ("d"."id" = "c"."did") \ + WHERE ("b"."id" = 1) + """) + } + } + func testChainOfThreeIncludingIncludingIncluding() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in diff --git a/Tests/GRDBTests/AssociationHasManyRowScopeTests.swift b/Tests/GRDBTests/AssociationHasManyRowScopeTests.swift new file mode 100644 index 000000000..c7194f37f --- /dev/null +++ b/Tests/GRDBTests/AssociationHasManyRowScopeTests.swift @@ -0,0 +1,107 @@ +import XCTest +#if GRDBCUSTOMSQLITE + import GRDBCustomSQLite +#else + import GRDB +#endif + +class AssociationHasManyRowScopeTests: GRDBTestCase { + + func testSingularTable() throws { + struct Child : TableRecord { + } + + struct Parent : TableRecord { + static let children = hasMany(Child.self) + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try db.create(table: "parent") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "child") { t in + t.autoIncrementedPrimaryKey("id") + t.column("parentId", .integer).references("parent") + } + try db.execute(sql: """ + INSERT INTO parent (id) VALUES (1); + INSERT INTO child (id, parentId) VALUES (2, 1); + """) + + let request = Parent.including(required: Parent.children) + let row = try Row.fetchOne(db, request)! + XCTAssertEqual(row.unscoped, ["id": 1]) + XCTAssertEqual(row.scopes["child"], ["id": 2, "parentId": 1]) + } + } + + func testPluralTable() throws { + struct Child : TableRecord { + static let databaseTableName = "children" + } + + struct Parent : TableRecord { + static let databaseTableName = "parents" + static let children = hasMany(Child.self) + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try db.create(table: "parents") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "children") { t in + t.autoIncrementedPrimaryKey("id") + t.column("parentId", .integer).references("parents") + } + try db.execute(sql: """ + INSERT INTO parents (id) VALUES (1); + INSERT INTO children (id, parentId) VALUES (2, 1); + """) + + let request = Parent.including(required: Parent.children) + let row = try Row.fetchOne(db, request)! + XCTAssertEqual(row.unscoped, ["id": 1]) + XCTAssertEqual(row.scopes["child"], ["id": 2, "parentId": 1]) + } + } + + func testCustomKey() throws { + struct Child : TableRecord { + } + + struct Parent : TableRecord { + static let littlePuppies = hasMany(Child.self, key: "littlePuppies") + static let kittens = hasMany(Child.self).forKey("kittens") + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try db.create(table: "parent") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "child") { t in + t.autoIncrementedPrimaryKey("id") + t.column("parentId", .integer).references("parent") + } + try db.execute(sql: """ + INSERT INTO parent (id) VALUES (1); + INSERT INTO child (id, parentId) VALUES (2, 1); + """) + + do { + let request = Parent.including(required: Parent.littlePuppies) + let row = try Row.fetchOne(db, request)! + XCTAssertEqual(row.unscoped, ["id": 1]) + XCTAssertEqual(row.scopes["littlePuppy"], ["id": 2, "parentId": 1]) + } + do { + let request = Parent.including(required: Parent.kittens) + let row = try Row.fetchOne(db, request)! + XCTAssertEqual(row.unscoped, ["id": 1]) + XCTAssertEqual(row.scopes["kitten"], ["id": 2, "parentId": 1]) + } + } + } +} diff --git a/Tests/GRDBTests/AssociationHasManySQLTests.swift b/Tests/GRDBTests/AssociationHasManySQLTests.swift new file mode 100644 index 000000000..f9f037113 --- /dev/null +++ b/Tests/GRDBTests/AssociationHasManySQLTests.swift @@ -0,0 +1,767 @@ +import XCTest +#if GRDBCUSTOMSQLITE + import GRDBCustomSQLite +#else + import GRDB +#endif + +/// Test SQL generation +class AssociationHasManySQLTests: GRDBTestCase { + + func testSingleColumnNoForeignKeyNoPrimaryKey() throws { + struct Child : TableRecord { + static let databaseTableName = "children" + } + + struct Parent : TableRecord, EncodableRecord { + static let databaseTableName = "parents" + func encode(to container: inout PersistenceContainer) { + container["id"] = 1 + container["rowid"] = 2 + } + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try db.create(table: "parents") { t in + t.column("id", .integer) + } + try db.create(table: "children") { t in + t.column("parentId", .integer) + } + } + + try dbQueue.inDatabase { db in + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parentId")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parentId" = "parents"."rowid") + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parentId" = "parents"."rowid") + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parentId" = "parents"."rowid") + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parentId" = "parents"."rowid") + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parentId\" = 2)") + } + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parentId")], to: [Column("id")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parentId\" = 1)") + } + } + } + + func testSingleColumnNoForeignKey() throws { + struct Child : TableRecord { + static let databaseTableName = "children" + } + + struct Parent : TableRecord, EncodableRecord { + static let databaseTableName = "parents" + func encode(to container: inout PersistenceContainer) { + container["id"] = 1 + } + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try db.create(table: "parents") { t in + t.column("id", .integer).primaryKey() + } + try db.create(table: "children") { t in + t.column("parentId", .integer) + } + } + + try dbQueue.inDatabase { db in + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parentId")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parentId\" = 1)") + } + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parentId")], to: [Column("id")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parentId\" = 1)") + } + } + } + + func testSingleColumnSingleForeignKey() throws { + struct Child : TableRecord { + static let databaseTableName = "children" + } + + struct Parent : TableRecord, EncodableRecord { + static let databaseTableName = "parents" + func encode(to container: inout PersistenceContainer) { + container["id"] = 1 + } + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try db.create(table: "parents") { t in + t.column("id", .integer).primaryKey() + } + try db.create(table: "children") { t in + t.column("parentId", .integer).references("parents") + } + } + + try dbQueue.inDatabase { db in + do { + let association = Parent.hasMany(Child.self) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parentId\" = 1)") + } + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parentId")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parentId\" = 1)") + } + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parentId")], to: [Column("id")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parentId" = "parents"."id") + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parentId\" = 1)") + } + } + } + + func testSingleColumnSeveralForeignKeys() throws { + struct Child : TableRecord { + static let databaseTableName = "children" + } + + struct Parent : TableRecord, EncodableRecord { + static let databaseTableName = "parents" + func encode(to container: inout PersistenceContainer) { + container["id"] = 1 + } + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try db.create(table: "parents") { t in + t.column("id", .integer).primaryKey() + } + try db.create(table: "children") { t in + t.column("parent1Id", .integer).references("parents") + t.column("parent2Id", .integer).references("parents") + } + } + + try dbQueue.inDatabase { db in + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parent1Id")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parent1Id" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parent1Id" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parent1Id" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parent1Id" = "parents"."id") + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parent1Id\" = 1)") + } + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parent1Id")], to: [Column("id")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parent1Id" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parent1Id" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parent1Id" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parent1Id" = "parents"."id") + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parent1Id\" = 1)") + } + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parent2Id")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parent2Id" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parent2Id" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parent2Id" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parent2Id" = "parents"."id") + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parent2Id\" = 1)") + } + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parent2Id")], to: [Column("id")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parent2Id" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parent2Id" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON ("children"."parent2Id" = "parents"."id") + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON ("children"."parent2Id" = "parents"."id") + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parent2Id\" = 1)") + } + } + } + + func testCompoundColumnNoForeignKeyNoPrimaryKey() throws { + struct Child : TableRecord { + static let databaseTableName = "children" + } + + struct Parent : TableRecord, EncodableRecord { + static let databaseTableName = "parents" + func encode(to container: inout PersistenceContainer) { + container["a"] = 1 + container["b"] = 2 + } + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try db.create(table: "parents") { t in + t.column("a", .integer) + t.column("b", .integer) + } + try db.create(table: "children") { t in + t.column("parentA", .integer) + t.column("parentB", .integer) + } + } + + try dbQueue.inDatabase { db in + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parentA"), Column("parentB")], to: [Column("a"), Column("b")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parentA\" = 1) AND (\"parentB\" = 2))") + } + } + } + + func testCompoundColumnNoForeignKey() throws { + struct Child : TableRecord { + static let databaseTableName = "children" + } + + struct Parent : TableRecord, EncodableRecord { + static let databaseTableName = "parents" + func encode(to container: inout PersistenceContainer) { + container["a"] = 1 + container["b"] = 2 + } + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try db.create(table: "parents") { t in + t.column("a", .integer) + t.column("b", .integer) + t.primaryKey(["a", "b"]) + } + try db.create(table: "children") { t in + t.column("parentA", .integer) + t.column("parentB", .integer) + } + } + + try dbQueue.inDatabase { db in + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parentA"), Column("parentB")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parentA\" = 1) AND (\"parentB\" = 2))") + } + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parentA"), Column("parentB")], to: [Column("a"), Column("b")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parentA\" = 1) AND (\"parentB\" = 2))") + } + } + } + + func testCompoundColumnSingleForeignKey() throws { + struct Child : TableRecord { + static let databaseTableName = "children" + } + + struct Parent : TableRecord, EncodableRecord { + static let databaseTableName = "parents" + func encode(to container: inout PersistenceContainer) { + container["a"] = 1 + container["b"] = 2 + } + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try db.create(table: "parents") { t in + t.column("a", .integer) + t.column("b", .integer) + t.primaryKey(["a", "b"]) + } + try db.create(table: "children") { t in + t.column("parentA", .integer) + t.column("parentB", .integer) + t.foreignKey(["parentA", "parentB"], references: "parents") + } + } + + try dbQueue.inDatabase { db in + do { + let association = Parent.hasMany(Child.self) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parentA\" = 1) AND (\"parentB\" = 2))") + } + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parentA"), Column("parentB")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parentA\" = 1) AND (\"parentB\" = 2))") + } + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parentA"), Column("parentB")], to: [Column("a"), Column("b")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b")) + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parentA\" = 1) AND (\"parentB\" = 2))") + } + } + } + + func testCompoundColumnSeveralForeignKeys() throws { + struct Child : TableRecord { + static let databaseTableName = "children" + } + + struct Parent : TableRecord, EncodableRecord { + static let databaseTableName = "parents" + func encode(to container: inout PersistenceContainer) { + container["a"] = 1 + container["b"] = 2 + } + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try db.create(table: "parents") { t in + t.column("a", .integer) + t.column("b", .integer) + t.primaryKey(["a", "b"]) + } + try db.create(table: "children") { t in + t.column("parent1A", .integer) + t.column("parent1B", .integer) + t.column("parent2A", .integer) + t.column("parent2B", .integer) + t.foreignKey(["parent1A", "parent1B"], references: "parents") + t.foreignKey(["parent2A", "parent2B"], references: "parents") + } + } + + try dbQueue.inDatabase { db in + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parent1A"), Column("parent1B")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parent1A" = "parents"."a") AND ("children"."parent1B" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parent1A" = "parents"."a") AND ("children"."parent1B" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parent1A" = "parents"."a") AND ("children"."parent1B" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parent1A" = "parents"."a") AND ("children"."parent1B" = "parents"."b")) + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parent1A\" = 1) AND (\"parent1B\" = 2))") + } + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parent1A"), Column("parent1B")], to: [Column("a"), Column("b")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parent1A" = "parents"."a") AND ("children"."parent1B" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parent1A" = "parents"."a") AND ("children"."parent1B" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parent1A" = "parents"."a") AND ("children"."parent1B" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parent1A" = "parents"."a") AND ("children"."parent1B" = "parents"."b")) + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parent1A\" = 1) AND (\"parent1B\" = 2))") + } + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parent2A"), Column("parent2B")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parent2A" = "parents"."a") AND ("children"."parent2B" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parent2A" = "parents"."a") AND ("children"."parent2B" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parent2A" = "parents"."a") AND ("children"."parent2B" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parent2A" = "parents"."a") AND ("children"."parent2B" = "parents"."b")) + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parent2A\" = 1) AND (\"parent2B\" = 2))") + } + do { + let association = Parent.hasMany(Child.self, using: ForeignKey([Column("parent2A"), Column("parent2B")], to: [Column("a"), Column("b")])) + try assertEqualSQL(db, Parent.all().including(required: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parent2A" = "parents"."a") AND ("children"."parent2B" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().including(optional: association), """ + SELECT "parents".*, "children".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parent2A" = "parents"."a") AND ("children"."parent2B" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(required: association), """ + SELECT "parents".* \ + FROM "parents" \ + JOIN "children" ON (("children"."parent2A" = "parents"."a") AND ("children"."parent2B" = "parents"."b")) + """) + try assertEqualSQL(db, Parent.all().joining(optional: association), """ + SELECT "parents".* \ + FROM "parents" \ + LEFT JOIN "children" ON (("children"."parent2A" = "parents"."a") AND ("children"."parent2B" = "parents"."b")) + """) + try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parent2A\" = 1) AND (\"parent2B\" = 2))") + } + } + } + + func testForeignKeyDefinitionFromColumn() { + // This test pass if code compiles + struct Parent : TableRecord { + static let databaseTableName = "parents" + enum Columns { + static let id = Column("id") + } + static let child1 = hasMany(Child.self, using: Child.ForeignKeys.parent1) + static let child2 = hasMany(Child.self, using: Child.ForeignKeys.parent2) + } + + struct Child : TableRecord { + static let databaseTableName = "children" + enum Columns { + static let parentId = Column("parentId") + } + enum ForeignKeys { + static let parent1 = ForeignKey([Columns.parentId]) + static let parent2 = ForeignKey([Columns.parentId], to: [Parent.Columns.id]) + } + } + } +} diff --git a/Tests/GRDBTests/AssociationHasManyThroughRowScopeTests.swift b/Tests/GRDBTests/AssociationHasManyThroughRowScopeTests.swift new file mode 100644 index 000000000..44f42f802 --- /dev/null +++ b/Tests/GRDBTests/AssociationHasManyThroughRowScopeTests.swift @@ -0,0 +1,270 @@ +import XCTest +#if GRDBCUSTOMSQLITE + import GRDBCustomSQLite +#else + import GRDB +#endif + +/// Test SQL generation + +class AssociationHasManyThroughRowScopeTests: GRDBTestCase { + + func testBelongsToHasManySingularTable() throws { + struct Parent: TableRecord { + static let child = belongsTo(Child.self) + static let grandChildren = hasMany(GrandChild.self, through: child, using: Child.grandChildren) + } + struct Child: TableRecord { + static let grandChildren = hasMany(GrandChild.self) + } + struct GrandChild: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "child") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "parent") { t in + t.autoIncrementedPrimaryKey("id") + t.column("childId").references("child") + } + try db.create(table: "grandChild") { t in + t.autoIncrementedPrimaryKey("id") + t.column("childId").references("child") + } + try db.execute(sql: """ + INSERT INTO child (id) VALUES (1); + INSERT INTO parent (id, childId) VALUES (2, 1); + INSERT INTO grandChild (id, childId) VALUES (3, 1); + """) + + let request = Parent.including(required: Parent.grandChildren) + let row = try Row.fetchOne(db, request)! + XCTAssertEqual(row.unscoped, ["id": 2, "childId": 1]) + XCTAssertEqual(Set(row.scopes.names), ["child"]) + XCTAssertEqual(row.scopesTree["grandChild"], ["id": 3, "childId": 1]) + } + } + + func testBelongsToHasManyPluralTable() throws { + struct Parent: TableRecord { + static let databaseTableName = "parents" + static let child = belongsTo(Child.self) + static let grandChildren = hasMany(GrandChild.self, through: child, using: Child.grandChildren) + } + struct Child: TableRecord { + static let databaseTableName = "children" + static let grandChildren = hasMany(GrandChild.self) + } + struct GrandChild: TableRecord { + static let databaseTableName = "grandChildren" + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "children") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "parents") { t in + t.autoIncrementedPrimaryKey("id") + t.column("childId").references("children") + } + try db.create(table: "grandChildren") { t in + t.autoIncrementedPrimaryKey("id") + t.column("childId").references("children") + } + try db.execute(sql: """ + INSERT INTO children (id) VALUES (1); + INSERT INTO parents (id, childId) VALUES (2, 1); + INSERT INTO grandChildren (id, childId) VALUES (3, 1); + """) + + let request = Parent.including(required: Parent.grandChildren) + let row = try Row.fetchOne(db, request)! + XCTAssertEqual(row.unscoped, ["id": 2, "childId": 1]) + XCTAssertEqual(Set(row.scopes.names), ["child"]) + XCTAssertEqual(row.scopesTree["grandChild"], ["id": 3, "childId": 1]) + } + } + + func testBelongsToHasManyCustomKey() throws { + struct Parent: TableRecord { + static let databaseTableName = "parents" + static let child = belongsTo(Child.self) + static let littlePuppies = hasMany(GrandChild.self, through: child, using: Child.grandChildren, key: "littlePuppies") + static let kittens = hasMany(GrandChild.self, through: child, using: Child.grandChildren).forKey("kittens") + } + struct Child: TableRecord { + static let databaseTableName = "children" + static let grandChildren = hasMany(GrandChild.self) + } + struct GrandChild: TableRecord { + static let databaseTableName = "grandChildren" + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "children") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "parents") { t in + t.autoIncrementedPrimaryKey("id") + t.column("childId").references("children") + } + try db.create(table: "grandChildren") { t in + t.autoIncrementedPrimaryKey("id") + t.column("childId").references("children") + } + try db.execute(sql: """ + INSERT INTO children (id) VALUES (1); + INSERT INTO parents (id, childId) VALUES (2, 1); + INSERT INTO grandChildren (id, childId) VALUES (3, 1); + """) + + do { + let request = Parent.including(required: Parent.littlePuppies) + let row = try Row.fetchOne(db, request)! + XCTAssertEqual(row.unscoped, ["id": 2, "childId": 1]) + XCTAssertEqual(Set(row.scopes.names), ["child"]) + XCTAssertEqual(row.scopesTree["littlePuppy"], ["id": 3, "childId": 1]) + } + + do { + let request = Parent.including(required: Parent.kittens) + let row = try Row.fetchOne(db, request)! + XCTAssertEqual(row.unscoped, ["id": 2, "childId": 1]) + XCTAssertEqual(Set(row.scopes.names), ["child"]) + XCTAssertEqual(row.scopesTree["kitten"], ["id": 3, "childId": 1]) + } + } + } + + func testHasManyBelongsToSingularTable() throws { + struct Parent: TableRecord { + static let children = hasMany(Child.self) + static let grandChildren = hasMany(GrandChild.self, through: children, using: Child.grandChild) + } + struct Child: TableRecord { + static let grandChild = belongsTo(GrandChild.self) + } + struct GrandChild: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "parent") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "grandChild") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "child") { t in + t.autoIncrementedPrimaryKey("id") + t.column("parentId").references("parent") + t.column("grandChildId").references("grandChild") + } + try db.execute(sql: """ + INSERT INTO parent (id) VALUES (1); + INSERT INTO grandChild (id) VALUES (2); + INSERT INTO child (id, parentId, grandChildId) VALUES (3, 1, 2); + """) + + let request = Parent.including(required: Parent.grandChildren) + let row = try Row.fetchOne(db, request)! + XCTAssertEqual(row.unscoped, ["id": 1]) + XCTAssertEqual(Set(row.scopes.names), ["child"]) + XCTAssertEqual(row.scopesTree["grandChild"], ["id": 2]) + } + } + + func testHasManyBelongsToPluralTable() throws { + struct Parent: TableRecord { + static let databaseTableName = "parents" + static let children = hasMany(Child.self) + static let grandChildren = hasMany(GrandChild.self, through: children, using: Child.grandChild) + } + struct Child: TableRecord { + static let databaseTableName = "children" + static let grandChild = belongsTo(GrandChild.self) + } + struct GrandChild: TableRecord { + static let databaseTableName = "grandChildren" + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "parents") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "grandChildren") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "children") { t in + t.autoIncrementedPrimaryKey("id") + t.column("parentId").references("parents") + t.column("grandChildId").references("grandChildren") + } + try db.execute(sql: """ + INSERT INTO parents (id) VALUES (1); + INSERT INTO grandChildren (id) VALUES (2); + INSERT INTO children (id, parentId, grandChildId) VALUES (3, 1, 2); + """) + + let request = Parent.including(required: Parent.grandChildren) + let row = try Row.fetchOne(db, request)! + XCTAssertEqual(row.unscoped, ["id": 1]) + XCTAssertEqual(Set(row.scopes.names), ["child"]) + XCTAssertEqual(row.scopesTree["grandChild"], ["id": 2]) + } + } + + func testHasManyBelongsToCustomKey() throws { + struct Parent: TableRecord { + static let children = hasMany(Child.self) + static let littlePuppies = hasMany(GrandChild.self, through: children, using: Child.grandChild, key: "littlePuppies") + static let kittens = hasMany(GrandChild.self, through: children, using: Child.grandChild).forKey("kittens") + } + struct Child: TableRecord { + static let grandChild = belongsTo(GrandChild.self) + } + struct GrandChild: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "parent") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "grandChild") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "child") { t in + t.autoIncrementedPrimaryKey("id") + t.column("parentId").references("parent") + t.column("grandChildId").references("grandChild") + } + try db.execute(sql: """ + INSERT INTO parent (id) VALUES (1); + INSERT INTO grandChild (id) VALUES (2); + INSERT INTO child (id, parentId, grandChildId) VALUES (3, 1, 2); + """) + + do { + let request = Parent.including(required: Parent.littlePuppies) + let row = try Row.fetchOne(db, request)! + XCTAssertEqual(row.unscoped, ["id": 1]) + XCTAssertEqual(Set(row.scopes.names), ["child"]) + XCTAssertEqual(row.scopesTree["littlePuppy"], ["id": 2]) + } + + do { + let request = Parent.including(required: Parent.kittens) + let row = try Row.fetchOne(db, request)! + XCTAssertEqual(row.unscoped, ["id": 1]) + XCTAssertEqual(Set(row.scopes.names), ["child"]) + XCTAssertEqual(row.scopesTree["kitten"], ["id": 2]) + } + } + } +} diff --git a/Tests/GRDBTests/AssociationHasManyThroughSQLTests.swift b/Tests/GRDBTests/AssociationHasManyThroughSQLTests.swift new file mode 100644 index 000000000..6abfb73e8 --- /dev/null +++ b/Tests/GRDBTests/AssociationHasManyThroughSQLTests.swift @@ -0,0 +1,316 @@ +import XCTest +#if GRDBCUSTOMSQLITE + import GRDBCustomSQLite +#else + import GRDB +#endif + +/// Test SQL generation + +class AssociationHasManyThroughSQLTests: GRDBTestCase { + + func testBelongsToHasMany() throws { + struct A: TableRecord, EncodableRecord { + static let b = belongsTo(B.self) + static let c = hasMany(C.self, through: b, using: B.c) + func encode(to container: inout PersistenceContainer) { + container["bId"] = 1 + } + } + struct B: TableRecord { + static let c = hasMany(C.self) + } + struct C: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + } + + try testHasManyWithTwoSteps( + db, ab: A.b, ac: A.c, + bCondition: "(\"b\".\"id\" = \"a\".\"bId\")", + cCondition: "(\"c\".\"bId\" = \"b\".\"id\")") + + try assertEqualSQL(db, A().request(for: A.c), """ + SELECT "c".* FROM "c" \ + JOIN "b" ON (("b"."id" = "c"."bId") AND ("b"."id" = 1)) + """) + } + } + + func testHasOneHasMany() throws { + struct A: TableRecord, EncodableRecord { + static let b = hasOne(B.self) + static let c = hasMany(C.self, through: b, using: B.c) + func encode(to container: inout PersistenceContainer) { + container["id"] = 1 + } + } + struct B: TableRecord { + static let c = hasMany(C.self) + } + struct C: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + t.column("aId").references("a") + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + } + + try testHasManyWithTwoSteps( + db, ab: A.b, ac: A.c, + bCondition: "(\"b\".\"aId\" = \"a\".\"id\")", + cCondition: "(\"c\".\"bId\" = \"b\".\"id\")") + + try assertEqualSQL(db, A().request(for: A.c), """ + SELECT "c".* FROM "c" \ + JOIN "b" ON (("b"."id" = "c"."bId") AND ("b"."aId" = 1)) + """) + } + } + + func testHasManyBelongsTo() throws { + struct A: TableRecord, EncodableRecord { + static let b = hasMany(B.self) + static let c = hasMany(C.self, through: b, using: B.c) + func encode(to container: inout PersistenceContainer) { + container["id"] = 1 + } + } + struct B: TableRecord { + static let c = belongsTo(C.self) + } + struct C: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + t.column("cId").references("c") + t.column("aId").references("a") + } + + try testHasManyWithTwoSteps( + db, ab: A.b, ac: A.c, + bCondition: "(\"b\".\"aId\" = \"a\".\"id\")", + cCondition: "(\"c\".\"id\" = \"b\".\"cId\")") + + try assertEqualSQL(db, A().request(for: A.c), """ + SELECT "c".* FROM "c" \ + JOIN "b" ON (("b"."cId" = "c"."id") AND ("b"."aId" = 1)) + """) + } + } + + func testHasManyHasOne() throws { + struct A: TableRecord, EncodableRecord { + static let b = hasMany(B.self) + static let c = hasMany(C.self, through: b, using: B.c) + func encode(to container: inout PersistenceContainer) { + container["id"] = 1 + } + } + struct B: TableRecord { + static let c = hasOne(C.self) + } + struct C: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + t.column("aId").references("a") + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + } + + try testHasManyWithTwoSteps( + db, ab: A.b, ac: A.c, + bCondition: "(\"b\".\"aId\" = \"a\".\"id\")", + cCondition: "(\"c\".\"bId\" = \"b\".\"id\")") + + try assertEqualSQL(db, A().request(for: A.c), """ + SELECT "c".* FROM "c" \ + JOIN "b" ON (("b"."id" = "c"."bId") AND ("b"."aId" = 1)) + """) + } + } + + private func testHasManyWithTwoSteps( + _ db: Database, + ab: BAssociation, + ac: CAssociation, + bCondition: String, + cCondition: String) throws + where BAssociation: Association, + CAssociation: Association, + BAssociation.OriginRowDecoder == CAssociation.OriginRowDecoder, + BAssociation.OriginRowDecoder: TableRecord + { + let A = BAssociation.OriginRowDecoder.self + + do { + try assertEqualSQL(db, A.including(optional: ac), """ + SELECT "a".*, "c".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.including(required: ac), """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.joining(optional: ac), """ + SELECT "a".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.joining(required: ac), """ + SELECT "a".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + } + do { + try assertEqualSQL(db, A.including(optional: ac).including(optional: ab), """ + SELECT "a".*, "b".*, "c".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.including(optional: ac).including(required: ab), """ + SELECT "a".*, "b".*, "c".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.including(optional: ac).joining(optional: ab), """ + SELECT "a".*, "c".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.including(optional: ac).joining(required: ab), """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + } + do { + try assertEqualSQL(db, A.including(required: ac).including(optional: ab), """ + SELECT "a".*, "b".*, "c".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.including(required: ac).including(required: ab), """ + SELECT "a".*, "b".*, "c".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.including(required: ac).joining(optional: ab), """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.including(required: ac).joining(required: ab), """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + } + do { + try assertEqualSQL(db, A.joining(optional: ac).including(optional: ab), """ + SELECT "a".*, "b".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.joining(optional: ac).including(required: ab), """ + SELECT "a".*, "b".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.joining(optional: ac).joining(optional: ab), """ + SELECT "a".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.joining(optional: ac).joining(required: ab), """ + SELECT "a".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + } + do { + try assertEqualSQL(db, A.joining(required: ac).including(optional: ab), """ + SELECT "a".*, "b".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.joining(required: ac).including(required: ab), """ + SELECT "a".*, "b".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.joining(required: ac).joining(optional: ab), """ + SELECT "a".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.joining(required: ac).joining(required: ab), """ + SELECT "a".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + } + } +} diff --git a/Tests/GRDBTests/AssociationHasOneSQLDerivationTests.swift b/Tests/GRDBTests/AssociationHasOneSQLDerivationTests.swift index d15bbd908..a83ab2d10 100644 --- a/Tests/GRDBTests/AssociationHasOneSQLDerivationTests.swift +++ b/Tests/GRDBTests/AssociationHasOneSQLDerivationTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/AssociationHasOneSQLTests.swift b/Tests/GRDBTests/AssociationHasOneSQLTests.swift index 182502be4..acaf773fc 100644 --- a/Tests/GRDBTests/AssociationHasOneSQLTests.swift +++ b/Tests/GRDBTests/AssociationHasOneSQLTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -15,7 +13,7 @@ class AssociationHasOneSQLTests: GRDBTestCase { static let databaseTableName = "children" } - struct Parent : TableRecord, MutablePersistableRecord { + struct Parent : TableRecord, EncodableRecord { static let databaseTableName = "parents" func encode(to container: inout PersistenceContainer) { container["id"] = 1 @@ -90,7 +88,7 @@ class AssociationHasOneSQLTests: GRDBTestCase { static let databaseTableName = "children" } - struct Parent : TableRecord, MutablePersistableRecord { + struct Parent : TableRecord, EncodableRecord { static let databaseTableName = "parents" func encode(to container: inout PersistenceContainer) { container["id"] = 1 @@ -164,7 +162,7 @@ class AssociationHasOneSQLTests: GRDBTestCase { static let databaseTableName = "children" } - struct Parent : TableRecord, MutablePersistableRecord { + struct Parent : TableRecord, EncodableRecord { static let databaseTableName = "parents" func encode(to container: inout PersistenceContainer) { container["id"] = 1 @@ -262,7 +260,7 @@ class AssociationHasOneSQLTests: GRDBTestCase { static let databaseTableName = "children" } - struct Parent : TableRecord, MutablePersistableRecord { + struct Parent : TableRecord, EncodableRecord { static let databaseTableName = "parents" func encode(to container: inout PersistenceContainer) { container["id"] = 1 @@ -385,7 +383,7 @@ class AssociationHasOneSQLTests: GRDBTestCase { static let databaseTableName = "children" } - struct Parent : TableRecord, MutablePersistableRecord { + struct Parent : TableRecord, EncodableRecord { static let databaseTableName = "parents" func encode(to container: inout PersistenceContainer) { container["a"] = 1 @@ -438,7 +436,7 @@ class AssociationHasOneSQLTests: GRDBTestCase { static let databaseTableName = "children" } - struct Parent : TableRecord, MutablePersistableRecord { + struct Parent : TableRecord, EncodableRecord { static let databaseTableName = "parents" func encode(to container: inout PersistenceContainer) { container["a"] = 1 @@ -516,7 +514,7 @@ class AssociationHasOneSQLTests: GRDBTestCase { static let databaseTableName = "children" } - struct Parent : TableRecord, MutablePersistableRecord { + struct Parent : TableRecord, EncodableRecord { static let databaseTableName = "parents" func encode(to container: inout PersistenceContainer) { container["a"] = 1 @@ -619,7 +617,7 @@ class AssociationHasOneSQLTests: GRDBTestCase { static let databaseTableName = "children" } - struct Parent : TableRecord, MutablePersistableRecord { + struct Parent : TableRecord, EncodableRecord { static let databaseTableName = "parents" func encode(to container: inout PersistenceContainer) { container["a"] = 1 diff --git a/Tests/GRDBTests/AssociationHasOneThroughDecodableRecordTests.swift b/Tests/GRDBTests/AssociationHasOneThroughDecodableRecordTests.swift new file mode 100644 index 000000000..ffecffb2d --- /dev/null +++ b/Tests/GRDBTests/AssociationHasOneThroughDecodableRecordTests.swift @@ -0,0 +1,180 @@ +import XCTest +#if GRDBCUSTOMSQLITE + import GRDBCustomSQLite +#else + import GRDB +#endif + +private struct A: Codable, FetchableRecord, PersistableRecord { + static let b = belongsTo(B.self) + static let c = hasOne(C.self, through: b, using: B.c) + var id: Int64 + var bId: Int64? + var name: String +} + +private struct B: Codable, FetchableRecord, PersistableRecord { + static let c = belongsTo(C.self) + var id: Int64 + var cId: Int64? + var name: String +} + +private struct C: Codable, FetchableRecord, PersistableRecord { + var id: Int64 + var name: String +} + +private struct AWithRequiredC: Decodable, FetchableRecord { + var a: A + var c: C +} + +private struct AWithOptionalC: Decodable, FetchableRecord { + var a: A + var optionalC: C? + static let c = A.c.forKey(CodingKeys.optionalC) +} + +private struct AWithRequiredBAndOptionalC: Decodable, FetchableRecord { + var a: A + var b: B + var c: C? +} + +/// Test support for FetchableRecord records +class AssociationHasOneThroughDecodableRecordTests: GRDBTestCase { + + override func setup(_ dbWriter: DatabaseWriter) throws { + try dbWriter.write { db in + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + t.column("name", .text) + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + t.column("cId").references("c") + t.column("name", .text) + } + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + t.column("name", .text) + } + + try C(id: 1, name: "c1").insert(db) + try B(id: 1, cId: 1, name: "b1").insert(db) + try B(id: 2, cId: nil, name: "b2").insert(db) + try A(id: 1, bId: 1, name: "a1").insert(db) + try A(id: 2, bId: 2, name: "a2").insert(db) + try A(id: 3, bId: nil, name: "a3").insert(db) + } + } + + func testIncludingRequired() throws { + let dbQueue = try makeDatabaseQueue() + let request = A + .including(required: A.c) + .order(sql: "a.id") + .asRequest(of: AWithRequiredC.self) + let records = try dbQueue.inDatabase(request.fetchAll) + + XCTAssertEqual(records.count, 1) + + XCTAssertEqual(records[0].a.id, 1) + XCTAssertEqual(records[0].a.bId, 1) + XCTAssertEqual(records[0].a.name, "a1") + XCTAssertEqual(records[0].c.id, 1) + XCTAssertEqual(records[0].c.name, "c1") + } + + func testIncludingOptional() throws { + let dbQueue = try makeDatabaseQueue() + let request = A + .including(optional: AWithOptionalC.c) + .order(sql: "a.id") + .asRequest(of: AWithOptionalC.self) + let records = try dbQueue.inDatabase(request.fetchAll) + + XCTAssertEqual(records.count, 3) + + XCTAssertEqual(records[0].a.id, 1) + XCTAssertEqual(records[0].a.bId, 1) + XCTAssertEqual(records[0].a.name, "a1") + XCTAssertEqual(records[0].optionalC!.id, 1) + XCTAssertEqual(records[0].optionalC!.name, "c1") + + XCTAssertEqual(records[1].a.id, 2) + XCTAssertEqual(records[1].a.bId, 2) + XCTAssertEqual(records[1].a.name, "a2") + XCTAssertNil(records[1].optionalC) + + XCTAssertEqual(records[2].a.id, 3) + XCTAssertNil(records[2].a.bId) + XCTAssertEqual(records[2].a.name, "a3") + XCTAssertNil(records[2].optionalC) + } + + func testJoiningRequired() throws { + let dbQueue = try makeDatabaseQueue() + let request = A + .joining(required: A.c) + .order(sql: "a.id") + let records = try dbQueue.inDatabase(request.fetchAll) + + XCTAssertEqual(records.count, 1) + + XCTAssertEqual(records[0].id, 1) + XCTAssertEqual(records[0].bId, 1) + XCTAssertEqual(records[0].name, "a1") + } + + func testJoiningOptional() throws { + let dbQueue = try makeDatabaseQueue() + let request = A + .joining(optional: A.c) + .order(sql: "a.id") + let records = try dbQueue.inDatabase(request.fetchAll) + + XCTAssertEqual(records.count, 3) + + XCTAssertEqual(records[0].id, 1) + XCTAssertEqual(records[0].bId, 1) + XCTAssertEqual(records[0].name, "a1") + + XCTAssertEqual(records[1].id, 2) + XCTAssertEqual(records[1].bId, 2) + XCTAssertEqual(records[1].name, "a2") + + XCTAssertEqual(records[2].id, 3) + XCTAssertNil(records[2].bId) + XCTAssertEqual(records[2].name, "a3") + } + + func testIncludingOptionalIncludingRequiredPivot() throws { + let dbQueue = try makeDatabaseQueue() + let request = A + .including(optional: A.c) + .including(required: A.b) + .order(sql: "a.id") + .asRequest(of: AWithRequiredBAndOptionalC.self) + let records = try dbQueue.inDatabase(request.fetchAll) + + XCTAssertEqual(records.count, 2) + + XCTAssertEqual(records[0].a.id, 1) + XCTAssertEqual(records[0].a.bId, 1) + XCTAssertEqual(records[0].a.name, "a1") + XCTAssertEqual(records[0].b.id, 1) + XCTAssertEqual(records[0].b.name, "b1") + XCTAssertEqual(records[0].c!.id, 1) + XCTAssertEqual(records[0].c!.name, "c1") + + XCTAssertEqual(records[1].a.id, 2) + XCTAssertEqual(records[1].a.bId, 2) + XCTAssertEqual(records[1].a.name, "a2") + XCTAssertEqual(records[1].b.id, 2) + XCTAssertEqual(records[1].b.name, "b2") + XCTAssertNil(records[1].c) + } +} diff --git a/Tests/GRDBTests/AssociationHasOneThroughFetchableRecordTests.swift b/Tests/GRDBTests/AssociationHasOneThroughFetchableRecordTests.swift new file mode 100644 index 000000000..2a8752a0d --- /dev/null +++ b/Tests/GRDBTests/AssociationHasOneThroughFetchableRecordTests.swift @@ -0,0 +1,184 @@ +import XCTest +#if GRDBCUSTOMSQLITE + import GRDBCustomSQLite +#else + import GRDB +#endif + +private struct A: Codable, FetchableRecord, PersistableRecord { + static let b = belongsTo(B.self) + static let c = hasOne(C.self, through: b, using: B.c) + var id: Int64 + var bId: Int64? + var name: String +} + +private struct B: Codable, FetchableRecord, PersistableRecord { + static let c = belongsTo(C.self) + var id: Int64 + var cId: Int64? + var name: String +} + +private struct C: Codable, FetchableRecord, PersistableRecord { + var id: Int64 + var name: String +} + +private struct AWithRequiredC: FetchableRecord { + var a: A + var c: C + + init(row: Row) { + a = A(row: row) + c = row["c"] + } +} + +private struct AWithOptionalC: FetchableRecord { + var a: A + var c: C? + + init(row: Row) { + a = A(row: row) + c = row["c"] + } +} + +private struct AWithRequiredBAndOptionalC: FetchableRecord { + var a: A + var b: B + var c: C? + + init(row: Row) { + a = A(row: row) + b = row["b"] + c = row["c"] + } +} + +/// Test support for FetchableRecord records +class AssociationHasOneThroughFetchableRecordTests: GRDBTestCase { + + override func setup(_ dbWriter: DatabaseWriter) throws { + try dbWriter.write { db in + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + t.column("name", .text) + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + t.column("cId").references("c") + t.column("name", .text) + } + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + t.column("name", .text) + } + + try C(id: 1, name: "c1").insert(db) + try B(id: 1, cId: 1, name: "b1").insert(db) + try B(id: 2, cId: nil, name: "b2").insert(db) + try A(id: 1, bId: 1, name: "a1").insert(db) + try A(id: 2, bId: 2, name: "a2").insert(db) + try A(id: 3, bId: nil, name: "a3").insert(db) + } + } + + func testIncludingRequired() throws { + let dbQueue = try makeDatabaseQueue() + let request = A.including(required: A.c).order(sql: "a.id") + let records = try dbQueue.inDatabase { try AWithRequiredC.fetchAll($0, request) } + + XCTAssertEqual(records.count, 1) + + XCTAssertEqual(records[0].a.id, 1) + XCTAssertEqual(records[0].a.bId, 1) + XCTAssertEqual(records[0].a.name, "a1") + XCTAssertEqual(records[0].c.id, 1) + XCTAssertEqual(records[0].c.name, "c1") + } + + func testIncludingOptional() throws { + let dbQueue = try makeDatabaseQueue() + let request = A.including(optional: A.c).order(sql: "a.id") + let records = try dbQueue.inDatabase { try AWithOptionalC.fetchAll($0, request) } + + XCTAssertEqual(records.count, 3) + + XCTAssertEqual(records[0].a.id, 1) + XCTAssertEqual(records[0].a.bId, 1) + XCTAssertEqual(records[0].a.name, "a1") + XCTAssertEqual(records[0].c!.id, 1) + XCTAssertEqual(records[0].c!.name, "c1") + + XCTAssertEqual(records[1].a.id, 2) + XCTAssertEqual(records[1].a.bId, 2) + XCTAssertEqual(records[1].a.name, "a2") + XCTAssertNil(records[1].c) + + XCTAssertEqual(records[2].a.id, 3) + XCTAssertNil(records[2].a.bId) + XCTAssertEqual(records[2].a.name, "a3") + XCTAssertNil(records[2].c) + } + + func testJoiningRequired() throws { + let dbQueue = try makeDatabaseQueue() + let request = A.joining(required: A.c).order(sql: "a.id") + let records = try dbQueue.inDatabase { try A.fetchAll($0, request) } + + XCTAssertEqual(records.count, 1) + + XCTAssertEqual(records[0].id, 1) + XCTAssertEqual(records[0].bId, 1) + XCTAssertEqual(records[0].name, "a1") + } + + func testJoiningOptional() throws { + let dbQueue = try makeDatabaseQueue() + let request = A.joining(optional: A.c).order(sql: "a.id") + let records = try dbQueue.inDatabase { try A.fetchAll($0, request) } + + XCTAssertEqual(records.count, 3) + + XCTAssertEqual(records[0].id, 1) + XCTAssertEqual(records[0].bId, 1) + XCTAssertEqual(records[0].name, "a1") + + XCTAssertEqual(records[1].id, 2) + XCTAssertEqual(records[1].bId, 2) + XCTAssertEqual(records[1].name, "a2") + + XCTAssertEqual(records[2].id, 3) + XCTAssertNil(records[2].bId) + XCTAssertEqual(records[2].name, "a3") + } + + func testIncludingOptionalIncludingRequiredPivot() throws { + let dbQueue = try makeDatabaseQueue() + let request = A + .including(optional: A.c) + .including(required: A.b) + .order(sql: "a.id") + let records = try dbQueue.inDatabase { try AWithRequiredBAndOptionalC.fetchAll($0, request) } + + XCTAssertEqual(records.count, 2) + + XCTAssertEqual(records[0].a.id, 1) + XCTAssertEqual(records[0].a.bId, 1) + XCTAssertEqual(records[0].a.name, "a1") + XCTAssertEqual(records[0].b.id, 1) + XCTAssertEqual(records[0].b.name, "b1") + XCTAssertEqual(records[0].c!.id, 1) + XCTAssertEqual(records[0].c!.name, "c1") + + XCTAssertEqual(records[1].a.id, 2) + XCTAssertEqual(records[1].a.bId, 2) + XCTAssertEqual(records[1].a.name, "a2") + XCTAssertEqual(records[1].b.id, 2) + XCTAssertEqual(records[1].b.name, "b2") + XCTAssertNil(records[1].c) + } +} diff --git a/Tests/GRDBTests/AssociationHasOneThroughRowScopeTests.swift b/Tests/GRDBTests/AssociationHasOneThroughRowScopeTests.swift new file mode 100644 index 000000000..515ca5b1e --- /dev/null +++ b/Tests/GRDBTests/AssociationHasOneThroughRowScopeTests.swift @@ -0,0 +1,191 @@ +import XCTest +#if GRDBCUSTOMSQLITE + import GRDBCustomSQLite +#else + import GRDB +#endif + +private struct A: Codable, FetchableRecord, PersistableRecord { + static let defaultB = belongsTo(B.self) + static let defaultC = hasOne(C.self, through: defaultB, using: B.c) + static let customC1 = hasOne(C.self, through: defaultB.forKey("customB"), using: B.c) + static let customC2 = hasOne(C.self, through: defaultB, using: B.c).forKey("customC2") + static let customC3 = hasOne(C.self, through: defaultB, using: B.c.forKey("customC3")) + var id: Int64 + var bId: Int64? + var name: String +} + +private struct B: Codable, FetchableRecord, PersistableRecord { + static let c = belongsTo(C.self) + var id: Int64 + var cId: Int64? + var name: String +} + +private struct C: Codable, FetchableRecord, PersistableRecord { + var id: Int64 + var name: String +} + +/// Test row scopes +class AssociationHasOneThroughRowscopeTests: GRDBTestCase { + + override func setup(_ dbWriter: DatabaseWriter) throws { + try dbWriter.write { db in + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + t.column("name", .text) + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + t.column("cId").references("c") + t.column("name", .text) + } + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + t.column("name", .text) + } + + try C(id: 1, name: "c1").insert(db) + try B(id: 1, cId: 1, name: "b1").insert(db) + try B(id: 2, cId: nil, name: "b2").insert(db) + try A(id: 1, bId: 1, name: "a1").insert(db) + try A(id: 2, bId: 2, name: "a2").insert(db) + try A(id: 3, bId: nil, name: "a3").insert(db) + } + } + + func testJoiningDoesNotUseAnyRowAdapter() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request = A.joining(required: A.defaultC) + let (_, adapter) = try request.prepare(db, forSingleResult: false) + XCTAssertNil(adapter) + } + } + + func testDefaultScopeIncludingRequired() throws { + let dbQueue = try makeDatabaseQueue() + let request = A.including(required: A.defaultC).order(sql: "a.id") + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } + XCTAssertEqual(rows.count, 1) + XCTAssertEqual(rows[0].unscoped, ["id":1, "bId":1, "name":"a1"]) + XCTAssertEqual(Set(rows[0].scopes.names), ["b"]) + XCTAssertEqual(rows[0].scopes["b"]!.unscoped, [:]) + XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes.names), ["c"]) + XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"]!.unscoped, ["id":1, "name":"c1"]) + } + + func testDefaultScopeIncludingOptional() throws { + let dbQueue = try makeDatabaseQueue() + let request = A.including(optional: A.defaultC).order(sql: "a.id") + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } + + XCTAssertEqual(rows.count, 3) + + XCTAssertEqual(rows[0].unscoped, ["id":1, "bId":1, "name":"a1"]) + XCTAssertEqual(Set(rows[0].scopes.names), ["b"]) + XCTAssertEqual(rows[0].scopes["b"]!.unscoped, [:]) + XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes.names), ["c"]) + XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"]!.unscoped, ["id":1, "name":"c1"]) + + XCTAssertEqual(rows[1].unscoped, ["id":2, "bId":2, "name":"a2"]) + XCTAssertEqual(Set(rows[1].scopes.names), ["b"]) + XCTAssertEqual(rows[1].scopes["b"]!.unscoped, [:]) + XCTAssertEqual(Set(rows[1].scopes["b"]!.scopes.names), ["c"]) + XCTAssertEqual(rows[1].scopes["b"]!.scopes["c"]!.unscoped, ["id":nil, "name":nil]) + + XCTAssertEqual(rows[2].unscoped, ["id":3, "bId":nil, "name":"a3"]) + XCTAssertEqual(Set(rows[2].scopes.names), ["b"]) + XCTAssertEqual(rows[2].scopes["b"]!.unscoped, [:]) + XCTAssertEqual(Set(rows[2].scopes["b"]!.scopes.names), ["c"]) + XCTAssertEqual(rows[2].scopes["b"]!.scopes["c"]!.unscoped, ["id":nil, "name":nil]) + } + + func testDefaultScopeJoiningRequired() throws { + let dbQueue = try makeDatabaseQueue() + let request = A.joining(required: A.defaultC).order(sql: "a.id") + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } + XCTAssertEqual(rows.count, 1) + XCTAssertEqual(rows[0].unscoped, ["id":1, "bId":1, "name":"a1"]) + XCTAssertTrue(rows[0].scopes.names.isEmpty) + } + + func testDefaultScopeJoiningOptional() throws { + let dbQueue = try makeDatabaseQueue() + let request = A.joining(optional: A.defaultC).order(sql: "a.id") + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } + + XCTAssertEqual(rows.count, 3) + + XCTAssertEqual(rows[0].unscoped, ["id":1, "bId":1, "name":"a1"]) + XCTAssertTrue(rows[0].scopes.names.isEmpty) + + XCTAssertEqual(rows[1].unscoped, ["id":2, "bId":2, "name":"a2"]) + XCTAssertTrue(rows[1].scopes.names.isEmpty) + + XCTAssertEqual(rows[2].unscoped, ["id":3, "bId":nil, "name":"a3"]) + XCTAssertTrue(rows[2].scopes.names.isEmpty) + } + + func testCustomC1() throws { + let dbQueue = try makeDatabaseQueue() + let request = A.including(required: A.customC1).order(sql: "a.id") + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } + XCTAssertEqual(rows.count, 1) + XCTAssertEqual(rows[0].unscoped, ["id":1, "bId":1, "name":"a1"]) + XCTAssertEqual(Set(rows[0].scopes.names), ["customB"]) + XCTAssertEqual(rows[0].scopes["customB"]!.unscoped, [:]) + XCTAssertEqual(Set(rows[0].scopes["customB"]!.scopes.names), ["c"]) + XCTAssertEqual(rows[0].scopes["customB"]!.scopes["c"]!.unscoped, ["id":1, "name":"c1"]) + } + + func testCustomC2() throws { + let dbQueue = try makeDatabaseQueue() + let request = A.including(required: A.customC2).order(sql: "a.id") + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } + XCTAssertEqual(rows.count, 1) + XCTAssertEqual(rows[0].unscoped, ["id":1, "bId":1, "name":"a1"]) + XCTAssertEqual(Set(rows[0].scopes.names), ["b"]) + XCTAssertEqual(rows[0].scopes["b"]!.unscoped, [:]) + XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes.names), ["customC2"]) + XCTAssertEqual(rows[0].scopes["b"]!.scopes["customC2"]!.unscoped, ["id":1, "name":"c1"]) + } + + func testCustomC3() throws { + let dbQueue = try makeDatabaseQueue() + let request = A.including(required: A.customC3).order(sql: "a.id") + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } + XCTAssertEqual(rows.count, 1) + XCTAssertEqual(rows[0].unscoped, ["id":1, "bId":1, "name":"a1"]) + XCTAssertEqual(Set(rows[0].scopes.names), ["b"]) + XCTAssertEqual(rows[0].scopes["b"]!.unscoped, [:]) + XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes.names), ["customC3"]) + XCTAssertEqual(rows[0].scopes["b"]!.scopes["customC3"]!.unscoped, ["id":1, "name":"c1"]) + } + + func testDefaultScopeIncludingOptionalIncludingRequiredPivot() throws { + let dbQueue = try makeDatabaseQueue() + let request = A + .including(optional: A.defaultC) + .including(required: A.defaultB) + .order(sql: "a.id") + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } + + XCTAssertEqual(rows.count, 2) + + XCTAssertEqual(rows[0].unscoped, ["id":1, "bId":1, "name":"a1"]) + XCTAssertEqual(Set(rows[0].scopes.names), ["b"]) + XCTAssertEqual(rows[0].scopes["b"]!.unscoped, ["id":1, "cId":1, "name":"b1"]) + XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes.names), ["c"]) + XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"]!.unscoped, ["id":1, "name":"c1"]) + + XCTAssertEqual(rows[1].unscoped, ["id":2, "bId":2, "name":"a2"]) + XCTAssertEqual(Set(rows[1].scopes.names), ["b"]) + XCTAssertEqual(rows[1].scopes["b"]!.unscoped, ["id":2, "cId":nil, "name":"b2"]) + XCTAssertEqual(Set(rows[1].scopes["b"]!.scopes.names), ["c"]) + XCTAssertEqual(rows[1].scopes["b"]!.scopes["c"]!.unscoped, ["id":nil, "name":nil]) + } +} diff --git a/Tests/GRDBTests/AssociationHasOneThroughSQLDerivationTests.swift b/Tests/GRDBTests/AssociationHasOneThroughSQLDerivationTests.swift new file mode 100644 index 000000000..9b11a5c92 --- /dev/null +++ b/Tests/GRDBTests/AssociationHasOneThroughSQLDerivationTests.swift @@ -0,0 +1,262 @@ +import XCTest +#if GRDBCUSTOMSQLITE + import GRDBCustomSQLite +#else + import GRDB +#endif + +private struct A: TableRecord { + static let b = belongsTo(B.self) + static let c = hasOne(C.self, through: b, using: B.c) + static let restrictedC = hasOne(RestrictedC.self, through: b, using: B.restrictedC) + static let extendedC = hasOne(ExtendedC.self, through: b, using: B.extendedC) +} + +private struct B: TableRecord { + static let c = belongsTo(C.self) + static let restrictedC = belongsTo(RestrictedC.self) + static let extendedC = belongsTo(ExtendedC.self) +} + +private struct C: TableRecord { +} + +private struct RestrictedC : TableRecord { + static let databaseTableName = "c" + static let databaseSelection: [SQLSelectable] = [Column("name")] +} + +private struct ExtendedC : TableRecord { + static let databaseTableName = "c" + static let databaseSelection: [SQLSelectable] = [AllColumns(), Column.rowID] +} + +/// Test SQL generation +class AssociationHasOneThroughSQLDerivationTests: GRDBTestCase { + + override func setup(_ dbWriter: DatabaseWriter) throws { + try dbWriter.write { db in + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + t.column("name", .text) + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + t.column("cId").references("c") + } + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + } + } + } + + func testDefaultSelection() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try assertEqualSQL(db, A.including(required: A.c), """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON ("c"."id" = "b"."cId") + """) + try assertEqualSQL(db, A.including(required: A.restrictedC), """ + SELECT "a".*, "c"."name" \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON ("c"."id" = "b"."cId") + """) + try assertEqualSQL(db, A.including(required: A.extendedC), """ + SELECT "a".*, "c".*, "c"."rowid" \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON ("c"."id" = "b"."cId") + """) + } + } + + func testCustomSelection() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + do { + let request = A.including(required: A.c + .select(Column("name"))) + try assertEqualSQL(db, request, """ + SELECT "a".*, "c"."name" \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON ("c"."id" = "b"."cId") + """) + } + do { + let request = A.including(required: A.c + .select( + AllColumns(), + Column.rowID)) + try assertEqualSQL(db, request, """ + SELECT "a".*, "c".*, "c"."rowid" \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON ("c"."id" = "b"."cId") + """) + } + do { + let aAlias = TableAlias() + let request = A + .aliased(aAlias) + .including(required: A.c + .select( + Column("name"), + (Column("id") + aAlias[Column("id")]).aliased("foo"))) + try assertEqualSQL(db, request, """ + SELECT "a".*, "c"."name", ("c"."id" + "a"."id") AS "foo" \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON ("c"."id" = "b"."cId") + """) + } + } + } + + func testFilteredAssociationImpactsJoinOnClause() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + do { + let request = A.including(required: A.c.filter(Column("name") != nil)) + try assertEqualSQL(db, request, """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON (("c"."id" = "b"."cId") AND ("c"."name" IS NOT NULL)) + """) + } + do { + let request = A.including(required: A.c.filter(key: 1)) + try assertEqualSQL(db, request, """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON (("c"."id" = "b"."cId") AND ("c"."id" = 1)) + """) + } + do { + let request = A.including(required: A.c.filter(keys: [1, 2, 3])) + try assertEqualSQL(db, request, """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON (("c"."id" = "b"."cId") AND ("c"."id" IN (1, 2, 3))) + """) + } + do { + let request = A.including(required: A.c.filter(key: ["id": 1])) + try assertEqualSQL(db, request, """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON (("c"."id" = "b"."cId") AND ("c"."id" = 1)) + """) + } + do { + let request = A.including(required: A.c.filter(keys: [["id": 1], ["id": 2]])) + try assertEqualSQL(db, request, """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON (("c"."id" = "b"."cId") AND (("c"."id" = 1) OR ("c"."id" = 2))) + """) + } + do { + let cAlias = TableAlias(name: "customC") + let request = A.including(required: A.c + .aliased(cAlias) + .filter(sql: "customC.name = ?", arguments: ["foo"])) + try assertEqualSQL(db, request, """ + SELECT "a".*, "customC".* \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" "customC" ON (("customC"."id" = "b"."cId") AND (customC.name = 'foo')) + """) + } + } + } + + func testFilterAssociationInWhereClause() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let cAlias = TableAlias() + let request = A + .including(required: A.c.aliased(cAlias)) + .filter(cAlias[Column("name")] != nil) + try assertEqualSQL(db, request, """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON ("c"."id" = "b"."cId") \ + WHERE ("c"."name" IS NOT NULL) + """) + } + } + + func testOrderAssociation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try assertEqualSQL(db, A.including(required: A.c.order(Column("name"))), """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON ("c"."id" = "b"."cId") \ + ORDER BY "c"."name" + """) + try assertEqualSQL(db, A.including(required: A.c.orderByPrimaryKey()), """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON ("c"."id" = "b"."cId") \ + ORDER BY "c"."id" + """) + try assertEqualSQL(db, A.including(required: A.c.orderByPrimaryKey()).orderByPrimaryKey(), """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON ("c"."id" = "b"."cId") \ + ORDER BY "a"."id", "c"."id" + """) + try assertEqualSQL(db, A.including(required: A.c.orderByPrimaryKey().reversed()).orderByPrimaryKey(), """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON ("c"."id" = "b"."cId") \ + ORDER BY "a"."id", "c"."id" DESC + """) + try assertEqualSQL(db, A.including(required: A.c.order(Column("name"))).reversed(), """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON ("c"."id" = "b"."cId") \ + ORDER BY "c"."name" DESC + """) + try assertEqualSQL(db, A.including(required: A.c.orderByPrimaryKey()).reversed(), """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON ("c"."id" = "b"."cId") \ + ORDER BY "c"."id" DESC + """) + try assertEqualSQL(db, A.including(required: A.c.orderByPrimaryKey()).orderByPrimaryKey().reversed(), """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON ("c"."id" = "b"."cId") \ + ORDER BY "a"."id" DESC, "c"."id" DESC + """) + try assertEqualSQL(db, A.including(required: A.c.orderByPrimaryKey().reversed()).orderByPrimaryKey().reversed(), """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON ("c"."id" = "b"."cId") \ + ORDER BY "a"."id" DESC, "c"."id" + """) + } + } +} diff --git a/Tests/GRDBTests/AssociationHasOneThroughSQLTests.swift b/Tests/GRDBTests/AssociationHasOneThroughSQLTests.swift new file mode 100644 index 000000000..7813b83ee --- /dev/null +++ b/Tests/GRDBTests/AssociationHasOneThroughSQLTests.swift @@ -0,0 +1,1366 @@ +import XCTest +#if GRDBCUSTOMSQLITE + import GRDBCustomSQLite +#else + import GRDB +#endif + +/// Test SQL generation + +class AssociationHasOneThroughSQLTests: GRDBTestCase { + + // MARK: - Two Steps + + func testBelongsToBelongsTo() throws { + struct A: TableRecord, EncodableRecord { + static let b = belongsTo(B.self) + static let c = hasOne(C.self, through: b, using: B.c) + func encode(to container: inout PersistenceContainer) { + container["bId"] = 1 + } + } + struct B: TableRecord { + static let c = belongsTo(C.self) + } + struct C: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + t.column("cId").references("c") + } + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + } + + try testHasOneWithTwoSteps( + db, ab: A.b, ac: A.c, + bCondition: "(\"b\".\"id\" = \"a\".\"bId\")", + cCondition: "(\"c\".\"id\" = \"b\".\"cId\")") + + try assertEqualSQL(db, A().request(for: A.c), """ + SELECT "c".* FROM "c" \ + JOIN "b" ON (("b"."cId" = "c"."id") AND ("b"."id" = 1)) + """) + } + } + + func testBelongsToHasOne() throws { + struct A: TableRecord, EncodableRecord { + static let b = belongsTo(B.self) + static let c = hasOne(C.self, through: b, using: B.c) + func encode(to container: inout PersistenceContainer) { + container["bId"] = 1 + } + } + struct B: TableRecord { + static let c = hasOne(C.self) + } + struct C: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + } + + try testHasOneWithTwoSteps( + db, ab: A.b, ac: A.c, + bCondition: "(\"b\".\"id\" = \"a\".\"bId\")", + cCondition: "(\"c\".\"bId\" = \"b\".\"id\")") + + try assertEqualSQL(db, A().request(for: A.c), """ + SELECT "c".* FROM "c" \ + JOIN "b" ON (("b"."id" = "c"."bId") AND ("b"."id" = 1)) + """) + } + } + + func testHasOneBelongsTo() throws { + struct A: TableRecord, EncodableRecord { + static let b = hasOne(B.self) + static let c = hasOne(C.self, through: b, using: B.c) + func encode(to container: inout PersistenceContainer) { + container["id"] = 1 + } + } + struct B: TableRecord { + static let c = belongsTo(C.self) + } + struct C: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + t.column("cId").references("c") + t.column("aId").references("a") + } + + try testHasOneWithTwoSteps( + db, ab: A.b, ac: A.c, + bCondition: "(\"b\".\"aId\" = \"a\".\"id\")", + cCondition: "(\"c\".\"id\" = \"b\".\"cId\")") + + try assertEqualSQL(db, A().request(for: A.c), """ + SELECT "c".* FROM "c" \ + JOIN "b" ON (("b"."cId" = "c"."id") AND ("b"."aId" = 1)) + """) + } + } + + func testHasOneHasOne() throws { + struct A: TableRecord, EncodableRecord { + static let b = hasOne(B.self) + static let c = hasOne(C.self, through: b, using: B.c) + func encode(to container: inout PersistenceContainer) { + container["id"] = 1 + } + } + struct B: TableRecord { + static let c = hasOne(C.self) + } + struct C: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + t.column("aId").references("a") + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + } + + try testHasOneWithTwoSteps( + db, ab: A.b, ac: A.c, + bCondition: "(\"b\".\"aId\" = \"a\".\"id\")", + cCondition: "(\"c\".\"bId\" = \"b\".\"id\")") + + try assertEqualSQL(db, A().request(for: A.c), """ + SELECT "c".* FROM "c" \ + JOIN "b" ON (("b"."id" = "c"."bId") AND ("b"."aId" = 1)) + """) + } + } + + private func testHasOneWithTwoSteps( + _ db: Database, + ab: BAssociation, + ac: CAssociation, + bCondition: String, + cCondition: String) throws + where BAssociation: AssociationToOne, + CAssociation: AssociationToOne, + BAssociation.OriginRowDecoder == CAssociation.OriginRowDecoder, + BAssociation.OriginRowDecoder: TableRecord + { + let A = BAssociation.OriginRowDecoder.self + + do { + try assertEqualSQL(db, A.including(optional: ac), """ + SELECT "a".*, "c".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.including(required: ac), """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.joining(optional: ac), """ + SELECT "a".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.joining(required: ac), """ + SELECT "a".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + } + do { + try assertEqualSQL(db, A.including(optional: ac).including(optional: ab), """ + SELECT "a".*, "b".*, "c".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.including(optional: ac).including(required: ab), """ + SELECT "a".*, "b".*, "c".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.including(optional: ac).joining(optional: ab), """ + SELECT "a".*, "c".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.including(optional: ac).joining(required: ab), """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + } + do { + try assertEqualSQL(db, A.including(required: ac).including(optional: ab), """ + SELECT "a".*, "b".*, "c".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.including(required: ac).including(required: ab), """ + SELECT "a".*, "b".*, "c".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.including(required: ac).joining(optional: ab), """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.including(required: ac).joining(required: ab), """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + } + do { + try assertEqualSQL(db, A.joining(optional: ac).including(optional: ab), """ + SELECT "a".*, "b".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.joining(optional: ac).including(required: ab), """ + SELECT "a".*, "b".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.joining(optional: ac).joining(optional: ab), """ + SELECT "a".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.joining(optional: ac).joining(required: ab), """ + SELECT "a".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) + """) + } + do { + try assertEqualSQL(db, A.joining(required: ac).including(optional: ab), """ + SELECT "a".*, "b".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.joining(required: ac).including(required: ab), """ + SELECT "a".*, "b".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.joining(required: ac).joining(optional: ab), """ + SELECT "a".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + try assertEqualSQL(db, A.joining(required: ac).joining(required: ab), """ + SELECT "a".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) + """) + } + } + + // MARK: - Three Steps + + func testBelongsToBelongsToBelongsTo() throws { + struct A: TableRecord, EncodableRecord { + static let b = belongsTo(B.self) + static let c = hasOne(C.self, through: b, using: B.c) + static let dThroughC = hasOne(D.self, through: c, using: C.d) + static let dThroughB = hasOne(D.self, through: b, using: B.d) + func encode(to container: inout PersistenceContainer) { + container["bId"] = 1 + } + } + struct B: TableRecord { + static let c = belongsTo(C.self) + static let d = hasOne(D.self, through: c, using: C.d) + } + struct C: TableRecord { + static let d = belongsTo(D.self) + } + struct D: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "d") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + t.column("dId").references("d") + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + t.column("cId").references("c") + } + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + } + + try testHasOneWithThreeSteps( + db, b: A.b, c: A.c, dThroughC: A.dThroughC, dThroughB: A.dThroughB, + bCondition: "(\"b\".\"id\" = \"a\".\"bId\")", + cCondition: "(\"c\".\"id\" = \"b\".\"cId\")", + dCondition: "(\"d\".\"id\" = \"c\".\"dId\")") + + try assertEqualSQL(db, A().request(for: A.dThroughC), """ + SELECT "d".* FROM "d" \ + JOIN "c" ON ("c"."dId" = "d"."id") \ + JOIN "b" ON (("b"."cId" = "c"."id") AND ("b"."id" = 1)) + """) + try assertEqualSQL(db, A().request(for: A.dThroughB), """ + SELECT "d".* FROM "d" \ + JOIN "c" ON ("c"."dId" = "d"."id") \ + JOIN "b" ON (("b"."cId" = "c"."id") AND ("b"."id" = 1)) + """) + } + } + + func testBelongsToBelongsToHasOne() throws { + struct A: TableRecord, EncodableRecord { + static let b = belongsTo(B.self) + static let c = hasOne(C.self, through: b, using: B.c) + static let dThroughC = hasOne(D.self, through: c, using: C.d) + static let dThroughB = hasOne(D.self, through: b, using: B.d) + func encode(to container: inout PersistenceContainer) { + container["bId"] = 1 + } + } + struct B: TableRecord { + static let c = belongsTo(C.self) + static let d = hasOne(D.self, through: c, using: C.d) + } + struct C: TableRecord { + static let d = hasOne(D.self) + } + struct D: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "d") { t in + t.autoIncrementedPrimaryKey("id") + t.column("cId").references("c") + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + t.column("cId").references("c") + } + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + } + + try testHasOneWithThreeSteps( + db, b: A.b, c: A.c, dThroughC: A.dThroughC, dThroughB: A.dThroughB, + bCondition: "(\"b\".\"id\" = \"a\".\"bId\")", + cCondition: "(\"c\".\"id\" = \"b\".\"cId\")", + dCondition: "(\"d\".\"cId\" = \"c\".\"id\")") + + try assertEqualSQL(db, A().request(for: A.dThroughC), """ + SELECT "d".* FROM "d" \ + JOIN "c" ON ("c"."id" = "d"."cId") \ + JOIN "b" ON (("b"."cId" = "c"."id") AND ("b"."id" = 1)) + """) + try assertEqualSQL(db, A().request(for: A.dThroughB), """ + SELECT "d".* FROM "d" \ + JOIN "c" ON ("c"."id" = "d"."cId") \ + JOIN "b" ON (("b"."cId" = "c"."id") AND ("b"."id" = 1)) + """) + } + } + + func testBelongsToHasOneBelongsTo() throws { + struct A: TableRecord, EncodableRecord { + static let b = belongsTo(B.self) + static let c = hasOne(C.self, through: b, using: B.c) + static let dThroughC = hasOne(D.self, through: c, using: C.d) + static let dThroughB = hasOne(D.self, through: b, using: B.d) + func encode(to container: inout PersistenceContainer) { + container["bId"] = 1 + } + } + struct B: TableRecord { + static let c = hasOne(C.self) + static let d = hasOne(D.self, through: c, using: C.d) + } + struct C: TableRecord { + static let d = belongsTo(D.self) + } + struct D: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "d") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + t.column("dId").references("d") + } + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + } + + try testHasOneWithThreeSteps( + db, b: A.b, c: A.c, dThroughC: A.dThroughC, dThroughB: A.dThroughB, + bCondition: "(\"b\".\"id\" = \"a\".\"bId\")", + cCondition: "(\"c\".\"bId\" = \"b\".\"id\")", + dCondition: "(\"d\".\"id\" = \"c\".\"dId\")") + + try assertEqualSQL(db, A().request(for: A.dThroughC), """ + SELECT "d".* FROM "d" \ + JOIN "c" ON ("c"."dId" = "d"."id") \ + JOIN "b" ON (("b"."id" = "c"."bId") AND ("b"."id" = 1)) + """) + try assertEqualSQL(db, A().request(for: A.dThroughB), """ + SELECT "d".* FROM "d" \ + JOIN "c" ON ("c"."dId" = "d"."id") \ + JOIN "b" ON (("b"."id" = "c"."bId") AND ("b"."id" = 1)) + """) + } + } + + func testBelongsToHasOneHasOne() throws { + struct A: TableRecord, EncodableRecord { + static let b = belongsTo(B.self) + static let c = hasOne(C.self, through: b, using: B.c) + static let dThroughC = hasOne(D.self, through: c, using: C.d) + static let dThroughB = hasOne(D.self, through: b, using: B.d) + func encode(to container: inout PersistenceContainer) { + container["bId"] = 1 + } + } + struct B: TableRecord { + static let c = hasOne(C.self) + static let d = hasOne(D.self, through: c, using: C.d) + } + struct C: TableRecord { + static let d = hasOne(D.self) + } + struct D: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + } + try db.create(table: "d") { t in + t.autoIncrementedPrimaryKey("id") + t.column("cId").references("c") + } + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + } + + try testHasOneWithThreeSteps( + db, b: A.b, c: A.c, dThroughC: A.dThroughC, dThroughB: A.dThroughB, + bCondition: "(\"b\".\"id\" = \"a\".\"bId\")", + cCondition: "(\"c\".\"bId\" = \"b\".\"id\")", + dCondition: "(\"d\".\"cId\" = \"c\".\"id\")") + + try assertEqualSQL(db, A().request(for: A.dThroughC), """ + SELECT "d".* FROM "d" \ + JOIN "c" ON ("c"."id" = "d"."cId") \ + JOIN "b" ON (("b"."id" = "c"."bId") AND ("b"."id" = 1)) + """) + try assertEqualSQL(db, A().request(for: A.dThroughB), """ + SELECT "d".* FROM "d" \ + JOIN "c" ON ("c"."id" = "d"."cId") \ + JOIN "b" ON (("b"."id" = "c"."bId") AND ("b"."id" = 1)) + """) + } + } + + func testHasOneBelongsToBelongsTo() throws { + struct A: TableRecord, EncodableRecord { + static let b = hasOne(B.self) + static let c = hasOne(C.self, through: b, using: B.c) + static let dThroughC = hasOne(D.self, through: c, using: C.d) + static let dThroughB = hasOne(D.self, through: b, using: B.d) + func encode(to container: inout PersistenceContainer) { + container["id"] = 1 + } + } + struct B: TableRecord { + static let c = belongsTo(C.self) + static let d = hasOne(D.self, through: c, using: C.d) + } + struct C: TableRecord { + static let d = belongsTo(D.self) + } + struct D: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "d") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + t.column("dId").references("d") + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + t.column("aId").references("a") + t.column("cId").references("c") + } + + try testHasOneWithThreeSteps( + db, b: A.b, c: A.c, dThroughC: A.dThroughC, dThroughB: A.dThroughB, + bCondition: "(\"b\".\"aId\" = \"a\".\"id\")", + cCondition: "(\"c\".\"id\" = \"b\".\"cId\")", + dCondition: "(\"d\".\"id\" = \"c\".\"dId\")") + + try assertEqualSQL(db, A().request(for: A.dThroughC), """ + SELECT "d".* FROM "d" \ + JOIN "c" ON ("c"."dId" = "d"."id") \ + JOIN "b" ON (("b"."cId" = "c"."id") AND ("b"."aId" = 1)) + """) + try assertEqualSQL(db, A().request(for: A.dThroughB), """ + SELECT "d".* FROM "d" \ + JOIN "c" ON ("c"."dId" = "d"."id") \ + JOIN "b" ON (("b"."cId" = "c"."id") AND ("b"."aId" = 1)) + """) + } + } + + func testHasOneBelongsToHasOne() throws { + struct A: TableRecord, EncodableRecord { + static let b = hasOne(B.self) + static let c = hasOne(C.self, through: b, using: B.c) + static let dThroughC = hasOne(D.self, through: c, using: C.d) + static let dThroughB = hasOne(D.self, through: b, using: B.d) + func encode(to container: inout PersistenceContainer) { + container["id"] = 1 + } + } + struct B: TableRecord { + static let c = belongsTo(C.self) + static let d = hasOne(D.self, through: c, using: C.d) + } + struct C: TableRecord { + static let d = hasOne(D.self) + } + struct D: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "d") { t in + t.autoIncrementedPrimaryKey("id") + t.column("cId").references("c") + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + t.column("aId").references("a") + t.column("cId").references("c") + } + + try testHasOneWithThreeSteps( + db, b: A.b, c: A.c, dThroughC: A.dThroughC, dThroughB: A.dThroughB, + bCondition: "(\"b\".\"aId\" = \"a\".\"id\")", + cCondition: "(\"c\".\"id\" = \"b\".\"cId\")", + dCondition: "(\"d\".\"cId\" = \"c\".\"id\")") + + try assertEqualSQL(db, A().request(for: A.dThroughC), """ + SELECT "d".* FROM "d" \ + JOIN "c" ON ("c"."id" = "d"."cId") \ + JOIN "b" ON (("b"."cId" = "c"."id") AND ("b"."aId" = 1)) + """) + try assertEqualSQL(db, A().request(for: A.dThroughB), """ + SELECT "d".* FROM "d" \ + JOIN "c" ON ("c"."id" = "d"."cId") \ + JOIN "b" ON (("b"."cId" = "c"."id") AND ("b"."aId" = 1)) + """) + } + } + + func testHasOneHasOneBelongsTo() throws { + struct A: TableRecord, EncodableRecord { + static let b = hasOne(B.self) + static let c = hasOne(C.self, through: b, using: B.c) + static let dThroughC = hasOne(D.self, through: c, using: C.d) + static let dThroughB = hasOne(D.self, through: b, using: B.d) + func encode(to container: inout PersistenceContainer) { + container["id"] = 1 + } + } + struct B: TableRecord { + static let c = hasOne(C.self) + static let d = hasOne(D.self, through: c, using: C.d) + } + struct C: TableRecord { + static let d = belongsTo(D.self) + } + struct D: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "d") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + t.column("aId").references("a") + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + t.column("dId").references("d") + } + + try testHasOneWithThreeSteps( + db, b: A.b, c: A.c, dThroughC: A.dThroughC, dThroughB: A.dThroughB, + bCondition: "(\"b\".\"aId\" = \"a\".\"id\")", + cCondition: "(\"c\".\"bId\" = \"b\".\"id\")", + dCondition: "(\"d\".\"id\" = \"c\".\"dId\")") + + try assertEqualSQL(db, A().request(for: A.dThroughC), """ + SELECT "d".* FROM "d" \ + JOIN "c" ON ("c"."dId" = "d"."id") \ + JOIN "b" ON (("b"."id" = "c"."bId") AND ("b"."aId" = 1)) + """) + try assertEqualSQL(db, A().request(for: A.dThroughB), """ + SELECT "d".* FROM "d" \ + JOIN "c" ON ("c"."dId" = "d"."id") \ + JOIN "b" ON (("b"."id" = "c"."bId") AND ("b"."aId" = 1)) + """) + } + } + + func testHasOneHasOneHasOne() throws { + struct A: TableRecord, EncodableRecord { + static let b = hasOne(B.self) + static let c = hasOne(C.self, through: b, using: B.c) + static let dThroughC = hasOne(D.self, through: c, using: C.d) + static let dThroughB = hasOne(D.self, through: b, using: B.d) + func encode(to container: inout PersistenceContainer) { + container["id"] = 1 + } + } + struct B: TableRecord { + static let c = hasOne(C.self) + static let d = hasOne(D.self, through: c, using: C.d) + } + struct C: TableRecord { + static let d = hasOne(D.self) + } + struct D: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + t.column("aId").references("a") + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + } + try db.create(table: "d") { t in + t.autoIncrementedPrimaryKey("id") + t.column("cId").references("c") + } + + try testHasOneWithThreeSteps( + db, b: A.b, c: A.c, dThroughC: A.dThroughC, dThroughB: A.dThroughB, + bCondition: "(\"b\".\"aId\" = \"a\".\"id\")", + cCondition: "(\"c\".\"bId\" = \"b\".\"id\")", + dCondition: "(\"d\".\"cId\" = \"c\".\"id\")") + + try assertEqualSQL(db, A().request(for: A.dThroughC), """ + SELECT "d".* FROM "d" \ + JOIN "c" ON ("c"."id" = "d"."cId") \ + JOIN "b" ON (("b"."id" = "c"."bId") AND ("b"."aId" = 1)) + """) + try assertEqualSQL(db, A().request(for: A.dThroughB), """ + SELECT "d".* FROM "d" \ + JOIN "c" ON ("c"."id" = "d"."cId") \ + JOIN "b" ON (("b"."id" = "c"."bId") AND ("b"."aId" = 1)) + """) + } + } + + private func testHasOneWithThreeSteps( + _ db: Database, + b: BAssociation, + c: CAssociation, + dThroughC: DCAssociation, + dThroughB: DBAssociation, + bCondition: String, + cCondition: String, + dCondition: String) throws + where BAssociation: AssociationToOne, + CAssociation: AssociationToOne, + DCAssociation: AssociationToOne, + DBAssociation: AssociationToOne, + BAssociation.OriginRowDecoder == CAssociation.OriginRowDecoder, + BAssociation.OriginRowDecoder == DCAssociation.OriginRowDecoder, + BAssociation.OriginRowDecoder == DBAssociation.OriginRowDecoder, + BAssociation.OriginRowDecoder: TableRecord + { + let A = CAssociation.OriginRowDecoder.self + + do { + for request in [ + A.including(optional: dThroughC), + A.including(optional: dThroughB)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "d".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) \ + LEFT JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.including(required: dThroughC), + A.including(required: dThroughB)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "d".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.joining(optional: dThroughC), + A.joining(optional: dThroughB)] + { + try assertEqualSQL(db, request, """ + SELECT "a".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) \ + LEFT JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.joining(required: dThroughC), + A.joining(required: dThroughB)] + { + try assertEqualSQL(db, request, """ + SELECT "a".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + JOIN "d" ON \(dCondition) + """) + } + } + + do { + do { + for request in [ + A.including(optional: dThroughC).including(optional: b), + A.including(optional: dThroughB).including(optional: b)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "b".*, "d".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) \ + LEFT JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.including(required: dThroughC).including(optional: b), + A.including(required: dThroughB).including(optional: b)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "b".*, "d".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.joining(optional: dThroughC).including(optional: b), + A.joining(optional: dThroughB).including(optional: b)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "b".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) \ + LEFT JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.joining(required: dThroughC).including(optional: b), + A.joining(required: dThroughB).including(optional: b)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "b".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + JOIN "d" ON \(dCondition) + """) + } + } + + do { + for request in [ + A.including(optional: dThroughC).including(required: b), + A.including(optional: dThroughB).including(required: b)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "b".*, "d".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) \ + LEFT JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.including(required: dThroughC).including(required: b), + A.including(required: dThroughB).including(required: b)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "b".*, "d".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.joining(optional: dThroughC).including(required: b), + A.joining(optional: dThroughB).including(required: b)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "b".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) \ + LEFT JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.joining(required: dThroughC).including(required: b), + A.joining(required: dThroughB).including(required: b)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "b".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + JOIN "d" ON \(dCondition) + """) + } + } + + do { + for request in [ + A.including(optional: dThroughC).joining(optional: b), + A.including(optional: dThroughB).joining(optional: b)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "d".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) \ + LEFT JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.including(required: dThroughC).joining(optional: b), + A.including(required: dThroughB).joining(optional: b)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "d".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.joining(optional: dThroughC).joining(optional: b), + A.joining(optional: dThroughB).joining(optional: b)] + { + try assertEqualSQL(db, request, """ + SELECT "a".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) \ + LEFT JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.joining(required: dThroughC).joining(optional: b), + A.joining(required: dThroughB).joining(optional: b)] + { + try assertEqualSQL(db, request, """ + SELECT "a".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + JOIN "d" ON \(dCondition) + """) + } + } + + do { + for request in [ + A.including(optional: dThroughC).joining(required: b), + A.including(optional: dThroughB).joining(required: b)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "d".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) \ + LEFT JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.including(required: dThroughC).joining(required: b), + A.including(required: dThroughB).joining(required: b)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "d".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.joining(optional: dThroughC).joining(required: b), + A.joining(optional: dThroughB).joining(required: b)] + { + try assertEqualSQL(db, request, """ + SELECT "a".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) \ + LEFT JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.joining(required: dThroughC).joining(required: b), + A.joining(required: dThroughB).joining(required: b)] + { + try assertEqualSQL(db, request, """ + SELECT "a".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + JOIN "d" ON \(dCondition) + """) + } + } + } + + do { + do { + for request in [ + A.including(optional: dThroughC).including(optional: c), + A.including(optional: dThroughB).including(optional: c)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "c".*, "d".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) \ + LEFT JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.including(required: dThroughC).including(optional: c), + A.including(required: dThroughB).including(optional: c)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "c".*, "d".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.joining(optional: dThroughC).including(optional: c), + A.joining(optional: dThroughB).including(optional: c)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "c".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) \ + LEFT JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.joining(required: dThroughC).including(optional: c), + A.joining(required: dThroughB).including(optional: c)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + JOIN "d" ON \(dCondition) + """) + } + } + + do { + for request in [ + A.including(optional: dThroughC).including(required: c), + A.including(optional: dThroughB).including(required: c)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "c".*, "d".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + LEFT JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.including(required: dThroughC).including(required: c), + A.including(required: dThroughB).including(required: c)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "c".*, "d".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.joining(optional: dThroughC).including(required: c), + A.joining(optional: dThroughB).including(required: c)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + LEFT JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.joining(required: dThroughC).including(required: c), + A.joining(required: dThroughB).including(required: c)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "c".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + JOIN "d" ON \(dCondition) + """) + } + } + + do { + for request in [ + A.including(optional: dThroughC).joining(optional: c), + A.including(optional: dThroughB).joining(optional: c)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "d".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) \ + LEFT JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.including(required: dThroughC).joining(optional: c), + A.including(required: dThroughB).joining(optional: c)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "d".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.joining(optional: dThroughC).joining(optional: c), + A.joining(optional: dThroughB).joining(optional: c)] + { + try assertEqualSQL(db, request, """ + SELECT "a".* \ + FROM "a" \ + LEFT JOIN "b" ON \(bCondition) \ + LEFT JOIN "c" ON \(cCondition) \ + LEFT JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.joining(required: dThroughC).joining(optional: c), + A.joining(required: dThroughB).joining(optional: c)] + { + try assertEqualSQL(db, request, """ + SELECT "a".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + JOIN "d" ON \(dCondition) + """) + } + } + + do { + for request in [ + A.including(optional: dThroughC).joining(required: c), + A.including(optional: dThroughB).joining(required: c)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "d".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + LEFT JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.including(required: dThroughC).joining(required: c), + A.including(required: dThroughB).joining(required: c)] + { + try assertEqualSQL(db, request, """ + SELECT "a".*, "d".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.joining(optional: dThroughC).joining(required: c), + A.joining(optional: dThroughB).joining(required: c)] + { + try assertEqualSQL(db, request, """ + SELECT "a".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + LEFT JOIN "d" ON \(dCondition) + """) + } + for request in [ + A.joining(required: dThroughC).joining(required: c), + A.joining(required: dThroughB).joining(required: c)] + { + try assertEqualSQL(db, request, """ + SELECT "a".* \ + FROM "a" \ + JOIN "b" ON \(bCondition) \ + JOIN "c" ON \(cCondition) \ + JOIN "d" ON \(dCondition) + """) + } + } + } + } + + // MARK: - Four Steps + + func testBelongsToBelongsToBelongsToBelongsTo() throws { + struct A: TableRecord, EncodableRecord { + static let b = belongsTo(B.self) + static let c = hasOne(C.self, through: b, using: B.c) + static let dThroughB = hasOne(D.self, through: b, using: B.d) + static let dThroughC = hasOne(D.self, through: c, using: C.d) + static let eThroughBThroughC = hasOne(E.self, through: b, using: B.eThroughC) + static let eThroughBThroughD = hasOne(E.self, through: b, using: B.eThroughD) + static let eThroughC = hasOne(E.self, through: c, using: C.e) + static let eThroughDThroughB = hasOne(E.self, through: dThroughB, using: D.e) + static let eThroughDThroughC = hasOne(E.self, through: dThroughC, using: D.e) + func encode(to container: inout PersistenceContainer) { + container["bId"] = 1 + } + } + struct B: TableRecord { + static let c = belongsTo(C.self) + static let d = hasOne(D.self, through: c, using: C.d) + static let eThroughC = hasOne(E.self, through: c, using: C.e) + static let eThroughD = hasOne(E.self, through: d, using: D.e) + } + struct C: TableRecord { + static let d = belongsTo(D.self) + static let e = hasOne(E.self, through: d, using: D.e) + } + struct D: TableRecord { + static let e = belongsTo(E.self) + } + struct E: TableRecord { + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "e") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "d") { t in + t.autoIncrementedPrimaryKey("id") + t.column("eId").references("e") + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("id") + t.column("dId").references("d") + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + t.column("cId").references("c") + } + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + t.column("bId").references("b") + } + + let associations = [ + A.eThroughBThroughC, + A.eThroughBThroughD, + A.eThroughC, + A.eThroughDThroughB, + A.eThroughDThroughC, + ] + for association in associations { + try assertEqualSQL(db, A.including(required: association), """ + SELECT "a".*, "e".* \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON ("c"."id" = "b"."cId") \ + JOIN "d" ON ("d"."id" = "c"."dId") \ + JOIN "e" ON ("e"."id" = "d"."eId") + """) + try assertEqualSQL(db, A.including(optional: association), """ + SELECT "a".*, "e".* \ + FROM "a" \ + LEFT JOIN "b" ON ("b"."id" = "a"."bId") \ + LEFT JOIN "c" ON ("c"."id" = "b"."cId") \ + LEFT JOIN "d" ON ("d"."id" = "c"."dId") \ + LEFT JOIN "e" ON ("e"."id" = "d"."eId") + """) + try assertEqualSQL(db, A.joining(required: association), """ + SELECT "a".* \ + FROM "a" \ + JOIN "b" ON ("b"."id" = "a"."bId") \ + JOIN "c" ON ("c"."id" = "b"."cId") \ + JOIN "d" ON ("d"."id" = "c"."dId") \ + JOIN "e" ON ("e"."id" = "d"."eId") + """) + try assertEqualSQL(db, A.joining(optional: association), """ + SELECT "a".* \ + FROM "a" \ + LEFT JOIN "b" ON ("b"."id" = "a"."bId") \ + LEFT JOIN "c" ON ("c"."id" = "b"."cId") \ + LEFT JOIN "d" ON ("d"."id" = "c"."dId") \ + LEFT JOIN "e" ON ("e"."id" = "d"."eId") + """) + try assertEqualSQL(db, A().request(for: association), """ + SELECT "e".* \ + FROM "e" \ + JOIN "d" ON ("d"."eId" = "e"."id") \ + JOIN "c" ON ("c"."dId" = "d"."id") \ + JOIN "b" ON (("b"."cId" = "c"."id") AND ("b"."id" = 1)) + """) + } + } + } +} diff --git a/Tests/GRDBTests/AssociationParallelDecodableRecordTests.swift b/Tests/GRDBTests/AssociationParallelDecodableRecordTests.swift index 4795ac7e0..9670671d4 100644 --- a/Tests/GRDBTests/AssociationParallelDecodableRecordTests.swift +++ b/Tests/GRDBTests/AssociationParallelDecodableRecordTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/AssociationParallelRowScopesTests.swift b/Tests/GRDBTests/AssociationParallelRowScopesTests.swift index f55a82980..a759451e9 100644 --- a/Tests/GRDBTests/AssociationParallelRowScopesTests.swift +++ b/Tests/GRDBTests/AssociationParallelRowScopesTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -89,7 +87,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.including(required: A.defaultB).including(required: A.defaultD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -105,7 +103,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(required: A.defaultB).including(optional: A.defaultD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -131,7 +129,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(optional: A.defaultB).including(required: A.defaultD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 3) @@ -152,7 +150,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(optional: A.defaultB).including(optional: A.defaultD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 6) @@ -188,7 +186,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.defaultA).including(required: B.defaultC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -204,7 +202,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.defaultA).including(optional: B.defaultC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -230,7 +228,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(optional: B.defaultA).including(required: B.defaultC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -246,7 +244,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(optional: B.defaultA).including(optional: B.defaultC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 5) @@ -281,7 +279,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.including(required: A.defaultB).including(required: A.defaultB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -303,7 +301,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(required: A.defaultB).including(optional: A.defaultB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -325,7 +323,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(optional: A.defaultB).including(required: A.defaultB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -347,7 +345,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(optional: A.defaultB).including(optional: A.defaultB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 6) @@ -377,7 +375,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.defaultA).including(required: B.defaultA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -399,7 +397,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.defaultA).including(optional: B.defaultA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -421,7 +419,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(optional: B.defaultA).including(required: B.defaultA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -443,7 +441,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(optional: B.defaultA).including(optional: B.defaultA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 5) @@ -473,7 +471,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.including(required: A.defaultB).joining(required: A.defaultD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -487,7 +485,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(required: A.defaultB).joining(optional: A.defaultD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -509,7 +507,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(optional: A.defaultB).joining(required: A.defaultD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 3) @@ -527,7 +525,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(optional: A.defaultB).joining(optional: A.defaultD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 6) @@ -557,7 +555,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.defaultA).joining(required: B.defaultC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -571,7 +569,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.defaultA).joining(optional: B.defaultC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -593,7 +591,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(optional: B.defaultA).joining(required: B.defaultC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -607,7 +605,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(optional: B.defaultA).joining(optional: B.defaultC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 5) @@ -637,7 +635,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.including(required: A.defaultB).joining(required: A.defaultB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -659,7 +657,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(required: A.defaultB).joining(optional: A.defaultB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -681,7 +679,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(optional: A.defaultB).joining(required: A.defaultB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -703,7 +701,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(optional: A.defaultB).joining(optional: A.defaultB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 6) @@ -733,7 +731,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.defaultA).joining(required: B.defaultA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -755,7 +753,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.defaultA).joining(optional: B.defaultA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -777,7 +775,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(optional: B.defaultA).joining(required: B.defaultA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -799,7 +797,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(optional: B.defaultA).joining(optional: B.defaultA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 5) @@ -829,7 +827,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.joining(required: A.defaultB).including(required: A.defaultD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -843,7 +841,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(required: A.defaultB).including(optional: A.defaultD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -865,7 +863,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(optional: A.defaultB).including(required: A.defaultD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 3) @@ -883,7 +881,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(optional: A.defaultB).including(optional: A.defaultD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 6) @@ -913,7 +911,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.defaultA).including(required: B.defaultC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -927,7 +925,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.defaultA).including(optional: B.defaultC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -949,7 +947,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(optional: B.defaultA).including(required: B.defaultC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -963,7 +961,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(optional: B.defaultA).including(optional: B.defaultC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 5) @@ -993,7 +991,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.joining(required: A.defaultB).including(required: A.defaultB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1015,7 +1013,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(required: A.defaultB).including(optional: A.defaultB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1037,7 +1035,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(optional: A.defaultB).including(required: A.defaultB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1059,7 +1057,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(optional: A.defaultB).including(optional: A.defaultB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 6) @@ -1089,7 +1087,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.defaultA).including(required: B.defaultA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1111,7 +1109,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.defaultA).including(optional: B.defaultA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1133,7 +1131,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(optional: B.defaultA).including(required: B.defaultA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1155,7 +1153,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(optional: B.defaultA).including(optional: B.defaultA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 5) @@ -1185,7 +1183,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.joining(required: A.defaultB).joining(required: A.defaultD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -1197,7 +1195,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(required: A.defaultB).joining(optional: A.defaultD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1215,7 +1213,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(optional: A.defaultB).joining(required: A.defaultD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 3) @@ -1230,7 +1228,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(optional: A.defaultB).joining(optional: A.defaultD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 6) @@ -1254,7 +1252,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.defaultA).joining(required: B.defaultC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -1266,7 +1264,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.defaultA).joining(optional: B.defaultC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1284,7 +1282,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(optional: B.defaultA).joining(required: B.defaultC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -1296,7 +1294,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(optional: B.defaultA).joining(optional: B.defaultC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 5) @@ -1321,7 +1319,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.joining(required: A.defaultB).joining(required: A.defaultB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1339,7 +1337,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(required: A.defaultB).joining(optional: A.defaultB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1357,7 +1355,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(optional: A.defaultB).joining(required: A.defaultB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1375,7 +1373,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(optional: A.defaultB).joining(optional: A.defaultB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 6) @@ -1399,7 +1397,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.defaultA).joining(required: B.defaultA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1417,7 +1415,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.defaultA).joining(optional: B.defaultA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1435,7 +1433,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(optional: B.defaultA).joining(required: B.defaultA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1453,7 +1451,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(optional: B.defaultA).joining(optional: B.defaultA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 5) @@ -1478,7 +1476,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.including(required: A.customB).including(required: A.customD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -1494,7 +1492,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(required: A.customB).including(optional: A.customD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1520,7 +1518,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(optional: A.customB).including(required: A.customD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 3) @@ -1541,7 +1539,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(optional: A.customB).including(optional: A.customD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 6) @@ -1577,7 +1575,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.customA).including(required: B.customC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -1593,7 +1591,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.customA).including(optional: B.customC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1619,7 +1617,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(optional: B.customA).including(required: B.customC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -1635,7 +1633,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(optional: B.customA).including(optional: B.customC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 5) @@ -1670,7 +1668,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.including(required: A.customB).including(required: A.customB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1692,7 +1690,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(required: A.customB).including(optional: A.customB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1714,7 +1712,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(optional: A.customB).including(required: A.customB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1736,7 +1734,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(optional: A.customB).including(optional: A.customB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 6) @@ -1766,7 +1764,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.customA).including(required: B.customA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1788,7 +1786,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.customA).including(optional: B.customA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1810,7 +1808,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(optional: B.customA).including(required: B.customA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1832,7 +1830,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(optional: B.customA).including(optional: B.customA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 5) @@ -1862,7 +1860,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.including(required: A.customB).joining(required: A.customD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -1876,7 +1874,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(required: A.customB).joining(optional: A.customD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1898,7 +1896,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(optional: A.customB).joining(required: A.customD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 3) @@ -1916,7 +1914,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(optional: A.customB).joining(optional: A.customD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 6) @@ -1946,7 +1944,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.customA).joining(required: B.customC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -1960,7 +1958,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.customA).joining(optional: B.customC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -1982,7 +1980,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(optional: B.customA).joining(required: B.customC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -1996,7 +1994,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(optional: B.customA).joining(optional: B.customC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 5) @@ -2026,7 +2024,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.including(required: A.customB).joining(required: A.customB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2048,7 +2046,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(required: A.customB).joining(optional: A.customB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2070,7 +2068,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(optional: A.customB).joining(required: A.customB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2092,7 +2090,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.including(optional: A.customB).joining(optional: A.customB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 6) @@ -2122,7 +2120,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.customA).joining(required: B.customA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2144,7 +2142,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(required: B.customA).joining(optional: B.customA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2166,7 +2164,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(optional: B.customA).joining(required: B.customA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2188,7 +2186,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.including(optional: B.customA).joining(optional: B.customA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 5) @@ -2218,7 +2216,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.joining(required: A.customB).including(required: A.customD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -2232,7 +2230,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(required: A.customB).including(optional: A.customD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2254,7 +2252,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(optional: A.customB).including(required: A.customD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 3) @@ -2272,7 +2270,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(optional: A.customB).including(optional: A.customD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 6) @@ -2302,7 +2300,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.customA).including(required: B.customC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -2316,7 +2314,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.customA).including(optional: B.customC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2338,7 +2336,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(optional: B.customA).including(required: B.customC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -2352,7 +2350,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(optional: B.customA).including(optional: B.customC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 5) @@ -2382,7 +2380,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.joining(required: A.customB).including(required: A.customB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2404,7 +2402,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(required: A.customB).including(optional: A.customB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2426,7 +2424,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(optional: A.customB).including(required: A.customB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2448,7 +2446,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(optional: A.customB).including(optional: A.customB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 6) @@ -2478,7 +2476,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.customA).including(required: B.customA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2500,7 +2498,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.customA).including(optional: B.customA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2522,7 +2520,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(optional: B.customA).including(required: B.customA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2544,7 +2542,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(optional: B.customA).including(optional: B.customA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 5) @@ -2574,7 +2572,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.joining(required: A.customB).joining(required: A.customD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -2586,7 +2584,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(required: A.customB).joining(optional: A.customD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2604,7 +2602,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(optional: A.customB).joining(required: A.customD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 3) @@ -2619,7 +2617,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(optional: A.customB).joining(optional: A.customD).order(sql: "a.id, b.id, d.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 6) @@ -2643,7 +2641,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.customA).joining(required: B.customC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -2655,7 +2653,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.customA).joining(optional: B.customC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2673,7 +2671,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(optional: B.customA).joining(required: B.customC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 2) @@ -2685,7 +2683,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(optional: B.customA).joining(optional: B.customC).order(sql: "b.id, a.id, c.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 5) @@ -2710,7 +2708,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { let request = A.joining(required: A.customB).joining(required: A.customB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2728,7 +2726,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(required: A.customB).joining(optional: A.customB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2746,7 +2744,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(optional: A.customB).joining(required: A.customB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2764,7 +2762,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = A.joining(optional: A.customB).joining(optional: A.customB).order(sql: "a.id, b.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 6) @@ -2788,7 +2786,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.customA).joining(required: B.customA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2806,7 +2804,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(required: B.customA).joining(optional: B.customA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2824,7 +2822,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(optional: B.customA).joining(required: B.customA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 4) @@ -2842,7 +2840,7 @@ class AssociationParallelRowScopesTests: GRDBTestCase { } do { let request = B.joining(optional: B.customA).joining(optional: B.customA).order(sql: "b.id, a.id") - let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) } + let rows = try dbQueue.inDatabase { try Row.fetchAll($0, request) } XCTAssertEqual(rows.count, 5) diff --git a/Tests/GRDBTests/AssociationParallelSQLTests.swift b/Tests/GRDBTests/AssociationParallelSQLTests.swift index 2eb3121f6..a51861dae 100644 --- a/Tests/GRDBTests/AssociationParallelSQLTests.swift +++ b/Tests/GRDBTests/AssociationParallelSQLTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -111,49 +109,49 @@ class AssociationParallelSQLTests: GRDBTestCase { func testParallelTwoIncludingIncludingOtherKey() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try assertEqualSQL(db, A.including(required: A.b).including(required: A.b.forKey("altb")), """ + try assertEqualSQL(db, A.including(required: A.b).including(required: A.b.forKey("customB")), """ SELECT "a".*, "b1".*, "b2".* \ FROM "a" \ JOIN "b" "b1" ON ("b1"."id" = "a"."bid") \ JOIN "b" "b2" ON ("b2"."id" = "a"."bid") """) - try assertEqualSQL(db, A.including(required: A.b).including(optional: A.b.forKey("altb")), """ + try assertEqualSQL(db, A.including(required: A.b).including(optional: A.b.forKey("customB")), """ SELECT "a".*, "b1".*, "b2".* \ FROM "a" \ JOIN "b" "b1" ON ("b1"."id" = "a"."bid") \ LEFT JOIN "b" "b2" ON ("b2"."id" = "a"."bid") """) - try assertEqualSQL(db, A.including(optional: A.b).including(required: A.b.forKey("altb")), """ + try assertEqualSQL(db, A.including(optional: A.b).including(required: A.b.forKey("customB")), """ SELECT "a".*, "b1".*, "b2".* \ FROM "a" \ LEFT JOIN "b" "b1" ON ("b1"."id" = "a"."bid") \ JOIN "b" "b2" ON ("b2"."id" = "a"."bid") """) - try assertEqualSQL(db, A.including(optional: A.b).including(optional: A.b.forKey("altb")), """ + try assertEqualSQL(db, A.including(optional: A.b).including(optional: A.b.forKey("customB")), """ SELECT "a".*, "b1".*, "b2".* \ FROM "a" \ LEFT JOIN "b" "b1" ON ("b1"."id" = "a"."bid") \ LEFT JOIN "b" "b2" ON ("b2"."id" = "a"."bid") """) - try assertEqualSQL(db, B.including(required: B.a).including(required: B.a.forKey("alta")), """ + try assertEqualSQL(db, B.including(required: B.a).including(required: B.a.forKey("customA")), """ SELECT "b".*, "a1".*, "a2".* \ FROM "b" \ JOIN "a" "a1" ON ("a1"."bid" = "b"."id") \ JOIN "a" "a2" ON ("a2"."bid" = "b"."id") """) - try assertEqualSQL(db, B.including(required: B.a).including(optional: B.a.forKey("alta")), """ + try assertEqualSQL(db, B.including(required: B.a).including(optional: B.a.forKey("customA")), """ SELECT "b".*, "a1".*, "a2".* \ FROM "b" \ JOIN "a" "a1" ON ("a1"."bid" = "b"."id") \ LEFT JOIN "a" "a2" ON ("a2"."bid" = "b"."id") """) - try assertEqualSQL(db, B.including(optional: B.a).including(required: B.a.forKey("alta")), """ + try assertEqualSQL(db, B.including(optional: B.a).including(required: B.a.forKey("customA")), """ SELECT "b".*, "a1".*, "a2".* \ FROM "b" \ LEFT JOIN "a" "a1" ON ("a1"."bid" = "b"."id") \ JOIN "a" "a2" ON ("a2"."bid" = "b"."id") """) - try assertEqualSQL(db, B.including(optional: B.a).including(optional: B.a.forKey("alta")), """ + try assertEqualSQL(db, B.including(optional: B.a).including(optional: B.a.forKey("customA")), """ SELECT "b".*, "a1".*, "a2".* \ FROM "b" \ LEFT JOIN "a" "a1" ON ("a1"."bid" = "b"."id") \ diff --git a/Tests/GRDBTests/AssociationPrefetchingCodableRecordTests.swift b/Tests/GRDBTests/AssociationPrefetchingCodableRecordTests.swift new file mode 100644 index 000000000..a8a2f85f3 --- /dev/null +++ b/Tests/GRDBTests/AssociationPrefetchingCodableRecordTests.swift @@ -0,0 +1,1084 @@ +import XCTest +#if GRDBCUSTOMSQLITE + import GRDBCustomSQLite +#else + import GRDB +#endif + +private struct A: TableRecord, FetchableRecord, Decodable, Equatable { + var cola1: Int64 + var cola2: String +} +private struct B: TableRecord, FetchableRecord, Decodable, Equatable, Hashable { + var colb1: Int64 + var colb2: Int64? + var colb3: String +} +private struct C: TableRecord, FetchableRecord, Decodable, Equatable { + var colc1: Int64 + var colc2: Int64 +} +private struct D: TableRecord, FetchableRecord, Decodable, Equatable { + var cold1: Int64 + var cold2: Int64 + var cold3: String +} + +class AssociationPrefetchingCodableRecordTests: GRDBTestCase { + override func setup(_ dbWriter: DatabaseWriter) throws { + try dbWriter.write { db in + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("cola1") + t.column("cola2", .text) + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("colb1") + t.column("colb2", .integer).references("a") + t.column("colb3", .text) + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("colc1") + t.column("colc2", .integer).references("a") + } + try db.create(table: "d") { t in + t.autoIncrementedPrimaryKey("cold1") + t.column("cold2", .integer).references("c") + t.column("cold3", .text) + } + try db.execute( + sql: """ + INSERT INTO a (cola1, cola2) VALUES (?, ?); + INSERT INTO a (cola1, cola2) VALUES (?, ?); + INSERT INTO a (cola1, cola2) VALUES (?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO c (colc1, colc2) VALUES (?, ?); + INSERT INTO c (colc1, colc2) VALUES (?, ?); + INSERT INTO c (colc1, colc2) VALUES (?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + """, + arguments: [ + 1, "a1", + 2, "a2", + 3, "a3", + 4, 1, "b1", + 5, 1, "b2", + 6, 2, "b3", + 14, nil, "b4", + 7, 1, + 8, 2, + 9, 2, + 10, 7, "d1", + 11, 8, "d2", + 12, 8, "d3", + 13, 9, "d4", + ]) + } + } + + func testIncludingAllHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(B.self) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + // Array + do { + struct Record: FetchableRecord, Decodable, Equatable { + var a: A + var bs: [B] + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + bs: [ + B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + B(row: ["colb1": 5, "colb2": 1, "colb3": "b2"]), + ]), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + bs: [ + B(row: ["colb1": 6, "colb2": 2, "colb3": "b3"]), + ]), + Record( + a: A(row: ["cola1": 3, "cola2": "a3"]), + bs: []), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + bs: [ + B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + B(row: ["colb1": 5, "colb2": 1, "colb3": "b2"]), + ])) + } + } + + // Set + do { + struct Record: FetchableRecord, Decodable, Equatable { + var a: A + var bs: Set + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + bs: [ + B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + B(row: ["colb1": 5, "colb2": 1, "colb3": "b2"]), + ]), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + bs: [ + B(row: ["colb1": 6, "colb2": 2, "colb3": "b3"]), + ]), + Record( + a: A(row: ["cola1": 3, "cola2": "a3"]), + bs: []), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + bs: [ + B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + B(row: ["colb1": 5, "colb2": 1, "colb3": "b2"]), + ])) + } + } + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(B.self) + .filter(Column("colb1") == 4) + .orderByPrimaryKey() + .forKey("bs1")) + .including(all: A + .hasMany(B.self) + .filter(Column("colb1") != 4) + .orderByPrimaryKey() + .forKey("bs2")) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Decodable, Equatable { + var a: A + var bs1: [B] + var bs2: [B] + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + print(records) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + bs1: [ + B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + ], + bs2: [ + B(row: ["colb1": 5, "colb2": 1, "colb3": "b2"]), + ]), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + bs1: [], + bs2: [ + B(row: ["colb1": 6, "colb2": 2, "colb3": "b3"]), + ]), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + bs1: [ + B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + ], + bs2: [ + B(row: ["colb1": 5, "colb2": 1, "colb3": "b2"]), + ])) + } + } + } + } + + func testIncludingAllHasManyIncludingAllHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(C.self) + .including(all: C + .hasMany(D.self) + .orderByPrimaryKey()) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Decodable, Equatable { + struct CInfo: Decodable, Equatable { + var c: C + var ds: [D] + } + var a: A + var cs: [CInfo] + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + Record.CInfo( + c: C(row: ["colc1": 7, "colc2": 1]), + ds: [ + D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"]), + ]), + ]), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + cs: [ + Record.CInfo( + c: C(row: ["colc1": 8, "colc2": 2]), + ds: [ + D(row: ["cold1": 11, "cold2": 8, "cold3": "d2"]), + D(row: ["cold1": 12, "cold2": 8, "cold3": "d3"]), + ]), + Record.CInfo( + c: C(row: ["colc1": 9, "colc2": 2]), + ds: [ + D(row: ["cold1": 13, "cold2": 9, "cold3": "d4"]), + ]), + ]), + Record( + a: A(row: ["cola1": 3, "cola2": "a3"]), + cs: []), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + Record.CInfo( + c: C(row: ["colc1": 7, "colc2": 1]), + ds: [ + D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"]), + ]), + ])) + } + } + + // Request with avoided prefetch + do { + let request = A + .including(all: A + .hasMany(C.self) + .filter(false) + .including(all: C + .hasMany(D.self) + .orderByPrimaryKey()) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Decodable, Equatable { + struct CInfo: Decodable, Equatable { + var c: C + var ds: [D] + } + var a: A + var cs: [CInfo] + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: []), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + cs: []), + Record( + a: A(row: ["cola1": 3, "cola2": "a3"]), + cs: []), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [])) + } + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") > 7) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("ds1")) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("ds2")) + .orderByPrimaryKey() + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") < 9) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("ds1")) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("ds2")) + .orderByPrimaryKey() + .forKey("cs2")) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Decodable, Equatable { + struct CInfo: Decodable, Equatable { + var c: C + var ds1: [D] + var ds2: [D] + } + var a: A + var cs1: [CInfo] + var cs2: [CInfo] + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs1: [], + cs2: [ + Record.CInfo( + c: C(row: ["colc1": 7, "colc2": 1]), + ds1: [], + ds2: [ + D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"]), + ]), + ]), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + cs1: [ + Record.CInfo( + c: C(row: ["colc1": 8, "colc2": 2]), + ds1: [ + D(row: ["cold1": 11, "cold2": 8, "cold3": "d2"]), + ], + ds2: [ + D(row: ["cold1": 12, "cold2": 8, "cold3": "d3"]), + ]), + Record.CInfo( + c: C(row: ["colc1": 9, "colc2": 2]), + ds1: [], + ds2: [ + D(row: ["cold1": 13, "cold2": 9, "cold3": "d4"]), + ]), + ], + cs2: [ + Record.CInfo( + c: C(row: ["colc1": 8, "colc2": 2]), + ds1: [ + D(row: ["cold1": 11, "cold2": 8, "cold3": "d2"]), + ], + ds2: [ + D(row: ["cold1": 12, "cold2": 8, "cold3": "d3"]), + ]), + ]), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs1: [], + cs2: [ + Record.CInfo( + c: C(row: ["colc1": 7, "colc2": 1]), + ds1: [], + ds2: [ + D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"]), + ]), + ])) + } + } + } + } + + func testIncludingAllHasManyIncludingRequiredOrOptionalHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(C.self) + .including(required: C + .hasMany(D.self) + .orderByPrimaryKey()) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Decodable, Equatable { + struct CInfo: Decodable, Equatable { + var c: C + var d: D + } + var a: A + var cs: [CInfo] + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + Record.CInfo( + c: C(row: ["colc1": 7, "colc2": 1]), + d: D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"])), + ]), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + cs: [ + Record.CInfo( + c: C(row: ["colc1": 8, "colc2": 2]), + d: D(row: ["cold1": 11, "cold2": 8, "cold3": "d2"])), + Record.CInfo( + c: C(row: ["colc1": 8, "colc2": 2]), + d: D(row: ["cold1": 12, "cold2": 8, "cold3": "d3"])), + Record.CInfo( + c: C(row: ["colc1": 9, "colc2": 2]), + d: D(row: ["cold1": 13, "cold2": 9, "cold3": "d4"])), + ]), + Record( + a: A(row: ["cola1": 3, "cola2": "a3"]), + cs: []), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + Record.CInfo( + c: C(row: ["colc1": 7, "colc2": 1]), + d: D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"])), + ])) + } + } + + // Request with avoided prefetch + do { + let request = A + .including(all: A + .hasMany(C.self) + .filter(false) + .including(required: C + .hasMany(D.self) + .orderByPrimaryKey()) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Decodable, Equatable { + struct CInfo: Decodable, Equatable { + var c: C + var d: D + } + var a: A + var cs: [CInfo] + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: []), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + cs: []), + Record( + a: A(row: ["cola1": 3, "cola2": "a3"]), + cs: []), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [])) + } + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") > 7) + .including(optional: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("ds1")) + .including(required: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("ds2")) + .orderByPrimaryKey() + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") < 9) + .including(optional: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("ds1")) + .including(required: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("ds2")) + .orderByPrimaryKey() + .forKey("cs2")) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Decodable, Equatable { + struct CInfo: Decodable, Equatable { + var c: C + var d1: D? + var d2: D + } + var a: A + var cs1: [CInfo] + var cs2: [CInfo] + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs1: [], + cs2: [ + Record.CInfo( + c: C(row: ["colc1": 7, "colc2": 1]), + d1: nil, + d2: D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"])), + ]), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + cs1: [ + Record.CInfo( + c: C(row: ["colc1": 8, "colc2": 2]), + d1: D(row: ["cold1": 11, "cold2": 8, "cold3": "d2"]), + d2: D(row: ["cold1": 12, "cold2": 8, "cold3": "d3"])), + Record.CInfo( + c: C(row: ["colc1": 9, "colc2": 2]), + d1: nil, + d2: D(row: ["cold1": 13, "cold2": 9, "cold3": "d4"])), + ], + cs2: [ + Record.CInfo( + c: C(row: ["colc1": 8, "colc2": 2]), + d1: D(row: ["cold1": 11, "cold2": 8, "cold3": "d2"]), + d2: D(row: ["cold1": 12, "cold2": 8, "cold3": "d3"])), + ]), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs1: [], + cs2: [ + Record.CInfo( + c: C(row: ["colc1": 7, "colc2": 1]), + d1: nil, + d2: D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"])), + ])) + } + } + } + } + + func testIncludingAllHasManyThroughHasManyUsingHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self), using: C.hasMany(D.self)) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Decodable, Equatable { + var a: A + var ds: [D] + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + ds: [ + D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"]), + ]), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + ds: [ + D(row: ["cold1": 11, "cold2": 8, "cold3": "d2"]), + D(row: ["cold1": 12, "cold2": 8, "cold3": "d3"]), + D(row: ["cold1": 13, "cold2": 9, "cold3": "d4"]), + ]), + Record( + a: A(row: ["cola1": 3, "cola2": "a3"]), + ds: []), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + ds: [ + D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"]), + ])) + } + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self).filter(Column("colc1") == 8).forKey("cs1"), using: C.hasMany(D.self)) + .orderByPrimaryKey() + .forKey("ds1")) + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self).forKey("cs2"), using: C.hasMany(D.self)) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("ds2")) + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self).forKey("cs2"), using: C.hasMany(D.self)) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("ds3")) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Decodable, Equatable { + var a: A + var ds1: [D] + var ds2: [D] + var ds3: [D] + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + ds1: [], + ds2: [ + D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"]), + ], + ds3: []), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + ds1: [ + D(row: ["cold1": 11, "cold2": 8, "cold3": "d2"]), + D(row: ["cold1": 12, "cold2": 8, "cold3": "d3"]), + ], + ds2: [ + D(row: ["cold1": 12, "cold2": 8, "cold3": "d3"]), + D(row: ["cold1": 13, "cold2": 9, "cold3": "d4"]), + ], + ds3: [ + D(row: ["cold1": 11, "cold2": 8, "cold3": "d2"]), + ]), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + ds1: [], + ds2: [ + D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"]), + ], + ds3: [])) + } + } + } + } + + // TODO: make a variant with joining(optional:) + func testIncludingOptionalBelongsToIncludingAllHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + // Plain request + do { + let request = B + .including(optional: B + .belongsTo(A.self) + .including(all: A + .hasMany(C.self) + .orderByPrimaryKey()) + ) + .orderByPrimaryKey() + + // Record (nested) + do { + struct Record: FetchableRecord, Decodable, Equatable { + struct AInfo: Decodable, Equatable { + var a: A + var cs: [C] + } + var b: B + var a: AInfo? + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + b: B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + a: Record.AInfo( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + C(row: ["colc1": 7, "colc2": 1]), + ])), + Record( + b: B(row: ["colb1": 5, "colb2": 1, "colb3": "b2"]), + a: Record.AInfo( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + C(row: ["colc1": 7, "colc2": 1]), + ])), + Record( + b: B(row: ["colb1": 6, "colb2": 2, "colb3": "b3"]), + a: Record.AInfo( + a: A(row: ["cola1": 2, "cola2": "a2"]), + cs: [ + C(row: ["colc1": 8, "colc2": 2]), + C(row: ["colc1": 9, "colc2": 2]), + ])), + Record( + b: B(row: ["colb1": 14, "colb2": nil, "colb3": "b4"]), + a: nil), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + b: B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + a: Record.AInfo( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + C(row: ["colc1": 7, "colc2": 1]), + ]))) + } + } + + // Record (flat) + do { + struct Record: FetchableRecord, Decodable, Equatable { + var b: B + var a: A? + var cs: [C] // not optional + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + b: B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + C(row: ["colc1": 7, "colc2": 1]), + ]), + Record( + b: B(row: ["colb1": 5, "colb2": 1, "colb3": "b2"]), + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + C(row: ["colc1": 7, "colc2": 1]), + ]), + Record( + b: B(row: ["colb1": 6, "colb2": 2, "colb3": "b3"]), + a: A(row: ["cola1": 2, "cola2": "a2"]), + cs: [ + C(row: ["colc1": 8, "colc2": 2]), + C(row: ["colc1": 9, "colc2": 2]), + ]), + Record( + b: B(row: ["colb1": 14, "colb2": nil, "colb3": "b4"]), + a: nil, + cs: []), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + b: B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + C(row: ["colc1": 7, "colc2": 1]), + ])) + } + } + } + + // Request with filters + do { + let request = B + .including(optional: B + .belongsTo(A.self) + .filter(Column("cola2") == "a1") + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") == 9) + .orderByPrimaryKey() + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") != 9) + .orderByPrimaryKey() + .forKey("cs2")) + .forKey("a1")) + .including(optional: B + .belongsTo(A.self) + .filter(Column("cola2") == "a2") + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") == 9) + .orderByPrimaryKey() + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") != 9) + .orderByPrimaryKey() + .forKey("cs2")) + .forKey("a2")) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Decodable, Equatable { + struct AInfo: Decodable, Equatable { + var a: A + var cs1: [C] + var cs2: [C] + } + var b: B + var a1: AInfo? + var a2: AInfo? + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + b: B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + a1: Record.AInfo( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs1: [], + cs2: [ + C(row: ["colc1": 7, "colc2": 1]), + ]), + a2: nil), + Record( + b: B(row: ["colb1": 5, "colb2": 1, "colb3": "b2"]), + a1: Record.AInfo( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs1: [], + cs2: [ + C(row: ["colc1": 7, "colc2": 1]), + ]), + a2: nil), + Record( + b: B(row: ["colb1": 6, "colb2": 2, "colb3": "b3"]), + a1: nil, + a2: Record.AInfo( + a: A(row: ["cola1": 2, "cola2": "a2"]), + cs1: [ + C(row: ["colc1": 9, "colc2": 2]), + ], + cs2: [ + C(row: ["colc1": 8, "colc2": 2]), + ])), + Record( + b: B(row: ["colb1": 14, "colb2": nil, "colb3": "b4"]), + a1: nil, + a2: nil), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + b: B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + a1: Record.AInfo( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs1: [], + cs2: [ + C(row: ["colc1": 7, "colc2": 1]), + ]), + a2: nil)) + } + } + } + } + + func testSelfJoin() throws { + struct Employee: TableRecord, FetchableRecord, Decodable, Hashable { + static let subordinates = hasMany(Employee.self, key: "subordinates") + static let manager = belongsTo(Employee.self, key: "manager") + var id: Int64 + var managerId: Int64? + var name: String + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "employee") { t in + t.autoIncrementedPrimaryKey("id") + t.column("managerId", .integer) + .indexed() + .references("employee", onDelete: .restrict) + t.column("name", .text) + } + try db.execute(sql: """ + INSERT INTO employee (id, managerId, name) VALUES (1, NULL, 'Arthur'); + INSERT INTO employee (id, managerId, name) VALUES (2, 1, 'Barbara'); + INSERT INTO employee (id, managerId, name) VALUES (3, 1, 'Craig'); + INSERT INTO employee (id, managerId, name) VALUES (4, 2, 'David'); + INSERT INTO employee (id, managerId, name) VALUES (5, NULL, 'Eve'); + """) + + struct EmployeeInfo: FetchableRecord, Decodable, Equatable { + var employee: Employee + var manager: Employee? + var subordinates: Set + } + + let request = Employee + .including(optional: Employee.manager) + .including(all: Employee.subordinates) + .orderByPrimaryKey() + + let employeeInfos: [EmployeeInfo] = try EmployeeInfo.fetchAll(db, request) + XCTAssertEqual(employeeInfos, [ + EmployeeInfo( + employee: Employee(id: 1, managerId: nil, name: "Arthur"), + manager: nil, + subordinates: [ + Employee(id: 2, managerId: 1, name: "Barbara"), + Employee(id: 3, managerId: 1, name: "Craig"), + ]), + EmployeeInfo( + employee: Employee(id: 2, managerId: 1, name: "Barbara"), + manager: Employee(id: 1, managerId: nil, name: "Arthur"), + subordinates: [ + Employee(id: 4, managerId: 2, name: "David"), + ]), + EmployeeInfo( + employee: Employee(id: 3, managerId: 1, name: "Craig"), + manager: Employee(id: 1, managerId: nil, name: "Arthur"), + subordinates: []), + EmployeeInfo( + employee: Employee(id: 4, managerId: 2, name: "David"), + manager: Employee(id: 2, managerId: 1, name: "Barbara"), + subordinates: []), + EmployeeInfo( + employee: Employee(id: 5, managerId: nil, name: "Eve"), + manager: nil, + subordinates: []), + ]) + } + } +} diff --git a/Tests/GRDBTests/AssociationPrefetchingFetchableRecordTests.swift b/Tests/GRDBTests/AssociationPrefetchingFetchableRecordTests.swift new file mode 100644 index 000000000..e7cd853b1 --- /dev/null +++ b/Tests/GRDBTests/AssociationPrefetchingFetchableRecordTests.swift @@ -0,0 +1,1246 @@ +import XCTest +#if GRDBCUSTOMSQLITE + import GRDBCustomSQLite +#else + import GRDB +#endif + +private struct A: TableRecord, FetchableRecord, Equatable { + var cola1: Int64 + var cola2: String + + init(row: Row) { + cola1 = row["cola1"] + cola2 = row["cola2"] + } +} +private struct B: TableRecord, FetchableRecord, Hashable { + var colb1: Int64 + var colb2: Int64? + var colb3: String + + init(row: Row) { + colb1 = row["colb1"] + colb2 = row["colb2"] + colb3 = row["colb3"] + } +} +private struct C: TableRecord, FetchableRecord, Equatable { + var colc1: Int64 + var colc2: Int64 + + init(row: Row) { + colc1 = row["colc1"] + colc2 = row["colc2"] + } +} +private struct D: TableRecord, FetchableRecord, Equatable { + var cold1: Int64 + var cold2: Int64 + var cold3: String + + init(row: Row) { + cold1 = row["cold1"] + cold2 = row["cold2"] + cold3 = row["cold3"] + } +} + +class AssociationPrefetchingFetchableRecordTests: GRDBTestCase { + override func setup(_ dbWriter: DatabaseWriter) throws { + try dbWriter.write { db in + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("cola1") + t.column("cola2", .text) + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("colb1") + t.column("colb2", .integer).references("a") + t.column("colb3", .text) + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("colc1") + t.column("colc2", .integer).references("a") + } + try db.create(table: "d") { t in + t.autoIncrementedPrimaryKey("cold1") + t.column("cold2", .integer).references("c") + t.column("cold3", .text) + } + try db.execute( + sql: """ + INSERT INTO a (cola1, cola2) VALUES (?, ?); + INSERT INTO a (cola1, cola2) VALUES (?, ?); + INSERT INTO a (cola1, cola2) VALUES (?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO c (colc1, colc2) VALUES (?, ?); + INSERT INTO c (colc1, colc2) VALUES (?, ?); + INSERT INTO c (colc1, colc2) VALUES (?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + """, + arguments: [ + 1, "a1", + 2, "a2", + 3, "a3", + 4, 1, "b1", + 5, 1, "b2", + 6, 2, "b3", + 14, nil, "b4", + 7, 1, + 8, 2, + 9, 2, + 10, 7, "d1", + 11, 8, "d2", + 12, 8, "d3", + 13, 9, "d4", + ]) + } + } + + func testIncludingAllHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(B.self) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + // Array + do { + struct Record: FetchableRecord, Equatable { + var a: A + var bs: [B] + + init(a: A, bs: [B]) { + self.a = a + self.bs = bs + } + + init(row: Row) { + self.init(a: A(row: row), bs: row["bs"]) + } + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + bs: [ + B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + B(row: ["colb1": 5, "colb2": 1, "colb3": "b2"]), + ]), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + bs: [ + B(row: ["colb1": 6, "colb2": 2, "colb3": "b3"]), + ]), + Record( + a: A(row: ["cola1": 3, "cola2": "a3"]), + bs: []), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + bs: [ + B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + B(row: ["colb1": 5, "colb2": 1, "colb3": "b2"]), + ])) + } + } + + // Set + do { + struct Record: FetchableRecord, Equatable { + var a: A + var bs: Set + + init(a: A, bs: Set) { + self.a = a + self.bs = bs + } + + init(row: Row) { + self.init(a: A(row: row), bs: row["bs"]) + } + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + bs: [ + B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + B(row: ["colb1": 5, "colb2": 1, "colb3": "b2"]), + ]), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + bs: [ + B(row: ["colb1": 6, "colb2": 2, "colb3": "b3"]), + ]), + Record( + a: A(row: ["cola1": 3, "cola2": "a3"]), + bs: []), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + bs: [ + B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + B(row: ["colb1": 5, "colb2": 1, "colb3": "b2"]), + ])) + } + } + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(B.self) + .filter(Column("colb1") == 4) + .orderByPrimaryKey() + .forKey("bs1")) + .including(all: A + .hasMany(B.self) + .filter(Column("colb1") != 4) + .orderByPrimaryKey() + .forKey("bs2")) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Equatable { + var a: A + var bs1: [B] + var bs2: [B] + + init(a: A, bs1: [B], bs2: [B]) { + self.a = a + self.bs1 = bs1 + self.bs2 = bs2 + } + + init(row: Row) { + self.init(a: A(row: row), bs1: row["bs1"], bs2: row["bs2"]) + } + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + print(records) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + bs1: [ + B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + ], + bs2: [ + B(row: ["colb1": 5, "colb2": 1, "colb3": "b2"]), + ]), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + bs1: [], + bs2: [ + B(row: ["colb1": 6, "colb2": 2, "colb3": "b3"]), + ]), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + bs1: [ + B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + ], + bs2: [ + B(row: ["colb1": 5, "colb2": 1, "colb3": "b2"]), + ])) + } + } + } + } + + func testIncludingAllHasManyIncludingAllHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(C.self) + .including(all: C + .hasMany(D.self) + .orderByPrimaryKey()) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Equatable { + struct CInfo: FetchableRecord, Equatable { + var c: C + var ds: [D] + + init(c: C, ds: [D]) { + self.c = c + self.ds = ds + } + + init(row: Row) { + self.init(c: C(row: row), ds: row["ds"]) + } + } + var a: A + var cs: [CInfo] + + init(a: A, cs: [CInfo]) { + self.a = a + self.cs = cs + } + + init(row: Row) { + self.init(a: A(row: row), cs: row["cs"]) + } + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + Record.CInfo( + c: C(row: ["colc1": 7, "colc2": 1]), + ds: [ + D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"]), + ]), + ]), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + cs: [ + Record.CInfo( + c: C(row: ["colc1": 8, "colc2": 2]), + ds: [ + D(row: ["cold1": 11, "cold2": 8, "cold3": "d2"]), + D(row: ["cold1": 12, "cold2": 8, "cold3": "d3"]), + ]), + Record.CInfo( + c: C(row: ["colc1": 9, "colc2": 2]), + ds: [ + D(row: ["cold1": 13, "cold2": 9, "cold3": "d4"]), + ]), + ]), + Record( + a: A(row: ["cola1": 3, "cola2": "a3"]), + cs: []), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + Record.CInfo( + c: C(row: ["colc1": 7, "colc2": 1]), + ds: [ + D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"]), + ]), + ])) + } + } + + // Request with avoided prefetch + do { + let request = A + .including(all: A + .hasMany(C.self) + .filter(false) + .including(all: C + .hasMany(D.self) + .orderByPrimaryKey()) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Equatable { + struct CInfo: FetchableRecord, Equatable { + var c: C + var ds: [D] + + init(c: C, ds: [D]) { + self.c = c + self.ds = ds + } + + init(row: Row) { + self.init(c: C(row: row), ds: row["ds"]) + } + } + var a: A + var cs: [CInfo] + + init(a: A, cs: [CInfo]) { + self.a = a + self.cs = cs + } + + init(row: Row) { + self.init(a: A(row: row), cs: row["cs"]) + } + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: []), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + cs: []), + Record( + a: A(row: ["cola1": 3, "cola2": "a3"]), + cs: []), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [])) + } + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") > 7) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("ds1")) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("ds2")) + .orderByPrimaryKey() + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") < 9) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("ds1")) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("ds2")) + .orderByPrimaryKey() + .forKey("cs2")) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Equatable { + struct CInfo: FetchableRecord, Equatable { + var c: C + var ds1: [D] + var ds2: [D] + + init(c: C, ds1: [D], ds2: [D]) { + self.c = c + self.ds1 = ds1 + self.ds2 = ds2 + } + + init(row: Row) { + self.init(c: C(row: row), ds1: row["ds1"], ds2: row["ds2"]) + } + } + var a: A + var cs1: [CInfo] + var cs2: [CInfo] + + init(a: A, cs1: [CInfo], cs2: [CInfo]) { + self.a = a + self.cs1 = cs1 + self.cs2 = cs2 + } + + init(row: Row) { + self.init(a: A(row: row), cs1: row["cs1"], cs2: row["cs2"]) + } + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs1: [], + cs2: [ + Record.CInfo( + c: C(row: ["colc1": 7, "colc2": 1]), + ds1: [], + ds2: [ + D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"]), + ]), + ]), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + cs1: [ + Record.CInfo( + c: C(row: ["colc1": 8, "colc2": 2]), + ds1: [ + D(row: ["cold1": 11, "cold2": 8, "cold3": "d2"]), + ], + ds2: [ + D(row: ["cold1": 12, "cold2": 8, "cold3": "d3"]), + ]), + Record.CInfo( + c: C(row: ["colc1": 9, "colc2": 2]), + ds1: [], + ds2: [ + D(row: ["cold1": 13, "cold2": 9, "cold3": "d4"]), + ]), + ], + cs2: [ + Record.CInfo( + c: C(row: ["colc1": 8, "colc2": 2]), + ds1: [ + D(row: ["cold1": 11, "cold2": 8, "cold3": "d2"]), + ], + ds2: [ + D(row: ["cold1": 12, "cold2": 8, "cold3": "d3"]), + ]), + ]), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs1: [], + cs2: [ + Record.CInfo( + c: C(row: ["colc1": 7, "colc2": 1]), + ds1: [], + ds2: [ + D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"]), + ]), + ])) + } + } + } + } + + func testIncludingAllHasManyIncludingRequiredOrOptionalHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(C.self) + .including(required: C + .hasMany(D.self) + .orderByPrimaryKey()) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Equatable { + struct CInfo: FetchableRecord, Equatable { + var c: C + var d: D + + init(c: C, d: D) { + self.c = c + self.d = d + } + + init(row: Row) { + self.init(c: C(row: row), d: row["d"]) + } + } + var a: A + var cs: [CInfo] + + init(a: A, cs: [CInfo]) { + self.a = a + self.cs = cs + } + + init(row: Row) { + self.init(a: A(row: row), cs: row["cs"]) + } + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + Record.CInfo( + c: C(row: ["colc1": 7, "colc2": 1]), + d: D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"])), + ]), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + cs: [ + Record.CInfo( + c: C(row: ["colc1": 8, "colc2": 2]), + d: D(row: ["cold1": 11, "cold2": 8, "cold3": "d2"])), + Record.CInfo( + c: C(row: ["colc1": 8, "colc2": 2]), + d: D(row: ["cold1": 12, "cold2": 8, "cold3": "d3"])), + Record.CInfo( + c: C(row: ["colc1": 9, "colc2": 2]), + d: D(row: ["cold1": 13, "cold2": 9, "cold3": "d4"])), + ]), + Record( + a: A(row: ["cola1": 3, "cola2": "a3"]), + cs: []), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + Record.CInfo( + c: C(row: ["colc1": 7, "colc2": 1]), + d: D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"])), + ])) + } + } + + // Request with avoided prefetch + do { + let request = A + .including(all: A + .hasMany(C.self) + .filter(false) + .including(required: C + .hasMany(D.self) + .orderByPrimaryKey()) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Equatable { + struct CInfo: FetchableRecord, Equatable { + var c: C + var d: D + + init(c: C, d: D) { + self.c = c + self.d = d + } + + init(row: Row) { + self.init(c: C(row: row), d: row["d"]) + } + } + var a: A + var cs: [CInfo] + + init(a: A, cs: [CInfo]) { + self.a = a + self.cs = cs + } + + init(row: Row) { + self.init(a: A(row: row), cs: row["cs"]) + } + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: []), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + cs: []), + Record( + a: A(row: ["cola1": 3, "cola2": "a3"]), + cs: []), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [])) + } + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") > 7) + .including(optional: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("d1")) + .including(required: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("d2")) + .orderByPrimaryKey() + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") < 9) + .including(optional: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("d1")) + .including(required: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("d2")) + .orderByPrimaryKey() + .forKey("cs2")) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Equatable { + struct CInfo: FetchableRecord, Equatable { + var c: C + var d1: D? + var d2: D + + init(c: C, d1: D?, d2: D) { + self.c = c + self.d1 = d1 + self.d2 = d2 + } + + init(row: Row) { + self.init(c: C(row: row), d1: row["d1"], d2: row["d2"]) + } + } + var a: A + var cs1: [CInfo] + var cs2: [CInfo] + + init(a: A, cs1: [CInfo], cs2: [CInfo]) { + self.a = a + self.cs1 = cs1 + self.cs2 = cs2 + } + + init(row: Row) { + self.init(a: A(row: row), cs1: row["cs1"], cs2: row["cs2"]) + } + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs1: [], + cs2: [ + Record.CInfo( + c: C(row: ["colc1": 7, "colc2": 1]), + d1: nil, + d2: D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"])), + ]), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + cs1: [ + Record.CInfo( + c: C(row: ["colc1": 8, "colc2": 2]), + d1: D(row: ["cold1": 11, "cold2": 8, "cold3": "d2"]), + d2: D(row: ["cold1": 12, "cold2": 8, "cold3": "d3"])), + Record.CInfo( + c: C(row: ["colc1": 9, "colc2": 2]), + d1: nil, + d2: D(row: ["cold1": 13, "cold2": 9, "cold3": "d4"])), + ], + cs2: [ + Record.CInfo( + c: C(row: ["colc1": 8, "colc2": 2]), + d1: D(row: ["cold1": 11, "cold2": 8, "cold3": "d2"]), + d2: D(row: ["cold1": 12, "cold2": 8, "cold3": "d3"])), + ]), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs1: [], + cs2: [ + Record.CInfo( + c: C(row: ["colc1": 7, "colc2": 1]), + d1: nil, + d2: D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"])), + ])) + } + } + } + } + + func testIncludingAllHasManyThroughHasManyUsingHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self), using: C.hasMany(D.self)) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Equatable { + var a: A + var ds: [D] + + init(a: A, ds: [D]) { + self.a = a + self.ds = ds + } + + init(row: Row) { + self.init(a: A(row: row), ds: row["ds"]) + } + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + ds: [ + D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"]), + ]), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + ds: [ + D(row: ["cold1": 11, "cold2": 8, "cold3": "d2"]), + D(row: ["cold1": 12, "cold2": 8, "cold3": "d3"]), + D(row: ["cold1": 13, "cold2": 9, "cold3": "d4"]), + ]), + Record( + a: A(row: ["cola1": 3, "cola2": "a3"]), + ds: []), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + ds: [ + D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"]), + ])) + } + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self).filter(Column("colc1") == 8).forKey("cs1"), using: C.hasMany(D.self)) + .orderByPrimaryKey() + .forKey("ds1")) + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self).forKey("cs2"), using: C.hasMany(D.self)) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("ds2")) + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self).forKey("cs2"), using: C.hasMany(D.self)) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("ds3")) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Equatable { + var a: A + var ds1: [D] + var ds2: [D] + var ds3: [D] + + init(a: A, ds1: [D], ds2: [D], ds3: [D]) { + self.a = a + self.ds1 = ds1 + self.ds2 = ds2 + self.ds3 = ds3 + } + + init(row: Row) { + self.init(a: A(row: row), ds1: row["ds1"], ds2: row["ds2"], ds3: row["ds3"]) + } + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + ds1: [], + ds2: [ + D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"]), + ], + ds3: []), + Record( + a: A(row: ["cola1": 2, "cola2": "a2"]), + ds1: [ + D(row: ["cold1": 11, "cold2": 8, "cold3": "d2"]), + D(row: ["cold1": 12, "cold2": 8, "cold3": "d3"]), + ], + ds2: [ + D(row: ["cold1": 12, "cold2": 8, "cold3": "d3"]), + D(row: ["cold1": 13, "cold2": 9, "cold3": "d4"]), + ], + ds3: [ + D(row: ["cold1": 11, "cold2": 8, "cold3": "d2"]), + ]), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + a: A(row: ["cola1": 1, "cola2": "a1"]), + ds1: [], + ds2: [ + D(row: ["cold1": 10, "cold2": 7, "cold3": "d1"]), + ], + ds3: [])) + } + } + } + } + + // TODO: make a variant with joining(optional:) + func testIncludingOptionalBelongsToIncludingAllHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + // Plain request + do { + let request = B + .including(optional: B + .belongsTo(A.self) + .including(all: A + .hasMany(C.self) + .orderByPrimaryKey()) + ) + .orderByPrimaryKey() + + // Record (nested) + do { + struct Record: FetchableRecord, Equatable { + struct AInfo: FetchableRecord, Equatable { + var a: A + var cs: [C] + + init(a: A, cs: [C]) { + self.a = a + self.cs = cs + } + + init(row: Row) { + self.init(a: A(row: row), cs: row["cs"]) + } + } + var b: B + var a: AInfo? + + init(b: B, a: AInfo?) { + self.b = b + self.a = a + } + + init(row: Row) { + self.init(b: B(row: row), a: row["a"]) + } + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + b: B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + a: Record.AInfo( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + C(row: ["colc1": 7, "colc2": 1]), + ])), + Record( + b: B(row: ["colb1": 5, "colb2": 1, "colb3": "b2"]), + a: Record.AInfo( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + C(row: ["colc1": 7, "colc2": 1]), + ])), + Record( + b: B(row: ["colb1": 6, "colb2": 2, "colb3": "b3"]), + a: Record.AInfo( + a: A(row: ["cola1": 2, "cola2": "a2"]), + cs: [ + C(row: ["colc1": 8, "colc2": 2]), + C(row: ["colc1": 9, "colc2": 2]), + ])), + Record( + b: B(row: ["colb1": 14, "colb2": nil, "colb3": "b4"]), + a: nil), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + b: B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + a: Record.AInfo( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + C(row: ["colc1": 7, "colc2": 1]), + ]))) + } + } + + // Record (flat) + do { + struct Record: FetchableRecord, Equatable { + var b: B + var a: A? + var cs: [C] // not optional + + init(b: B, a: A?, cs: [C]) { + self.b = b + self.a = a + self.cs = cs + } + + init(row: Row) { + self.init(b: B(row: row), a: row["a"], cs: row["cs"]) + } + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + b: B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + C(row: ["colc1": 7, "colc2": 1]), + ]), + Record( + b: B(row: ["colb1": 5, "colb2": 1, "colb3": "b2"]), + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + C(row: ["colc1": 7, "colc2": 1]), + ]), + Record( + b: B(row: ["colb1": 6, "colb2": 2, "colb3": "b3"]), + a: A(row: ["cola1": 2, "cola2": "a2"]), + cs: [ + C(row: ["colc1": 8, "colc2": 2]), + C(row: ["colc1": 9, "colc2": 2]), + ]), + Record( + b: B(row: ["colb1": 14, "colb2": nil, "colb3": "b4"]), + a: nil, + cs: []), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + b: B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs: [ + C(row: ["colc1": 7, "colc2": 1]), + ])) + } + } + } + + // Request with filters + do { + let request = B + .including(optional: B + .belongsTo(A.self) + .filter(Column("cola2") == "a1") + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") == 9) + .orderByPrimaryKey() + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") != 9) + .orderByPrimaryKey() + .forKey("cs2")) + .forKey("a1")) + .including(optional: B + .belongsTo(A.self) + .filter(Column("cola2") == "a2") + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") == 9) + .orderByPrimaryKey() + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") != 9) + .orderByPrimaryKey() + .forKey("cs2")) + .forKey("a2")) + .orderByPrimaryKey() + + struct Record: FetchableRecord, Equatable { + struct AInfo: FetchableRecord, Equatable { + var a: A + var cs1: [C] + var cs2: [C] + + init(a: A, cs1: [C], cs2: [C]) { + self.a = a + self.cs1 = cs1 + self.cs2 = cs2 + } + + init(row: Row) { + self.init(a: A(row: row), cs1: row["cs1"], cs2: row["cs2"]) + } + } + var b: B + var a1: AInfo? + var a2: AInfo? + + init(b: B, a1: AInfo?, a2: AInfo?) { + self.b = b + self.a1 = a1 + self.a2 = a2 + } + + init(row: Row) { + self.init(b: B(row: row), a1: row["a1"], a2: row["a2"]) + } + } + + // Record.fetchAll + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records, [ + Record( + b: B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + a1: Record.AInfo( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs1: [], + cs2: [ + C(row: ["colc1": 7, "colc2": 1]), + ]), + a2: nil), + Record( + b: B(row: ["colb1": 5, "colb2": 1, "colb3": "b2"]), + a1: Record.AInfo( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs1: [], + cs2: [ + C(row: ["colc1": 7, "colc2": 1]), + ]), + a2: nil), + Record( + b: B(row: ["colb1": 6, "colb2": 2, "colb3": "b3"]), + a1: nil, + a2: Record.AInfo( + a: A(row: ["cola1": 2, "cola2": "a2"]), + cs1: [ + C(row: ["colc1": 9, "colc2": 2]), + ], + cs2: [ + C(row: ["colc1": 8, "colc2": 2]), + ])), + Record( + b: B(row: ["colb1": 14, "colb2": nil, "colb3": "b4"]), + a1: nil, + a2: nil), + ]) + } + + // Record.fetchOne + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record, Record( + b: B(row: ["colb1": 4, "colb2": 1, "colb3": "b1"]), + a1: Record.AInfo( + a: A(row: ["cola1": 1, "cola2": "a1"]), + cs1: [], + cs2: [ + C(row: ["colc1": 7, "colc2": 1]), + ]), + a2: nil)) + } + } + } + } +} diff --git a/Tests/GRDBTests/AssociationPrefetchingObservationTests.swift b/Tests/GRDBTests/AssociationPrefetchingObservationTests.swift new file mode 100644 index 000000000..fc37d82c3 --- /dev/null +++ b/Tests/GRDBTests/AssociationPrefetchingObservationTests.swift @@ -0,0 +1,290 @@ +import XCTest +#if GRDBCUSTOMSQLITE + import GRDBCustomSQLite +#else + import GRDB +#endif + +private struct A: TableRecord { } +private struct B: TableRecord { } +private struct C: TableRecord { } +private struct D: TableRecord { } + +class AssociationPrefetchingObservationTests: GRDBTestCase { + override func setup(_ dbWriter: DatabaseWriter) throws { + try dbWriter.write { db in + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("cola1") + t.column("cola2", .text) + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("colb1") + t.column("colb2", .integer).references("a") + t.column("colb3", .text) + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("colc1") + t.column("colc2", .integer).references("a") + } + try db.create(table: "d") { t in + t.autoIncrementedPrimaryKey("cold1") + t.column("cold2", .integer).references("c") + t.column("cold3", .text) + } + try db.execute( + sql: """ + INSERT INTO a (cola1, cola2) VALUES (?, ?); + INSERT INTO a (cola1, cola2) VALUES (?, ?); + INSERT INTO a (cola1, cola2) VALUES (?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO c (colc1, colc2) VALUES (?, ?); + INSERT INTO c (colc1, colc2) VALUES (?, ?); + INSERT INTO c (colc1, colc2) VALUES (?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + """, + arguments: [ + 1, "a1", + 2, "a2", + 3, "a3", + 4, 1, "b1", + 5, 1, "b2", + 6, 2, "b3", + 14, nil, "b4", + 7, 1, + 8, 2, + 9, 2, + 10, 7, "d1", + 11, 8, "d2", + 12, 8, "d3", + 13, 9, "d4", + ]) + } + } + + func testIncludingAllHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(B.self)) + + try XCTAssertEqual(request.databaseRegion(db).description, "a(cola1,cola2),b(colb1,colb2,colb3)") + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(B.self) + .filter(Column("colb1") == 4) + .forKey("bs1")) + .including(all: A + .hasMany(B.self) + .filter(Column("colb1") != 4) + .forKey("bs2")) + + try XCTAssertEqual(request.databaseRegion(db).description, "a(cola1,cola2),b(colb1,colb2,colb3)") + } + + // Request with altered selection + do { + let request = A + .including(all: A + .hasMany(B.self) + .select(Column("colb1"))) + + try XCTAssertEqual(request.databaseRegion(db).description, "a(cola1,cola2),b(colb1,colb2)") + } + } + } + + func testIncludingAllHasManyIncludingAllHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(C.self) + .including(all: C + .hasMany(D.self))) + + try XCTAssertEqual(request.databaseRegion(db).description, "a(cola1,cola2),c(colc1,colc2),d(cold1,cold2,cold3)") + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") > 7) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .forKey("ds1")) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .forKey("ds2")) + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") < 9) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .forKey("ds1")) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .forKey("ds2")) + .forKey("cs2")) + + try XCTAssertEqual(request.databaseRegion(db).description, "a(cola1,cola2),c(colc1,colc2),d(cold1,cold2,cold3)") + } + } + } + + func testIncludingAllHasManyIncludingRequiredOrOptionalHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(C.self) + .including(required: C + .hasMany(D.self))) + + try XCTAssertEqual(request.databaseRegion(db).description, "a(cola1,cola2),c(colc1,colc2),d(cold1,cold2,cold3)") + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") > 7) + .including(optional: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .forKey("d1")) + .including(required: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .forKey("d2")) + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") < 9) + .including(optional: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .forKey("d1")) + .including(required: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .forKey("d2")) + .forKey("cs2")) + + try XCTAssertEqual(request.databaseRegion(db).description, "a(cola1,cola2),c(colc1,colc2),d(cold1,cold2,cold3)") + } + } + } + + func testIncludingAllHasManyThroughHasManyUsingHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self), using: C.hasMany(D.self))) + + try XCTAssertEqual(request.databaseRegion(db).description, "a(cola1,cola2),c(colc1,colc2),d(cold1,cold2,cold3)") + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self).filter(Column("colc1") == 8).forKey("cs1"), using: C.hasMany(D.self)) + .forKey("ds1")) + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self).forKey("cs2"), using: C.hasMany(D.self)) + .filter(Column("cold1") != 11) + .forKey("ds2")) + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self).forKey("cs2"), using: C.hasMany(D.self)) + .filter(Column("cold1") == 11) + .forKey("ds3")) + + try XCTAssertEqual(request.databaseRegion(db).description, "a(cola1,cola2),c(colc1,colc2),d(cold1,cold2,cold3)") + } + } + } + + // TODO: make a variant with joining(optional:) + func testIncludingOptionalBelongsToIncludingAllHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + // Plain request + do { + let request = B + .including(optional: B + .belongsTo(A.self) + .including(all: A + .hasMany(C.self)) + ) + + try XCTAssert([ + "a(*),b(colb1,colb2,colb3),c(colc1,colc2)", // iOS 12 + "a(cola1,cola2),b(colb1,colb2,colb3),c(colc1,colc2)", // iOS 9 + ].contains(request.databaseRegion(db).description)) + } + + // Request with filters + do { + let request = B + .including(optional: B + .belongsTo(A.self) + .filter(Column("cola2") == "a1") + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") == 9) + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") != 9) + .forKey("cs2")) + .forKey("a1")) + .including(optional: B + .belongsTo(A.self) + .filter(Column("cola2") == "a2") + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") == 9) + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") != 9) + .forKey("cs2")) + .forKey("a2")) + + try XCTAssertEqual(request.databaseRegion(db).description, "a(cola1,cola2),b(colb1,colb2,colb3),c(colc1,colc2)") + } + } + } +} diff --git a/Tests/GRDBTests/AssociationPrefetchingRowTests.swift b/Tests/GRDBTests/AssociationPrefetchingRowTests.swift new file mode 100644 index 000000000..8413ce108 --- /dev/null +++ b/Tests/GRDBTests/AssociationPrefetchingRowTests.swift @@ -0,0 +1,1074 @@ +import XCTest +#if GRDBCUSTOMSQLITE + import GRDBCustomSQLite +#else + import GRDB +#endif + +private struct A: TableRecord { } +private struct B: TableRecord { } +private struct C: TableRecord { } +private struct D: TableRecord { } + +class AssociationPrefetchingRowTests: GRDBTestCase { + override func setup(_ dbWriter: DatabaseWriter) throws { + try dbWriter.write { db in + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("cola1") + t.column("cola2", .text) + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("colb1") + t.column("colb2", .integer).references("a") + t.column("colb3", .text) + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("colc1") + t.column("colc2", .integer).references("a") + } + try db.create(table: "d") { t in + t.autoIncrementedPrimaryKey("cold1") + t.column("cold2", .integer).references("c") + t.column("cold3", .text) + } + try db.execute( + sql: """ + INSERT INTO a (cola1, cola2) VALUES (?, ?); + INSERT INTO a (cola1, cola2) VALUES (?, ?); + INSERT INTO a (cola1, cola2) VALUES (?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO c (colc1, colc2) VALUES (?, ?); + INSERT INTO c (colc1, colc2) VALUES (?, ?); + INSERT INTO c (colc1, colc2) VALUES (?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + """, + arguments: [ + 1, "a1", + 2, "a2", + 3, "a3", + 4, 1, "b1", + 5, 1, "b2", + 6, 2, "b3", + 14, nil, "b4", + 7, 1, + 8, 2, + 9, 2, + 10, 7, "d1", + 11, 8, "d2", + 12, 8, "d3", + 13, 9, "d4", + ]) + } + } + + func testIncludingAllHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(B.self) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + // Row.fetchAll + do { + let rows = try Row.fetchAll(db, request) + XCTAssertEqual(rows.count, 3) + + XCTAssertEqual(rows[0].description, "[cola1:1 cola2:\"a1\"]") + XCTAssertEqual(rows[0].debugDescription, """ + ▿ [cola1:1 cola2:"a1"] + + bs: 2 rows + """) + + XCTAssertEqual(rows[0].unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(rows[0].prefetchedRows.keys, ["bs"]) + XCTAssertEqual(rows[0].prefetchedRows["bs"]!.count, 2) + XCTAssertEqual(rows[0].prefetchedRows["bs"]![0], ["colb1": 4, "colb2": 1, "colb3": "b1", "grdb_colb2": 1]) + XCTAssertEqual(rows[0].prefetchedRows["bs"]![1], ["colb1": 5, "colb2": 1, "colb3": "b2", "grdb_colb2": 1]) + + XCTAssertEqual(rows[1].unscoped, ["cola1": 2, "cola2": "a2"]) + XCTAssertEqual(rows[1].prefetchedRows.keys, ["bs"]) + XCTAssertEqual(rows[1].prefetchedRows["bs"]!.count, 1) + XCTAssertEqual(rows[1].prefetchedRows["bs"]![0], ["colb1": 6, "colb2": 2, "colb3": "b3", "grdb_colb2": 2]) + + XCTAssertEqual(rows[2].unscoped, ["cola1": 3, "cola2": "a3"]) + XCTAssertEqual(rows[2].prefetchedRows.keys, ["bs"]) + XCTAssertEqual(rows[2].prefetchedRows["bs"]!.count, 0) + } + + // Row.fetchOne + do { + let row = try Row.fetchOne(db, request)! + + XCTAssertEqual(row.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(row.prefetchedRows.keys, ["bs"]) + XCTAssertEqual(row.prefetchedRows["bs"]!.count, 2) + XCTAssertEqual(row.prefetchedRows["bs"]![0], ["colb1": 4, "colb2": 1, "colb3": "b1", "grdb_colb2": 1]) + XCTAssertEqual(row.prefetchedRows["bs"]![1], ["colb1": 5, "colb2": 1, "colb3": "b2", "grdb_colb2": 1]) + } + } + + // Request with avoided prefetch + do { + let request = A + .filter(false) + .including(all: A + .hasMany(B.self) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + // Row.fetchAll + do { + let rows = try Row.fetchAll(db, request) + XCTAssertEqual(rows.count, 0) + } + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(B.self) + .filter(Column("colb1") == 4) + .orderByPrimaryKey() + .forKey("bs1")) + .including(all: A + .hasMany(B.self) + .filter(Column("colb1") != 4) + .orderByPrimaryKey() + .forKey("bs2")) + .orderByPrimaryKey() + + // Row.fetchAll + do { + let rows = try Row.fetchAll(db, request) + XCTAssertEqual(rows.count, 2) + + XCTAssertEqual(rows[0].description, "[cola1:1 cola2:\"a1\"]") + XCTAssertEqual(rows[0].debugDescription, """ + ▿ [cola1:1 cola2:"a1"] + + bs1: 1 row + + bs2: 1 row + """) + + XCTAssertEqual(rows[0].unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(rows[0].prefetchedRows.keys, ["bs1", "bs2"]) + XCTAssertEqual(rows[0].prefetchedRows["bs1"]!.count, 1) + XCTAssertEqual(rows[0].prefetchedRows["bs1"]![0], ["colb1": 4, "colb2": 1, "colb3": "b1", "grdb_colb2": 1]) + XCTAssertEqual(rows[0].prefetchedRows["bs2"]!.count, 1) + XCTAssertEqual(rows[0].prefetchedRows["bs2"]![0], ["colb1": 5, "colb2": 1, "colb3": "b2", "grdb_colb2": 1]) + + XCTAssertEqual(rows[1].unscoped, ["cola1": 2, "cola2": "a2"]) + XCTAssertEqual(rows[1].prefetchedRows.keys, ["bs1", "bs2"]) + XCTAssertEqual(rows[1].prefetchedRows["bs1"]!.count, 0) + XCTAssertEqual(rows[1].prefetchedRows["bs2"]!.count, 1) + XCTAssertEqual(rows[1].prefetchedRows["bs2"]![0], ["colb1": 6, "colb2": 2, "colb3": "b3", "grdb_colb2": 2]) + } + + // Row.fetchOne + do { + let row = try Row.fetchOne(db, request)! + + XCTAssertEqual(row.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(row.prefetchedRows.keys, ["bs1", "bs2"]) + XCTAssertEqual(row.prefetchedRows["bs1"]!.count, 1) + XCTAssertEqual(row.prefetchedRows["bs1"]![0], ["colb1": 4, "colb2": 1, "colb3": "b1", "grdb_colb2": 1]) + XCTAssertEqual(row.prefetchedRows["bs2"]!.count, 1) + XCTAssertEqual(row.prefetchedRows["bs2"]![0], ["colb1": 5, "colb2": 1, "colb3": "b2", "grdb_colb2": 1]) + } + } + } + } + + func testIncludingAllHasManyIncludingAllHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(C.self) + .including(all: C + .hasMany(D.self) + .orderByPrimaryKey()) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + // Row.fetchAll + do { + let rows = try Row.fetchAll(db, request) + XCTAssertEqual(rows.count, 3) + + XCTAssertEqual(rows[0].description, "[cola1:1 cola2:\"a1\"]") + XCTAssertEqual(rows[0].debugDescription, """ + ▿ [cola1:1 cola2:"a1"] + + cs: 1 row + """) + + XCTAssertEqual(rows[0].unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(rows[0].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[0].prefetchedRows["cs"]!.count, 1) + XCTAssertEqual(rows[0].prefetchedRows["cs"]![0].unscoped, ["colc1": 7, "colc2": 1, "grdb_colc2": 1]) + XCTAssertEqual(rows[0].prefetchedRows["cs"]![0].prefetchedRows.keys, ["ds"]) + XCTAssertEqual(rows[0].prefetchedRows["cs"]![0].prefetchedRows["ds"]!.count, 1) + XCTAssertEqual(rows[0].prefetchedRows["cs"]![0].prefetchedRows["ds"]![0], ["cold1": 10, "cold2": 7, "cold3": "d1", "grdb_cold2": 7]) + + XCTAssertEqual(rows[1].unscoped, ["cola1": 2, "cola2": "a2"]) + XCTAssertEqual(rows[1].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[1].prefetchedRows["cs"]!.count, 2) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![0].unscoped, ["colc1": 8, "colc2": 2, "grdb_colc2": 2]) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![0].prefetchedRows.keys, ["ds"]) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![0].prefetchedRows["ds"]!.count, 2) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![0].prefetchedRows["ds"]![0], ["cold1": 11, "cold2": 8, "cold3": "d2", "grdb_cold2": 8]) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![0].prefetchedRows["ds"]![1], ["cold1": 12, "cold2": 8, "cold3": "d3", "grdb_cold2": 8]) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![1].unscoped, ["colc1": 9, "colc2": 2, "grdb_colc2": 2]) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![1].prefetchedRows.keys, ["ds"]) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![1].prefetchedRows["ds"]!.count, 1) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![1].prefetchedRows["ds"]![0], ["cold1": 13, "cold2": 9, "cold3": "d4", "grdb_cold2": 9]) + + XCTAssertEqual(rows[2].unscoped, ["cola1": 3, "cola2": "a3"]) + XCTAssertEqual(rows[2].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[2].prefetchedRows["cs"]!.count, 0) + } + + // Row.fetchOne + do { + let row = try Row.fetchOne(db, request)! + + XCTAssertEqual(row.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(row.prefetchedRows.keys, ["cs"]) + XCTAssertEqual(row.prefetchedRows["cs"]!.count, 1) + XCTAssertEqual(row.prefetchedRows["cs"]![0].unscoped, ["colc1": 7, "colc2": 1, "grdb_colc2": 1]) + XCTAssertEqual(row.prefetchedRows["cs"]![0].prefetchedRows.keys, ["ds"]) + XCTAssertEqual(row.prefetchedRows["cs"]![0].prefetchedRows["ds"]!.count, 1) + XCTAssertEqual(row.prefetchedRows["cs"]![0].prefetchedRows["ds"]![0], ["cold1": 10, "cold2": 7, "cold3": "d1", "grdb_cold2": 7]) + } + } + + // Request with avoided prefetch + do { + let request = A + .including(all: A + .hasMany(C.self) + .filter(false) + .including(all: C + .hasMany(D.self) + .orderByPrimaryKey()) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + // Row.fetchAll + do { + let rows = try Row.fetchAll(db, request) + XCTAssertEqual(rows.count, 3) + + XCTAssertEqual(rows[0].description, "[cola1:1 cola2:\"a1\"]") + XCTAssertEqual(rows[0].debugDescription, """ + ▿ [cola1:1 cola2:"a1"] + + cs: 0 row + """) + + XCTAssertEqual(rows[0].unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(rows[0].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[0].prefetchedRows["cs"]!.count, 0) + + XCTAssertEqual(rows[1].unscoped, ["cola1": 2, "cola2": "a2"]) + XCTAssertEqual(rows[1].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[1].prefetchedRows["cs"]!.count, 0) + + XCTAssertEqual(rows[2].unscoped, ["cola1": 3, "cola2": "a3"]) + XCTAssertEqual(rows[2].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[2].prefetchedRows["cs"]!.count, 0) + } + + // Row.fetchOne + do { + let row = try Row.fetchOne(db, request)! + + XCTAssertEqual(row.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(row.prefetchedRows.keys, ["cs"]) + XCTAssertEqual(row.prefetchedRows["cs"]!.count, 0) + } + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") > 7) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("ds1")) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("ds2")) + .orderByPrimaryKey() + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") < 9) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("ds1")) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("ds2")) + .orderByPrimaryKey() + .forKey("cs2")) + .orderByPrimaryKey() + + // Row.fetchAll + do { + let rows = try Row.fetchAll(db, request) + XCTAssertEqual(rows.count, 2) + + XCTAssertEqual(rows[0].description, "[cola1:1 cola2:\"a1\"]") + XCTAssertEqual(rows[0].debugDescription, """ + ▿ [cola1:1 cola2:"a1"] + + cs1: 0 row + + cs2: 1 row + """) + + XCTAssertEqual(rows[0].unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(rows[0].prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(rows[0].prefetchedRows["cs1"]!.count, 0) + XCTAssertEqual(rows[0].prefetchedRows["cs2"]!.count, 1) + XCTAssertEqual(rows[0].prefetchedRows["cs2"]![0].unscoped, ["colc1": 7, "colc2": 1, "grdb_colc2": 1]) + XCTAssertEqual(rows[0].prefetchedRows["cs2"]![0].prefetchedRows.keys, ["ds1", "ds2"]) + XCTAssertEqual(rows[0].prefetchedRows["cs2"]![0].prefetchedRows["ds1"]!.count, 0) + XCTAssertEqual(rows[0].prefetchedRows["cs2"]![0].prefetchedRows["ds2"]!.count, 1) + XCTAssertEqual(rows[0].prefetchedRows["cs2"]![0].prefetchedRows["ds2"]![0], ["cold1": 10, "cold2": 7, "cold3": "d1", "grdb_cold2": 7]) + + XCTAssertEqual(rows[1].unscoped, ["cola1": 2, "cola2": "a2"]) + XCTAssertEqual(rows[1].prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]!.count, 2) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![0].unscoped, ["colc1": 8, "colc2": 2, "grdb_colc2": 2]) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![0].prefetchedRows.keys, ["ds1", "ds2"]) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![0].prefetchedRows["ds1"]!.count, 1) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![0].prefetchedRows["ds1"]![0], ["cold1": 11, "cold2": 8, "cold3": "d2", "grdb_cold2": 8]) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![0].prefetchedRows["ds2"]!.count, 1) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![0].prefetchedRows["ds2"]![0], ["cold1": 12, "cold2": 8, "cold3": "d3", "grdb_cold2": 8]) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![1].unscoped, ["colc1": 9, "colc2": 2, "grdb_colc2": 2]) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![1].prefetchedRows.keys, ["ds1", "ds2"]) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![1].prefetchedRows["ds1"]!.count, 0) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![1].prefetchedRows["ds2"]!.count, 1) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![1].prefetchedRows["ds2"]![0], ["cold1": 13, "cold2": 9, "cold3": "d4", "grdb_cold2": 9]) + XCTAssertEqual(rows[1].prefetchedRows["cs2"]!.count, 1) + XCTAssertEqual(rows[1].prefetchedRows["cs2"]![0].unscoped, ["colc1": 8, "colc2": 2, "grdb_colc2": 2]) + XCTAssertEqual(rows[1].prefetchedRows["cs2"]![0].prefetchedRows.keys, ["ds1", "ds2"]) + XCTAssertEqual(rows[1].prefetchedRows["cs2"]![0].prefetchedRows["ds1"]!.count, 1) + XCTAssertEqual(rows[1].prefetchedRows["cs2"]![0].prefetchedRows["ds1"]![0], ["cold1": 11, "cold2": 8, "cold3": "d2", "grdb_cold2": 8]) + XCTAssertEqual(rows[1].prefetchedRows["cs2"]![0].prefetchedRows["ds2"]!.count, 1) + XCTAssertEqual(rows[1].prefetchedRows["cs2"]![0].prefetchedRows["ds2"]![0], ["cold1": 12, "cold2": 8, "cold3": "d3", "grdb_cold2": 8]) + } + + // Row.fetchOne + do { + let row = try Row.fetchOne(db, request)! + + XCTAssertEqual(row.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(row.prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(row.prefetchedRows["cs1"]!.count, 0) + XCTAssertEqual(row.prefetchedRows["cs2"]!.count, 1) + XCTAssertEqual(row.prefetchedRows["cs2"]![0].unscoped, ["colc1": 7, "colc2": 1, "grdb_colc2": 1]) + XCTAssertEqual(row.prefetchedRows["cs2"]![0].prefetchedRows.keys, ["ds1", "ds2"]) + XCTAssertEqual(row.prefetchedRows["cs2"]![0].prefetchedRows["ds1"]!.count, 0) + XCTAssertEqual(row.prefetchedRows["cs2"]![0].prefetchedRows["ds2"]!.count, 1) + XCTAssertEqual(row.prefetchedRows["cs2"]![0].prefetchedRows["ds2"]![0], ["cold1": 10, "cold2": 7, "cold3": "d1", "grdb_cold2": 7]) + } + } + } + } + + func testIncludingAllHasManyIncludingRequiredOrOptionalHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(C.self) + .including(required: C + .hasMany(D.self) + .orderByPrimaryKey()) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + // Row.fetchAll + do { + let rows = try Row.fetchAll(db, request) + XCTAssertEqual(rows.count, 3) + + XCTAssertEqual(rows[0].description, "[cola1:1 cola2:\"a1\"]") + XCTAssertEqual(rows[0].debugDescription, """ + ▿ [cola1:1 cola2:"a1"] + + cs: 1 row + """) + + XCTAssertEqual(rows[0].unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(rows[0].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[0].prefetchedRows["cs"]!.count, 1) + XCTAssertEqual(rows[0].prefetchedRows["cs"]![0].unscoped, ["colc1": 7, "colc2": 1, "grdb_colc2": 1]) + XCTAssertEqual(rows[0].prefetchedRows["cs"]![0].scopes.count, 1) + XCTAssertEqual(rows[0].prefetchedRows["cs"]![0].scopes["d"], ["cold1": 10, "cold2": 7, "cold3": "d1"]) + + XCTAssertEqual(rows[1].unscoped, ["cola1": 2, "cola2": "a2"]) + XCTAssertEqual(rows[1].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[1].prefetchedRows["cs"]!.count, 3) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![0].unscoped, ["colc1": 8, "colc2": 2, "grdb_colc2": 2]) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![0].scopes.count, 1) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![0].scopes["d"], ["cold1": 11, "cold2": 8, "cold3": "d2"]) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![1].unscoped, ["colc1": 8, "colc2": 2, "grdb_colc2": 2]) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![1].scopes.count, 1) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![1].scopes["d"], ["cold1": 12, "cold2": 8, "cold3": "d3"]) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![2].unscoped, ["colc1": 9, "colc2": 2, "grdb_colc2": 2]) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![2].scopes.count, 1) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![2].scopes["d"], ["cold1": 13, "cold2": 9, "cold3": "d4"]) + + XCTAssertEqual(rows[2].unscoped, ["cola1": 3, "cola2": "a3"]) + XCTAssertEqual(rows[2].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[2].prefetchedRows["cs"]!.count, 0) + } + + // Row.fetchOne + do { + let row = try Row.fetchOne(db, request)! + + XCTAssertEqual(row.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(row.prefetchedRows.keys, ["cs"]) + XCTAssertEqual(row.prefetchedRows["cs"]!.count, 1) + XCTAssertEqual(row.prefetchedRows["cs"]![0].unscoped, ["colc1": 7, "colc2": 1, "grdb_colc2": 1]) + XCTAssertEqual(row.prefetchedRows["cs"]![0].scopes.count, 1) + XCTAssertEqual(row.prefetchedRows["cs"]![0].scopes["d"], ["cold1": 10, "cold2": 7, "cold3": "d1"]) + } + } + + // Request with avoided prefetch + do { + let request = A + .including(all: A + .hasMany(C.self) + .filter(false) + .including(required: C + .hasMany(D.self) + .orderByPrimaryKey()) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + // Row.fetchAll + do { + let rows = try Row.fetchAll(db, request) + XCTAssertEqual(rows.count, 3) + + XCTAssertEqual(rows[0].description, "[cola1:1 cola2:\"a1\"]") + XCTAssertEqual(rows[0].debugDescription, """ + ▿ [cola1:1 cola2:"a1"] + + cs: 0 row + """) + + XCTAssertEqual(rows[0].unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(rows[0].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[0].prefetchedRows["cs"]!.count, 0) + + XCTAssertEqual(rows[1].unscoped, ["cola1": 2, "cola2": "a2"]) + XCTAssertEqual(rows[1].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[1].prefetchedRows["cs"]!.count, 0) + + XCTAssertEqual(rows[2].unscoped, ["cola1": 3, "cola2": "a3"]) + XCTAssertEqual(rows[2].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[2].prefetchedRows["cs"]!.count, 0) + } + + // Row.fetchOne + do { + let row = try Row.fetchOne(db, request)! + + XCTAssertEqual(row.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(row.prefetchedRows.keys, ["cs"]) + XCTAssertEqual(row.prefetchedRows["cs"]!.count, 0) + } + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") > 7) + .including(optional: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("ds1")) + .including(required: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("ds2")) + .orderByPrimaryKey() + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") < 9) + .including(optional: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("ds1")) + .including(required: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("ds2")) + .orderByPrimaryKey() + .forKey("cs2")) + .orderByPrimaryKey() + + // Row.fetchAll + do { + let rows = try Row.fetchAll(db, request) + XCTAssertEqual(rows.count, 2) + + XCTAssertEqual(rows[0].description, "[cola1:1 cola2:\"a1\"]") + XCTAssertEqual(rows[0].debugDescription, """ + ▿ [cola1:1 cola2:"a1"] + + cs1: 0 row + + cs2: 1 row + """) + + XCTAssertEqual(rows[0].unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(rows[0].prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(rows[0].prefetchedRows["cs1"]!.count, 0) + XCTAssertEqual(rows[0].prefetchedRows["cs2"]!.count, 1) + XCTAssertEqual(rows[0].prefetchedRows["cs2"]![0].unscoped, ["colc1": 7, "colc2": 1, "grdb_colc2": 1]) + XCTAssertEqual(rows[0].prefetchedRows["cs2"]![0].scopes.count, 2) + XCTAssertEqual(rows[0].prefetchedRows["cs2"]![0].scopes["d1"], ["cold1": nil, "cold2": nil, "cold3": nil]) + XCTAssertEqual(rows[0].prefetchedRows["cs2"]![0].scopes["d2"], ["cold1": 10, "cold2": 7, "cold3": "d1"]) + + XCTAssertEqual(rows[1].unscoped, ["cola1": 2, "cola2": "a2"]) + XCTAssertEqual(rows[1].prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]!.count, 2) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![0].unscoped, ["colc1": 8, "colc2": 2, "grdb_colc2": 2]) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![0].scopes.count, 2) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![0].scopes["d1"], ["cold1": 11, "cold2": 8, "cold3": "d2"]) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![0].scopes["d2"], ["cold1": 12, "cold2": 8, "cold3": "d3"]) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![1].unscoped, ["colc1": 9, "colc2": 2, "grdb_colc2": 2]) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![1].scopes.count, 2) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![1].scopes["d1"], ["cold1": nil, "cold2": nil, "cold3": nil]) + XCTAssertEqual(rows[1].prefetchedRows["cs1"]![1].scopes["d2"], ["cold1": 13, "cold2": 9, "cold3": "d4"]) + XCTAssertEqual(rows[1].prefetchedRows["cs2"]!.count, 1) + XCTAssertEqual(rows[1].prefetchedRows["cs2"]![0].unscoped, ["colc1": 8, "colc2": 2, "grdb_colc2": 2]) + XCTAssertEqual(rows[1].prefetchedRows["cs2"]![0].scopes.count, 2) + XCTAssertEqual(rows[1].prefetchedRows["cs2"]![0].scopes["d1"], ["cold1": 11, "cold2": 8, "cold3": "d2"]) + XCTAssertEqual(rows[1].prefetchedRows["cs2"]![0].scopes["d2"], ["cold1": 12, "cold2": 8, "cold3": "d3"]) + } + + // Row.fetchOne + do { + let row = try Row.fetchOne(db, request)! + + XCTAssertEqual(row.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(row.prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(row.prefetchedRows["cs1"]!.count, 0) + XCTAssertEqual(row.prefetchedRows["cs2"]!.count, 1) + XCTAssertEqual(row.prefetchedRows["cs2"]![0].unscoped, ["colc1": 7, "colc2": 1, "grdb_colc2": 1]) + XCTAssertEqual(row.prefetchedRows["cs2"]![0].scopes.count, 2) + XCTAssertEqual(row.prefetchedRows["cs2"]![0].scopes["d1"], ["cold1": nil, "cold2": nil, "cold3": nil]) + XCTAssertEqual(row.prefetchedRows["cs2"]![0].scopes["d2"], ["cold1": 10, "cold2": 7, "cold3": "d1"]) + } + } + } + } + + func testIncludingAllHasManyThroughHasManyUsingHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self), using: C.hasMany(D.self)) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + // Row.fetchAll + do { + let rows = try Row.fetchAll(db, request) + XCTAssertEqual(rows.count, 3) + + XCTAssertEqual(rows[0].description, "[cola1:1 cola2:\"a1\"]") + XCTAssertEqual(rows[0].debugDescription, """ + ▿ [cola1:1 cola2:"a1"] + + ds: 1 row + """) + + XCTAssertEqual(rows[0].unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(rows[0].prefetchedRows.keys, ["ds"]) + XCTAssertEqual(rows[0].prefetchedRows["ds"]!.count, 1) + XCTAssertEqual(rows[0].prefetchedRows["ds"]![0], ["cold1": 10, "cold2": 7, "cold3": "d1", "grdb_colc2": 1]) + + XCTAssertEqual(rows[1].unscoped, ["cola1": 2, "cola2": "a2"]) + XCTAssertEqual(rows[1].prefetchedRows.keys, ["ds"]) + XCTAssertEqual(rows[1].prefetchedRows["ds"]!.count, 3) + XCTAssertEqual(rows[1].prefetchedRows["ds"]![0], ["cold1": 11, "cold2": 8, "cold3": "d2", "grdb_colc2": 2]) + XCTAssertEqual(rows[1].prefetchedRows["ds"]![1], ["cold1": 12, "cold2": 8, "cold3": "d3", "grdb_colc2": 2]) + XCTAssertEqual(rows[1].prefetchedRows["ds"]![2], ["cold1": 13, "cold2": 9, "cold3": "d4", "grdb_colc2": 2]) + + XCTAssertEqual(rows[2].unscoped, ["cola1": 3, "cola2": "a3"]) + XCTAssertEqual(rows[2].prefetchedRows.keys, ["ds"]) + XCTAssertEqual(rows[2].prefetchedRows["ds"]!.count, 0) + } + + // Row.fetchOne + do { + let row = try Row.fetchOne(db, request)! + + XCTAssertEqual(row.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(row.prefetchedRows.keys, ["ds"]) + XCTAssertEqual(row.prefetchedRows["ds"]!.count, 1) + XCTAssertEqual(row.prefetchedRows["ds"]![0], ["cold1": 10, "cold2": 7, "cold3": "d1", "grdb_colc2": 1]) + } + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self).filter(Column("colc1") == 8).forKey("cs1"), using: C.hasMany(D.self)) + .orderByPrimaryKey() + .forKey("ds1")) + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self).forKey("cs2"), using: C.hasMany(D.self)) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("ds2")) + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self).forKey("cs2"), using: C.hasMany(D.self)) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("ds3")) + .orderByPrimaryKey() + + // Row.fetchAll + do { + let rows = try Row.fetchAll(db, request) + XCTAssertEqual(rows.count, 2) + + XCTAssertEqual(rows[0].description, "[cola1:1 cola2:\"a1\"]") + XCTAssertEqual(rows[0].debugDescription, """ + ▿ [cola1:1 cola2:"a1"] + + ds1: 0 row + + ds2: 1 row + + ds3: 0 row + """) + + XCTAssertEqual(rows[0].unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(rows[0].prefetchedRows.keys, ["ds1", "ds2", "ds3"]) + XCTAssertEqual(rows[0].prefetchedRows["ds1"]!.count, 0) + XCTAssertEqual(rows[0].prefetchedRows["ds2"]!.count, 1) + XCTAssertEqual(rows[0].prefetchedRows["ds2"]![0], ["cold1": 10, "cold2": 7, "cold3": "d1", "grdb_colc2": 1]) + XCTAssertEqual(rows[0].prefetchedRows["ds3"]!.count, 0) + + XCTAssertEqual(rows[1].unscoped, ["cola1": 2, "cola2": "a2"]) + XCTAssertEqual(rows[1].prefetchedRows.keys, ["ds1", "ds2", "ds3"]) + XCTAssertEqual(rows[1].prefetchedRows["ds1"]!.count, 2) + XCTAssertEqual(rows[1].prefetchedRows["ds1"]![0], ["cold1": 11, "cold2": 8, "cold3": "d2", "grdb_colc2": 2]) + XCTAssertEqual(rows[1].prefetchedRows["ds1"]![1], ["cold1": 12, "cold2": 8, "cold3": "d3", "grdb_colc2": 2]) + XCTAssertEqual(rows[1].prefetchedRows["ds2"]!.count, 2) + XCTAssertEqual(rows[1].prefetchedRows["ds2"]![0], ["cold1": 12, "cold2": 8, "cold3": "d3", "grdb_colc2": 2]) + XCTAssertEqual(rows[1].prefetchedRows["ds2"]![1], ["cold1": 13, "cold2": 9, "cold3": "d4", "grdb_colc2": 2]) + XCTAssertEqual(rows[1].prefetchedRows["ds3"]!.count, 1) + XCTAssertEqual(rows[1].prefetchedRows["ds3"]![0], ["cold1": 11, "cold2": 8, "cold3": "d2", "grdb_colc2": 2]) + } + + // Row.fetchOne + do { + let row = try Row.fetchOne(db, request)! + + XCTAssertEqual(row.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(row.prefetchedRows.keys, ["ds1", "ds2", "ds3"]) + XCTAssertEqual(row.prefetchedRows["ds1"]!.count, 0) + XCTAssertEqual(row.prefetchedRows["ds2"]!.count, 1) + XCTAssertEqual(row.prefetchedRows["ds2"]![0], ["cold1": 10, "cold2": 7, "cold3": "d1", "grdb_colc2": 1]) + XCTAssertEqual(row.prefetchedRows["ds3"]!.count, 0) + } + } + } + } + + func testIncludingAllHasManyThroughBelongsToUsingHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = B + .including(all: B + .hasMany(C.self, through: B.belongsTo(A.self), using: A.hasMany(C.self)) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + // Row.fetchAll + do { + let rows = try Row.fetchAll(db, request) + XCTAssertEqual(rows.count, 4) + + XCTAssertEqual(rows[0].description, "[colb1:4 colb2:1 colb3:\"b1\"]") + XCTAssertEqual(rows[0].debugDescription, """ + ▿ [colb1:4 colb2:1 colb3:"b1"] + + cs: 1 row + """) + + XCTAssertEqual(rows[0].unscoped, ["colb1": 4, "colb2": 1, "colb3": "b1"]) + XCTAssertEqual(rows[0].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[0].prefetchedRows["cs"]!.count, 1) + XCTAssertEqual(rows[0].prefetchedRows["cs"]![0], ["colc1": 7, "colc2": 1, "grdb_cola1": 1]) + XCTAssert(rows[0].scopes.isEmpty) + + XCTAssertEqual(rows[1].unscoped, ["colb1": 5, "colb2": 1, "colb3": "b2"]) + XCTAssertEqual(rows[1].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[1].prefetchedRows["cs"]!.count, 1) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![0], ["colc1": 7, "colc2": 1, "grdb_cola1": 1]) + XCTAssert(rows[1].scopes.isEmpty) + + XCTAssertEqual(rows[2].unscoped, ["colb1": 6, "colb2": 2, "colb3": "b3"]) + XCTAssertEqual(rows[2].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[2].prefetchedRows["cs"]!.count, 2) + XCTAssertEqual(rows[2].prefetchedRows["cs"]![0], ["colc1": 8, "colc2": 2, "grdb_cola1": 2]) + XCTAssertEqual(rows[2].prefetchedRows["cs"]![1], ["colc1": 9, "colc2": 2, "grdb_cola1": 2]) + XCTAssert(rows[2].scopes.isEmpty) + + XCTAssertEqual(rows[3].unscoped, ["colb1": 14, "colb2": nil, "colb3": "b4"]) + XCTAssertEqual(rows[3].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[3].prefetchedRows["cs"]!.count, 0) + XCTAssert(rows[3].scopes.isEmpty) + } + + // Row.fetchOne + do { + let row = try Row.fetchOne(db, request)! + + XCTAssertEqual(row.unscoped, ["colb1": 4, "colb2": 1, "colb3": "b1"]) + XCTAssertEqual(row.prefetchedRows.keys, ["cs"]) + XCTAssertEqual(row.prefetchedRows["cs"]!.count, 1) + XCTAssertEqual(row.prefetchedRows["cs"]![0], ["colc1": 7, "colc2": 1, "grdb_cola1": 1]) + XCTAssert(row.scopes.isEmpty) + } + } + } + } + + // TODO: make a variant with joining(optional:) + func testIncludingOptionalBelongsToIncludingAllHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + // Plain request + do { + let request = B + .including(optional: B + .belongsTo(A.self) + .including(all: A + .hasMany(C.self) + .orderByPrimaryKey()) + ) + .orderByPrimaryKey() + + // Row.fetchAll + do { + let rows = try Row.fetchAll(db, request) + XCTAssertEqual(rows.count, 4) + + XCTAssertEqual(rows[0].description, "[colb1:4 colb2:1 colb3:\"b1\"]") + XCTAssertEqual(rows[0].debugDescription, """ + ▿ [colb1:4 colb2:1 colb3:"b1"] + unadapted: [colb1:4 colb2:1 colb3:"b1" cola1:1 cola2:"a1"] + - a: [cola1:1 cola2:"a1"] + + cs: 1 row + + cs: 1 row + """) + + XCTAssertEqual(rows[0].unscoped, ["colb1": 4, "colb2": 1, "colb3": "b1"]) + XCTAssertEqual(rows[0].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[0].prefetchedRows["cs"]!.count, 1) + XCTAssertEqual(rows[0].prefetchedRows["cs"]![0], ["colc1": 7, "colc2": 1, "grdb_cola1": 1]) + XCTAssertEqual(rows[0].scopes.count, 1) + XCTAssertEqual(rows[0].scopes["a"]!.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(rows[0].scopes["a"]!.prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[0].scopes["a"]!.prefetchedRows["cs"]!.count, 1) + XCTAssertEqual(rows[0].scopes["a"]!.prefetchedRows["cs"]![0], ["colc1": 7, "colc2": 1, "grdb_cola1": 1]) + + XCTAssertEqual(rows[1].unscoped, ["colb1": 5, "colb2": 1, "colb3": "b2"]) + XCTAssertEqual(rows[1].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[1].prefetchedRows["cs"]!.count, 1) + XCTAssertEqual(rows[1].prefetchedRows["cs"]![0], ["colc1": 7, "colc2": 1, "grdb_cola1": 1]) + XCTAssertEqual(rows[1].scopes.count, 1) + XCTAssertEqual(rows[1].scopes["a"]!.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(rows[1].scopes["a"]!.prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[1].scopes["a"]!.prefetchedRows["cs"]!.count, 1) + XCTAssertEqual(rows[1].scopes["a"]!.prefetchedRows["cs"]![0], ["colc1": 7, "colc2": 1, "grdb_cola1": 1]) + + XCTAssertEqual(rows[2].unscoped, ["colb1": 6, "colb2": 2, "colb3": "b3"]) + XCTAssertEqual(rows[2].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[2].prefetchedRows["cs"]!.count, 2) + XCTAssertEqual(rows[2].prefetchedRows["cs"]![0], ["colc1": 8, "colc2": 2, "grdb_cola1": 2]) + XCTAssertEqual(rows[2].prefetchedRows["cs"]![1], ["colc1": 9, "colc2": 2, "grdb_cola1": 2]) + XCTAssertEqual(rows[2].scopes.count, 1) + XCTAssertEqual(rows[2].scopes["a"]!.unscoped, ["cola1": 2, "cola2": "a2"]) + XCTAssertEqual(rows[2].scopes["a"]!.prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[2].scopes["a"]!.prefetchedRows["cs"]!.count, 2) + XCTAssertEqual(rows[2].scopes["a"]!.prefetchedRows["cs"]![0], ["colc1": 8, "colc2": 2, "grdb_cola1": 2]) + XCTAssertEqual(rows[2].scopes["a"]!.prefetchedRows["cs"]![1], ["colc1": 9, "colc2": 2, "grdb_cola1": 2]) + + XCTAssertEqual(rows[3].unscoped, ["colb1": 14, "colb2": nil, "colb3": "b4"]) + XCTAssertEqual(rows[3].prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[3].prefetchedRows["cs"]!.count, 0) + XCTAssertEqual(rows[3].scopes.count, 1) + XCTAssertEqual(rows[3].scopes["a"]!.unscoped, ["cola1": nil, "cola2": nil]) + XCTAssertEqual(rows[3].scopes["a"]!.prefetchedRows.keys, ["cs"]) + XCTAssertEqual(rows[3].scopes["a"]!.prefetchedRows["cs"]!.count, 0) + } + + // Row.fetchOne + do { + let row = try Row.fetchOne(db, request)! + + XCTAssertEqual(row.unscoped, ["colb1": 4, "colb2": 1, "colb3": "b1"]) + XCTAssertEqual(row.prefetchedRows.keys, ["cs"]) + XCTAssertEqual(row.prefetchedRows["cs"]!.count, 1) + XCTAssertEqual(row.prefetchedRows["cs"]![0], ["colc1": 7, "colc2": 1, "grdb_cola1": 1]) + XCTAssertEqual(row.scopes.count, 1) + XCTAssertEqual(row.scopes["a"]!.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(row.scopes["a"]!.prefetchedRows.keys, ["cs"]) + XCTAssertEqual(row.scopes["a"]!.prefetchedRows["cs"]!.count, 1) + XCTAssertEqual(row.scopes["a"]!.prefetchedRows["cs"]![0], ["colc1": 7, "colc2": 1, "grdb_cola1": 1]) + } + } + + // Request with filters + do { + let request = B + .including(optional: B + .belongsTo(A.self) + .filter(Column("cola2") == "a1") + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") == 9) + .orderByPrimaryKey() + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") != 9) + .orderByPrimaryKey() + .forKey("cs2")) + .forKey("a1")) + .including(optional: B + .belongsTo(A.self) + .filter(Column("cola2") == "a2") + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") == 9) + .orderByPrimaryKey() + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") != 9) + .orderByPrimaryKey() + .forKey("cs2")) + .forKey("a2")) + .orderByPrimaryKey() + + // Row.fetchAll + do { + let rows = try Row.fetchAll(db, request) + XCTAssertEqual(rows.count, 4) + + XCTAssertEqual(rows[0].description, "[colb1:4 colb2:1 colb3:\"b1\"]") + XCTAssertEqual(rows[0].debugDescription, """ + ▿ [colb1:4 colb2:1 colb3:"b1"] + unadapted: [colb1:4 colb2:1 colb3:"b1" cola1:1 cola2:"a1" cola1:NULL cola2:NULL] + - a1: [cola1:1 cola2:"a1"] + + cs1: 0 row + + cs2: 1 row + - a2: [cola1:NULL cola2:NULL] + + cs1: 0 row + + cs2: 0 row + + cs1: 0 row + + cs2: 1 row + """) + + XCTAssertEqual(rows[0].unscoped, ["colb1": 4, "colb2": 1, "colb3": "b1"]) + XCTAssertEqual(rows[0].prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(rows[0].scopes.count, 2) + XCTAssertEqual(rows[0].scopes["a1"]!.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(rows[0].scopes["a1"]!.prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(rows[0].scopes["a1"]!.prefetchedRows["cs1"]!.count, 0) + XCTAssertEqual(rows[0].scopes["a1"]!.prefetchedRows["cs2"]!.count, 1) + XCTAssertEqual(rows[0].scopes["a1"]!.prefetchedRows["cs2"]![0], ["colc1": 7, "colc2": 1, "grdb_cola1": 1]) + XCTAssertEqual(rows[0].scopes["a2"]!.unscoped, ["cola1": nil, "cola2": nil]) + XCTAssertEqual(rows[0].scopes["a2"]!.prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(rows[0].scopes["a2"]!.prefetchedRows["cs1"]!.count, 0) + XCTAssertEqual(rows[0].scopes["a2"]!.prefetchedRows["cs2"]!.count, 0) + + XCTAssertEqual(rows[1].unscoped, ["colb1": 5, "colb2": 1, "colb3": "b2"]) + XCTAssertEqual(rows[1].prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(rows[1].scopes.count, 2) + XCTAssertEqual(rows[1].scopes["a1"]!.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(rows[1].scopes["a1"]!.prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(rows[1].scopes["a1"]!.prefetchedRows["cs1"]!.count, 0) + XCTAssertEqual(rows[1].scopes["a1"]!.prefetchedRows["cs2"]!.count, 1) + XCTAssertEqual(rows[1].scopes["a1"]!.prefetchedRows["cs2"]![0], ["colc1": 7, "colc2": 1, "grdb_cola1": 1]) + XCTAssertEqual(rows[1].scopes["a2"]!.unscoped, ["cola1": nil, "cola2": nil]) + XCTAssertEqual(rows[1].scopes["a2"]!.prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(rows[1].scopes["a2"]!.prefetchedRows["cs1"]!.count, 0) + XCTAssertEqual(rows[1].scopes["a2"]!.prefetchedRows["cs2"]!.count, 0) + + XCTAssertEqual(rows[2].unscoped, ["colb1": 6, "colb2": 2, "colb3": "b3"]) + XCTAssertEqual(rows[2].prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(rows[2].scopes.count, 2) + XCTAssertEqual(rows[2].scopes["a1"]!.unscoped, ["cola1": nil, "cola2": nil]) + XCTAssertEqual(rows[2].scopes["a1"]!.prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(rows[2].scopes["a1"]!.prefetchedRows["cs1"]!.count, 0) + XCTAssertEqual(rows[2].scopes["a1"]!.prefetchedRows["cs2"]!.count, 0) + XCTAssertEqual(rows[2].scopes["a2"]!.unscoped, ["cola1": 2, "cola2": "a2"]) + XCTAssertEqual(rows[2].scopes["a2"]!.prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(rows[2].scopes["a2"]!.prefetchedRows["cs1"]!.count, 1) + XCTAssertEqual(rows[2].scopes["a2"]!.prefetchedRows["cs1"]![0], ["colc1": 9, "colc2": 2, "grdb_cola1": 2]) + XCTAssertEqual(rows[2].scopes["a2"]!.prefetchedRows["cs2"]!.count, 1) + XCTAssertEqual(rows[2].scopes["a2"]!.prefetchedRows["cs2"]![0], ["colc1": 8, "colc2": 2, "grdb_cola1": 2]) + + XCTAssertEqual(rows[3].unscoped, ["colb1": 14, "colb2": nil, "colb3": "b4"]) + XCTAssertEqual(rows[3].prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(rows[3].scopes.count, 2) + XCTAssertEqual(rows[3].scopes["a1"]!.unscoped, ["cola1": nil, "cola2": nil]) + XCTAssertEqual(rows[3].scopes["a1"]!.prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(rows[3].scopes["a1"]!.prefetchedRows["cs1"]!.count, 0) + XCTAssertEqual(rows[3].scopes["a1"]!.prefetchedRows["cs2"]!.count, 0) + XCTAssertEqual(rows[3].scopes["a2"]!.unscoped, ["cola1": nil, "cola2": nil]) + XCTAssertEqual(rows[3].scopes["a2"]!.prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(rows[3].scopes["a2"]!.prefetchedRows["cs1"]!.count, 0) + XCTAssertEqual(rows[3].scopes["a2"]!.prefetchedRows["cs2"]!.count, 0) + } + + // Row.fetchOne + do { + let row = try Row.fetchOne(db, request)! + + XCTAssertEqual(row.unscoped, ["colb1": 4, "colb2": 1, "colb3": "b1"]) + XCTAssertEqual(row.prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(row.scopes.count, 2) + XCTAssertEqual(row.scopes["a1"]!.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(row.scopes["a1"]!.prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(row.scopes["a1"]!.prefetchedRows["cs1"]!.count, 0) + XCTAssertEqual(row.scopes["a1"]!.prefetchedRows["cs2"]!.count, 1) + XCTAssertEqual(row.scopes["a1"]!.prefetchedRows["cs2"]![0], ["colc1": 7, "colc2": 1, "grdb_cola1": 1]) + XCTAssertEqual(row.scopes["a2"]!.unscoped, ["cola1": nil, "cola2": nil]) + XCTAssertEqual(row.scopes["a2"]!.prefetchedRows.keys, ["cs1", "cs2"]) + XCTAssertEqual(row.scopes["a2"]!.prefetchedRows["cs1"]!.count, 0) + XCTAssertEqual(row.scopes["a2"]!.prefetchedRows["cs2"]!.count, 0) + } + } + } + } + + func testEquatable() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + let request1 = A + .orderByPrimaryKey() + let request2 = A + .including(all: A.hasMany(B.self).orderByPrimaryKey()) + .orderByPrimaryKey() + let request3 = A + .including(all: A.hasMany(B.self).none()) + .orderByPrimaryKey() + + let row1 = try Row.fetchOne(db, request1)! + let row2 = try Row.fetchOne(db, request2)! + let row3 = try Row.fetchOne(db, request3)! + + XCTAssertEqual(row1.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(row2.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(row3.unscoped, ["cola1": 1, "cola2": "a1"]) + + XCTAssertTrue(row1.prefetchedRows.isEmpty) + XCTAssertFalse(row2.prefetchedRows.isEmpty) + XCTAssertFalse(row3.prefetchedRows.isEmpty) + + XCTAssertNil(row1.prefetchedRows["bs"]) + XCTAssertEqual(row2.prefetchedRows["bs"], [ + ["colb1": 4, "colb2": 1, "colb3": "b1", "grdb_colb2": 1], + ["colb1": 5, "colb2": 1, "colb3": "b2", "grdb_colb2": 1]]) + XCTAssertEqual(row3.prefetchedRows["bs"], []) + + XCTAssertEqual(row1, row1) + XCTAssertEqual(row1, row1.copy()) + XCTAssertEqual(row1, row1.unscoped) + XCTAssertEqual(row1, row2.unscoped) + XCTAssertEqual(row1, row3.unscoped) + XCTAssertNotEqual(row1, row2) + XCTAssertNotEqual(row1, row3) + + XCTAssertEqual(row2, row2) + XCTAssertEqual(row2, row2.copy()) + XCTAssertNotEqual(row2, row2.unscoped) + XCTAssertNotEqual(row2, row3) + + XCTAssertEqual(row3, row3) + XCTAssertEqual(row3, row3.copy()) + XCTAssertNotEqual(row3, row3.unscoped) + } + } + + func testCopy() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + let request1 = A + .orderByPrimaryKey() + let request2 = A + .including(all: A.hasMany(B.self).orderByPrimaryKey()) + .orderByPrimaryKey() + let request3 = A + .including(all: A.hasMany(B.self).none()) + .orderByPrimaryKey() + + let row1 = try Row.fetchOne(db, request1)!.copy() + let row2 = try Row.fetchOne(db, request2)!.copy() + let row3 = try Row.fetchOne(db, request3)!.copy() + + XCTAssertEqual(row1.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(row2.unscoped, ["cola1": 1, "cola2": "a1"]) + XCTAssertEqual(row3.unscoped, ["cola1": 1, "cola2": "a1"]) + + XCTAssertTrue(row1.prefetchedRows.isEmpty) + XCTAssertFalse(row2.prefetchedRows.isEmpty) + XCTAssertFalse(row3.prefetchedRows.isEmpty) + + XCTAssertNil(row1.prefetchedRows["bs"]) + XCTAssertEqual(row2.prefetchedRows["bs"], [ + ["colb1": 4, "colb2": 1, "colb3": "b1", "grdb_colb2": 1], + ["colb1": 5, "colb2": 1, "colb3": "b2", "grdb_colb2": 1]]) + XCTAssertEqual(row3.prefetchedRows["bs"], []) + } + } +} diff --git a/Tests/GRDBTests/AssociationPrefetchingSQLTests.swift b/Tests/GRDBTests/AssociationPrefetchingSQLTests.swift new file mode 100644 index 000000000..7d85a0907 --- /dev/null +++ b/Tests/GRDBTests/AssociationPrefetchingSQLTests.swift @@ -0,0 +1,694 @@ +import XCTest +#if GRDBCUSTOMSQLITE + import GRDBCustomSQLite +#else + import GRDB +#endif + +private struct A: TableRecord { } +private struct B: TableRecord { } +private struct C: TableRecord { } +private struct D: TableRecord { } + +class AssociationPrefetchingSQLTests: GRDBTestCase { + override func setup(_ dbWriter: DatabaseWriter) throws { + try dbWriter.write { db in + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("cola1") + t.column("cola2", .text) + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("colb1") + t.column("colb2", .integer).references("a") + t.column("colb3", .text) + } + try db.create(table: "c") { t in + t.autoIncrementedPrimaryKey("colc1") + t.column("colc2", .integer).references("a") + } + try db.create(table: "d") { t in + t.autoIncrementedPrimaryKey("cold1") + t.column("cold2", .integer).references("c") + t.column("cold3", .text) + } + try db.execute( + sql: """ + INSERT INTO a (cola1, cola2) VALUES (?, ?); + INSERT INTO a (cola1, cola2) VALUES (?, ?); + INSERT INTO a (cola1, cola2) VALUES (?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO b (colb1, colb2, colb3) VALUES (?, ?, ?); + INSERT INTO c (colc1, colc2) VALUES (?, ?); + INSERT INTO c (colc1, colc2) VALUES (?, ?); + INSERT INTO c (colc1, colc2) VALUES (?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + INSERT INTO d (cold1, cold2, cold3) VALUES (?, ?, ?); + """, + arguments: [ + 1, "a1", + 2, "a2", + 3, "a3", + 4, 1, "b1", + 5, 1, "b2", + 6, 2, "b3", + 14, nil, "b4", + 7, 1, + 8, 2, + 9, 2, + 10, 7, "d1", + 11, 8, "d2", + 12, 8, "d3", + 13, 9, "d4", + ]) + } + } + + func testIncludingAllHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(B.self) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + sqlQueries.removeAll() + _ = try Row.fetchAll(db, request) + + let selectQueries = sqlQueries.filter { $0.contains("SELECT") } + XCTAssertEqual(selectQueries, [ + """ + SELECT * FROM "a" ORDER BY "cola1" + """, + """ + SELECT *, "colb2" AS "grdb_colb2" \ + FROM "b" \ + WHERE ("colb2" IN (1, 2, 3)) \ + ORDER BY "colb1" + """]) + } + + // Request with avoided prefetch + do { + let request = A + .filter(false) + .including(all: A + .hasMany(B.self) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + sqlQueries.removeAll() + _ = try Row.fetchAll(db, request) + + let selectQueries = sqlQueries.filter { $0.contains("SELECT") } + XCTAssertEqual(selectQueries, [ + """ + SELECT * FROM \"a\" WHERE 0 ORDER BY \"cola1\" + """]) + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(B.self) + .filter(Column("colb1") == 4) + .orderByPrimaryKey() + .forKey("bs1")) + .including(all: A + .hasMany(B.self) + .filter(Column("colb1") != 4) + .orderByPrimaryKey() + .forKey("bs2")) + .orderByPrimaryKey() + + sqlQueries.removeAll() + _ = try Row.fetchAll(db, request) + + let selectQueries = sqlQueries.filter { $0.contains("SELECT") } + XCTAssertEqual(selectQueries, [ + """ + SELECT * FROM "a" \ + WHERE ("cola1" <> 3) \ + ORDER BY "cola1" + """, + """ + SELECT *, "colb2" AS "grdb_colb2" \ + FROM "b" \ + WHERE (("colb1" = 4) AND ("colb2" IN (1, 2))) \ + ORDER BY "colb1" + """, + """ + SELECT *, "colb2" AS "grdb_colb2" \ + FROM "b" \ + WHERE (("colb1" <> 4) AND ("colb2" IN (1, 2))) \ + ORDER BY "colb1" + """]) + } + } + } + + func testIncludingAllHasManyWithCompoundForeignKey() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "parent") { t in + t.column("parentA", .text) + t.column("parentB", .text) + t.primaryKey(["parentA", "parentB"]) + } + try db.create(table: "child") { t in + t.column("parentA", .text) + t.column("parentB", .text) + t.column("name", .text) + t.foreignKey(["parentA", "parentB"], references: "parent") + } + try db.execute(sql: """ + INSERT INTO parent (parentA, parentB) VALUES ('foo', 'bar'); + INSERT INTO parent (parentA, parentB) VALUES ('baz', 'qux'); + INSERT INTO child (parentA, parentB, name) VALUES ('foo', 'bar', 'foobar1'); + INSERT INTO child (parentA, parentB, name) VALUES ('foo', 'bar', 'foobar2'); + INSERT INTO child (parentA, parentB, name) VALUES ('baz', 'qux', 'bazqux1'); + """) + + struct Parent: TableRecord { } + struct Child: TableRecord { } + + // Plain request + do { + let request = Parent + .including(all: Parent + .hasMany(Child.self)) + .orderByPrimaryKey() + + sqlQueries.removeAll() + _ = try Row.fetchAll(db, request) + + let selectQueries = sqlQueries.filter { $0.contains("SELECT") } + XCTAssertEqual(selectQueries, [ + """ + SELECT * FROM "parent" ORDER BY "parentA", "parentB" + """, + """ + SELECT *, "parentA" AS "grdb_parentA", "parentB" AS "grdb_parentB" \ + FROM "child" \ + WHERE ((("parentA" = 'baz') AND ("parentB" = 'qux')) OR (("parentA" = 'foo') AND ("parentB" = 'bar'))) + """]) + } + + // Request with avoided prefetch + do { + let request = Parent + .filter(false) + .including(all: Parent + .hasMany(Child.self)) + .orderByPrimaryKey() + + sqlQueries.removeAll() + _ = try Row.fetchAll(db, request) + + let selectQueries = sqlQueries.filter { $0.contains("SELECT") } + XCTAssertEqual(selectQueries, [ + """ + SELECT * FROM "parent" WHERE 0 ORDER BY "parentA", "parentB" + """]) + } + } + } + + func testIncludingAllHasManyIncludingAllHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(C.self) + .including(all: C + .hasMany(D.self) + .orderByPrimaryKey()) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + sqlQueries.removeAll() + _ = try Row.fetchAll(db, request) + + let selectQueries = sqlQueries.filter { $0.contains("SELECT") } + XCTAssertEqual(selectQueries, [ + """ + SELECT * FROM "a" ORDER BY "cola1" + """, + """ + SELECT *, "colc2" AS "grdb_colc2" \ + FROM "c" \ + WHERE ("colc2" IN (1, 2, 3)) \ + ORDER BY "colc1" + """, + """ + SELECT *, "cold2" AS "grdb_cold2" \ + FROM "d" \ + WHERE ("cold2" IN (7, 8, 9)) \ + ORDER BY "cold1" + """]) + } + + // Request with avoided prefetch + do { + let request = A + .including(all: A + .hasMany(C.self) + .filter(false) + .including(all: C + .hasMany(D.self) + .orderByPrimaryKey()) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + sqlQueries.removeAll() + _ = try Row.fetchAll(db, request) + + let selectQueries = sqlQueries.filter { $0.contains("SELECT") } + XCTAssertEqual(selectQueries, [ + """ + SELECT * FROM "a" ORDER BY "cola1" + """, + """ + SELECT *, "colc2" AS "grdb_colc2" \ + FROM "c" \ + WHERE (0 AND ("colc2" IN (1, 2, 3))) \ + ORDER BY "colc1" + """]) + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") > 7) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("ds1")) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("ds2")) + .orderByPrimaryKey() + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") < 9) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("ds1")) + .including(all: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("ds2")) + .orderByPrimaryKey() + .forKey("cs2")) + .orderByPrimaryKey() + + sqlQueries.removeAll() + _ = try Row.fetchAll(db, request) + + let selectQueries = sqlQueries.filter { $0.contains("SELECT") } + XCTAssertEqual(selectQueries, [ + """ + SELECT * \ + FROM "a" \ + WHERE ("cola1" <> 3) \ + ORDER BY "cola1" + """, + """ + SELECT *, "colc2" AS "grdb_colc2" \ + FROM "c" \ + WHERE (("colc1" > 7) AND ("colc2" IN (1, 2))) \ + ORDER BY "colc1" + """, + """ + SELECT *, "cold2" AS "grdb_cold2" \ + FROM "d" \ + WHERE (("cold1" = 11) AND ("cold2" IN (8, 9))) \ + ORDER BY "cold1" + """, + """ + SELECT *, "cold2" AS "grdb_cold2" \ + FROM "d" \ + WHERE (("cold1" <> 11) AND ("cold2" IN (8, 9))) \ + ORDER BY "cold1" + """, + """ + SELECT *, "colc2" AS "grdb_colc2" \ + FROM "c" \ + WHERE (("colc1" < 9) AND ("colc2" IN (1, 2))) \ + ORDER BY "colc1" + """, + """ + SELECT *, "cold2" AS "grdb_cold2" \ + FROM "d" \ + WHERE (("cold1" = 11) AND ("cold2" IN (7, 8))) \ + ORDER BY "cold1" + """, + """ + SELECT *, "cold2" AS "grdb_cold2" \ + FROM "d" \ + WHERE (("cold1" <> 11) AND ("cold2" IN (7, 8))) \ + ORDER BY "cold1" + """]) + } + } + } + + func testIncludingAllHasManyIncludingRequiredOrOptionalHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(C.self) + .including(required: C + .hasMany(D.self) + .orderByPrimaryKey()) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + sqlQueries.removeAll() + _ = try Row.fetchAll(db, request) + + let selectQueries = sqlQueries.filter { $0.contains("SELECT") } + XCTAssertEqual(selectQueries, [ + """ + SELECT * FROM "a" ORDER BY "cola1" + """, + """ + SELECT "c".*, "c"."colc2" AS "grdb_colc2", "d".* \ + FROM "c" \ + JOIN "d" ON ("d"."cold2" = "c"."colc1") \ + WHERE ("c"."colc2" IN (1, 2, 3)) \ + ORDER BY "c"."colc1", "d"."cold1" + """]) + } + + // Request with avoided prefetch + do { + let request = A + .including(all: A + .hasMany(C.self) + .filter(false) + .including(required: C + .hasMany(D.self) + .orderByPrimaryKey()) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + sqlQueries.removeAll() + _ = try Row.fetchAll(db, request) + + let selectQueries = sqlQueries.filter { $0.contains("SELECT") } + XCTAssertEqual(selectQueries, [ + """ + SELECT * FROM "a" ORDER BY "cola1" + """, + """ + SELECT "c".*, "c"."colc2" AS "grdb_colc2", "d".* \ + FROM "c" \ + JOIN "d" ON ("d"."cold2" = "c"."colc1") \ + WHERE (0 AND ("c"."colc2" IN (1, 2, 3))) \ + ORDER BY "c"."colc1", "d"."cold1" + """]) + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") > 7) + .including(optional: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("d1")) + .including(required: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("d2")) + .orderByPrimaryKey() + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") < 9) + .including(optional: C + .hasMany(D.self) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("d1")) + .including(required: C + .hasMany(D.self) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("d2")) + .orderByPrimaryKey() + .forKey("cs2")) + .orderByPrimaryKey() + + sqlQueries.removeAll() + _ = try Row.fetchAll(db, request) + + let selectQueries = sqlQueries.filter { $0.contains("SELECT") } + XCTAssertEqual(selectQueries, [ + """ + SELECT * \ + FROM "a" \ + WHERE ("cola1" <> 3) \ + ORDER BY "cola1" + """, + """ + SELECT "c".*, "c"."colc2" AS "grdb_colc2", "d1".*, "d2".* \ + FROM "c" \ + LEFT JOIN "d" "d1" ON (("d1"."cold2" = "c"."colc1") AND ("d1"."cold1" = 11)) \ + JOIN "d" "d2" ON (("d2"."cold2" = "c"."colc1") AND ("d2"."cold1" <> 11)) \ + WHERE (("c"."colc1" > 7) AND ("c"."colc2" IN (1, 2))) \ + ORDER BY "c"."colc1", "d1"."cold1", "d2"."cold1" + """, + """ + SELECT "c".*, "c"."colc2" AS "grdb_colc2", "d1".*, "d2".* \ + FROM "c" \ + LEFT JOIN "d" "d1" ON (("d1"."cold2" = "c"."colc1") AND ("d1"."cold1" = 11)) \ + JOIN "d" "d2" ON (("d2"."cold2" = "c"."colc1") AND ("d2"."cold1" <> 11)) \ + WHERE (("c"."colc1" < 9) AND ("c"."colc2" IN (1, 2))) \ + ORDER BY "c"."colc1", "d1"."cold1", "d2"."cold1" + """]) + } + } + } + + func testIncludingAllHasManyThroughHasManyUsingHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Plain request + do { + let request = A + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self), using: C.hasMany(D.self)) + .orderByPrimaryKey()) + .orderByPrimaryKey() + + sqlQueries.removeAll() + _ = try Row.fetchAll(db, request) + + let selectQueries = sqlQueries.filter { $0.contains("SELECT") } + XCTAssertEqual(selectQueries, [ + """ + SELECT * FROM "a" ORDER BY "cola1" + """, + """ + SELECT "d".*, "c"."colc2" AS "grdb_colc2" \ + FROM "d" \ + JOIN "c" ON (("c"."colc1" = "d"."cold2") AND ("c"."colc2" IN (1, 2, 3))) \ + ORDER BY "d"."cold1" + """]) + } + + // Request with filters + do { + let request = A + .filter(Column("cola1") != 3) + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self).filter(Column("colc1") == 8).forKey("cs1"), using: C.hasMany(D.self)) + .orderByPrimaryKey() + .forKey("ds1")) + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self).forKey("cs2"), using: C.hasMany(D.self)) + .filter(Column("cold1") != 11) + .orderByPrimaryKey() + .forKey("ds2")) + .including(all: A + .hasMany(D.self, through: A.hasMany(C.self).forKey("cs2"), using: C.hasMany(D.self)) + .filter(Column("cold1") == 11) + .orderByPrimaryKey() + .forKey("ds3")) + .orderByPrimaryKey() + + sqlQueries.removeAll() + _ = try Row.fetchAll(db, request) + + let selectQueries = sqlQueries.filter { $0.contains("SELECT") } + XCTAssertEqual(selectQueries, [ + """ + SELECT * FROM "a" \ + WHERE ("cola1" <> 3) \ + ORDER BY "cola1" + """, + """ + SELECT "d".*, "c"."colc2" AS "grdb_colc2" \ + FROM "d" \ + JOIN "c" ON (("c"."colc1" = "d"."cold2") AND (("c"."colc1" = 8) AND ("c"."colc2" IN (1, 2)))) \ + ORDER BY "d"."cold1" + """, + """ + SELECT "d".*, "c"."colc2" AS "grdb_colc2" \ + FROM "d" \ + JOIN "c" ON (("c"."colc1" = "d"."cold2") AND ("c"."colc2" IN (1, 2))) \ + WHERE ("d"."cold1" <> 11) \ + ORDER BY "d"."cold1" + """, + """ + SELECT "d".*, "c"."colc2" AS "grdb_colc2" \ + FROM "d" \ + JOIN "c" ON (("c"."colc1" = "d"."cold2") AND ("c"."colc2" IN (1, 2))) \ + WHERE ("d"."cold1" = 11) \ + ORDER BY "d"."cold1" + """]) + } + } + } + + // TODO: make a variant with joining(optional:) + func testIncludingOptionalBelongsToIncludingAllHasMany() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + // Plain request + do { + let request = B + .including(optional: B + .belongsTo(A.self) + .including(all: A + .hasMany(C.self) + .orderByPrimaryKey()) + ) + .orderByPrimaryKey() + + sqlQueries.removeAll() + _ = try Row.fetchAll(db, request) + + let selectQueries = sqlQueries.filter { $0.contains("SELECT") } + XCTAssertEqual(selectQueries, [ + """ + SELECT "b".*, "a".* \ + FROM "b" \ + LEFT JOIN "a" ON ("a"."cola1" = "b"."colb2") \ + ORDER BY "b"."colb1" + """, + """ + SELECT "c".*, "a"."cola1" AS "grdb_cola1" \ + FROM "c" \ + JOIN "a" ON (("a"."cola1" = "c"."colc2") AND ("a"."cola1" IN (1, 2))) \ + ORDER BY "c"."colc1" + """]) + } + + // Request with filters + do { + let request = B + .including(optional: B + .belongsTo(A.self) + .filter(Column("cola2") == "a1") + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") == 9) + .orderByPrimaryKey() + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") != 9) + .orderByPrimaryKey() + .forKey("cs2")) + .forKey("a1")) + .including(optional: B + .belongsTo(A.self) + .filter(Column("cola2") == "a2") + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") == 9) + .orderByPrimaryKey() + .forKey("cs1")) + .including(all: A + .hasMany(C.self) + .filter(Column("colc1") != 9) + .orderByPrimaryKey() + .forKey("cs2")) + .forKey("a2")) + .orderByPrimaryKey() + + sqlQueries.removeAll() + _ = try Row.fetchAll(db, request) + + let selectQueries = sqlQueries.filter { $0.contains("SELECT") } + XCTAssertEqual(selectQueries, [ + """ + SELECT "b".*, "a1".*, "a2".* \ + FROM "b" \ + LEFT JOIN "a" "a1" ON (("a1"."cola1" = "b"."colb2") AND ("a1"."cola2" = 'a1')) \ + LEFT JOIN "a" "a2" ON (("a2"."cola1" = "b"."colb2") AND ("a2"."cola2" = 'a2')) \ + ORDER BY "b"."colb1" + """, + """ + SELECT "c".*, "a"."cola1" AS "grdb_cola1" \ + FROM "c" \ + JOIN "a" ON (("a"."cola1" = "c"."colc2") AND (("a"."cola2" = 'a1') AND ("a"."cola1" IN (1, 2)))) \ + WHERE ("c"."colc1" = 9) \ + ORDER BY "c"."colc1" + """, + """ + SELECT "c".*, "a"."cola1" AS "grdb_cola1" \ + FROM "c" \ + JOIN "a" ON (("a"."cola1" = "c"."colc2") AND (("a"."cola2" = 'a1') AND ("a"."cola1" IN (1, 2)))) \ + WHERE ("c"."colc1" <> 9) \ + ORDER BY "c"."colc1" + """, + """ + SELECT "c".*, "a"."cola1" AS "grdb_cola1" \ + FROM "c" \ + JOIN "a" ON (("a"."cola1" = "c"."colc2") AND (("a"."cola2" = 'a2') AND ("a"."cola1" IN (1, 2)))) \ + WHERE ("c"."colc1" = 9) \ + ORDER BY "c"."colc1" + """, + """ + SELECT "c".*, "a"."cola1" AS "grdb_cola1" \ + FROM "c" \ + JOIN "a" ON (("a"."cola1" = "c"."colc2") AND (("a"."cola2" = 'a2') AND ("a"."cola1" IN (1, 2)))) \ + WHERE ("c"."colc1" <> 9) \ + ORDER BY "c"."colc1" + """]) + } + } + } +} diff --git a/Tests/GRDBTests/AssociationRowScopeSearchTests.swift b/Tests/GRDBTests/AssociationRowScopeSearchTests.swift index 6e1f1f8b9..649314ed8 100644 --- a/Tests/GRDBTests/AssociationRowScopeSearchTests.swift +++ b/Tests/GRDBTests/AssociationRowScopeSearchTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else @testable import GRDB @@ -55,11 +53,11 @@ class AssociationRowScopeSearchTests: GRDBTestCase { t.column("id", .integer).primaryKey() t.column("bid", .integer).references("b") } - try db.execute("INSERT INTO a (id) VALUES (1)") - try db.execute("INSERT INTO b (id, aid) VALUES (2, 1)") - try db.execute("INSERT INTO c (id, aid, bid) VALUES (3, NULL, 2)") - try db.execute("INSERT INTO c (id, aid, bid) VALUES (4, 1, NULL)") - try db.execute("INSERT INTO d (id, bid) VALUES (5, 2)") + try db.execute(sql: "INSERT INTO a (id) VALUES (1)") + try db.execute(sql: "INSERT INTO b (id, aid) VALUES (2, 1)") + try db.execute(sql: "INSERT INTO c (id, aid, bid) VALUES (3, NULL, 2)") + try db.execute(sql: "INSERT INTO c (id, aid, bid) VALUES (4, 1, NULL)") + try db.execute(sql: "INSERT INTO d (id, bid) VALUES (5, 2)") } } diff --git a/Tests/GRDBTests/AssociationTableAliasTestsSQLTests.swift b/Tests/GRDBTests/AssociationTableAliasTestsSQLTests.swift index 297903a83..92c161bf6 100644 --- a/Tests/GRDBTests/AssociationTableAliasTestsSQLTests.swift +++ b/Tests/GRDBTests/AssociationTableAliasTestsSQLTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/CGFloatTests.swift b/Tests/GRDBTests/CGFloatTests.swift index 35f468099..5b4131d77 100644 --- a/Tests/GRDBTests/CGFloatTests.swift +++ b/Tests/GRDBTests/CGFloatTests.swift @@ -1,8 +1,6 @@ import XCTest import CoreGraphics -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -13,13 +11,13 @@ class CGFloatTests: GRDBTestCase { func testCGFLoat() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE points (x DOUBLE, y DOUBLE)") + try db.execute(sql: "CREATE TABLE points (x DOUBLE, y DOUBLE)") let x: CGFloat = 1 let y: CGFloat? = nil - try db.execute("INSERT INTO points VALUES (?,?)", arguments: [x, y]) + try db.execute(sql: "INSERT INTO points VALUES (?,?)", arguments: [x, y]) - let row = try Row.fetchOne(db, "SELECT * FROM points")! + let row = try Row.fetchOne(db, sql: "SELECT * FROM points")! let fetchedX: CGFloat = row["x"] let fetchedY: CGFloat? = row["y"] XCTAssertEqual(x, fetchedX) diff --git a/Tests/GRDBTests/ColumnExpressionTests.swift b/Tests/GRDBTests/ColumnExpressionTests.swift index 8c74f8d46..eebf08d53 100644 --- a/Tests/GRDBTests/ColumnExpressionTests.swift +++ b/Tests/GRDBTests/ColumnExpressionTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -70,9 +68,9 @@ class ColumnExpressionTests: GRDBTestCase { // Test FTS3 match expression let expression = try Player.Columns.name.match(FTS3Pattern(rawPattern: "foo")) - let literal = expression.literal - XCTAssertEqual(literal.sql, "(\"name\" MATCH ?)") - XCTAssertEqual(literal.arguments, ["foo"]) + let sqlLiteral = expression.sqlLiteral + XCTAssertEqual(sqlLiteral.sql, "(\"name\" MATCH ?)") + XCTAssertEqual(sqlLiteral.arguments, ["foo"]) } } @@ -131,12 +129,67 @@ class ColumnExpressionTests: GRDBTestCase { // Test FTS3 match expression let expression = try Player.Columns.name.match(FTS3Pattern(rawPattern: "foo")) - let literal = expression.literal - XCTAssertEqual(literal.sql, "(\"name\" MATCH ?)") - XCTAssertEqual(literal.arguments, ["foo"]) + let sqlLiteral = expression.sqlLiteral + XCTAssertEqual(sqlLiteral.sql, "(\"name\" MATCH ?)") + XCTAssertEqual(sqlLiteral.arguments, ["foo"]) } } + func testColumnsDerivedFromCodingKeys() throws { + struct Player: Codable, TableRecord, FetchableRecord, PersistableRecord { + var id: Int64 + var name: String + var score: Int + + enum CodingKeys: String, CodingKey { + case id + case name = "full_name" + case score + } + + enum Columns { + static let id = Column(CodingKeys.id) + static let name = Column(CodingKeys.name) + static let score = Column(CodingKeys.score) + } + + // Test databaseSelection + static let databaseSelection: [SQLSelectable] = [Columns.id, Columns.name, Columns.score] + + static var testRequest: QueryInterfaceRequest { + // Test expression derivation + return filter(Columns.name != nil).order(Columns.score.desc) + } + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try db.create(table: "player") { t in + t.autoIncrementedPrimaryKey("id") + t.column("full_name") + t.column("score") + } + + // Test rowId column identification + try XCTAssertEqual(Player.filter(key: 1).databaseRegion(db).description, "player(full_name,id,score)[1]") + try XCTAssertEqual(Player.filter(Player.Columns.id == 1).databaseRegion(db).description, "player(full_name,id,score)[1]") + try XCTAssertEqual(Player.filter(1 == Player.Columns.id).databaseRegion(db).description, "player(full_name,id,score)[1]") + try XCTAssertEqual(Player.filter(Player.Columns.id == 1 || Player.Columns.id == 2).databaseRegion(db).description, "player(full_name,id,score)[1,2]") + try XCTAssertEqual(Player.filter([1, 2, 3].contains(Player.Columns.id)).databaseRegion(db).description, "player(full_name,id,score)[1,2,3]") + + // Test specific column updates + let player = Player(row: ["id": 1, "full_name": "Arthur", "score": 1000]) + try? player.update(db, columns: [Player.Columns.name, Player.Columns.score]) + XCTAssertEqual(lastSQLQuery, "UPDATE \"player\" SET \"full_name\"=\'Arthur\', \"score\"=1000 WHERE \"id\"=1") + + // Test FTS3 match expression + let expression = try Player.Columns.name.match(FTS3Pattern(rawPattern: "foo")) + let sqlLiteral = expression.sqlLiteral + XCTAssertEqual(sqlLiteral.sql, "(\"full_name\" MATCH ?)") + XCTAssertEqual(sqlLiteral.arguments, ["foo"]) + } + } + func testCodingKeysAsColumnExpression() throws { struct Player: Codable, TableRecord, FetchableRecord, PersistableRecord { var id: Int64 @@ -180,9 +233,9 @@ class ColumnExpressionTests: GRDBTestCase { // Test FTS3 match expression let expression = try Player.CodingKeys.name.match(FTS3Pattern(rawPattern: "foo")) - let literal = expression.literal - XCTAssertEqual(literal.sql, "(\"full_name\" MATCH ?)") - XCTAssertEqual(literal.arguments, ["foo"]) + let sqlLiteral = expression.sqlLiteral + XCTAssertEqual(sqlLiteral.sql, "(\"full_name\" MATCH ?)") + XCTAssertEqual(sqlLiteral.arguments, ["foo"]) } } } diff --git a/Tests/GRDBTests/ColumnInfoTests.swift b/Tests/GRDBTests/ColumnInfoTests.swift index e4e8cbea9..685145aaf 100644 --- a/Tests/GRDBTests/ColumnInfoTests.swift +++ b/Tests/GRDBTests/ColumnInfoTests.swift @@ -1,10 +1,10 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else - #if SWIFT_PACKAGE + #if GRDBCIPHER + import SQLCipher + #elseif SWIFT_PACKAGE import CSQLite #else import SQLite3 @@ -17,7 +17,7 @@ class ColumnInfoTests: GRDBTestCase { func testColumnInfo() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE t ( a INT, b TEXT, diff --git a/Tests/GRDBTests/CompilationProtocolTests.swift b/Tests/GRDBTests/CompilationProtocolTests.swift index f92531a46..ef810ff89 100644 --- a/Tests/GRDBTests/CompilationProtocolTests.swift +++ b/Tests/GRDBTests/CompilationProtocolTests.swift @@ -1,6 +1,4 @@ -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -112,7 +110,7 @@ private class UserPersistableRecord2 : PersistableRecord { private struct UserRowRequest : FetchRequest { struct CustomType { } typealias RowDecoder = CustomType - func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) { preconditionFailure() } + func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) { preconditionFailure() } } // MARK: - FetchableRecord diff --git a/Tests/GRDBTests/CompilationSubClassTests.swift b/Tests/GRDBTests/CompilationSubClassTests.swift index 826b57088..7e48c49a1 100644 --- a/Tests/GRDBTests/CompilationSubClassTests.swift +++ b/Tests/GRDBTests/CompilationSubClassTests.swift @@ -1,6 +1,4 @@ -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/CursorTests.swift b/Tests/GRDBTests/CursorTests.swift index c69411c3b..64e5a7889 100644 --- a/Tests/GRDBTests/CursorTests.swift +++ b/Tests/GRDBTests/CursorTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/DataMemoryTests.swift b/Tests/GRDBTests/DataMemoryTests.swift index 58c30f77a..ecae52595 100644 --- a/Tests/GRDBTests/DataMemoryTests.swift +++ b/Tests/GRDBTests/DataMemoryTests.swift @@ -1,10 +1,10 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else - #if SWIFT_PACKAGE + #if GRDBCIPHER + import SQLCipher + #elseif SWIFT_PACKAGE import CSQLite #else import SQLite3 @@ -17,56 +17,55 @@ class DataMemoryTests: GRDBTestCase { func testMemoryBehavior() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE datas (data BLOB)") + // Make sure Data is on the heap (15 bytes is enough) + // For more context, see: + // https://forums.swift.org/t/swift-5-how-to-test-data-bytesnocopydeallocator/20299/2?u=gwendal.roue + let data = Data(repeating: 0xaa, count: 15) - let data = "foo".data(using: .utf8) - try db.execute("INSERT INTO datas (data) VALUES (?)", arguments: [data]) - - let rows = try Row.fetchCursor(db, "SELECT * FROM datas") + let rows = try Row.fetchCursor(db, sql: "SELECT ?", arguments: [data]) while let row = try rows.next() { - let sqliteStatement = row.sqliteStatement - let sqliteBytes = sqlite3_column_blob(sqliteStatement, 0) + let blobPointer = sqlite3_column_blob(row.sqliteStatement, 0) do { // This data should be copied: let copiedData: Data = row[0] - copiedData.withUnsafeBytes { copiedBytes in - XCTAssertNotEqual(copiedBytes, sqliteBytes) - } XCTAssertEqual(copiedData, data) + copiedData.withBaseAddress { dataPointer in + XCTAssertNotEqual(dataPointer, blobPointer) + } } do { // This data should not be copied let nonCopiedData = row.dataNoCopy(atIndex: 0)! - nonCopiedData.withUnsafeBytes { nonCopiedBytes in - XCTAssertEqual(nonCopiedBytes, sqliteBytes) - } XCTAssertEqual(nonCopiedData, data) + nonCopiedData.withBaseAddress { dataPointer in + XCTAssertEqual(dataPointer, blobPointer) + } } } - let row = try Row.fetchOne(db, "SELECT * FROM datas")! - let dbValue = row.first!.1 + let row = try Row.fetchOne(db, sql: "SELECT ?", arguments: [data])! + let dbValue = row.first!.1 // TODO: think about exposing a (column:,databaseValue:) tuple switch dbValue.storage { case .blob(let data): - data.withUnsafeBytes { (dataBytes: UnsafePointer) -> Void in + data.withBaseAddress { dataPointer in do { // This data should not be copied: let nonCopiedData: Data = row[0] - nonCopiedData.withUnsafeBytes { nonCopiedBytes in - XCTAssertEqual(nonCopiedBytes, dataBytes) - } XCTAssertEqual(nonCopiedData, data) + nonCopiedData.withBaseAddress { nonCopiedBytes in + XCTAssertEqual(nonCopiedBytes, dataPointer) + } } do { // This data should not be copied: let nonCopiedData = row.dataNoCopy(atIndex: 0)! - nonCopiedData.withUnsafeBytes { nonCopiedBytes in - XCTAssertEqual(nonCopiedBytes, dataBytes) - } XCTAssertEqual(nonCopiedData, data) + nonCopiedData.withBaseAddress { nonCopiedBytes in + XCTAssertEqual(nonCopiedBytes, dataPointer) + } } } default: @@ -75,3 +74,18 @@ class DataMemoryTests: GRDBTestCase { } } } + +extension Data { + // Helper for comparing data heap pointers, depending on the Swift version + fileprivate func withBaseAddress(_ body: (UnsafeRawPointer?) -> Void) { + #if swift(>=5.0) + withUnsafeBytes { + body($0.baseAddress) + } + #else + withUnsafeBytes { + body(UnsafeRawPointer($0)) + } + #endif + } +} diff --git a/Tests/GRDBTests/DatabaseAfterNextTransactionCommitTests.swift b/Tests/GRDBTests/DatabaseAfterNextTransactionCommitTests.swift index c663af6fd..00c492622 100644 --- a/Tests/GRDBTests/DatabaseAfterNextTransactionCommitTests.swift +++ b/Tests/GRDBTests/DatabaseAfterNextTransactionCommitTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -62,8 +60,8 @@ class DatabaseAfterNextTransactionCommitTests: GRDBTestCase { XCTAssertNotNil(deallocationWitness) XCTAssertEqual(transactionCount, 0) - try db.execute(startSQL) - try db.execute(endSQL) + try db.execute(sql: startSQL) + try db.execute(sql: endSQL) switch expectedCompletion { case .commit: XCTAssertEqual(transactionCount, 1, "\(startSQL); \(endSQL)") @@ -73,7 +71,7 @@ class DatabaseAfterNextTransactionCommitTests: GRDBTestCase { XCTAssertNil(deallocationWitness) try db.inTransaction { - try db.execute("DROP TABLE IF EXISTS t; CREATE TABLE t(a); ") + try db.execute(sql: "DROP TABLE IF EXISTS t; CREATE TABLE t(a); ") return .commit } switch expectedCompletion { @@ -91,7 +89,7 @@ class DatabaseAfterNextTransactionCommitTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in var transactionCount = 0 - try db.execute(startSQL) + try db.execute(sql: startSQL) weak var deallocationWitness: Witness? = nil do { @@ -106,7 +104,7 @@ class DatabaseAfterNextTransactionCommitTests: GRDBTestCase { XCTAssertNotNil(deallocationWitness) XCTAssertEqual(transactionCount, 0) - try db.execute(endSQL) + try db.execute(sql: endSQL) switch expectedCompletion { case .commit: XCTAssertEqual(transactionCount, 1, "\(startSQL); \(endSQL)") @@ -116,7 +114,7 @@ class DatabaseAfterNextTransactionCommitTests: GRDBTestCase { XCTAssertNil(deallocationWitness) try db.inTransaction { - try db.execute("DROP TABLE IF EXISTS t; CREATE TABLE t(a); ") + try db.execute(sql: "DROP TABLE IF EXISTS t; CREATE TABLE t(a); ") return .commit } switch expectedCompletion { diff --git a/Tests/GRDBTests/DatabaseAggregateTests.swift b/Tests/GRDBTests/DatabaseAggregateTests.swift index bf466b528..0db6d2706 100644 --- a/Tests/GRDBTests/DatabaseAggregateTests.swift +++ b/Tests/GRDBTests/DatabaseAggregateTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -34,7 +32,7 @@ class DatabaseAggregateTests: GRDBTestCase { let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self) dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertTrue(try DatabaseValue.fetchOne(db, "SELECT f()")!.isNull) + XCTAssertTrue(try DatabaseValue.fetchOne(db, sql: "SELECT f()")!.isNull) } } @@ -49,7 +47,7 @@ class DatabaseAggregateTests: GRDBTestCase { let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self) dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertEqual(try Int64.fetchOne(db, "SELECT f()")!, Int64(1)) + XCTAssertEqual(try Int64.fetchOne(db, sql: "SELECT f()")!, Int64(1)) } } @@ -64,7 +62,7 @@ class DatabaseAggregateTests: GRDBTestCase { let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self) dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertEqual(try Double.fetchOne(db, "SELECT f()")!, 1e100) + XCTAssertEqual(try Double.fetchOne(db, sql: "SELECT f()")!, 1e100) } } @@ -79,7 +77,7 @@ class DatabaseAggregateTests: GRDBTestCase { let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self) dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertEqual(try String.fetchOne(db, "SELECT f()")!, "foo") + XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f()")!, "foo") } } @@ -94,7 +92,7 @@ class DatabaseAggregateTests: GRDBTestCase { let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self) dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertEqual(try Data.fetchOne(db, "SELECT f()")!, "foo".data(using: .utf8)) + XCTAssertEqual(try Data.fetchOne(db, sql: "SELECT f()")!, "foo".data(using: .utf8)) } } @@ -109,7 +107,7 @@ class DatabaseAggregateTests: GRDBTestCase { let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self) dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertTrue(try CustomValueType.fetchOne(db, "SELECT f()") != nil) + XCTAssertTrue(try CustomValueType.fetchOne(db, sql: "SELECT f()") != nil) } } @@ -129,12 +127,12 @@ class DatabaseAggregateTests: GRDBTestCase { let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self) dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertTrue(try Bool.fetchOne(db, "SELECT f(NULL)")!) - XCTAssertFalse(try Bool.fetchOne(db, "SELECT f(1)")!) - XCTAssertFalse(try Bool.fetchOne(db, "SELECT f(1.1)")!) - XCTAssertFalse(try Bool.fetchOne(db, "SELECT f('foo')")!) - XCTAssertFalse(try Bool.fetchOne(db, "SELECT f(?)", arguments: ["foo".data(using: .utf8)])!) - XCTAssertFalse(try Bool.fetchOne(db, "SELECT f(?)", arguments: [Data()])!) + XCTAssertTrue(try Bool.fetchOne(db, sql: "SELECT f(NULL)")!) + XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f(1)")!) + XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f(1.1)")!) + XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f('foo')")!) + XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f(?)", arguments: ["foo".data(using: .utf8)])!) + XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f(?)", arguments: [Data()])!) } } @@ -152,9 +150,9 @@ class DatabaseAggregateTests: GRDBTestCase { let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self) dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertTrue(try Int64.fetchOne(db, "SELECT f(NULL)") == nil) - XCTAssertEqual(try Int64.fetchOne(db, "SELECT f(1)")!, 1) - XCTAssertEqual(try Int64.fetchOne(db, "SELECT f(1.1)")!, 1) + XCTAssertTrue(try Int64.fetchOne(db, sql: "SELECT f(NULL)") == nil) + XCTAssertEqual(try Int64.fetchOne(db, sql: "SELECT f(1)")!, 1) + XCTAssertEqual(try Int64.fetchOne(db, sql: "SELECT f(1.1)")!, 1) } } @@ -172,9 +170,9 @@ class DatabaseAggregateTests: GRDBTestCase { let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self) dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertTrue(try Double.fetchOne(db, "SELECT f(NULL)") == nil) - XCTAssertEqual(try Double.fetchOne(db, "SELECT f(1)")!, 1.0) - XCTAssertEqual(try Double.fetchOne(db, "SELECT f(1.1)")!, 1.1) + XCTAssertTrue(try Double.fetchOne(db, sql: "SELECT f(NULL)") == nil) + XCTAssertEqual(try Double.fetchOne(db, sql: "SELECT f(1)")!, 1.0) + XCTAssertEqual(try Double.fetchOne(db, sql: "SELECT f(1.1)")!, 1.1) } } @@ -192,8 +190,8 @@ class DatabaseAggregateTests: GRDBTestCase { let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self) dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertTrue(try String.fetchOne(db, "SELECT f(NULL)") == nil) - XCTAssertEqual(try String.fetchOne(db, "SELECT f('foo')")!, "foo") + XCTAssertTrue(try String.fetchOne(db, sql: "SELECT f(NULL)") == nil) + XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f('foo')")!, "foo") } } @@ -211,9 +209,9 @@ class DatabaseAggregateTests: GRDBTestCase { let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self) dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertTrue(try Data.fetchOne(db, "SELECT f(NULL)") == nil) - XCTAssertEqual(try Data.fetchOne(db, "SELECT f(?)", arguments: ["foo".data(using: .utf8)])!, "foo".data(using: .utf8)) - XCTAssertEqual(try Data.fetchOne(db, "SELECT f(?)", arguments: [Data()])!, Data()) + XCTAssertTrue(try Data.fetchOne(db, sql: "SELECT f(NULL)") == nil) + XCTAssertEqual(try Data.fetchOne(db, sql: "SELECT f(?)", arguments: ["foo".data(using: .utf8)])!, "foo".data(using: .utf8)) + XCTAssertEqual(try Data.fetchOne(db, sql: "SELECT f(?)", arguments: [Data()])!, Data()) } } @@ -231,8 +229,8 @@ class DatabaseAggregateTests: GRDBTestCase { let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self) dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertTrue(try CustomValueType.fetchOne(db, "SELECT f(NULL)") == nil) - XCTAssertTrue(try CustomValueType.fetchOne(db, "SELECT f('CustomValueType')") != nil) + XCTAssertTrue(try CustomValueType.fetchOne(db, sql: "SELECT f(NULL)") == nil) + XCTAssertTrue(try CustomValueType.fetchOne(db, sql: "SELECT f('CustomValueType')") != nil) } } @@ -249,9 +247,9 @@ class DatabaseAggregateTests: GRDBTestCase { let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self) dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertEqual(try String.fetchOne(db, "SELECT f()")!, "foo") + XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f()")!, "foo") do { - try db.execute("SELECT f(1)") + try db.execute(sql: "SELECT f(1)") XCTFail("Expected error") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) @@ -276,11 +274,11 @@ class DatabaseAggregateTests: GRDBTestCase { let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self) dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertEqual(try String.fetchOne(db, "SELECT upper(?)", arguments: ["Roué"])!, "ROUé") - XCTAssertEqual(try String.fetchOne(db, "SELECT f(?)", arguments: ["Roué"])!, "ROUÉ") - XCTAssertTrue(try String.fetchOne(db, "SELECT f(NULL)") == nil) + XCTAssertEqual(try String.fetchOne(db, sql: "SELECT upper(?)", arguments: ["Roué"])!, "ROUé") + XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f(?)", arguments: ["Roué"])!, "ROUÉ") + XCTAssertTrue(try String.fetchOne(db, sql: "SELECT f(NULL)") == nil) do { - try db.execute("SELECT f()") + try db.execute(sql: "SELECT f()") XCTFail("Expected error") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) @@ -306,9 +304,9 @@ class DatabaseAggregateTests: GRDBTestCase { let fn = DatabaseFunction("f", argumentCount: 2, aggregate: Aggregate.self) dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT f(1, 2)")!, 3) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f(1, 2)")!, 3) do { - try db.execute("SELECT f()") + try db.execute(sql: "SELECT f()") XCTFail("Expected error") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) @@ -333,9 +331,9 @@ class DatabaseAggregateTests: GRDBTestCase { let fn = DatabaseFunction("f", aggregate: Aggregate.self) dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT f()")!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT f(1)")!, 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT f(1, 1)")!, 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f()")!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f(1)")!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f(1, 1)")!, 2) } } @@ -355,7 +353,7 @@ class DatabaseAggregateTests: GRDBTestCase { dbQueue.add(function: fn) try dbQueue.inDatabase { db in do { - try db.execute("SELECT f()") + try db.execute(sql: "SELECT f()") XCTFail("Expected DatabaseError") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) @@ -378,7 +376,7 @@ class DatabaseAggregateTests: GRDBTestCase { dbQueue.add(function: fn) try dbQueue.inDatabase { db in do { - try db.execute("SELECT f()") + try db.execute(sql: "SELECT f()") XCTFail("Expected DatabaseError") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode.rawValue, 123) @@ -401,7 +399,7 @@ class DatabaseAggregateTests: GRDBTestCase { dbQueue.add(function: fn) try dbQueue.inDatabase { db in do { - try db.execute("SELECT f()") + try db.execute(sql: "SELECT f()") XCTFail("Expected DatabaseError") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode.rawValue, 123) @@ -424,7 +422,7 @@ class DatabaseAggregateTests: GRDBTestCase { dbQueue.add(function: fn) try dbQueue.inDatabase { db in do { - try db.execute("SELECT f()") + try db.execute(sql: "SELECT f()") XCTFail("Expected DatabaseError") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) @@ -449,7 +447,7 @@ class DatabaseAggregateTests: GRDBTestCase { dbQueue.add(function: fn) try dbQueue.inDatabase { db in do { - try db.execute("SELECT f()") + try db.execute(sql: "SELECT f()") XCTFail("Expected DatabaseError") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) @@ -470,7 +468,7 @@ class DatabaseAggregateTests: GRDBTestCase { dbQueue.add(function: fn) try dbQueue.inDatabase { db in do { - try db.execute("SELECT f()") + try db.execute(sql: "SELECT f()") XCTFail("Expected DatabaseError") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode.rawValue, 123) @@ -491,7 +489,7 @@ class DatabaseAggregateTests: GRDBTestCase { dbQueue.add(function: fn) try dbQueue.inDatabase { db in do { - try db.execute("SELECT f()") + try db.execute(sql: "SELECT f()") XCTFail("Expected DatabaseError") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode.rawValue, 123) @@ -512,7 +510,7 @@ class DatabaseAggregateTests: GRDBTestCase { dbQueue.add(function: fn) try dbQueue.inDatabase { db in do { - try db.execute("SELECT f()") + try db.execute(sql: "SELECT f()") XCTFail("Expected DatabaseError") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) @@ -541,7 +539,7 @@ class DatabaseAggregateTests: GRDBTestCase { let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self) dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT f(a) FROM (SELECT 1 AS a UNION ALL SELECT 2 UNION ALL SELECT 3)")!, 6) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f(a) FROM (SELECT 1 AS a UNION ALL SELECT 2 UNION ALL SELECT 3)")!, 6) } } @@ -561,7 +559,7 @@ class DatabaseAggregateTests: GRDBTestCase { let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self) dbQueue.add(function: fn) try dbQueue.inDatabase { db in - let row = try Row.fetchOne(db, "SELECT f(a), f(b) FROM (SELECT 1 AS a, 2 AS b UNION ALL SELECT 2, 4 UNION ALL SELECT 3, 6)")! + let row = try Row.fetchOne(db, sql: "SELECT f(a), f(b) FROM (SELECT 1 AS a, 2 AS b UNION ALL SELECT 2, 4 UNION ALL SELECT 3, 6)")! XCTAssertEqual(row[0], 6) XCTAssertEqual(row[1], 12) } @@ -596,7 +594,7 @@ class DatabaseAggregateTests: GRDBTestCase { try dbQueue.inDatabase { db in XCTAssertEqual(allocationCount, 0) XCTAssertEqual(aliveCount, 0) - try db.execute("SELECT f()") + try db.execute(sql: "SELECT f()") XCTAssertEqual(allocationCount, 1) XCTAssertEqual(aliveCount, 0) } @@ -631,7 +629,7 @@ class DatabaseAggregateTests: GRDBTestCase { dbQueue.inDatabase { db in XCTAssertEqual(allocationCount, 0) XCTAssertEqual(aliveCount, 0) - _ = try? db.execute("SELECT f()") + _ = try? db.execute(sql: "SELECT f()") XCTAssertEqual(allocationCount, 1) XCTAssertEqual(aliveCount, 0) } @@ -665,7 +663,7 @@ class DatabaseAggregateTests: GRDBTestCase { dbQueue.inDatabase { db in XCTAssertEqual(allocationCount, 0) XCTAssertEqual(aliveCount, 0) - _ = try? db.execute("SELECT f()") + _ = try? db.execute(sql: "SELECT f()") XCTAssertEqual(allocationCount, 1) XCTAssertEqual(aliveCount, 0) } diff --git a/Tests/GRDBTests/DatabaseCollationTests.swift b/Tests/GRDBTests/DatabaseCollationTests.swift index 04297a1db..9e83e2fb0 100644 --- a/Tests/GRDBTests/DatabaseCollationTests.swift +++ b/Tests/GRDBTests/DatabaseCollationTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,37 +10,37 @@ class DatabaseCollationTests: GRDBTestCase { func testDefaultCollations() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE strings (id INTEGER PRIMARY KEY, name TEXT)") - try db.execute("INSERT INTO strings VALUES (1, '1')") - try db.execute("INSERT INTO strings VALUES (2, '2')") - try db.execute("INSERT INTO strings VALUES (3, '10')") - try db.execute("INSERT INTO strings VALUES (4, 'a')") - try db.execute("INSERT INTO strings VALUES (5, 'à')") - try db.execute("INSERT INTO strings VALUES (6, 'A')") - try db.execute("INSERT INTO strings VALUES (7, 'Z')") - try db.execute("INSERT INTO strings VALUES (8, 'z')") + try db.execute(sql: "CREATE TABLE strings (id INTEGER PRIMARY KEY, name TEXT)") + try db.execute(sql: "INSERT INTO strings VALUES (1, '1')") + try db.execute(sql: "INSERT INTO strings VALUES (2, '2')") + try db.execute(sql: "INSERT INTO strings VALUES (3, '10')") + try db.execute(sql: "INSERT INTO strings VALUES (4, 'a')") + try db.execute(sql: "INSERT INTO strings VALUES (5, 'à')") + try db.execute(sql: "INSERT INTO strings VALUES (6, 'A')") + try db.execute(sql: "INSERT INTO strings VALUES (7, 'Z')") + try db.execute(sql: "INSERT INTO strings VALUES (8, 'z')") // Swift 4.2 and Swift 4.1 don't sort strings in the same way if "z" < "à" { XCTAssertEqual( - try Int.fetchAll(db, "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.unicodeCompare.name), id"), + try Int.fetchAll(db, sql: "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.unicodeCompare.name), id"), [1,3,2,6,7,4,8,5]) } else { XCTAssertEqual( - try Int.fetchAll(db, "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.unicodeCompare.name), id"), + try Int.fetchAll(db, sql: "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.unicodeCompare.name), id"), [1,3,2,6,7,4,5,8]) } XCTAssertEqual( - try Int.fetchAll(db, "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.caseInsensitiveCompare.name), id"), + try Int.fetchAll(db, sql: "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.caseInsensitiveCompare.name), id"), [1,3,2,4,6,5,7,8]) XCTAssertEqual( - try Int.fetchAll(db, "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.localizedCaseInsensitiveCompare.name), id"), + try Int.fetchAll(db, sql: "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.localizedCaseInsensitiveCompare.name), id"), [1,3,2,4,6,5,7,8]) XCTAssertEqual( - try Int.fetchAll(db, "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.localizedCompare.name), id"), + try Int.fetchAll(db, sql: "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.localizedCompare.name), id"), [1,3,2,4,6,5,8,7]) XCTAssertEqual( - try Int.fetchAll(db, "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.localizedStandardCompare.name), id"), + try Int.fetchAll(db, sql: "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.localizedStandardCompare.name), id"), [1,2,3,4,6,5,8,7]) } } @@ -63,18 +61,18 @@ class DatabaseCollationTests: GRDBTestCase { dbQueue.add(collation: collation) try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE strings (id INTEGER PRIMARY KEY, name TEXT COLLATE LOCALIZED_STANDARD)") - try db.execute("INSERT INTO strings VALUES (1, 'a')") - try db.execute("INSERT INTO strings VALUES (2, 'aa')") - try db.execute("INSERT INTO strings VALUES (3, 'aaa')") - try db.execute("INSERT INTO strings VALUES (4, 'b')") - try db.execute("INSERT INTO strings VALUES (5, 'bb')") - try db.execute("INSERT INTO strings VALUES (6, 'bbb')") - try db.execute("INSERT INTO strings VALUES (7, 'c')") - try db.execute("INSERT INTO strings VALUES (8, 'cc')") - try db.execute("INSERT INTO strings VALUES (9, 'ccc')") + try db.execute(sql: "CREATE TABLE strings (id INTEGER PRIMARY KEY, name TEXT COLLATE LOCALIZED_STANDARD)") + try db.execute(sql: "INSERT INTO strings VALUES (1, 'a')") + try db.execute(sql: "INSERT INTO strings VALUES (2, 'aa')") + try db.execute(sql: "INSERT INTO strings VALUES (3, 'aaa')") + try db.execute(sql: "INSERT INTO strings VALUES (4, 'b')") + try db.execute(sql: "INSERT INTO strings VALUES (5, 'bb')") + try db.execute(sql: "INSERT INTO strings VALUES (6, 'bbb')") + try db.execute(sql: "INSERT INTO strings VALUES (7, 'c')") + try db.execute(sql: "INSERT INTO strings VALUES (8, 'cc')") + try db.execute(sql: "INSERT INTO strings VALUES (9, 'ccc')") - let ids = try Int.fetchAll(db, "SELECT id FROM strings ORDER BY NAME") + let ids = try Int.fetchAll(db, sql: "SELECT id FROM strings ORDER BY NAME") XCTAssertEqual(ids, [1,4,7,2,5,8,3,6,9]) } } diff --git a/Tests/GRDBTests/DatabaseCursorTests.swift b/Tests/GRDBTests/DatabaseCursorTests.swift index 60947fe3b..02a2733e5 100644 --- a/Tests/GRDBTests/DatabaseCursorTests.swift +++ b/Tests/GRDBTests/DatabaseCursorTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -14,18 +12,18 @@ class DatabaseCursorTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in do { - let cursor = try Int.fetchCursor(db, "SELECT 1 WHERE 0") + let cursor = try Int.fetchCursor(db, sql: "SELECT 1 WHERE 0") XCTAssert(try cursor.next() == nil) // end XCTAssert(try cursor.next() == nil) // past the end } do { - let cursor = try Int.fetchCursor(db, "SELECT 1") + let cursor = try Int.fetchCursor(db, sql: "SELECT 1") XCTAssertEqual(try cursor.next()!, 1) XCTAssert(try cursor.next() == nil) // end XCTAssert(try cursor.next() == nil) // past the end } do { - let cursor = try Int.fetchCursor(db, "SELECT 1 UNION ALL SELECT 2") + let cursor = try Int.fetchCursor(db, sql: "SELECT 1 UNION ALL SELECT 2") XCTAssertEqual(try cursor.next()!, 1) XCTAssertEqual(try cursor.next()!, 2) XCTAssert(try cursor.next() == nil) // end @@ -40,7 +38,7 @@ class DatabaseCursorTests: GRDBTestCase { let customError = NSError(domain: "Custom", code: 0xDEAD) dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError }) try dbQueue.inDatabase { db in - let cursor = try Int.fetchCursor(db, "SELECT throw()") + let cursor = try Int.fetchCursor(db, sql: "SELECT throw()") do { _ = try cursor.next() XCTFail() @@ -59,7 +57,7 @@ class DatabaseCursorTests: GRDBTestCase { let customError = DatabaseError(resultCode: ResultCode(rawValue: 0xDEAD), message: "custom error") dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError }) try dbQueue.inDatabase { db in - let cursor = try Int.fetchCursor(db, "SELECT throw()") + let cursor = try Int.fetchCursor(db, sql: "SELECT throw()") do { _ = try cursor.next() XCTFail() diff --git a/Tests/GRDBTests/DatabaseDateDecodingStrategyTests.swift b/Tests/GRDBTests/DatabaseDateDecodingStrategyTests.swift index d3e1a9c6b..d2b13e337 100644 --- a/Tests/GRDBTests/DatabaseDateDecodingStrategyTests.swift +++ b/Tests/GRDBTests/DatabaseDateDecodingStrategyTests.swift @@ -1,8 +1,6 @@ import Foundation import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -69,7 +67,7 @@ class DatabaseDateDecodingStrategyTests: GRDBTestCase { databaseValue: DatabaseValueConvertible?, with test: (Date?) -> Void) throws { - let request = SQLRequest("SELECT ? AS date", arguments: [databaseValue]) + let request = SQLRequest(sql: "SELECT ? AS date", arguments: [databaseValue]) do { // test decoding straight from SQLite let record = try T.fetchOne(db, request)! diff --git a/Tests/GRDBTests/DatabaseDateEncodingStrategyTests.swift b/Tests/GRDBTests/DatabaseDateEncodingStrategyTests.swift index b4f109185..a1bea43ab 100644 --- a/Tests/GRDBTests/DatabaseDateEncodingStrategyTests.swift +++ b/Tests/GRDBTests/DatabaseDateEncodingStrategyTests.swift @@ -1,8 +1,6 @@ import XCTest import Foundation -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else @testable import GRDB @@ -170,7 +168,6 @@ extension DatabaseDateEncodingStrategyTests { // MARK: - iso8601(ISO8601DateFormatter) -@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) extension DatabaseDateEncodingStrategyTests { func testIso8601() { // check ISO8601DateFormatter availabiliity diff --git a/Tests/GRDBTests/DatabaseErrorTests.swift b/Tests/GRDBTests/DatabaseErrorTests.swift index 82d4139bf..ddd9d65a3 100644 --- a/Tests/GRDBTests/DatabaseErrorTests.swift +++ b/Tests/GRDBTests/DatabaseErrorTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -24,10 +22,10 @@ class DatabaseErrorTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() do { try dbQueue.inTransaction { db in - try db.execute("CREATE TABLE persons (id INTEGER PRIMARY KEY)") - try db.execute("CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)") + try db.execute(sql: "CREATE TABLE persons (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)") sqlQueries.removeAll() - try db.execute("INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [1, "Bobby"]) + try db.execute(sql: "INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [1, "Bobby"]) XCTFail() return .commit } @@ -55,10 +53,10 @@ class DatabaseErrorTests: GRDBTestCase { do { try db.inSavepoint { XCTAssertTrue(db.isInsideTransaction) - try db.execute("CREATE TABLE persons (id INTEGER PRIMARY KEY)") - try db.execute("CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)") + try db.execute(sql: "CREATE TABLE persons (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)") sqlQueries.removeAll() - try db.execute("INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [1, "Bobby"]) + try db.execute(sql: "INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [1, "Bobby"]) XCTFail() return .commit } @@ -82,14 +80,14 @@ class DatabaseErrorTests: GRDBTestCase { func testDatabaseErrorThrownByUpdateStatementContainSQLAndArguments() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (id INTEGER PRIMARY KEY)") - try db.execute("CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)") + try db.execute(sql: "CREATE TABLE persons (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)") } // db.execute(sql, arguments) try dbQueue.inDatabase { db in do { - try db.execute("INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [1, "Bobby"]) + try db.execute(sql: "INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [1, "Bobby"]) XCTFail() } catch let error as DatabaseError { // SQLITE_CONSTRAINT_FOREIGNKEY was added in SQLite 3.7.16 http://www.sqlite.org/changes.html#version_3_7_16 @@ -105,7 +103,7 @@ class DatabaseErrorTests: GRDBTestCase { // statement.execute(arguments) try dbQueue.inDatabase { db in do { - let statement = try db.makeUpdateStatement("INSERT INTO pets (masterId, name) VALUES (?, ?)") + let statement = try db.makeUpdateStatement(sql: "INSERT INTO pets (masterId, name) VALUES (?, ?)") try statement.execute(arguments: [1, "Bobby"]) XCTFail() } catch let error as DatabaseError { @@ -122,7 +120,7 @@ class DatabaseErrorTests: GRDBTestCase { // statement.execute() try dbQueue.inDatabase { db in do { - let statement = try db.makeUpdateStatement("INSERT INTO pets (masterId, name) VALUES (?, ?)") + let statement = try db.makeUpdateStatement(sql: "INSERT INTO pets (masterId, name) VALUES (?, ?)") statement.arguments = [1, "Bobby"] try statement.execute() XCTFail() @@ -142,7 +140,7 @@ class DatabaseErrorTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in do { - try db.execute(""" + try db.execute(sql: """ CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT, age INT); CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT); INSERT INTO pets (masterId, name) VALUES (1, 'Bobby') @@ -166,7 +164,7 @@ class DatabaseErrorTests: GRDBTestCase { try db.create(table: "parents") { $0.column("id", .integer).primaryKey() } try db.create(table: "children") { $0.column("parentId", .integer).references("parents") } do { - try db.execute("INSERT INTO children (parentId) VALUES (1)") + try db.execute(sql: "INSERT INTO children (parentId) VALUES (1)") } catch let error as DatabaseError { // SQLITE_CONSTRAINT_FOREIGNKEY was added in SQLite 3.7.16 http://www.sqlite.org/changes.html#version_3_7_16 // It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS) @@ -182,7 +180,7 @@ class DatabaseErrorTests: GRDBTestCase { try db.create(table: "parents") { $0.column("id", .integer).primaryKey() } try db.create(table: "children") { $0.column("parentId", .integer).references("parents") } do { - try db.execute("INSERT INTO children (parentId) VALUES (1)") + try db.execute(sql: "INSERT INTO children (parentId) VALUES (1)") } catch let error as NSError { XCTAssertEqual(DatabaseError.errorDomain, "GRDB.DatabaseError") XCTAssertEqual(error.domain, DatabaseError.errorDomain) diff --git a/Tests/GRDBTests/DatabaseFunctionTests.swift b/Tests/GRDBTests/DatabaseFunctionTests.swift index 60ae195bb..d5cb28ece 100644 --- a/Tests/GRDBTests/DatabaseFunctionTests.swift +++ b/Tests/GRDBTests/DatabaseFunctionTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -31,25 +29,25 @@ class DatabaseFunctionTests: GRDBTestCase { // See Database.setupDefaultFunctions() let capitalize = DatabaseFunction.capitalize - XCTAssertEqual(try String.fetchOne(db, "SELECT \(capitalize.name)('jérÔME')"), "Jérôme") + XCTAssertEqual(try String.fetchOne(db, sql: "SELECT \(capitalize.name)('jérÔME')"), "Jérôme") let lowercase = DatabaseFunction.lowercase - XCTAssertEqual(try String.fetchOne(db, "SELECT \(lowercase.name)('jérÔME')"), "jérôme") + XCTAssertEqual(try String.fetchOne(db, sql: "SELECT \(lowercase.name)('jérÔME')"), "jérôme") let uppercase = DatabaseFunction.uppercase - XCTAssertEqual(try String.fetchOne(db, "SELECT \(uppercase.name)('jérÔME')"), "JÉRÔME") + XCTAssertEqual(try String.fetchOne(db, sql: "SELECT \(uppercase.name)('jérÔME')"), "JÉRÔME") if #available(iOS 9.0, OSX 10.11, *) { // Locale-dependent tests. Are they fragile? let localizedCapitalize = DatabaseFunction.localizedCapitalize - XCTAssertEqual(try String.fetchOne(db, "SELECT \(localizedCapitalize.name)('jérÔME')"), "Jérôme") + XCTAssertEqual(try String.fetchOne(db, sql: "SELECT \(localizedCapitalize.name)('jérÔME')"), "Jérôme") let localizedLowercase = DatabaseFunction.localizedLowercase - XCTAssertEqual(try String.fetchOne(db, "SELECT \(localizedLowercase.name)('jérÔME')"), "jérôme") + XCTAssertEqual(try String.fetchOne(db, sql: "SELECT \(localizedLowercase.name)('jérÔME')"), "jérôme") let localizedUppercase = DatabaseFunction.localizedUppercase - XCTAssertEqual(try String.fetchOne(db, "SELECT \(localizedUppercase.name)('jérÔME')"), "JÉRÔME") + XCTAssertEqual(try String.fetchOne(db, sql: "SELECT \(localizedUppercase.name)('jérÔME')"), "JÉRÔME") } } } @@ -63,7 +61,7 @@ class DatabaseFunctionTests: GRDBTestCase { } dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertTrue(try DatabaseValue.fetchOne(db, "SELECT f()")!.isNull) + XCTAssertTrue(try DatabaseValue.fetchOne(db, sql: "SELECT f()")!.isNull) } } @@ -74,7 +72,7 @@ class DatabaseFunctionTests: GRDBTestCase { } dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertEqual(try Int64.fetchOne(db, "SELECT f()")!, Int64(1)) + XCTAssertEqual(try Int64.fetchOne(db, sql: "SELECT f()")!, Int64(1)) } } @@ -85,7 +83,7 @@ class DatabaseFunctionTests: GRDBTestCase { } dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertEqual(try Double.fetchOne(db, "SELECT f()")!, 1e100) + XCTAssertEqual(try Double.fetchOne(db, sql: "SELECT f()")!, 1e100) } } @@ -96,7 +94,7 @@ class DatabaseFunctionTests: GRDBTestCase { } dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertEqual(try String.fetchOne(db, "SELECT f()")!, "foo") + XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f()")!, "foo") } } @@ -107,7 +105,7 @@ class DatabaseFunctionTests: GRDBTestCase { } dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertEqual(try Data.fetchOne(db, "SELECT f()")!, "foo".data(using: .utf8)) + XCTAssertEqual(try Data.fetchOne(db, sql: "SELECT f()")!, "foo".data(using: .utf8)) } } @@ -118,7 +116,7 @@ class DatabaseFunctionTests: GRDBTestCase { } dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertTrue(try CustomValueType.fetchOne(db, "SELECT f()") != nil) + XCTAssertTrue(try CustomValueType.fetchOne(db, sql: "SELECT f()") != nil) } } @@ -131,12 +129,12 @@ class DatabaseFunctionTests: GRDBTestCase { } dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertTrue(try Bool.fetchOne(db, "SELECT f(NULL)")!) - XCTAssertFalse(try Bool.fetchOne(db, "SELECT f(1)")!) - XCTAssertFalse(try Bool.fetchOne(db, "SELECT f(1.1)")!) - XCTAssertFalse(try Bool.fetchOne(db, "SELECT f('foo')")!) - XCTAssertFalse(try Bool.fetchOne(db, "SELECT f(?)", arguments: ["foo".data(using: .utf8)])!) - XCTAssertFalse(try Bool.fetchOne(db, "SELECT f(?)", arguments: [Data()])!) + XCTAssertTrue(try Bool.fetchOne(db, sql: "SELECT f(NULL)")!) + XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f(1)")!) + XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f(1.1)")!) + XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f('foo')")!) + XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f(?)", arguments: ["foo".data(using: .utf8)])!) + XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f(?)", arguments: [Data()])!) } } @@ -147,9 +145,9 @@ class DatabaseFunctionTests: GRDBTestCase { } dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertTrue(try Int64.fetchOne(db, "SELECT f(NULL)") == nil) - XCTAssertEqual(try Int64.fetchOne(db, "SELECT f(1)")!, 1) - XCTAssertEqual(try Int64.fetchOne(db, "SELECT f(1.1)")!, 1) + XCTAssertTrue(try Int64.fetchOne(db, sql: "SELECT f(NULL)") == nil) + XCTAssertEqual(try Int64.fetchOne(db, sql: "SELECT f(1)")!, 1) + XCTAssertEqual(try Int64.fetchOne(db, sql: "SELECT f(1.1)")!, 1) } } @@ -160,9 +158,9 @@ class DatabaseFunctionTests: GRDBTestCase { } dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertTrue(try Double.fetchOne(db, "SELECT f(NULL)") == nil) - XCTAssertEqual(try Double.fetchOne(db, "SELECT f(1)")!, 1.0) - XCTAssertEqual(try Double.fetchOne(db, "SELECT f(1.1)")!, 1.1) + XCTAssertTrue(try Double.fetchOne(db, sql: "SELECT f(NULL)") == nil) + XCTAssertEqual(try Double.fetchOne(db, sql: "SELECT f(1)")!, 1.0) + XCTAssertEqual(try Double.fetchOne(db, sql: "SELECT f(1.1)")!, 1.1) } } @@ -173,8 +171,8 @@ class DatabaseFunctionTests: GRDBTestCase { } dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertTrue(try String.fetchOne(db, "SELECT f(NULL)") == nil) - XCTAssertEqual(try String.fetchOne(db, "SELECT f('foo')")!, "foo") + XCTAssertTrue(try String.fetchOne(db, sql: "SELECT f(NULL)") == nil) + XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f('foo')")!, "foo") } } @@ -185,9 +183,9 @@ class DatabaseFunctionTests: GRDBTestCase { } dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertTrue(try Data.fetchOne(db, "SELECT f(NULL)") == nil) - XCTAssertEqual(try Data.fetchOne(db, "SELECT f(?)", arguments: ["foo".data(using: .utf8)])!, "foo".data(using: .utf8)) - XCTAssertEqual(try Data.fetchOne(db, "SELECT f(?)", arguments: [Data()])!, Data()) + XCTAssertTrue(try Data.fetchOne(db, sql: "SELECT f(NULL)") == nil) + XCTAssertEqual(try Data.fetchOne(db, sql: "SELECT f(?)", arguments: ["foo".data(using: .utf8)])!, "foo".data(using: .utf8)) + XCTAssertEqual(try Data.fetchOne(db, sql: "SELECT f(?)", arguments: [Data()])!, Data()) } } @@ -198,8 +196,8 @@ class DatabaseFunctionTests: GRDBTestCase { } dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertTrue(try CustomValueType.fetchOne(db, "SELECT f(NULL)") == nil) - XCTAssertTrue(try CustomValueType.fetchOne(db, "SELECT f('CustomValueType')") != nil) + XCTAssertTrue(try CustomValueType.fetchOne(db, sql: "SELECT f(NULL)") == nil) + XCTAssertTrue(try CustomValueType.fetchOne(db, sql: "SELECT f('CustomValueType')") != nil) } } @@ -212,9 +210,9 @@ class DatabaseFunctionTests: GRDBTestCase { } dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertEqual(try String.fetchOne(db, "SELECT f()")!, "foo") + XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f()")!, "foo") do { - try db.execute("SELECT f(1)") + try db.execute(sql: "SELECT f(1)") XCTFail("Expected error") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) @@ -232,11 +230,11 @@ class DatabaseFunctionTests: GRDBTestCase { } dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertEqual(try String.fetchOne(db, "SELECT upper(?)", arguments: ["Roué"])!, "ROUé") - XCTAssertEqual(try String.fetchOne(db, "SELECT f(?)", arguments: ["Roué"])!, "ROUÉ") - XCTAssertTrue(try String.fetchOne(db, "SELECT f(NULL)") == nil) + XCTAssertEqual(try String.fetchOne(db, sql: "SELECT upper(?)", arguments: ["Roué"])!, "ROUé") + XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f(?)", arguments: ["Roué"])!, "ROUÉ") + XCTAssertTrue(try String.fetchOne(db, sql: "SELECT f(NULL)") == nil) do { - try db.execute("SELECT f()") + try db.execute(sql: "SELECT f()") XCTFail("Expected error") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) @@ -255,9 +253,9 @@ class DatabaseFunctionTests: GRDBTestCase { } dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT f(1, 2)")!, 3) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f(1, 2)")!, 3) do { - try db.execute("SELECT f()") + try db.execute(sql: "SELECT f()") XCTFail("Expected error") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) @@ -275,9 +273,9 @@ class DatabaseFunctionTests: GRDBTestCase { } dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT f()")!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT f(1)")!, 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT f(1, 1)")!, 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f()")!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f(1)")!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f(1, 1)")!, 2) } } @@ -291,7 +289,7 @@ class DatabaseFunctionTests: GRDBTestCase { dbQueue.add(function: fn) try dbQueue.inDatabase { db in do { - try db.execute("SELECT f()") + try db.execute(sql: "SELECT f()") XCTFail("Expected DatabaseError") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) @@ -308,7 +306,7 @@ class DatabaseFunctionTests: GRDBTestCase { dbQueue.add(function: fn) try dbQueue.inDatabase { db in do { - try db.execute("SELECT f()") + try db.execute(sql: "SELECT f()") XCTFail("Expected DatabaseError") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode.rawValue, 123) @@ -325,7 +323,7 @@ class DatabaseFunctionTests: GRDBTestCase { dbQueue.add(function: fn) try dbQueue.inDatabase { db in do { - try db.execute("SELECT f()") + try db.execute(sql: "SELECT f()") XCTFail("Expected DatabaseError") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode.rawValue, 123) @@ -342,7 +340,7 @@ class DatabaseFunctionTests: GRDBTestCase { dbQueue.add(function: fn) try dbQueue.inDatabase { db in do { - try db.execute("SELECT f()") + try db.execute(sql: "SELECT f()") XCTFail("Expected DatabaseError") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) @@ -364,7 +362,7 @@ class DatabaseFunctionTests: GRDBTestCase { dbQueue.add(function: fn) try dbQueue.inDatabase { db in x = 321 - XCTAssertEqual(try Int.fetchOne(db, "SELECT f()")!, 321) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f()")!, 321) } } } diff --git a/Tests/GRDBTests/DatabaseLogErrorTests.swift b/Tests/GRDBTests/DatabaseLogErrorTests.swift index 9ff05cb7b..1dfb7d00b 100644 --- a/Tests/GRDBTests/DatabaseLogErrorTests.swift +++ b/Tests/GRDBTests/DatabaseLogErrorTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else @testable import GRDB @@ -12,7 +10,7 @@ class DatabaseLogErrorTests: GRDBTestCase { func testErrorLog() throws { let dbQueue = try makeDatabaseQueue() dbQueue.inDatabase { db in - _ = try? db.execute("Abracadabra") + _ = try? db.execute(sql: "Abracadabra") } XCTAssertEqual(lastResultCode!, ResultCode.SQLITE_ERROR) // Don't check for exact error message because it depends on SQLite version diff --git a/Tests/GRDBTests/DatabaseMigratorTests.swift b/Tests/GRDBTests/DatabaseMigratorTests.swift index ff6ba59ac..4c0b00059 100644 --- a/Tests/GRDBTests/DatabaseMigratorTests.swift +++ b/Tests/GRDBTests/DatabaseMigratorTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -14,14 +12,14 @@ class DatabaseMigratorTests : GRDBTestCase { var migrator = DatabaseMigrator() migrator.registerMigration("createPersons") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE persons ( id INTEGER PRIMARY KEY, name TEXT) """) } migrator.registerMigration("createPets") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE pets ( id INTEGER PRIMARY KEY, masterID INTEGER NOT NULL @@ -38,7 +36,7 @@ class DatabaseMigratorTests : GRDBTestCase { } migrator.registerMigration("destroyPersons") { db in - try db.execute("DROP TABLE pets") + try db.execute(sql: "DROP TABLE pets") } try migrator.migrate(dbQueue) @@ -53,14 +51,14 @@ class DatabaseMigratorTests : GRDBTestCase { var migrator = DatabaseMigrator() migrator.registerMigration("createPersons") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE persons ( id INTEGER PRIMARY KEY, name TEXT) """) } migrator.registerMigration("createPets") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE pets ( id INTEGER PRIMARY KEY, masterID INTEGER NOT NULL @@ -77,7 +75,7 @@ class DatabaseMigratorTests : GRDBTestCase { } migrator.registerMigration("destroyPersons") { db in - try db.execute("DROP TABLE pets") + try db.execute(sql: "DROP TABLE pets") } try migrator.migrate(dbPool) @@ -92,13 +90,13 @@ class DatabaseMigratorTests : GRDBTestCase { var migrator = DatabaseMigrator() migrator.registerMigration("a") { db in - try db.execute("CREATE TABLE a (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE a (id INTEGER PRIMARY KEY)") } migrator.registerMigration("b") { db in - try db.execute("CREATE TABLE b (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE b (id INTEGER PRIMARY KEY)") } migrator.registerMigration("c") { db in - try db.execute("CREATE TABLE c (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE c (id INTEGER PRIMARY KEY)") } // one step @@ -137,15 +135,15 @@ class DatabaseMigratorTests : GRDBTestCase { func testMigrationFailureTriggersRollback() throws { var migrator = DatabaseMigrator() migrator.registerMigration("createPersons") { db in - try db.execute("CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT)") - try db.execute("CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)") - try db.execute("INSERT INTO persons (name) VALUES ('Arthur')") + try db.execute(sql: "CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT)") + try db.execute(sql: "CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)") + try db.execute(sql: "INSERT INTO persons (name) VALUES ('Arthur')") } migrator.registerMigration("foreignKeyError") { db in - try db.execute("INSERT INTO persons (name) VALUES ('Barbara')") + try db.execute(sql: "INSERT INTO persons (name) VALUES ('Barbara')") do { // triggers immediate foreign key error: - try db.execute("INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [123, "Bobby"]) + try db.execute(sql: "INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [123, "Bobby"]) XCTFail("Expected error") } catch { throw error @@ -169,7 +167,7 @@ class DatabaseMigratorTests : GRDBTestCase { XCTAssertEqual(error.description.lowercased(), "sqlite error 19 with statement `insert into pets (masterid, name) values (?, ?)` arguments [123, \"bobby\"]: foreign key constraint failed") let names = try dbQueue.inDatabase { db in - try String.fetchAll(db, "SELECT name FROM persons") + try String.fetchAll(db, sql: "SELECT name FROM persons") } XCTAssertEqual(names, ["Arthur"]) } @@ -183,25 +181,25 @@ class DatabaseMigratorTests : GRDBTestCase { #endif var migrator = DatabaseMigrator() migrator.registerMigration("createPersons") { db in - try db.execute("CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT, tmp TEXT)") - try db.execute("CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)") - try db.execute("INSERT INTO persons (name) VALUES ('Arthur')") + try db.execute(sql: "CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT, tmp TEXT)") + try db.execute(sql: "CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)") + try db.execute(sql: "INSERT INTO persons (name) VALUES ('Arthur')") let personId = db.lastInsertedRowID - try db.execute("INSERT INTO pets (masterId, name) VALUES (?, 'Bobby')", arguments:[personId]) + try db.execute(sql: "INSERT INTO pets (masterId, name) VALUES (?, 'Bobby')", arguments:[personId]) } migrator.registerMigrationWithDeferredForeignKeyCheck("removePersonTmpColumn") { db in // Test the technique described at https://www.sqlite.org/lang_altertable.html#otheralter - try db.execute("CREATE TABLE new_persons (id INTEGER PRIMARY KEY, name TEXT)") - try db.execute("INSERT INTO new_persons SELECT id, name FROM persons") - try db.execute("DROP TABLE persons") - try db.execute("ALTER TABLE new_persons RENAME TO persons") + try db.execute(sql: "CREATE TABLE new_persons (id INTEGER PRIMARY KEY, name TEXT)") + try db.execute(sql: "INSERT INTO new_persons SELECT id, name FROM persons") + try db.execute(sql: "DROP TABLE persons") + try db.execute(sql: "ALTER TABLE new_persons RENAME TO persons") } migrator.registerMigrationWithDeferredForeignKeyCheck("foreignKeyError") { db in // Make sure foreign keys are checked at the end. - try db.execute("INSERT INTO persons (name) VALUES ('Barbara')") + try db.execute(sql: "INSERT INTO persons (name) VALUES ('Barbara')") do { // triggers foreign key error, but not now. - try db.execute("INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [123, "Bobby"]) + try db.execute(sql: "INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [123, "Bobby"]) } catch { XCTFail("Error not expected at this point") } @@ -222,7 +220,7 @@ class DatabaseMigratorTests : GRDBTestCase { try dbQueue.inDatabase { db in // Arthur inserted (migration 1), Barbara (migration 3) not inserted. - var rows = try Row.fetchAll(db, "SELECT * FROM persons") + var rows = try Row.fetchAll(db, sql: "SELECT * FROM persons") XCTAssertEqual(rows.count, 1) var row = rows.first! XCTAssertEqual(row["name"] as String, "Arthur") @@ -231,7 +229,7 @@ class DatabaseMigratorTests : GRDBTestCase { XCTAssertEqual(Array(row.columnNames), ["id", "name"]) // Bobby inserted (migration 1), not deleted by migration 2. - rows = try Row.fetchAll(db, "SELECT * FROM pets") + rows = try Row.fetchAll(db, sql: "SELECT * FROM pets") XCTAssertEqual(rows.count, 1) row = rows.first! XCTAssertEqual(row["name"] as String, "Bobby") @@ -259,7 +257,7 @@ class DatabaseMigratorTests : GRDBTestCase { } } migrator2.registerMigration("2") { db in - try db.execute("INSERT INTO player (id, name, score) VALUES (NULL, 'Arthur', 1000)") + try db.execute(sql: "INSERT INTO player (id, name, score) VALUES (NULL, 'Arthur', 1000)") } // Apply 1st migrator @@ -288,7 +286,7 @@ class DatabaseMigratorTests : GRDBTestCase { var witness = 1 migrator.registerMigration("1") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE t1(id INTEGER PRIMARY KEY); INSERT INTO t1(id) VALUES (?) """, arguments: [witness]) @@ -299,16 +297,16 @@ class DatabaseMigratorTests : GRDBTestCase { // 1st migration try migrator.migrate(dbQueue) - try XCTAssertEqual(dbQueue.read { try Int.fetchOne($0, "SELECT id FROM t1") }, 1) + try XCTAssertEqual(dbQueue.read { try Int.fetchOne($0, sql: "SELECT id FROM t1") }, 1) // 2nd migration does not erase database migrator.registerMigration("2") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE t2(id INTEGER PRIMARY KEY); """) } try migrator.migrate(dbQueue) - try XCTAssertEqual(dbQueue.read { try Int.fetchOne($0, "SELECT id FROM t1") }, 1) + try XCTAssertEqual(dbQueue.read { try Int.fetchOne($0, sql: "SELECT id FROM t1") }, 1) try XCTAssertTrue(dbQueue.read { try $0.tableExists("t2") }) } } diff --git a/Tests/GRDBTests/DatabasePoolBackupTests.swift b/Tests/GRDBTests/DatabasePoolBackupTests.swift index 0bf37285f..55c760afd 100644 --- a/Tests/GRDBTests/DatabasePoolBackupTests.swift +++ b/Tests/GRDBTests/DatabasePoolBackupTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else @testable import GRDB @@ -10,23 +8,30 @@ import XCTest class DatabasePoolBackupTests: GRDBTestCase { func testBackup() throws { + #if GRDBCIPHER + // SQLCipher can't backup encrypted databases: skip this test + if dbConfiguration.passphrase != nil { + return + } + #endif + let source = try makeDatabasePool(filename: "source.sqlite") let destination = try makeDatabasePool(filename: "destination.sqlite") try source.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") - try db.execute("INSERT INTO items (id) VALUES (NULL)") - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 1) + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1) } try source.backup(to: destination) try destination.read { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1) } try source.write { db in - try db.execute("DROP TABLE items") + try db.execute(sql: "DROP TABLE items") } try source.backup(to: destination) @@ -43,9 +48,9 @@ class DatabasePoolBackupTests: GRDBTestCase { // let destination = try makeDatabasePool(filename: "destination.sqlite") // // try source.write { db in -// try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") -// try db.execute("INSERT INTO items (id) VALUES (NULL)") -// XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 1) +// try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") +// try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") +// XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1) // } // // let s1 = DispatchSemaphore(value: 0) @@ -53,7 +58,7 @@ class DatabasePoolBackupTests: GRDBTestCase { // DispatchQueue.global().async { // _ = s1.wait(timeout: .distantFuture) // try! source.writeInTransaction(.immediate) { db in -// try db.execute("INSERT INTO items (id) VALUES (NULL)") +// try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") // s2.signal() // return .commit // } @@ -67,18 +72,18 @@ class DatabasePoolBackupTests: GRDBTestCase { // }, // afterBackupStep: { // try! source.write { db in -// try db.execute("INSERT INTO items (id) VALUES (NULL)") +// try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") // } // }) // // try source.read { db in -// XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 3) +// XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 3) // } // try destination.read { db in // // TODO: understand why the fix for https://github.com/groue/GRDB.swift/issues/102 // // had this value change from 2 to 1. // // TODO: Worse, this test is fragile. I've seen not 1 but 2 once. -// XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 1) +// XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1) // } // } } diff --git a/Tests/GRDBTests/DatabasePoolCollationTests.swift b/Tests/GRDBTests/DatabasePoolCollationTests.swift index 4c411092b..5a53822b5 100644 --- a/Tests/GRDBTests/DatabasePoolCollationTests.swift +++ b/Tests/GRDBTests/DatabasePoolCollationTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -18,14 +16,14 @@ class DatabasePoolCollationTests: GRDBTestCase { dbPool.add(collation: collation1) try dbPool.write { db in - try db.execute("CREATE TABLE items (text TEXT COLLATE collation1)") - try db.execute("INSERT INTO items (text) VALUES ('a')") - try db.execute("INSERT INTO items (text) VALUES ('b')") - try db.execute("INSERT INTO items (text) VALUES ('c')") + try db.execute(sql: "CREATE TABLE items (text TEXT COLLATE collation1)") + try db.execute(sql: "INSERT INTO items (text) VALUES ('a')") + try db.execute(sql: "INSERT INTO items (text) VALUES ('b')") + try db.execute(sql: "INSERT INTO items (text) VALUES ('c')") } try dbPool.read { db in - XCTAssertEqual(try String.fetchAll(db, "SELECT text FROM items ORDER BY text"), ["a", "b", "c"]) - XCTAssertEqual(try String.fetchAll(db, "SELECT text FROM items ORDER BY text COLLATE collation1"), ["a", "b", "c"]) + XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text"), ["a", "b", "c"]) + XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation1"), ["a", "b", "c"]) } let collation2 = DatabaseCollation("collation2") { (string1, string2) in @@ -34,7 +32,7 @@ class DatabasePoolCollationTests: GRDBTestCase { dbPool.add(collation: collation2) try dbPool.read { db in - XCTAssertEqual(try String.fetchAll(db, "SELECT text FROM items ORDER BY text COLLATE collation2"), ["c", "b", "a"]) + XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation2"), ["c", "b", "a"]) } } } diff --git a/Tests/GRDBTests/DatabasePoolConcurrencyTests.swift b/Tests/GRDBTests/DatabasePoolConcurrencyTests.swift index 44ef15faa..a70bd9955 100644 --- a/Tests/GRDBTests/DatabasePoolConcurrencyTests.swift +++ b/Tests/GRDBTests/DatabasePoolConcurrencyTests.swift @@ -1,8 +1,6 @@ import XCTest import Dispatch -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -33,10 +31,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { do { let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.writeWithoutTransaction { db in - let journalMode = try String.fetchOne(db, "PRAGMA journal_mode = wal") + let journalMode = try String.fetchOne(db, sql: "PRAGMA journal_mode = wal") XCTAssertEqual(journalMode, "wal") try db.create(table: "moves") { $0.column("value", .integer) } - try db.execute("INSERT INTO moves VALUES (0)") + try db.execute(sql: "INSERT INTO moves VALUES (0)") } } let s0 = DispatchSemaphore(value: 0) @@ -44,14 +42,14 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let dbQueue = try! self.makeDatabaseQueue(filename: "test.sqlite") s0.signal() // Avoid "database is locked" error: don't open the two databases at the same time try! dbQueue.writeWithoutTransaction { db in - try db.execute("BEGIN DEFERRED TRANSACTION") + try db.execute(sql: "BEGIN DEFERRED TRANSACTION") s1.signal() _ = s2.wait(timeout: .distantFuture) - XCTAssertEqual(try Int.fetchOne(db, "SELECT SUM(value) AS balance FROM moves"), 1) // Non-zero balance + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT SUM(value) AS balance FROM moves"), 1) // Non-zero balance s3.signal() _ = s4.wait(timeout: .distantFuture) - XCTAssertEqual(try Int.fetchOne(db, "SELECT SUM(value) AS balance FROM moves"), 1) // Non-zero balance - try db.execute("END") + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT SUM(value) AS balance FROM moves"), 1) // Non-zero balance + try db.execute(sql: "END") } } let block2 = { () in @@ -59,10 +57,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let dbQueue = try! self.makeDatabaseQueue(filename: "test.sqlite") try! dbQueue.writeWithoutTransaction { db in _ = s1.wait(timeout: .distantFuture) - try db.execute("INSERT INTO moves VALUES (1)") + try db.execute(sql: "INSERT INTO moves VALUES (1)") s2.signal() _ = s3.wait(timeout: .distantFuture) - try db.execute("INSERT INTO moves VALUES (-1)") + try db.execute(sql: "INSERT INTO moves VALUES (-1)") s4.signal() } } @@ -95,10 +93,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { do { let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.writeWithoutTransaction { db in - let journalMode = try String.fetchOne(db, "PRAGMA journal_mode = wal") + let journalMode = try String.fetchOne(db, sql: "PRAGMA journal_mode = wal") XCTAssertEqual(journalMode, "wal") try db.create(table: "moves") { $0.column("value", .integer) } - try db.execute("INSERT INTO moves VALUES (0)") + try db.execute(sql: "INSERT INTO moves VALUES (0)") } } let s0 = DispatchSemaphore(value: 0) @@ -107,29 +105,29 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { s0.signal() // Avoid "database is locked" error: don't open the two databases at the same time try! dbQueue.writeWithoutTransaction { db in _ = s1.wait(timeout: .distantFuture) - try db.execute("BEGIN DEFERRED TRANSACTION") + try db.execute(sql: "BEGIN DEFERRED TRANSACTION") s2.signal() _ = s3.wait(timeout: .distantFuture) - XCTAssertEqual(try Int.fetchOne(db, "SELECT SUM(value) AS balance FROM moves"), 0) // Zero balance + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT SUM(value) AS balance FROM moves"), 0) // Zero balance s4.signal() _ = s5.wait(timeout: .distantFuture) - XCTAssertEqual(try Int.fetchOne(db, "SELECT SUM(value) AS balance FROM moves"), 0) // Zero balance - try db.execute("END") + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT SUM(value) AS balance FROM moves"), 0) // Zero balance + try db.execute(sql: "END") } } let block2 = { () in _ = s0.wait(timeout: .distantFuture) // Avoid "database is locked" error: don't open the two databases at the same time let dbQueue = try! self.makeDatabaseQueue(filename: "test.sqlite") try! dbQueue.writeWithoutTransaction { db in - try db.execute("BEGIN DEFERRED TRANSACTION") + try db.execute(sql: "BEGIN DEFERRED TRANSACTION") s1.signal() _ = s2.wait(timeout: .distantFuture) - try db.execute("INSERT INTO moves VALUES (1)") + try db.execute(sql: "INSERT INTO moves VALUES (1)") s3.signal() _ = s4.wait(timeout: .distantFuture) - try db.execute("INSERT INTO moves VALUES (-1)") + try db.execute(sql: "INSERT INTO moves VALUES (-1)") s5.signal() - try db.execute("END") + try db.execute(sql: "END") } } let blocks = [block1, block2] @@ -160,10 +158,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { do { let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.writeWithoutTransaction { db in - let journalMode = try String.fetchOne(db, "PRAGMA journal_mode = wal") + let journalMode = try String.fetchOne(db, sql: "PRAGMA journal_mode = wal") XCTAssertEqual(journalMode, "wal") try db.create(table: "moves") { $0.column("value", .integer) } - try db.execute("INSERT INTO moves VALUES (0)") + try db.execute(sql: "INSERT INTO moves VALUES (0)") } } let s0 = DispatchSemaphore(value: 0) @@ -171,14 +169,14 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let dbQueue = try! self.makeDatabaseQueue(filename: "test.sqlite") s0.signal() // Avoid "database is locked" error: don't open the two databases at the same time try! dbQueue.writeWithoutTransaction { db in - try db.execute("BEGIN DEFERRED TRANSACTION") + try db.execute(sql: "BEGIN DEFERRED TRANSACTION") s1.signal() _ = s2.wait(timeout: .distantFuture) - XCTAssertEqual(try Int.fetchOne(db, "SELECT SUM(value) AS balance FROM moves"), 0) // Zero balance + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT SUM(value) AS balance FROM moves"), 0) // Zero balance s3.signal() _ = s4.wait(timeout: .distantFuture) - XCTAssertEqual(try Int.fetchOne(db, "SELECT SUM(value) AS balance FROM moves"), 0) // Zero balance - try db.execute("END") + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT SUM(value) AS balance FROM moves"), 0) // Zero balance + try db.execute(sql: "END") } } let block2 = { () in @@ -186,13 +184,13 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let dbQueue = try! self.makeDatabaseQueue(filename: "test.sqlite") try! dbQueue.writeWithoutTransaction { db in _ = s1.wait(timeout: .distantFuture) - try db.execute("BEGIN DEFERRED TRANSACTION") - try db.execute("INSERT INTO moves VALUES (1)") + try db.execute(sql: "BEGIN DEFERRED TRANSACTION") + try db.execute(sql: "INSERT INTO moves VALUES (1)") s2.signal() _ = s3.wait(timeout: .distantFuture) - try db.execute("INSERT INTO moves VALUES (-1)") + try db.execute(sql: "INSERT INTO moves VALUES (-1)") s4.signal() - try db.execute("END") + try db.execute(sql: "END") } } let blocks = [block1, block2] @@ -204,11 +202,11 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { func testWrappedReadWrite() throws { let dbPool = try makeDatabasePool() try dbPool.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") - try db.execute("INSERT INTO items (id) VALUES (NULL)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") } let id = try dbPool.read { db in - try Int.fetchOne(db, "SELECT id FROM items")! + try Int.fetchOne(db, sql: "SELECT id FROM items")! } XCTAssertEqual(id, 1) } @@ -217,14 +215,14 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { do { let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") - try db.execute("INSERT INTO items (id) VALUES (NULL)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") } } do { let dbPool = try makeDatabasePool(filename: "test.sqlite") let id = try dbPool.read { db in - try Int.fetchOne(db, "SELECT id FROM items")! + try Int.fetchOne(db, sql: "SELECT id FROM items")! } XCTAssertEqual(id, 1) } @@ -235,7 +233,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { try dbPool.write { db in XCTAssertTrue(db.isInsideTransaction) do { - try db.execute("BEGIN DEFERRED TRANSACTION") + try db.execute(sql: "BEGIN DEFERRED TRANSACTION") XCTFail("Expected error") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) @@ -260,7 +258,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { try dbPool.read { db in XCTAssertTrue(db.isInsideTransaction) do { - try db.execute("BEGIN DEFERRED TRANSACTION") + try db.execute(sql: "BEGIN DEFERRED TRANSACTION") XCTFail("Expected error") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) @@ -283,8 +281,8 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let block1 = { () in try! dbPool.writeWithoutTransaction { db in - try db.execute("PRAGMA locking_mode=EXCLUSIVE") - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "PRAGMA locking_mode=EXCLUSIVE") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") s1.signal() } } @@ -296,8 +294,6 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_BUSY) XCTAssertEqual(error.message!, "database is locked") - XCTAssertTrue(error.sql == nil) - XCTAssertEqual(error.description, "SQLite error 5: database is locked") } catch { XCTFail("Expected DatabaseError") } @@ -311,9 +307,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { func testConcurrentRead() throws { let dbPool = try makeDatabasePool() try dbPool.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") for _ in 0..<3 { - try db.execute("INSERT INTO items (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") } } @@ -333,7 +329,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let block1 = { () in try! dbPool.read { db in - let cursor = try Row.fetchCursor(db, "SELECT * FROM items") + let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items") XCTAssertTrue(try cursor.next() != nil) s1.signal() _ = s2.wait(timeout: .distantFuture) @@ -344,7 +340,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { } let block2 = { () in try! dbPool.read { db in - let cursor = try Row.fetchCursor(db, "SELECT * FROM items") + let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items") XCTAssertTrue(try cursor.next() != nil) _ = s1.wait(timeout: .distantFuture) XCTAssertTrue(try cursor.next() != nil) @@ -362,9 +358,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { func testReadMethodIsolationOfStatement() throws { let dbPool = try makeDatabasePool() try dbPool.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") for _ in 0..<2 { - try db.execute("INSERT INTO items (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") } } @@ -383,7 +379,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let block1 = { () in try! dbPool.read { db in - let cursor = try Row.fetchCursor(db, "SELECT * FROM items") + let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items") XCTAssertTrue(try cursor.next() != nil) s1.signal() _ = s2.wait(timeout: .distantFuture) @@ -396,7 +392,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { _ = s1.wait(timeout: .distantFuture) defer { s2.signal() } try dbPool.writeWithoutTransaction { db in - try db.execute("DELETE FROM items") + try db.execute(sql: "DELETE FROM items") } } catch { XCTFail("error: \(error)") @@ -411,9 +407,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { func testReadMethodIsolationOfStatementWithCheckpoint() throws { let dbPool = try makeDatabasePool() try dbPool.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") for _ in 0..<2 { - try db.execute("INSERT INTO items (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") } } @@ -433,7 +429,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let block1 = { () in try! dbPool.read { db in - let cursor = try Row.fetchCursor(db, "SELECT * FROM items") + let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items") XCTAssertTrue(try cursor.next() != nil) s1.signal() _ = s2.wait(timeout: .distantFuture) @@ -446,7 +442,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { _ = s1.wait(timeout: .distantFuture) defer { s2.signal() } try dbPool.writeWithoutTransaction { db in - try db.execute("DELETE FROM items") + try db.execute(sql: "DELETE FROM items") } try dbPool.checkpoint() } catch { @@ -462,7 +458,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { func testReadBlockIsolationStartingWithRead() throws { let dbPool = try makeDatabasePool() try dbPool.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") } // Block 1 Block 2 @@ -485,20 +481,20 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { try! dbPool.read { db in s1.signal() _ = s2.wait(timeout: .distantFuture) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 1) // Not a bug. The writer did not start a transaction. + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1) // Not a bug. The writer did not start a transaction. s3.signal() _ = s4.wait(timeout: .distantFuture) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1) } } let block2 = { () in do { _ = s1.wait(timeout: .distantFuture) try dbPool.writeWithoutTransaction { db in - try db.execute("INSERT INTO items (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") s2.signal() _ = s3.wait(timeout: .distantFuture) - try db.execute("INSERT INTO items (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") s4.signal() } } catch { @@ -514,7 +510,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { func testReadBlockIsolationStartingWithSelect() throws { let dbPool = try makeDatabasePool() try dbPool.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") } // Block 1 Block 2 @@ -531,10 +527,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let block1 = { () in try! dbPool.read { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 0) s1.signal() _ = s2.wait(timeout: .distantFuture) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 0) } } let block2 = { () in @@ -542,7 +538,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { _ = s1.wait(timeout: .distantFuture) defer { s2.signal() } try dbPool.writeWithoutTransaction { db in - try db.execute("INSERT INTO items (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") } try dbPool.checkpoint() } catch { @@ -558,7 +554,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { func testReadBlockIsolationStartingWithWrite() throws { let dbPool = try makeDatabasePool() try dbPool.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") } // Block 1 Block 2 @@ -583,10 +579,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let block1 = { () in do { try dbPool.writeWithoutTransaction { db in - try db.execute("INSERT INTO items (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") s1.signal() _ = s2.wait(timeout: .distantFuture) - try db.execute("INSERT INTO items (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") s3.signal() _ = s4.wait(timeout: .distantFuture) } @@ -598,13 +594,13 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let block2 = { () in try! dbPool.read { db in _ = s1.wait(timeout: .distantFuture) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1) s2.signal() _ = s3.wait(timeout: .distantFuture) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1) s4.signal() _ = s5.wait(timeout: .distantFuture) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1) } } let blocks = [block1, block2] @@ -616,7 +612,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { func testReadBlockIsolationStartingWithWriteTransaction() throws { let dbPool = try makeDatabasePool() try dbPool.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") } // Block 1 Block 2 @@ -643,10 +639,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let block1 = { () in do { try dbPool.writeInTransaction(.immediate) { db in - try db.execute("INSERT INTO items (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") s1.signal() _ = s2.wait(timeout: .distantFuture) - try db.execute("INSERT INTO items (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") s3.signal() _ = s4.wait(timeout: .distantFuture) return .commit @@ -659,13 +655,13 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let block2 = { () in try! dbPool.read { db in _ = s1.wait(timeout: .distantFuture) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 0) s2.signal() _ = s3.wait(timeout: .distantFuture) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 0) s4.signal() _ = s5.wait(timeout: .distantFuture) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 0) } } let blocks = [block1, block2] @@ -677,9 +673,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { func testUnsafeReadMethodIsolationOfStatement() throws { let dbPool = try makeDatabasePool() try dbPool.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") for _ in 0..<2 { - try db.execute("INSERT INTO items (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") } } @@ -699,13 +695,13 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let block1 = { () in try! dbPool.unsafeRead { db in - let cursor = try Row.fetchCursor(db, "SELECT * FROM items") + let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items") XCTAssertTrue(try cursor.next() != nil) s1.signal() _ = s2.wait(timeout: .distantFuture) XCTAssertTrue(try cursor.next() != nil) XCTAssertTrue(try cursor.next() == nil) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 0) } } let block2 = { () in @@ -713,7 +709,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { _ = s1.wait(timeout: .distantFuture) defer { s2.signal() } try dbPool.writeWithoutTransaction { db in - try db.execute("DELETE FROM items") + try db.execute(sql: "DELETE FROM items") } } catch { XCTFail("error: \(error)") @@ -728,9 +724,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { func testUnsafeReadMethodIsolationOfStatementWithCheckpoint() throws { let dbPool = try makeDatabasePool() try dbPool.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") for _ in 0..<2 { - try db.execute("INSERT INTO items (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") } } @@ -750,7 +746,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let block1 = { () in try! dbPool.unsafeRead { db in - let cursor = try Row.fetchCursor(db, "SELECT * FROM items") + let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items") XCTAssertTrue(try cursor.next() != nil) s1.signal() _ = s2.wait(timeout: .distantFuture) @@ -763,7 +759,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { _ = s1.wait(timeout: .distantFuture) defer { s2.signal() } try dbPool.writeWithoutTransaction { db in - try db.execute("DELETE FROM items") + try db.execute(sql: "DELETE FROM items") } try dbPool.checkpoint() } catch { @@ -779,7 +775,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { func testUnsafeReadMethodIsolationOfBlock() throws { let dbPool = try makeDatabasePool() try dbPool.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") } // Block 1 Block 2 @@ -796,10 +792,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let block1 = { () in try! dbPool.unsafeRead { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 0) s1.signal() _ = s2.wait(timeout: .distantFuture) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1) } } let block2 = { () in @@ -807,7 +803,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { _ = s1.wait(timeout: .distantFuture) defer { s2.signal() } try dbPool.writeWithoutTransaction { db in - try db.execute("INSERT INTO items (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") } try dbPool.checkpoint() } catch { @@ -819,31 +815,14 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { blocks[index]() } } - - func testReadFromCurrentStateOpensATransaction() throws { - let dbPool = try makeDatabasePool() - let s = DispatchSemaphore(value: 0) - try dbPool.writeWithoutTransaction { db in - try dbPool.readFromCurrentState { db in - XCTAssertTrue(db.isInsideTransaction) - do { - try db.execute("BEGIN DEFERRED TRANSACTION") - XCTFail("Expected error") - } catch { - } - s.signal() - } - } - _ = s.wait(timeout: .distantFuture) - } - + func testConcurrentReadOpensATransaction() throws { let dbPool = try makeDatabasePool() let future = dbPool.writeWithoutTransaction { db in dbPool.concurrentRead { db in XCTAssertTrue(db.isInsideTransaction) do { - try db.execute("BEGIN DEFERRED TRANSACTION") + try db.execute(sql: "BEGIN DEFERRED TRANSACTION") XCTFail("Expected error") } catch { } @@ -851,42 +830,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { } try future.wait() } - - func testReadFromCurrentStateOutsideOfTransaction() throws { - let dbPool = try makeDatabasePool() - try dbPool.write { db in - try db.create(table: "persons") { t in - t.column("id", .integer).primaryKey() - } - } - - // Writer Reader - // dbPool.writeWithoutTransaction { - // > - // dbPool.readFromCurrentState { - // < - // INSERT INTO items (id) VALUES (NULL) - // > - let s1 = DispatchSemaphore(value: 0) - // } SELECT COUNT(*) FROM persons -> 0 - // < - let s2 = DispatchSemaphore(value: 0) - // } - - var i: Int! = nil - try dbPool.writeWithoutTransaction { db in - try dbPool.readFromCurrentState { db in - _ = s1.wait(timeout: .distantFuture) - i = try! Int.fetchOne(db, "SELECT COUNT(*) FROM persons")! - s2.signal() - } - try db.execute("INSERT INTO persons DEFAULT VALUES") - s1.signal() - } - _ = s2.wait(timeout: .distantFuture) - XCTAssertEqual(i, 0) - } - + func testConcurrentReadOutsideOfTransaction() throws { let dbPool = try makeDatabasePool() try dbPool.write { db in @@ -907,42 +851,23 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { // < // } - let future: Future = try dbPool.writeWithoutTransaction { db in - let future: Future = dbPool.concurrentRead { db in + let future: DatabaseFuture = try dbPool.writeWithoutTransaction { db in + let future: DatabaseFuture = dbPool.concurrentRead { db in _ = s1.wait(timeout: .distantFuture) - return try! Int.fetchOne(db, "SELECT COUNT(*) FROM persons")! + return try! Int.fetchOne(db, sql: "SELECT COUNT(*) FROM persons")! } - try db.execute("INSERT INTO persons DEFAULT VALUES") + try db.execute(sql: "INSERT INTO persons DEFAULT VALUES") s1.signal() return future } XCTAssertEqual(try future.wait(), 0) } - - func testReadFromCurrentStateError() throws { - let dbPool = try makeDatabasePool() - try dbPool.writeWithoutTransaction { db in - try db.execute("PRAGMA locking_mode=EXCLUSIVE") - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") - do { - try dbPool.readFromCurrentState { db in - fatalError("Should not run") - } - XCTFail("Expected error") - } catch let error as DatabaseError { - XCTAssertEqual(error.resultCode, .SQLITE_BUSY) - XCTAssertEqual(error.message!, "database is locked") - XCTAssertTrue(error.sql == nil) - XCTAssertEqual(error.description, "SQLite error 5: database is locked") - } - } - } func testConcurrentReadError() throws { let dbPool = try makeDatabasePool() try dbPool.writeWithoutTransaction { db in - try db.execute("PRAGMA locking_mode=EXCLUSIVE") - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "PRAGMA locking_mode=EXCLUSIVE") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") let future = dbPool.concurrentRead { db in fatalError("Should not run") } @@ -951,8 +876,6 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_BUSY) XCTAssertEqual(error.message!, "database is locked") - XCTAssertTrue(error.sql == nil) - XCTAssertEqual(error.description, "SQLite error 5: database is locked") } } } @@ -967,7 +890,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { try dbPool.write { db in try db.create(table: "t") { $0.column("id", .integer).primaryKey() } - try db.execute("INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") } try dbQueue.writeWithoutTransaction { db in @@ -975,17 +898,17 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { } try dbQueue.writeWithoutTransaction { db in - try XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM t")!, 1) + try XCTAssertEqual(Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")!, 1) } try dbPool.write { db in - try db.execute("INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") } try dbQueue.writeWithoutTransaction { db in - try XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM t")!, 1) + try XCTAssertEqual(Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")!, 1) try db.rollback() - try XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM t")!, 2) + try XCTAssertEqual(Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")!, 2) } } @@ -1003,10 +926,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let dbPool = try makeDatabasePool() try dbPool.write { db in - try db.execute("CREATE VIRTUAL TABLE search USING fts3(title)") + try db.execute(sql: "CREATE VIRTUAL TABLE search USING fts3(title)") } try dbPool.read { db in - _ = try Row.fetchAll(db, "SELECT * FROM search") + _ = try Row.fetchAll(db, sql: "SELECT * FROM search") } } diff --git a/Tests/GRDBTests/DatabasePoolFunctionTests.swift b/Tests/GRDBTests/DatabasePoolFunctionTests.swift index 13290efe7..0e5937da7 100644 --- a/Tests/GRDBTests/DatabasePoolFunctionTests.swift +++ b/Tests/GRDBTests/DatabasePoolFunctionTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -19,11 +17,11 @@ class DatabasePoolFunctionTests: GRDBTestCase { dbPool.add(function: function1) try dbPool.write { db in - try db.execute("CREATE TABLE items (text TEXT)") - try db.execute("INSERT INTO items (text) VALUES (function1('a'))") + try db.execute(sql: "CREATE TABLE items (text TEXT)") + try db.execute(sql: "INSERT INTO items (text) VALUES (function1('a'))") } try dbPool.read { db in - XCTAssertEqual(try String.fetchOne(db, "SELECT function1(text) FROM items")!, "a") + XCTAssertEqual(try String.fetchOne(db, sql: "SELECT function1(text) FROM items")!, "a") } let function2 = DatabaseFunction("function2", argumentCount: 1, pure: true) { (dbValues: [DatabaseValue]) in @@ -32,7 +30,7 @@ class DatabasePoolFunctionTests: GRDBTestCase { dbPool.add(function: function2) try dbPool.read { db in - XCTAssertTrue(try String.fetchOne(db, "SELECT function2(text) FROM items") == "foo") + XCTAssertTrue(try String.fetchOne(db, sql: "SELECT function2(text) FROM items") == "foo") } } } diff --git a/Tests/GRDBTests/DatabasePoolReadOnlyTests.swift b/Tests/GRDBTests/DatabasePoolReadOnlyTests.swift index 1367dfab7..64befb137 100644 --- a/Tests/GRDBTests/DatabasePoolReadOnlyTests.swift +++ b/Tests/GRDBTests/DatabasePoolReadOnlyTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -16,9 +14,9 @@ class DatabasePoolReadOnlyTests: GRDBTestCase { do { let dbQueue = try makeDatabaseQueue(filename: databaseFileName) try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") for _ in 0..<3 { - try db.execute("INSERT INTO items (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") } } } @@ -29,7 +27,7 @@ class DatabasePoolReadOnlyTests: GRDBTestCase { // Make sure the database is not in WAL mode let mode = try dbPool.read { db in - try String.fetchOne(db, "PRAGMA journal_mode")! + try String.fetchOne(db, sql: "PRAGMA journal_mode")! } XCTAssertNotEqual(mode.lowercased(), "wal") @@ -47,7 +45,7 @@ class DatabasePoolReadOnlyTests: GRDBTestCase { let block1 = { () in try! dbPool.read { db in - let cursor = try Row.fetchCursor(db, "SELECT * FROM items") + let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items") XCTAssertTrue(try cursor.next() != nil) s1.signal() _ = s2.wait(timeout: .distantFuture) @@ -58,7 +56,7 @@ class DatabasePoolReadOnlyTests: GRDBTestCase { } let block2 = { () in try! dbPool.read { db in - let cursor = try Row.fetchCursor(db, "SELECT * FROM items") + let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items") XCTAssertTrue(try cursor.next() != nil) _ = s1.wait(timeout: .distantFuture) XCTAssertTrue(try cursor.next() != nil) diff --git a/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift b/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift index 491fb1199..374686e88 100644 --- a/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift +++ b/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else @testable import GRDB @@ -34,7 +32,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase { let dbPool = try makeDatabasePool() // Writer connection try dbPool.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") } // Reader connection try dbPool.read { _ in } @@ -67,9 +65,9 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase { let dbPool = try makeDatabasePool() try dbPool.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") for _ in 0..<2 { - try db.execute("INSERT INTO items (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") } } @@ -89,7 +87,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase { let block1 = { () in try! dbPool.read { db in - let cursor = try Row.fetchCursor(db, "SELECT * FROM items") + let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items") XCTAssertTrue(try cursor.next() != nil) s1.signal() _ = s2.wait(timeout: .distantFuture) @@ -101,7 +99,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase { let block2 = { () in _ = s1.wait(timeout: .distantFuture) try! dbPool.read { db in - let cursor = try Row.fetchCursor(db, "SELECT * FROM items") + let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items") XCTAssertTrue(try cursor.next() != nil) s2.signal() XCTAssertTrue(try cursor.next() != nil) @@ -155,7 +153,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase { let (block1, block2) = { () -> (() -> (), () -> ()) in var dbPool: DatabasePool? = try! self.makeDatabasePool() try! dbPool!.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") } let block1 = { () in @@ -168,7 +166,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase { try! dbPool.read { db in s1.signal() _ = s2.wait(timeout: .distantFuture) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items"), 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items"), 0) } } else { XCTFail("expect non nil dbPool") @@ -211,7 +209,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase { if let dbPool = dbPool { do { try dbPool.write { db in - statement = try db.makeUpdateStatement("CREATE TABLE items (id INTEGER PRIMARY KEY)") + statement = try db.makeUpdateStatement(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") s1.signal() } } catch { diff --git a/Tests/GRDBTests/DatabasePoolSchemaCacheTests.swift b/Tests/GRDBTests/DatabasePoolSchemaCacheTests.swift index 592227a39..b02a5b789 100644 --- a/Tests/GRDBTests/DatabasePoolSchemaCacheTests.swift +++ b/Tests/GRDBTests/DatabasePoolSchemaCacheTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else @testable import GRDB @@ -13,8 +11,8 @@ class DatabasePoolSchemaCacheTests : GRDBTestCase { let dbPool = try makeDatabasePool() try dbPool.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY, email TEXT UNIQUE, foo INT, bar DOUBLE)") - try db.execute("CREATE INDEX foobar ON items(foo, bar)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY, email TEXT UNIQUE, foo INT, bar DOUBLE)") + try db.execute(sql: "CREATE INDEX foobar ON items(foo, bar)") } try dbPool.write { db in @@ -57,7 +55,7 @@ class DatabasePoolSchemaCacheTests : GRDBTestCase { try dbPool.write { db in // Empty cache after schema change - try db.execute("DROP TABLE items") + try db.execute(sql: "DROP TABLE items") // Assert that the writer cache is empty XCTAssertTrue(db.schemaCache.primaryKey("items") == nil) @@ -94,8 +92,8 @@ class DatabasePoolSchemaCacheTests : GRDBTestCase { // correct thread. let dbPool = try makeDatabasePool() try dbPool.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") - try db.execute("INSERT INTO items (id) VALUES (1)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "INSERT INTO items (id) VALUES (1)") } // Block 1 Block 2 @@ -106,7 +104,7 @@ class DatabasePoolSchemaCacheTests : GRDBTestCase { let block1 = { () in try! dbPool.read { db in - let stmt = try! db.cachedSelectStatement("SELECT * FROM items") + let stmt = try! db.cachedSelectStatement(sql: "SELECT * FROM items") XCTAssertEqual(try Int.fetchOne(stmt)!, 1) s1.signal() } @@ -114,7 +112,7 @@ class DatabasePoolSchemaCacheTests : GRDBTestCase { let block2 = { () in try! dbPool.read { db in _ = s1.wait(timeout: .distantFuture) - let stmt = try! db.cachedSelectStatement("SELECT * FROM items") + let stmt = try! db.cachedSelectStatement(sql: "SELECT * FROM items") XCTAssertEqual(try Int.fetchOne(stmt)!, 1) } } @@ -148,14 +146,14 @@ class DatabasePoolSchemaCacheTests : GRDBTestCase { let block1 = { () in try! dbPool.writeWithoutTransaction { db in - try db.execute("CREATE TABLE foo(id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE foo(id INTEGER PRIMARY KEY)") // warm cache _ = try db.primaryKey("foo") // cache contains the primary key XCTAssertNotNil(db.schemaCache.primaryKey("foo")) s1.signal() _ = s2.wait(timeout: .distantFuture) - try db.execute("DROP TABLE foo") + try db.execute(sql: "DROP TABLE foo") // cache does not contain the primary key XCTAssertNil(db.schemaCache.primaryKey("foo")) s3.signal() @@ -168,7 +166,7 @@ class DatabasePoolSchemaCacheTests : GRDBTestCase { _ = s1.wait(timeout: .distantFuture) try! dbPool.read { db in // activate snapshot isolation so that foo table is visible during the whole read. Any read is enough. - try db.makeSelectStatement("SELECT * FROM sqlite_master").makeCursor().next() + try db.makeSelectStatement(sql: "SELECT * FROM sqlite_master").makeCursor().next() // warm cache _ = try db.primaryKey("foo") // cache contains the primary key @@ -192,8 +190,8 @@ class DatabasePoolSchemaCacheTests : GRDBTestCase { let dbPool = try makeDatabasePool() try dbPool.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY, email TEXT UNIQUE, foo INT, bar DOUBLE)") - try db.execute("CREATE INDEX foobar ON items(foo, bar)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY, email TEXT UNIQUE, foo INT, bar DOUBLE)") + try db.execute(sql: "CREATE INDEX foobar ON items(foo, bar)") } try dbPool.unsafeRead { db in diff --git a/Tests/GRDBTests/DatabaseQueueBackupTests.swift b/Tests/GRDBTests/DatabaseQueueBackupTests.swift index ca2949bc6..83ec12391 100644 --- a/Tests/GRDBTests/DatabaseQueueBackupTests.swift +++ b/Tests/GRDBTests/DatabaseQueueBackupTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -10,23 +8,30 @@ import XCTest class DatabaseQueueBackupTests: GRDBTestCase { func testBackup() throws { + #if GRDBCIPHER + // SQLCipher can't backup encrypted databases: skip this test + if dbConfiguration.passphrase != nil { + return + } + #endif + let source = try makeDatabaseQueue(filename: "source.sqlite") let destination = try makeDatabaseQueue(filename: "destination.sqlite") try source.inDatabase { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") - try db.execute("INSERT INTO items (id) VALUES (NULL)") - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 1) + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1) } try source.backup(to: destination) try destination.inDatabase { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1) } try source.inDatabase { db in - try db.execute("DROP TABLE items") + try db.execute(sql: "DROP TABLE items") } try source.backup(to: destination) diff --git a/Tests/GRDBTests/DatabaseQueueConcurrencyTests.swift b/Tests/GRDBTests/DatabaseQueueConcurrencyTests.swift index cb3829448..7e19da0fe 100644 --- a/Tests/GRDBTests/DatabaseQueueConcurrencyTests.swift +++ b/Tests/GRDBTests/DatabaseQueueConcurrencyTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -29,11 +27,11 @@ class ConcurrencyTests: GRDBTestCase { func testWrappedReadWrite() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") - try db.execute("INSERT INTO items (id) VALUES (NULL)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)") } let id = try dbQueue.inDatabase { db in - try Int.fetchOne(db, "SELECT id FROM items")! + try Int.fetchOne(db, sql: "SELECT id FROM items")! } XCTAssertEqual(id, 1) } @@ -45,7 +43,7 @@ class ConcurrencyTests: GRDBTestCase { // same empty database: make sure the database is not empty before // running this test try dbQueue1.inDatabase { db in - try db.execute("CREATE TABLE SQLCipherWorkAround (foo INTEGER)") + try db.execute(sql: "CREATE TABLE SQLCipherWorkAround (foo INTEGER)") } #endif let dbQueue2 = try makeDatabaseQueue(filename: "test.sqlite") @@ -63,7 +61,7 @@ class ConcurrencyTests: GRDBTestCase { // COMMIT try dbQueue1.inDatabase { db in - try db.execute("CREATE TABLE stuffs (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE stuffs (id INTEGER PRIMARY KEY)") } let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent]) @@ -75,7 +73,7 @@ class ConcurrencyTests: GRDBTestCase { try dbQueue1.inTransaction(.deferred) { db in s1.signal() _ = s2.wait(timeout: .distantFuture) - try db.execute("INSERT INTO stuffs (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO stuffs (id) VALUES (NULL)") s3.signal() _ = s4.wait(timeout: .distantFuture) return .commit @@ -94,7 +92,7 @@ class ConcurrencyTests: GRDBTestCase { try dbQueue2.inTransaction(.deferred) { db in s2.signal() _ = s3.wait(timeout: .distantFuture) - try db.execute("INSERT INTO stuffs (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO stuffs (id) VALUES (NULL)") return .commit } } @@ -236,7 +234,7 @@ class ConcurrencyTests: GRDBTestCase { // same empty database: make sure the database is not empty before // running this test try dbQueue1.inDatabase { db in - try db.execute("CREATE TABLE SQLCipherWorkAround (foo INTEGER)") + try db.execute(sql: "CREATE TABLE SQLCipherWorkAround (foo INTEGER)") } #endif let dbQueue2 = try makeDatabaseQueue(filename: "test.sqlite") @@ -299,7 +297,7 @@ class ConcurrencyTests: GRDBTestCase { // same empty database: make sure the database is not empty before // running this test try dbQueue1.inDatabase { db in - try db.execute("CREATE TABLE SQLCipherWorkAround (foo INTEGER)") + try db.execute(sql: "CREATE TABLE SQLCipherWorkAround (foo INTEGER)") } #endif let dbQueue2 = try makeDatabaseQueue(filename: "test.sqlite") @@ -317,7 +315,7 @@ class ConcurrencyTests: GRDBTestCase { // SELECT * FROM stuffs <--- 1 result try dbQueue1.inDatabase { db in - try db.execute("CREATE TABLE stuffs (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE stuffs (id INTEGER PRIMARY KEY)") } let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent]) @@ -327,7 +325,7 @@ class ConcurrencyTests: GRDBTestCase { queue.async(group: group) { do { try dbQueue1.inTransaction { db in - try db.execute("INSERT INTO stuffs (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO stuffs (id) VALUES (NULL)") s1.signal() _ = s2.wait(timeout: .distantFuture) return .commit @@ -345,10 +343,10 @@ class ConcurrencyTests: GRDBTestCase { queue.async(group: group) { try! dbQueue2.writeWithoutTransaction { db in _ = s1.wait(timeout: .distantFuture) - rows1 = try Row.fetchAll(db, "SELECT * FROM stuffs") + rows1 = try Row.fetchAll(db, sql: "SELECT * FROM stuffs") s2.signal() _ = s3.wait(timeout: .distantFuture) - rows2 = try Row.fetchAll(db, "SELECT * FROM stuffs") + rows2 = try Row.fetchAll(db, sql: "SELECT * FROM stuffs") } } @@ -365,7 +363,7 @@ class ConcurrencyTests: GRDBTestCase { // same empty database: make sure the database is not empty before // running this test try dbQueue1.inDatabase { db in - try db.execute("CREATE TABLE SQLCipherWorkAround (foo INTEGER)") + try db.execute(sql: "CREATE TABLE SQLCipherWorkAround (foo INTEGER)") } #endif let dbQueue2 = try makeDatabaseQueue(filename: "test.sqlite") @@ -398,7 +396,7 @@ class ConcurrencyTests: GRDBTestCase { } try dbQueue1.inDatabase { db in - try db.execute("CREATE TABLE stuffs (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE stuffs (id INTEGER PRIMARY KEY)") } let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent]) @@ -408,7 +406,7 @@ class ConcurrencyTests: GRDBTestCase { queue.async(group: group) { do { try dbQueue1.inTransaction { db in - try db.execute("INSERT INTO stuffs (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO stuffs (id) VALUES (NULL)") s1.signal() _ = s2.wait(timeout: .distantFuture) return .commit @@ -424,7 +422,7 @@ class ConcurrencyTests: GRDBTestCase { do { _ = s1.wait(timeout: .distantFuture) try dbQueue2.inTransaction(.deferred) { db in - _ = try Row.fetchAll(db, "SELECT * FROM stuffs") + _ = try Row.fetchAll(db, sql: "SELECT * FROM stuffs") s2.signal() _ = s3.wait(timeout: .distantFuture) return .commit diff --git a/Tests/GRDBTests/DatabaseQueueInMemoryTests.swift b/Tests/GRDBTests/DatabaseQueueInMemoryTests.swift index 573577359..a91942597 100644 --- a/Tests/GRDBTests/DatabaseQueueInMemoryTests.swift +++ b/Tests/GRDBTests/DatabaseQueueInMemoryTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,9 +10,9 @@ class DatabaseQueueInMemoryTests : GRDBTestCase func testInMemoryDatabase() throws { let dbQueue = DatabaseQueue() try dbQueue.inTransaction { db in - try db.execute("CREATE TABLE foo (bar TEXT)") - try db.execute("INSERT INTO foo (bar) VALUES ('baz')") - let baz = try String.fetchOne(db, "SELECT bar FROM foo")! + try db.execute(sql: "CREATE TABLE foo (bar TEXT)") + try db.execute(sql: "INSERT INTO foo (bar) VALUES ('baz')") + let baz = try String.fetchOne(db, sql: "SELECT bar FROM foo")! XCTAssertEqual(baz, "baz") return .rollback } diff --git a/Tests/GRDBTests/DatabaseQueueReadOnlyTests.swift b/Tests/GRDBTests/DatabaseQueueReadOnlyTests.swift index c618eb05b..4d72923f9 100644 --- a/Tests/GRDBTests/DatabaseQueueReadOnlyTests.swift +++ b/Tests/GRDBTests/DatabaseQueueReadOnlyTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -19,7 +17,7 @@ class DatabaseQueueReadOnlyTests : GRDBTestCase { dbConfiguration.readonly = true let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") let statement = try dbQueue.inDatabase { db in - try db.makeUpdateStatement("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.makeUpdateStatement(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") } do { try dbQueue.inDatabase { db in diff --git a/Tests/GRDBTests/DatabaseQueueReleaseMemoryTests.swift b/Tests/GRDBTests/DatabaseQueueReleaseMemoryTests.swift index 08707fd51..b7f0ec40d 100644 --- a/Tests/GRDBTests/DatabaseQueueReleaseMemoryTests.swift +++ b/Tests/GRDBTests/DatabaseQueueReleaseMemoryTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else @testable import GRDB @@ -70,7 +68,7 @@ class DatabaseQueueReleaseMemoryTests: GRDBTestCase { let (block1, block2) = { () -> (() -> (), () -> ()) in var dbQueue: DatabaseQueue? = try! self.makeDatabaseQueue() try! dbQueue!.write { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") } let block1 = { () in @@ -83,7 +81,7 @@ class DatabaseQueueReleaseMemoryTests: GRDBTestCase { try! dbQueue.write { db in s1.signal() _ = s2.wait(timeout: .distantFuture) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items"), 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items"), 0) } } else { XCTFail("expect non nil dbQueue") @@ -127,7 +125,7 @@ class DatabaseQueueReleaseMemoryTests: GRDBTestCase { if let dbQueue = dbQueue { do { try dbQueue.write { db in - statement = try db.makeUpdateStatement("CREATE TABLE items (id INTEGER PRIMARY KEY)") + statement = try db.makeUpdateStatement(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") s1.signal() } } catch { diff --git a/Tests/GRDBTests/DatabaseQueueSchemaCacheTests.swift b/Tests/GRDBTests/DatabaseQueueSchemaCacheTests.swift index 29c104522..4d86bd659 100644 --- a/Tests/GRDBTests/DatabaseQueueSchemaCacheTests.swift +++ b/Tests/GRDBTests/DatabaseQueueSchemaCacheTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else @testable import GRDB @@ -13,7 +11,7 @@ class DatabaseQueueSchemaCacheTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") } dbQueue.inDatabase { db in @@ -32,7 +30,7 @@ class DatabaseQueueSchemaCacheTests : GRDBTestCase { try dbQueue.inDatabase { db in // Empty cache after schema change - try db.execute("DROP TABLE items") + try db.execute(sql: "DROP TABLE items") // Assert that cache is empty XCTAssertTrue(db.schemaCache.primaryKey("items") == nil) diff --git a/Tests/GRDBTests/DatabaseQueueTests.swift b/Tests/GRDBTests/DatabaseQueueTests.swift index e2014d9dd..9f5c7670f 100644 --- a/Tests/GRDBTests/DatabaseQueueTests.swift +++ b/Tests/GRDBTests/DatabaseQueueTests.swift @@ -1,8 +1,6 @@ import XCTest import Dispatch -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -27,10 +25,6 @@ class DatabaseQueueTests: GRDBTestCase { XCTAssert([ "file is encrypted or is not a database", "file is not a database"].contains(error.message!)) - XCTAssertTrue(error.sql == nil) - XCTAssert([ - "SQLite error 26: file is encrypted or is not a database", - "SQLite error 26: file is not a database"].contains(error.description)) } } #endif @@ -46,12 +40,12 @@ class DatabaseQueueTests: GRDBTestCase { } dbQueue.add(function: fn) try dbQueue.inDatabase { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT succ(1)"), 2) // 2 + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT succ(1)"), 2) // 2 } dbQueue.remove(function: fn) do { try dbQueue.inDatabase { db in - try db.execute("SELECT succ(1)") + try db.execute(sql: "SELECT succ(1)") XCTFail("Expected Error") } XCTFail("Expected Error") @@ -73,12 +67,12 @@ class DatabaseQueueTests: GRDBTestCase { } dbQueue.add(collation: collation) try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE files (name TEXT COLLATE TEST_COLLATION_FOO)") + try db.execute(sql: "CREATE TABLE files (name TEXT COLLATE TEST_COLLATION_FOO)") } dbQueue.remove(collation: collation) do { try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE files_fail (name TEXT COLLATE TEST_COLLATION_FOO)") + try db.execute(sql: "CREATE TABLE files_fail (name TEXT COLLATE TEST_COLLATION_FOO)") XCTFail("Expected Error") } XCTFail("Expected Error") diff --git a/Tests/GRDBTests/DatabaseReaderTests.swift b/Tests/GRDBTests/DatabaseReaderTests.swift index 9cd696a58..7aac58fa6 100644 --- a/Tests/GRDBTests/DatabaseReaderTests.swift +++ b/Tests/GRDBTests/DatabaseReaderTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -25,7 +23,7 @@ class DatabaseReaderTests : GRDBTestCase { } } do { - try dbQueue.read { try $0.execute("INSERT INTO table1 DEFAULT VALUES") } + try dbQueue.read { try $0.execute(sql: "INSERT INTO table1 DEFAULT VALUES") } XCTFail() } catch let error as DatabaseError where error.resultCode == .SQLITE_READONLY { } @@ -39,7 +37,7 @@ class DatabaseReaderTests : GRDBTestCase { } } do { - try dbPool.read { try $0.execute("INSERT INTO table1 DEFAULT VALUES") } + try dbPool.read { try $0.execute(sql: "INSERT INTO table1 DEFAULT VALUES") } XCTFail() } catch let error as DatabaseError where error.resultCode == .SQLITE_READONLY { } diff --git a/Tests/GRDBTests/DatabaseRegionObservationTests.swift b/Tests/GRDBTests/DatabaseRegionObservationTests.swift index dff415cc5..ed20dc524 100644 --- a/Tests/GRDBTests/DatabaseRegionObservationTests.swift +++ b/Tests/GRDBTests/DatabaseRegionObservationTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else #if SWIFT_PACKAGE @@ -16,16 +14,16 @@ class DatabaseRegionObservationTests: GRDBTestCase { func testDatabaseRegionObservationVariadic() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.write { - try $0.execute("CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") - try $0.execute("CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") + try $0.execute(sql: "CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") + try $0.execute(sql: "CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } let notificationExpectation = expectation(description: "notification") notificationExpectation.assertForOverFulfill = true notificationExpectation.expectedFulfillmentCount = 3 - let request1 = SQLRequest("SELECT * FROM t1 ORDER BY id") - let request2 = SQLRequest("SELECT * FROM t2 ORDER BY id") + let request1 = SQLRequest(sql: "SELECT * FROM t1 ORDER BY id") + let request2 = SQLRequest(sql: "SELECT * FROM t2 ORDER BY id") var observation = DatabaseRegionObservation(tracking: request1, request2) observation.extent = .databaseLifetime @@ -37,14 +35,14 @@ class DatabaseRegionObservationTests: GRDBTestCase { } try dbQueue.write { db in - try db.execute("INSERT INTO t1 (id, name) VALUES (1, 'foo')") + try db.execute(sql: "INSERT INTO t1 (id, name) VALUES (1, 'foo')") } try dbQueue.write { db in - try db.execute("INSERT INTO t2 (id, name) VALUES (1, 'foo')") + try db.execute(sql: "INSERT INTO t2 (id, name) VALUES (1, 'foo')") } try dbQueue.write { db in - try db.execute("INSERT INTO t1 (id, name) VALUES (2, 'foo')") - try db.execute("INSERT INTO t2 (id, name) VALUES (2, 'foo')") + try db.execute(sql: "INSERT INTO t1 (id, name) VALUES (2, 'foo')") + try db.execute(sql: "INSERT INTO t2 (id, name) VALUES (2, 'foo')") } waitForExpectations(timeout: 1, handler: nil) @@ -54,16 +52,16 @@ class DatabaseRegionObservationTests: GRDBTestCase { func testDatabaseRegionObservationArray() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.write { - try $0.execute("CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") - try $0.execute("CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") + try $0.execute(sql: "CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") + try $0.execute(sql: "CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } let notificationExpectation = expectation(description: "notification") notificationExpectation.assertForOverFulfill = true notificationExpectation.expectedFulfillmentCount = 3 - let request1 = SQLRequest("SELECT * FROM t1 ORDER BY id") - let request2 = SQLRequest("SELECT * FROM t2 ORDER BY id") + let request1 = SQLRequest(sql: "SELECT * FROM t1 ORDER BY id") + let request2 = SQLRequest(sql: "SELECT * FROM t2 ORDER BY id") var observation = DatabaseRegionObservation(tracking: [request1, request2]) observation.extent = .databaseLifetime @@ -75,14 +73,14 @@ class DatabaseRegionObservationTests: GRDBTestCase { } try dbQueue.write { db in - try db.execute("INSERT INTO t1 (id, name) VALUES (1, 'foo')") + try db.execute(sql: "INSERT INTO t1 (id, name) VALUES (1, 'foo')") } try dbQueue.write { db in - try db.execute("INSERT INTO t2 (id, name) VALUES (1, 'foo')") + try db.execute(sql: "INSERT INTO t2 (id, name) VALUES (1, 'foo')") } try dbQueue.write { db in - try db.execute("INSERT INTO t1 (id, name) VALUES (2, 'foo')") - try db.execute("INSERT INTO t2 (id, name) VALUES (2, 'foo')") + try db.execute(sql: "INSERT INTO t1 (id, name) VALUES (2, 'foo')") + try db.execute(sql: "INSERT INTO t2 (id, name) VALUES (2, 'foo')") } waitForExpectations(timeout: 1, handler: nil) @@ -91,13 +89,13 @@ class DatabaseRegionObservationTests: GRDBTestCase { func testDatabaseRegionDefaultExtent() throws { let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } + try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } let notificationExpectation = expectation(description: "notification") notificationExpectation.assertForOverFulfill = true notificationExpectation.expectedFulfillmentCount = 2 - let observation = DatabaseRegionObservation(tracking: SQLRequest("SELECT * FROM t ORDER BY id")) + let observation = DatabaseRegionObservation(tracking: SQLRequest(sql: "SELECT * FROM t ORDER BY id")) var count = 0 do { @@ -108,16 +106,16 @@ class DatabaseRegionObservationTests: GRDBTestCase { try withExtendedLifetime(observer) { try dbQueue.write { db in - try db.execute("INSERT INTO t (id, name) VALUES (1, 'foo')") + try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')") } try dbQueue.write { db in - try db.execute("INSERT INTO t (id, name) VALUES (2, 'bar')") + try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, 'bar')") } } } // not notified try dbQueue.write { db in - try db.execute("INSERT INTO t (id, name) VALUES (3, 'baz')") + try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'baz')") } waitForExpectations(timeout: 1, handler: nil) @@ -126,13 +124,13 @@ class DatabaseRegionObservationTests: GRDBTestCase { func testDatabaseRegionExtentNextTransaction() throws { let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } + try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } let notificationExpectation = expectation(description: "notification") notificationExpectation.assertForOverFulfill = true notificationExpectation.expectedFulfillmentCount = 1 - var observation = DatabaseRegionObservation(tracking: SQLRequest("SELECT * FROM t ORDER BY id")) + var observation = DatabaseRegionObservation(tracking: SQLRequest(sql: "SELECT * FROM t ORDER BY id")) observation.extent = .nextTransaction var count = 0 @@ -142,14 +140,51 @@ class DatabaseRegionObservationTests: GRDBTestCase { } try dbQueue.write { db in - try db.execute("INSERT INTO t (id, name) VALUES (1, 'foo')") + try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')") } // not notified try dbQueue.write { db in - try db.execute("INSERT INTO t (id, name) VALUES (2, 'bar')") + try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, 'bar')") } waitForExpectations(timeout: 1, handler: nil) XCTAssertEqual(count, 1) } + + // Regression test for https://github.com/groue/GRDB.swift/issues/514 + // TODO: uncomment and make this test pass. +// func testIssue514() throws { +// let dbQueue = try makeDatabaseQueue() +// try dbQueue.write { db in +// try db.create(table: "gallery") { t in +// t.column("id", .integer).primaryKey() +// t.column("status", .integer) +// } +// } +// +// struct Gallery: TableRecord { } +// let observation = DatabaseRegionObservation(tracking: Gallery.select(Column("id"))) +// +// var notificationCount = 0 +// let observer = try observation.start(in: dbQueue) { _ in +// notificationCount += 1 +// } +// +// try withExtendedLifetime(observer) { +// try dbQueue.write { db in +// try db.execute(sql: "INSERT INTO gallery (id, status) VALUES (NULL, 0)") +// } +// XCTAssertEqual(notificationCount, 1) +// +// try dbQueue.write { db in +// try db.execute(sql: "UPDATE gallery SET status = 1") +// } +// XCTAssertEqual(notificationCount, 1) // status is not observed +// +// try dbQueue.write { db in +// try db.execute(sql: "DELETE FROM gallery") +// } +// XCTAssertEqual(notificationCount, 2) +// } +// } } diff --git a/Tests/GRDBTests/DatabaseRegionTests.swift b/Tests/GRDBTests/DatabaseRegionTests.swift index 80bd6630e..4c0052130 100644 --- a/Tests/GRDBTests/DatabaseRegionTests.swift +++ b/Tests/GRDBTests/DatabaseRegionTests.swift @@ -1,10 +1,10 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else - #if SWIFT_PACKAGE + #if GRDBCIPHER + import SQLCipher + #elseif SWIFT_PACKAGE import CSQLite #else import SQLite3 @@ -258,18 +258,18 @@ class DatabaseRegionTests : GRDBTestCase { func testSelectStatement() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE foo (id INTEGER, name TEXT)") - try db.execute("CREATE TABLE bar (id INTEGER, fooId INTEGER)") + try db.execute(sql: "CREATE TABLE foo (id INTEGER, name TEXT)") + try db.execute(sql: "CREATE TABLE bar (id INTEGER, fooId INTEGER)") do { - let statement = try db.makeSelectStatement("SELECT foo.name FROM FOO JOIN BAR ON fooId = foo.id") + let statement = try db.makeSelectStatement(sql: "SELECT foo.name FROM FOO JOIN BAR ON fooId = foo.id") let expectedRegion = DatabaseRegion(table: "foo", columns: ["name", "id"]) .union(DatabaseRegion(table: "bar", columns: ["fooId"])) XCTAssertEqual(statement.databaseRegion, expectedRegion) XCTAssertEqual(statement.databaseRegion.description, "bar(fooId),foo(id,name)") } do { - let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM foo") + let statement = try db.makeSelectStatement(sql: "SELECT COUNT(*) FROM foo") if sqlite3_libversion_number() < 3019000 { let expectedRegion = DatabaseRegion.fullDatabase XCTAssertEqual(statement.databaseRegion, expectedRegion) @@ -286,7 +286,7 @@ class DatabaseRegionTests : GRDBTestCase { func testRegionRowIds() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE foo (id INTEGER PRIMARY KEY, a TEXT)") + try db.execute(sql: "CREATE TABLE foo (id INTEGER PRIMARY KEY, a TEXT)") struct Record: TableRecord { static let databaseTableName = "foo" } @@ -413,9 +413,9 @@ class DatabaseRegionTests : GRDBTestCase { func testDatabaseRegionOfJoinedRequests() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE a (id INTEGER PRIMARY KEY, name TEXT)") - try db.execute("CREATE TABLE b (id INTEGER PRIMARY KEY, name TEXT, aid INTEGER REFERENCES a(id))") - try db.execute("CREATE TABLE c (id INTEGER PRIMARY KEY, name TEXT, aid INTEGER REFERENCES a(id))") + try db.execute(sql: "CREATE TABLE a (id INTEGER PRIMARY KEY, name TEXT)") + try db.execute(sql: "CREATE TABLE b (id INTEGER PRIMARY KEY, name TEXT, aid INTEGER REFERENCES a(id))") + try db.execute(sql: "CREATE TABLE c (id INTEGER PRIMARY KEY, name TEXT, aid INTEGER REFERENCES a(id))") struct A: TableRecord { static let databaseTableName = "a" static let b = hasOne(B.self) @@ -448,7 +448,7 @@ class DatabaseRegionTests : GRDBTestCase { func testDatabaseRegionOfDerivedRequests() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE foo (id INTEGER PRIMARY KEY, a TEXT)") + try db.execute(sql: "CREATE TABLE foo (id INTEGER PRIMARY KEY, a TEXT)") struct Record: TableRecord { static let databaseTableName = "foo" } @@ -475,8 +475,8 @@ class DatabaseRegionTests : GRDBTestCase { func testUpdateStatement() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE foo (id INTEGER, bar TEXT, baz TEXT, qux TEXT)") - let statement = try db.makeUpdateStatement("UPDATE foo SET bar = 'bar', baz = 'baz' WHERE id = 1") + try db.execute(sql: "CREATE TABLE foo (id INTEGER, bar TEXT, baz TEXT, qux TEXT)") + let statement = try db.makeUpdateStatement(sql: "UPDATE foo SET bar = 'bar', baz = 'baz' WHERE id = 1") XCTAssertFalse(statement.invalidatesDatabaseSchemaCache) XCTAssertEqual(statement.databaseEventKinds.count, 1) guard case .update(let tableName, let columnNames) = statement.databaseEventKinds[0] else { @@ -502,21 +502,21 @@ class DatabaseRegionTests : GRDBTestCase { } let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE foo (name TEXT)") + try db.execute(sql: "CREATE TABLE foo (name TEXT)") do { - let statement = try db.makeSelectStatement("SELECT rowid FROM FOO") + let statement = try db.makeSelectStatement(sql: "SELECT rowid FROM FOO") let expectedRegion = DatabaseRegion(table: "foo", columns: ["ROWID"]) XCTAssertEqual(statement.databaseRegion, expectedRegion) XCTAssertEqual(statement.databaseRegion.description, "foo(ROWID)") } do { - let statement = try db.makeSelectStatement("SELECT _ROWID_ FROM FOO") + let statement = try db.makeSelectStatement(sql: "SELECT _ROWID_ FROM FOO") let expectedRegion = DatabaseRegion(table: "foo", columns: ["ROWID"]) XCTAssertEqual(statement.databaseRegion, expectedRegion) XCTAssertEqual(statement.databaseRegion.description, "foo(ROWID)") } do { - let statement = try db.makeSelectStatement("SELECT oID FROM FOO") + let statement = try db.makeSelectStatement(sql: "SELECT oID FROM FOO") let expectedRegion = DatabaseRegion(table: "foo", columns: ["ROWID"]) XCTAssertEqual(statement.databaseRegion, expectedRegion) XCTAssertEqual(statement.databaseRegion.description, "foo(ROWID)") @@ -537,9 +537,9 @@ class DatabaseRegionTests : GRDBTestCase { } let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE foo (name TEXT)") + try db.execute(sql: "CREATE TABLE foo (name TEXT)") do { - let statement = try db.makeUpdateStatement("UPDATE foo SET rowid = 1") + let statement = try db.makeUpdateStatement(sql: "UPDATE foo SET rowid = 1") XCTAssertEqual(statement.databaseEventKinds.count, 1) guard case .update(let tableName, let columnNames) = statement.databaseEventKinds[0] else { XCTFail() @@ -549,7 +549,7 @@ class DatabaseRegionTests : GRDBTestCase { XCTAssertEqual(columnNames, ["ROWID"]) } do { - let statement = try db.makeUpdateStatement("UPDATE foo SET _ROWID_ = 1") + let statement = try db.makeUpdateStatement(sql: "UPDATE foo SET _ROWID_ = 1") XCTAssertEqual(statement.databaseEventKinds.count, 1) guard case .update(let tableName, let columnNames) = statement.databaseEventKinds[0] else { XCTFail() @@ -559,7 +559,7 @@ class DatabaseRegionTests : GRDBTestCase { XCTAssertEqual(columnNames, ["ROWID"]) } do { - let statement = try db.makeUpdateStatement("UPDATE foo SET oID = 1") + let statement = try db.makeUpdateStatement(sql: "UPDATE foo SET oID = 1") XCTAssertEqual(statement.databaseEventKinds.count, 1) guard case .update(let tableName, let columnNames) = statement.databaseEventKinds[0] else { XCTFail() @@ -574,8 +574,8 @@ class DatabaseRegionTests : GRDBTestCase { func testInsertStatement() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE foo (id INTEGER, bar TEXT, baz TEXT, qux TEXT)") - let statement = try db.makeUpdateStatement("INSERT INTO foo (id, bar) VALUES (1, 'bar')") + try db.execute(sql: "CREATE TABLE foo (id INTEGER, bar TEXT, baz TEXT, qux TEXT)") + let statement = try db.makeUpdateStatement(sql: "INSERT INTO foo (id, bar) VALUES (1, 'bar')") XCTAssertFalse(statement.invalidatesDatabaseSchemaCache) XCTAssertEqual(statement.databaseEventKinds.count, 1) guard case .insert(let tableName) = statement.databaseEventKinds[0] else { @@ -589,8 +589,8 @@ class DatabaseRegionTests : GRDBTestCase { func testDeleteStatement() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE foo (id INTEGER, bar TEXT, baz TEXT, qux TEXT)") - let statement = try db.makeUpdateStatement("DELETE FROM foo") + try db.execute(sql: "CREATE TABLE foo (id INTEGER, bar TEXT, baz TEXT, qux TEXT)") + let statement = try db.makeUpdateStatement(sql: "DELETE FROM foo") XCTAssertFalse(statement.invalidatesDatabaseSchemaCache) XCTAssertEqual(statement.databaseEventKinds.count, 1) guard case .delete(let tableName) = statement.databaseEventKinds[0] else { @@ -605,16 +605,16 @@ class DatabaseRegionTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in do { - let statement = try db.makeUpdateStatement("CREATE TABLE foo (id INTEGER)") + let statement = try db.makeUpdateStatement(sql: "CREATE TABLE foo (id INTEGER)") XCTAssertTrue(statement.invalidatesDatabaseSchemaCache) try statement.execute() } do { - let statement = try db.makeUpdateStatement("ALTER TABLE foo ADD COLUMN name TEXT") + let statement = try db.makeUpdateStatement(sql: "ALTER TABLE foo ADD COLUMN name TEXT") XCTAssertTrue(statement.invalidatesDatabaseSchemaCache) } do { - let statement = try db.makeUpdateStatement("DROP TABLE foo") + let statement = try db.makeUpdateStatement(sql: "DROP TABLE foo") XCTAssertTrue(statement.invalidatesDatabaseSchemaCache) } } @@ -785,4 +785,50 @@ class DatabaseRegionTests : GRDBTestCase { } } } + + // Regression test for https://github.com/groue/GRDB.swift/issues/514 + func testIssue514() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.execute(sql: """ + CREATE TABLE a (id INTEGER PRIMARY KEY, name TEXT); + CREATE TABLE b (id TEXT, name TEXT); + """) + + // INTEGER PRIMARY KEY + do { + // TODO: contact SQLite and ask if this test is expected to fail +// let statement = try db.makeSelectStatement(sql: "SELECT id FROM a") +// let expectedRegion = DatabaseRegion(table: "a", columns: ["id"]) +// XCTAssertEqual(statement.databaseRegion, expectedRegion) + } + do { + let statement = try db.makeSelectStatement(sql: "SELECT name FROM a") + let expectedRegion = DatabaseRegion(table: "a", columns: ["name"]) + XCTAssertEqual(statement.databaseRegion, expectedRegion) + } + do { + let statement = try db.makeSelectStatement(sql: "SELECT id, name FROM a") + let expectedRegion = DatabaseRegion(table: "a", columns: ["id", "name"]) + XCTAssertEqual(statement.databaseRegion, expectedRegion) + } + + // TEXT primary key + do { + let statement = try db.makeSelectStatement(sql: "SELECT id FROM b") + let expectedRegion = DatabaseRegion(table: "b", columns: ["id"]) + XCTAssertEqual(statement.databaseRegion, expectedRegion) + } + do { + let statement = try db.makeSelectStatement(sql: "SELECT name FROM b") + let expectedRegion = DatabaseRegion(table: "b", columns: ["name"]) + XCTAssertEqual(statement.databaseRegion, expectedRegion) + } + do { + let statement = try db.makeSelectStatement(sql: "SELECT id, name FROM b") + let expectedRegion = DatabaseRegion(table: "b", columns: ["id", "name"]) + XCTAssertEqual(statement.databaseRegion, expectedRegion) + } + } + } } diff --git a/Tests/GRDBTests/DatabaseSavepointTests.swift b/Tests/GRDBTests/DatabaseSavepointTests.swift index 4f47e35a9..ec07890e8 100644 --- a/Tests/GRDBTests/DatabaseSavepointTests.swift +++ b/Tests/GRDBTests/DatabaseSavepointTests.swift @@ -1,19 +1,17 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB #endif func insertItem(_ db: Database, name: String) throws { - try db.execute("INSERT INTO items (name) VALUES (?)", arguments: [name]) + try db.execute(sql: "INSERT INTO items (name) VALUES (?)", arguments: [name]) } func fetchAllItemNames(_ dbReader: DatabaseReader) throws -> [String] { return try dbReader.read { db in - try String.fetchAll(db, "SELECT * FROM items ORDER BY name") + try String.fetchAll(db, sql: "SELECT * FROM items ORDER BY name") } } @@ -53,7 +51,7 @@ class DatabaseSavepointTests: GRDBTestCase { override func setup(_ dbWriter: DatabaseWriter) throws { try dbWriter.write { db in - try db.execute("CREATE TABLE items (name TEXT)") + try db.execute(sql: "CREATE TABLE items (name TEXT)") } } @@ -67,24 +65,24 @@ class DatabaseSavepointTests: GRDBTestCase { } XCTAssertFalse(db.isInsideTransaction) - try db.execute("BEGIN DEFERRED TRANSACTION") + try db.execute(sql: "BEGIN DEFERRED TRANSACTION") XCTAssertTrue(db.isInsideTransaction) - try db.execute("COMMIT") // does not trigger sqlite3_commit_hook, because transaction was not open yet. + try db.execute(sql: "COMMIT") // does not trigger sqlite3_commit_hook, because transaction was not open yet. XCTAssertFalse(db.isInsideTransaction) - try db.execute("BEGIN DEFERRED TRANSACTION") + try db.execute(sql: "BEGIN DEFERRED TRANSACTION") XCTAssertTrue(db.isInsideTransaction) - try db.execute("ROLLBACK") // does trigger sqlite3_rollback_hook + try db.execute(sql: "ROLLBACK") // does trigger sqlite3_rollback_hook XCTAssertFalse(db.isInsideTransaction) - try db.execute("BEGIN IMMEDIATE TRANSACTION") + try db.execute(sql: "BEGIN IMMEDIATE TRANSACTION") XCTAssertTrue(db.isInsideTransaction) - try db.execute("COMMIT") // does trigger sqlite3_commit_hook + try db.execute(sql: "COMMIT") // does trigger sqlite3_commit_hook XCTAssertFalse(db.isInsideTransaction) - try db.execute("BEGIN IMMEDIATE TRANSACTION") + try db.execute(sql: "BEGIN IMMEDIATE TRANSACTION") XCTAssertTrue(db.isInsideTransaction) - try db.execute("ROLLBACK") + try db.execute(sql: "ROLLBACK") XCTAssertFalse(db.isInsideTransaction) } } @@ -95,13 +93,13 @@ class DatabaseSavepointTests: GRDBTestCase { try db.create(table: "test") { t in t.column("value", .integer).unique() } - try db.execute("BEGIN TRANSACTION") + try db.execute(sql: "BEGIN TRANSACTION") XCTAssertTrue(db.isInsideTransaction) - try db.execute("INSERT INTO test (value) VALUES (?)", arguments: [1]) + try db.execute(sql: "INSERT INTO test (value) VALUES (?)", arguments: [1]) XCTAssertTrue(db.isInsideTransaction) - XCTAssertThrowsError(try db.execute("INSERT OR ROLLBACK INTO test (value) VALUES (?)", arguments: [1])) + XCTAssertThrowsError(try db.execute(sql: "INSERT OR ROLLBACK INTO test (value) VALUES (?)", arguments: [1])) XCTAssertFalse(db.isInsideTransaction) - XCTAssertThrowsError(try db.execute("COMMIT")) + XCTAssertThrowsError(try db.execute(sql: "COMMIT")) } } @@ -205,7 +203,7 @@ class DatabaseSavepointTests: GRDBTestCase { #if SQLITE_ENABLE_PREUPDATE_HOOK XCTAssertEqual(observer.allRecordedPreUpdateEvents.count, 5) #endif - try dbQueue.inDatabase { db in try db.execute("DELETE FROM items") } + try dbQueue.inDatabase { db in try db.execute(sql: "DELETE FROM items") } observer.reset() sqlQueries.removeAll() @@ -242,7 +240,7 @@ class DatabaseSavepointTests: GRDBTestCase { #if SQLITE_ENABLE_PREUPDATE_HOOK XCTAssertEqual(observer.allRecordedPreUpdateEvents.count, 2) #endif - try dbQueue.inDatabase { db in try db.execute("DELETE FROM items") } + try dbQueue.inDatabase { db in try db.execute(sql: "DELETE FROM items") } observer.reset() sqlQueries.removeAll() @@ -280,7 +278,7 @@ class DatabaseSavepointTests: GRDBTestCase { #if SQLITE_ENABLE_PREUPDATE_HOOK XCTAssertEqual(observer.allRecordedPreUpdateEvents.count, 4) #endif - try dbQueue.inDatabase { db in try db.execute("DELETE FROM items") } + try dbQueue.inDatabase { db in try db.execute(sql: "DELETE FROM items") } observer.reset() sqlQueries.removeAll() @@ -318,7 +316,7 @@ class DatabaseSavepointTests: GRDBTestCase { #if SQLITE_ENABLE_PREUPDATE_HOOK XCTAssertEqual(observer.allRecordedPreUpdateEvents.count, 2) #endif - try dbQueue.inDatabase { db in try db.execute("DELETE FROM items") } + try dbQueue.inDatabase { db in try db.execute(sql: "DELETE FROM items") } observer.reset() } @@ -421,7 +419,7 @@ class DatabaseSavepointTests: GRDBTestCase { #if SQLITE_ENABLE_PREUPDATE_HOOK XCTAssertEqual(observer.allRecordedPreUpdateEvents.count, 5) #endif - try dbQueue.inDatabase { db in try db.execute("DELETE FROM items") } + try dbQueue.inDatabase { db in try db.execute(sql: "DELETE FROM items") } observer.reset() sqlQueries.removeAll() @@ -458,7 +456,7 @@ class DatabaseSavepointTests: GRDBTestCase { #if SQLITE_ENABLE_PREUPDATE_HOOK XCTAssertEqual(observer.allRecordedPreUpdateEvents.count, 5) #endif - try dbQueue.inDatabase { db in try db.execute("DELETE FROM items") } + try dbQueue.inDatabase { db in try db.execute(sql: "DELETE FROM items") } observer.reset() sqlQueries.removeAll() @@ -496,7 +494,7 @@ class DatabaseSavepointTests: GRDBTestCase { #if SQLITE_ENABLE_PREUPDATE_HOOK XCTAssertEqual(observer.allRecordedPreUpdateEvents.count, 4) #endif - try dbQueue.inDatabase { db in try db.execute("DELETE FROM items") } + try dbQueue.inDatabase { db in try db.execute(sql: "DELETE FROM items") } observer.reset() sqlQueries.removeAll() @@ -534,7 +532,7 @@ class DatabaseSavepointTests: GRDBTestCase { #if SQLITE_ENABLE_PREUPDATE_HOOK XCTAssertEqual(observer.allRecordedPreUpdateEvents.count, 4) #endif - try dbQueue.inDatabase { db in try db.execute("DELETE FROM items") } + try dbQueue.inDatabase { db in try db.execute(sql: "DELETE FROM items") } observer.reset() } diff --git a/Tests/GRDBTests/DatabaseSnapshotTests.swift b/Tests/GRDBTests/DatabaseSnapshotTests.swift index aea92eb01..d5b3bbd57 100644 --- a/Tests/GRDBTests/DatabaseSnapshotTests.swift +++ b/Tests/GRDBTests/DatabaseSnapshotTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -27,15 +25,15 @@ class DatabaseSnapshotTests: GRDBTestCase { let dbPool = try makeDatabasePool() try dbPool.writeWithoutTransaction { db in try db.create(table: "t") { $0.column("id", .integer).primaryKey() } - try db.execute("INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") let snapshot = try dbPool.makeSnapshot() try snapshot.read { db in - try XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM t")!, 1) + try XCTAssertEqual(Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")!, 1) } - try db.execute("INSERT INTO t DEFAULT VALUES") - try XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM t")!, 2) + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + try XCTAssertEqual(Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")!, 2) try snapshot.read { db in - try XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM t")!, 1) + try XCTAssertEqual(Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")!, 1) } } } @@ -44,19 +42,19 @@ class DatabaseSnapshotTests: GRDBTestCase { let dbPool = try makeDatabasePool() try dbPool.write { db in try db.create(table: "t") { $0.column("id", .integer).primaryKey() } - try db.execute("INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") } let snapshot = try dbPool.makeSnapshot() try snapshot.read { db in - try XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM t")!, 1) + try XCTAssertEqual(Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")!, 1) } try dbPool.write { db in - try db.execute("INSERT INTO t DEFAULT VALUES") - try XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM t")!, 2) + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + try XCTAssertEqual(Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")!, 2) } try snapshot.read { db in - try XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM t")!, 1) + try XCTAssertEqual(Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")!, 1) } } @@ -67,7 +65,7 @@ class DatabaseSnapshotTests: GRDBTestCase { let snapshot = try dbPool.makeSnapshot() try snapshot.read { db in - try XCTAssertEqual(String.fetchOne(db, "SELECT foo()")!, "foo") + try XCTAssertEqual(String.fetchOne(db, sql: "SELECT foo()")!, "foo") } } @@ -77,7 +75,7 @@ class DatabaseSnapshotTests: GRDBTestCase { let function = DatabaseFunction("foo", argumentCount: 0, pure: true) { _ in return "foo" } snapshot.add(function: function) try snapshot.read { db in - try XCTAssertEqual(String.fetchOne(db, "SELECT foo()")!, "foo") + try XCTAssertEqual(String.fetchOne(db, sql: "SELECT foo()")!, "foo") } } @@ -89,25 +87,25 @@ class DatabaseSnapshotTests: GRDBTestCase { dbPool.add(collation: collation) try dbPool.write { db in - try db.execute("CREATE TABLE items (text TEXT)") - try db.execute("INSERT INTO items (text) VALUES ('a')") - try db.execute("INSERT INTO items (text) VALUES ('b')") - try db.execute("INSERT INTO items (text) VALUES ('c')") + try db.execute(sql: "CREATE TABLE items (text TEXT)") + try db.execute(sql: "INSERT INTO items (text) VALUES ('a')") + try db.execute(sql: "INSERT INTO items (text) VALUES ('b')") + try db.execute(sql: "INSERT INTO items (text) VALUES ('c')") } let snapshot = try dbPool.makeSnapshot() try snapshot.read { db in - XCTAssertEqual(try String.fetchAll(db, "SELECT text FROM items ORDER BY text COLLATE reverse"), ["c", "b", "a"]) + XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE reverse"), ["c", "b", "a"]) } } func testSnapshotCollations() throws { let dbPool = try makeDatabasePool() try dbPool.write { db in - try db.execute("CREATE TABLE items (text TEXT)") - try db.execute("INSERT INTO items (text) VALUES ('a')") - try db.execute("INSERT INTO items (text) VALUES ('b')") - try db.execute("INSERT INTO items (text) VALUES ('c')") + try db.execute(sql: "CREATE TABLE items (text TEXT)") + try db.execute(sql: "INSERT INTO items (text) VALUES ('a')") + try db.execute(sql: "INSERT INTO items (text) VALUES ('b')") + try db.execute(sql: "INSERT INTO items (text) VALUES ('c')") } let snapshot = try dbPool.makeSnapshot() @@ -116,7 +114,7 @@ class DatabaseSnapshotTests: GRDBTestCase { } snapshot.add(collation: collation) try snapshot.read { db in - XCTAssertEqual(try String.fetchAll(db, "SELECT text FROM items ORDER BY text COLLATE reverse"), ["c", "b", "a"]) + XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE reverse"), ["c", "b", "a"]) } } diff --git a/Tests/GRDBTests/DatabaseTests.swift b/Tests/GRDBTests/DatabaseTests.swift index 91369b7f6..ce47b0a07 100644 --- a/Tests/GRDBTests/DatabaseTests.swift +++ b/Tests/GRDBTests/DatabaseTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -13,7 +11,7 @@ class DatabaseTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in XCTAssertFalse(try db.tableExists("persons")) - try db.execute(""" + try db.execute(sql: """ CREATE TABLE persons ( id INTEGER PRIMARY KEY, name TEXT, @@ -27,7 +25,7 @@ class DatabaseTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in XCTAssertFalse(try db.tableExists("persons")) - try db.execute(""" + try db.execute(sql: """ CREATE TEMPORARY TABLE persons ( id INTEGER PRIMARY KEY, name TEXT, @@ -42,7 +40,7 @@ class DatabaseTests : GRDBTestCase { try dbQueue.inDatabase { db in XCTAssertFalse(try db.tableExists("persons")) XCTAssertFalse(try db.tableExists("pets")) - try db.execute(""" + try db.execute(sql: """ CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT, age INT); CREATE TABLE pets (id INTEGER PRIMARY KEY, name TEXT, age INT); """) @@ -54,13 +52,13 @@ class DatabaseTests : GRDBTestCase { func testUpdateStatement() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT, age INT)") + try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)") // The tested function: - let statement = try db.makeUpdateStatement("INSERT INTO persons (name, age) VALUES ('Arthur', 41)") + let statement = try db.makeUpdateStatement(sql: "INSERT INTO persons (name, age) VALUES ('Arthur', 41)") try statement.execute() - let row = try Row.fetchOne(db, "SELECT * FROM persons")! + let row = try Row.fetchOne(db, sql: "SELECT * FROM persons")! XCTAssertEqual(row[0] as String, "Arthur") XCTAssertEqual(row[1] as Int, 41) } @@ -69,12 +67,12 @@ class DatabaseTests : GRDBTestCase { func testUpdateStatementWithArrayBinding() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT, age INT)") + try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)") - let statement = try db.makeUpdateStatement("INSERT INTO persons (name, age) VALUES (?, ?)") + let statement = try db.makeUpdateStatement(sql: "INSERT INTO persons (name, age) VALUES (?, ?)") try statement.execute(arguments: ["Arthur", 41]) - let row = try Row.fetchOne(db, "SELECT * FROM persons")! + let row = try Row.fetchOne(db, sql: "SELECT * FROM persons")! XCTAssertEqual(row[0] as String, "Arthur") XCTAssertEqual(row[1] as Int, 41) } @@ -83,12 +81,12 @@ class DatabaseTests : GRDBTestCase { func testUpdateStatementWithDictionaryBinding() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT, age INT)") + try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)") - let statement = try db.makeUpdateStatement("INSERT INTO persons (name, age) VALUES (:name, :age)") + let statement = try db.makeUpdateStatement(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)") try statement.execute(arguments: ["name": "Arthur", "age": 41]) - let row = try Row.fetchOne(db, "SELECT * FROM persons")! + let row = try Row.fetchOne(db, sql: "SELECT * FROM persons")! XCTAssertEqual(row[0] as String, "Arthur") XCTAssertEqual(row[1] as Int, 41) } @@ -97,12 +95,12 @@ class DatabaseTests : GRDBTestCase { func testDatabaseExecute() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT, age INT)") + try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)") // The tested function: - try db.execute("INSERT INTO persons (name, age) VALUES ('Arthur', 41)") + try db.execute(sql: "INSERT INTO persons (name, age) VALUES ('Arthur', 41)") - let row = try Row.fetchOne(db, "SELECT * FROM persons")! + let row = try Row.fetchOne(db, sql: "SELECT * FROM persons")! XCTAssertEqual(row[0] as String, "Arthur") XCTAssertEqual(row[1] as Int, 41) } @@ -115,19 +113,19 @@ class DatabaseTests : GRDBTestCase { XCTAssertEqual(db.totalChangesCount, 0) XCTAssertEqual(db.lastInsertedRowID, 0) - try db.execute("CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT)") + try db.execute(sql: "CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT)") - try db.execute("INSERT INTO persons (name) VALUES ('Arthur')") + try db.execute(sql: "INSERT INTO persons (name) VALUES ('Arthur')") XCTAssertEqual(db.changesCount, 1) XCTAssertEqual(db.totalChangesCount, 1) XCTAssertEqual(db.lastInsertedRowID, 1) - try db.execute("INSERT INTO persons (name) VALUES (?)", arguments: ["Barbara"]) + try db.execute(sql: "INSERT INTO persons (name) VALUES (?)", arguments: ["Barbara"]) XCTAssertEqual(db.changesCount, 1) XCTAssertEqual(db.totalChangesCount, 2) XCTAssertEqual(db.lastInsertedRowID, 2) - try db.execute("DELETE FROM persons") + try db.execute(sql: "DELETE FROM persons") XCTAssertEqual(db.changesCount, 2) XCTAssertEqual(db.totalChangesCount, 4) XCTAssertEqual(db.lastInsertedRowID, 2) @@ -137,12 +135,12 @@ class DatabaseTests : GRDBTestCase { func testDatabaseExecuteWithArrayBinding() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT, age INT)") + try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)") // The tested function: - try db.execute("INSERT INTO persons (name, age) VALUES (?, ?)", arguments: ["Arthur", 41]) + try db.execute(sql: "INSERT INTO persons (name, age) VALUES (?, ?)", arguments: ["Arthur", 41]) - let row = try Row.fetchOne(db, "SELECT * FROM persons")! + let row = try Row.fetchOne(db, sql: "SELECT * FROM persons")! XCTAssertEqual(row[0] as String, "Arthur") XCTAssertEqual(row[1] as Int, 41) } @@ -151,12 +149,12 @@ class DatabaseTests : GRDBTestCase { func testDatabaseExecuteWithDictionaryBinding() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT, age INT)") + try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)") // The tested function: - try db.execute("INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41]) + try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41]) - let row = try Row.fetchOne(db, "SELECT * FROM persons")! + let row = try Row.fetchOne(db, sql: "SELECT * FROM persons")! XCTAssertEqual(row[0] as String, "Arthur") XCTAssertEqual(row[1] as Int, 41) } @@ -165,11 +163,11 @@ class DatabaseTests : GRDBTestCase { func testSelectStatement() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT, age INT)") - try db.execute("INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41]) - try db.execute("INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil]) + try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)") + try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41]) + try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil]) - let statement = try db.makeSelectStatement("SELECT * FROM persons") + let statement = try db.makeSelectStatement(sql: "SELECT * FROM persons") let rows = try Row.fetchAll(statement) XCTAssertEqual(rows.count, 2) } @@ -178,11 +176,11 @@ class DatabaseTests : GRDBTestCase { func testSelectStatementWithArrayBinding() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT, age INT)") - try db.execute("INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41]) - try db.execute("INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil]) + try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)") + try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41]) + try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil]) - let statement = try db.makeSelectStatement("SELECT * FROM persons WHERE name = ?") + let statement = try db.makeSelectStatement(sql: "SELECT * FROM persons WHERE name = ?") let rows = try Row.fetchAll(statement, arguments: ["Arthur"]) XCTAssertEqual(rows.count, 1) } @@ -191,11 +189,11 @@ class DatabaseTests : GRDBTestCase { func testSelectStatementWithDictionaryBinding() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT, age INT)") - try db.execute("INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41]) - try db.execute("INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil]) + try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)") + try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41]) + try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil]) - let statement = try db.makeSelectStatement("SELECT * FROM persons WHERE name = :name") + let statement = try db.makeSelectStatement(sql: "SELECT * FROM persons WHERE name = :name") let rows = try Row.fetchAll(statement, arguments: ["name": "Arthur"]) XCTAssertEqual(rows.count, 1) } @@ -204,13 +202,13 @@ class DatabaseTests : GRDBTestCase { func testRowValueAtIndex() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT, age INT)") - try db.execute("INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41]) - try db.execute("INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil]) + try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)") + try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41]) + try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil]) var names: [String?] = [] var ages: [Int?] = [] - let rows = try Row.fetchCursor(db, "SELECT * FROM persons ORDER BY name") + let rows = try Row.fetchCursor(db, sql: "SELECT * FROM persons ORDER BY name") while let row = try rows.next() { // The tested function: let name: String? = row[0] @@ -229,13 +227,13 @@ class DatabaseTests : GRDBTestCase { func testRowValueNamed() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (name TEXT, age INT)") - try db.execute("INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41]) - try db.execute("INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil]) + try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)") + try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41]) + try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil]) var names: [String?] = [] var ages: [Int?] = [] - let rows = try Row.fetchCursor(db, "SELECT * FROM persons ORDER BY name") + let rows = try Row.fetchCursor(db, sql: "SELECT * FROM persons ORDER BY name") while let row = try rows.next() { // The tested function: let name: String? = row["name"] @@ -258,7 +256,7 @@ class DatabaseTests : GRDBTestCase { database = db } try dbQueue.inDatabase { _ in - try database!.execute("CREATE TABLE persons (name TEXT)") + try database!.execute(sql: "CREATE TABLE persons (name TEXT)") } } @@ -273,15 +271,15 @@ class DatabaseTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE parent (id INTEGER PRIMARY KEY)") - try db.execute("CREATE TABLE child (parentID INTEGER NOT NULL REFERENCES parent(id))") + try db.execute(sql: "CREATE TABLE parent (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE child (parentID INTEGER NOT NULL REFERENCES parent(id))") } do { try dbQueue.inTransaction { db in do { - try db.execute("PRAGMA defer_foreign_keys = ON") - try db.execute("INSERT INTO child (parentID) VALUES (1)") + try db.execute(sql: "PRAGMA defer_foreign_keys = ON") + try db.execute(sql: "INSERT INTO child (parentID) VALUES (1)") } catch { XCTFail() } diff --git a/Tests/GRDBTests/DatabaseTimestampTests.swift b/Tests/GRDBTests/DatabaseTimestampTests.swift index 248e4366c..ca721df05 100644 --- a/Tests/GRDBTests/DatabaseTimestampTests.swift +++ b/Tests/GRDBTests/DatabaseTimestampTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -53,10 +51,10 @@ class DatabaseTimestampTests: GRDBTestCase { func testDatabaseTimestamp() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE dates (date DATETIME)") + try db.execute(sql: "CREATE TABLE dates (date DATETIME)") let storedDate = Date() - try db.execute("INSERT INTO dates (date) VALUES (?)", arguments: [DatabaseTimestamp(storedDate)]) - let fetchedDate = try DatabaseTimestamp.fetchOne(db, "SELECT date FROM dates")!.date + try db.execute(sql: "INSERT INTO dates (date) VALUES (?)", arguments: [DatabaseTimestamp(storedDate)]) + let fetchedDate = try DatabaseTimestamp.fetchOne(db, sql: "SELECT date FROM dates")!.date let delta = storedDate.timeIntervalSince(fetchedDate) XCTAssertTrue(abs(delta) < 0.1) } diff --git a/Tests/GRDBTests/DatabaseUUIDEncodingStrategyTests.swift b/Tests/GRDBTests/DatabaseUUIDEncodingStrategyTests.swift index 351809d9a..b79b5cb11 100644 --- a/Tests/GRDBTests/DatabaseUUIDEncodingStrategyTests.swift +++ b/Tests/GRDBTests/DatabaseUUIDEncodingStrategyTests.swift @@ -1,8 +1,6 @@ import XCTest import Foundation -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else @testable import GRDB diff --git a/Tests/GRDBTests/DatabaseValueConversionErrorTests.swift b/Tests/GRDBTests/DatabaseValueConversionErrorTests.swift index f4ded7dce..4e58f8075 100644 --- a/Tests/GRDBTests/DatabaseValueConversionErrorTests.swift +++ b/Tests/GRDBTests/DatabaseValueConversionErrorTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else @testable import GRDB @@ -23,7 +21,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase { // conversion error try dbQueue.read { db in - let statement = try db.makeSelectStatement("SELECT ? AS name") + let statement = try db.makeSelectStatement(sql: "SELECT ? AS name") statement.arguments = [nil] let row = try Row.fetchOne(statement)! @@ -49,7 +47,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase { // missing column try dbQueue.read { db in - let statement = try db.makeSelectStatement("SELECT ? AS unused") + let statement = try db.makeSelectStatement(sql: "SELECT ? AS unused") statement.arguments = ["ignored"] let row = try Row.fetchOne(statement)! @@ -90,7 +88,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase { // conversion error try dbQueue.read { db in - let statement = try db.makeSelectStatement("SELECT 1, ? AS value") + let statement = try db.makeSelectStatement(sql: "SELECT 1, ? AS value") statement.arguments = ["invalid"] let row = try Row.fetchOne(statement)! @@ -115,7 +113,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase { // missing column try dbQueue.read { db in - let statement = try db.makeSelectStatement("SELECT ? AS unused") + let statement = try db.makeSelectStatement(sql: "SELECT ? AS unused") statement.arguments = ["ignored"] let row = try Row.fetchOne(statement)! @@ -149,7 +147,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase { // conversion error try dbQueue.read { db in - let statement = try db.makeSelectStatement("SELECT NULL AS name, ? AS team") + let statement = try db.makeSelectStatement(sql: "SELECT NULL AS name, ? AS team") statement.arguments = ["invalid"] let row = try Row.fetchOne(statement)! @@ -175,7 +173,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase { // missing column try dbQueue.read { db in - let statement = try db.makeSelectStatement("SELECT ? AS unused") + let statement = try db.makeSelectStatement(sql: "SELECT ? AS unused") statement.arguments = ["ignored"] let row = try Row.fetchOne(statement)! @@ -212,7 +210,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase { // conversion error try dbQueue.read { db in - let statement = try db.makeSelectStatement("SELECT NULL AS name, ? AS value") + let statement = try db.makeSelectStatement(sql: "SELECT NULL AS name, ? AS value") statement.arguments = ["invalid"] let row = try Row.fetchOne(statement)! @@ -237,7 +235,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase { // missing column try dbQueue.read { db in - let statement = try db.makeSelectStatement("SELECT ? AS unused") + let statement = try db.makeSelectStatement(sql: "SELECT ? AS unused") statement.arguments = ["ignored"] let row = try Row.fetchOne(statement)! @@ -274,7 +272,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase { // conversion error try dbQueue.read { db in - let statement = try db.makeSelectStatement("SELECT NULL AS name, ? AS value") + let statement = try db.makeSelectStatement(sql: "SELECT NULL AS name, ? AS value") statement.arguments = ["invalid"] let row = try Row.fetchOne(statement)! @@ -301,7 +299,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase { // missing column try dbQueue.read { db in - let statement = try db.makeSelectStatement("SELECT ? AS unused") + let statement = try db.makeSelectStatement(sql: "SELECT ? AS unused") statement.arguments = ["ignored"] let row = try Row.fetchOne(statement)! @@ -330,7 +328,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase { // Each test comes with one or several commented crashing code snippets that trigger it. let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in - let statement = try db.makeSelectStatement("SELECT NULL AS name, ? AS team") + let statement = try db.makeSelectStatement(sql: "SELECT NULL AS name, ? AS team") statement.arguments = ["invalid"] let row = try Row.fetchOne(statement)! @@ -368,7 +366,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase { // Each test comes with one or several commented crashing code snippets that trigger it. let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in - let statement = try db.makeSelectStatement("SELECT ? AS foo") + let statement = try db.makeSelectStatement(sql: "SELECT ? AS foo") statement.arguments = [1000] let row = try Row.fetchOne(statement)! @@ -420,7 +418,7 @@ class DatabaseValueConversionErrorTests: GRDBTestCase { // Each test comes with one or several commented crashing code snippets that trigger it. let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in - let statement = try db.makeSelectStatement("SELECT NULL AS name, ? AS team") + let statement = try db.makeSelectStatement(sql: "SELECT NULL AS name, ? AS team") statement.arguments = ["invalid"] let row = try Row.fetchOne(statement)! diff --git a/Tests/GRDBTests/DatabaseValueConversionTests.swift b/Tests/GRDBTests/DatabaseValueConversionTests.swift index bda0dadb3..761758897 100644 --- a/Tests/GRDBTests/DatabaseValueConversionTests.swift +++ b/Tests/GRDBTests/DatabaseValueConversionTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -31,7 +29,11 @@ private extension DatabaseValue { private let emojiString = "'fooéı👨👨🏿🇫🇷🇨🇮'" private let emojiData = emojiString.data(using: .utf8) +#if swift(>=5.0) +private let nonUTF8Data = Data([0x80]) +#else private let nonUTF8Data = Data(bytes: [0x80]) +#endif private let invalidString = "\u{FFFD}" // decoded from nonUTF8Data // Until SPM tests can load resources, disable this test for SPM. #if !SWIFT_PACKAGE @@ -56,7 +58,7 @@ class DatabaseValueConversionTests : GRDBTestCase { do { // test T.fetchOne - let sqliteConversion = try T.fetchOne(db, sql) + let sqliteConversion = try T.fetchOne(db, sql: sql) XCTAssert( sqliteConversion == expectedSQLiteConversion, "unexpected SQLite conversion: \(stringRepresentation(sqliteConversion)) instead of \(stringRepresentation(expectedSQLiteConversion))", @@ -65,7 +67,7 @@ class DatabaseValueConversionTests : GRDBTestCase { do { // test row[0] as T? - let sqliteConversion = try Row.fetchCursor(db, sql).map { $0[0] as T? }.next()! + let sqliteConversion = try Row.fetchCursor(db, sql: sql).map { $0[0] as T? }.next()! XCTAssert( sqliteConversion == expectedSQLiteConversion, "unexpected SQLite conversion: \(stringRepresentation(sqliteConversion)) instead of \(stringRepresentation(expectedSQLiteConversion))", @@ -74,7 +76,7 @@ class DatabaseValueConversionTests : GRDBTestCase { do { // test row[0] as T - let sqliteConversion = try Row.fetchCursor(db, sql).map { $0.hasNull(atIndex: 0) ? nil : ($0[0] as T) }.next()! + let sqliteConversion = try Row.fetchCursor(db, sql: sql).map { $0.hasNull(atIndex: 0) ? nil : ($0[0] as T) }.next()! XCTAssert( sqliteConversion == expectedSQLiteConversion, "unexpected SQLite conversion: \(stringRepresentation(sqliteConversion)) instead of \(stringRepresentation(expectedSQLiteConversion))", @@ -83,7 +85,7 @@ class DatabaseValueConversionTests : GRDBTestCase { do { // test T.fromDatabaseValue - let dbValue = try DatabaseValue.fetchOne(db, sql)! + let dbValue = try DatabaseValue.fetchOne(db, sql: sql)! let dbValueConversion = T.fromDatabaseValue(dbValue) XCTAssert( dbValueConversion == expectedDatabaseValueConversion, @@ -102,7 +104,7 @@ class DatabaseValueConversionTests : GRDBTestCase { // We can only test failed decoding from database value, since // StatementColumnConvertible only supports optimistic decoding which // never fails. - let dbValue = try DatabaseValue.fetchOne(db, sql)! + let dbValue = try DatabaseValue.fetchOne(db, sql: sql)! XCTAssertNil(T.fromDatabaseValue(dbValue), file: file, line: line) } @@ -111,7 +113,7 @@ class DatabaseValueConversionTests : GRDBTestCase { override func setup(_ dbWriter: DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("createPersons") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE `values` ( integerAffinity INTEGER, textAffinity TEXT, @@ -136,9 +138,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Null is turned to null try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (textAffinity) VALUES (NULL)") + try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (NULL)") let sql = "SELECT textAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .null) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .null) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil) @@ -152,9 +154,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Int is turned to Text try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0 as Int]) + try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0 as Int]) let sql = "SELECT textAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .text) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -168,9 +170,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Int64 is turned to Text try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0 as Int64]) + try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0 as Int64]) let sql = "SELECT textAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .text) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -184,9 +186,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Int32 is turned to Text try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0 as Int32]) + try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0 as Int32]) let sql = "SELECT textAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .text) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -200,9 +202,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Double is turned to Text try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0.0]) + try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0.0]) let sql = "SELECT textAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .text) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -217,9 +219,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Empty string is turned to Text try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [""]) + try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [""]) let sql = "SELECT textAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .text) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -233,9 +235,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // "3.0e+5" is turned to Text try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: ["3.0e+5"]) + try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: ["3.0e+5"]) let sql = "SELECT textAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .text) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:3, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 3, expectedDatabaseValueConversion: nil) @@ -249,9 +251,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // emojiString is turned to Text try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [emojiString]) + try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [emojiString]) let sql = "SELECT textAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .text) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -265,9 +267,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // emojiData is turned to Blob try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [emojiData]) + try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [emojiData]) let sql = "SELECT textAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .blob) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -281,9 +283,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // nonUTF8Data is turned to Blob try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [nonUTF8Data]) + try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [nonUTF8Data]) let sql = "SELECT textAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .blob) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -298,9 +300,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // jpegData is turned to Blob try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [jpegData]) + try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [jpegData]) let sql = "SELECT textAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .blob) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -366,9 +368,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Null is turned to null try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (realAffinity) VALUES (NULL)") + try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (NULL)") let sql = "SELECT realAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .null) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .null) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil) @@ -382,9 +384,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Int is turned to Real try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [0 as Int]) + try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [0 as Int]) let sql = "SELECT realAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .real) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) @@ -398,9 +400,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Int64 is turned to Real try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [0 as Int64]) + try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [0 as Int64]) let sql = "SELECT realAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .real) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) @@ -414,9 +416,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Int32 is turned to Real try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [0 as Int32]) + try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [0 as Int32]) let sql = "SELECT realAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .real) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) @@ -430,9 +432,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // 3.0e5 Double is turned to Real try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [3.0e5]) + try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [3.0e5]) let sql = "SELECT realAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .real) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: true) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 300000, expectedDatabaseValueConversion: 300000) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 300000, expectedDatabaseValueConversion: 300000) @@ -446,9 +448,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // 1.0e20 Double is turned to Real try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [1.0e20]) + try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [1.0e20]) let sql = "SELECT realAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .real) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: true) try assertFailedDecoding(db, sql, Int.self) try assertFailedDecoding(db, sql, Int32.self) @@ -462,9 +464,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Empty string is turned to Text try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [""]) + try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [""]) let sql = "SELECT realAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .text) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -478,9 +480,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // "3.0e+5" is turned to Real try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: ["3.0e+5"]) + try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: ["3.0e+5"]) let sql = "SELECT realAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .real) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: true) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 300000, expectedDatabaseValueConversion: 300000) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 300000, expectedDatabaseValueConversion: 300000) @@ -494,9 +496,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // "1.0e+20" is turned to Real try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: ["1.0e+20"]) + try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: ["1.0e+20"]) let sql = "SELECT realAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .real) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: true) try assertFailedDecoding(db, sql, Int.self) try assertFailedDecoding(db, sql, Int32.self) @@ -510,9 +512,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // emojiString is turned to Text try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [emojiString]) + try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [emojiString]) let sql = "SELECT realAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .text) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -526,9 +528,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // emojiData is turned to Blob try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [emojiData]) + try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [emojiData]) let sql = "SELECT realAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .blob) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -542,9 +544,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // nonUTF8Data is turned to Blob try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [nonUTF8Data]) + try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [nonUTF8Data]) let sql = "SELECT realAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .blob) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -559,9 +561,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // jpegData is turned to Blob try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [jpegData]) + try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [jpegData]) let sql = "SELECT realAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .blob) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -587,9 +589,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Null is turned to null try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (noneAffinity) VALUES (NULL)") + try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (NULL)") let sql = "SELECT noneAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .null) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .null) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil) @@ -603,9 +605,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Int is turned to Integer try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0 as Int]) + try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0 as Int]) let sql = "SELECT noneAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .integer) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .integer) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) @@ -619,9 +621,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Int64 is turned to Integer try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0 as Int64]) + try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0 as Int64]) let sql = "SELECT noneAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .integer) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .integer) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) @@ -635,9 +637,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Int32 is turned to Integer try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0 as Int32]) + try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0 as Int32]) let sql = "SELECT noneAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .integer) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .integer) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) @@ -651,9 +653,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Double is turned to Real try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0.0]) + try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0.0]) let sql = "SELECT noneAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .real) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) @@ -667,9 +669,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Empty string is turned to Text try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [""]) + try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [""]) let sql = "SELECT noneAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .text) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -683,9 +685,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // "3.0e+5" is turned to Text try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: ["3.0e+5"]) + try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: ["3.0e+5"]) let sql = "SELECT noneAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .text) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:3, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 3, expectedDatabaseValueConversion: nil) @@ -699,9 +701,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // emojiString is turned to Text try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [emojiString]) + try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [emojiString]) let sql = "SELECT noneAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .text) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -715,9 +717,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // emojiData is turned to Blob try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [emojiData]) + try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [emojiData]) let sql = "SELECT noneAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .blob) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -731,9 +733,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // nonUTF8Data is turned to Blob try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [nonUTF8Data]) + try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [nonUTF8Data]) let sql = "SELECT noneAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .blob) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -748,9 +750,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // jpegData is turned to Blob try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [jpegData]) + try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [jpegData]) let sql = "SELECT noneAffinity FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .blob) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -790,9 +792,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Null is turned to null try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (\(columnName)) VALUES (NULL)") + try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (NULL)") let sql = "SELECT \(columnName) FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .null) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .null) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil) @@ -806,9 +808,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Int is turned to Integer try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [0 as Int]) + try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [0 as Int]) let sql = "SELECT \(columnName) FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .integer) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .integer) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) @@ -822,9 +824,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Int64 is turned to Integer try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [0 as Int64]) + try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [0 as Int64]) let sql = "SELECT \(columnName) FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .integer) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .integer) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) @@ -838,9 +840,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Int32 is turned to Integer try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [0 as Int32]) + try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [0 as Int32]) let sql = "SELECT \(columnName) FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .integer) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .integer) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0) @@ -854,9 +856,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // 3.0e5 Double is turned to Integer try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [3.0e5]) + try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [3.0e5]) let sql = "SELECT \(columnName) FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .integer) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .integer) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: true) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 300000, expectedDatabaseValueConversion: 300000) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 300000, expectedDatabaseValueConversion: 300000) @@ -870,9 +872,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // 1.0e20 Double is turned to Real try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [1.0e20]) + try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [1.0e20]) let sql = "SELECT \(columnName) FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .real) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: true) try assertFailedDecoding(db, sql, Int.self) try assertFailedDecoding(db, sql, Int32.self) @@ -886,9 +888,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // Empty string is turned to Text try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [""]) + try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [""]) let sql = "SELECT \(columnName) FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .text) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -902,9 +904,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // "3.0e+5" is turned to Integer try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: ["3.0e+5"]) + try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: ["3.0e+5"]) let sql = "SELECT \(columnName) FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .integer) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .integer) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: true) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 300000, expectedDatabaseValueConversion: 300000) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 300000, expectedDatabaseValueConversion: 300000) @@ -918,9 +920,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // "1.0e+20" is turned to Real try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: ["1.0e+20"]) + try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: ["1.0e+20"]) let sql = "SELECT \(columnName) FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .real) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: true) try assertFailedDecoding(db, sql, Int.self) try assertFailedDecoding(db, sql, Int32.self) @@ -934,9 +936,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // emojiString is turned to Text try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [emojiString]) + try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [emojiString]) let sql = "SELECT \(columnName) FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .text) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -950,9 +952,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // emojiData is turned to Blob try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [emojiData]) + try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [emojiData]) let sql = "SELECT \(columnName) FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .blob) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -966,9 +968,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // nonUTF8Data is turned to Blob try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [nonUTF8Data]) + try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [nonUTF8Data]) let sql = "SELECT \(columnName) FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .blob) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) @@ -983,9 +985,9 @@ class DatabaseValueConversionTests : GRDBTestCase { // jpegData is turned to Blob try dbQueue.inTransaction { db in - try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [jpegData]) + try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [jpegData]) let sql = "SELECT \(columnName) FROM `values`" - XCTAssertEqual(try DatabaseValue.fetchOne(db, sql)!.storageClass, .blob) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob) try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil) try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil) diff --git a/Tests/GRDBTests/DatabaseValueConvertibleDecodableTests.swift b/Tests/GRDBTests/DatabaseValueConvertibleDecodableTests.swift index ca05602c4..263ddda73 100644 --- a/Tests/GRDBTests/DatabaseValueConvertibleDecodableTests.swift +++ b/Tests/GRDBTests/DatabaseValueConvertibleDecodableTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -33,7 +31,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase { // Success from database let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let value = try Value.fetchOne(db, "SELECT 'foo'")! + let value = try Value.fetchOne(db, sql: "SELECT 'foo'")! XCTAssertEqual(value.string, "foo") } } @@ -81,7 +79,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase { // Success from database let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let wrapper = try ValueWrapper.fetchOne(db, "SELECT 'foo'")! + let wrapper = try ValueWrapper.fetchOne(db, sql: "SELECT 'foo'")! XCTAssertEqual(wrapper.value.string, "foo") } } @@ -124,7 +122,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase { // Success from database let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let wrapper = try ValueWrapper.fetchOne(db, "SELECT 'foo'")! + let wrapper = try ValueWrapper.fetchOne(db, sql: "SELECT 'foo'")! XCTAssertEqual(wrapper.nested.string, "foo") } } @@ -154,7 +152,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let value = try Value.fetchOne(db, "SELECT 'foo'")! + let value = try Value.fetchOne(db, sql: "SELECT 'foo'")! XCTAssertEqual(value.string, "foo (DatabaseValueConvertible)") } } @@ -165,7 +163,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase { } let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let value = try Value.fetchOne(db, "SELECT 'foo'")! + let value = try Value.fetchOne(db, sql: "SELECT 'foo'")! XCTAssertEqual(value, .foo) } } diff --git a/Tests/GRDBTests/DatabaseValueConvertibleEncodableTests.swift b/Tests/GRDBTests/DatabaseValueConvertibleEncodableTests.swift index ef84e10e4..0a6fa42c6 100644 --- a/Tests/GRDBTests/DatabaseValueConvertibleEncodableTests.swift +++ b/Tests/GRDBTests/DatabaseValueConvertibleEncodableTests.swift @@ -1,8 +1,6 @@ import XCTest import Foundation -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/DatabaseValueConvertibleEscapingTests.swift b/Tests/GRDBTests/DatabaseValueConvertibleEscapingTests.swift index 302cf6d8e..76e3a1c93 100644 --- a/Tests/GRDBTests/DatabaseValueConvertibleEscapingTests.swift +++ b/Tests/GRDBTests/DatabaseValueConvertibleEscapingTests.swift @@ -1,8 +1,6 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else @testable import GRDB @@ -11,27 +9,27 @@ import XCTest class DatabaseValueConvertibleEscapingTests: GRDBTestCase { func testText() { - XCTAssertEqual("".databaseValue.sql, "''") - XCTAssertEqual("foo".databaseValue.sql, "'foo'") - XCTAssertEqual("\"foo\"".databaseValue.sql, "'\"foo\"'") - XCTAssertEqual("'foo'".databaseValue.sql, "'''foo'''") + XCTAssertEqual("".databaseValue.quotedSQL(), "''") + XCTAssertEqual("foo".databaseValue.quotedSQL(), "'foo'") + XCTAssertEqual("\"foo\"".databaseValue.quotedSQL(), "'\"foo\"'") + XCTAssertEqual("'foo'".databaseValue.quotedSQL(), "'''foo'''") } func testInteger() { - XCTAssertEqual(0.databaseValue.sql, "0") - XCTAssertEqual(Int64.min.databaseValue.sql, "-9223372036854775808") - XCTAssertEqual(Int64.max.databaseValue.sql, "9223372036854775807") + XCTAssertEqual(0.databaseValue.quotedSQL(), "0") + XCTAssertEqual(Int64.min.databaseValue.quotedSQL(), "-9223372036854775808") + XCTAssertEqual(Int64.max.databaseValue.quotedSQL(), "9223372036854775807") } func testDouble() { - XCTAssertEqual(0.0.databaseValue.sql, "0.0") - XCTAssertEqual(1.0.databaseValue.sql, "1.0") - XCTAssertEqual((-1.0).databaseValue.sql, "-1.0") - XCTAssertEqual(1.5.databaseValue.sql, "1.5") + XCTAssertEqual(0.0.databaseValue.quotedSQL(), "0.0") + XCTAssertEqual(1.0.databaseValue.quotedSQL(), "1.0") + XCTAssertEqual((-1.0).databaseValue.quotedSQL(), "-1.0") + XCTAssertEqual(1.5.databaseValue.quotedSQL(), "1.5") } func testBlob() { - XCTAssertEqual("".data(using: .utf8)!.databaseValue.sql, "X''") - XCTAssertEqual("foo".data(using: .utf8)!.databaseValue.sql, "X'666F6F'") + XCTAssertEqual(Data().databaseValue.quotedSQL(), "X''") + XCTAssertEqual("foo".data(using: .utf8)!.databaseValue.quotedSQL(), "X'666F6F'") } } diff --git a/Tests/GRDBTests/DatabaseValueConvertibleFetchTests.swift b/Tests/GRDBTests/DatabaseValueConvertibleFetchTests.swift index ccfb8d39d..886d251f6 100644 --- a/Tests/GRDBTests/DatabaseValueConvertibleFetchTests.swift +++ b/Tests/GRDBTests/DatabaseValueConvertibleFetchTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -39,23 +37,35 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT 1 UNION ALL SELECT 2" - let statement = try db.makeSelectStatement(sql) - try test(Fetched.fetchCursor(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Fetched.fetchCursor(db, sql: sql)) try test(Fetched.fetchCursor(statement)) - try test(Fetched.fetchCursor(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchCursor(db)) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchCursor(db)) } do { let sql = "SELECT 0, 1 UNION ALL SELECT 0, 2" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchCursor(db, sql, adapter: adapter)) + try test(Fetched.fetchCursor(db, sql: sql, adapter: adapter)) try test(Fetched.fetchCursor(statement, adapter: adapter)) - try test(Fetched.fetchCursor(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchCursor(db)) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db)) } } } + + #if swift(>=5.0) + func testFetchCursorWithInterpolation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request: SQLRequest = "SELECT \(42)" + let cursor = try request.fetchCursor(db) + let fetched = try cursor.next()! + XCTAssertEqual(fetched.int, 42) + } + } + #endif func testFetchCursorStepFailure() throws { let dbQueue = try makeDatabaseQueue() @@ -75,27 +85,25 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { do { _ = try cursor.next() XCTFail() - } catch let error as DatabaseError { - XCTAssertEqual(error.resultCode, .SQLITE_MISUSE) - XCTAssertEqual(error.message, "\(customError)") - XCTAssertEqual(error.sql!, sql) - XCTAssertEqual(error.description, "SQLite error 21 with statement `\(sql)`: \(customError)") + } catch is DatabaseError { + // Various SQLite and SQLCipher versions don't emit the same + // error. What we care about is that there is an error. } } do { let sql = "SELECT throw()" - try test(Fetched.fetchCursor(db, sql), sql: sql) - try test(Fetched.fetchCursor(db.makeSelectStatement(sql)), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchCursor(db), sql: sql) + try test(Fetched.fetchCursor(db, sql: sql), sql: sql) + try test(Fetched.fetchCursor(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchCursor(db), sql: sql) } do { let sql = "SELECT 0, throw()" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchCursor(db, sql, adapter: adapter), sql: sql) - try test(Fetched.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchCursor(db), sql: sql) + try test(Fetched.fetchCursor(db, sql: sql, adapter: adapter), sql: sql) + try test(Fetched.fetchCursor(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db), sql: sql) } } } @@ -116,18 +124,18 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT * FROM nonExistingTable" - try test(Fetched.fetchCursor(db, sql), sql: sql) - try test(Fetched.fetchCursor(db.makeSelectStatement(sql)), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchCursor(db), sql: sql) + try test(Fetched.fetchCursor(db, sql: sql), sql: sql) + try test(Fetched.fetchCursor(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchCursor(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchCursor(db, sql, adapter: adapter), sql: sql) - try test(Fetched.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchCursor(db), sql: sql) + try test(Fetched.fetchCursor(db, sql: sql, adapter: adapter), sql: sql) + try test(Fetched.fetchCursor(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db), sql: sql) } } } @@ -140,24 +148,35 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT 1 UNION ALL SELECT 2" - let statement = try db.makeSelectStatement(sql) - try test(Fetched.fetchAll(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Fetched.fetchAll(db, sql: sql)) try test(Fetched.fetchAll(statement)) - try test(Fetched.fetchAll(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchAll(db)) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchAll(db)) } do { let sql = "SELECT 0, 1 UNION ALL SELECT 0, 2" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchAll(db, sql, adapter: adapter)) + try test(Fetched.fetchAll(db, sql: sql, adapter: adapter)) try test(Fetched.fetchAll(statement, adapter: adapter)) - try test(Fetched.fetchAll(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchAll(db)) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db)) } } } - + + #if swift(>=5.0) + func testFetchAllWithInterpolation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request: SQLRequest = "SELECT \(42)" + let array = try request.fetchAll(db) + XCTAssertEqual(array[0].int, 42) + } + } + #endif + func testFetchAllStepFailure() throws { let dbQueue = try makeDatabaseQueue() let customError = NSError(domain: "Custom", code: 0xDEAD) @@ -176,18 +195,18 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT throw()" - try test(Fetched.fetchAll(db, sql), sql: sql) - try test(Fetched.fetchAll(db.makeSelectStatement(sql)), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchAll(db), sql: sql) + try test(Fetched.fetchAll(db, sql: sql), sql: sql) + try test(Fetched.fetchAll(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchAll(db), sql: sql) } do { let sql = "SELECT 0, throw()" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchAll(db, sql, adapter: adapter), sql: sql) - try test(Fetched.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchAll(db), sql: sql) + try test(Fetched.fetchAll(db, sql: sql, adapter: adapter), sql: sql) + try test(Fetched.fetchAll(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db), sql: sql) } } } @@ -208,18 +227,18 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT * FROM nonExistingTable" - try test(Fetched.fetchAll(db, sql), sql: sql) - try test(Fetched.fetchAll(db.makeSelectStatement(sql)), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchAll(db), sql: sql) + try test(Fetched.fetchAll(db, sql: sql), sql: sql) + try test(Fetched.fetchAll(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchAll(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchAll(db, sql, adapter: adapter), sql: sql) - try test(Fetched.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchAll(db), sql: sql) + try test(Fetched.fetchAll(db, sql: sql, adapter: adapter), sql: sql) + try test(Fetched.fetchAll(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db), sql: sql) } } } @@ -233,20 +252,20 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT 1 WHERE 0" - let statement = try db.makeSelectStatement(sql) - try test(Fetched.fetchOne(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Fetched.fetchOne(db, sql: sql)) try test(Fetched.fetchOne(statement)) - try test(Fetched.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchOne(db)) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchOne(db)) } do { let sql = "SELECT 0, 1 WHERE 0" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchOne(db, sql, adapter: adapter)) + try test(Fetched.fetchOne(db, sql: sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) - try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchOne(db)) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db)) } } do { @@ -255,20 +274,20 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT NULL" - let statement = try db.makeSelectStatement(sql) - try test(Fetched.fetchOne(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Fetched.fetchOne(db, sql: sql)) try test(Fetched.fetchOne(statement)) - try test(Fetched.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchOne(db)) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchOne(db)) } do { let sql = "SELECT 0, NULL" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchOne(db, sql, adapter: adapter)) + try test(Fetched.fetchOne(db, sql: sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) - try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchOne(db)) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db)) } } do { @@ -277,25 +296,36 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT 1" - let statement = try db.makeSelectStatement(sql) - try test(Fetched.fetchOne(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Fetched.fetchOne(db, sql: sql)) try test(Fetched.fetchOne(statement)) - try test(Fetched.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchOne(db)) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchOne(db)) } do { let sql = "SELECT 0, 1" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchOne(db, sql, adapter: adapter)) + try test(Fetched.fetchOne(db, sql: sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) - try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchOne(db)) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db)) } } } } - + + #if swift(>=5.0) + func testFetchOneWithInterpolation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request: SQLRequest = "SELECT \(42)" + let fetched = try request.fetchOne(db) + XCTAssertEqual(fetched!.int, 42) + } + } + #endif + func testFetchOneStepFailure() throws { let dbQueue = try makeDatabaseQueue() let customError = NSError(domain: "Custom", code: 0xDEAD) @@ -314,18 +344,18 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT throw()" - try test(Fetched.fetchOne(db, sql), sql: sql) - try test(Fetched.fetchOne(db.makeSelectStatement(sql)), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchOne(db), sql: sql) + try test(Fetched.fetchOne(db, sql: sql), sql: sql) + try test(Fetched.fetchOne(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchOne(db), sql: sql) } do { let sql = "SELECT 0, throw()" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchOne(db, sql, adapter: adapter), sql: sql) - try test(Fetched.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchOne(db), sql: sql) + try test(Fetched.fetchOne(db, sql: sql, adapter: adapter), sql: sql) + try test(Fetched.fetchOne(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db), sql: sql) } } } @@ -346,18 +376,18 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT * FROM nonExistingTable" - try test(Fetched.fetchOne(db, sql), sql: sql) - try test(Fetched.fetchOne(db.makeSelectStatement(sql)), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchOne(db), sql: sql) + try test(Fetched.fetchOne(db, sql: sql), sql: sql) + try test(Fetched.fetchOne(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchOne(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchOne(db, sql, adapter: adapter), sql: sql) - try test(Fetched.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchOne(db), sql: sql) + try test(Fetched.fetchOne(db, sql: sql, adapter: adapter), sql: sql) + try test(Fetched.fetchOne(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db), sql: sql) } } } @@ -375,24 +405,36 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT 1 UNION ALL SELECT NULL" - let statement = try db.makeSelectStatement(sql) - try test(Optional.fetchCursor(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Optional.fetchCursor(db, sql: sql)) try test(Optional.fetchCursor(statement)) - try test(Optional.fetchCursor(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchCursor(db)) + try test(Optional.fetchCursor(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchCursor(db)) } do { let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Optional.fetchCursor(db, sql, adapter: adapter)) + try test(Optional.fetchCursor(db, sql: sql, adapter: adapter)) try test(Optional.fetchCursor(statement, adapter: adapter)) - try test(Optional.fetchCursor(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchCursor(db)) + try test(Optional.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db)) } } } - + + #if swift(>=5.0) + func testOptionalFetchCursorWithInterpolation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request: SQLRequest = "SELECT \(42)" + let cursor = try request.fetchCursor(db) + let fetched = try cursor.next()! + XCTAssertEqual(fetched!.int, 42) + } + } + #endif + func testOptionalFetchCursorStepFailure() throws { let dbQueue = try makeDatabaseQueue() let customError = NSError(domain: "Custom", code: 0xDEAD) @@ -411,27 +453,25 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { do { _ = try cursor.next() XCTFail() - } catch let error as DatabaseError { - XCTAssertEqual(error.resultCode, .SQLITE_MISUSE) - XCTAssertEqual(error.message, "\(customError)") - XCTAssertEqual(error.sql!, sql) - XCTAssertEqual(error.description, "SQLite error 21 with statement `\(sql)`: \(customError)") + } catch is DatabaseError { + // Various SQLite and SQLCipher versions don't emit the same + // error. What we care about is that there is an error. } } do { let sql = "SELECT throw()" - try test(Optional.fetchCursor(db, sql), sql: sql) - try test(Optional.fetchCursor(db.makeSelectStatement(sql)), sql: sql) - try test(Optional.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchCursor(db), sql: sql) + try test(Optional.fetchCursor(db, sql: sql), sql: sql) + try test(Optional.fetchCursor(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Optional.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchCursor(db), sql: sql) } do { let sql = "SELECT 0, throw()" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Optional.fetchCursor(db, sql, adapter: adapter), sql: sql) - try test(Optional.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Optional.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchCursor(db), sql: sql) + try test(Optional.fetchCursor(db, sql: sql, adapter: adapter), sql: sql) + try test(Optional.fetchCursor(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Optional.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db), sql: sql) } } } @@ -452,18 +492,18 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT * FROM nonExistingTable" - try test(Optional.fetchCursor(db, sql), sql: sql) - try test(Optional.fetchCursor(db.makeSelectStatement(sql)), sql: sql) - try test(Optional.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchCursor(db), sql: sql) + try test(Optional.fetchCursor(db, sql: sql), sql: sql) + try test(Optional.fetchCursor(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Optional.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchCursor(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Optional.fetchCursor(db, sql, adapter: adapter), sql: sql) - try test(Optional.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Optional.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchCursor(db), sql: sql) + try test(Optional.fetchCursor(db, sql: sql, adapter: adapter), sql: sql) + try test(Optional.fetchCursor(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Optional.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db), sql: sql) } } } @@ -478,24 +518,35 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT 1 UNION ALL SELECT NULL" - let statement = try db.makeSelectStatement(sql) - try test(Optional.fetchAll(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Optional.fetchAll(db, sql: sql)) try test(Optional.fetchAll(statement)) - try test(Optional.fetchAll(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchAll(db)) + try test(Optional.fetchAll(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchAll(db)) } do { let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Optional.fetchAll(db, sql, adapter: adapter)) + try test(Optional.fetchAll(db, sql: sql, adapter: adapter)) try test(Optional.fetchAll(statement, adapter: adapter)) - try test(Optional.fetchAll(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchAll(db)) + try test(Optional.fetchAll(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db)) } } } - + + #if swift(>=5.0) + func testOptionalFetchAllWithInterpolation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request: SQLRequest = "SELECT \(42)" + let array = try request.fetchAll(db) + XCTAssertEqual(array[0]!.int, 42) + } + } + #endif + func testOptionalFetchAllStepFailure() throws { let dbQueue = try makeDatabaseQueue() let customError = NSError(domain: "Custom", code: 0xDEAD) @@ -514,18 +565,18 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT throw()" - try test(Optional.fetchAll(db, sql), sql: sql) - try test(Optional.fetchAll(db.makeSelectStatement(sql)), sql: sql) - try test(Optional.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchAll(db), sql: sql) + try test(Optional.fetchAll(db, sql: sql), sql: sql) + try test(Optional.fetchAll(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Optional.fetchAll(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchAll(db), sql: sql) } do { let sql = "SELECT 0, throw()" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Optional.fetchAll(db, sql, adapter: adapter), sql: sql) - try test(Optional.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Optional.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchAll(db), sql: sql) + try test(Optional.fetchAll(db, sql: sql, adapter: adapter), sql: sql) + try test(Optional.fetchAll(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Optional.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db), sql: sql) } } } @@ -546,18 +597,18 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT * FROM nonExistingTable" - try test(Optional.fetchAll(db, sql), sql: sql) - try test(Optional.fetchAll(db.makeSelectStatement(sql)), sql: sql) - try test(Optional.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchAll(db), sql: sql) + try test(Optional.fetchAll(db, sql: sql), sql: sql) + try test(Optional.fetchAll(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Optional.fetchAll(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchAll(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Optional.fetchAll(db, sql, adapter: adapter), sql: sql) - try test(Optional.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Optional.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchAll(db), sql: sql) + try test(Optional.fetchAll(db, sql: sql, adapter: adapter), sql: sql) + try test(Optional.fetchAll(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Optional.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db), sql: sql) } } } diff --git a/Tests/GRDBTests/DatabaseValueConvertibleSubclassTests.swift b/Tests/GRDBTests/DatabaseValueConvertibleSubclassTests.swift index 9dbe64cea..62b9fafb7 100644 --- a/Tests/GRDBTests/DatabaseValueConvertibleSubclassTests.swift +++ b/Tests/GRDBTests/DatabaseValueConvertibleSubclassTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -36,13 +34,13 @@ class DatabaseValueConvertibleSubclassTests: GRDBTestCase { func testParent() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE parents (name TEXT)") - try db.execute("INSERT INTO parents (name) VALUES (?)", arguments: [FetchableParent()]) - let string = try String.fetchOne(db, "SELECT * FROM parents")! + try db.execute(sql: "CREATE TABLE parents (name TEXT)") + try db.execute(sql: "INSERT INTO parents (name) VALUES (?)", arguments: [FetchableParent()]) + let string = try String.fetchOne(db, sql: "SELECT * FROM parents")! XCTAssertEqual(string, "Parent") - let parent = try FetchableParent.fetchOne(db, "SELECT * FROM parents")! + let parent = try FetchableParent.fetchOne(db, sql: "SELECT * FROM parents")! XCTAssertEqual(parent.description, "Parent") - let parents = try FetchableParent.fetchAll(db, "SELECT * FROM parents") + let parents = try FetchableParent.fetchAll(db, sql: "SELECT * FROM parents") XCTAssertEqual(parents.first!.description, "Parent") } } @@ -50,13 +48,13 @@ class DatabaseValueConvertibleSubclassTests: GRDBTestCase { func testChild() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE children (name TEXT)") - try db.execute("INSERT INTO children (name) VALUES (?)", arguments: [FetchableChild()]) - let string = try String.fetchOne(db, "SELECT * FROM children")! + try db.execute(sql: "CREATE TABLE children (name TEXT)") + try db.execute(sql: "INSERT INTO children (name) VALUES (?)", arguments: [FetchableChild()]) + let string = try String.fetchOne(db, sql: "SELECT * FROM children")! XCTAssertEqual(string, "Child") - let child = try FetchableChild.fetchOne(db, "SELECT * FROM children")! + let child = try FetchableChild.fetchOne(db, sql: "SELECT * FROM children")! XCTAssertEqual(child.description, "Child") - let children = try FetchableChild.fetchAll(db, "SELECT * FROM children") + let children = try FetchableChild.fetchAll(db, sql: "SELECT * FROM children") XCTAssertEqual(children.first!.description, "Child") } } diff --git a/Tests/GRDBTests/DatabaseValueTests.swift b/Tests/GRDBTests/DatabaseValueTests.swift index 2db3b009a..5cb8cf580 100644 --- a/Tests/GRDBTests/DatabaseValueTests.swift +++ b/Tests/GRDBTests/DatabaseValueTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,21 +10,21 @@ class DatabaseValueTests: GRDBTestCase { func testDatabaseValueAsDatabaseValueConvertible() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - XCTAssertEqual(try DatabaseValue.fetchOne(db, "SELECT 1")!.storage, DatabaseValue.Storage.int64(1)) - XCTAssertEqual(try DatabaseValue.fetchOne(db, "SELECT 1.0")!.storage, DatabaseValue.Storage.double(1)) - XCTAssertEqual(try DatabaseValue.fetchOne(db, "SELECT 'foo'")!.storage, DatabaseValue.Storage.string("foo")) - XCTAssertEqual(try DatabaseValue.fetchOne(db, "SELECT x'53514C697465'")!.storage, DatabaseValue.Storage.blob("SQLite".data(using: .utf8)!)) - XCTAssertTrue(try DatabaseValue.fetchOne(db, "SELECT NULL")!.isNull) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: "SELECT 1")!.storage, DatabaseValue.Storage.int64(1)) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: "SELECT 1.0")!.storage, DatabaseValue.Storage.double(1)) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: "SELECT 'foo'")!.storage, DatabaseValue.Storage.string("foo")) + XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: "SELECT x'53514C697465'")!.storage, DatabaseValue.Storage.blob("SQLite".data(using: .utf8)!)) + XCTAssertTrue(try DatabaseValue.fetchOne(db, sql: "SELECT NULL")!.isNull) } } func testDatabaseValueCanBeUsedAsStatementArgument() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE integers (integer INTEGER)") - try db.execute("INSERT INTO integers (integer) VALUES (1)") + try db.execute(sql: "CREATE TABLE integers (integer INTEGER)") + try db.execute(sql: "INSERT INTO integers (integer) VALUES (1)") let dbValue: DatabaseValue = 1.databaseValue - let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM integers WHERE integer = ?", arguments: [dbValue])! + let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM integers WHERE integer = ?", arguments: [dbValue])! XCTAssertEqual(count, 1) } } diff --git a/Tests/GRDBTests/DatabaseWriterTests.swift b/Tests/GRDBTests/DatabaseWriterTests.swift index 757453dc4..6357e6e08 100644 --- a/Tests/GRDBTests/DatabaseWriterTests.swift +++ b/Tests/GRDBTests/DatabaseWriterTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -16,10 +14,10 @@ class DatabaseWriterTests : GRDBTestCase { t.column("id", .integer).primaryKey() } try dbQueue.unsafeReentrantWrite { db2 in - try db2.execute("INSERT INTO table1 (id) VALUES (NULL)") + try db2.execute(sql: "INSERT INTO table1 (id) VALUES (NULL)") try dbQueue.unsafeReentrantWrite { db3 in - try XCTAssertEqual(Int.fetchOne(db3, "SELECT * FROM table1"), 1) + try XCTAssertEqual(Int.fetchOne(db3, sql: "SELECT * FROM table1"), 1) XCTAssertTrue(db1 === db2) XCTAssertTrue(db2 === db3) } @@ -34,10 +32,10 @@ class DatabaseWriterTests : GRDBTestCase { t.column("id", .integer).primaryKey() } try dbPool.unsafeReentrantWrite { db2 in - try db2.execute("INSERT INTO table1 (id) VALUES (NULL)") + try db2.execute(sql: "INSERT INTO table1 (id) VALUES (NULL)") try dbPool.unsafeReentrantWrite { db3 in - try XCTAssertEqual(Int.fetchOne(db3, "SELECT * FROM table1"), 1) + try XCTAssertEqual(Int.fetchOne(db3, sql: "SELECT * FROM table1"), 1) XCTAssertTrue(db1 === db2) XCTAssertTrue(db2 === db3) } @@ -61,7 +59,7 @@ class DatabaseWriterTests : GRDBTestCase { migrator.registerMigration("init") { db in // Create a database with recursive constraints, so that we test // that those don't prevent database erasure. - try db.execute(""" + try db.execute(sql: """ CREATE TABLE t1 (id INTEGER PRIMARY KEY AUTOINCREMENT, b UNIQUE, c REFERENCES t2(id) ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED); CREATE TABLE t2 (id INTEGER PRIMARY KEY AUTOINCREMENT, b UNIQUE, c REFERENCES t1(id) ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED); CREATE VIRTUAL TABLE ft USING fts4(content); @@ -87,7 +85,7 @@ class DatabaseWriterTests : GRDBTestCase { try writer.vacuum() try writer.read { db in - try XCTAssertNil(Row.fetchOne(db, "SELECT * FROM sqlite_master")) + try XCTAssertNil(Row.fetchOne(db, sql: "SELECT * FROM sqlite_master")) } } @@ -95,27 +93,34 @@ class DatabaseWriterTests : GRDBTestCase { func testIssue424() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.write { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE t(a); INSERT INTO t VALUES (1) """) } try dbQueue.read { db in - _ = try Row.fetchCursor(db.cachedSelectStatement("SELECT * FROM t")).next() + _ = try Row.fetchCursor(db.cachedSelectStatement(sql: "SELECT * FROM t")).next() } try dbQueue.erase() } // See https://github.com/groue/GRDB.swift/issues/424 func testIssue424Minimal() throws { + #if GRDBCIPHER + // SQLCipher can't backup encrypted databases: skip this test + if dbConfiguration.passphrase != nil { + return + } + #endif + let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE t(a); INSERT INTO t VALUES (1); PRAGMA query_only = 1; """) - _ = try Row.fetchCursor(db.cachedSelectStatement("SELECT * FROM t")).next() + _ = try Row.fetchCursor(db.cachedSelectStatement(sql: "SELECT * FROM t")).next() } try DatabaseQueue().backup(to: dbQueue) } diff --git a/Tests/GRDBTests/DerivableRequestTests.swift b/Tests/GRDBTests/DerivableRequestTests.swift index 1286ecffb..c0f5e978f 100644 --- a/Tests/GRDBTests/DerivableRequestTests.swift +++ b/Tests/GRDBTests/DerivableRequestTests.swift @@ -1,10 +1,8 @@ import XCTest -#if GRDBCIPHER -import GRDBCipher -#elseif GRDBCUSTOMSQLITE -import GRDBCustomSQLite +#if GRDBCUSTOMSQLITE + import GRDBCustomSQLite #else -import GRDB + import GRDB #endif private struct Author: FetchableRecord, PersistableRecord, Codable { @@ -60,7 +58,7 @@ private var libraryMigrator: DatabaseMigrator = { return migrator }() -// One extension... +// Define DerivableRequest extensions extension DerivableRequest where RowDecoder == Author { func filter(country: String) -> Self { return filter(Column("country") == country) @@ -73,6 +71,12 @@ extension DerivableRequest where RowDecoder == Author { } } +extension DerivableRequest where RowDecoder == Book { + func orderByTitle() -> Self { + return order(Column("title").collating(.localizedCaseInsensitiveCompare)) + } +} + class DerivableRequestTests: GRDBTestCase { func testFilter() throws { let dbQueue = try makeDatabaseQueue() @@ -100,32 +104,84 @@ class DerivableRequestTests: GRDBTestCase { try libraryMigrator.migrate(dbQueue) try dbQueue.inDatabase { db in // ... for two requests (1) + sqlQueries.removeAll() let authorNames = try Author.all() .orderByFullName() .fetchAll(db) .map { $0.fullName } XCTAssertEqual(authorNames, ["Herman Melville", "Marcel Proust"]) + XCTAssertEqual(lastSQLQuery, """ + SELECT * FROM "author" \ + ORDER BY "lastName" COLLATE swiftLocalizedCaseInsensitiveCompare, \ + "firstName" COLLATE swiftLocalizedCaseInsensitiveCompare + """) + sqlQueries.removeAll() let reversedAuthorNames = try Author.all() .orderByFullName() .reversed() .fetchAll(db) .map { $0.fullName } XCTAssertEqual(reversedAuthorNames, ["Marcel Proust", "Herman Melville"]) - + XCTAssertEqual(lastSQLQuery, """ + SELECT * FROM "author" \ + ORDER BY "lastName" COLLATE swiftLocalizedCaseInsensitiveCompare DESC, \ + "firstName" COLLATE swiftLocalizedCaseInsensitiveCompare DESC + """) + + sqlQueries.removeAll() + _ /* unorderedAuthors */ = try Author.all() + .orderByFullName() + .unordered() + .fetchAll(db) + XCTAssertEqual(lastSQLQuery, """ + SELECT * FROM "author" + """) + // ... for two requests (2) + sqlQueries.removeAll() let bookTitles = try Book .joining(required: Book.author.orderByFullName()) + .orderByTitle() .fetchAll(db) .map { $0.title } - XCTAssertEqual(bookTitles, ["Moby-Dick", "Du côté de chez Swann"]) + XCTAssertEqual(bookTitles, ["Du côté de chez Swann", "Moby-Dick"]) + XCTAssertEqual(lastSQLQuery, """ + SELECT "book".* FROM "book" \ + JOIN "author" ON ("author"."id" = "book"."authorId") \ + ORDER BY \ + "book"."title" COLLATE swiftLocalizedCaseInsensitiveCompare, \ + "author"."lastName" COLLATE swiftLocalizedCaseInsensitiveCompare, \ + "author"."firstName" COLLATE swiftLocalizedCaseInsensitiveCompare + """) + sqlQueries.removeAll() let reversedBookTitles = try Book .joining(required: Book.author.orderByFullName()) + .orderByTitle() .reversed() .fetchAll(db) .map { $0.title } - XCTAssertEqual(reversedBookTitles, ["Du côté de chez Swann", "Moby-Dick"]) + XCTAssertEqual(reversedBookTitles, ["Moby-Dick", "Du côté de chez Swann"]) + XCTAssertEqual(lastSQLQuery, """ + SELECT "book".* FROM "book" \ + JOIN "author" ON ("author"."id" = "book"."authorId") \ + ORDER BY \ + "book"."title" COLLATE swiftLocalizedCaseInsensitiveCompare DESC, \ + "author"."lastName" COLLATE swiftLocalizedCaseInsensitiveCompare DESC, \ + "author"."firstName" COLLATE swiftLocalizedCaseInsensitiveCompare DESC + """) + + sqlQueries.removeAll() + _ /* unorderedBooks */ = try Book + .joining(required: Book.author.orderByFullName()) + .orderByTitle() + .unordered() + .fetchAll(db) + XCTAssertEqual(lastSQLQuery, """ + SELECT "book".* FROM "book" \ + JOIN "author" ON ("author"."id" = "book"."authorId") + """) } } } diff --git a/Tests/GRDBTests/DropFirstCursorTests.swift b/Tests/GRDBTests/DropFirstCursorTests.swift index 2343305c5..0744986b3 100644 --- a/Tests/GRDBTests/DropFirstCursorTests.swift +++ b/Tests/GRDBTests/DropFirstCursorTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/DropWhileCursorTests.swift b/Tests/GRDBTests/DropWhileCursorTests.swift index 7cbcc336d..ef97a512d 100644 --- a/Tests/GRDBTests/DropWhileCursorTests.swift +++ b/Tests/GRDBTests/DropWhileCursorTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/EncryptionTests.swift b/Tests/GRDBTests/EncryptionTests.swift index ce5d9fbe1..8bfbb634e 100644 --- a/Tests/GRDBTests/EncryptionTests.swift +++ b/Tests/GRDBTests/EncryptionTests.swift @@ -1,6 +1,6 @@ #if SQLITE_HAS_CODEC import XCTest -import GRDBCipher +import GRDB class EncryptionTests: GRDBTestCase { @@ -9,8 +9,8 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE data (value INTEGER)") - try db.execute("INSERT INTO data (value) VALUES (1)") + try db.execute(sql: "CREATE TABLE data (value INTEGER)") + try db.execute(sql: "INSERT INTO data (value) VALUES (1)") } } @@ -18,7 +18,7 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.inDatabase { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 1) } } } @@ -28,8 +28,8 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE data (value INTEGER)") - try db.execute("INSERT INTO data (value) VALUES (1)") + try db.execute(sql: "CREATE TABLE data (value INTEGER)") + try db.execute(sql: "INSERT INTO data (value) VALUES (1)") } } @@ -41,8 +41,6 @@ class EncryptionTests: GRDBTestCase { } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_NOTADB) XCTAssertEqual(error.message!, "file is not a database") - XCTAssertTrue(error.sql == nil) - XCTAssertEqual(error.description, "SQLite error 26: file is not a database") } } } @@ -52,8 +50,8 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE data (value INTEGER)") - try db.execute("INSERT INTO data (value) VALUES (1)") + try db.execute(sql: "CREATE TABLE data (value INTEGER)") + try db.execute(sql: "INSERT INTO data (value) VALUES (1)") } } @@ -65,8 +63,6 @@ class EncryptionTests: GRDBTestCase { } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_NOTADB) XCTAssertEqual(error.message!, "file is not a database") - XCTAssertTrue(error.sql == nil) - XCTAssertEqual(error.description, "SQLite error 26: file is not a database") } } } @@ -76,8 +72,8 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE data (value INTEGER)") - try db.execute("INSERT INTO data (value) VALUES (1)") + try db.execute(sql: "CREATE TABLE data (value INTEGER)") + try db.execute(sql: "INSERT INTO data (value) VALUES (1)") } } @@ -86,10 +82,10 @@ class EncryptionTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.change(passphrase: "newSecret") try dbQueue.inDatabase { db in - try db.execute("INSERT INTO data (value) VALUES (2)") + try db.execute(sql: "INSERT INTO data (value) VALUES (2)") } try dbQueue.inDatabase { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 2) } } @@ -97,7 +93,7 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "newSecret" let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.inDatabase { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 2) } } } @@ -107,8 +103,8 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE data (value INTEGER)") - try db.execute("INSERT INTO data (value) VALUES (1)") + try db.execute(sql: "CREATE TABLE data (value INTEGER)") + try db.execute(sql: "INSERT INTO data (value) VALUES (1)") } } @@ -116,7 +112,7 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" let dbPool = try makeDatabasePool(filename: "test.sqlite") try dbPool.read { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 1) } } } @@ -126,8 +122,8 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE data (value INTEGER)") - try db.execute("INSERT INTO data (value) VALUES (1)") + try db.execute(sql: "CREATE TABLE data (value INTEGER)") + try db.execute(sql: "INSERT INTO data (value) VALUES (1)") } } @@ -139,8 +135,6 @@ class EncryptionTests: GRDBTestCase { } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_NOTADB) XCTAssertEqual(error.message!, "file is not a database") - XCTAssertTrue(error.sql == nil) - XCTAssertEqual(error.description, "SQLite error 26: file is not a database") } } } @@ -150,8 +144,8 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE data (value INTEGER)") - try db.execute("INSERT INTO data (value) VALUES (1)") + try db.execute(sql: "CREATE TABLE data (value INTEGER)") + try db.execute(sql: "INSERT INTO data (value) VALUES (1)") } } @@ -163,8 +157,6 @@ class EncryptionTests: GRDBTestCase { } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_NOTADB) XCTAssertEqual(error.message!, "file is not a database") - XCTAssertTrue(error.sql == nil) - XCTAssertEqual(error.description, "SQLite error 26: file is not a database") } } } @@ -174,8 +166,8 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE data (value INTEGER)") - try db.execute("INSERT INTO data (value) VALUES (1)") + try db.execute(sql: "CREATE TABLE data (value INTEGER)") + try db.execute(sql: "INSERT INTO data (value) VALUES (1)") } } @@ -184,8 +176,8 @@ class EncryptionTests: GRDBTestCase { let dbPool = try makeDatabasePool(filename: "test.sqlite") try dbPool.change(passphrase: "newSecret") try dbPool.write { db in - try db.execute("INSERT INTO data (value) VALUES (2)") - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 2) + try db.execute(sql: "INSERT INTO data (value) VALUES (2)") + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 2) } } @@ -193,7 +185,7 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "newSecret" let dbPool = try makeDatabasePool(filename: "test.sqlite") try dbPool.read { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 2) } } } @@ -203,8 +195,8 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" let dbPool = try makeDatabasePool(filename: "test.sqlite") try dbPool.write { db in - try db.execute("CREATE TABLE data (value INTEGER)") - try db.execute("INSERT INTO data (value) VALUES (1)") + try db.execute(sql: "CREATE TABLE data (value INTEGER)") + try db.execute(sql: "INSERT INTO data (value) VALUES (1)") } } @@ -212,7 +204,7 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" let dbPool = try makeDatabasePool(filename: "test.sqlite") try dbPool.read { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 1) } } } @@ -222,8 +214,8 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" let dbPool = try makeDatabasePool(filename: "test.sqlite") try dbPool.write { db in - try db.execute("CREATE TABLE data (value INTEGER)") - try db.execute("INSERT INTO data (value) VALUES (1)") + try db.execute(sql: "CREATE TABLE data (value INTEGER)") + try db.execute(sql: "INSERT INTO data (value) VALUES (1)") } } @@ -235,8 +227,6 @@ class EncryptionTests: GRDBTestCase { } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_NOTADB) XCTAssertEqual(error.message!, "file is not a database") - XCTAssertTrue(error.sql == nil) - XCTAssertEqual(error.description, "SQLite error 26: file is not a database") } } } @@ -246,8 +236,8 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" let dbPool = try makeDatabasePool(filename: "test.sqlite") try dbPool.write { db in - try db.execute("CREATE TABLE data (value INTEGER)") - try db.execute("INSERT INTO data (value) VALUES (1)") + try db.execute(sql: "CREATE TABLE data (value INTEGER)") + try db.execute(sql: "INSERT INTO data (value) VALUES (1)") } } @@ -259,8 +249,6 @@ class EncryptionTests: GRDBTestCase { } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_NOTADB) XCTAssertEqual(error.message!, "file is not a database") - XCTAssertTrue(error.sql == nil) - XCTAssertEqual(error.description, "SQLite error 26: file is not a database") } } } @@ -271,8 +259,8 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" let dbPool = try makeDatabasePool(filename: "test.sqlite") try dbPool.write { db in - try db.execute("CREATE TABLE data (value INTEGER)") - try db.execute("INSERT INTO data (value) VALUES (1)") + try db.execute(sql: "CREATE TABLE data (value INTEGER)") + try db.execute(sql: "INSERT INTO data (value) VALUES (1)") } } @@ -281,8 +269,8 @@ class EncryptionTests: GRDBTestCase { let dbPool = try makeDatabasePool(filename: "test.sqlite") try dbPool.change(passphrase: "newSecret") try dbPool.write { db in - try db.execute("INSERT INTO data (value) VALUES (2)") - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 2) + try db.execute(sql: "INSERT INTO data (value) VALUES (2)") + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 2) } } @@ -290,7 +278,7 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "newSecret" let dbPool = try makeDatabasePool(filename: "test.sqlite") try dbPool.read { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 2) } } } @@ -300,9 +288,9 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = nil let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.inDatabase { db in - try db.execute("PRAGMA key = 'secret'") - try db.execute("CREATE TABLE data (value INTEGER)") - try db.execute("INSERT INTO data (value) VALUES (1)") + try db.execute(sql: "PRAGMA key = 'secret'") + try db.execute(sql: "CREATE TABLE data (value INTEGER)") + try db.execute(sql: "INSERT INTO data (value) VALUES (1)") } } @@ -310,7 +298,7 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.inDatabase { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 1) } } } @@ -320,9 +308,9 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = nil let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.inDatabase { db in - try db.execute("PRAGMA key = 'secret'") - try db.execute("CREATE TABLE data (value INTEGER)") - try db.execute("INSERT INTO data (value) VALUES (1)") + try db.execute(sql: "PRAGMA key = 'secret'") + try db.execute(sql: "CREATE TABLE data (value INTEGER)") + try db.execute(sql: "INSERT INTO data (value) VALUES (1)") } } @@ -334,8 +322,6 @@ class EncryptionTests: GRDBTestCase { } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_NOTADB) XCTAssertEqual(error.message!, "file is not a database") - XCTAssertTrue(error.sql == nil) - XCTAssertEqual(error.description, "SQLite error 26: file is not a database") } } } @@ -343,26 +329,31 @@ class EncryptionTests: GRDBTestCase { func testCipherPageSize() throws { do { dbConfiguration.passphrase = "secret" - dbConfiguration.cipherPageSize = 8192 + dbConfiguration.prepareDatabase = { db in + try db.execute(sql: "PRAGMA cipher_page_size = 8192") + } let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.inDatabase({ db in - XCTAssertEqual(try Int.fetchOne(db, "PRAGMA cipher_page_size")!, 8192) + XCTAssertEqual(try Int.fetchOne(db, sql: "PRAGMA cipher_page_size")!, 8192) }) } do { - dbConfiguration.cipherPageSize = 4096 + dbConfiguration.passphrase = "secret" + dbConfiguration.prepareDatabase = { db in + try db.execute(sql: "PRAGMA cipher_page_size = 4096") + } let dbPool = try makeDatabasePool(filename: "testpool.sqlite") try dbPool.write({ db in - XCTAssertEqual(try Int.fetchOne(db, "PRAGMA cipher_page_size")!, 4096) - try db.execute("CREATE TABLE data(value INTEGER)") - try db.execute("INSERT INTO data(value) VALUES(1)") + XCTAssertEqual(try Int.fetchOne(db, sql: "PRAGMA cipher_page_size")!, 4096) + try db.execute(sql: "CREATE TABLE data(value INTEGER)") + try db.execute(sql: "INSERT INTO data(value) VALUES(1)") }) try dbPool.read({ db in - XCTAssertEqual(try Int.fetchOne(db, "PRAGMA cipher_page_size")!, 4096) - XCTAssertEqual(try Int.fetchOne(db, "SELECT value FROM data"), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "PRAGMA cipher_page_size")!, 4096) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT value FROM data"), 1) }) } @@ -371,27 +362,73 @@ class EncryptionTests: GRDBTestCase { func testCipherKDFIterations() throws { do { dbConfiguration.passphrase = "secret" - dbConfiguration.kdfIterations = 128000 + dbConfiguration.prepareDatabase = { db in + try db.execute(sql: "PRAGMA kdf_iter = 128000") + } let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.inDatabase { db in - XCTAssertEqual(try Int.fetchOne(db, "PRAGMA kdf_iter"), 128000) + XCTAssertEqual(try Int.fetchOne(db, sql: "PRAGMA kdf_iter"), 128000) } } do { - dbConfiguration.kdfIterations = 128000 - + dbConfiguration.passphrase = "secret" + dbConfiguration.prepareDatabase = { db in + try db.execute(sql: "PRAGMA kdf_iter = 128000") + } + let dbPool = try makeDatabasePool(filename: "testpool.sqlite") try dbPool.write { db in - XCTAssertEqual(try Int.fetchOne(db, "PRAGMA kdf_iter"), 128000) - try db.execute("CREATE TABLE data(value INTEGER)") - try db.execute("INSERT INTO data(value) VALUES(1)") + XCTAssertEqual(try Int.fetchOne(db, sql: "PRAGMA kdf_iter"), 128000) + try db.execute(sql: "CREATE TABLE data(value INTEGER)") + try db.execute(sql: "INSERT INTO data(value) VALUES(1)") } try dbPool.read { db in - XCTAssertEqual(try Int.fetchOne(db, "PRAGMA kdf_iter"), 128000) - XCTAssertEqual(try Int.fetchOne(db, "SELECT value FROM data"), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "PRAGMA kdf_iter"), 128000) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT value FROM data"), 1) + } + } + } + + func testCipherWithMismatchedKDFIterations() throws { + do { + dbConfiguration.passphrase = "secret" + dbConfiguration.prepareDatabase = { db in + try db.execute(sql: "PRAGMA kdf_iter = 128000") + } + + let dbPool = try makeDatabasePool(filename: "testpool.sqlite") + try dbPool.write { db in + XCTAssertEqual(try Int.fetchOne(db, sql: "PRAGMA kdf_iter"), 128000) + try db.execute(sql: "CREATE TABLE data(value INTEGER)") + try db.execute(sql: "INSERT INTO data(value) VALUES(1)") + } + + try dbPool.read { db in + XCTAssertEqual(try Int.fetchOne(db, sql: "PRAGMA kdf_iter"), 128000) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT value FROM data"), 1) + } + } + + do { + dbConfiguration.passphrase = "secret" + dbConfiguration.prepareDatabase = { db in + try db.execute(sql: "PRAGMA kdf_iter = 64000") + } + + do { + let dbPool = try makeDatabasePool(filename: "testpool.sqlite") + + try dbPool.read { db in + XCTAssertEqual(try Int.fetchOne(db, sql: "PRAGMA kdf_iter"), 64000) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT value FROM data"), 1) + } + XCTFail("Expected error") + } catch let error as DatabaseError { + XCTAssertEqual(error.resultCode, .SQLITE_NOTADB) + XCTAssertEqual(error.message!, "file is not a database") } } } @@ -408,8 +445,8 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = nil let plainTextDBQueue = try makeDatabaseQueue(filename: "plaintext.sqlite") try plainTextDBQueue.inDatabase { db in - try db.execute("CREATE TABLE data (value INTEGER)") - try db.execute("INSERT INTO data (value) VALUES (1)") + try db.execute(sql: "CREATE TABLE data (value INTEGER)") + try db.execute(sql: "INSERT INTO data (value) VALUES (1)") } dbConfiguration.passphrase = "secret" @@ -419,16 +456,14 @@ class EncryptionTests: GRDBTestCase { } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_NOTADB) XCTAssertEqual(error.message!, "file is not a database") - XCTAssertTrue(error.sql == nil) - XCTAssertEqual(error.description, "SQLite error 26: file is not a database") } let encryptedDBQueue = try makeDatabaseQueue(filename: "encrypted.sqlite") try plainTextDBQueue.inDatabase { db in - try db.execute("ATTACH DATABASE ? AS encrypted KEY ?", arguments: [encryptedDBQueue.path, "secret"]) - try db.execute("SELECT sqlcipher_export('encrypted')") - try db.execute("DETACH DATABASE encrypted") + try db.execute(sql: "ATTACH DATABASE ? AS encrypted KEY ?", arguments: [encryptedDBQueue.path, "secret"]) + try db.execute(sql: "SELECT sqlcipher_export('encrypted')") + try db.execute(sql: "DETACH DATABASE encrypted") } } @@ -436,7 +471,37 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" let dbQueue = try makeDatabaseQueue(filename: "encrypted.sqlite") try dbQueue.inDatabase { db in - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 1) + } + } + } + + func testSQLCipher3Compatibility() throws { + guard let cipherMajorVersion = try DatabaseQueue() + .read({ try String.fetchOne($0, sql: "PRAGMA cipher_version") }) + .flatMap({ $0.split(separator: ".").first }) + .flatMap({ Int($0 )}) + else { XCTFail("Unknown SQLCipher version"); return } + + if cipherMajorVersion >= 4 { + let testBundle = Bundle(for: type(of: self)) + let path = testBundle.url(forResource: "db", withExtension: "SQLCipher3")!.path + var configuration = Configuration() + configuration.passphrase = "secret" + configuration.prepareDatabase = { db in + try db.execute(sql: "PRAGMA cipher_compatibility = 3") + } + + do { + let dbQueue = try DatabaseQueue(path: path, configuration: configuration) + let success = try dbQueue.read { try String.fetchOne($0, sql: "SELECT a FROM t") } + XCTAssertEqual(success, "success") + } + + do { + let dbPool = try DatabasePool(path: path, configuration: configuration) + let success = try dbPool.read { try String.fetchOne($0, sql: "SELECT a FROM t") } + XCTAssertEqual(success, "success") } } } diff --git a/Tests/GRDBTests/EnumeratedCursorTests.swift b/Tests/GRDBTests/EnumeratedCursorTests.swift index c4625be92..0db74111a 100644 --- a/Tests/GRDBTests/EnumeratedCursorTests.swift +++ b/Tests/GRDBTests/EnumeratedCursorTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/FTS3PatternTests.swift b/Tests/GRDBTests/FTS3PatternTests.swift index 8099261ac..8109a451c 100644 --- a/Tests/GRDBTests/FTS3PatternTests.swift +++ b/Tests/GRDBTests/FTS3PatternTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -16,10 +14,10 @@ class FTS3PatternTests: GRDBTestCase { t.column("author") t.column("body") } - try db.execute("INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Moby Dick", "Herman Melville", "Call me Ishmael. Some years ago--never mind how long precisely--having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world."]) - try db.execute("INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Red Mars", "Kim Stanley Robinson", "History is not evolution! It is a false analogy! Evolution is a matter of environment and chance, acting over millions of years. But history is a matter of environment and choice, acting within lifetimes, and sometimes within years, or months, or days! History is Lamarckian!"]) - try db.execute("INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Querelle de Brest", "Jean Genet", "L’idée de mer évoque souvent l’idée de mer, de marins. Mer et marins ne se présentent pas alors avec la précision d’une image, le meurtre plutôt fait en nous l’émotion déferler par vagues."]) - try db.execute("INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Éden, Éden, Éden", "Pierre Guyotat", "/ Les soldats, casqués, jambes ouvertes, foulent, muscles retenus, les nouveau-nés emmaillotés dans les châles écarlates, violets : les bébés roulent hors des bras des femmes accroupies sur les tôles mitraillées des G. M. C. ;"]) + try db.execute(sql: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Moby Dick", "Herman Melville", "Call me Ishmael. Some years ago--never mind how long precisely--having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world."]) + try db.execute(sql: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Red Mars", "Kim Stanley Robinson", "History is not evolution! It is a false analogy! Evolution is a matter of environment and chance, acting over millions of years. But history is a matter of environment and choice, acting within lifetimes, and sometimes within years, or months, or days! History is Lamarckian!"]) + try db.execute(sql: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Querelle de Brest", "Jean Genet", "L’idée de mer évoque souvent l’idée de mer, de marins. Mer et marins ne se présentent pas alors avec la précision d’une image, le meurtre plutôt fait en nous l’émotion déferler par vagues."]) + try db.execute(sql: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Éden, Éden, Éden", "Pierre Guyotat", "/ Les soldats, casqués, jambes ouvertes, foulent, muscles retenus, les nouveau-nés emmaillotés dans les châles écarlates, violets : les bébés roulent hors des bras des femmes accroupies sur les tôles mitraillées des G. M. C. ;"]) } } @@ -52,7 +50,7 @@ class FTS3PatternTests: GRDBTestCase { ] for (rawPattern, expectedCount) in validRawPatterns { let pattern = try FTS3Pattern(rawPattern: rawPattern) - let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! + let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results") } } @@ -100,7 +98,7 @@ class FTS3PatternTests: GRDBTestCase { if let pattern = FTS3Pattern(matchingAnyTokenIn: string) { let rawPattern = String.fromDatabaseValue(pattern.databaseValue)! XCTAssertEqual(rawPattern, expectedRawPattern) - let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! + let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results") } } @@ -136,7 +134,7 @@ class FTS3PatternTests: GRDBTestCase { if let pattern = FTS3Pattern(matchingAllTokensIn: string) { let rawPattern = String.fromDatabaseValue(pattern.databaseValue)! XCTAssertEqual(rawPattern, expectedRawPattern) - let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! + let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results") } } @@ -172,7 +170,7 @@ class FTS3PatternTests: GRDBTestCase { if let pattern = FTS3Pattern(matchingPhrase: string) { let rawPattern = String.fromDatabaseValue(pattern.databaseValue)! XCTAssertEqual(rawPattern, expectedRawPattern) - let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! + let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results") } } diff --git a/Tests/GRDBTests/FTS3RecordTests.swift b/Tests/GRDBTests/FTS3RecordTests.swift index f440074f8..d27b523e6 100644 --- a/Tests/GRDBTests/FTS3RecordTests.swift +++ b/Tests/GRDBTests/FTS3RecordTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/FTS3TableBuilderTests.swift b/Tests/GRDBTests/FTS3TableBuilderTests.swift index 90f7049a6..97665379f 100644 --- a/Tests/GRDBTests/FTS3TableBuilderTests.swift +++ b/Tests/GRDBTests/FTS3TableBuilderTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -26,8 +24,8 @@ class FTS3TableBuilderTests: GRDBTestCase { try db.create(virtualTable: "documents", using: FTS3()) assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts3") - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["abc"]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["abc"]) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1) } } @@ -37,8 +35,8 @@ class FTS3TableBuilderTests: GRDBTestCase { try db.create(virtualTable: "documents", ifNotExists: true, using: FTS3()) assertDidExecute(sql: "CREATE VIRTUAL TABLE IF NOT EXISTS \"documents\" USING fts3") - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["abc"]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["abc"]) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1) } } @@ -78,7 +76,7 @@ class FTS3TableBuilderTests: GRDBTestCase { } } - func testUnicode61TokenizerRemoveDiacritics() throws { + func testUnicode61TokenizerDiacriticsKeep() throws { #if !GRDBCUSTOMSQLITE && !GRDBCIPHER guard #available(iOS 8.2, OSX 10.10, *) else { return @@ -88,12 +86,24 @@ class FTS3TableBuilderTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.create(virtualTable: "documents", using: FTS3()) { t in - t.tokenizer = .unicode61(removeDiacritics: false) + t.tokenizer = .unicode61(diacritics: .keep) } assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts3(tokenize=unicode61 \"remove_diacritics=0\")") } } + #if GRDBCUSTOMSQLITE + func testUnicode61TokenizerDiacriticsRemove() throws { + 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 { #if !GRDBCUSTOMSQLITE && !GRDBCIPHER guard #available(iOS 8.2, OSX 10.10, *) else { @@ -136,12 +146,12 @@ class FTS3TableBuilderTests: GRDBTestCase { } assertDidExecute(sql: "CREATE VIRTUAL TABLE \"books\" USING fts3(author, title, body)") - try db.execute("INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE title MATCH ?", arguments: ["Melville"])!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE author MATCH ?", arguments: ["Melville"])!, 1) + try db.execute(sql: "INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."]) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE title MATCH ?", arguments: ["Melville"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE author MATCH ?", arguments: ["Melville"])!, 1) } } } diff --git a/Tests/GRDBTests/FTS3TokenizerTests.swift b/Tests/GRDBTests/FTS3TokenizerTests.swift index 18193b254..a9adb35a1 100644 --- a/Tests/GRDBTests/FTS3TokenizerTests.swift +++ b/Tests/GRDBTests/FTS3TokenizerTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -10,11 +8,11 @@ import XCTest class FTS3TokenizerTests: GRDBTestCase { private func match(_ db: Database, _ content: String, _ query: String) -> Bool { - try! db.execute("INSERT INTO documents VALUES (?)", arguments: [content]) + try! db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: [content]) defer { - try! db.execute("DELETE FROM documents") + try! db.execute(sql: "DELETE FROM documents") } - return try! Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: [query])! > 0 + return try! Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: [query])! > 0 } func testSimpleTokenizer() throws { @@ -86,7 +84,7 @@ class FTS3TokenizerTests: GRDBTestCase { } } - func testUnicode61TokenizerRemoveDiacritics() throws { + func testUnicode61TokenizerDiacriticsKeep() throws { #if !GRDBCUSTOMSQLITE && !GRDBCIPHER guard #available(iOS 8.2, OSX 10.10, *) else { return @@ -96,7 +94,7 @@ class FTS3TokenizerTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.create(virtualTable: "documents", using: FTS3()) { t in - t.tokenizer = .unicode61(removeDiacritics: false) + t.tokenizer = .unicode61(diacritics: .keep) } // simple match @@ -112,6 +110,29 @@ class FTS3TokenizerTests: GRDBTestCase { XCTAssertTrue(match(db, "jérôme", "JÉRÔME")) } } + + #if GRDBCUSTOMSQLITE + func testUnicode61TokenizerDiacriticsRemove() throws { + 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")) + } + } + #endif func testUnicode61TokenizerSeparators() throws { #if !GRDBCUSTOMSQLITE && !GRDBCIPHER diff --git a/Tests/GRDBTests/FTS4RecordTests.swift b/Tests/GRDBTests/FTS4RecordTests.swift index 022554d6d..cdda44c5f 100644 --- a/Tests/GRDBTests/FTS4RecordTests.swift +++ b/Tests/GRDBTests/FTS4RecordTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/FTS4TableBuilderTests.swift b/Tests/GRDBTests/FTS4TableBuilderTests.swift index c2ac3fb74..4069ca0a1 100644 --- a/Tests/GRDBTests/FTS4TableBuilderTests.swift +++ b/Tests/GRDBTests/FTS4TableBuilderTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -26,8 +24,8 @@ class FTS4TableBuilderTests: GRDBTestCase { try db.create(virtualTable: "documents", using: FTS4()) assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts4") - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["abc"]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["abc"]) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1) } } @@ -37,8 +35,8 @@ class FTS4TableBuilderTests: GRDBTestCase { try db.create(virtualTable: "documents", ifNotExists: true, using: FTS4()) assertDidExecute(sql: "CREATE VIRTUAL TABLE IF NOT EXISTS \"documents\" USING fts4") - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["abc"]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["abc"]) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1) } } @@ -78,7 +76,7 @@ class FTS4TableBuilderTests: GRDBTestCase { } } - func testUnicode61TokenizerRemoveDiacritics() throws { + func testUnicode61TokenizerDiacriticsKeep() throws { #if !GRDBCUSTOMSQLITE && !GRDBCIPHER guard #available(iOS 8.2, OSX 10.10, *) else { return @@ -88,11 +86,23 @@ class FTS4TableBuilderTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.create(virtualTable: "documents", using: FTS4()) { t in - t.tokenizer = .unicode61(removeDiacritics: false) + t.tokenizer = .unicode61(diacritics: .keep) } assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts4(tokenize=unicode61 \"remove_diacritics=0\")") } } + + #if GRDBCUSTOMSQLITE + func testUnicode61TokenizerDiacriticsRemove() throws { + 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\")") + } + } + #endif func testUnicode61TokenizerSeparators() throws { #if !GRDBCUSTOMSQLITE && !GRDBCIPHER @@ -136,12 +146,12 @@ class FTS4TableBuilderTests: GRDBTestCase { } assertDidExecute(sql: "CREATE VIRTUAL TABLE \"books\" USING fts4(author, title, body)") - try db.execute("INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE title MATCH ?", arguments: ["Melville"])!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE author MATCH ?", arguments: ["Melville"])!, 1) + try db.execute(sql: "INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."]) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE title MATCH ?", arguments: ["Melville"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE author MATCH ?", arguments: ["Melville"])!, 1) } } @@ -161,17 +171,17 @@ class FTS4TableBuilderTests: GRDBTestCase { } assertDidExecute(sql: "CREATE VIRTUAL TABLE \"books\" USING fts4(author, notindexed=author, title, body, notindexed=body)") - try db.execute("INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Dick"])!, 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Dick"])!, 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE title MATCH ?", arguments: ["Dick"])!, 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Dick"])!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE author MATCH ?", arguments: ["Dick"])!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE title MATCH ?", arguments: ["Melville"])!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE author MATCH ?", arguments: ["Melville"])!, 0) + try db.execute(sql: "INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."]) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Dick"])!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Dick"])!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE title MATCH ?", arguments: ["Dick"])!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Dick"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE author MATCH ?", arguments: ["Dick"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE title MATCH ?", arguments: ["Melville"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE author MATCH ?", arguments: ["Melville"])!, 0) } } @@ -189,9 +199,9 @@ class FTS4TableBuilderTests: GRDBTestCase { } assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts4(content, languageid=\"lid\", content=\"\", compress=\"zip\", uncompress=\"unzip\", matchinfo=\"fts3\", prefix=\"2,4\")") - try db.execute("INSERT INTO documents (docid, content, lid) VALUES (?, ?, ?)", arguments: [1, "abc", 0]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ? AND lid=0", arguments: ["abc"])!, 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ? AND lid=1", arguments: ["abc"])!, 0) + try db.execute(sql: "INSERT INTO documents (docid, content, lid) VALUES (?, ?, ?)", arguments: [1, "abc", 0]) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ? AND lid=0", arguments: ["abc"])!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ? AND lid=1", arguments: ["abc"])!, 0) } } @@ -202,30 +212,30 @@ class FTS4TableBuilderTests: GRDBTestCase { t.column("id", .integer).primaryKey() t.column("content", .text) } - try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) + try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) try db.create(virtualTable: "ft_documents", using: FTS4()) { t in t.synchronize(withTable: "documents") t.column("content") } // Prepopulated - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 0) // Synchronized on update - try db.execute("UPDATE documents SET content = ?", arguments: ["bar"]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1) + try db.execute(sql: "UPDATE documents SET content = ?", arguments: ["bar"]) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1) // Synchronized on insert - try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1) + try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1) // Synchronized on delete - try db.execute("DELETE FROM documents WHERE content = ?", arguments: ["foo"]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1) + try db.execute(sql: "DELETE FROM documents WHERE content = ?", arguments: ["foo"]) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1) } } @@ -236,7 +246,7 @@ class FTS4TableBuilderTests: GRDBTestCase { t.column("id", .integer).primaryKey() t.column("content", .text) } - try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) + try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) try db.create(virtualTable: "ft_documents", using: FTS4()) { t in t.synchronize(withTable: "documents") t.column("content") @@ -246,9 +256,9 @@ class FTS4TableBuilderTests: GRDBTestCase { try db.dropFTS4SynchronizationTriggers(forTable: "ft_documents") // It is possible to modify the content table - try db.execute("UPDATE documents SET content = ?", arguments: ["bar"]) - try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) - try db.execute("DELETE FROM documents WHERE content = ?", arguments: ["foo"]) + try db.execute(sql: "UPDATE documents SET content = ?", arguments: ["bar"]) + try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) + try db.execute(sql: "DELETE FROM documents WHERE content = ?", arguments: ["foo"]) // It is possible to recreate the FT table try db.create(virtualTable: "ft_documents", using: FTS4()) { t in @@ -265,7 +275,7 @@ class FTS4TableBuilderTests: GRDBTestCase { t.column("id", .integer).primaryKey() t.column("content", .text) } - try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) + try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) try db.create(virtualTable: "ft_documents", using: FTS4()) { t in t.synchronize(withTable: "documents") t.column("content") @@ -276,9 +286,9 @@ class FTS4TableBuilderTests: GRDBTestCase { try db.dropFTS4SynchronizationTriggers(forTable: "ft_documents") // It is possible to modify the content table - try db.execute("UPDATE documents SET content = ?", arguments: ["bar"]) - try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) - try db.execute("DELETE FROM documents WHERE content = ?", arguments: ["foo"]) + try db.execute(sql: "UPDATE documents SET content = ?", arguments: ["bar"]) + try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) + try db.execute(sql: "DELETE FROM documents WHERE content = ?", arguments: ["foo"]) // It is possible to recreate the FT table try db.create(virtualTable: "ft_documents", using: FTS4()) { t in @@ -311,12 +321,12 @@ class FTS4TableBuilderTests: GRDBTestCase { } assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts4(content, compress=\"zipit\", uncompress=\"unzipit\")") - try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["abc"]) + try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["abc"]) XCTAssertTrue(compressCalled) } try dbPool.read { db in - _ = try Row.fetchOne(db, "SELECT * FROM documents") + _ = try Row.fetchOne(db, sql: "SELECT * FROM documents") XCTAssertTrue(uncompressCalled) } } diff --git a/Tests/GRDBTests/FTS5CustomTokenizerTests.swift b/Tests/GRDBTests/FTS5CustomTokenizerTests.swift index 6c8c6425a..433e41748 100644 --- a/Tests/GRDBTests/FTS5CustomTokenizerTests.swift +++ b/Tests/GRDBTests/FTS5CustomTokenizerTests.swift @@ -1,9 +1,7 @@ #if SQLITE_ENABLE_FTS5 import XCTest import Foundation -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -210,15 +208,15 @@ class FTS5CustomTokenizerTests: GRDBTestCase { t.column("content") } - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["foo bar"]) - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["foo baz"]) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["foo bar"]) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["foo baz"]) // foo is not ignored - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["foo"]), 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["foo"]), 2) // bar is ignored - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["bar"]), 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["bar"]), 0) // bar is ignored in queries too: the "foo bar baz" phrase matches the "foo baz" content - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1) } } @@ -232,24 +230,24 @@ class FTS5CustomTokenizerTests: GRDBTestCase { t.column("content") } - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["foo bar"]) - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["foo baz"]) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["foo bar"]) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["foo baz"]) // foo is not ignored - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["foo"]), 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["foo"]), 2) // bar is ignored - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["bar"]), 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["bar"]), 0) // bar is ignored in queries too: the "foo bar baz" phrase matches the "foo baz" content - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1) } try dbPool.read { db in // foo is not ignored - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["foo"]), 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["foo"]), 2) // bar is ignored - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["bar"]), 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["bar"]), 0) // bar is ignored in queries too: the "foo bar baz" phrase matches the "foo baz" content - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1) } } @@ -264,12 +262,12 @@ class FTS5CustomTokenizerTests: GRDBTestCase { t.column("content") } - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["aimé\u{FB01}"]) // U+FB01: LATIN SMALL LIGATURE FI + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["aimé\u{FB01}"]) // U+FB01: LATIN SMALL LIGATURE FI - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimé\u{FB01}"]), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimefi"]), 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aim\u{00E9}fi"]), 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime\u{0301}\u{FB01}"]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimé\u{FB01}"]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimefi"]), 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aim\u{00E9}fi"]), 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime\u{0301}\u{FB01}"]), 1) try db.drop(table: "documents") } @@ -281,12 +279,12 @@ class FTS5CustomTokenizerTests: GRDBTestCase { t.column("content") } - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["aimé\u{FB01}"]) // U+FB01: LATIN SMALL LIGATURE FI + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["aimé\u{FB01}"]) // U+FB01: LATIN SMALL LIGATURE FI - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimé\u{FB01}"]), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimefi"]), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aim\u{00E9}fi"]), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime\u{0301}\u{FB01}"]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimé\u{FB01}"]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimefi"]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aim\u{00E9}fi"]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime\u{0301}\u{FB01}"]), 1) try db.drop(table: "documents") } @@ -299,12 +297,12 @@ class FTS5CustomTokenizerTests: GRDBTestCase { t.column("content") } - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["aimé\u{FB01}"]) // U+FB01: LATIN SMALL LIGATURE FI + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["aimé\u{FB01}"]) // U+FB01: LATIN SMALL LIGATURE FI - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimé\u{FB01}"]), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimefi"]), 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aim\u{00E9}fi"]), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime\u{0301}\u{FB01}"]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimé\u{FB01}"]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimefi"]), 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aim\u{00E9}fi"]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime\u{0301}\u{FB01}"]), 1) try db.drop(table: "documents") } @@ -320,17 +318,17 @@ class FTS5CustomTokenizerTests: GRDBTestCase { t.column("content") } - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["first foo"]) - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["1st bar"]) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["first foo"]) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["1st bar"]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["first"]), 2) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["1st"]), 2) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"first foo\""]), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"1st foo\""]), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"first bar\""]), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"1st bar\""]), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["fi*"]), 2) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["1s*"]), 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["first"]), 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["1st"]), 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"first foo\""]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"1st foo\""]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"first bar\""]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"1st bar\""]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["fi*"]), 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["1s*"]), 2) } } } diff --git a/Tests/GRDBTests/FTS5PatternTests.swift b/Tests/GRDBTests/FTS5PatternTests.swift index f3f7265e4..9d51de329 100644 --- a/Tests/GRDBTests/FTS5PatternTests.swift +++ b/Tests/GRDBTests/FTS5PatternTests.swift @@ -1,8 +1,6 @@ #if SQLITE_ENABLE_FTS5 import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -17,10 +15,10 @@ class FTS5PatternTests: GRDBTestCase { t.column("author") t.column("body") } - try db.execute("INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Moby-Dick", "Herman Melville", "Call me Ishmael. Some years ago--never mind how long precisely--having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world."]) - try db.execute("INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Red Mars", "Kim Stanley Robinson", "History is not evolution! It is a false analogy! Evolution is a matter of environment and chance, acting over millions of years. But history is a matter of environment and choice, acting within lifetimes, and sometimes within years, or months, or days! History is Lamarckian!"]) - try db.execute("INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Querelle de Brest", "Jean Genet", "L’idée de mer évoque souvent l’idée de mer, de marins. Mer et marins ne se présentent pas alors avec la précision d’une image, le meurtre plutôt fait en nous l’émotion déferler par vagues."]) - try db.execute("INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Éden, Éden, Éden", "Pierre Guyotat", "/ Les soldats, casqués, jambes ouvertes, foulent, muscles retenus, les nouveau-nés emmaillotés dans les châles écarlates, violets : les bébés roulent hors des bras des femmes accroupies sur les tôles mitraillées des G. M. C. ;"]) + try db.execute(sql: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Moby-Dick", "Herman Melville", "Call me Ishmael. Some years ago--never mind how long precisely--having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world."]) + try db.execute(sql: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Red Mars", "Kim Stanley Robinson", "History is not evolution! It is a false analogy! Evolution is a matter of environment and chance, acting over millions of years. But history is a matter of environment and choice, acting within lifetimes, and sometimes within years, or months, or days! History is Lamarckian!"]) + try db.execute(sql: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Querelle de Brest", "Jean Genet", "L’idée de mer évoque souvent l’idée de mer, de marins. Mer et marins ne se présentent pas alors avec la précision d’une image, le meurtre plutôt fait en nous l’émotion déferler par vagues."]) + try db.execute(sql: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Éden, Éden, Éden", "Pierre Guyotat", "/ Les soldats, casqués, jambes ouvertes, foulent, muscles retenus, les nouveau-nés emmaillotés dans les châles écarlates, violets : les bébés roulent hors des bras des femmes accroupies sur les tôles mitraillées des G. M. C. ;"]) } } @@ -50,7 +48,7 @@ class FTS5PatternTests: GRDBTestCase { ] for (rawPattern, expectedCount) in validRawPatterns { let pattern = try db.makeFTS5Pattern(rawPattern: rawPattern, forTable: "books") - let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! + let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results") } } @@ -95,7 +93,7 @@ class FTS5PatternTests: GRDBTestCase { if let pattern = FTS5Pattern(matchingAnyTokenIn: string) { let rawPattern = String.fromDatabaseValue(pattern.databaseValue)! XCTAssertEqual(rawPattern, expectedRawPattern) - let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! + let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results") } } @@ -125,7 +123,7 @@ class FTS5PatternTests: GRDBTestCase { if let pattern = FTS5Pattern(matchingAllTokensIn: string) { let rawPattern = String.fromDatabaseValue(pattern.databaseValue)! XCTAssertEqual(rawPattern, expectedRawPattern) - let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! + let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results") } } @@ -155,7 +153,7 @@ class FTS5PatternTests: GRDBTestCase { if let pattern = FTS5Pattern(matchingPhrase: string) { let rawPattern = String.fromDatabaseValue(pattern.databaseValue)! XCTAssertEqual(rawPattern, expectedRawPattern) - let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! + let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results") } } @@ -187,7 +185,7 @@ class FTS5PatternTests: GRDBTestCase { if let pattern = FTS5Pattern(matchingPrefixPhrase: string) { let rawPattern = String.fromDatabaseValue(pattern.databaseValue)! XCTAssertEqual(rawPattern, expectedRawPattern) - let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! + let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results") } } diff --git a/Tests/GRDBTests/FTS5RecordTests.swift b/Tests/GRDBTests/FTS5RecordTests.swift index 0d645db56..0c2b24848 100644 --- a/Tests/GRDBTests/FTS5RecordTests.swift +++ b/Tests/GRDBTests/FTS5RecordTests.swift @@ -1,8 +1,6 @@ #if SQLITE_ENABLE_FTS5 import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/FTS5TableBuilderTests.swift b/Tests/GRDBTests/FTS5TableBuilderTests.swift index c18eea07d..3106ef2ff 100644 --- a/Tests/GRDBTests/FTS5TableBuilderTests.swift +++ b/Tests/GRDBTests/FTS5TableBuilderTests.swift @@ -1,8 +1,6 @@ #if SQLITE_ENABLE_FTS5 import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -29,8 +27,8 @@ class FTS5TableBuilderTests: GRDBTestCase { } assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts5(content)") - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["abc"]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["abc"]) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1) } } @@ -42,8 +40,8 @@ class FTS5TableBuilderTests: GRDBTestCase { } assertDidExecute(sql: "CREATE VIRTUAL TABLE IF NOT EXISTS \"documents\" USING fts5(content)") - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["abc"]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["abc"]) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1) } } @@ -102,17 +100,30 @@ class FTS5TableBuilderTests: GRDBTestCase { } } - func testUnicode61TokenizerRemoveDiacritics() throws { + func testUnicode61TokenizerDiacriticsKeep() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.create(virtualTable: "documents", using: FTS5()) { t in - t.tokenizer = .unicode61(removeDiacritics: false) + t.tokenizer = .unicode61(diacritics: .keep) t.column("content") } assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts5(content, tokenize='unicode61 remove_diacritics 0')") } } + #if GRDBCUSTOMSQLITE + func testUnicode61TokenizerDiacriticsRemove() throws { + 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 { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in @@ -145,10 +156,10 @@ class FTS5TableBuilderTests: GRDBTestCase { } assertDidExecute(sql: "CREATE VIRTUAL TABLE \"books\" USING fts5(author, title, body)") - try db.execute("INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 1) + try db.execute(sql: "INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."]) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 1) } } @@ -162,13 +173,13 @@ class FTS5TableBuilderTests: GRDBTestCase { } assertDidExecute(sql: "CREATE VIRTUAL TABLE \"books\" USING fts5(author UNINDEXED, title, body UNINDEXED)") - try db.execute("INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Dick"])!, 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Dick"])!, 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Dick"])!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 0) + try db.execute(sql: "INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."]) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Dick"])!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Dick"])!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Dick"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 0) } } @@ -193,30 +204,30 @@ class FTS5TableBuilderTests: GRDBTestCase { t.column("id", .integer).primaryKey() t.column("content", .text) } - try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) + try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) try db.create(virtualTable: "ft_documents", using: FTS5()) { t in t.synchronize(withTable: "documents") t.column("content") } // Prepopulated - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 0) // Synchronized on update - try db.execute("UPDATE documents SET content = ?", arguments: ["bar"]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1) + try db.execute(sql: "UPDATE documents SET content = ?", arguments: ["bar"]) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1) // Synchronized on insert - try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1) + try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1) // Synchronized on delete - try db.execute("DELETE FROM documents WHERE content = ?", arguments: ["foo"]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1) + try db.execute(sql: "DELETE FROM documents WHERE content = ?", arguments: ["foo"]) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1) } } @@ -227,7 +238,7 @@ class FTS5TableBuilderTests: GRDBTestCase { t.column("id", .integer).primaryKey() t.column("content", .text) } - try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) + try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) try db.create(virtualTable: "ft_documents", using: FTS5()) { t in t.synchronize(withTable: "documents") t.column("content") @@ -237,9 +248,9 @@ class FTS5TableBuilderTests: GRDBTestCase { try db.dropFTS5SynchronizationTriggers(forTable: "ft_documents") // It is possible to modify the content table - try db.execute("UPDATE documents SET content = ?", arguments: ["bar"]) - try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) - try db.execute("DELETE FROM documents WHERE content = ?", arguments: ["foo"]) + try db.execute(sql: "UPDATE documents SET content = ?", arguments: ["bar"]) + try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) + try db.execute(sql: "DELETE FROM documents WHERE content = ?", arguments: ["foo"]) // It is possible to recreate the FT table try db.create(virtualTable: "ft_documents", using: FTS5()) { t in @@ -256,7 +267,7 @@ class FTS5TableBuilderTests: GRDBTestCase { t.column("id", .integer).primaryKey() t.column("content", .text) } - try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) + try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) try db.create(virtualTable: "ft_documents", using: FTS5()) { t in t.synchronize(withTable: "documents") t.column("content") @@ -267,9 +278,9 @@ class FTS5TableBuilderTests: GRDBTestCase { try db.dropFTS5SynchronizationTriggers(forTable: "ft_documents") // It is possible to modify the content table - try db.execute("UPDATE documents SET content = ?", arguments: ["bar"]) - try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) - try db.execute("DELETE FROM documents WHERE content = ?", arguments: ["foo"]) + try db.execute(sql: "UPDATE documents SET content = ?", arguments: ["bar"]) + try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"]) + try db.execute(sql: "DELETE FROM documents WHERE content = ?", arguments: ["foo"]) // It is possible to recreate the FT table try db.create(virtualTable: "ft_documents", using: FTS5()) { t in diff --git a/Tests/GRDBTests/FTS5TokenizerTests.swift b/Tests/GRDBTests/FTS5TokenizerTests.swift index 38ca58e03..9664c4bfa 100644 --- a/Tests/GRDBTests/FTS5TokenizerTests.swift +++ b/Tests/GRDBTests/FTS5TokenizerTests.swift @@ -1,8 +1,6 @@ #if SQLITE_ENABLE_FTS5 import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -11,11 +9,11 @@ import XCTest class FTS5TokenizerTests: GRDBTestCase { private func match(_ db: Database, _ content: String, _ query: String) -> Bool { - try! db.execute("INSERT INTO documents VALUES (?)", arguments: [content]) + try! db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: [content]) defer { - try! db.execute("DELETE FROM documents") + try! db.execute(sql: "DELETE FROM documents") } - return try! Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: [query])! > 0 + return try! Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: [query])! > 0 } func testAsciiTokenizer() throws { @@ -128,11 +126,11 @@ class FTS5TokenizerTests: GRDBTestCase { } } - func testUnicode61TokenizerRemoveDiacritics() throws { + func testUnicode61TokenizerDiacriticsKeep() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.create(virtualTable: "documents", using: FTS5()) { t in - t.tokenizer = .unicode61(removeDiacritics: false) + t.tokenizer = .unicode61(diacritics: .keep) t.column("content") } @@ -149,6 +147,30 @@ class FTS5TokenizerTests: GRDBTestCase { XCTAssertTrue(match(db, "jérôme", "JÉRÔME")) } } + + #if GRDBCUSTOMSQLITE + func testUnicode61TokenizerDiacriticsRemove() throws { + 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") + } + + // 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")) + } + } + #endif func testUnicode61TokenizerSeparators() throws { let dbQueue = try makeDatabaseQueue() diff --git a/Tests/GRDBTests/FTS5WrapperTokenizerTests.swift b/Tests/GRDBTests/FTS5WrapperTokenizerTests.swift index 5a6b56d1c..6d4e329f2 100644 --- a/Tests/GRDBTests/FTS5WrapperTokenizerTests.swift +++ b/Tests/GRDBTests/FTS5WrapperTokenizerTests.swift @@ -1,9 +1,7 @@ #if SQLITE_ENABLE_FTS5 import XCTest import Foundation -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -112,15 +110,15 @@ class FTS5WrapperTokenizerTests: GRDBTestCase { t.column("content") } - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["foo bar"]) - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["foo baz"]) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["foo bar"]) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["foo baz"]) // foo is not ignored - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["foo"]), 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["foo"]), 2) // bar is ignored - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["bar"]), 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["bar"]), 0) // bar is ignored in queries too: the "foo bar baz" phrase matches the "foo baz" content - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1) } } @@ -134,24 +132,24 @@ class FTS5WrapperTokenizerTests: GRDBTestCase { t.column("content") } - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["foo bar"]) - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["foo baz"]) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["foo bar"]) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["foo baz"]) // foo is not ignored - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["foo"]), 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["foo"]), 2) // bar is ignored - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["bar"]), 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["bar"]), 0) // bar is ignored in queries too: the "foo bar baz" phrase matches the "foo baz" content - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1) } try dbPool.read { db in // foo is not ignored - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["foo"]), 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["foo"]), 2) // bar is ignored - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["bar"]), 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["bar"]), 0) // bar is ignored in queries too: the "foo bar baz" phrase matches the "foo baz" content - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1) } } @@ -166,11 +164,11 @@ class FTS5WrapperTokenizerTests: GRDBTestCase { t.column("content") } - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["aimé \u{FB01}délité Encyclopædia Großmann Diyarbakır"]) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["aimé \u{FB01}délité Encyclopædia Großmann Diyarbakır"]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimé \u{FB01}délité Encyclopædia Großmann Diyarbakır"]), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime fidelite encyclopaedia grossmann diyarbakir"]), 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime\u{0301} \u{FB01}de\u{0301}lite\u{0301} Encyclopædia Großmann Diyarbakır"]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimé \u{FB01}délité Encyclopædia Großmann Diyarbakır"]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime fidelite encyclopaedia grossmann diyarbakir"]), 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime\u{0301} \u{FB01}de\u{0301}lite\u{0301} Encyclopædia Großmann Diyarbakır"]), 1) try db.drop(table: "documents") } @@ -182,11 +180,11 @@ class FTS5WrapperTokenizerTests: GRDBTestCase { t.column("content") } - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["aimé \u{FB01}délité Encyclopædia Großmann Diyarbakır"]) // U+FB01: LATIN SMALL LIGATURE FI + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["aimé \u{FB01}délité Encyclopædia Großmann Diyarbakır"]) // U+FB01: LATIN SMALL LIGATURE FI - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimé \u{FB01}délité Encyclopædia Großmann Diyarbakır"]), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime fidelite encyclopaedia grossmann diyarbakir"]), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime\u{0301} \u{FB01}de\u{0301}lite\u{0301} Encyclopædia Großmann Diyarbakır"]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimé \u{FB01}délité Encyclopædia Großmann Diyarbakır"]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime fidelite encyclopaedia grossmann diyarbakir"]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime\u{0301} \u{FB01}de\u{0301}lite\u{0301} Encyclopædia Großmann Diyarbakır"]), 1) try db.drop(table: "documents") } @@ -202,17 +200,17 @@ class FTS5WrapperTokenizerTests: GRDBTestCase { t.column("content") } - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["first foo"]) - try db.execute("INSERT INTO documents VALUES (?)", arguments: ["1st bar"]) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["first foo"]) + try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["1st bar"]) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["first"]), 2) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["1st"]), 2) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"first foo\""]), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"1st foo\""]), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"first bar\""]), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"1st bar\""]), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["fi*"]), 2) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["1s*"]), 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["first"]), 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["1st"]), 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"first foo\""]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"1st foo\""]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"first bar\""]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"1st bar\""]), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["fi*"]), 2) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["1s*"]), 2) } } } diff --git a/Tests/GRDBTests/FetchRequestTests.swift b/Tests/GRDBTests/FetchRequestTests.swift index 6ba92882a..e0dfb6f7f 100644 --- a/Tests/GRDBTests/FetchRequestTests.swift +++ b/Tests/GRDBTests/FetchRequestTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,8 +10,8 @@ class FetchRequestTests: GRDBTestCase { func testRequestFetchRows() throws { struct CustomRequest : FetchRequest { typealias RowDecoder = Row - func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) { - return try (db.makeSelectStatement("SELECT * FROM table1"), nil) + func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) { + return try (db.makeSelectStatement(sql: "SELECT * FROM table1"), nil) } } @@ -22,8 +20,8 @@ class FetchRequestTests: GRDBTestCase { try db.create(table: "table1") { t in t.column("id", .integer).primaryKey() } - try db.execute("INSERT INTO table1 DEFAULT VALUES") - try db.execute("INSERT INTO table1 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO table1 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO table1 DEFAULT VALUES") let request = CustomRequest() let rows = try request.fetchAll(db) @@ -37,8 +35,8 @@ class FetchRequestTests: GRDBTestCase { func testRequestFetchValues() throws { struct CustomRequest : FetchRequest { typealias RowDecoder = Int - func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) { - return try (db.makeSelectStatement("SELECT id FROM table1"), nil) + func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) { + return try (db.makeSelectStatement(sql: "SELECT id FROM table1"), nil) } } @@ -47,8 +45,8 @@ class FetchRequestTests: GRDBTestCase { try db.create(table: "table1") { t in t.column("id", .integer).primaryKey() } - try db.execute("INSERT INTO table1 DEFAULT VALUES") - try db.execute("INSERT INTO table1 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO table1 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO table1 DEFAULT VALUES") let request = CustomRequest() let ints = try request.fetchAll(db) @@ -65,8 +63,8 @@ class FetchRequestTests: GRDBTestCase { } struct CustomRequest : FetchRequest { typealias RowDecoder = CustomRecord - func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) { - return try (db.makeSelectStatement("SELECT id FROM table1"), nil) + func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) { + return try (db.makeSelectStatement(sql: "SELECT id FROM table1"), nil) } } @@ -75,8 +73,8 @@ class FetchRequestTests: GRDBTestCase { try db.create(table: "table1") { t in t.column("id", .integer).primaryKey() } - try db.execute("INSERT INTO table1 DEFAULT VALUES") - try db.execute("INSERT INTO table1 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO table1 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO table1 DEFAULT VALUES") let request = CustomRequest() let records = try request.fetchAll(db) @@ -90,8 +88,8 @@ class FetchRequestTests: GRDBTestCase { func testRequestFetchCount() throws { struct CustomRequest : FetchRequest { typealias RowDecoder = Row - func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) { - return try (db.makeSelectStatement("SELECT * FROM table1"), nil) + func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) { + return try (db.makeSelectStatement(sql: "SELECT * FROM table1"), nil) } } @@ -100,8 +98,8 @@ class FetchRequestTests: GRDBTestCase { try db.create(table: "table1") { t in t.column("id", .integer).primaryKey() } - try db.execute("INSERT INTO table1 DEFAULT VALUES") - try db.execute("INSERT INTO table1 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO table1 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO table1 DEFAULT VALUES") let request = CustomRequest() let count = try request.fetchCount(db) @@ -113,8 +111,8 @@ class FetchRequestTests: GRDBTestCase { func testRequestCustomizedFetchCount() throws { struct CustomRequest : FetchRequest { typealias RowDecoder = Row - func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) { - return try (db.makeSelectStatement("INVALID"), nil) + func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) { + return try (db.makeSelectStatement(sql: "INVALID"), nil) } func fetchCount(_ db: Database) throws -> Int { @@ -127,8 +125,8 @@ class FetchRequestTests: GRDBTestCase { try db.create(table: "table1") { t in t.column("id", .integer).primaryKey() } - try db.execute("INSERT INTO table1 DEFAULT VALUES") - try db.execute("INSERT INTO table1 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO table1 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO table1 DEFAULT VALUES") let request = CustomRequest() let count = try request.fetchCount(db) @@ -136,4 +134,244 @@ class FetchRequestTests: GRDBTestCase { XCTAssertEqual(count, 2) } } + + // Test for the `singleResult` parameter of + // FetchRequest.prepare(_:singleResult:) + func testSingleResultHint() throws { + struct CustomRequest: FetchRequest { + typealias RowDecoder = T + func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) { + if singleResult { + return try (db.makeSelectStatement(sql: "SELECT 'single' AS hint"), nil) + } else { + return try (db.makeSelectStatement(sql: "SELECT 'multiple' AS hint"), nil) + } + } + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + // Row + do { + do { + let request = CustomRequest() + do { + let rows = try request.fetchAll(db) + XCTAssertEqual(rows.count, 1) + XCTAssertEqual(rows[0], ["hint": "multiple"]) + } + do { + let rows = try request.fetchCursor(db) + while let row = try rows.next() { + XCTAssertEqual(row, ["hint": "multiple"]) + } + } + do { + let row = try request.fetchOne(db)! + XCTAssertEqual(row, ["hint": "single"]) + } + } + do { + let request = CustomRequest() + do { + let rows = try Row.fetchAll(db, request) + XCTAssertEqual(rows.count, 1) + XCTAssertEqual(rows[0], ["hint": "multiple"]) + } + do { + let rows = try Row.fetchCursor(db, request) + while let row = try rows.next() { + XCTAssertEqual(row, ["hint": "multiple"]) + } + } + do { + let row = try Row.fetchOne(db, request)! + XCTAssertEqual(row, ["hint": "single"]) + } + } + } + + // DatabaseValueConvertible + do { + struct Value: DatabaseValueConvertible { + var string: String + var databaseValue: DatabaseValue { return string.databaseValue } + static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Value? { + return String.fromDatabaseValue(dbValue).map(Value.init) + } + } + do { + let request = CustomRequest() + do { + let values = try request.fetchAll(db) + XCTAssertEqual(values.count, 1) + XCTAssertEqual(values[0].string, "multiple") + } + do { + let values = try request.fetchCursor(db) + while let value = try values.next() { + XCTAssertEqual(value.string, "multiple") + } + } + do { + let value = try request.fetchOne(db)! + XCTAssertEqual(value.string, "single") + } + } + do { + let request = CustomRequest() + do { + let values = try Value.fetchAll(db, request) + XCTAssertEqual(values.count, 1) + XCTAssertEqual(values[0].string, "multiple") + } + do { + let values = try Value.fetchCursor(db, request) + while let value = try values.next() { + XCTAssertEqual(value.string, "multiple") + } + } + do { + let value = try Value.fetchOne(db, request)! + XCTAssertEqual(value.string, "single") + } + } + } + + // DatabaseValueConvertible + StatementColumnConvertible + do { + struct Value: DatabaseValueConvertible, StatementColumnConvertible { + var string: String + init(string: String) { + self.string = string + } + init(sqliteStatement: SQLiteStatement, index: Int32) { + self.init(string: String(sqliteStatement: sqliteStatement, index: index)) + } + var databaseValue: DatabaseValue { return string.databaseValue } + static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Value? { + return String.fromDatabaseValue(dbValue).map { Value(string: $0) } + } + } + do { + let request = CustomRequest() + do { + let values = try request.fetchAll(db) + XCTAssertEqual(values.count, 1) + XCTAssertEqual(values[0].string, "multiple") + } + do { + let values = try request.fetchCursor(db) + while let value = try values.next() { + XCTAssertEqual(value.string, "multiple") + } + } + do { + let value = try request.fetchOne(db)! + XCTAssertEqual(value.string, "single") + } + } + do { + let request = CustomRequest() + do { + let values = try Value.fetchAll(db, request) + XCTAssertEqual(values.count, 1) + XCTAssertEqual(values[0].string, "multiple") + } + do { + let values = try Value.fetchCursor(db, request) + while let value = try values.next() { + XCTAssertEqual(value.string, "multiple") + } + } + do { + let value = try Value.fetchOne(db, request)! + XCTAssertEqual(value.string, "single") + } + } + } + + // FetchableRecord + do { + struct Record: FetchableRecord { + var string: String + init(row: Row) { + string = row[0] + } + } + do { + let request = CustomRequest() + do { + let records = try request.fetchAll(db) + XCTAssertEqual(records.count, 1) + XCTAssertEqual(records[0].string, "multiple") + } + do { + let records = try request.fetchCursor(db) + while let record = try records.next() { + XCTAssertEqual(record.string, "multiple") + } + } + do { + let record = try request.fetchOne(db)! + XCTAssertEqual(record.string, "single") + } + } + do { + let request = CustomRequest() + do { + let records = try Record.fetchAll(db, request) + XCTAssertEqual(records.count, 1) + XCTAssertEqual(records[0].string, "multiple") + } + do { + let records = try Record.fetchCursor(db, request) + while let record = try records.next() { + XCTAssertEqual(record.string, "multiple") + } + } + do { + let record = try Record.fetchOne(db, request)! + XCTAssertEqual(record.string, "single") + } + } + } + } + } + + func testSingleResultHintIsNotUsedForDefaultFetchCount() throws { + struct CustomRequest: FetchRequest { + typealias RowDecoder = Void + func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) { + if singleResult { fatalError("not implemented") } + return try (db.makeSelectStatement(sql: "SELECT 'multiple'"), nil) + } + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + let request = CustomRequest() + _ = try request.fetchCount(db) + XCTAssertEqual(lastSQLQuery, "SELECT COUNT(*) FROM (SELECT 'multiple')") + } + } + + func testSingleResultHintIsNotUsedForDefaultDatabaseRegion() throws { + struct CustomRequest: FetchRequest { + typealias RowDecoder = Void + func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) { + if singleResult { fatalError("not implemented") } + return try (db.makeSelectStatement(sql: "SELECT * FROM multiple"), nil) + } + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.execute(sql: "CREATE TABLE multiple(a)") + + let request = CustomRequest() + let region = try request.databaseRegion(db) + XCTAssertEqual(region.description, "multiple(a)") + } + } } diff --git a/Tests/GRDBTests/FetchableRecord+QueryInterfaceRequestTests.swift b/Tests/GRDBTests/FetchableRecord+QueryInterfaceRequestTests.swift index 6eb9671fa..16d33c1fe 100644 --- a/Tests/GRDBTests/FetchableRecord+QueryInterfaceRequestTests.swift +++ b/Tests/GRDBTests/FetchableRecord+QueryInterfaceRequestTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -55,7 +53,7 @@ class FetchableRecordQueryInterfaceRequestTests: GRDBTestCase { override func setup(_ dbWriter: DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("createReaders") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE readers ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, @@ -92,7 +90,7 @@ class FetchableRecordQueryInterfaceRequestTests: GRDBTestCase { do { let reader = try request.fetchOne(db)! - XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\"") + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\" LIMIT 1") XCTAssertEqual(reader.id!, arthur.id!) XCTAssertEqual(reader.name, arthur.name) XCTAssertEqual(reader.age, arthur.age) @@ -100,10 +98,12 @@ class FetchableRecordQueryInterfaceRequestTests: GRDBTestCase { do { let names = try request.fetchCursor(db).map { $0.name } - XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\"") XCTAssertEqual(try names.next()!, arthur.name) XCTAssertEqual(try names.next()!, barbara.name) XCTAssertTrue(try names.next() == nil) + + // validate query *after* cursor has retrieved a record + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\"") } } } @@ -130,7 +130,7 @@ class FetchableRecordQueryInterfaceRequestTests: GRDBTestCase { do { let reader = try Reader.fetchOne(db)! - XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\"") + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\" LIMIT 1") XCTAssertEqual(reader.id!, arthur.id!) XCTAssertEqual(reader.name, arthur.name) XCTAssertEqual(reader.age, arthur.age) @@ -139,10 +139,20 @@ class FetchableRecordQueryInterfaceRequestTests: GRDBTestCase { do { let cursor = try Reader.fetchCursor(db) let names = cursor.map { $0.name } - XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\"") XCTAssertEqual(try names.next()!, arthur.name) XCTAssertEqual(try names.next()!, barbara.name) XCTAssertTrue(try names.next() == nil) + + // validate query *after* cursor has retrieved a record + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\"") + } + + do { + let reader = try Reader.limit(1, offset: 1).fetchOne(db)! + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\" LIMIT 1 OFFSET 1") + XCTAssertEqual(reader.id!, barbara.id!) + XCTAssertEqual(reader.name, barbara.name) + XCTAssertEqual(reader.age, barbara.age) } } } @@ -171,7 +181,7 @@ class FetchableRecordQueryInterfaceRequestTests: GRDBTestCase { do { let reader = try AltReader.fetchOne(db, request)! - XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\"") + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\" LIMIT 1") XCTAssertEqual(reader.id!, arthur.id!) XCTAssertEqual(reader.name, arthur.name) XCTAssertEqual(reader.age, arthur.age) @@ -179,10 +189,12 @@ class FetchableRecordQueryInterfaceRequestTests: GRDBTestCase { do { let names = try AltReader.fetchCursor(db, request).map { $0.name } - XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\"") XCTAssertEqual(try names.next()!, arthur.name) XCTAssertEqual(try names.next()!, barbara.name) XCTAssertTrue(try names.next() == nil) + + // validate query *after* cursor has retrieved a record + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\"") } } } diff --git a/Tests/GRDBTests/FetchableRecordDecodableTests.swift b/Tests/GRDBTests/FetchableRecordDecodableTests.swift index 1722d5eb4..66cf3bb10 100644 --- a/Tests/GRDBTests/FetchableRecordDecodableTests.swift +++ b/Tests/GRDBTests/FetchableRecordDecodableTests.swift @@ -1,8 +1,6 @@ import Foundation import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -620,7 +618,7 @@ extension FetchableRecordDecodableTests { try dbQueue.read { db in // ... with an array of detached rows: - let array = try Row.fetchAll(db, "SELECT * FROM t1") + let array = try Row.fetchAll(db, sql: "SELECT * FROM t1") for row in array { let data1: Data? = row["name"] XCTAssertEqual(jsonAsData, data1) @@ -651,7 +649,7 @@ extension FetchableRecordDecodableTests { try dbQueue.read { db in // ... with an array of detached rows: - let array = try Row.fetchAll(db, "SELECT * FROM t1") + let array = try Row.fetchAll(db, sql: "SELECT * FROM t1") for row in array { let string: String? = row["name"] XCTAssertEqual(jsonAsString, string) @@ -680,7 +678,7 @@ extension FetchableRecordDecodableTests { try dbQueue.read { db in // Compare cursor of low-level rows: - let cursor = try Row.fetchCursor(db, "SELECT * FROM t1") + let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM t1") while let row = try cursor.next() { let data1: Data? = row["name"] XCTAssertEqual(jsonAsData, data1) @@ -710,7 +708,7 @@ extension FetchableRecordDecodableTests { try dbQueue.read { db in // Compare cursor of low-level rows: - let cursor = try Row.fetchCursor(db, "SELECT * FROM t1") + let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM t1") while let row = try cursor.next() { let string: String? = row["name"] XCTAssertEqual(jsonAsString, string) @@ -729,7 +727,7 @@ extension FetchableRecordDecodableTests { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let data = "foo".data(using: .utf8)! - let record = try Record.fetchOne(db, "SELECT ? AS data, ? AS optionalData, ? AS datas, ? AS optionalDatas", arguments: [ + let record = try Record.fetchOne(db, sql: "SELECT ? AS data, ? AS optionalData, ? AS datas, ? AS optionalDatas", arguments: [ data, data, "[\"Zm9v\"]", @@ -755,7 +753,7 @@ extension FetchableRecordDecodableTests { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let record = try Record.fetchOne(db, "SELECT ? AS date, ? AS optionalDate, ? AS dates, ? AS optionalDates", arguments: [ + let record = try Record.fetchOne(db, sql: "SELECT ? AS date, ? AS optionalDate, ? AS dates, ? AS optionalDates", arguments: [ "1970-01-01 00:02:08.000", "1970-01-01 00:02:08.000", "[128000]", @@ -942,7 +940,7 @@ extension FetchableRecordDecodableTests { let adapter = SuffixRowAdapter(fromIndex: 1).addingScopes(["nestedKeyed": RangeRowAdapter(0..<1)]) let request = SQLRequest( - "SELECT ? AS name, ? AS nestedSingle, ? AS nestedUnkeyed", + sql: "SELECT ? AS name, ? AS nestedSingle, ? AS nestedUnkeyed", arguments: ["foo", "bar", "[\"baz\"]"], adapter: adapter) @@ -978,7 +976,7 @@ extension FetchableRecordDecodableTests { } let request = SQLRequest( - "SELECT ? AS nestedKeyed, ? AS nestedSingle, ? AS nestedUnkeyed", + sql: "SELECT ? AS nestedKeyed, ? AS nestedSingle, ? AS nestedUnkeyed", arguments: ["{\"name\":\"foo\"}", "bar", "[\"baz\"]"]) let record = try Record.fetchOne(db, request)! @@ -1014,7 +1012,7 @@ extension FetchableRecordDecodableTests { let adapter = SuffixRowAdapter(fromIndex: 1).addingScopes(["nestedKeyed": RangeRowAdapter(0..<1)]) let request = SQLRequest( - "SELECT ? AS name, ? AS nestedSingle, ? AS nestedUnkeyed", + sql: "SELECT ? AS name, ? AS nestedSingle, ? AS nestedUnkeyed", arguments: ["foo", "bar", "[\"baz\"]"], adapter: adapter) @@ -1050,7 +1048,7 @@ extension FetchableRecordDecodableTests { } let request = SQLRequest( - "SELECT ? AS nestedKeyed, ? AS nestedSingle, ? AS nestedUnkeyed", + sql: "SELECT ? AS nestedKeyed, ? AS nestedSingle, ? AS nestedUnkeyed", arguments: ["{\"name\":\"foo\"}", "bar", "[\"baz\"]"]) let record = try CustomizedRecord.fetchOne(db, request)! diff --git a/Tests/GRDBTests/FetchableRecordTests.swift b/Tests/GRDBTests/FetchableRecordTests.swift index a928b9ef4..93f84b81d 100644 --- a/Tests/GRDBTests/FetchableRecordTests.swift +++ b/Tests/GRDBTests/FetchableRecordTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -42,24 +40,39 @@ class FetchableRecordTests: GRDBTestCase { } do { let sql = "SELECT 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 'Barbara', 'Gourde'" - let statement = try db.makeSelectStatement(sql) - try test(Fetched.fetchCursor(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Fetched.fetchCursor(db, sql: sql)) try test(Fetched.fetchCursor(statement)) - try test(Fetched.fetchCursor(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchCursor(db)) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchCursor(db)) } do { let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 0, 'Barbara', 'Gourde'" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchCursor(db, sql, adapter: adapter)) + try test(Fetched.fetchCursor(db, sql: sql, adapter: adapter)) try test(Fetched.fetchCursor(statement, adapter: adapter)) - try test(Fetched.fetchCursor(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchCursor(db)) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db)) } } } - + + #if swift(>=5.0) + func testFetchCursorWithInterpolation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request: SQLRequest = """ + SELECT \("Arthur") AS firstName, \("O'Brien") AS lastName + """ + let cursor = try request.fetchCursor(db) + let fetched = try cursor.next()! + XCTAssertEqual(fetched.firstName, "Arthur") + XCTAssertEqual(fetched.lastName, "O'Brien") + } + } + #endif + func testFetchCursorStepFailure() throws { let dbQueue = try makeDatabaseQueue() let customError = NSError(domain: "Custom", code: 0xDEAD) @@ -78,27 +91,25 @@ class FetchableRecordTests: GRDBTestCase { do { _ = try cursor.next() XCTFail() - } catch let error as DatabaseError { - XCTAssertEqual(error.resultCode, .SQLITE_MISUSE) - XCTAssertEqual(error.message, "\(customError)") - XCTAssertEqual(error.sql!, sql) - XCTAssertEqual(error.description, "SQLite error 21 with statement `\(sql)`: \(customError)") + } catch is DatabaseError { + // Various SQLite and SQLCipher versions don't emit the same + // error. What we care about is that there is an error. } } do { let sql = "SELECT throw(), NULL" - try test(Fetched.fetchCursor(db, sql), sql: sql) - try test(Fetched.fetchCursor(db.makeSelectStatement(sql)), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchCursor(db), sql: sql) + try test(Fetched.fetchCursor(db, sql: sql), sql: sql) + try test(Fetched.fetchCursor(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchCursor(db), sql: sql) } do { let sql = "SELECT 0, throw(), NULL" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchCursor(db, sql, adapter: adapter), sql: sql) - try test(Fetched.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchCursor(db), sql: sql) + try test(Fetched.fetchCursor(db, sql: sql, adapter: adapter), sql: sql) + try test(Fetched.fetchCursor(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db), sql: sql) } } } @@ -119,18 +130,18 @@ class FetchableRecordTests: GRDBTestCase { } do { let sql = "SELECT * FROM nonExistingTable" - try test(Fetched.fetchCursor(db, sql), sql: sql) - try test(Fetched.fetchCursor(db.makeSelectStatement(sql)), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchCursor(db), sql: sql) + try test(Fetched.fetchCursor(db, sql: sql), sql: sql) + try test(Fetched.fetchCursor(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchCursor(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchCursor(db, sql, adapter: adapter), sql: sql) - try test(Fetched.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchCursor(db), sql: sql) + try test(Fetched.fetchCursor(db, sql: sql, adapter: adapter), sql: sql) + try test(Fetched.fetchCursor(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db), sql: sql) } } } @@ -144,24 +155,38 @@ class FetchableRecordTests: GRDBTestCase { } do { let sql = "SELECT 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 'Barbara', 'Gourde'" - let statement = try db.makeSelectStatement(sql) - try test(Fetched.fetchAll(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Fetched.fetchAll(db, sql: sql)) try test(Fetched.fetchAll(statement)) - try test(Fetched.fetchAll(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchAll(db)) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchAll(db)) } do { let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 0, 'Barbara', 'Gourde'" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchAll(db, sql, adapter: adapter)) + try test(Fetched.fetchAll(db, sql: sql, adapter: adapter)) try test(Fetched.fetchAll(statement, adapter: adapter)) - try test(Fetched.fetchAll(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchAll(db)) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db)) } } } - + + #if swift(>=5.0) + func testFetchAllWithInterpolation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request: SQLRequest = """ + SELECT \("Arthur") AS firstName, \("O'Brien") AS lastName + """ + let array = try request.fetchAll(db) + XCTAssertEqual(array[0].firstName, "Arthur") + XCTAssertEqual(array[0].lastName, "O'Brien") + } + } + #endif + func testFetchAllStepFailure() throws { let dbQueue = try makeDatabaseQueue() let customError = NSError(domain: "Custom", code: 0xDEAD) @@ -180,18 +205,18 @@ class FetchableRecordTests: GRDBTestCase { } do { let sql = "SELECT throw()" - try test(Fetched.fetchAll(db, sql), sql: sql) - try test(Fetched.fetchAll(db.makeSelectStatement(sql)), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchAll(db), sql: sql) + try test(Fetched.fetchAll(db, sql: sql), sql: sql) + try test(Fetched.fetchAll(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchAll(db), sql: sql) } do { let sql = "SELECT 0, throw()" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchAll(db, sql, adapter: adapter), sql: sql) - try test(Fetched.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchAll(db), sql: sql) + try test(Fetched.fetchAll(db, sql: sql, adapter: adapter), sql: sql) + try test(Fetched.fetchAll(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db), sql: sql) } } } @@ -212,18 +237,18 @@ class FetchableRecordTests: GRDBTestCase { } do { let sql = "SELECT * FROM nonExistingTable" - try test(Fetched.fetchAll(db, sql), sql: sql) - try test(Fetched.fetchAll(db.makeSelectStatement(sql)), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchAll(db), sql: sql) + try test(Fetched.fetchAll(db, sql: sql), sql: sql) + try test(Fetched.fetchAll(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchAll(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchAll(db, sql, adapter: adapter), sql: sql) - try test(Fetched.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchAll(db), sql: sql) + try test(Fetched.fetchAll(db, sql: sql, adapter: adapter), sql: sql) + try test(Fetched.fetchAll(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db), sql: sql) } } } @@ -237,20 +262,20 @@ class FetchableRecordTests: GRDBTestCase { } do { let sql = "SELECT 1 WHERE 0" - let statement = try db.makeSelectStatement(sql) - try test(Fetched.fetchOne(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Fetched.fetchOne(db, sql: sql)) try test(Fetched.fetchOne(statement)) - try test(Fetched.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchOne(db)) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchOne(db)) } do { let sql = "SELECT 0, 1 WHERE 0" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchOne(db, sql, adapter: adapter)) + try test(Fetched.fetchOne(db, sql: sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) - try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchOne(db)) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db)) } } do { @@ -260,25 +285,39 @@ class FetchableRecordTests: GRDBTestCase { } do { let sql = "SELECT 'Arthur' AS firstName, 'Martin' AS lastName" - let statement = try db.makeSelectStatement(sql) - try test(Fetched.fetchOne(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Fetched.fetchOne(db, sql: sql)) try test(Fetched.fetchOne(statement)) - try test(Fetched.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchOne(db)) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchOne(db)) } do { let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchOne(db, sql, adapter: adapter)) + try test(Fetched.fetchOne(db, sql: sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) - try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchOne(db)) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db)) } } } } - + + #if swift(>=5.0) + func testFetchOneWithInterpolation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request: SQLRequest = """ + SELECT \("Arthur") AS firstName, \("O'Brien") AS lastName + """ + let fetched = try request.fetchOne(db) + XCTAssertEqual(fetched!.firstName, "Arthur") + XCTAssertEqual(fetched!.lastName, "O'Brien") + } + } + #endif + func testFetchOneStepFailure() throws { let dbQueue = try makeDatabaseQueue() let customError = NSError(domain: "Custom", code: 0xDEAD) @@ -297,18 +336,18 @@ class FetchableRecordTests: GRDBTestCase { } do { let sql = "SELECT throw()" - try test(Fetched.fetchOne(db, sql), sql: sql) - try test(Fetched.fetchOne(db.makeSelectStatement(sql)), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchOne(db), sql: sql) + try test(Fetched.fetchOne(db, sql: sql), sql: sql) + try test(Fetched.fetchOne(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchOne(db), sql: sql) } do { let sql = "SELECT 0, throw()" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchOne(db, sql, adapter: adapter), sql: sql) - try test(Fetched.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchOne(db), sql: sql) + try test(Fetched.fetchOne(db, sql: sql, adapter: adapter), sql: sql) + try test(Fetched.fetchOne(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db), sql: sql) } } } @@ -329,18 +368,18 @@ class FetchableRecordTests: GRDBTestCase { } do { let sql = "SELECT * FROM nonExistingTable" - try test(Fetched.fetchOne(db, sql), sql: sql) - try test(Fetched.fetchOne(db.makeSelectStatement(sql)), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchOne(db), sql: sql) + try test(Fetched.fetchOne(db, sql: sql), sql: sql) + try test(Fetched.fetchOne(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchOne(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchOne(db, sql, adapter: adapter), sql: sql) - try test(Fetched.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchOne(db), sql: sql) + try test(Fetched.fetchOne(db, sql: sql, adapter: adapter), sql: sql) + try test(Fetched.fetchOne(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db), sql: sql) } } } diff --git a/Tests/GRDBTests/FetchedRecordsControllerTests.swift b/Tests/GRDBTests/FetchedRecordsControllerTests.swift index 867f5594c..3a733448a 100644 --- a/Tests/GRDBTests/FetchedRecordsControllerTests.swift +++ b/Tests/GRDBTests/FetchedRecordsControllerTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -123,10 +121,10 @@ class FetchedRecordsControllerTests: GRDBTestCase { let authorId: Int64 = try dbQueue.inDatabase { db in let plato = Person(name: "Plato") try plato.insert(db) - try db.execute("INSERT INTO books (authorID, title) VALUES (?, ?)", arguments: [plato.id, "Symposium"]) + try db.execute(sql: "INSERT INTO books (authorID, title) VALUES (?, ?)", arguments: [plato.id, "Symposium"]) let cervantes = Person(name: "Cervantes") try cervantes.insert(db) - try db.execute("INSERT INTO books (authorID, title) VALUES (?, ?)", arguments: [cervantes.id, "Don Quixote"]) + try db.execute(sql: "INSERT INTO books (authorID, title) VALUES (?, ?)", arguments: [cervantes.id, "Don Quixote"]) return cervantes.id! } @@ -141,10 +139,10 @@ class FetchedRecordsControllerTests: GRDBTestCase { let authorId: Int64 = try dbQueue.inDatabase { db in let plato = Person(name: "Plato") try plato.insert(db) - try db.execute("INSERT INTO books (authorID, title) VALUES (?, ?)", arguments: [plato.id, "Symposium"]) + try db.execute(sql: "INSERT INTO books (authorID, title) VALUES (?, ?)", arguments: [plato.id, "Symposium"]) let cervantes = Person(name: "Cervantes") try cervantes.insert(db) - try db.execute("INSERT INTO books (authorID, title) VALUES (?, ?)", arguments: [cervantes.id, "Don Quixote"]) + try db.execute(sql: "INSERT INTO books (authorID, title) VALUES (?, ?)", arguments: [cervantes.id, "Don Quixote"]) return cervantes.id! } @@ -288,7 +286,7 @@ class FetchedRecordsControllerTests: GRDBTestCase { recorder.transactionExpectation = expectation(description: "expectation") // No change should be recorded try dbQueue.inTransaction { db in - try db.execute("UPDATE persons SET name = ? WHERE id = ?", arguments: ["Arthur", 1]) + try db.execute(sql: "UPDATE persons SET name = ? WHERE id = ?", arguments: ["Arthur", 1]) return .commit } // One change should be recorded @@ -474,8 +472,8 @@ class FetchedRecordsControllerTests: GRDBTestCase { // Insert recorder.transactionExpectation = expectation(description: "expectation") try dbQueue.inTransaction { db in - try db.execute("INSERT INTO persons (name) VALUES (?)", arguments: ["Arthur"]) - try db.execute("INSERT INTO books (authorId, title) VALUES (?, ?)", arguments: [1, "Moby Dick"]) + try db.execute(sql: "INSERT INTO persons (name) VALUES (?)", arguments: ["Arthur"]) + try db.execute(sql: "INSERT INTO books (authorId, title) VALUES (?, ?)", arguments: [1, "Moby Dick"]) return .commit } waitForExpectations(timeout: 1, handler: nil) @@ -483,7 +481,7 @@ class FetchedRecordsControllerTests: GRDBTestCase { // Change books recorder.transactionExpectation = expectation(description: "expectation") try dbQueue.inTransaction { db in - try db.execute("DELETE FROM books") + try db.execute(sql: "DELETE FROM books") return .commit } waitForExpectations(timeout: 1, handler: nil) @@ -722,7 +720,7 @@ class FetchedRecordsControllerTests: GRDBTestCase { recorder.transactionExpectation = expectation(description: "expectation") try dbQueue.inTransaction { db in - try db.execute("UPDATE persons SET email = ? WHERE name = ?", arguments: ["arthur@example.com", "Arthur"]) + try db.execute(sql: "UPDATE persons SET email = ? WHERE name = ?", arguments: ["arthur@example.com", "Arthur"]) return .commit } waitForExpectations(timeout: 1, handler: nil) @@ -734,7 +732,7 @@ class FetchedRecordsControllerTests: GRDBTestCase { recorder.transactionExpectation = expectation(description: "expectation") try dbQueue.inTransaction { db in - try db.execute("UPDATE PERSONS SET EMAIL = ? WHERE NAME = ?", arguments: ["barbara@example.com", "Barbara"]) + try db.execute(sql: "UPDATE PERSONS SET EMAIL = ? WHERE NAME = ?", arguments: ["barbara@example.com", "Barbara"]) return .commit } waitForExpectations(timeout: 1, handler: nil) @@ -898,11 +896,11 @@ class FetchedRecordsControllerTests: GRDBTestCase { try specificController.performFetch() try dbQueue.writeWithoutTransaction { db in - try db.execute("INSERT INTO persons (id, name) VALUES (?, ?)", arguments: [1, "Arthur"]) - try db.execute("INSERT INTO persons (id, name) VALUES (?, ?)", arguments: [2, "Barbara"]) - try db.execute("UPDATE persons SET name = ? WHERE id = ?", arguments: ["Craig", 1]) - try db.execute("UPDATE persons SET name = ? WHERE id = ?", arguments: ["David", 2]) - try db.execute("DELETE FROM persons") + try db.execute(sql: "INSERT INTO persons (id, name) VALUES (?, ?)", arguments: [1, "Arthur"]) + try db.execute(sql: "INSERT INTO persons (id, name) VALUES (?, ?)", arguments: [2, "Barbara"]) + try db.execute(sql: "UPDATE persons SET name = ? WHERE id = ?", arguments: ["Craig", 1]) + try db.execute(sql: "UPDATE persons SET name = ? WHERE id = ?", arguments: ["David", 2]) + try db.execute(sql: "DELETE FROM persons") } waitForExpectations(timeout: 1, handler: nil) XCTAssertEqual(generalChangeCount, 6) @@ -915,7 +913,7 @@ class FetchedRecordsControllerTests: GRDBTestCase { private func synchronizePersons(_ db: Database, _ newPersons: [Person]) throws { // Sort new persons and database persons by id: let newPersons = newPersons.sorted { $0.id! < $1.id! } - let databasePersons = try Person.fetchAll(db, "SELECT * FROM persons ORDER BY id") + let databasePersons = try Person.fetchAll(db, sql: "SELECT * FROM persons ORDER BY id") // Now that both lists are sorted by id, we can compare them with // the sortedMerge() function. diff --git a/Tests/GRDBTests/FilterCursorTests.swift b/Tests/GRDBTests/FilterCursorTests.swift index dbde9254e..b41a570a5 100644 --- a/Tests/GRDBTests/FilterCursorTests.swift +++ b/Tests/GRDBTests/FilterCursorTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/FlattenCursorTests.swift b/Tests/GRDBTests/FlattenCursorTests.swift index f2fa00338..cbc9da5a7 100644 --- a/Tests/GRDBTests/FlattenCursorTests.swift +++ b/Tests/GRDBTests/FlattenCursorTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/ForeignKeyInfoTests.swift b/Tests/GRDBTests/ForeignKeyInfoTests.swift index 91d8e0d4c..1c4b41fed 100644 --- a/Tests/GRDBTests/ForeignKeyInfoTests.swift +++ b/Tests/GRDBTests/ForeignKeyInfoTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else @testable import GRDB @@ -21,12 +19,12 @@ class ForeignKeyInfoTests: GRDBTestCase { func testForeignKeys() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE parents1 (id PRIMARY KEY)") - try db.execute("CREATE TABLE parents2 (a, b, PRIMARY KEY (a,b))") - try db.execute("CREATE TABLE children1 (parentId REFERENCES parents1)") - try db.execute("CREATE TABLE children2 (parentId1 REFERENCES parents1, parentId2 REFERENCES parents1)") - try db.execute("CREATE TABLE children3 (parentA, parentB, FOREIGN KEY (parentA, parentB) REFERENCES parents2)") - try db.execute("CREATE TABLE children4 (parentA1, parentB1, parentA2, parentB2, FOREIGN KEY (parentA1, parentB1) REFERENCES parents2, FOREIGN KEY (parentA2, parentB2) REFERENCES parents2(b, a))") + try db.execute(sql: "CREATE TABLE parents1 (id PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE parents2 (a, b, PRIMARY KEY (a,b))") + try db.execute(sql: "CREATE TABLE children1 (parentId REFERENCES parents1)") + try db.execute(sql: "CREATE TABLE children2 (parentId1 REFERENCES parents1, parentId2 REFERENCES parents1)") + try db.execute(sql: "CREATE TABLE children3 (parentA, parentB, FOREIGN KEY (parentA, parentB) REFERENCES parents2)") + try db.execute(sql: "CREATE TABLE children4 (parentA1, parentB1, parentA2, parentB2, FOREIGN KEY (parentA1, parentB1) REFERENCES parents2, FOREIGN KEY (parentA2, parentB2) REFERENCES parents2(b, a))") do { _ = try db.foreignKeys(on: "missing") diff --git a/Tests/GRDBTests/FoundationDataTests.swift b/Tests/GRDBTests/FoundationDataTests.swift index fc798ed0b..73c8aa726 100644 --- a/Tests/GRDBTests/FoundationDataTests.swift +++ b/Tests/GRDBTests/FoundationDataTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,7 +10,7 @@ class FoundationDataTests: GRDBTestCase { func testDataDatabaseRoundTrip() throws { let dbQueue = try makeDatabaseQueue() func roundTrip(_ value: Data) throws -> Bool { - guard let back = try dbQueue.inDatabase({ try Data.fetchOne($0, "SELECT ?", arguments: [value]) }) else { + guard let back = try dbQueue.inDatabase({ try Data.fetchOne($0, sql: "SELECT ?", arguments: [value]) }) else { XCTFail() return false } diff --git a/Tests/GRDBTests/FoundationDateComponentsTests.swift b/Tests/GRDBTests/FoundationDateComponentsTests.swift index dc2c9dc78..e49b05389 100644 --- a/Tests/GRDBTests/FoundationDateComponentsTests.swift +++ b/Tests/GRDBTests/FoundationDateComponentsTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,7 +10,7 @@ class FoundationDateComponentsTests : GRDBTestCase { override func setup(_ dbWriter: DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("createDates") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE dates ( ID INTEGER PRIMARY KEY, creationDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP) @@ -33,12 +31,12 @@ class FoundationDateComponentsTests : GRDBTestCase { dateComponents.minute = 11 dateComponents.second = 12 dateComponents.nanosecond = 123_456_789 - try db.execute("INSERT INTO dates (creationDate) VALUES (?)", arguments: [DatabaseDateComponents(dateComponents, format: .HM)]) + try db.execute(sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: [DatabaseDateComponents(dateComponents, format: .HM)]) - let string = try String.fetchOne(db, "SELECT creationDate from dates")! + let string = try String.fetchOne(db, sql: "SELECT creationDate from dates")! XCTAssertEqual(string, "10:11") - let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, "SELECT creationDate FROM dates")! + let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, sql: "SELECT creationDate FROM dates")! XCTAssertEqual(databaseDateComponents.format, DatabaseDateComponents.Format.HM) XCTAssertTrue(databaseDateComponents.dateComponents.year == nil) XCTAssertTrue(databaseDateComponents.dateComponents.month == nil) @@ -62,12 +60,12 @@ class FoundationDateComponentsTests : GRDBTestCase { dateComponents.minute = 11 dateComponents.second = 12 dateComponents.nanosecond = 123_456_789 - try db.execute("INSERT INTO dates (creationDate) VALUES (?)", arguments: [DatabaseDateComponents(dateComponents, format: .HMS)]) + try db.execute(sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: [DatabaseDateComponents(dateComponents, format: .HMS)]) - let string = try String.fetchOne(db, "SELECT creationDate from dates")! + let string = try String.fetchOne(db, sql: "SELECT creationDate from dates")! XCTAssertEqual(string, "10:11:12") - let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, "SELECT creationDate FROM dates")! + let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, sql: "SELECT creationDate FROM dates")! XCTAssertEqual(databaseDateComponents.format, DatabaseDateComponents.Format.HMS) XCTAssertTrue(databaseDateComponents.dateComponents.year == nil) XCTAssertTrue(databaseDateComponents.dateComponents.month == nil) @@ -91,12 +89,12 @@ class FoundationDateComponentsTests : GRDBTestCase { dateComponents.minute = 11 dateComponents.second = 12 dateComponents.nanosecond = 123_456_789 - try db.execute("INSERT INTO dates (creationDate) VALUES (?)", arguments: [DatabaseDateComponents(dateComponents, format: .HMSS)]) + try db.execute(sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: [DatabaseDateComponents(dateComponents, format: .HMSS)]) - let string = try String.fetchOne(db, "SELECT creationDate from dates")! + let string = try String.fetchOne(db, sql: "SELECT creationDate from dates")! XCTAssertEqual(string, "10:11:12.123") - let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, "SELECT creationDate FROM dates")! + let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, sql: "SELECT creationDate FROM dates")! XCTAssertEqual(databaseDateComponents.format, DatabaseDateComponents.Format.HMSS) XCTAssertTrue(databaseDateComponents.dateComponents.year == nil) XCTAssertTrue(databaseDateComponents.dateComponents.month == nil) @@ -120,12 +118,12 @@ class FoundationDateComponentsTests : GRDBTestCase { dateComponents.minute = 11 dateComponents.second = 12 dateComponents.nanosecond = 123_456_789 - try db.execute("INSERT INTO dates (creationDate) VALUES (?)", arguments: [DatabaseDateComponents(dateComponents, format: .YMD)]) + try db.execute(sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: [DatabaseDateComponents(dateComponents, format: .YMD)]) - let string = try String.fetchOne(db, "SELECT creationDate from dates")! + let string = try String.fetchOne(db, sql: "SELECT creationDate from dates")! XCTAssertEqual(string, "1973-09-18") - let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, "SELECT creationDate FROM dates")! + let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, sql: "SELECT creationDate FROM dates")! XCTAssertEqual(databaseDateComponents.format, DatabaseDateComponents.Format.YMD) XCTAssertEqual(databaseDateComponents.dateComponents.year, dateComponents.year) XCTAssertEqual(databaseDateComponents.dateComponents.month, dateComponents.month) @@ -149,12 +147,12 @@ class FoundationDateComponentsTests : GRDBTestCase { dateComponents.minute = 11 dateComponents.second = 12 dateComponents.nanosecond = 123_456_789 - try db.execute("INSERT INTO dates (creationDate) VALUES (?)", arguments: [DatabaseDateComponents(dateComponents, format: .YMD_HM)]) + try db.execute(sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: [DatabaseDateComponents(dateComponents, format: .YMD_HM)]) - let string = try String.fetchOne(db, "SELECT creationDate from dates")! + let string = try String.fetchOne(db, sql: "SELECT creationDate from dates")! XCTAssertEqual(string, "1973-09-18 10:11") - let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, "SELECT creationDate FROM dates")! + let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, sql: "SELECT creationDate FROM dates")! XCTAssertEqual(databaseDateComponents.format, DatabaseDateComponents.Format.YMD_HM) XCTAssertEqual(databaseDateComponents.dateComponents.year, dateComponents.year) XCTAssertEqual(databaseDateComponents.dateComponents.month, dateComponents.month) @@ -178,12 +176,12 @@ class FoundationDateComponentsTests : GRDBTestCase { dateComponents.minute = 11 dateComponents.second = 12 dateComponents.nanosecond = 123_456_789 - try db.execute("INSERT INTO dates (creationDate) VALUES (?)", arguments: [DatabaseDateComponents(dateComponents, format: .YMD_HMS)]) + try db.execute(sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: [DatabaseDateComponents(dateComponents, format: .YMD_HMS)]) - let string = try String.fetchOne(db, "SELECT creationDate from dates")! + let string = try String.fetchOne(db, sql: "SELECT creationDate from dates")! XCTAssertEqual(string, "1973-09-18 10:11:12") - let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, "SELECT creationDate FROM dates")! + let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, sql: "SELECT creationDate FROM dates")! XCTAssertEqual(databaseDateComponents.format, DatabaseDateComponents.Format.YMD_HMS) XCTAssertEqual(databaseDateComponents.dateComponents.year, dateComponents.year) XCTAssertEqual(databaseDateComponents.dateComponents.month, dateComponents.month) @@ -207,12 +205,12 @@ class FoundationDateComponentsTests : GRDBTestCase { dateComponents.minute = 11 dateComponents.second = 12 dateComponents.nanosecond = 123_456_789 - try db.execute("INSERT INTO dates (creationDate) VALUES (?)", arguments: [DatabaseDateComponents(dateComponents, format: .YMD_HMSS)]) + try db.execute(sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: [DatabaseDateComponents(dateComponents, format: .YMD_HMSS)]) - let string = try String.fetchOne(db, "SELECT creationDate from dates")! + let string = try String.fetchOne(db, sql: "SELECT creationDate from dates")! XCTAssertEqual(string, "1973-09-18 10:11:12.123") - let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, "SELECT creationDate FROM dates")! + let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, sql: "SELECT creationDate FROM dates")! XCTAssertEqual(databaseDateComponents.format, DatabaseDateComponents.Format.YMD_HMSS) XCTAssertEqual(databaseDateComponents.dateComponents.year, dateComponents.year) XCTAssertEqual(databaseDateComponents.dateComponents.month, dateComponents.month) @@ -229,12 +227,12 @@ class FoundationDateComponentsTests : GRDBTestCase { try dbQueue.inDatabase { db in let dateComponents = DateComponents() - try db.execute("INSERT INTO dates (creationDate) VALUES (?)", arguments: [DatabaseDateComponents(dateComponents, format: .YMD_HMSS)]) + try db.execute(sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: [DatabaseDateComponents(dateComponents, format: .YMD_HMSS)]) - let string = try String.fetchOne(db, "SELECT creationDate from dates")! + let string = try String.fetchOne(db, sql: "SELECT creationDate from dates")! XCTAssertEqual(string, "0000-01-01 00:00:00.000") - let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, "SELECT creationDate FROM dates")! + let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, sql: "SELECT creationDate FROM dates")! XCTAssertEqual(databaseDateComponents.format, DatabaseDateComponents.Format.YMD_HMSS) XCTAssertEqual(databaseDateComponents.dateComponents.year, 0) XCTAssertEqual(databaseDateComponents.dateComponents.month, 1) @@ -258,9 +256,9 @@ class FoundationDateComponentsTests : GRDBTestCase { dateComponents.minute = 11 dateComponents.second = 12 dateComponents.nanosecond = 123_456_789 - try db.execute("INSERT INTO dates (creationDate) VALUES (?)", arguments: ["1973-09-18T10:11"]) + try db.execute(sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: ["1973-09-18T10:11"]) - let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, "SELECT creationDate FROM dates")! + let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, sql: "SELECT creationDate FROM dates")! XCTAssertEqual(databaseDateComponents.format, DatabaseDateComponents.Format.YMD_HM) XCTAssertEqual(databaseDateComponents.dateComponents.year, dateComponents.year) XCTAssertEqual(databaseDateComponents.dateComponents.month, dateComponents.month) @@ -284,9 +282,9 @@ class FoundationDateComponentsTests : GRDBTestCase { dateComponents.minute = 11 dateComponents.second = 12 dateComponents.nanosecond = 123_456_789 - try db.execute("INSERT INTO dates (creationDate) VALUES (?)", arguments: ["1973-09-18T10:11:12"]) + try db.execute(sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: ["1973-09-18T10:11:12"]) - let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, "SELECT creationDate FROM dates")! + let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, sql: "SELECT creationDate FROM dates")! XCTAssertEqual(databaseDateComponents.format, DatabaseDateComponents.Format.YMD_HMS) XCTAssertEqual(databaseDateComponents.dateComponents.year, dateComponents.year) XCTAssertEqual(databaseDateComponents.dateComponents.month, dateComponents.month) @@ -310,9 +308,9 @@ class FoundationDateComponentsTests : GRDBTestCase { dateComponents.minute = 11 dateComponents.second = 12 dateComponents.nanosecond = 123_456_789 - try db.execute("INSERT INTO dates (creationDate) VALUES (?)", arguments: ["1973-09-18T10:11:12.123"]) + try db.execute(sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: ["1973-09-18T10:11:12.123"]) - let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, "SELECT creationDate FROM dates")! + let databaseDateComponents = try DatabaseDateComponents.fetchOne(db, sql: "SELECT creationDate FROM dates")! XCTAssertEqual(databaseDateComponents.format, DatabaseDateComponents.Format.YMD_HMSS) XCTAssertEqual(databaseDateComponents.dateComponents.year, dateComponents.year) XCTAssertEqual(databaseDateComponents.dateComponents.month, dateComponents.month) @@ -333,23 +331,23 @@ class FoundationDateComponentsTests : GRDBTestCase { let date = Date().addingTimeInterval(-1) let dateComponents = calendar.dateComponents([.year, .month, .day, .hour, .minute, .second], from: date) try db.execute( - "INSERT INTO dates (id, creationDate) VALUES (?,?)", + sql: "INSERT INTO dates (id, creationDate) VALUES (?,?)", arguments: [1, DatabaseDateComponents(dateComponents, format: .YMD_HMS)]) } do { try db.execute( - "INSERT INTO dates (id) VALUES (?)", + sql: "INSERT INTO dates (id) VALUES (?)", arguments: [2]) } do { let date = Date().addingTimeInterval(1) let dateComponents = calendar.dateComponents([.year, .month, .day, .hour, .minute, .second], from: date) try db.execute( - "INSERT INTO dates (id, creationDate) VALUES (?,?)", + sql: "INSERT INTO dates (id, creationDate) VALUES (?,?)", arguments: [3, DatabaseDateComponents(dateComponents, format: .YMD_HMS)]) } - let ids = try Int.fetchAll(db, "SELECT id FROM dates ORDER BY creationDate") + let ids = try Int.fetchAll(db, sql: "SELECT id FROM dates ORDER BY creationDate") XCTAssertEqual(ids, [1,2,3]) } } @@ -365,7 +363,7 @@ class FoundationDateComponentsTests : GRDBTestCase { do { // Test StatementColumnConvertible adoption let parsed = DatabaseQueue().inDatabase { - try! DatabaseDateComponents.fetchOne($0, "SELECT ?", arguments: [string])! + try! DatabaseDateComponents.fetchOne($0, sql: "SELECT ?", arguments: [string])! } XCTAssertEqual(parsed.format, dateComponent.format, file: file, line: line) XCTAssertEqual(parsed.dateComponents, dateComponent.dateComponents, file: file, line: line) diff --git a/Tests/GRDBTests/FoundationDateTests.swift b/Tests/GRDBTests/FoundationDateTests.swift index 920d15f01..ae6e76af8 100644 --- a/Tests/GRDBTests/FoundationDateTests.swift +++ b/Tests/GRDBTests/FoundationDateTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,7 +10,7 @@ class FoundationDateTests : GRDBTestCase { override func setup(_ dbWriter: DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("createDates") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE dates ( ID INTEGER PRIMARY KEY, creationDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP) @@ -37,11 +35,11 @@ class FoundationDateTests : GRDBTestCase { do { let date = calendar.date(from: dateComponents)! - try db.execute("INSERT INTO dates (creationDate) VALUES (?)", arguments: [date]) + try db.execute(sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: [date]) } do { - let date = try Date.fetchOne(db, "SELECT creationDate FROM dates")! + let date = try Date.fetchOne(db, sql: "SELECT creationDate FROM dates")! // All components must be preserved, but nanosecond since ISO-8601 stores milliseconds. XCTAssertEqual(calendar.component(.year, from: date), dateComponents.year) XCTAssertEqual(calendar.component(.month, from: date), dateComponents.month) @@ -58,18 +56,18 @@ class FoundationDateTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.execute( - "INSERT INTO dates (id, creationDate) VALUES (?,?)", + sql: "INSERT INTO dates (id, creationDate) VALUES (?,?)", arguments: [1, Date().addingTimeInterval(-1)]) try db.execute( - "INSERT INTO dates (id) VALUES (?)", + sql: "INSERT INTO dates (id) VALUES (?)", arguments: [2]) try db.execute( - "INSERT INTO dates (id, creationDate) VALUES (?,?)", + sql: "INSERT INTO dates (id, creationDate) VALUES (?,?)", arguments: [3, Date().addingTimeInterval(1)]) - let ids = try Int.fetchAll(db, "SELECT id FROM dates ORDER BY creationDate") + let ids = try Int.fetchAll(db, sql: "SELECT id FROM dates ORDER BY creationDate") XCTAssertEqual(ids, [1,2,3]) } } @@ -111,9 +109,9 @@ class FoundationDateTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.execute( - "INSERT INTO dates (creationDate) VALUES (?)", + sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: ["2015-07-22"]) - let date = try Date.fetchOne(db, "SELECT creationDate from dates")! + let date = try Date.fetchOne(db, sql: "SELECT creationDate from dates")! var calendar = Calendar(identifier: .gregorian) calendar.timeZone = TimeZone(secondsFromGMT: 0)! XCTAssertEqual(calendar.component(.year, from: date), 2015) @@ -130,9 +128,9 @@ class FoundationDateTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.execute( - "INSERT INTO dates (creationDate) VALUES (?)", + sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: ["2015-07-22 01:02"]) - let date = try Date.fetchOne(db, "SELECT creationDate from dates")! + let date = try Date.fetchOne(db, sql: "SELECT creationDate from dates")! var calendar = Calendar(identifier: .gregorian) calendar.timeZone = TimeZone(secondsFromGMT: 0)! XCTAssertEqual(calendar.component(.year, from: date), 2015) @@ -149,9 +147,9 @@ class FoundationDateTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.execute( - "INSERT INTO dates (creationDate) VALUES (?)", + sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: ["2015-07-22 01:02:03"]) - let date = try Date.fetchOne(db, "SELECT creationDate from dates")! + let date = try Date.fetchOne(db, sql: "SELECT creationDate from dates")! var calendar = Calendar(identifier: .gregorian) calendar.timeZone = TimeZone(secondsFromGMT: 0)! XCTAssertEqual(calendar.component(.year, from: date), 2015) @@ -168,9 +166,9 @@ class FoundationDateTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.execute( - "INSERT INTO dates (creationDate) VALUES (?)", + sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: ["2015-07-22 01:02:03.00456"]) - let date = try Date.fetchOne(db, "SELECT creationDate from dates")! + let date = try Date.fetchOne(db, sql: "SELECT creationDate from dates")! var calendar = Calendar(identifier: .gregorian) calendar.timeZone = TimeZone(secondsFromGMT: 0)! XCTAssertEqual(calendar.component(.year, from: date), 2015) @@ -187,13 +185,13 @@ class FoundationDateTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.execute( - "INSERT INTO dates (creationDate) VALUES (?)", + sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: [1437526920]) - let string = try String.fetchOne(db, "SELECT datetime(creationDate, 'unixepoch') from dates")! + let string = try String.fetchOne(db, sql: "SELECT datetime(creationDate, 'unixepoch') from dates")! XCTAssertEqual(string, "2015-07-22 01:02:00") - let date = try Date.fetchOne(db, "SELECT creationDate from dates")! + let date = try Date.fetchOne(db, sql: "SELECT creationDate from dates")! var calendar = Calendar(identifier: .gregorian) calendar.timeZone = TimeZone(secondsFromGMT: 0)! XCTAssertEqual(calendar.component(.year, from: date), 2015) @@ -210,9 +208,9 @@ class FoundationDateTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.execute( - "INSERT INTO dates (creationDate) VALUES (?)", + sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: ["2015-07-22T01:02"]) - let date = try Date.fetchOne(db, "SELECT creationDate from dates")! + let date = try Date.fetchOne(db, sql: "SELECT creationDate from dates")! var calendar = Calendar(identifier: .gregorian) calendar.timeZone = TimeZone(secondsFromGMT: 0)! XCTAssertEqual(calendar.component(.year, from: date), 2015) @@ -229,9 +227,9 @@ class FoundationDateTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.execute( - "INSERT INTO dates (creationDate) VALUES (?)", + sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: ["2015-07-22T01:02:03"]) - let date = try Date.fetchOne(db, "SELECT creationDate from dates")! + let date = try Date.fetchOne(db, sql: "SELECT creationDate from dates")! var calendar = Calendar(identifier: .gregorian) calendar.timeZone = TimeZone(secondsFromGMT: 0)! XCTAssertEqual(calendar.component(.year, from: date), 2015) @@ -248,9 +246,9 @@ class FoundationDateTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.execute( - "INSERT INTO dates (creationDate) VALUES (?)", + sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: ["2015-07-22T01:02:03.00456"]) - let date = try Date.fetchOne(db, "SELECT creationDate from dates")! + let date = try Date.fetchOne(db, sql: "SELECT creationDate from dates")! var calendar = Calendar(identifier: .gregorian) calendar.timeZone = TimeZone(secondsFromGMT: 0)! XCTAssertEqual(calendar.component(.year, from: date), 2015) diff --git a/Tests/GRDBTests/FoundationNSDataTests.swift b/Tests/GRDBTests/FoundationNSDataTests.swift index 6ae612ec0..8f02a40fd 100644 --- a/Tests/GRDBTests/FoundationNSDataTests.swift +++ b/Tests/GRDBTests/FoundationNSDataTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,7 +10,7 @@ class FoundationNSDataTests: GRDBTestCase { func testNSDataDatabaseRoundTrip() throws { let dbQueue = try makeDatabaseQueue() func roundTrip(_ value: NSData) throws -> Bool { - guard let back = try dbQueue.inDatabase({ try NSData.fetchOne($0, "SELECT ?", arguments: [value]) }) else { + guard let back = try dbQueue.inDatabase({ try NSData.fetchOne($0, sql: "SELECT ?", arguments: [value]) }) else { XCTFail() return false } diff --git a/Tests/GRDBTests/FoundationNSDateTests.swift b/Tests/GRDBTests/FoundationNSDateTests.swift index ea43fb71f..71dc21462 100644 --- a/Tests/GRDBTests/FoundationNSDateTests.swift +++ b/Tests/GRDBTests/FoundationNSDateTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,7 +10,7 @@ class FoundationNSDateTests : GRDBTestCase { override func setup(_ dbWriter: DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("createDates") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE dates ( ID INTEGER PRIMARY KEY, creationDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP) @@ -37,11 +35,11 @@ class FoundationNSDateTests : GRDBTestCase { do { let date = calendar.date(from: dateComponents as DateComponents)! - try db.execute("INSERT INTO dates (creationDate) VALUES (?)", arguments: [date]) + try db.execute(sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: [date]) } do { - let date = try NSDate.fetchOne(db, "SELECT creationDate FROM dates")! + let date = try NSDate.fetchOne(db, sql: "SELECT creationDate FROM dates")! // All components must be preserved, but nanosecond since ISO-8601 stores milliseconds. XCTAssertEqual(calendar.component(.year, from: date as Date), dateComponents.year) XCTAssertEqual(calendar.component(.month, from: date as Date), dateComponents.month) @@ -58,18 +56,18 @@ class FoundationNSDateTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.execute( - "INSERT INTO dates (id, creationDate) VALUES (?,?)", + sql: "INSERT INTO dates (id, creationDate) VALUES (?,?)", arguments: [1, NSDate().addingTimeInterval(-1)]) try db.execute( - "INSERT INTO dates (id) VALUES (?)", + sql: "INSERT INTO dates (id) VALUES (?)", arguments: [2]) try db.execute( - "INSERT INTO dates (id, creationDate) VALUES (?,?)", + sql: "INSERT INTO dates (id, creationDate) VALUES (?,?)", arguments: [3, NSDate().addingTimeInterval(1)]) - let ids = try Int.fetchAll(db, "SELECT id FROM dates ORDER BY creationDate") + let ids = try Int.fetchAll(db, sql: "SELECT id FROM dates ORDER BY creationDate") XCTAssertEqual(ids, [1,2,3]) } } @@ -94,9 +92,9 @@ class FoundationNSDateTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.execute( - "INSERT INTO dates (creationDate) VALUES (?)", + sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: ["2015-07-22"]) - let date = try NSDate.fetchOne(db, "SELECT creationDate from dates")! + let date = try NSDate.fetchOne(db, sql: "SELECT creationDate from dates")! var calendar = Calendar(identifier: .gregorian) calendar.timeZone = TimeZone(secondsFromGMT: 0)! XCTAssertEqual(calendar.component(.year, from: date as Date), 2015) @@ -113,9 +111,9 @@ class FoundationNSDateTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.execute( - "INSERT INTO dates (creationDate) VALUES (?)", + sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: ["2015-07-22 01:02"]) - let date = try NSDate.fetchOne(db, "SELECT creationDate from dates")! + let date = try NSDate.fetchOne(db, sql: "SELECT creationDate from dates")! var calendar = Calendar(identifier: .gregorian) calendar.timeZone = TimeZone(secondsFromGMT: 0)! XCTAssertEqual(calendar.component(.year, from: date as Date), 2015) @@ -132,9 +130,9 @@ class FoundationNSDateTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.execute( - "INSERT INTO dates (creationDate) VALUES (?)", + sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: ["2015-07-22 01:02:03"]) - let date = try NSDate.fetchOne(db, "SELECT creationDate from dates")! + let date = try NSDate.fetchOne(db, sql: "SELECT creationDate from dates")! var calendar = Calendar(identifier: .gregorian) calendar.timeZone = TimeZone(secondsFromGMT: 0)! XCTAssertEqual(calendar.component(.year, from: date as Date), 2015) @@ -151,9 +149,9 @@ class FoundationNSDateTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.execute( - "INSERT INTO dates (creationDate) VALUES (?)", + sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: ["2015-07-22 01:02:03.00456"]) - let date = try NSDate.fetchOne(db, "SELECT creationDate from dates")! + let date = try NSDate.fetchOne(db, sql: "SELECT creationDate from dates")! var calendar = Calendar(identifier: .gregorian) calendar.timeZone = TimeZone(secondsFromGMT: 0)! XCTAssertEqual(calendar.component(.year, from: date as Date), 2015) @@ -170,13 +168,13 @@ class FoundationNSDateTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.execute( - "INSERT INTO dates (creationDate) VALUES (?)", + sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: [1437526920]) - let string = try String.fetchOne(db, "SELECT datetime(creationDate, 'unixepoch') from dates")! + let string = try String.fetchOne(db, sql: "SELECT datetime(creationDate, 'unixepoch') from dates")! XCTAssertEqual(string, "2015-07-22 01:02:00") - let date = try NSDate.fetchOne(db, "SELECT creationDate from dates")! + let date = try NSDate.fetchOne(db, sql: "SELECT creationDate from dates")! var calendar = Calendar(identifier: .gregorian) calendar.timeZone = TimeZone(secondsFromGMT: 0)! XCTAssertEqual(calendar.component(.year, from: date as Date), 2015) @@ -193,9 +191,9 @@ class FoundationNSDateTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.execute( - "INSERT INTO dates (creationDate) VALUES (?)", + sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: ["2015-07-22T01:02"]) - let date = try NSDate.fetchOne(db, "SELECT creationDate from dates")! + let date = try NSDate.fetchOne(db, sql: "SELECT creationDate from dates")! var calendar = Calendar(identifier: .gregorian) calendar.timeZone = TimeZone(secondsFromGMT: 0)! XCTAssertEqual(calendar.component(.year, from: date as Date), 2015) @@ -212,9 +210,9 @@ class FoundationNSDateTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.execute( - "INSERT INTO dates (creationDate) VALUES (?)", + sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: ["2015-07-22T01:02:03"]) - let date = try NSDate.fetchOne(db, "SELECT creationDate from dates")! + let date = try NSDate.fetchOne(db, sql: "SELECT creationDate from dates")! var calendar = Calendar(identifier: .gregorian) calendar.timeZone = TimeZone(secondsFromGMT: 0)! XCTAssertEqual(calendar.component(.year, from: date as Date), 2015) @@ -231,9 +229,9 @@ class FoundationNSDateTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.execute( - "INSERT INTO dates (creationDate) VALUES (?)", + sql: "INSERT INTO dates (creationDate) VALUES (?)", arguments: ["2015-07-22T01:02:03.00456"]) - let date = try NSDate.fetchOne(db, "SELECT creationDate from dates")! + let date = try NSDate.fetchOne(db, sql: "SELECT creationDate from dates")! var calendar = Calendar(identifier: .gregorian) calendar.timeZone = TimeZone(secondsFromGMT: 0)! XCTAssertEqual(calendar.component(.year, from: date as Date), 2015) diff --git a/Tests/GRDBTests/FoundationNSDecimalNumberTests.swift b/Tests/GRDBTests/FoundationNSDecimalNumberTests.swift index bc63ea18a..00ad0ba1c 100644 --- a/Tests/GRDBTests/FoundationNSDecimalNumberTests.swift +++ b/Tests/GRDBTests/FoundationNSDecimalNumberTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/FoundationNSNullTests.swift b/Tests/GRDBTests/FoundationNSNullTests.swift index 68537ef53..1bb8b2eed 100644 --- a/Tests/GRDBTests/FoundationNSNullTests.swift +++ b/Tests/GRDBTests/FoundationNSNullTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/FoundationNSNumberTests.swift b/Tests/GRDBTests/FoundationNSNumberTests.swift index 626db1a40..ec23f59fa 100644 --- a/Tests/GRDBTests/FoundationNSNumberTests.swift +++ b/Tests/GRDBTests/FoundationNSNumberTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -101,7 +99,7 @@ class FoundationNSNumberTests: GRDBTestCase { func testNSNumberDatabaseRoundTrip() throws { let dbQueue = try makeDatabaseQueue() func roundTrip(_ value: NSNumber) throws -> Bool { - guard let back = try dbQueue.inDatabase({ try NSNumber.fetchOne($0, "SELECT ?", arguments: [value]) }) else { + guard let back = try dbQueue.inDatabase({ try NSNumber.fetchOne($0, sql: "SELECT ?", arguments: [value]) }) else { XCTFail() return false } diff --git a/Tests/GRDBTests/FoundationNSStringTests.swift b/Tests/GRDBTests/FoundationNSStringTests.swift index 258ca6321..14ab30821 100644 --- a/Tests/GRDBTests/FoundationNSStringTests.swift +++ b/Tests/GRDBTests/FoundationNSStringTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,7 +10,7 @@ class FoundationNSStringTests: GRDBTestCase { func testNSStringDatabaseRoundTrip() throws { let dbQueue = try makeDatabaseQueue() func roundTrip(_ value: NSString) throws -> Bool { - guard let back = try dbQueue.inDatabase({ try NSString.fetchOne($0, "SELECT ?", arguments: [value]) }) else { + guard let back = try dbQueue.inDatabase({ try NSString.fetchOne($0, sql: "SELECT ?", arguments: [value]) }) else { XCTFail() return false } diff --git a/Tests/GRDBTests/FoundationNSURLTests.swift b/Tests/GRDBTests/FoundationNSURLTests.swift index 404a48935..cb91d2f18 100644 --- a/Tests/GRDBTests/FoundationNSURLTests.swift +++ b/Tests/GRDBTests/FoundationNSURLTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,7 +10,7 @@ class FoundationNSURLTests: GRDBTestCase { func testNSURLDatabaseRoundTrip() throws { let dbQueue = try makeDatabaseQueue() func roundTrip(_ value: NSURL) throws -> Bool { - guard let back = try dbQueue.inDatabase({ try NSURL.fetchOne($0, "SELECT ?", arguments: [value]) }) else { + guard let back = try dbQueue.inDatabase({ try NSURL.fetchOne($0, sql: "SELECT ?", arguments: [value]) }) else { XCTFail() return false } diff --git a/Tests/GRDBTests/FoundationNSUUIDTests.swift b/Tests/GRDBTests/FoundationNSUUIDTests.swift index cf251ac35..a698e311a 100644 --- a/Tests/GRDBTests/FoundationNSUUIDTests.swift +++ b/Tests/GRDBTests/FoundationNSUUIDTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -11,10 +9,10 @@ class FoundationNSUUIDTests: GRDBTestCase { private func assert(_ value: DatabaseValueConvertible?, isDecodedAs expectedUUID: NSUUID?) throws { try makeDatabaseQueue().read { db in if let expectedUUID = expectedUUID { - let decodedUUID = try NSUUID.fetchOne(db, "SELECT ?", arguments: [value]) + let decodedUUID = try NSUUID.fetchOne(db, sql: "SELECT ?", arguments: [value]) XCTAssertEqual(decodedUUID, expectedUUID) } else if value == nil { - let decodedUUID = try Optional.fetchAll(db, "SELECT NULL")[0] + let decodedUUID = try Optional.fetchAll(db, sql: "SELECT NULL")[0] XCTAssertNil(decodedUUID) } } diff --git a/Tests/GRDBTests/FoundationURLTests.swift b/Tests/GRDBTests/FoundationURLTests.swift index 1e2a96f2d..8897c57bd 100644 --- a/Tests/GRDBTests/FoundationURLTests.swift +++ b/Tests/GRDBTests/FoundationURLTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,7 +10,7 @@ class FoundationURLTests: GRDBTestCase { func testURLDatabaseRoundTrip() throws { let dbQueue = try makeDatabaseQueue() func roundTrip(_ value: URL) throws -> Bool { - guard let back = try dbQueue.inDatabase({ try URL.fetchOne($0, "SELECT ?", arguments: [value]) }) else { + guard let back = try dbQueue.inDatabase({ try URL.fetchOne($0, sql: "SELECT ?", arguments: [value]) }) else { XCTFail() return false } diff --git a/Tests/GRDBTests/FoundationUUIDTests.swift b/Tests/GRDBTests/FoundationUUIDTests.swift index 7e33b041c..ac2037bb0 100644 --- a/Tests/GRDBTests/FoundationUUIDTests.swift +++ b/Tests/GRDBTests/FoundationUUIDTests.swift @@ -1,8 +1,6 @@ import XCTest import Foundation -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,10 +10,10 @@ class FoundationUUIDTests: GRDBTestCase { private func assert(_ value: DatabaseValueConvertible?, isDecodedAs expectedUUID: UUID?) throws { try makeDatabaseQueue().read { db in if let expectedUUID = expectedUUID { - let decodedUUID = try UUID.fetchOne(db, "SELECT ?", arguments: [value]) + let decodedUUID = try UUID.fetchOne(db, sql: "SELECT ?", arguments: [value]) XCTAssertEqual(decodedUUID, expectedUUID) } else if value == nil { - let decodedUUID = try Optional.fetchAll(db, "SELECT NULL")[0] + let decodedUUID = try Optional.fetchAll(db, sql: "SELECT NULL")[0] XCTAssertNil(decodedUUID) } } diff --git a/Tests/GRDBTests/GRDBTestCase.swift b/Tests/GRDBTests/GRDBTestCase.swift index 60fa4f0ff..f16109cfa 100644 --- a/Tests/GRDBTests/GRDBTestCase.swift +++ b/Tests/GRDBTests/GRDBTestCase.swift @@ -1,15 +1,15 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher // @testable so that we have access to SQLiteConnectionWillClose -#elseif GRDBCUSTOMSQLITE - @testable import GRDBCustomSQLite // @testable so that we have access to SQLiteConnectionWillClose +#if GRDBCUSTOMSQLITE + @testable import GRDBCustomSQLite #else - #if SWIFT_PACKAGE + #if GRDBCIPHER + import SQLCipher + #elseif SWIFT_PACKAGE import CSQLite #else import SQLite3 #endif - @testable import GRDB // @testable so that we have access to SQLiteConnectionWillClose + @testable import GRDB #endif // Support for Database.logError @@ -131,7 +131,7 @@ class GRDBTestCase: XCTestCase { XCTAssertTrue(sqlQueries.contains(sql), "Did not execute \(sql)") } - func assert(_ record: MutablePersistableRecord, isEncodedIn row: Row, file: StaticString = #file, line: UInt = #line) { + func assert(_ record: EncodableRecord, isEncodedIn row: Row, file: StaticString = #file, line: UInt = #line) { let recordDict = record.databaseDictionary let rowDict = Dictionary(row, uniquingKeysWith: { (left, _) in left }) XCTAssertEqual(recordDict, rowDict, file: file, line: line) @@ -146,7 +146,7 @@ class GRDBTestCase: XCTestCase { // Compare SQL strings (ignoring leading and trailing white space and semicolons. func assertEqualSQL(_ db: Database, _ request: Request, _ sql: String, file: StaticString = #file, line: UInt = #line) throws { - let (statement, _) = try request.prepare(db) + let (statement, _) = try request.prepare(db, forSingleResult: false) try statement.makeCursor().next() assertEqualSQL(lastSQLQuery, sql, file: file, line: line) } @@ -160,7 +160,7 @@ class GRDBTestCase: XCTestCase { func sql(_ databaseReader: DatabaseReader, _ request: Request) -> String { return try! databaseReader.unsafeRead { db in - let (statement, _) = try request.prepare(db) + let (statement, _) = try request.prepare(db, forSingleResult: false) try statement.makeCursor().next() return lastSQLQuery } diff --git a/Tests/GRDBTests/IndexInfoTests.swift b/Tests/GRDBTests/IndexInfoTests.swift index 5fc09de3c..47737f698 100644 --- a/Tests/GRDBTests/IndexInfoTests.swift +++ b/Tests/GRDBTests/IndexInfoTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -21,7 +19,7 @@ class IndexInfoTests: GRDBTestCase { } do { - try db.execute("CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT, email TEXT UNIQUE)") + try db.execute(sql: "CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT, email TEXT UNIQUE)") let indexes = try db.indexes(on: "persons") XCTAssertEqual(indexes.count, 1) @@ -31,19 +29,19 @@ class IndexInfoTests: GRDBTestCase { } do { - try db.execute("CREATE TABLE citizenships (year INTEGER, personId INTEGER NOT NULL, countryIsoCode TEXT NOT NULL, PRIMARY KEY (personId, countryIsoCode))") - try db.execute("CREATE INDEX citizenshipsOnYear ON citizenships(year)") + try db.execute(sql: "CREATE TABLE citizenships (year INTEGER, personId INTEGER NOT NULL, countryIsoCode TEXT NOT NULL, PRIMARY KEY (personId, countryIsoCode))") + try db.execute(sql: "CREATE INDEX citizenshipsOnYear ON citizenships(year)") let indexes = try db.indexes(on: "citizenships") XCTAssertEqual(indexes.count, 2) - if let i = indexes.index(where: { $0.columns == ["year"] }) { + if let i = indexes.firstIndex(where: { $0.columns == ["year"] }) { XCTAssertEqual(indexes[i].name, "citizenshipsOnYear") XCTAssertEqual(indexes[i].columns, ["year"]) XCTAssertFalse(indexes[i].isUnique) } else { XCTFail() } - if let i = indexes.index(where: { $0.columns == ["personId", "countryIsoCode"] }) { + if let i = indexes.firstIndex(where: { $0.columns == ["personId", "countryIsoCode"] }) { XCTAssertEqual(indexes[i].name, "sqlite_autoindex_citizenships_1") XCTAssertEqual(indexes[i].columns, ["personId", "countryIsoCode"]) XCTAssertTrue(indexes[i].isUnique) @@ -57,15 +55,15 @@ class IndexInfoTests: GRDBTestCase { func testColumnsThatUniquelyIdentityRows() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT, email TEXT UNIQUE)") + try db.execute(sql: "CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT, email TEXT UNIQUE)") try XCTAssertTrue(db.table("persons", hasUniqueKey: ["id"])) try XCTAssertTrue(db.table("persons", hasUniqueKey: ["email"])) try XCTAssertFalse(db.table("persons", hasUniqueKey: [])) try XCTAssertFalse(db.table("persons", hasUniqueKey: ["name"])) try XCTAssertFalse(db.table("persons", hasUniqueKey: ["id", "email"])) - try db.execute("CREATE TABLE citizenships (year INTEGER, personId INTEGER NOT NULL, countryIsoCode TEXT NOT NULL, PRIMARY KEY (personId, countryIsoCode))") - try db.execute("CREATE INDEX citizenshipsOnYear ON citizenships(year)") + try db.execute(sql: "CREATE TABLE citizenships (year INTEGER, personId INTEGER NOT NULL, countryIsoCode TEXT NOT NULL, PRIMARY KEY (personId, countryIsoCode))") + try db.execute(sql: "CREATE INDEX citizenshipsOnYear ON citizenships(year)") try XCTAssertTrue(db.table("citizenships", hasUniqueKey: ["personId", "countryIsoCode"])) try XCTAssertTrue(db.table("citizenships", hasUniqueKey: ["countryIsoCode", "personId"])) try XCTAssertFalse(db.table("citizenships", hasUniqueKey: [])) diff --git a/Tests/GRDBTests/InflectionsTests.json b/Tests/GRDBTests/InflectionsTests.json new file mode 100644 index 000000000..872132256 --- /dev/null +++ b/Tests/GRDBTests/InflectionsTests.json @@ -0,0 +1,140 @@ +{ + "SingularToPlural": { + "search" : "searches", + "switch" : "switches", + "fix" : "fixes", + "box" : "boxes", + "process" : "processes", + "address" : "addresses", + "case" : "cases", + "stack" : "stacks", + "wish" : "wishes", + "fish" : "fish", + "sheep" : "sheep", + "jeans" : "jeans", + "funky jeans" : "funky jeans", + "my money" : "my money", + + "category" : "categories", + "query" : "queries", + "ability" : "abilities", + "agency" : "agencies", + "movie" : "movies", + + "archive" : "archives", + + "index" : "indices", + + "wife" : "wives", + "safe" : "saves", + "half" : "halves", + + "move" : "moves", + + "salesperson" : "salespeople", + "person" : "people", + + "spokesman" : "spokesmen", + "man" : "men", + "woman" : "women", + + "basis" : "bases", + "diagnosis" : "diagnoses", + "diagnosis_a" : "diagnosis_as", + + "datum" : "data", + "medium" : "media", + "stadium" : "stadia", + "analysis" : "analyses", + "my_analysis" : "my_analyses", + + "node_child" : "node_children", + "child" : "children", + + "experience" : "experiences", + "day" : "days", + + "comment" : "comments", + "foobar" : "foobars", + "newsletter" : "newsletters", + + "old_news" : "old_news", + "news" : "news", + + "series" : "series", + "miniseries" : "miniseries", + "species" : "species", + + "quiz" : "quizzes", + + "perspective" : "perspectives", + + "ox" : "oxen", + "photo" : "photos", + "buffalo" : "buffaloes", + "tomato" : "tomatoes", + "dwarf" : "dwarves", + "elf" : "elves", + "information" : "information", + "equipment" : "equipment", + "bus" : "buses", + "status" : "statuses", + "status_code" : "status_codes", + "mouse" : "mice", + + "louse" : "lice", + "house" : "houses", + "octopus" : "octopi", + "virus" : "viri", + "alias" : "aliases", + "portfolio" : "portfolios", + + "vertex" : "vertices", + "matrix" : "matrices", + "matrix_fu" : "matrix_fus", + + "axis" : "axes", + "taxi" : "taxis", + "testis" : "testes", + "crisis" : "crises", + + "rice" : "rice", + "shoe" : "shoes", + + "horse" : "horses", + "prize" : "prizes", + "edge" : "edges", + + "database" : "databases", + + "slice" : "slices", + "police" : "police", + + "specimen" : "specimens", + "canvas" : "canvases", + "corps" : "corps", + "offspring" : "offspring", + "advice" : "advice", + "thesis" : "theses", + "dice" : "dice", + "kudos" : "kudos", + "life" : "lives", + "leaf" : "leaves", + "proof" : "proofs", + "hero" : "heroes", + "foot" : "feet", + "matrix" : "matrices", + "watch" : "watches" + }, + + "Irregularities": { + "person" : "people", + "man" : "men", + "child" : "children", + "sex" : "sexes", + "move" : "moves", + "cow" : "kine", + "zombie" : "zombies", + "genus" : "genera" + } +} diff --git a/Tests/GRDBTests/InflectionsTests.swift b/Tests/GRDBTests/InflectionsTests.swift new file mode 100644 index 000000000..e8848f9a5 --- /dev/null +++ b/Tests/GRDBTests/InflectionsTests.swift @@ -0,0 +1,292 @@ +import XCTest +#if GRDBCUSTOMSQLITE + @testable import GRDBCustomSQLite +#else + @testable import GRDB +#endif + +// https://github.com/rails/rails/blob/v6.0.0.rc1/activesupport/test/inflector_test.rb +class InflectionsTests: GRDBTestCase { + private var originalInflections: Inflections? + + override func setUp() { + // Dups the singleton before each test, restoring the original inflections later. + originalInflections = Inflections.default + } + + override func tearDown() { + Inflections.default = originalInflections! + } + + // Until SPM tests can load resources, disable this test for SPM. + #if !SWIFT_PACKAGE + private var inflectionTestCases: InflectionTestCases { + let url = Bundle(for: type(of: self)).url(forResource: "InflectionsTests", withExtension: "json")! + let data = try! Data(contentsOf: url) + return try! JSONDecoder().decode(InflectionTestCases.self, from: data) + } + #endif + + func testStartIndexOfLastWord() { + func lastWord(_ string: String) -> String { + return String(string.suffix(from: Inflections.startIndexOfLastWord(string))) + } + XCTAssertEqual(lastWord(""), "") + XCTAssertEqual(lastWord(" "), " ") + XCTAssertEqual(lastWord("_"), "_") + + XCTAssertEqual(lastWord("player"), "player") + XCTAssertEqual(lastWord("Player"), "Player") + XCTAssertEqual(lastWord("PLAYER"), "PLAYER") + + XCTAssertEqual(lastWord(" player"), "player") + XCTAssertEqual(lastWord(" Player"), "Player") + XCTAssertEqual(lastWord(" PLAYER"), "PLAYER") + + XCTAssertEqual(lastWord("_player"), "player") + XCTAssertEqual(lastWord("_Player"), "Player") + XCTAssertEqual(lastWord("_PLAYER"), "PLAYER") + + XCTAssertEqual(lastWord("player score"), "score") + XCTAssertEqual(lastWord("player Score"), "Score") + XCTAssertEqual(lastWord("Player Score"), "Score") + XCTAssertEqual(lastWord("PLAYER SCORE"), "SCORE") + + XCTAssertEqual(lastWord("player_score"), "score") + XCTAssertEqual(lastWord("player_Score"), "Score") + XCTAssertEqual(lastWord("Player_Score"), "Score") + XCTAssertEqual(lastWord("PLAYER_SCORE"), "SCORE") + + XCTAssertEqual(lastWord("playerScore"), "Score") + XCTAssertEqual(lastWord("PlayerScore"), "Score") + + XCTAssertEqual(lastWord("best player score"), "score") + XCTAssertEqual(lastWord("best player Score"), "Score") + XCTAssertEqual(lastWord("Best Player Score"), "Score") + XCTAssertEqual(lastWord("BEST PLAYER SCORE"), "SCORE") + + XCTAssertEqual(lastWord("best_player_score"), "score") + XCTAssertEqual(lastWord("best_player_Score"), "Score") + XCTAssertEqual(lastWord("Best_Player_Score"), "Score") + XCTAssertEqual(lastWord("BEST_PLAYER_SCORE"), "SCORE") + + XCTAssertEqual(lastWord("bestPlayerScore"), "Score") + XCTAssertEqual(lastWord("BestPlayerScore"), "Score") + + XCTAssertEqual(lastWord("player1"), "player1") + XCTAssertEqual(lastWord("Player1"), "Player1") + XCTAssertEqual(lastWord("PLAYER1"), "PLAYER1") + + XCTAssertEqual(lastWord("player score1"), "score1") + XCTAssertEqual(lastWord("player Score1"), "Score1") + XCTAssertEqual(lastWord("Player Score1"), "Score1") + XCTAssertEqual(lastWord("PLAYER SCORE1"), "SCORE1") + + XCTAssertEqual(lastWord("player_score1"), "score1") + XCTAssertEqual(lastWord("player_Score1"), "Score1") + XCTAssertEqual(lastWord("Player_Score1"), "Score1") + XCTAssertEqual(lastWord("PLAYER_SCORE1"), "SCORE1") + + XCTAssertEqual(lastWord("playerScore1"), "Score1") + XCTAssertEqual(lastWord("PlayerScore1"), "Score1") + } + + func testDigitlessRadical() { + XCTAssertEqual("".digitlessRadical, "") + XCTAssertEqual("player".digitlessRadical, "player") + XCTAssertEqual("player0".digitlessRadical, "player") + XCTAssertEqual("player123".digitlessRadical, "player") + } + + func testPluralizePlurals() { + XCTAssertEqual("plurals".pluralized, "plurals") + XCTAssertEqual("Plurals".pluralized, "Plurals") + } + + func testPluralizeEmptyString() { + XCTAssertEqual("".pluralized, "") + } + + func testUncountabilityOfASCIIWord() { + let word = "HTTP" + Inflections.default.uncountableWords([word]) + XCTAssertEqual(word.pluralized, word) + XCTAssertEqual(word.singularized, word) + XCTAssertEqual(word.pluralized, word.singularized) + } + + func testUncountabilityOfNonASCIIWord() { + let word = "猫" + Inflections.default.uncountableWords([word]) + XCTAssertEqual(word.pluralized, word) + XCTAssertEqual(word.singularized, word) + XCTAssertEqual(word.pluralized, word.singularized) + } + + func testUncountableWords() { + for word in Inflections.default.uncountables { + XCTAssertEqual(word.pluralized, word) + XCTAssertEqual(word.singularized, word) + XCTAssertEqual(word.pluralized, word.singularized) + } + } + + func testUncountableCapitalizedWords() { + for word in Inflections.default.uncountables { + XCTAssertEqual(word.capitalized.pluralized, word.capitalized) + XCTAssertEqual(word.capitalized.singularized, word.capitalized) + XCTAssertEqual(word.capitalized.pluralized, word.capitalized.singularized) + } + } + + func testUncountableUppercasedWords() { + for word in Inflections.default.uncountables { + XCTAssertEqual(word.uppercased().pluralized, word.uppercased()) + XCTAssertEqual(word.uppercased().singularized, word.uppercased()) + XCTAssertEqual(word.uppercased().pluralized, word.uppercased().singularized) + } + } + + func testUncountableWordIsNotGreedy() { + let uncountableWord = "ors" + let countableWord = "sponsor" + + Inflections.default.uncountableWords([uncountableWord]) + + XCTAssertEqual(uncountableWord.singularized, uncountableWord) + XCTAssertEqual(uncountableWord.pluralized, uncountableWord) + XCTAssertEqual(uncountableWord.pluralized, uncountableWord.singularized) + + XCTAssertEqual(countableWord.singularized, "sponsor") + XCTAssertEqual(countableWord.pluralized, "sponsors") + XCTAssertEqual(countableWord.pluralized.singularized, "sponsor") + } + + // Until SPM tests can load resources, disable this test for SPM. + #if !SWIFT_PACKAGE + func testPluralizeSingularWord() { + for (singular, plural) in inflectionTestCases.testCases["SingularToPlural"]! { + XCTAssertEqual(singular.pluralized, plural) + XCTAssertEqual(singular.capitalized.pluralized, plural.capitalized) + + let prefixedSingular = "prefixed" + singular.capitalized + let prefixedPlural = "prefixed" + plural.capitalized + XCTAssertEqual(prefixedSingular.pluralized, prefixedPlural) + + let suffixedSingular = singular + "123" + let suffixedPlural = plural + "123" + XCTAssertEqual(suffixedSingular.pluralized, suffixedPlural) + } + } + #endif + + // Until SPM tests can load resources, disable this test for SPM. + #if !SWIFT_PACKAGE + func testSingularizePluralWord() { + for (singular, plural) in inflectionTestCases.testCases["SingularToPlural"]! { + XCTAssertEqual(plural.singularized, singular) + XCTAssertEqual(plural.capitalized.singularized, singular.capitalized) + + let prefixedSingular = "prefixed" + singular.capitalized + let prefixedPlural = "prefixed" + plural.capitalized + XCTAssertEqual(prefixedPlural.singularized, prefixedSingular) + + let suffixedSingular = singular + "123" + let suffixedPlural = plural + "123" + XCTAssertEqual(suffixedPlural.singularized, suffixedSingular) + } + } + #endif + + // Until SPM tests can load resources, disable this test for SPM. + #if !SWIFT_PACKAGE + func testPluralizePluralWord() { + for (_, plural) in inflectionTestCases.testCases["SingularToPlural"]! { + XCTAssertEqual(plural.pluralized, plural) + XCTAssertEqual(plural.capitalized.pluralized, plural.capitalized) + + let prefixedPlural = "prefixed" + plural.capitalized + XCTAssertEqual(prefixedPlural.pluralized, prefixedPlural) + + let suffixedPlural = plural + "123" + XCTAssertEqual(suffixedPlural.pluralized, suffixedPlural) + } + } + #endif + + // Until SPM tests can load resources, disable this test for SPM. + #if !SWIFT_PACKAGE + func testSingularizeSingularWord() { + for (singular, _) in inflectionTestCases.testCases["SingularToPlural"]! { + XCTAssertEqual(singular.singularized, singular) + XCTAssertEqual(singular.capitalized.singularized, singular.capitalized) + + let prefixedSingular = "prefixed" + singular.capitalized + XCTAssertEqual(prefixedSingular.singularized, prefixedSingular) + + let suffixedSingular = singular + "123" + XCTAssertEqual(suffixedSingular.singularized, suffixedSingular) + } + } + #endif + + // Until SPM tests can load resources, disable this test for SPM. + #if !SWIFT_PACKAGE + func testIrregularityBetweenSingularAndPlural() { + for (singular, plural) in inflectionTestCases.testCases["Irregularities"]! { + Inflections.default.irregularSuffix(singular, plural) + XCTAssertEqual(plural.singularized, singular) + XCTAssertEqual(singular.pluralized, plural) + XCTAssertEqual(singular.singularized, singular) + XCTAssertEqual(plural.pluralized, plural) + + let prefixedSingular = "prefixed" + singular.capitalized + let prefixedPlural = "prefixed" + plural.capitalized + XCTAssertEqual(prefixedPlural.singularized, prefixedSingular) + XCTAssertEqual(prefixedSingular.pluralized, prefixedPlural) + XCTAssertEqual(prefixedSingular.singularized, prefixedSingular) + XCTAssertEqual(prefixedPlural.pluralized, prefixedPlural) + + let suffixedSingular = singular + "123" + let suffixedPlural = plural + "123" + XCTAssertEqual(suffixedPlural.singularized, suffixedSingular) + XCTAssertEqual(suffixedSingular.pluralized, suffixedPlural) + XCTAssertEqual(suffixedSingular.singularized, suffixedSingular) + XCTAssertEqual(suffixedPlural.pluralized, suffixedPlural) + } + } + #endif +} + +// Until SPM tests can load resources, disable this test for SPM. +#if !SWIFT_PACKAGE +struct InflectionTestCases: Decodable { + var testCases: [String: [(String, String)]] + + struct AnyCodingKey: CodingKey { + var stringValue: String + var intValue: Int? { return nil } + + init?(stringValue: String) { + self.stringValue = stringValue + } + + init?(intValue: Int) { + return nil + } + } + + init(from decoder: Decoder) throws { + var testCases: [String: [(String, String)]] = [:] + let container = try decoder.container(keyedBy: AnyCodingKey.self) + for key in container.allKeys { + let nested = try container.nestedContainer(keyedBy: AnyCodingKey.self, forKey: key) + for wordKey in nested.allKeys { + let otherWord = try nested.decode(String.self, forKey: wordKey) + testCases[key.stringValue, default: []].append((wordKey.stringValue, otherWord)) + } + } + self.testCases = testCases + } +} +#endif diff --git a/Tests/GRDBTests/JoinSupportTests.swift b/Tests/GRDBTests/JoinSupportTests.swift index f436c4965..bea35f0fd 100644 --- a/Tests/GRDBTests/JoinSupportTests.swift +++ b/Tests/GRDBTests/JoinSupportTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -99,7 +97,7 @@ private struct FlatModel: FetchableRecord { } static func all() -> AdaptedFetchRequest> { - return SQLRequest(testedSQL).adapted { db in + return SQLRequest(sql: testedSQL).adapted { db in let adapters = try splittingRowAdapters(columnCounts: [ T1.numberOfSelectedColumns(db), T2.numberOfSelectedColumns(db), @@ -115,7 +113,7 @@ private struct FlatModel: FetchableRecord { } static func hierarchicalAll() -> AdaptedFetchRequest> { - return SQLRequest(testedSQL).adapted { db in + return SQLRequest(sql: testedSQL).adapted { db in let adapters = try splittingRowAdapters(columnCounts: [ T1.numberOfSelectedColumns(db), T2.numberOfSelectedColumns(db), @@ -140,7 +138,7 @@ private struct CodableFlatModel: FetchableRecord, Codable { var t5count: Int static func all() -> AdaptedFetchRequest> { - return SQLRequest(testedSQL).adapted { db in + return SQLRequest(sql: testedSQL).adapted { db in let adapters = try splittingRowAdapters(columnCounts: [ T1.numberOfSelectedColumns(db), T2.numberOfSelectedColumns(db), @@ -155,7 +153,7 @@ private struct CodableFlatModel: FetchableRecord, Codable { } static func hierarchicalAll() -> AdaptedFetchRequest> { - return SQLRequest(testedSQL).adapted { db in + return SQLRequest(sql: testedSQL).adapted { db in let adapters = try splittingRowAdapters(columnCounts: [ T1.numberOfSelectedColumns(db), T2.numberOfSelectedColumns(db), @@ -183,7 +181,7 @@ private struct CodableNestedModel: FetchableRecord, Codable { var t5count: Int static func all() -> AdaptedFetchRequest> { - return SQLRequest(testedSQL).adapted { db in + return SQLRequest(sql: testedSQL).adapted { db in let adapters = try splittingRowAdapters(columnCounts: [ T1.numberOfSelectedColumns(db), T2.numberOfSelectedColumns(db), @@ -235,7 +233,7 @@ class JoinSupportTests: GRDBTestCase { // Sample data - try db.execute(""" + try db.execute(sql: """ INSERT INTO t1 (id, name) VALUES (1, 'A1'); INSERT INTO t1 (id, name) VALUES (2, 'A2'); INSERT INTO t1 (id, name) VALUES (3, 'A3'); @@ -259,7 +257,7 @@ class JoinSupportTests: GRDBTestCase { func testSampleData() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let rows = try Row.fetchAll(db, expectedSQL) + let rows = try Row.fetchAll(db, sql: expectedSQL) XCTAssertEqual(rows.count, 3) XCTAssertEqual(rows[0], [ // t1.* @@ -304,7 +302,7 @@ class JoinSupportTests: GRDBTestCase { func testSplittingRowAdapters() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let request = SQLRequest(testedSQL).adapted { db in + let request = SQLRequest(sql: testedSQL).adapted { db in let adapters = try splittingRowAdapters(columnCounts: [ T1.numberOfSelectedColumns(db), T2.numberOfSelectedColumns(db), diff --git a/Tests/GRDBTests/MapCursorTests.swift b/Tests/GRDBTests/MapCursorTests.swift index 56a647325..1cc334519 100644 --- a/Tests/GRDBTests/MapCursorTests.swift +++ b/Tests/GRDBTests/MapCursorTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/MutablePersistableRecordChangesTests.swift b/Tests/GRDBTests/MutablePersistableRecordChangesTests.swift index 0ab1ccccb..10a8824d7 100644 --- a/Tests/GRDBTests/MutablePersistableRecordChangesTests.swift +++ b/Tests/GRDBTests/MutablePersistableRecordChangesTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -48,7 +46,7 @@ class MutablePersistableRecordChangesTests: GRDBTestCase { func testDegenerateDatabaseEqualsWithSelf() throws { struct DegenerateRecord: MutablePersistableRecord { - static let databaseTableName = "ignored" + static let databaseTableName = "degenerated" func encode(to container: inout PersistenceContainer) { } } @@ -58,6 +56,10 @@ class MutablePersistableRecordChangesTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in + // table must exist + try db.create(table: DegenerateRecord.databaseTableName) { t in + t.autoIncrementedPrimaryKey("id") + } let totalChangesCount = db.totalChangesCount try XCTAssertFalse(record.updateChanges(db, from: record)) XCTAssertEqual(db.totalChangesCount, totalChangesCount) diff --git a/Tests/GRDBTests/MutablePersistableRecordDeleteTests.swift b/Tests/GRDBTests/MutablePersistableRecordDeleteTests.swift index 2a8318ae7..62e1307ad 100644 --- a/Tests/GRDBTests/MutablePersistableRecordDeleteTests.swift +++ b/Tests/GRDBTests/MutablePersistableRecordDeleteTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -27,9 +25,9 @@ class MutablePersistableRecordDeleteTests: GRDBTestCase { override func setup(_ dbWriter: DatabaseWriter) throws { try dbWriter.write { db in - try db.execute("CREATE TABLE hackers (name TEXT)") - try db.execute("CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT, email TEXT UNIQUE)") - try db.execute("CREATE TABLE citizenships (personId INTEGER NOT NULL, countryIsoCode TEXT NOT NULL, PRIMARY KEY (personId, countryIsoCode))") + try db.execute(sql: "CREATE TABLE hackers (name TEXT)") + try db.execute(sql: "CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT, email TEXT UNIQUE)") + try db.execute(sql: "CREATE TABLE citizenships (personId INTEGER NOT NULL, countryIsoCode TEXT NOT NULL, PRIMARY KEY (personId, countryIsoCode))") } } @@ -40,14 +38,14 @@ class MutablePersistableRecordDeleteTests: GRDBTestCase { XCTAssertEqual(self.lastSQLQuery, "DELETE FROM \"hackers\" WHERE (\"rowid\" = 1)") XCTAssertFalse(deleted) - try db.execute("INSERT INTO hackers (rowid, name) VALUES (?, ?)", arguments: [1, "Arthur"]) + try db.execute(sql: "INSERT INTO hackers (rowid, name) VALUES (?, ?)", arguments: [1, "Arthur"]) deleted = try Hacker.deleteOne(db, key: 1) XCTAssertTrue(deleted) XCTAssertEqual(try Hacker.fetchCount(db), 0) - try db.execute("INSERT INTO hackers (rowid, name) VALUES (?, ?)", arguments: [1, "Arthur"]) - try db.execute("INSERT INTO hackers (rowid, name) VALUES (?, ?)", arguments: [2, "Barbara"]) - try db.execute("INSERT INTO hackers (rowid, name) VALUES (?, ?)", arguments: [3, "Craig"]) + try db.execute(sql: "INSERT INTO hackers (rowid, name) VALUES (?, ?)", arguments: [1, "Arthur"]) + try db.execute(sql: "INSERT INTO hackers (rowid, name) VALUES (?, ?)", arguments: [2, "Barbara"]) + try db.execute(sql: "INSERT INTO hackers (rowid, name) VALUES (?, ?)", arguments: [3, "Craig"]) let deletedCount = try Hacker.deleteAll(db, keys: [2, 3, 4]) XCTAssertEqual(self.lastSQLQuery, "DELETE FROM \"hackers\" WHERE (\"rowid\" IN (2, 3, 4))") XCTAssertEqual(deletedCount, 2) @@ -62,14 +60,14 @@ class MutablePersistableRecordDeleteTests: GRDBTestCase { XCTAssertEqual(self.lastSQLQuery, "DELETE FROM \"persons\" WHERE (\"id\" = 1)") XCTAssertFalse(deleted) - try db.execute("INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [1, "Arthur", "arthur@example.com"]) + try db.execute(sql: "INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [1, "Arthur", "arthur@example.com"]) deleted = try Person.deleteOne(db, key: 1) XCTAssertTrue(deleted) XCTAssertEqual(try Person.fetchCount(db), 0) - try db.execute("INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [1, "Arthur", "arthur@example.com"]) - try db.execute("INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [2, "Barbara", "barbara@example.com"]) - try db.execute("INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [3, "Craig", "craig@example.com"]) + try db.execute(sql: "INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [1, "Arthur", "arthur@example.com"]) + try db.execute(sql: "INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [2, "Barbara", "barbara@example.com"]) + try db.execute(sql: "INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [3, "Craig", "craig@example.com"]) let deletedCount = try Person.deleteAll(db, keys: [2, 3, 4]) XCTAssertEqual(self.lastSQLQuery, "DELETE FROM \"persons\" WHERE (\"id\" IN (2, 3, 4))") XCTAssertEqual(deletedCount, 2) @@ -84,14 +82,14 @@ class MutablePersistableRecordDeleteTests: GRDBTestCase { XCTAssertEqual(self.lastSQLQuery, "DELETE FROM \"citizenships\" WHERE ((\"personId\" = 1) AND (\"countryIsoCode\" = 'FR'))") XCTAssertFalse(deleted) - try db.execute("INSERT INTO citizenships (personId, countryIsoCode) VALUES (?, ?)", arguments: [1, "FR"]) + try db.execute(sql: "INSERT INTO citizenships (personId, countryIsoCode) VALUES (?, ?)", arguments: [1, "FR"]) deleted = try Citizenship.deleteOne(db, key: ["personId": 1, "countryIsoCode": "FR"]) XCTAssertTrue(deleted) XCTAssertEqual(try Citizenship.fetchCount(db), 0) - try db.execute("INSERT INTO citizenships (personId, countryIsoCode) VALUES (?, ?)", arguments: [1, "FR"]) - try db.execute("INSERT INTO citizenships (personId, countryIsoCode) VALUES (?, ?)", arguments: [1, "US"]) - try db.execute("INSERT INTO citizenships (personId, countryIsoCode) VALUES (?, ?)", arguments: [2, "US"]) + try db.execute(sql: "INSERT INTO citizenships (personId, countryIsoCode) VALUES (?, ?)", arguments: [1, "FR"]) + try db.execute(sql: "INSERT INTO citizenships (personId, countryIsoCode) VALUES (?, ?)", arguments: [1, "US"]) + try db.execute(sql: "INSERT INTO citizenships (personId, countryIsoCode) VALUES (?, ?)", arguments: [2, "US"]) let deletedCount = try Citizenship.deleteAll(db, keys: [["personId": 1, "countryIsoCode": "FR"], ["personId": 1, "countryIsoCode": "US"], ["personId": 1, "countryIsoCode": "DE"]]) XCTAssertEqual(deletedCount, 2) XCTAssertEqual(try Citizenship.fetchCount(db), 1) @@ -105,14 +103,14 @@ class MutablePersistableRecordDeleteTests: GRDBTestCase { XCTAssertEqual(self.lastSQLQuery, "DELETE FROM \"persons\" WHERE (\"email\" = 'arthur@example.com')") XCTAssertFalse(deleted) - try db.execute("INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [1, "Arthur", "arthur@example.com"]) + try db.execute(sql: "INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [1, "Arthur", "arthur@example.com"]) deleted = try Person.deleteOne(db, key: ["email": "arthur@example.com"]) XCTAssertTrue(deleted) XCTAssertEqual(try Person.fetchCount(db), 0) - try db.execute("INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [1, "Arthur", "arthur@example.com"]) - try db.execute("INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [2, "Barbara", "barbara@example.com"]) - try db.execute("INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [3, "Craig", "craig@example.com"]) + try db.execute(sql: "INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [1, "Arthur", "arthur@example.com"]) + try db.execute(sql: "INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [2, "Barbara", "barbara@example.com"]) + try db.execute(sql: "INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [3, "Craig", "craig@example.com"]) let deletedCount = try Person.deleteAll(db, keys: [["email": "arthur@example.com"], ["email": "barbara@example.com"], ["email": "david@example.com"]]) XCTAssertEqual(deletedCount, 2) XCTAssertEqual(try Person.fetchCount(db), 1) @@ -126,14 +124,14 @@ class MutablePersistableRecordDeleteTests: GRDBTestCase { XCTAssertEqual(self.lastSQLQuery, "DELETE FROM \"persons\" WHERE (\"id\" = 1)") XCTAssertFalse(deleted) - try db.execute("INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [1, "Arthur", "arthur@example.com"]) + try db.execute(sql: "INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [1, "Arthur", "arthur@example.com"]) deleted = try Person.deleteOne(db, key: ["id": 1]) XCTAssertTrue(deleted) XCTAssertEqual(try Person.fetchCount(db), 0) - try db.execute("INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [1, "Arthur", "arthur@example.com"]) - try db.execute("INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [2, "Barbara", "barbara@example.com"]) - try db.execute("INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [3, "Craig", "craig@example.com"]) + try db.execute(sql: "INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [1, "Arthur", "arthur@example.com"]) + try db.execute(sql: "INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [2, "Barbara", "barbara@example.com"]) + try db.execute(sql: "INSERT INTO persons (id, name, email) VALUES (?, ?, ?)", arguments: [3, "Craig", "craig@example.com"]) let deletedCount = try Person.deleteAll(db, keys: [["id": 2], ["id": 3], ["id": 4]]) XCTAssertEqual(deletedCount, 2) XCTAssertEqual(try Person.fetchCount(db), 1) @@ -161,7 +159,7 @@ class MutablePersistableRecordDeleteTests: GRDBTestCase { // TODO: find out when ENABLE_UPDATE_DELETE_LIMIT is not there. // iOS8.1 can't run those tests, for example. - if try String.fetchAll(db, "PRAGMA COMPILE_OPTIONS").contains("ENABLE_UPDATE_DELETE_LIMIT") { + if try String.fetchAll(db, sql: "PRAGMA COMPILE_OPTIONS").contains("ENABLE_UPDATE_DELETE_LIMIT") { try Person.limit(1).deleteAll(db) XCTAssertEqual(self.lastSQLQuery, "DELETE FROM \"persons\" LIMIT 1") diff --git a/Tests/GRDBTests/MutablePersistableRecordEncodableTests.swift b/Tests/GRDBTests/MutablePersistableRecordEncodableTests.swift index 6d166a88e..2ad5815f7 100644 --- a/Tests/GRDBTests/MutablePersistableRecordEncodableTests.swift +++ b/Tests/GRDBTests/MutablePersistableRecordEncodableTests.swift @@ -1,8 +1,6 @@ import XCTest import Foundation -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -30,7 +28,7 @@ extension MutablePersistableRecordEncodableTests { assert(value, isEncodedIn: ["value": "foo"]) try value.insert(db) - let string = try String.fetchOne(db, "SELECT value FROM t1")! + let string = try String.fetchOne(db, sql: "SELECT value FROM t1")! XCTAssertEqual(string, "foo") } } @@ -60,7 +58,7 @@ extension MutablePersistableRecordEncodableTests { assert(value, isEncodedIn: ["someColumn": "foo (Encodable)"]) try value.insert(db) - let string = try String.fetchOne(db, "SELECT someColumn FROM t1")! + let string = try String.fetchOne(db, sql: "SELECT someColumn FROM t1")! XCTAssertEqual(string, "foo (Encodable)") } } @@ -85,7 +83,7 @@ extension MutablePersistableRecordEncodableTests { assert(value, isEncodedIn: ["value": "foo (MutablePersistableRecord)"]) try value.insert(db) - let string = try String.fetchOne(db, "SELECT value FROM t1")! + let string = try String.fetchOne(db, sql: "SELECT value FROM t1")! XCTAssertEqual(string, "foo (MutablePersistableRecord)") } } @@ -115,7 +113,7 @@ extension MutablePersistableRecordEncodableTests { assert(value, isEncodedIn: ["int64": 123, "optionalInt64": 456]) try value.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM t1")! + let row = try Row.fetchOne(db, sql: "SELECT * FROM t1")! XCTAssertEqual(row, ["int64": 123, "optionalInt64": 456]) return .rollback } @@ -125,7 +123,7 @@ extension MutablePersistableRecordEncodableTests { assert(value, isEncodedIn: ["int64": 123, "optionalInt64": nil]) try value.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM t1")! + let row = try Row.fetchOne(db, sql: "SELECT * FROM t1")! XCTAssertEqual(row, ["int64": 123, "optionalInt64": nil]) return .rollback } @@ -160,7 +158,7 @@ extension MutablePersistableRecordEncodableTests { assert(value, isEncodedIn: ["value": "foo", "optionalValue": "bar"]) try value.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM t1")! + let row = try Row.fetchOne(db, sql: "SELECT * FROM t1")! XCTAssertEqual(row, ["value": "foo", "optionalValue": "bar"]) return .rollback } @@ -170,7 +168,7 @@ extension MutablePersistableRecordEncodableTests { assert(value, isEncodedIn: ["value": "foo", "optionalValue": nil]) try value.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM t1")! + let row = try Row.fetchOne(db, sql: "SELECT * FROM t1")! XCTAssertEqual(row, ["value": "foo", "optionalValue": nil]) return .rollback } @@ -214,7 +212,7 @@ extension MutablePersistableRecordEncodableTests { assert(value, isEncodedIn: ["value": "foo", "optionalValue": "bar"]) try value.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM t1")! + let row = try Row.fetchOne(db, sql: "SELECT * FROM t1")! XCTAssertEqual(row, ["value": "foo", "optionalValue": "bar"]) return .rollback } @@ -224,7 +222,7 @@ extension MutablePersistableRecordEncodableTests { assert(value, isEncodedIn: ["value": "foo", "optionalValue": nil]) try value.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM t1")! + let row = try Row.fetchOne(db, sql: "SELECT * FROM t1")! XCTAssertEqual(row, ["value": "foo", "optionalValue": nil]) return .rollback } @@ -259,7 +257,7 @@ extension MutablePersistableRecordEncodableTests { assert(value, isEncodedIn: ["value": "foo", "optionalValue": "bar"]) try value.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM t1")! + let row = try Row.fetchOne(db, sql: "SELECT * FROM t1")! XCTAssertEqual(row, ["value": "foo", "optionalValue": "bar"]) return .rollback } @@ -269,7 +267,7 @@ extension MutablePersistableRecordEncodableTests { assert(value, isEncodedIn: ["value": "foo", "optionalValue": nil]) try value.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM t1")! + let row = try Row.fetchOne(db, sql: "SELECT * FROM t1")! XCTAssertEqual(row, ["value": "foo", "optionalValue": nil]) return .rollback } @@ -322,7 +320,7 @@ extension MutablePersistableRecordEncodableTests { assert(value, isEncodedIn: ["value": "foo (DatabaseValueConvertible)", "optionalValue": "bar (DatabaseValueConvertible)"]) try value.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM t1")! + let row = try Row.fetchOne(db, sql: "SELECT * FROM t1")! XCTAssertEqual(row, ["value": "foo (DatabaseValueConvertible)", "optionalValue": "bar (DatabaseValueConvertible)"]) return .rollback } @@ -332,7 +330,7 @@ extension MutablePersistableRecordEncodableTests { assert(value, isEncodedIn: ["value": "foo (DatabaseValueConvertible)", "optionalValue": nil]) try value.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM t1")! + let row = try Row.fetchOne(db, sql: "SELECT * FROM t1")! XCTAssertEqual(row, ["value": "foo (DatabaseValueConvertible)", "optionalValue": nil]) return .rollback } @@ -358,7 +356,7 @@ extension MutablePersistableRecordEncodableTests { let value = StructWithDate(date: Date()) try value.insert(db) - let dbValue = try DatabaseValue.fetchOne(db, "SELECT date FROM t1")! + let dbValue = try DatabaseValue.fetchOne(db, sql: "SELECT date FROM t1")! // Date has a default Encodable implementation which encodes a Double. // We expect here a String, because DatabaseValueConvertible has @@ -386,7 +384,7 @@ extension MutablePersistableRecordEncodableTests { assert(value, isEncodedIn: ["url": value.url]) try value.insert(db) - let dbValue = try DatabaseValue.fetchOne(db, "SELECT url FROM t1")! + let dbValue = try DatabaseValue.fetchOne(db, sql: "SELECT url FROM t1")! XCTAssert(dbValue.storage.value is String) let fetchedURL = URL.fromDatabaseValue(dbValue)! XCTAssertEqual(fetchedURL, value.url) @@ -409,7 +407,7 @@ extension MutablePersistableRecordEncodableTests { assert(value, isEncodedIn: ["uuid": value.uuid]) try value.insert(db) - let dbValue = try DatabaseValue.fetchOne(db, "SELECT uuid FROM t1")! + let dbValue = try DatabaseValue.fetchOne(db, sql: "SELECT uuid FROM t1")! XCTAssert(dbValue.storage.value is Data) let fetchedUUID = UUID.fromDatabaseValue(dbValue)! XCTAssertEqual(fetchedUUID, value.uuid) @@ -432,7 +430,7 @@ extension MutablePersistableRecordEncodableTests { try Record(array: ["foo"]).insert(db) try Record(array: ["foo", "bar"]).insert(db) - let rows = try Row.fetchAll(db, "SELECT * FROM record ORDER BY id") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM record ORDER BY id") XCTAssertEqual(rows.count, 3) XCTAssertEqual(rows[0]["array"], "[]") XCTAssertEqual(rows[1]["array"], "[\"foo\"]") @@ -457,7 +455,7 @@ extension MutablePersistableRecordEncodableTests { try Record(array: ["foo"]).insert(db) try Record(array: ["foo", "bar"]).insert(db) - let rows = try Row.fetchAll(db, "SELECT * FROM record ORDER BY id") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM record ORDER BY id") XCTAssertEqual(rows.count, 4) XCTAssertTrue(rows[0]["array"] == nil) XCTAssertEqual(rows[1]["array"], "[]") @@ -481,7 +479,7 @@ extension MutablePersistableRecordEncodableTests { try Record(dictionary: [:]).insert(db) try Record(dictionary: ["foo": 1]).insert(db) - let rows = try Row.fetchAll(db, "SELECT * FROM record ORDER BY id") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM record ORDER BY id") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["dictionary"], "{}") XCTAssertEqual(rows[1]["dictionary"], "{\"foo\":1}") @@ -504,7 +502,7 @@ extension MutablePersistableRecordEncodableTests { try Record(dictionary: [:]).insert(db) try Record(dictionary: ["foo": 1]).insert(db) - let rows = try Row.fetchAll(db, "SELECT * FROM record ORDER BY id") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM record ORDER BY id") XCTAssertEqual(rows.count, 3) XCTAssertTrue(rows[0]["dictionary"] == nil) XCTAssertEqual(rows[1]["dictionary"], "{}") diff --git a/Tests/GRDBTests/MutablePersistableRecordPersistenceConflictPolicyTests.swift b/Tests/GRDBTests/MutablePersistableRecordPersistenceConflictPolicyTests.swift index 02deef3a3..6694564a0 100644 --- a/Tests/GRDBTests/MutablePersistableRecordPersistenceConflictPolicyTests.swift +++ b/Tests/GRDBTests/MutablePersistableRecordPersistenceConflictPolicyTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -232,7 +230,7 @@ class MutablePersistableRecordPersistenceConflictPolicyTests: GRDBTestCase { record.email = "arthur@example.com" try record.update(db) XCTAssertTrue(try ReplacePolicy.fetchCount(db) == 1) - XCTAssertEqual(try Int64.fetchOne(db, "SELECT id FROM records")!, 3) + XCTAssertEqual(try Int64.fetchOne(db, sql: "SELECT id FROM records")!, 3) XCTAssertEqual(observer.events.count, 1) XCTAssertEqual(observer.events[0].kind, .update) XCTAssertEqual(observer.events[0].rowID, 3) diff --git a/Tests/GRDBTests/MutablePersistableRecordTests.swift b/Tests/GRDBTests/MutablePersistableRecordTests.swift index 1f2175db2..9a9ba9c1b 100644 --- a/Tests/GRDBTests/MutablePersistableRecordTests.swift +++ b/Tests/GRDBTests/MutablePersistableRecordTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -95,7 +93,7 @@ class MutablePersistableRecordTests: GRDBTestCase { override func setup(_ dbWriter: DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("setUp") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE persons ( id INTEGER PRIMARY KEY, name NOT NULL, @@ -117,7 +115,7 @@ class MutablePersistableRecordTests: GRDBTestCase { var person = MutablePersistableRecordPerson(id: nil, name: "Arthur", age: 24) try person.insert(db) - let rows = try Row.fetchAll(db, "SELECT * FROM persons") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["id"] as Int64, person.id!) XCTAssertEqual(rows[0]["name"] as String, "Arthur") @@ -139,7 +137,7 @@ class MutablePersistableRecordTests: GRDBTestCase { "UPDATE \"persons\" SET \"name\"='Craig', \"age\"=24 WHERE \"id\"=1" ].contains(self.lastSQLQuery)) - let rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY id") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY id") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["id"] as Int64, person1.id!) XCTAssertEqual(rows[0]["name"] as String, "Craig") @@ -161,7 +159,7 @@ class MutablePersistableRecordTests: GRDBTestCase { try person1.update(db, columns: [String]()) XCTAssertEqual(self.lastSQLQuery, "UPDATE \"persons\" SET \"id\"=1 WHERE \"id\"=1") - let rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY id") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY id") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["id"] as Int64, person1.id!) XCTAssertEqual(rows[0]["name"] as String, "Arthur") @@ -177,7 +175,7 @@ class MutablePersistableRecordTests: GRDBTestCase { try person1.update(db, columns: [Column("name")]) XCTAssertEqual(self.lastSQLQuery, "UPDATE \"persons\" SET \"name\"='Craig' WHERE \"id\"=1") - let rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY id") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY id") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["id"] as Int64, person1.id!) XCTAssertEqual(rows[0]["name"] as String, "Craig") @@ -192,7 +190,7 @@ class MutablePersistableRecordTests: GRDBTestCase { try person1.update(db, columns: ["AgE"]) // case insensitivity XCTAssertEqual(self.lastSQLQuery, "UPDATE \"persons\" SET \"age\"=25 WHERE \"id\"=1") - let rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY id") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY id") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["id"] as Int64, person1.id!) XCTAssertEqual(rows[0]["name"] as String, "Craig") @@ -210,7 +208,7 @@ class MutablePersistableRecordTests: GRDBTestCase { var person1 = MutablePersistableRecordPerson(id: nil, name: "Arthur", age: 24) try person1.save(db) - var rows = try Row.fetchAll(db, "SELECT * FROM persons") + var rows = try Row.fetchAll(db, sql: "SELECT * FROM persons") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["id"] as Int64, person1.id!) XCTAssertEqual(rows[0]["name"] as String, "Arthur") @@ -221,7 +219,7 @@ class MutablePersistableRecordTests: GRDBTestCase { person1.name = "Craig" try person1.save(db) - rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY id") + rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY id") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["id"] as Int64, person1.id!) XCTAssertEqual(rows[0]["name"] as String, "Craig") @@ -231,7 +229,7 @@ class MutablePersistableRecordTests: GRDBTestCase { try person1.delete(db) try person1.save(db) - rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY id") + rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY id") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["id"] as Int64, person1.id!) XCTAssertEqual(rows[0]["name"] as String, "Craig") @@ -253,7 +251,7 @@ class MutablePersistableRecordTests: GRDBTestCase { deleted = try person1.delete(db) XCTAssertFalse(deleted) - let rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY id") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY id") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["id"] as Int64, person2.id!) XCTAssertEqual(rows[0]["name"] as String, "Barbara") @@ -286,7 +284,7 @@ class MutablePersistableRecordTests: GRDBTestCase { var country = MutablePersistableRecordCountry(rowID: nil, isoCode: "FR", name: "France") try country.insert(db) - let rows = try Row.fetchAll(db, "SELECT rowID, * FROM countries") + let rows = try Row.fetchAll(db, sql: "SELECT rowID, * FROM countries") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["rowID"] as Int64, country.rowID!) XCTAssertEqual(rows[0]["name"] as String, "France") @@ -305,7 +303,7 @@ class MutablePersistableRecordTests: GRDBTestCase { try country1.update(db) XCTAssertEqual(self.lastSQLQuery, "UPDATE \"countries\" SET \"name\"='France Métropolitaine' WHERE \"isoCode\"='FR'") - let rows = try Row.fetchAll(db, "SELECT rowID, * FROM countries ORDER BY rowID") + let rows = try Row.fetchAll(db, sql: "SELECT rowID, * FROM countries ORDER BY rowID") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["rowID"] as Int64, country1.rowID!) XCTAssertEqual(rows[0]["name"] as String, "France Métropolitaine") @@ -320,7 +318,7 @@ class MutablePersistableRecordTests: GRDBTestCase { var country1 = MutablePersistableRecordCountry(rowID: nil, isoCode: "FR", name: "France") try country1.save(db) - var rows = try Row.fetchAll(db, "SELECT rowID, * FROM countries") + var rows = try Row.fetchAll(db, sql: "SELECT rowID, * FROM countries") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["rowID"] as Int64, country1.rowID!) XCTAssertEqual(rows[0]["name"] as String, "France") @@ -331,7 +329,7 @@ class MutablePersistableRecordTests: GRDBTestCase { country1.name = "France Métropolitaine" try country1.save(db) - rows = try Row.fetchAll(db, "SELECT rowID, * FROM countries ORDER BY rowID") + rows = try Row.fetchAll(db, sql: "SELECT rowID, * FROM countries ORDER BY rowID") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["rowID"] as Int64, country1.rowID!) XCTAssertEqual(rows[0]["name"] as String, "France Métropolitaine") @@ -341,7 +339,7 @@ class MutablePersistableRecordTests: GRDBTestCase { try country1.delete(db) try country1.save(db) - rows = try Row.fetchAll(db, "SELECT rowID, * FROM countries ORDER BY rowID") + rows = try Row.fetchAll(db, sql: "SELECT rowID, * FROM countries ORDER BY rowID") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["rowID"] as Int64, country2.rowID!) XCTAssertEqual(rows[0]["name"] as String, "United States") @@ -363,7 +361,7 @@ class MutablePersistableRecordTests: GRDBTestCase { deleted = try country1.delete(db) XCTAssertFalse(deleted) - let rows = try Row.fetchAll(db, "SELECT rowID, * FROM countries ORDER BY rowID") + let rows = try Row.fetchAll(db, sql: "SELECT rowID, * FROM countries ORDER BY rowID") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["rowID"] as Int64, country2.rowID!) XCTAssertEqual(rows[0]["name"] as String, "United States") @@ -410,7 +408,7 @@ class MutablePersistableRecordTests: GRDBTestCase { XCTAssertEqual(deleteCount, 0) XCTAssertEqual(existsCount, 0) - let rows = try Row.fetchAll(db, "SELECT rowID, * FROM countries") + let rows = try Row.fetchAll(db, sql: "SELECT rowID, * FROM countries") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["rowID"] as Int64, country.rowID!) XCTAssertEqual(rows[0]["name"] as String, "France") @@ -456,7 +454,7 @@ class MutablePersistableRecordTests: GRDBTestCase { XCTAssertEqual(deleteCount, 0) XCTAssertEqual(existsCount, 0) - let rows = try Row.fetchAll(db, "SELECT rowID, * FROM countries ORDER BY rowID") + let rows = try Row.fetchAll(db, sql: "SELECT rowID, * FROM countries ORDER BY rowID") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["rowID"] as Int64, country1.rowID!) XCTAssertEqual(rows[0]["name"] as String, "France Métropolitaine") @@ -490,7 +488,7 @@ class MutablePersistableRecordTests: GRDBTestCase { XCTAssertEqual(deleteCount, 0) XCTAssertEqual(existsCount, 0) - var rows = try Row.fetchAll(db, "SELECT rowID, * FROM countries") + var rows = try Row.fetchAll(db, sql: "SELECT rowID, * FROM countries") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["rowID"] as Int64, country1.rowID!) XCTAssertEqual(rows[0]["name"] as String, "France") @@ -515,7 +513,7 @@ class MutablePersistableRecordTests: GRDBTestCase { XCTAssertEqual(deleteCount, 0) XCTAssertEqual(existsCount, 0) - rows = try Row.fetchAll(db, "SELECT rowID, * FROM countries ORDER BY rowID") + rows = try Row.fetchAll(db, sql: "SELECT rowID, * FROM countries ORDER BY rowID") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["rowID"] as Int64, country1.rowID!) XCTAssertEqual(rows[0]["name"] as String, "France Métropolitaine") @@ -531,7 +529,7 @@ class MutablePersistableRecordTests: GRDBTestCase { XCTAssertEqual(deleteCount, 1) XCTAssertEqual(existsCount, 0) - rows = try Row.fetchAll(db, "SELECT rowID, * FROM countries ORDER BY rowID") + rows = try Row.fetchAll(db, sql: "SELECT rowID, * FROM countries ORDER BY rowID") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["rowID"] as Int64, country2.rowID!) XCTAssertEqual(rows[0]["name"] as String, "United States") @@ -580,7 +578,7 @@ class MutablePersistableRecordTests: GRDBTestCase { XCTAssertEqual(deleteCount, 2) XCTAssertEqual(existsCount, 0) - let rows = try Row.fetchAll(db, "SELECT rowID, * FROM countries ORDER BY rowID") + let rows = try Row.fetchAll(db, sql: "SELECT rowID, * FROM countries ORDER BY rowID") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["rowID"] as Int64, country2.rowID!) XCTAssertEqual(rows[0]["name"] as String, "United States") @@ -659,24 +657,24 @@ class MutablePersistableRecordTests: GRDBTestCase { ["INSERT INTO \"records\" (\"id\", \"a\") VALUES (NULL,'foo')", "INSERT INTO \"records\" (\"a\", \"id\") VALUES ('foo',NULL)"] .contains(lastSQLQuery)) - XCTAssertEqual(try Row.fetchOne(db, "SELECT * FROM records")!, ["id": 1, "a": "foo", "b": nil, "c": 123]) + XCTAssertEqual(try Row.fetchOne(db, sql: "SELECT * FROM records")!, ["id": 1, "a": "foo", "b": nil, "c": 123]) // Update only updates defined columns record.a = "bar" try record.update(db) XCTAssertEqual(lastSQLQuery, "UPDATE \"records\" SET \"a\"='bar' WHERE \"id\"=1") - XCTAssertEqual(try Row.fetchOne(db, "SELECT * FROM records")!, ["id": 1, "a": "bar", "b": nil, "c": 123]) + XCTAssertEqual(try Row.fetchOne(db, sql: "SELECT * FROM records")!, ["id": 1, "a": "bar", "b": nil, "c": 123]) // Update always update something record.a = "baz" try record.update(db, columns: ["b"]) XCTAssertEqual(lastSQLQuery, "UPDATE \"records\" SET \"id\"=1 WHERE \"id\"=1") - XCTAssertEqual(try Row.fetchOne(db, "SELECT * FROM records")!, ["id": 1, "a": "bar", "b": nil, "c": 123]) + XCTAssertEqual(try Row.fetchOne(db, sql: "SELECT * FROM records")!, ["id": 1, "a": "bar", "b": nil, "c": 123]) // Deletion try record.delete(db) XCTAssertEqual(lastSQLQuery, "DELETE FROM \"records\" WHERE \"id\"=1") - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM records")!, 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM records")!, 0) // Expect database errors when missing columns must have a value try db.drop(table: "records") @@ -696,4 +694,23 @@ class MutablePersistableRecordTests: GRDBTestCase { } } } + + func testPersistenceErrorRecordNotFoundDescription() { + do { + let error = PersistenceError.recordNotFound( + databaseTableName: "place", + key: ["id": .null]) + XCTAssertEqual( + error.description, + "Key not found in table place: [id:NULL]") + } + do { + let error = PersistenceError.recordNotFound( + databaseTableName: "user", + key: ["uuid": "E621E1F8-C36C-495A-93FC-0C247A3E6E5F".databaseValue]) + XCTAssertEqual( + error.description, + "Key not found in table user: [uuid:\"E621E1F8-C36C-495A-93FC-0C247A3E6E5F\"]") + } + } } diff --git a/Tests/GRDBTests/NumericOverflowTests.swift b/Tests/GRDBTests/NumericOverflowTests.swift index 96e1de036..8ea8b4bfc 100644 --- a/Tests/GRDBTests/NumericOverflowTests.swift +++ b/Tests/GRDBTests/NumericOverflowTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/OrderedDictionaryTests.swift b/Tests/GRDBTests/OrderedDictionaryTests.swift new file mode 100644 index 000000000..ac1d2cca6 --- /dev/null +++ b/Tests/GRDBTests/OrderedDictionaryTests.swift @@ -0,0 +1,15 @@ +import XCTest +#if GRDBCUSTOMSQLITE + @testable import GRDBCustomSQLite +#else + @testable import GRDB +#endif + +class OrderedDictionaryTests: GRDBTestCase { + func testSubscriptWithDefaultValue() throws { + var dict: OrderedDictionary = [:] + dict["a", default: []].append("foo") + dict["a", default: []].append("bar") + XCTAssertEqual(dict, ["a": ["foo", "bar"]]) + } +} diff --git a/Tests/GRDBTests/PersistableRecordTests.swift b/Tests/GRDBTests/PersistableRecordTests.swift index f06d7a95b..23080a262 100644 --- a/Tests/GRDBTests/PersistableRecordTests.swift +++ b/Tests/GRDBTests/PersistableRecordTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -115,7 +113,7 @@ class PersistableRecordTests: GRDBTestCase { override func setup(_ dbWriter: DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("setUp") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE persons ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, @@ -140,7 +138,7 @@ class PersistableRecordTests: GRDBTestCase { let person = PersistableRecordPerson(name: "Arthur", age: 42) try person.insert(db) - let rows = try Row.fetchAll(db, "SELECT * FROM persons") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["name"] as String, "Arthur") } @@ -152,7 +150,7 @@ class PersistableRecordTests: GRDBTestCase { let person = PersistableRecordPerson(name: "Arthur", age: 42) try person.save(db) - let rows = try Row.fetchAll(db, "SELECT * FROM persons") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["name"] as String, "Arthur") } @@ -167,7 +165,7 @@ class PersistableRecordTests: GRDBTestCase { let person = PersistableRecordPersonClass(id: nil, name: "Arthur", age: 42) try person.insert(db) - let rows = try Row.fetchAll(db, "SELECT * FROM persons") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["id"] as Int64, person.id!) XCTAssertEqual(rows[0]["name"] as String, "Arthur") @@ -189,7 +187,7 @@ class PersistableRecordTests: GRDBTestCase { "UPDATE \"persons\" SET \"name\"='Craig', \"age\"=42 WHERE \"id\"=1" ].contains(self.lastSQLQuery)) - let rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY id") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY id") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["id"] as Int64, person1.id!) XCTAssertEqual(rows[0]["name"] as String, "Craig") @@ -211,7 +209,7 @@ class PersistableRecordTests: GRDBTestCase { try person1.update(db, columns: [String]()) XCTAssertEqual(self.lastSQLQuery, "UPDATE \"persons\" SET \"id\"=1 WHERE \"id\"=1") - let rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY id") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY id") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["id"] as Int64, person1.id!) XCTAssertEqual(rows[0]["name"] as String, "Arthur") @@ -227,7 +225,7 @@ class PersistableRecordTests: GRDBTestCase { try person1.update(db, columns: [Column("name")]) XCTAssertEqual(self.lastSQLQuery, "UPDATE \"persons\" SET \"name\"='Craig' WHERE \"id\"=1") - let rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY id") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY id") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["id"] as Int64, person1.id!) XCTAssertEqual(rows[0]["name"] as String, "Craig") @@ -242,7 +240,7 @@ class PersistableRecordTests: GRDBTestCase { try person1.update(db, columns: ["AgE"]) // case insensitivity XCTAssertEqual(self.lastSQLQuery, "UPDATE \"persons\" SET \"age\"=25 WHERE \"id\"=1") - let rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY id") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY id") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["id"] as Int64, person1.id!) XCTAssertEqual(rows[0]["name"] as String, "Craig") @@ -260,7 +258,7 @@ class PersistableRecordTests: GRDBTestCase { let person1 = PersistableRecordPersonClass(id: nil, name: "Arthur", age: 42) try person1.save(db) - var rows = try Row.fetchAll(db, "SELECT * FROM persons") + var rows = try Row.fetchAll(db, sql: "SELECT * FROM persons") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["id"] as Int64, person1.id!) XCTAssertEqual(rows[0]["name"] as String, "Arthur") @@ -271,7 +269,7 @@ class PersistableRecordTests: GRDBTestCase { person1.name = "Craig" try person1.save(db) - rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY id") + rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY id") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["id"] as Int64, person1.id!) XCTAssertEqual(rows[0]["name"] as String, "Craig") @@ -281,7 +279,7 @@ class PersistableRecordTests: GRDBTestCase { try person1.delete(db) try person1.save(db) - rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY id") + rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY id") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["id"] as Int64, person1.id!) XCTAssertEqual(rows[0]["name"] as String, "Craig") @@ -303,7 +301,7 @@ class PersistableRecordTests: GRDBTestCase { deleted = try person1.delete(db) XCTAssertFalse(deleted) - let rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY id") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY id") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["id"] as Int64, person2.id!) XCTAssertEqual(rows[0]["name"] as String, "Barbara") @@ -331,7 +329,7 @@ class PersistableRecordTests: GRDBTestCase { let country = PersistableRecordCountry(isoCode: "FR", name: "France") try country.insert(db) - let rows = try Row.fetchAll(db, "SELECT * FROM countries") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM countries") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["isoCode"] as String, "FR") XCTAssertEqual(rows[0]["name"] as String, "France") @@ -350,7 +348,7 @@ class PersistableRecordTests: GRDBTestCase { try country1.update(db) XCTAssertEqual(self.lastSQLQuery, "UPDATE \"countries\" SET \"name\"='France Métropolitaine' WHERE \"isoCode\"='FR'") - let rows = try Row.fetchAll(db, "SELECT * FROM countries ORDER BY isoCode") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM countries ORDER BY isoCode") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["isoCode"] as String, "FR") XCTAssertEqual(rows[0]["name"] as String, "France Métropolitaine") @@ -372,7 +370,7 @@ class PersistableRecordTests: GRDBTestCase { try country1.update(db, columns: [String]()) XCTAssertEqual(self.lastSQLQuery, "UPDATE \"countries\" SET \"isoCode\"='FR' WHERE \"isoCode\"='FR'") - let rows = try Row.fetchAll(db, "SELECT * FROM countries ORDER BY isoCode") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM countries ORDER BY isoCode") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["isoCode"] as String, "FR") XCTAssertEqual(rows[0]["name"] as String, "France") @@ -385,7 +383,7 @@ class PersistableRecordTests: GRDBTestCase { try country1.update(db, columns: [Column("name")]) XCTAssertEqual(self.lastSQLQuery, "UPDATE \"countries\" SET \"name\"='France Métropolitaine' WHERE \"isoCode\"='FR'") - let rows = try Row.fetchAll(db, "SELECT * FROM countries ORDER BY isoCode") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM countries ORDER BY isoCode") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["isoCode"] as String, "FR") XCTAssertEqual(rows[0]["name"] as String, "France Métropolitaine") @@ -401,7 +399,7 @@ class PersistableRecordTests: GRDBTestCase { var country1 = PersistableRecordCountry(isoCode: "FR", name: "France") try country1.save(db) - var rows = try Row.fetchAll(db, "SELECT * FROM countries") + var rows = try Row.fetchAll(db, sql: "SELECT * FROM countries") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["isoCode"] as String, "FR") XCTAssertEqual(rows[0]["name"] as String, "France") @@ -412,7 +410,7 @@ class PersistableRecordTests: GRDBTestCase { country1.name = "France Métropolitaine" try country1.save(db) - rows = try Row.fetchAll(db, "SELECT * FROM countries ORDER BY isoCode") + rows = try Row.fetchAll(db, sql: "SELECT * FROM countries ORDER BY isoCode") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["isoCode"] as String, "FR") XCTAssertEqual(rows[0]["name"] as String, "France Métropolitaine") @@ -422,7 +420,7 @@ class PersistableRecordTests: GRDBTestCase { try country1.delete(db) try country1.save(db) - rows = try Row.fetchAll(db, "SELECT * FROM countries ORDER BY isoCode") + rows = try Row.fetchAll(db, sql: "SELECT * FROM countries ORDER BY isoCode") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["isoCode"] as String, "FR") XCTAssertEqual(rows[0]["name"] as String, "France Métropolitaine") @@ -444,7 +442,7 @@ class PersistableRecordTests: GRDBTestCase { deleted = try country1.delete(db) XCTAssertFalse(deleted) - let rows = try Row.fetchAll(db, "SELECT * FROM countries ORDER BY isoCode") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM countries ORDER BY isoCode") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["isoCode"] as String, "US") XCTAssertEqual(rows[0]["name"] as String, "United States") @@ -490,7 +488,7 @@ class PersistableRecordTests: GRDBTestCase { XCTAssertEqual(deleteCount, 0) XCTAssertEqual(existsCount, 0) - let rows = try Row.fetchAll(db, "SELECT * FROM countries") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM countries") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["isoCode"] as String, "FR") XCTAssertEqual(rows[0]["name"] as String, "France") @@ -534,7 +532,7 @@ class PersistableRecordTests: GRDBTestCase { XCTAssertEqual(deleteCount, 0) XCTAssertEqual(existsCount, 0) - let rows = try Row.fetchAll(db, "SELECT * FROM countries ORDER BY isoCode") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM countries ORDER BY isoCode") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["isoCode"] as String, "FR") XCTAssertEqual(rows[0]["name"] as String, "France Métropolitaine") @@ -580,7 +578,7 @@ class PersistableRecordTests: GRDBTestCase { XCTAssertEqual(deleteCount, 0) XCTAssertEqual(existsCount, 0) - let rows = try Row.fetchAll(db, "SELECT * FROM countries ORDER BY isoCode") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM countries ORDER BY isoCode") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["isoCode"] as String, "FR") XCTAssertEqual(rows[0]["name"] as String, "France Métropolitaine") @@ -613,7 +611,7 @@ class PersistableRecordTests: GRDBTestCase { XCTAssertEqual(deleteCount, 0) XCTAssertEqual(existsCount, 0) - var rows = try Row.fetchAll(db, "SELECT * FROM countries") + var rows = try Row.fetchAll(db, sql: "SELECT * FROM countries") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["isoCode"] as String, "FR") XCTAssertEqual(rows[0]["name"] as String, "France") @@ -637,7 +635,7 @@ class PersistableRecordTests: GRDBTestCase { XCTAssertEqual(deleteCount, 0) XCTAssertEqual(existsCount, 0) - rows = try Row.fetchAll(db, "SELECT * FROM countries ORDER BY isoCode") + rows = try Row.fetchAll(db, sql: "SELECT * FROM countries ORDER BY isoCode") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["isoCode"] as String, "FR") XCTAssertEqual(rows[0]["name"] as String, "France Métropolitaine") @@ -653,7 +651,7 @@ class PersistableRecordTests: GRDBTestCase { XCTAssertEqual(deleteCount, 1) XCTAssertEqual(existsCount, 0) - rows = try Row.fetchAll(db, "SELECT * FROM countries ORDER BY isoCode") + rows = try Row.fetchAll(db, sql: "SELECT * FROM countries ORDER BY isoCode") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["isoCode"] as String, "FR") XCTAssertEqual(rows[0]["name"] as String, "France Métropolitaine") @@ -700,7 +698,7 @@ class PersistableRecordTests: GRDBTestCase { XCTAssertEqual(deleteCount, 2) XCTAssertEqual(existsCount, 0) - let rows = try Row.fetchAll(db, "SELECT * FROM countries ORDER BY isoCode") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM countries ORDER BY isoCode") XCTAssertEqual(rows.count, 1) XCTAssertEqual(rows[0]["isoCode"] as String, "US") XCTAssertEqual(rows[0]["name"] as String, "United States") @@ -787,7 +785,7 @@ extension PersistableRecordTests { let value = StructWithNestedType(nested: nested) try value.insert(db) - let dbValue = try DatabaseValue.fetchOne(db, "SELECT nested FROM t1")! + let dbValue = try DatabaseValue.fetchOne(db, sql: "SELECT nested FROM t1")! // Encodable has a default implementation which encodes a model to JSON as String. // We expect here JSON in the form of a String @@ -827,7 +825,7 @@ extension PersistableRecordTests { let value = StructWithNestedType(nested: nil) try value.insert(db) - let dbValue = try DatabaseValue.fetchOne(db, "SELECT nested FROM t1")! + let dbValue = try DatabaseValue.fetchOne(db, sql: "SELECT nested FROM t1")! // We expect here nil XCTAssertNil(dbValue.storage.value) @@ -855,7 +853,7 @@ extension PersistableRecordTests { let value = StructWithNestedType(nested: [nested, nested]) try value.insert(db) - let dbValue = try DatabaseValue.fetchOne(db, "SELECT nested FROM t1")! + let dbValue = try DatabaseValue.fetchOne(db, sql: "SELECT nested FROM t1")! // Encodable has a default implementation which encodes a model to JSON as String. // We expect here JSON in the form of a String @@ -898,7 +896,7 @@ extension PersistableRecordTests { let value = StructWithNestedType(nested: nil) try value.insert(db) - let dbValue = try DatabaseValue.fetchOne(db, "SELECT nested FROM t1")! + let dbValue = try DatabaseValue.fetchOne(db, sql: "SELECT nested FROM t1")! // We expect here nil XCTAssertNil(dbValue.storage.value) @@ -926,7 +924,7 @@ extension PersistableRecordTests { let value = StructWithNestedType(nested: nested) try value.insert(db) - let dbValue = try DatabaseValue.fetchOne(db, "SELECT nested FROM t1")! + let dbValue = try DatabaseValue.fetchOne(db, sql: "SELECT nested FROM t1")! // Encodable has a default implementation which encodes a model to JSON as String. // We expect here JSON in the form of a String @@ -967,7 +965,7 @@ extension PersistableRecordTests { let value = StructWithNestedType(nested: [nested]) try value.insert(db) - let dbValue = try DatabaseValue.fetchOne(db, "SELECT nested FROM t1")! + let dbValue = try DatabaseValue.fetchOne(db, sql: "SELECT nested FROM t1")! // Encodable has a default implementation which encodes a model to JSON as String. // We expect here JSON in the form of a String diff --git a/Tests/GRDBTests/PrefixCursorTests.swift b/Tests/GRDBTests/PrefixCursorTests.swift index 5ee9d2094..272578587 100644 --- a/Tests/GRDBTests/PrefixCursorTests.swift +++ b/Tests/GRDBTests/PrefixCursorTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/PrefixWhileCursorTests.swift b/Tests/GRDBTests/PrefixWhileCursorTests.swift index 9300b5faf..02b87dd8b 100644 --- a/Tests/GRDBTests/PrefixWhileCursorTests.swift +++ b/Tests/GRDBTests/PrefixWhileCursorTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/PrimaryKeyInfoTests.swift b/Tests/GRDBTests/PrimaryKeyInfoTests.swift index 9cc96df73..7fc30c0ae 100644 --- a/Tests/GRDBTests/PrimaryKeyInfoTests.swift +++ b/Tests/GRDBTests/PrimaryKeyInfoTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,7 +10,7 @@ class PrimaryKeyInfoTests: GRDBTestCase { func testHiddenRowID() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE items (name TEXT)") + try db.execute(sql: "CREATE TABLE items (name TEXT)") let primaryKey = try db.primaryKey("items") XCTAssertEqual(primaryKey.columns, [Column.rowID.name]) XCTAssertNil(primaryKey.rowIDColumn) @@ -23,7 +21,7 @@ class PrimaryKeyInfoTests: GRDBTestCase { func testIntegerPrimaryKey() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY, name TEXT)") + try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY, name TEXT)") let primaryKey = try db.primaryKey("items") XCTAssertEqual(primaryKey.columns, ["id"]) XCTAssertEqual(primaryKey.rowIDColumn, "id") @@ -34,7 +32,7 @@ class PrimaryKeyInfoTests: GRDBTestCase { func testNonRowIDPrimaryKey() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE items (name TEXT PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items (name TEXT PRIMARY KEY)") let primaryKey = try db.primaryKey("items") XCTAssertEqual(primaryKey.columns, ["name"]) XCTAssertNil(primaryKey.rowIDColumn) @@ -45,7 +43,7 @@ class PrimaryKeyInfoTests: GRDBTestCase { func testCompoundPrimaryKey() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE items (a TEXT, b INTEGER, PRIMARY KEY (a,b))") + try db.execute(sql: "CREATE TABLE items (a TEXT, b INTEGER, PRIMARY KEY (a,b))") let primaryKey = try db.primaryKey("items") XCTAssertEqual(primaryKey.columns, ["a", "b"]) XCTAssertNil(primaryKey.rowIDColumn) diff --git a/Tests/GRDBTests/QueryInterfaceExpressionsTests.swift b/Tests/GRDBTests/QueryInterfaceExpressionsTests.swift index f2c8e18e0..f15645a5e 100644 --- a/Tests/GRDBTests/QueryInterfaceExpressionsTests.swift +++ b/Tests/GRDBTests/QueryInterfaceExpressionsTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -38,7 +36,7 @@ class QueryInterfaceExpressionsTests: GRDBTestCase { var migrator = DatabaseMigrator() migrator.registerMigration("createReaders") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE readers ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, @@ -64,6 +62,11 @@ class QueryInterfaceExpressionsTests: GRDBTestCase { sql(dbQueue, tableRequest.filter(![Int]().contains(Col.id))), "SELECT * FROM \"readers\" WHERE 1") + // Array.contains(): = operator + XCTAssertEqual( + sql(dbQueue, tableRequest.filter([1].contains(Col.id))), + "SELECT * FROM \"readers\" WHERE (\"id\" = 1)") + // Array.contains(): IN operator XCTAssertEqual( sql(dbQueue, tableRequest.filter([1,2,3].contains(Col.id))), @@ -72,7 +75,7 @@ class QueryInterfaceExpressionsTests: GRDBTestCase { // Array.contains(): IN operator XCTAssertEqual( sql(dbQueue, tableRequest.filter([Col.id].contains(Col.id))), - "SELECT * FROM \"readers\" WHERE (\"id\" IN (\"id\"))") + "SELECT * FROM \"readers\" WHERE (\"id\" = \"id\")") // EmptyCollection.contains(): 0 XCTAssertEqual( @@ -84,6 +87,11 @@ class QueryInterfaceExpressionsTests: GRDBTestCase { sql(dbQueue, tableRequest.filter(!EmptyCollection().contains(Col.id))), "SELECT * FROM \"readers\" WHERE 1") + // Sequence.contains(): = operator + XCTAssertEqual( + sql(dbQueue, tableRequest.filter(AnySequence([1]).contains(Col.id))), + "SELECT * FROM \"readers\" WHERE (\"id\" = 1)") + // Sequence.contains(): IN operator XCTAssertEqual( sql(dbQueue, tableRequest.filter(AnySequence([1,2,3]).contains(Col.id))), @@ -92,13 +100,23 @@ class QueryInterfaceExpressionsTests: GRDBTestCase { // Sequence.contains(): IN operator XCTAssertEqual( sql(dbQueue, tableRequest.filter(AnySequence([Col.id]).contains(Col.id))), - "SELECT * FROM \"readers\" WHERE (\"id\" IN (\"id\"))") + "SELECT * FROM \"readers\" WHERE (\"id\" = \"id\")") + + // !Sequence.contains(): <> operator + XCTAssertEqual( + sql(dbQueue, tableRequest.filter(![1].contains(Col.id))), + "SELECT * FROM \"readers\" WHERE (\"id\" <> 1)") // !Sequence.contains(): NOT IN operator XCTAssertEqual( sql(dbQueue, tableRequest.filter(![1,2,3].contains(Col.id))), "SELECT * FROM \"readers\" WHERE (\"id\" NOT IN (1, 2, 3))") + // !!Sequence.contains(): = operator + XCTAssertEqual( + sql(dbQueue, tableRequest.filter(!(![1].contains(Col.id)))), + "SELECT * FROM \"readers\" WHERE (\"id\" = 1)") + // !!Sequence.contains(): IN operator XCTAssertEqual( sql(dbQueue, tableRequest.filter(!(![1,2,3].contains(Col.id)))), @@ -158,11 +176,16 @@ class QueryInterfaceExpressionsTests: GRDBTestCase { sql(dbQueue, tableRequest.filter(AnySequence(["arthur", "barbara"]).contains(Col.name.collating(.nocase)))), "SELECT * FROM \"readers\" WHERE (\"name\" IN ('arthur', 'barbara') COLLATE NOCASE)") - // Sequence.contains(): IN operator + // Sequence.contains(): = operator XCTAssertEqual( sql(dbQueue, tableRequest.filter(AnySequence([Col.name]).contains(Col.name.collating(.nocase)))), - "SELECT * FROM \"readers\" WHERE (\"name\" IN (\"name\") COLLATE NOCASE)") + "SELECT * FROM \"readers\" WHERE (\"name\" = \"name\" COLLATE NOCASE)") + // Sequence.contains(): false + XCTAssertEqual( + sql(dbQueue, tableRequest.filter(EmptyCollection().contains(Col.name.collating(.nocase)))), + "SELECT * FROM \"readers\" WHERE 0 COLLATE NOCASE") + // ClosedInterval: BETWEEN operator let closedInterval = "A"..."z" XCTAssertEqual( diff --git a/Tests/GRDBTests/QueryInterfaceExtensibilityTests.swift b/Tests/GRDBTests/QueryInterfaceExtensibilityTests.swift index f2d5c55c6..1dcc4136e 100644 --- a/Tests/GRDBTests/QueryInterfaceExtensibilityTests.swift +++ b/Tests/GRDBTests/QueryInterfaceExtensibilityTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -40,14 +38,11 @@ func ~= (_ lhs: SQLExpressible, _ rhs: Column) -> SQLExpression { // CAST func cast(_ value: SQLExpressible, as type: Database.ColumnType) -> SQLExpression { - // Turn the value into a literal expression - let literal: SQLExpressionLiteral = value.sqlExpression.literal - - // Build our "CAST(value AS type)" sql snippet - let sql = "CAST(\(literal.sql) AS \(type.rawValue))" - - // And return a new literal expression, preserving input arguments - return SQLExpressionLiteral(sql, arguments: literal.arguments) + let literal = value.sqlExpression.sqlLiteral + let castLiteral = literal.mapSQL { sql in + "CAST(\(sql) AS \(type.rawValue))" + } + return SQLExpressionLiteral(literal: castLiteral) } @@ -65,26 +60,26 @@ class QueryInterfaceExtensibilityTests: GRDBTestCase { } let date = Date(timeIntervalSince1970: 0) - try db.execute("INSERT INTO records (date) VALUES (?)", arguments: [date]) + try db.execute(sql: "INSERT INTO records (date) VALUES (?)", arguments: [date]) let request = Record.select(strftime("%Y", Column("date"))) let year = try Int.fetchOne(db, request) XCTAssertEqual(year, 1970) - XCTAssertEqual(self.lastSQLQuery, "SELECT STRFTIME('%Y', \"date\") FROM \"records\"") + XCTAssertEqual(self.lastSQLQuery, "SELECT STRFTIME('%Y', \"date\") FROM \"records\" LIMIT 1") } } func testMatch() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE VIRTUAL TABLE records USING fts3(content TEXT)") + try db.execute(sql: "CREATE VIRTUAL TABLE records USING fts3(content TEXT)") struct Record : TableRecord { static let databaseTableName = "records" } - try db.execute("INSERT INTO records (content) VALUES (?)", arguments: ["foo"]) - try db.execute("INSERT INTO records (content) VALUES (?)", arguments: ["foo bar"]) - try db.execute("INSERT INTO records (content) VALUES (?)", arguments: ["bar"]) + try db.execute(sql: "INSERT INTO records (content) VALUES (?)", arguments: ["foo"]) + try db.execute(sql: "INSERT INTO records (content) VALUES (?)", arguments: ["foo bar"]) + try db.execute(sql: "INSERT INTO records (content) VALUES (?)", arguments: ["bar"]) let request = Record.filter("foo" ~= Column("content")) let count = try request.fetchCount(db) @@ -102,7 +97,7 @@ class QueryInterfaceExtensibilityTests: GRDBTestCase { static let databaseTableName = "records" } - try db.execute("INSERT INTO records (text) VALUES (?)", arguments: ["foo"]) + try db.execute(sql: "INSERT INTO records (text) VALUES (?)", arguments: ["foo"]) let request = Record.select(cast(Column("text"), as: .blob)) let dbValue = try DatabaseValue.fetchOne(db, request)! @@ -112,7 +107,7 @@ class QueryInterfaceExtensibilityTests: GRDBTestCase { default: XCTFail("Expected data blob") } - XCTAssertEqual(self.lastSQLQuery, "SELECT (CAST(\"text\" AS BLOB)) FROM \"records\"") + XCTAssertEqual(self.lastSQLQuery, "SELECT (CAST(\"text\" AS BLOB)) FROM \"records\" LIMIT 1") } } } diff --git a/Tests/GRDBTests/QueryInterfacePromiseTests.swift b/Tests/GRDBTests/QueryInterfacePromiseTests.swift index 66c2000ae..c455f09d1 100644 --- a/Tests/GRDBTests/QueryInterfacePromiseTests.swift +++ b/Tests/GRDBTests/QueryInterfacePromiseTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -11,6 +9,8 @@ private struct Node: TableRecord { static let parent = belongsTo(Node.self) } +private struct NotARecord { } + // Here we test that filter(key:), orderByPrimaryKey(), and groupByPrimaryKey() // don't forget their table when the request type is changed. class QueryInterfacePromiseTests: GRDBTestCase { @@ -27,7 +27,8 @@ class QueryInterfacePromiseTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in do { - let request = Node.filter(key: 1) + let request = Node + .filter(key: 1) let sql = """ SELECT * FROM "node" WHERE ("id" = 1) """ @@ -35,7 +36,22 @@ class QueryInterfacePromiseTests: GRDBTestCase { try assertEqualSQL(db, request.asRequest(of: Row.self), sql) } do { - let request = Node.filter(key: 1).joining(optional: Node.parent.filter(key: 2)) + let request = Node + .filter(key: 1) + .joining(optional: Node.parent.filter(key: 2)) + let sql = """ + SELECT "node1".* \ + FROM "node" "node1" \ + LEFT JOIN "node" "node2" ON (("node2"."id" = "node1"."parentId") AND ("node2"."id" = 2)) \ + WHERE ("node1"."id" = 1) + """ + try assertEqualSQL(db, request, sql) + try assertEqualSQL(db, request.asRequest(of: Row.self), sql) + } + do { + let request = Node + .joining(optional: Node.parent.filter(key: 2)) + .filter(key: 1) let sql = """ SELECT "node1".* \ FROM "node" "node1" \ @@ -48,7 +64,7 @@ class QueryInterfacePromiseTests: GRDBTestCase { } } - func testOrderbyPrimaryKeyCapturesTableName() throws { + func testOrderByPrimaryKeyCapturesTableName() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in do { @@ -73,7 +89,7 @@ class QueryInterfacePromiseTests: GRDBTestCase { } } - func testGroupbyPrimaryKeyCapturesTableName() throws { + func testGroupByPrimaryKeyCapturesTableName() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.read { db in let request = Node.all().groupByPrimaryKey() @@ -84,4 +100,34 @@ class QueryInterfacePromiseTests: GRDBTestCase { try assertEqualSQL(db, request.asRequest(of: Row.self), sql) } } + + func testSourceTableIsCapturedInTheRequestAndNotInTheTypeOfTheFetchedRecord() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.read { db in + do { + let request = Node.all() + .asRequest(of: NotARecord.self) + .filter(key: 1) + let sql = """ + SELECT * FROM "node" WHERE ("id" = 1) + """ + try assertEqualSQL(db, request, sql) + try assertEqualSQL(db, request.asRequest(of: Row.self), sql) + } + do { + let request = Node + .joining(optional: Node.parent.filter(key: 2)) + .asRequest(of: NotARecord.self) + .filter(key: 1) + let sql = """ + SELECT "node1".* \ + FROM "node" "node1" \ + LEFT JOIN "node" "node2" ON (("node2"."id" = "node1"."parentId") AND ("node2"."id" = 2)) \ + WHERE ("node1"."id" = 1) + """ + try assertEqualSQL(db, request, sql) + try assertEqualSQL(db, request.asRequest(of: Row.self), sql) + } + } + } } diff --git a/Tests/GRDBTests/QueryInterfaceRequestTests.swift b/Tests/GRDBTests/QueryInterfaceRequestTests.swift index ee3b99bdc..23e669651 100644 --- a/Tests/GRDBTests/QueryInterfaceRequestTests.swift +++ b/Tests/GRDBTests/QueryInterfaceRequestTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -31,7 +29,7 @@ class QueryInterfaceRequestTests: GRDBTestCase { var migrator = DatabaseMigrator() migrator.registerMigration("createReaders") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE readers ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, @@ -46,7 +44,7 @@ class QueryInterfaceRequestTests: GRDBTestCase { func testSimpleRequestDoesNotUseAnyRowAdapter() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let (_, adapter) = try Reader.all().prepare(db) + let (_, adapter) = try Reader.all().prepare(db, forSingleResult: false) XCTAssertNil(adapter) } } @@ -56,8 +54,8 @@ class QueryInterfaceRequestTests: GRDBTestCase { func testFetchRowFromRequest() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) do { let rows = try Row.fetchAll(db, tableRequest) @@ -73,7 +71,7 @@ class QueryInterfaceRequestTests: GRDBTestCase { do { let row = try Row.fetchOne(db, tableRequest)! - XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\"") + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\" LIMIT 1") XCTAssertEqual(row["id"] as Int64, 1) XCTAssertEqual(row["name"] as String, "Arthur") XCTAssertEqual(row["age"] as Int, 42) @@ -144,8 +142,8 @@ class QueryInterfaceRequestTests: GRDBTestCase { func testSelectLiteral() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) let request = tableRequest.select(sql: "name, id - 1") let rows = try Row.fetchAll(db, request) @@ -161,8 +159,8 @@ class QueryInterfaceRequestTests: GRDBTestCase { func testSelectLiteralWithPositionalArguments() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) let request = tableRequest.select(sql: "name, id - ?", arguments: [1]) let rows = try Row.fetchAll(db, request) @@ -178,8 +176,8 @@ class QueryInterfaceRequestTests: GRDBTestCase { func testSelectLiteralWithNamedArguments() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) let request = tableRequest.select(sql: "name, id - :n", arguments: ["n": 1]) let rows = try Row.fetchAll(db, request) @@ -191,12 +189,34 @@ class QueryInterfaceRequestTests: GRDBTestCase { XCTAssertEqual(rows[1][1] as Int64, 1) } } - + + func testSelectSQLLiteral() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) + + func test(_ request: QueryInterfaceRequest) throws { + let rows = try Row.fetchAll(db, request) + XCTAssertEqual(rows.count, 2) + XCTAssertEqual(rows[0][0] as String, "O'Brien") + XCTAssertEqual(rows[0][1] as Int64, 0) + XCTAssertEqual(rows[1][0] as String, "O'Brien") + XCTAssertEqual(rows[1][1] as Int64, 1) + } + try test(tableRequest.select(literal: SQLLiteral(sql: ":name, id - :value", arguments: ["name": "O'Brien", "value": 1]))) + #if swift(>=5) + // Interpolation + try test(tableRequest.select(literal: "\("O'Brien"), id - \(1)")) + #endif + } + } + func testSelect() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) let request = tableRequest.select(Col.name, Col.id - 1) let rows = try Row.fetchAll(db, request) @@ -212,16 +232,52 @@ class QueryInterfaceRequestTests: GRDBTestCase { func testSelectAliased() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) let request = tableRequest.select(Col.name.aliased("nom"), (Col.age + 1).aliased("agePlusOne")) let row = try Row.fetchOne(db, request)! - XCTAssertEqual(lastSQLQuery, "SELECT \"name\" AS \"nom\", (\"age\" + 1) AS \"agePlusOne\" FROM \"readers\"") + XCTAssertEqual(lastSQLQuery, "SELECT \"name\" AS \"nom\", (\"age\" + 1) AS \"agePlusOne\" FROM \"readers\" LIMIT 1") XCTAssertEqual(row["nom"] as String, "Arthur") XCTAssertEqual(row["agePlusOne"] as Int, 43) } } - + + func testAnnotated() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + do { + let request = Reader.annotated(with: [Col.id - 1]) + _ = try Row.fetchAll(db, request) + XCTAssertEqual(lastSQLQuery, "SELECT *, (\"id\" - 1) FROM \"readers\"") + } + do { + let request = Reader.annotated(with: Col.id - 1, Col.id + 1) + _ = try Row.fetchAll(db, request) + XCTAssertEqual(lastSQLQuery, "SELECT *, (\"id\" - 1), (\"id\" + 1) FROM \"readers\"") + } + do { + let request = tableRequest.annotated(with: [Col.id - 1]) + _ = try Row.fetchAll(db, request) + XCTAssertEqual(lastSQLQuery, "SELECT *, (\"id\" - 1) FROM \"readers\"") + } + do { + let request = tableRequest.annotated(with: Col.id - 1, Col.id + 1) + _ = try Row.fetchAll(db, request) + XCTAssertEqual(lastSQLQuery, "SELECT *, (\"id\" - 1), (\"id\" + 1) FROM \"readers\"") + } + do { + let request = tableRequest.select(Col.name).annotated(with: [Col.id - 1]) + _ = try Row.fetchAll(db, request) + XCTAssertEqual(lastSQLQuery, "SELECT \"name\", (\"id\" - 1) FROM \"readers\"") + } + do { + let request = tableRequest.select(Col.name).annotated(with: Col.id - 1, Col.id + 1) + _ = try Row.fetchAll(db, request) + XCTAssertEqual(lastSQLQuery, "SELECT \"name\", (\"id\" - 1), (\"id\" + 1) FROM \"readers\"") + } + } + } + func testMultipleSelect() throws { let dbQueue = try makeDatabaseQueue() XCTAssertEqual( @@ -232,7 +288,7 @@ class QueryInterfaceRequestTests: GRDBTestCase { func testSelectAs() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) // select(..., as: String.self) do { @@ -252,6 +308,22 @@ class QueryInterfaceRequestTests: GRDBTestCase { .fetchOne(db)! XCTAssertEqual(value, "Arthur") } + // SQLLiteral + do { + let value = try Reader + .select(literal: SQLLiteral(sql: "? AS name", arguments: ["O'Brien"]), as: String.self) + .fetchOne(db)! + XCTAssertEqual(value, "O'Brien") + } + #if swift(>=5.0) + // SQLLiteral with interpolation + do { + let value = try Reader + .select(literal: "\("O'Brien") AS name", as: String.self) + .fetchOne(db)! + XCTAssertEqual(value, "O'Brien") + } + #endif // raw sql without argument do { let value = try Reader @@ -278,6 +350,24 @@ class QueryInterfaceRequestTests: GRDBTestCase { .fetchOne(db)! XCTAssertEqual(value, "Arthur") } + // SQLLiteral + do { + let value = try Reader + .all() + .select(literal: SQLLiteral(sql: "? AS name", arguments: ["O'Brien"]), as: String.self) + .fetchOne(db)! + XCTAssertEqual(value, "O'Brien") + } + #if swift(>=5.0) + // SQLLiteral with interpolation + do { + let value = try Reader + .all() + .select(literal: "\("O'Brien") AS name", as: String.self) + .fetchOne(db)! + XCTAssertEqual(value, "O'Brien") + } + #endif // raw sql without argument do { let value = try Reader @@ -307,6 +397,22 @@ class QueryInterfaceRequestTests: GRDBTestCase { .fetchOne(db)! XCTAssertEqual(value, ["name": "Arthur", "age": 42]) } + // SQLLiteral with named argument + do { + let value = try Reader + .select(literal: SQLLiteral(sql: "name, :age AS age", arguments: ["age": 22]), as: Row.self) + .fetchOne(db)! + XCTAssertEqual(value, ["name": "Arthur", "age": 22]) + } + #if swift(>=5.0) + // SQLLiteral with interpolation + do { + let value = try Reader + .select(literal: "\("O'Brien") AS name, \(22) AS age", as: Row.self) + .fetchOne(db)! + XCTAssertEqual(value, ["name": "O'Brien", "age": 22]) + } + #endif // raw sql with named argument do { let value = try Reader @@ -333,6 +439,24 @@ class QueryInterfaceRequestTests: GRDBTestCase { .fetchOne(db)! XCTAssertEqual(value, ["name": "Arthur", "age": 42]) } + // SQLLiteral with positional argument + do { + let value = try Reader + .all() + .select(literal: SQLLiteral(sql: "name, ? AS age", arguments: [22]), as: Row.self) + .fetchOne(db)! + XCTAssertEqual(value, ["name": "Arthur", "age": 22]) + } + #if swift(>=5.0) + // SQLLiteral with interpolation + do { + let value = try Reader + .all() + .select(literal: "\("O'Brien") AS name, \(22) AS age", as: Row.self) + .fetchOne(db)! + XCTAssertEqual(value, ["name": "O'Brien", "age": 22]) + } + #endif // raw sql with positional argument do { let value = try Reader diff --git a/Tests/GRDBTests/RawRepresentable+DatabaseValueConvertibleTests.swift b/Tests/GRDBTests/RawRepresentable+DatabaseValueConvertibleTests.swift index 27064944a..cea4c2819 100644 --- a/Tests/GRDBTests/RawRepresentable+DatabaseValueConvertibleTests.swift +++ b/Tests/GRDBTests/RawRepresentable+DatabaseValueConvertibleTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -41,7 +39,7 @@ class RawRepresentableDatabaseValueConvertibleTests: GRDBTestCase { override func setup(_ dbWriter: DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("createPersons") { db in - try db.execute("CREATE TABLE wines (grape TEXT, color INTEGER)") + try db.execute(sql: "CREATE TABLE wines (grape TEXT, color INTEGER)") } try migrator.migrate(dbWriter) } @@ -52,13 +50,13 @@ class RawRepresentableDatabaseValueConvertibleTests: GRDBTestCase { do { for color in [Color32.red, Color32.white, Color32.rose] { - try db.execute("INSERT INTO wines (color) VALUES (?)", arguments: [color]) + try db.execute(sql: "INSERT INTO wines (color) VALUES (?)", arguments: [color]) } - try db.execute("INSERT INTO wines (color) VALUES (NULL)") + try db.execute(sql: "INSERT INTO wines (color) VALUES (NULL)") } do { - let rows = try Row.fetchAll(db, "SELECT color FROM wines ORDER BY color") + let rows = try Row.fetchAll(db, sql: "SELECT color FROM wines ORDER BY color") let colors = rows.map { $0[0] as Color32? } XCTAssertTrue(colors[0] == nil) XCTAssertEqual(colors[1]!, Color32.red) @@ -67,7 +65,7 @@ class RawRepresentableDatabaseValueConvertibleTests: GRDBTestCase { } do { - let colors = try Optional.fetchAll(db, "SELECT color FROM wines ORDER BY color") + let colors = try Optional.fetchAll(db, sql: "SELECT color FROM wines ORDER BY color") XCTAssertTrue(colors[0] == nil) XCTAssertEqual(colors[1]!, Color32.red) XCTAssertEqual(colors[2]!, Color32.white) @@ -84,13 +82,13 @@ class RawRepresentableDatabaseValueConvertibleTests: GRDBTestCase { do { for color in [Color64.red, Color64.white, Color64.rose] { - try db.execute("INSERT INTO wines (color) VALUES (?)", arguments: [color]) + try db.execute(sql: "INSERT INTO wines (color) VALUES (?)", arguments: [color]) } - try db.execute("INSERT INTO wines (color) VALUES (NULL)") + try db.execute(sql: "INSERT INTO wines (color) VALUES (NULL)") } do { - let rows = try Row.fetchAll(db, "SELECT color FROM wines ORDER BY color") + let rows = try Row.fetchAll(db, sql: "SELECT color FROM wines ORDER BY color") let colors = rows.map { $0[0] as Color64? } XCTAssertTrue(colors[0] == nil) XCTAssertEqual(colors[1]!, Color64.red) @@ -99,7 +97,7 @@ class RawRepresentableDatabaseValueConvertibleTests: GRDBTestCase { } do { - let colors = try Optional.fetchAll(db, "SELECT color FROM wines ORDER BY color") + let colors = try Optional.fetchAll(db, sql: "SELECT color FROM wines ORDER BY color") XCTAssertTrue(colors[0] == nil) XCTAssertEqual(colors[1]!, Color64.red) XCTAssertEqual(colors[2]!, Color64.white) @@ -116,13 +114,13 @@ class RawRepresentableDatabaseValueConvertibleTests: GRDBTestCase { do { for color in [Color.red, Color.white, Color.rose] { - try db.execute("INSERT INTO wines (color) VALUES (?)", arguments: [color]) + try db.execute(sql: "INSERT INTO wines (color) VALUES (?)", arguments: [color]) } - try db.execute("INSERT INTO wines (color) VALUES (NULL)") + try db.execute(sql: "INSERT INTO wines (color) VALUES (NULL)") } do { - let rows = try Row.fetchAll(db, "SELECT color FROM wines ORDER BY color") + let rows = try Row.fetchAll(db, sql: "SELECT color FROM wines ORDER BY color") let colors = rows.map { $0[0] as Color? } XCTAssertTrue(colors[0] == nil) XCTAssertEqual(colors[1]!, Color.red) @@ -131,7 +129,7 @@ class RawRepresentableDatabaseValueConvertibleTests: GRDBTestCase { } do { - let colors = try Optional.fetchAll(db, "SELECT color FROM wines ORDER BY color") + let colors = try Optional.fetchAll(db, sql: "SELECT color FROM wines ORDER BY color") XCTAssertTrue(colors[0] == nil) XCTAssertEqual(colors[1]!, Color.red) XCTAssertEqual(colors[2]!, Color.white) @@ -148,13 +146,13 @@ class RawRepresentableDatabaseValueConvertibleTests: GRDBTestCase { do { for grape in [Grape.chardonnay, Grape.merlot, Grape.riesling] { - try db.execute("INSERT INTO wines (grape) VALUES (?)", arguments: [grape]) + try db.execute(sql: "INSERT INTO wines (grape) VALUES (?)", arguments: [grape]) } - try db.execute("INSERT INTO wines (grape) VALUES (NULL)") + try db.execute(sql: "INSERT INTO wines (grape) VALUES (NULL)") } do { - let rows = try Row.fetchAll(db, "SELECT grape FROM wines ORDER BY grape") + let rows = try Row.fetchAll(db, sql: "SELECT grape FROM wines ORDER BY grape") let grapes = rows.map { $0[0] as Grape? } XCTAssertTrue(grapes[0] == nil) XCTAssertEqual(grapes[1]!, Grape.chardonnay) @@ -163,7 +161,7 @@ class RawRepresentableDatabaseValueConvertibleTests: GRDBTestCase { } do { - let grapes = try Optional.fetchAll(db, "SELECT grape FROM wines ORDER BY grape") + let grapes = try Optional.fetchAll(db, sql: "SELECT grape FROM wines ORDER BY grape") XCTAssertTrue(grapes[0] == nil) XCTAssertEqual(grapes[1]!, Grape.chardonnay) XCTAssertEqual(grapes[2]!, Grape.merlot) diff --git a/Tests/GRDBTests/Record+QueryInterfaceRequestTests.swift b/Tests/GRDBTests/Record+QueryInterfaceRequestTests.swift index 74de62c56..e9b8ba91f 100644 --- a/Tests/GRDBTests/Record+QueryInterfaceRequestTests.swift +++ b/Tests/GRDBTests/Record+QueryInterfaceRequestTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -47,7 +45,7 @@ class RecordQueryInterfaceRequestTests: GRDBTestCase { override func setup(_ dbWriter: DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("createReaders") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE readers ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, @@ -84,7 +82,7 @@ class RecordQueryInterfaceRequestTests: GRDBTestCase { do { let reader = try request.fetchOne(db)! - XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\"") + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\" LIMIT 1") XCTAssertEqual(reader.id!, arthur.id!) XCTAssertEqual(reader.name, arthur.name) XCTAssertEqual(reader.age, arthur.age) @@ -93,10 +91,12 @@ class RecordQueryInterfaceRequestTests: GRDBTestCase { do { let cursor = try request.fetchCursor(db) let names = cursor.map { $0.name } - XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\"") XCTAssertEqual(try names.next()!, arthur.name) XCTAssertEqual(try names.next()!, barbara.name) XCTAssertTrue(try names.next() == nil) + + // validate query *after* cursor has retrieved a record + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\"") } } } diff --git a/Tests/GRDBTests/RecordCopyTests.swift b/Tests/GRDBTests/RecordCopyTests.swift index 50ad68cb5..09bee2593 100644 --- a/Tests/GRDBTests/RecordCopyTests.swift +++ b/Tests/GRDBTests/RecordCopyTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/RecordEditedTests.swift b/Tests/GRDBTests/RecordEditedTests.swift index 0a1810674..c6bf73226 100644 --- a/Tests/GRDBTests/RecordEditedTests.swift +++ b/Tests/GRDBTests/RecordEditedTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -22,7 +20,7 @@ private class Person : Record { } static func setup(inDatabase db: Database) throws { - try db.execute(""" + try db.execute(sql: """ CREATE TABLE persons ( id INTEGER PRIMARY KEY, creationDate TEXT NOT NULL, @@ -166,12 +164,12 @@ class RecordEditedTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try Person(name: "Arthur", age: 41).insert(db) - let person = try Person.fetchOne(db, "SELECT * FROM persons")! + let person = try Person.fetchOne(db, sql: "SELECT * FROM persons")! XCTAssertFalse(person.hasDatabaseChanges) } try dbQueue.inDatabase { db in try PersonWithModifiedCaseColumns(name: "Arthur", age: 41).insert(db) - let person = try PersonWithModifiedCaseColumns.fetchOne(db, "SELECT * FROM persons")! + let person = try PersonWithModifiedCaseColumns.fetchOne(db, sql: "SELECT * FROM persons")! XCTAssertFalse(person.hasDatabaseChanges) } } @@ -179,9 +177,9 @@ class RecordEditedTests: GRDBTestCase { func testRecordIsNotEditedAfterFullFetchWithIntegerPropertyOnRealAffinityColumn() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE t (value REAL)") - try db.execute("INSERT INTO t (value) VALUES (1)") - let record = try IntegerPropertyOnRealAffinityColumn.fetchOne(db, "SELECT * FROM t")! + try db.execute(sql: "CREATE TABLE t (value REAL)") + try db.execute(sql: "INSERT INTO t (value) VALUES (1)") + let record = try IntegerPropertyOnRealAffinityColumn.fetchOne(db, sql: "SELECT * FROM t")! XCTAssertFalse(record.hasDatabaseChanges) } } @@ -194,12 +192,12 @@ class RecordEditedTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try Person(name: "Arthur", age: 41).insert(db) - let person = try Person.fetchOne(db, "SELECT *, 1 AS foo FROM persons")! + let person = try Person.fetchOne(db, sql: "SELECT *, 1 AS foo FROM persons")! XCTAssertFalse(person.hasDatabaseChanges) } try dbQueue.inDatabase { db in try PersonWithModifiedCaseColumns(name: "Arthur", age: 41).insert(db) - let person = try PersonWithModifiedCaseColumns.fetchOne(db, "SELECT *, 1 AS foo FROM persons")! + let person = try PersonWithModifiedCaseColumns.fetchOne(db, sql: "SELECT *, 1 AS foo FROM persons")! XCTAssertFalse(person.hasDatabaseChanges) } } @@ -212,12 +210,12 @@ class RecordEditedTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try Person(name: "Arthur", age: 41).insert(db) - let person = try Person.fetchOne(db, "SELECT name FROM persons")! + let person = try Person.fetchOne(db, sql: "SELECT name FROM persons")! XCTAssertTrue(person.hasDatabaseChanges) } try dbQueue.inDatabase { db in try PersonWithModifiedCaseColumns(name: "Arthur", age: 41).insert(db) - let person = try PersonWithModifiedCaseColumns.fetchOne(db, "SELECT name FROM persons")! + let person = try PersonWithModifiedCaseColumns.fetchOne(db, sql: "SELECT name FROM persons")! XCTAssertTrue(person.hasDatabaseChanges) } } @@ -475,29 +473,29 @@ class RecordEditedTests: GRDBTestCase { try dbQueue.inDatabase { db in try Person(name: "Arthur", age: 41).insert(db) do { - let person = try Person.fetchOne(db, "SELECT * FROM persons")! + let person = try Person.fetchOne(db, sql: "SELECT * FROM persons")! let changes = person.databaseChanges XCTAssertEqual(changes.count, 0) } do { - let persons = try Person.fetchAll(db, "SELECT * FROM persons") + let persons = try Person.fetchAll(db, sql: "SELECT * FROM persons") let changes = persons[0].databaseChanges XCTAssertEqual(changes.count, 0) } do { - let persons = try Person.fetchCursor(db, "SELECT * FROM persons") + let persons = try Person.fetchCursor(db, sql: "SELECT * FROM persons") let changes = try persons.next()!.databaseChanges XCTAssertEqual(changes.count, 0) } do { - let person = try Person.fetchOne(db, "SELECT * FROM persons", adapter: SuffixRowAdapter(fromIndex: 0))! + let person = try Person.fetchOne(db, sql: "SELECT * FROM persons", adapter: SuffixRowAdapter(fromIndex: 0))! let changes = person.databaseChanges XCTAssertEqual(changes.count, 0) } } try dbQueue.inDatabase { db in try PersonWithModifiedCaseColumns(name: "Arthur", age: 41).insert(db) - let person = try PersonWithModifiedCaseColumns.fetchOne(db, "SELECT * FROM persons")! + let person = try PersonWithModifiedCaseColumns.fetchOne(db, sql: "SELECT * FROM persons")! let changes = person.databaseChanges XCTAssertEqual(changes.count, 0) } @@ -511,7 +509,7 @@ class RecordEditedTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try Person(name: "Arthur", age: 41).insert(db) - let person = try Person.fetchOne(db, "SELECT name FROM persons")! + let person = try Person.fetchOne(db, sql: "SELECT name FROM persons")! let changes = person.databaseChanges XCTAssertEqual(changes.count, 3) for (column, old) in changes { @@ -529,7 +527,7 @@ class RecordEditedTests: GRDBTestCase { } try dbQueue.inDatabase { db in try PersonWithModifiedCaseColumns(name: "Arthur", age: 41).insert(db) - let person = try PersonWithModifiedCaseColumns.fetchOne(db, "SELECT name FROM persons")! + let person = try PersonWithModifiedCaseColumns.fetchOne(db, sql: "SELECT name FROM persons")! let changes = person.databaseChanges XCTAssertEqual(changes.count, 3) for (column, old) in changes { diff --git a/Tests/GRDBTests/RecordInitializersTests.swift b/Tests/GRDBTests/RecordInitializersTests.swift index b5b86a571..43ecf827d 100644 --- a/Tests/GRDBTests/RecordInitializersTests.swift +++ b/Tests/GRDBTests/RecordInitializersTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -110,10 +108,10 @@ class RecordInitializersTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE pedigrees (foo INTEGER)") - try db.execute("INSERT INTO pedigrees (foo) VALUES (NULL)") + try db.execute(sql: "CREATE TABLE pedigrees (foo INTEGER)") + try db.execute(sql: "INSERT INTO pedigrees (foo) VALUES (NULL)") - let pedigree = try RecordWithPedigree.fetchOne(db, "SELECT * FROM pedigrees")! + let pedigree = try RecordWithPedigree.fetchOne(db, sql: "SELECT * FROM pedigrees")! XCTAssertTrue(pedigree.initializedFromRow) // very important } } diff --git a/Tests/GRDBTests/RecordMinimalPrimaryKeyRowIDTests.swift b/Tests/GRDBTests/RecordMinimalPrimaryKeyRowIDTests.swift index 65dd3e4ca..b36a05e08 100644 --- a/Tests/GRDBTests/RecordMinimalPrimaryKeyRowIDTests.swift +++ b/Tests/GRDBTests/RecordMinimalPrimaryKeyRowIDTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -18,8 +16,7 @@ class MinimalRowID : Record { } static func setup(inDatabase db: Database) throws { - try db.execute( - "CREATE TABLE minimalRowIDs (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE minimalRowIDs (id INTEGER PRIMARY KEY)") } // Record @@ -61,7 +58,7 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase { try record.insert(db) XCTAssertTrue(record.id != nil) - let row = try Row.fetchOne(db, "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -73,7 +70,7 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase { record.id = 123456 try record.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -100,7 +97,7 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase { try record.delete(db) try record.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -116,8 +113,10 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase { do { try record.update(db) XCTFail("Expected PersistenceError.recordNotFound") - } catch PersistenceError.recordNotFound { + } catch let PersistenceError.recordNotFound(databaseTableName: databaseTableName, key: key) { // Expected PersistenceError.recordNotFound + XCTAssertEqual(databaseTableName, "minimalRowIDs") + XCTAssertEqual(key, ["id": record.id.databaseValue]) } } } @@ -129,7 +128,7 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase { try record.insert(db) try record.update(db) - let row = try Row.fetchOne(db, "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -143,8 +142,10 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase { do { try record.update(db) XCTFail("Expected PersistenceError.recordNotFound") - } catch PersistenceError.recordNotFound { + } catch let PersistenceError.recordNotFound(databaseTableName: databaseTableName, key: key) { // Expected PersistenceError.recordNotFound + XCTAssertEqual(databaseTableName, "minimalRowIDs") + XCTAssertEqual(key, ["id": record.id.databaseValue]) } } } @@ -160,7 +161,7 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase { try record.save(db) XCTAssertTrue(record.id != nil) - let row = try Row.fetchOne(db, "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -172,7 +173,7 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase { record.id = 123456 try record.save(db) - let row = try Row.fetchOne(db, "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -184,7 +185,7 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase { try record.insert(db) try record.save(db) - let row = try Row.fetchOne(db, "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -197,7 +198,7 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase { try record.delete(db) try record.save(db) - let row = try Row.fetchOne(db, "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -223,7 +224,7 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase { let deleted = try record.delete(db) XCTAssertTrue(deleted) - let row = try Row.fetchOne(db, "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id]) + let row = try Row.fetchOne(db, sql: "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id]) XCTAssertTrue(row == nil) } } @@ -307,6 +308,7 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase { let fetchedRecord = try MinimalRowID.fetchOne(db, key: ["id": record.id])! XCTAssertTrue(fetchedRecord.id == record.id) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"minimalRowIDs\" WHERE (\"id\" = \(record.id!))") } } @@ -377,6 +379,7 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase { let fetchedRecord = try MinimalRowID.filter(key: ["id": record.id]).fetchOne(db)! XCTAssertTrue(fetchedRecord.id == record.id) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"minimalRowIDs\" WHERE (\"id\" = \(record.id!))") } } @@ -457,6 +460,7 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase { do { let fetchedRecord = try MinimalRowID.fetchOne(db, key: record.id)! XCTAssertTrue(fetchedRecord.id == record.id) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"minimalRowIDs\" WHERE (\"id\" = \(record.id!))") } } } @@ -526,6 +530,7 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase { do { let fetchedRecord = try MinimalRowID.filter(key: record.id).fetchOne(db)! XCTAssertTrue(fetchedRecord.id == record.id) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"minimalRowIDs\" WHERE (\"id\" = \(record.id!))") } } } diff --git a/Tests/GRDBTests/RecordMinimalPrimaryKeySingleTests.swift b/Tests/GRDBTests/RecordMinimalPrimaryKeySingleTests.swift index 1615624cd..7293c35e3 100644 --- a/Tests/GRDBTests/RecordMinimalPrimaryKeySingleTests.swift +++ b/Tests/GRDBTests/RecordMinimalPrimaryKeySingleTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -18,8 +16,7 @@ class MinimalSingle: Record { } static func setup(inDatabase db: Database) throws { - try db.execute( - "CREATE TABLE minimalSingles (UUID TEXT NOT NULL PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE minimalSingles (UUID TEXT NOT NULL PRIMARY KEY)") } // Record @@ -70,7 +67,7 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase { record.UUID = "theUUID" try record.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID])! assert(record, isEncodedIn: row) } } @@ -99,7 +96,7 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase { try record.delete(db) try record.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID])! assert(record, isEncodedIn: row) } } @@ -115,8 +112,10 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase { do { try record.update(db) XCTFail("Expected PersistenceError.recordNotFound") - } catch PersistenceError.recordNotFound { + } catch let PersistenceError.recordNotFound(databaseTableName: databaseTableName, key: key) { // Expected PersistenceError.recordNotFound + XCTAssertEqual(databaseTableName, "minimalSingles") + XCTAssertEqual(key, ["UUID": "theUUID".databaseValue]) } } } @@ -129,7 +128,7 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase { try record.insert(db) try record.update(db) - let row = try Row.fetchOne(db, "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID])! assert(record, isEncodedIn: row) } } @@ -144,8 +143,10 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase { do { try record.update(db) XCTFail("Expected PersistenceError.recordNotFound") - } catch PersistenceError.recordNotFound { + } catch let PersistenceError.recordNotFound(databaseTableName: databaseTableName, key: key) { // Expected PersistenceError.recordNotFound + XCTAssertEqual(databaseTableName, "minimalSingles") + XCTAssertEqual(key, ["UUID": "theUUID".databaseValue]) } } } @@ -174,7 +175,7 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase { record.UUID = "theUUID" try record.save(db) - let row = try Row.fetchOne(db, "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID])! assert(record, isEncodedIn: row) } } @@ -187,7 +188,7 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase { try record.insert(db) try record.save(db) - let row = try Row.fetchOne(db, "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID])! assert(record, isEncodedIn: row) } } @@ -201,7 +202,7 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase { try record.delete(db) try record.save(db) - let row = try Row.fetchOne(db, "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID])! assert(record, isEncodedIn: row) } } @@ -228,7 +229,7 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase { let deleted = try record.delete(db) XCTAssertTrue(deleted) - let row = try Row.fetchOne(db, "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID]) + let row = try Row.fetchOne(db, sql: "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID]) XCTAssertTrue(row == nil) } } @@ -318,6 +319,7 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase { let fetchedRecord = try MinimalSingle.fetchOne(db, key: ["UUID": record.UUID])! XCTAssertTrue(fetchedRecord.UUID == record.UUID) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"minimalSingles\" WHERE (\"UUID\" = '\(record.UUID!)')") } } @@ -393,6 +395,7 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase { let fetchedRecord = try MinimalSingle.filter(key: ["UUID": record.UUID]).fetchOne(db)! XCTAssertTrue(fetchedRecord.UUID == record.UUID) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"minimalSingles\" WHERE (\"UUID\" = '\(record.UUID!)')") } } @@ -478,6 +481,7 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase { do { let fetchedRecord = try MinimalSingle.fetchOne(db, key: record.UUID)! XCTAssertTrue(fetchedRecord.UUID == record.UUID) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"minimalSingles\" WHERE (\"UUID\" = '\(record.UUID!)')") } } } @@ -552,6 +556,7 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase { do { let fetchedRecord = try MinimalSingle.filter(key: record.UUID).fetchOne(db)! XCTAssertTrue(fetchedRecord.UUID == record.UUID) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"minimalSingles\" WHERE (\"UUID\" = '\(record.UUID!)')") } } } diff --git a/Tests/GRDBTests/RecordPersistenceConflictPolicy.swift b/Tests/GRDBTests/RecordPersistenceConflictPolicy.swift index 27f9adc71..b6cbd0467 100644 --- a/Tests/GRDBTests/RecordPersistenceConflictPolicy.swift +++ b/Tests/GRDBTests/RecordPersistenceConflictPolicy.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/RecordPrimaryKeyHiddenRowIDTests.swift b/Tests/GRDBTests/RecordPrimaryKeyHiddenRowIDTests.swift index 4a8ab4b90..016f872b7 100644 --- a/Tests/GRDBTests/RecordPrimaryKeyHiddenRowIDTests.swift +++ b/Tests/GRDBTests/RecordPrimaryKeyHiddenRowIDTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -23,7 +21,7 @@ private class Person : Record { } static func setup(inDatabase db: Database) throws { - try db.execute(""" + try db.execute(sql: """ CREATE TABLE persons ( creationDate TEXT NOT NULL, name TEXT NOT NULL, @@ -89,7 +87,7 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase { try record.insert(db) XCTAssertTrue(record.id != nil) - let row = try Row.fetchOne(db, "SELECT *, rowid FROM persons WHERE rowid = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT *, rowid FROM persons WHERE rowid = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -102,7 +100,7 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase { try record.insert(db) XCTAssertTrue(record.id != nil) - let row = try Row.fetchOne(db, "SELECT *, rowid FROM persons WHERE rowid = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT *, rowid FROM persons WHERE rowid = ?", arguments: [record.id])! assert(record, isEncodedIn: row) return .rollback } @@ -116,7 +114,7 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase { let record = Person(id: 123456, name: "Arthur") try record.insert(db) - let row = try Row.fetchOne(db, "SELECT *, rowid FROM persons WHERE rowid = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT *, rowid FROM persons WHERE rowid = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -154,7 +152,7 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase { try record.delete(db) try record.insert(db) - let row = try Row.fetchOne(db, "SELECT *, rowid FROM persons WHERE rowid = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT *, rowid FROM persons WHERE rowid = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -169,8 +167,10 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase { do { try record.update(db) XCTFail("Expected PersistenceError.recordNotFound") - } catch PersistenceError.recordNotFound { + } catch let PersistenceError.recordNotFound(databaseTableName: databaseTableName, key: key) { // Expected PersistenceError.recordNotFound + XCTAssertEqual(databaseTableName, "persons") + XCTAssertEqual(key, ["rowid": .null]) } } } @@ -182,8 +182,10 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase { do { try record.update(db) XCTFail("Expected PersistenceError.recordNotFound") - } catch PersistenceError.recordNotFound { + } catch let PersistenceError.recordNotFound(databaseTableName: databaseTableName, key: key) { // Expected PersistenceError.recordNotFound + XCTAssertEqual(databaseTableName, "persons") + XCTAssertEqual(key, ["rowid": record.id.databaseValue]) } } } @@ -196,7 +198,7 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase { record.age = record.age! + 1 try record.update(db) - let row = try Row.fetchOne(db, "SELECT *, rowid FROM persons WHERE rowid = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT *, rowid FROM persons WHERE rowid = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -210,8 +212,10 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase { do { try record.update(db) XCTFail("Expected PersistenceError.recordNotFound") - } catch PersistenceError.recordNotFound { + } catch let PersistenceError.recordNotFound(databaseTableName: databaseTableName, key: key) { // Expected PersistenceError.recordNotFound + XCTAssertEqual(databaseTableName, "persons") + XCTAssertEqual(key, ["rowid": record.id.databaseValue]) } } } @@ -227,7 +231,7 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase { try record.save(db) XCTAssertTrue(record.id != nil) - let row = try Row.fetchOne(db, "SELECT *, rowid FROM persons WHERE rowid = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT *, rowid FROM persons WHERE rowid = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -238,7 +242,7 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase { let record = Person(id: 123456, name: "Arthur") try record.save(db) - let row = try Row.fetchOne(db, "SELECT *, rowid FROM persons WHERE rowid = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT *, rowid FROM persons WHERE rowid = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -253,7 +257,7 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase { record.age = record.age! + 1 try record.save(db) // Actual update - let row = try Row.fetchOne(db, "SELECT *, rowid FROM persons WHERE rowid = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT *, rowid FROM persons WHERE rowid = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -266,7 +270,7 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase { try record.delete(db) try record.save(db) - let row = try Row.fetchOne(db, "SELECT *, rowid FROM persons WHERE rowid = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT *, rowid FROM persons WHERE rowid = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -300,7 +304,7 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase { let deleted = try record.delete(db) XCTAssertTrue(deleted) - let row = try Row.fetchOne(db, "SELECT * FROM persons WHERE rowid = ?", arguments: [record.id]) + let row = try Row.fetchOne(db, sql: "SELECT * FROM persons WHERE rowid = ?", arguments: [record.id]) XCTAssertTrue(row == nil) } } @@ -387,6 +391,7 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase { XCTAssertTrue(fetchedRecord.name == record.name) XCTAssertTrue(fetchedRecord.age == record.age) XCTAssertTrue(abs(fetchedRecord.creationDate.timeIntervalSince(record.creationDate)) < 1e-3) // ISO-8601 is precise to the millisecond. + XCTAssertEqual(lastSQLQuery, "SELECT *, \"rowid\" FROM \"persons\" WHERE (\"rowid\" = \(record.id!))") } } @@ -460,6 +465,7 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase { XCTAssertTrue(fetchedRecord.name == record.name) XCTAssertTrue(fetchedRecord.age == record.age) XCTAssertTrue(abs(fetchedRecord.creationDate.timeIntervalSince(record.creationDate)) < 1e-3) // ISO-8601 is precise to the millisecond. + XCTAssertEqual(lastSQLQuery, "SELECT *, \"rowid\" FROM \"persons\" WHERE (\"rowid\" = \(record.id!))") } } @@ -543,6 +549,7 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase { XCTAssertTrue(fetchedRecord.name == record.name) XCTAssertTrue(fetchedRecord.age == record.age) XCTAssertTrue(abs(fetchedRecord.creationDate.timeIntervalSince(record.creationDate)) < 1e-3) // ISO-8601 is precise to the millisecond. + XCTAssertEqual(lastSQLQuery, "SELECT *, \"rowid\" FROM \"persons\" WHERE (\"rowid\" = \(record.id!))") } } } @@ -615,6 +622,7 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase { XCTAssertTrue(fetchedRecord.name == record.name) XCTAssertTrue(fetchedRecord.age == record.age) XCTAssertTrue(abs(fetchedRecord.creationDate.timeIntervalSince(record.creationDate)) < 1e-3) // ISO-8601 is precise to the millisecond. + XCTAssertEqual(lastSQLQuery, "SELECT *, \"rowid\" FROM \"persons\" WHERE (\"rowid\" = \(record.id!))") } } } diff --git a/Tests/GRDBTests/RecordPrimaryKeyMultipleTests.swift b/Tests/GRDBTests/RecordPrimaryKeyMultipleTests.swift index c153f6ffc..d14e4d6e5 100644 --- a/Tests/GRDBTests/RecordPrimaryKeyMultipleTests.swift +++ b/Tests/GRDBTests/RecordPrimaryKeyMultipleTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -21,7 +19,7 @@ private class Citizenship : Record { } static func setup(inDatabase db: Database) throws { - try db.execute(""" + try db.execute(sql: """ CREATE TABLE citizenships ( personName TEXT NOT NULL, countryName TEXT NOT NULL, @@ -82,7 +80,7 @@ class RecordPrimaryKeyMultipleTests: GRDBTestCase { let record = Citizenship(personName: "Arthur", countryName: "France", native: true) try record.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName])! assert(record, isEncodedIn: row) } } @@ -109,7 +107,7 @@ class RecordPrimaryKeyMultipleTests: GRDBTestCase { try record.delete(db) try record.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName])! assert(record, isEncodedIn: row) } } @@ -124,8 +122,10 @@ class RecordPrimaryKeyMultipleTests: GRDBTestCase { do { try record.update(db) XCTFail("Expected PersistenceError.recordNotFound") - } catch PersistenceError.recordNotFound { + } catch let PersistenceError.recordNotFound(databaseTableName: databaseTableName, key: key) { // Expected PersistenceError.recordNotFound + XCTAssertEqual(databaseTableName, "citizenships") + XCTAssertEqual(key, ["countryName": .null, "personName": .null]) } } } @@ -137,8 +137,10 @@ class RecordPrimaryKeyMultipleTests: GRDBTestCase { do { try record.update(db) XCTFail("Expected PersistenceError.recordNotFound") - } catch PersistenceError.recordNotFound { + } catch let PersistenceError.recordNotFound(databaseTableName: databaseTableName, key: key) { // Expected PersistenceError.recordNotFound + XCTAssertEqual(databaseTableName, "citizenships") + XCTAssertEqual(key, ["countryName": "France".databaseValue, "personName": "Arthur".databaseValue]) } } } @@ -151,7 +153,7 @@ class RecordPrimaryKeyMultipleTests: GRDBTestCase { record.native = false try record.update(db) - let row = try Row.fetchOne(db, "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName])! assert(record, isEncodedIn: row) } } @@ -165,8 +167,10 @@ class RecordPrimaryKeyMultipleTests: GRDBTestCase { do { try record.update(db) XCTFail("Expected PersistenceError.recordNotFound") - } catch PersistenceError.recordNotFound { + } catch let PersistenceError.recordNotFound(databaseTableName: databaseTableName, key: key) { // Expected PersistenceError.recordNotFound + XCTAssertEqual(databaseTableName, "citizenships") + XCTAssertEqual(key, ["countryName": "France".databaseValue, "personName": "Arthur".databaseValue]) } } } @@ -194,7 +198,7 @@ class RecordPrimaryKeyMultipleTests: GRDBTestCase { let record = Citizenship(personName: "Arthur", countryName: "France", native: true) try record.save(db) - let row = try Row.fetchOne(db, "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName])! assert(record, isEncodedIn: row) } } @@ -208,7 +212,7 @@ class RecordPrimaryKeyMultipleTests: GRDBTestCase { record.native = false try record.save(db) // Actual update - let row = try Row.fetchOne(db, "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName])! assert(record, isEncodedIn: row) } } @@ -221,7 +225,7 @@ class RecordPrimaryKeyMultipleTests: GRDBTestCase { try record.delete(db) try record.save(db) - let row = try Row.fetchOne(db, "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName])! assert(record, isEncodedIn: row) } } @@ -255,7 +259,7 @@ class RecordPrimaryKeyMultipleTests: GRDBTestCase { let deleted = try record.delete(db) XCTAssertTrue(deleted) - let row = try Row.fetchOne(db, "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName]) + let row = try Row.fetchOne(db, sql: "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName]) XCTAssertTrue(row == nil) } } @@ -341,6 +345,7 @@ class RecordPrimaryKeyMultipleTests: GRDBTestCase { XCTAssertTrue(fetchedRecord.personName == record.personName) XCTAssertTrue(fetchedRecord.countryName == record.countryName) XCTAssertTrue(fetchedRecord.native == record.native) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"citizenships\" WHERE ((\"personName\" = '\(record.personName!)') AND (\"countryName\" = '\(record.countryName!)'))") } } @@ -413,6 +418,7 @@ class RecordPrimaryKeyMultipleTests: GRDBTestCase { XCTAssertTrue(fetchedRecord.personName == record.personName) XCTAssertTrue(fetchedRecord.countryName == record.countryName) XCTAssertTrue(fetchedRecord.native == record.native) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"citizenships\" WHERE ((\"personName\" = '\(record.personName!)') AND (\"countryName\" = '\(record.countryName!)'))") } } diff --git a/Tests/GRDBTests/RecordPrimaryKeyNoneTests.swift b/Tests/GRDBTests/RecordPrimaryKeyNoneTests.swift index 34f15af93..b066f9b53 100644 --- a/Tests/GRDBTests/RecordPrimaryKeyNoneTests.swift +++ b/Tests/GRDBTests/RecordPrimaryKeyNoneTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -21,7 +19,7 @@ private class Item : Record { } static func setup(inDatabase db: Database) throws { - try db.execute(""" + try db.execute(sql: """ CREATE TABLE items ( name TEXT, email TEXT UNIQUE) @@ -69,7 +67,7 @@ class RecordPrimaryKeyNoneTests: GRDBTestCase { XCTAssertTrue(record.insertedRowIDColumn == nil) try record.insert(db) - let names = try String.fetchAll(db, "SELECT name FROM items") + let names = try String.fetchAll(db, sql: "SELECT name FROM items") XCTAssertEqual(names, ["Table", "Table"]) } } @@ -84,7 +82,7 @@ class RecordPrimaryKeyNoneTests: GRDBTestCase { try record.save(db) try record.save(db) - let names = try String.fetchAll(db, "SELECT name FROM items") + let names = try String.fetchAll(db, sql: "SELECT name FROM items") XCTAssertEqual(names, ["Table", "Table"]) } } @@ -100,6 +98,7 @@ class RecordPrimaryKeyNoneTests: GRDBTestCase { let fetchedRecord = try Item.fetchOne(db, key: ["email": record.email])! XCTAssertTrue(fetchedRecord.email == record.email) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"items\" WHERE (\"email\" = 'item@example.com')") } } @@ -114,6 +113,7 @@ class RecordPrimaryKeyNoneTests: GRDBTestCase { let fetchedRecord = try Item.filter(key: ["email": record.email]).fetchOne(db)! XCTAssertTrue(fetchedRecord.email == record.email) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"items\" WHERE (\"email\" = 'item@example.com')") } } @@ -152,7 +152,9 @@ class RecordPrimaryKeyNoneTests: GRDBTestCase { let ids = [id1, id2] let cursor = try Item.fetchCursor(db, keys: ids) let fetchedRecords = try [cursor.next()!, cursor.next()!] - XCTAssertEqual(Set(fetchedRecords.map { $0.name! }), Set([record1, record2].map { $0.name! })) + let fetchedNames = Set(fetchedRecords.map { $0.name! }) + let expectedNames = Set([record1, record2].map { $0.name! }) + XCTAssertEqual(fetchedNames, expectedNames) XCTAssertTrue(try cursor.next() == nil) // end } } @@ -178,7 +180,9 @@ class RecordPrimaryKeyNoneTests: GRDBTestCase { let ids = [id1, id2] let fetchedRecords = try Item.fetchAll(db, keys: ids) XCTAssertEqual(fetchedRecords.count, 2) - XCTAssertEqual(Set(fetchedRecords.map { $0.name! }), Set([record1, record2].map { $0.name! })) + let fetchedNames = Set(fetchedRecords.map { $0.name! }) + let expectedNames = Set([record1, record2].map { $0.name! }) + XCTAssertEqual(fetchedNames, expectedNames) } } } @@ -199,6 +203,7 @@ class RecordPrimaryKeyNoneTests: GRDBTestCase { do { let fetchedRecord = try Item.fetchOne(db, key: id)! XCTAssertTrue(fetchedRecord.name == record.name) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"items\" WHERE (\"rowid\" = \(id))") } } } @@ -226,7 +231,9 @@ class RecordPrimaryKeyNoneTests: GRDBTestCase { let ids = [id1, id2] let cursor = try Item.filter(keys: ids).fetchCursor(db) let fetchedRecords = try [cursor.next()!, cursor.next()!] - XCTAssertEqual(Set(fetchedRecords.map { $0.name! }), Set([record1, record2].map { $0.name! })) + let fetchedNames = Set(fetchedRecords.map { $0.name! }) + let expectedNames = Set([record1, record2].map { $0.name! }) + XCTAssertEqual(fetchedNames, expectedNames) XCTAssertTrue(try cursor.next() == nil) // end } } @@ -252,7 +259,9 @@ class RecordPrimaryKeyNoneTests: GRDBTestCase { let ids = [id1, id2] let fetchedRecords = try Item.filter(keys: ids).fetchAll(db) XCTAssertEqual(fetchedRecords.count, 2) - XCTAssertEqual(Set(fetchedRecords.map { $0.name! }), Set([record1, record2].map { $0.name! })) + let fetchedNames = Set(fetchedRecords.map { $0.name! }) + let expectedNames = Set([record1, record2].map { $0.name! }) + XCTAssertEqual(fetchedNames, expectedNames) } } } @@ -273,6 +282,7 @@ class RecordPrimaryKeyNoneTests: GRDBTestCase { do { let fetchedRecord = try Item.filter(key: id).fetchOne(db)! XCTAssertTrue(fetchedRecord.name == record.name) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"items\" WHERE (\"rowid\" = \(id))") } } } diff --git a/Tests/GRDBTests/RecordPrimaryKeyRowIDTests.swift b/Tests/GRDBTests/RecordPrimaryKeyRowIDTests.swift index df044d945..391ce88ef 100644 --- a/Tests/GRDBTests/RecordPrimaryKeyRowIDTests.swift +++ b/Tests/GRDBTests/RecordPrimaryKeyRowIDTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -23,7 +21,7 @@ private class Person : Record { } static func setup(inDatabase db: Database) throws { - try db.execute(""" + try db.execute(sql: """ CREATE TABLE persons ( id INTEGER PRIMARY KEY, creationDate TEXT NOT NULL, @@ -86,7 +84,7 @@ class RecordPrimaryKeyRowIDTests: GRDBTestCase { try record.insert(db) XCTAssertTrue(record.id != nil) - let row = try Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM persons WHERE id = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -99,7 +97,7 @@ class RecordPrimaryKeyRowIDTests: GRDBTestCase { try record.insert(db) XCTAssertTrue(record.id != nil) - let row = try Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM persons WHERE id = ?", arguments: [record.id])! assert(record, isEncodedIn: row) return .rollback } @@ -113,7 +111,7 @@ class RecordPrimaryKeyRowIDTests: GRDBTestCase { let record = Person(id: 123456, name: "Arthur") try record.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM persons WHERE id = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -151,7 +149,7 @@ class RecordPrimaryKeyRowIDTests: GRDBTestCase { try record.delete(db) try record.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM persons WHERE id = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -166,8 +164,10 @@ class RecordPrimaryKeyRowIDTests: GRDBTestCase { do { try record.update(db) XCTFail("Expected PersistenceError.recordNotFound") - } catch PersistenceError.recordNotFound { + } catch let PersistenceError.recordNotFound(databaseTableName: databaseTableName, key: key) { // Expected PersistenceError.recordNotFound + XCTAssertEqual(databaseTableName, "persons") + XCTAssertEqual(key, ["id": .null]) } } } @@ -179,8 +179,10 @@ class RecordPrimaryKeyRowIDTests: GRDBTestCase { do { try record.update(db) XCTFail("Expected PersistenceError.recordNotFound") - } catch PersistenceError.recordNotFound { + } catch let PersistenceError.recordNotFound(databaseTableName: databaseTableName, key: key) { // Expected PersistenceError.recordNotFound + XCTAssertEqual(databaseTableName, "persons") + XCTAssertEqual(key, ["id": record.id.databaseValue]) } } } @@ -193,7 +195,7 @@ class RecordPrimaryKeyRowIDTests: GRDBTestCase { record.age = record.age! + 1 try record.update(db) - let row = try Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM persons WHERE id = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -207,8 +209,10 @@ class RecordPrimaryKeyRowIDTests: GRDBTestCase { do { try record.update(db) XCTFail("Expected PersistenceError.recordNotFound") - } catch PersistenceError.recordNotFound { + } catch let PersistenceError.recordNotFound(databaseTableName: databaseTableName, key: key) { // Expected PersistenceError.recordNotFound + XCTAssertEqual(databaseTableName, "persons") + XCTAssertEqual(key, ["id": record.id.databaseValue]) } } } @@ -224,7 +228,7 @@ class RecordPrimaryKeyRowIDTests: GRDBTestCase { try record.save(db) XCTAssertTrue(record.id != nil) - let row = try Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM persons WHERE id = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -235,7 +239,7 @@ class RecordPrimaryKeyRowIDTests: GRDBTestCase { let record = Person(id: 123456, name: "Arthur") try record.save(db) - let row = try Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM persons WHERE id = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -249,7 +253,7 @@ class RecordPrimaryKeyRowIDTests: GRDBTestCase { record.age = record.age! + 1 try record.save(db) // Actual update - let row = try Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM persons WHERE id = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -262,7 +266,7 @@ class RecordPrimaryKeyRowIDTests: GRDBTestCase { try record.delete(db) try record.save(db) - let row = try Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM persons WHERE id = ?", arguments: [record.id])! assert(record, isEncodedIn: row) } } @@ -296,7 +300,7 @@ class RecordPrimaryKeyRowIDTests: GRDBTestCase { let deleted = try record.delete(db) XCTAssertTrue(deleted) - let row = try Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id]) + let row = try Row.fetchOne(db, sql: "SELECT * FROM persons WHERE id = ?", arguments: [record.id]) XCTAssertTrue(row == nil) } } @@ -383,6 +387,7 @@ class RecordPrimaryKeyRowIDTests: GRDBTestCase { XCTAssertTrue(fetchedRecord.name == record.name) XCTAssertTrue(fetchedRecord.age == record.age) XCTAssertTrue(abs(fetchedRecord.creationDate.timeIntervalSince(record.creationDate)) < 1e-3) // ISO-8601 is precise to the millisecond. + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"persons\" WHERE (\"id\" = \(record.id!))") } } @@ -456,6 +461,7 @@ class RecordPrimaryKeyRowIDTests: GRDBTestCase { XCTAssertTrue(fetchedRecord.name == record.name) XCTAssertTrue(fetchedRecord.age == record.age) XCTAssertTrue(abs(fetchedRecord.creationDate.timeIntervalSince(record.creationDate)) < 1e-3) // ISO-8601 is precise to the millisecond. + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"persons\" WHERE (\"id\" = \(record.id!))") } } @@ -539,6 +545,7 @@ class RecordPrimaryKeyRowIDTests: GRDBTestCase { XCTAssertTrue(fetchedRecord.name == record.name) XCTAssertTrue(fetchedRecord.age == record.age) XCTAssertTrue(abs(fetchedRecord.creationDate.timeIntervalSince(record.creationDate)) < 1e-3) // ISO-8601 is precise to the millisecond. + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"persons\" WHERE (\"id\" = \(record.id!))") } } } @@ -611,6 +618,7 @@ class RecordPrimaryKeyRowIDTests: GRDBTestCase { XCTAssertTrue(fetchedRecord.name == record.name) XCTAssertTrue(fetchedRecord.age == record.age) XCTAssertTrue(abs(fetchedRecord.creationDate.timeIntervalSince(record.creationDate)) < 1e-3) // ISO-8601 is precise to the millisecond. + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"persons\" WHERE (\"id\" = \(record.id!))") } } } diff --git a/Tests/GRDBTests/RecordPrimaryKeySingleTests.swift b/Tests/GRDBTests/RecordPrimaryKeySingleTests.swift index fdd2ae692..6514db703 100644 --- a/Tests/GRDBTests/RecordPrimaryKeySingleTests.swift +++ b/Tests/GRDBTests/RecordPrimaryKeySingleTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -19,7 +17,7 @@ class Pet : Record { } static func setup(inDatabase db: Database) throws { - try db.execute(""" + try db.execute(sql: """ CREATE TABLE pets ( UUID TEXT NOT NULL PRIMARY KEY, name TEXT NOT NULL) @@ -75,7 +73,7 @@ class RecordPrimaryKeySingleTests: GRDBTestCase { let record = Pet(UUID: "BobbyUUID", name: "Bobby") try record.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID])! assert(record, isEncodedIn: row) } } @@ -102,7 +100,7 @@ class RecordPrimaryKeySingleTests: GRDBTestCase { try record.delete(db) try record.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID])! assert(record, isEncodedIn: row) } } @@ -117,8 +115,10 @@ class RecordPrimaryKeySingleTests: GRDBTestCase { do { try record.update(db) XCTFail("Expected PersistenceError.recordNotFound") - } catch PersistenceError.recordNotFound { + } catch let PersistenceError.recordNotFound(databaseTableName: databaseTableName, key: key) { // Expected PersistenceError.recordNotFound + XCTAssertEqual(databaseTableName, "pets") + XCTAssertEqual(key, ["UUID": .null]) } } } @@ -130,8 +130,10 @@ class RecordPrimaryKeySingleTests: GRDBTestCase { do { try record.update(db) XCTFail("Expected PersistenceError.recordNotFound") - } catch PersistenceError.recordNotFound { + } catch let PersistenceError.recordNotFound(databaseTableName: databaseTableName, key: key) { // Expected PersistenceError.recordNotFound + XCTAssertEqual(databaseTableName, "pets") + XCTAssertEqual(key, ["UUID": "BobbyUUID".databaseValue]) } } } @@ -144,7 +146,7 @@ class RecordPrimaryKeySingleTests: GRDBTestCase { record.name = "Carl" try record.update(db) - let row = try Row.fetchOne(db, "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID])! assert(record, isEncodedIn: row) } } @@ -158,8 +160,10 @@ class RecordPrimaryKeySingleTests: GRDBTestCase { do { try record.update(db) XCTFail("Expected PersistenceError.recordNotFound") - } catch PersistenceError.recordNotFound { + } catch let PersistenceError.recordNotFound(databaseTableName: databaseTableName, key: key) { // Expected PersistenceError.recordNotFound + XCTAssertEqual(databaseTableName, "pets") + XCTAssertEqual(key, ["UUID": "BobbyUUID".databaseValue]) } } } @@ -187,7 +191,7 @@ class RecordPrimaryKeySingleTests: GRDBTestCase { let record = Pet(UUID: "BobbyUUID", name: "Bobby") try record.save(db) - let row = try Row.fetchOne(db, "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID])! assert(record, isEncodedIn: row) } } @@ -201,7 +205,7 @@ class RecordPrimaryKeySingleTests: GRDBTestCase { record.name = "Carl" try record.save(db) // Actual update - let row = try Row.fetchOne(db, "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID])! assert(record, isEncodedIn: row) } } @@ -214,7 +218,7 @@ class RecordPrimaryKeySingleTests: GRDBTestCase { try record.delete(db) try record.save(db) - let row = try Row.fetchOne(db, "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID])! assert(record, isEncodedIn: row) } } @@ -248,7 +252,7 @@ class RecordPrimaryKeySingleTests: GRDBTestCase { let deleted = try record.delete(db) XCTAssertTrue(deleted) - let row = try Row.fetchOne(db, "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID]) + let row = try Row.fetchOne(db, sql: "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID]) XCTAssertTrue(row == nil) } } @@ -333,6 +337,7 @@ class RecordPrimaryKeySingleTests: GRDBTestCase { let fetchedRecord = try Pet.fetchOne(db, key: ["UUID": record.UUID])! XCTAssertTrue(fetchedRecord.UUID == record.UUID) XCTAssertTrue(fetchedRecord.name == record.name) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"pets\" WHERE (\"UUID\" = '\(record.UUID!)')") } } @@ -404,6 +409,7 @@ class RecordPrimaryKeySingleTests: GRDBTestCase { let fetchedRecord = try Pet.filter(key: ["UUID": record.UUID]).fetchOne(db)! XCTAssertTrue(fetchedRecord.UUID == record.UUID) XCTAssertTrue(fetchedRecord.name == record.name) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"pets\" WHERE (\"UUID\" = '\(record.UUID!)')") } } @@ -485,6 +491,7 @@ class RecordPrimaryKeySingleTests: GRDBTestCase { let fetchedRecord = try Pet.fetchOne(db, key: record.UUID)! XCTAssertTrue(fetchedRecord.UUID == record.UUID) XCTAssertTrue(fetchedRecord.name == record.name) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"pets\" WHERE (\"UUID\" = '\(record.UUID!)')") } } } @@ -555,6 +562,7 @@ class RecordPrimaryKeySingleTests: GRDBTestCase { let fetchedRecord = try Pet.filter(key: record.UUID).fetchOne(db)! XCTAssertTrue(fetchedRecord.UUID == record.UUID) XCTAssertTrue(fetchedRecord.name == record.name) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"pets\" WHERE (\"UUID\" = '\(record.UUID!)')") } } } diff --git a/Tests/GRDBTests/RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift b/Tests/GRDBTests/RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift index 3a550c14c..9eca41cdb 100644 --- a/Tests/GRDBTests/RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift +++ b/Tests/GRDBTests/RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -18,7 +16,7 @@ class Email : Record { } static func setup(inDatabase db: Database) throws { - try db.execute(""" + try db.execute(sql: """ CREATE TABLE emails ( email TEXT NOT NULL PRIMARY KEY ON CONFLICT REPLACE, label TEXT) @@ -76,7 +74,7 @@ class RecordPrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase { record.label = "Home" try record.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM emails WHERE email = ?", arguments: [record.email])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM emails WHERE email = ?", arguments: [record.email])! assert(record, isEncodedIn: row) } } @@ -91,7 +89,7 @@ class RecordPrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase { record.label = "Work" try record.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM emails WHERE email = ?", arguments: [record.email])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM emails WHERE email = ?", arguments: [record.email])! assert(record, isEncodedIn: row) } } @@ -105,7 +103,7 @@ class RecordPrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase { try record.delete(db) try record.insert(db) - let row = try Row.fetchOne(db, "SELECT * FROM emails WHERE email = ?", arguments: [record.email])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM emails WHERE email = ?", arguments: [record.email])! assert(record, isEncodedIn: row) } } @@ -121,8 +119,10 @@ class RecordPrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase { do { try record.update(db) XCTFail("Expected PersistenceError.recordNotFound") - } catch PersistenceError.recordNotFound { + } catch let PersistenceError.recordNotFound(databaseTableName: databaseTableName, key: key) { // Expected PersistenceError.recordNotFound + XCTAssertEqual(databaseTableName, "emails") + XCTAssertEqual(key, ["email": record.email.databaseValue]) } } } @@ -135,7 +135,7 @@ class RecordPrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase { try record.insert(db) try record.update(db) - let row = try Row.fetchOne(db, "SELECT * FROM emails WHERE email = ?", arguments: [record.email])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM emails WHERE email = ?", arguments: [record.email])! assert(record, isEncodedIn: row) } } @@ -150,8 +150,10 @@ class RecordPrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase { do { try record.update(db) XCTFail("Expected PersistenceError.recordNotFound") - } catch PersistenceError.recordNotFound { + } catch let PersistenceError.recordNotFound(databaseTableName: databaseTableName, key: key) { // Expected PersistenceError.recordNotFound + XCTAssertEqual(databaseTableName, "emails") + XCTAssertEqual(key, ["email": record.email.databaseValue]) } } } @@ -180,7 +182,7 @@ class RecordPrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase { record.email = "me@domain.com" try record.save(db) - let row = try Row.fetchOne(db, "SELECT * FROM emails WHERE email = ?", arguments: [record.email])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM emails WHERE email = ?", arguments: [record.email])! assert(record, isEncodedIn: row) } } @@ -193,7 +195,7 @@ class RecordPrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase { try record.insert(db) try record.save(db) - let row = try Row.fetchOne(db, "SELECT * FROM emails WHERE email = ?", arguments: [record.email])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM emails WHERE email = ?", arguments: [record.email])! assert(record, isEncodedIn: row) } } @@ -207,7 +209,7 @@ class RecordPrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase { try record.delete(db) try record.save(db) - let row = try Row.fetchOne(db, "SELECT * FROM emails WHERE email = ?", arguments: [record.email])! + let row = try Row.fetchOne(db, sql: "SELECT * FROM emails WHERE email = ?", arguments: [record.email])! assert(record, isEncodedIn: row) } } @@ -234,7 +236,7 @@ class RecordPrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase { let deleted = try record.delete(db) XCTAssertTrue(deleted) - let row = try Row.fetchOne(db, "SELECT * FROM emails WHERE email = ?", arguments: [record.email]) + let row = try Row.fetchOne(db, sql: "SELECT * FROM emails WHERE email = ?", arguments: [record.email]) XCTAssertTrue(row == nil) } } @@ -324,6 +326,7 @@ class RecordPrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase { let fetchedRecord = try Email.fetchOne(db, key: ["email": record.email])! XCTAssertTrue(fetchedRecord.email == record.email) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"emails\" WHERE (\"email\" = '\(record.email!)')") } } @@ -399,6 +402,7 @@ class RecordPrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase { let fetchedRecord = try Email.filter(key: ["email": record.email]).fetchOne(db)! XCTAssertTrue(fetchedRecord.email == record.email) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"emails\" WHERE (\"email\" = '\(record.email!)')") } } @@ -484,6 +488,7 @@ class RecordPrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase { do { let fetchedRecord = try Email.fetchOne(db, key: record.email)! XCTAssertTrue(fetchedRecord.email == record.email) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"emails\" WHERE (\"email\" = '\(record.email!)')") } } } @@ -558,6 +563,7 @@ class RecordPrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase { do { let fetchedRecord = try Email.filter(key: record.email).fetchOne(db)! XCTAssertTrue(fetchedRecord.email == record.email) + XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"emails\" WHERE (\"email\" = '\(record.email!)')") } } } diff --git a/Tests/GRDBTests/RecordSubClassTests.swift b/Tests/GRDBTests/RecordSubClassTests.swift index 1f100486b..cd50de393 100644 --- a/Tests/GRDBTests/RecordSubClassTests.swift +++ b/Tests/GRDBTests/RecordSubClassTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -22,7 +20,7 @@ private class Person : Record { } static func setup(inDatabase db: Database) throws { - try db.execute(""" + try db.execute(sql: """ CREATE TABLE persons ( id INTEGER PRIMARY KEY, creationDate TEXT NOT NULL, @@ -170,7 +168,7 @@ class RecordSubClassTests: GRDBTestCase { try record.insert(db) do { - let fetchedRecord = try PersonWithOverrides.fetchOne(db, "SELECT *, 123 as extra FROM persons")! + let fetchedRecord = try PersonWithOverrides.fetchOne(db, sql: "SELECT *, 123 as extra FROM persons")! XCTAssertTrue(fetchedRecord.id == record.id) XCTAssertTrue(fetchedRecord.name == record.name) XCTAssertTrue(fetchedRecord.age == record.age) @@ -179,7 +177,7 @@ class RecordSubClassTests: GRDBTestCase { } do { - let fetchedRecord = try MinimalPersonWithOverrides.fetchOne(db, "SELECT *, 123 as extra FROM persons")! + let fetchedRecord = try MinimalPersonWithOverrides.fetchOne(db, sql: "SELECT *, 123 as extra FROM persons")! XCTAssertTrue(fetchedRecord.id == record.id) XCTAssertTrue(fetchedRecord.name == record.name) XCTAssertTrue(fetchedRecord.age == record.age) diff --git a/Tests/GRDBTests/RecordUniqueIndexTests.swift b/Tests/GRDBTests/RecordUniqueIndexTests.swift index 6633e444f..86753ad10 100644 --- a/Tests/GRDBTests/RecordUniqueIndexTests.swift +++ b/Tests/GRDBTests/RecordUniqueIndexTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else @testable import GRDB @@ -18,7 +16,7 @@ class RecordUniqueIndexTests: GRDBTestCase { func testKeyFilterAcceptsUniqueIndex() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT, email TEXT UNIQUE)") + try db.execute(sql: "CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT, email TEXT UNIQUE)") _ = try Person.filter(keys: [["id": nil]]).fetchOne(db) _ = try Person.filter(keys: [["email": nil]]).fetchOne(db) diff --git a/Tests/GRDBTests/RecordWithColumnNameManglingTests.swift b/Tests/GRDBTests/RecordWithColumnNameManglingTests.swift index bf0c2e1b7..7a6f2d0b9 100644 --- a/Tests/GRDBTests/RecordWithColumnNameManglingTests.swift +++ b/Tests/GRDBTests/RecordWithColumnNameManglingTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -20,7 +18,7 @@ class BadlyMangledStuff : Record { } static func setup(inDatabase db: Database) throws { - try db.execute("CREATE TABLE stuffs (id INTEGER PRIMARY KEY, name TEXT)") + try db.execute(sql: "CREATE TABLE stuffs (id INTEGER PRIMARY KEY, name TEXT)") } // Record @@ -69,7 +67,7 @@ class RecordWithColumnNameManglingTests: GRDBTestCase { XCTAssertFalse(record.hasDatabaseChanges) } do { - let record = try BadlyMangledStuff.fetchOne(db, "SELECT id AS mangled_id, name AS mangled_name FROM stuffs")! + let record = try BadlyMangledStuff.fetchOne(db, sql: "SELECT id AS mangled_id, name AS mangled_name FROM stuffs")! // OK we could extract values. XCTAssertEqual(record.id, 1) XCTAssertEqual(record.name, "foo") diff --git a/Tests/GRDBTests/ResultCodeTests.swift b/Tests/GRDBTests/ResultCodeTests.swift index c83e76f0a..0bad5a141 100644 --- a/Tests/GRDBTests/ResultCodeTests.swift +++ b/Tests/GRDBTests/ResultCodeTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/Row+FoundationTests.swift b/Tests/GRDBTests/Row+FoundationTests.swift index fdbf69ea3..e8928e010 100644 --- a/Tests/GRDBTests/Row+FoundationTests.swift +++ b/Tests/GRDBTests/Row+FoundationTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/RowAdapterTests.swift b/Tests/GRDBTests/RowAdapterTests.swift index c5c79e8a7..f4533b807 100644 --- a/Tests/GRDBTests/RowAdapterTests.swift +++ b/Tests/GRDBTests/RowAdapterTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -19,7 +17,7 @@ class AdapterRowTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let adapter = ColumnMapping(["a": "basea", "b": "baseb", "c": "basec"]) - let row = try Row.fetchOne(db, "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 2 as basec", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 2 as basec", adapter: adapter)! var columnNames = [String]() var ints = [Int]() @@ -40,7 +38,7 @@ class AdapterRowTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let adapter = ColumnMapping(["a": "basea", "b": "baseb", "c": "basec"]) - let row = try Row.fetchOne(db, "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 2 as basec", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 2 as basec", adapter: adapter)! // Raw extraction assertRowRawValueEqual(row, index: 0, value: 0 as Int64) @@ -68,7 +66,7 @@ class AdapterRowTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let adapter = ColumnMapping(["a": "basea", "b": "baseb", "c": "basec"]) - let row = try Row.fetchOne(db, "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 2 as basec", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 2 as basec", adapter: adapter)! // Raw extraction assertRowRawValueEqual(row, name: "a", value: 0 as Int64) @@ -91,7 +89,7 @@ class AdapterRowTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let adapter = ColumnMapping(["a": "basea", "b": "baseb", "c": "basec"]) - let row = try Row.fetchOne(db, "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 2 as basec", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 2 as basec", adapter: adapter)! // Raw extraction assertRowRawValueEqual(row, column: Column("a"), value: 0 as Int64) @@ -116,7 +114,7 @@ class AdapterRowTests : RowTestCase { let data = "foo".data(using: .utf8)! let emptyData = Data() let adapter = ColumnMapping(["a": "basea", "b": "baseb", "c": "basec"]) - let row = try Row.fetchOne(db, "SELECT ? AS basea, ? AS baseb, ? AS basec", arguments: [data, emptyData, nil], adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT ? AS basea, ? AS baseb, ? AS basec", arguments: [data, emptyData, nil], adapter: adapter)! XCTAssertEqual(row.dataNoCopy(atIndex: 0), data) XCTAssertEqual(row.dataNoCopy(named: "a"), data) @@ -136,7 +134,7 @@ class AdapterRowTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let adapter = ColumnMapping(["null": "basenull", "int64": "baseint64", "double": "basedouble", "string": "basestring", "blob": "baseblob"]) - let row = try Row.fetchOne(db, "SELECT NULL AS basenull, 'XXX' AS extra, 1 AS baseint64, 1.1 AS basedouble, 'foo' AS basestring, x'53514C697465' AS baseblob", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT NULL AS basenull, 'XXX' AS extra, 1 AS baseint64, 1.1 AS basedouble, 'foo' AS basestring, x'53514C697465' AS baseblob", adapter: adapter)! guard case .null = (row[0] as DatabaseValue).storage else { XCTFail(); return } guard case .int64(let int64) = (row[1] as DatabaseValue).storage, int64 == 1 else { XCTFail(); return } @@ -150,7 +148,7 @@ class AdapterRowTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let adapter = ColumnMapping(["null": "basenull", "int64": "baseint64", "double": "basedouble", "string": "basestring", "blob": "baseblob"]) - let row = try Row.fetchOne(db, "SELECT NULL AS basenull, 'XXX' AS extra, 1 AS baseint64, 1.1 AS basedouble, 'foo' AS basestring, x'53514C697465' AS baseblob", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT NULL AS basenull, 'XXX' AS extra, 1 AS baseint64, 1.1 AS basedouble, 'foo' AS basestring, x'53514C697465' AS baseblob", adapter: adapter)! guard case .null = (row["null"] as DatabaseValue).storage else { XCTFail(); return } guard case .int64(let int64) = (row["int64"] as DatabaseValue).storage, int64 == 1 else { XCTFail(); return } @@ -164,7 +162,7 @@ class AdapterRowTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let adapter = ColumnMapping(["a": "basea", "b": "baseb", "c": "basec"]) - let row = try Row.fetchOne(db, "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 2 as basec", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 2 as basec", adapter: adapter)! XCTAssertEqual(row.count, 3) } @@ -174,7 +172,7 @@ class AdapterRowTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let adapter = ColumnMapping(["a": "basea", "b": "baseb", "c": "basec"]) - let row = try Row.fetchOne(db, "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 2 as basec", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 2 as basec", adapter: adapter)! XCTAssertEqual(Array(row.columnNames), ["a", "b", "c"]) } @@ -184,7 +182,7 @@ class AdapterRowTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let adapter = ColumnMapping(["a": "basea", "b": "baseb", "c": "basec"]) - let row = try Row.fetchOne(db, "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 2 as basec", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 2 as basec", adapter: adapter)! XCTAssertEqual(Array(row.databaseValues), [0.databaseValue, 1.databaseValue, 2.databaseValue]) } @@ -194,7 +192,7 @@ class AdapterRowTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let adapter = ColumnMapping(["nAmE": "basenAmE"]) - let row = try Row.fetchOne(db, "SELECT 'foo' AS basenAmE, 'XXX' AS extra", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 'foo' AS basenAmE, 'XXX' AS extra", adapter: adapter)! XCTAssertEqual(row["name"] as DatabaseValue, "foo".databaseValue) XCTAssertEqual(row["NAME"] as DatabaseValue, "foo".databaseValue) @@ -209,7 +207,7 @@ class AdapterRowTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let adapter = ColumnMapping(["name": "basename", "NAME": "baseNAME"]) - let row = try Row.fetchOne(db, "SELECT 1 AS basename, 'XXX' AS extra, 2 AS baseNAME", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 1 AS basename, 'XXX' AS extra, 2 AS baseNAME", adapter: adapter)! XCTAssertEqual(row["name"] as DatabaseValue, 1.databaseValue) XCTAssertEqual(row["NAME"] as DatabaseValue, 1.databaseValue) @@ -224,7 +222,7 @@ class AdapterRowTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let adapter = ColumnMapping(["name": "baseNaMe"]) - let row = try Row.fetchOne(db, "SELECT 1 AS basename, 2 AS baseNaMe, 3 AS BASENAME", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 1 AS basename, 2 AS baseNaMe, 3 AS BASENAME", adapter: adapter)! XCTAssertEqual(row["name"] as DatabaseValue, 1.databaseValue) } @@ -234,7 +232,7 @@ class AdapterRowTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let adapter = ColumnMapping(["name": "name"]) - let row = try Row.fetchOne(db, "SELECT 1 AS name, 'foo' AS missing", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 1 AS name, 'foo' AS missing", adapter: adapter)! XCTAssertFalse(row.hasColumn("missing")) XCTAssertFalse(row.hasColumn("missingInBaseRow")) @@ -249,7 +247,7 @@ class AdapterRowTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let adapter = ColumnMapping(["nAmE": "basenAmE", "foo": "basefoo"]) - let row = try Row.fetchOne(db, "SELECT 'foo' AS basenAmE, 'XXX' AS extra, 1 AS basefoo", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 'foo' AS basenAmE, 'XXX' AS extra, 1 AS basefoo", adapter: adapter)! XCTAssertTrue(row.hasColumn("name")) XCTAssertTrue(row.hasColumn("NAME")) @@ -267,7 +265,7 @@ class AdapterRowTests : RowTestCase { let adapter = ScopeAdapter([ "sub1": ColumnMapping(["id": "id1", "val": "val1"]), "sub2": ColumnMapping(["id": "id2", "val": "val2"])]) - let row = try Row.fetchOne(db, "SELECT 1 AS id1, 'foo1' AS val1, 2 as id2, 'foo2' AS val2", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 1 AS id1, 'foo1' AS val1, 2 as id2, 'foo2' AS val2", adapter: adapter)! XCTAssertEqual(row.count, 4) XCTAssertEqual(row["id1"] as Int, 1) @@ -312,7 +310,7 @@ class AdapterRowTests : RowTestCase { .addingScopes([ "sub1": ColumnMapping(["id": "id1", "val": "val1"]), "sub2": ColumnMapping(["id": "id2", "val": "val2"])]) - let row = try Row.fetchOne(db, "SELECT 0 AS id0, 'foo0' AS val0, 1 AS id1, 'foo1' AS val1, 2 as id2, 'foo2' AS val2", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 0 AS id0, 'foo0' AS val0, 1 AS id1, 'foo1' AS val1, 2 as id2, 'foo2' AS val2", adapter: adapter)! XCTAssertEqual(row.count, 2) XCTAssertEqual(row["id"] as Int, 0) @@ -361,7 +359,7 @@ class AdapterRowTests : RowTestCase { // - sub2 is defined in the the second scoped adapter let mainAdapter = ScopeAdapter(["sub0": adapter0, "sub1": adapter2]) let adapter = mainAdapter.addingScopes(["sub1": adapter1, "sub2": adapter2]) - let row = try Row.fetchOne(db, "SELECT 0 AS id0, 'foo0' AS val0, 1 AS id1, 'foo1' AS val1, 2 as id2, 'foo2' AS val2", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 0 AS id0, 'foo0' AS val0, 1 AS id1, 'foo1' AS val1, 2 as id2, 'foo2' AS val2", adapter: adapter)! XCTAssertEqual(Set(row.scopes.names), ["sub0", "sub1", "sub2"]) XCTAssertEqual(row.scopes.count, 3) @@ -401,7 +399,7 @@ class AdapterRowTests : RowTestCase { "sub1": ColumnMapping(["id": "id1", "val": "val1"]) .addingScopes([ "sub2": ColumnMapping(["id": "id2", "val": "val2"])])]) - let row = try Row.fetchOne(db, "SELECT 0 AS id0, 'foo0' AS val0, 1 AS id1, 'foo1' AS val1, 2 as id2, 'foo2' AS val2", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 0 AS id0, 'foo0' AS val0, 1 AS id1, 'foo1' AS val1, 2 as id2, 'foo2' AS val2", adapter: adapter)! XCTAssertEqual(row.count, 2) XCTAssertEqual(row["id"] as Int, 0) @@ -447,22 +445,22 @@ class AdapterRowTests : RowTestCase { try dbQueue.inDatabase { db in let sql = "SELECT 0 AS a0, 1 AS a1, 2 AS a2, 3 AS a3" do { - let row = try Row.fetchOne(db, sql, adapter: SuffixRowAdapter(fromIndex:0))! + let row = try Row.fetchOne(db, sql: sql, adapter: SuffixRowAdapter(fromIndex:0))! XCTAssertEqual(Array(row.columnNames), ["a0", "a1", "a2", "a3"]) XCTAssertEqual(Array(row.databaseValues), [0.databaseValue, 1.databaseValue, 2.databaseValue, 3.databaseValue]) } do { - let row = try Row.fetchOne(db, sql, adapter: SuffixRowAdapter(fromIndex:1))! + let row = try Row.fetchOne(db, sql: sql, adapter: SuffixRowAdapter(fromIndex:1))! XCTAssertEqual(Array(row.columnNames), ["a1", "a2", "a3"]) XCTAssertEqual(Array(row.databaseValues), [1.databaseValue, 2.databaseValue, 3.databaseValue]) } do { - let row = try Row.fetchOne(db, sql, adapter: SuffixRowAdapter(fromIndex:3))! + let row = try Row.fetchOne(db, sql: sql, adapter: SuffixRowAdapter(fromIndex:3))! XCTAssertEqual(Array(row.columnNames), ["a3"]) XCTAssertEqual(Array(row.databaseValues), [3.databaseValue]) } do { - let row = try Row.fetchOne(db, sql, adapter: SuffixRowAdapter(fromIndex:4))! + let row = try Row.fetchOne(db, sql: sql, adapter: SuffixRowAdapter(fromIndex:4))! XCTAssertEqual(Array(row.columnNames), []) XCTAssertEqual(Array(row.databaseValues), []) } @@ -476,7 +474,7 @@ class AdapterRowTests : RowTestCase { "sub1": SuffixRowAdapter(fromIndex: 1) .addingScopes([ "sub2": SuffixRowAdapter(fromIndex: 1)])]) - let row = try Row.fetchOne(db, "SELECT 0 AS a0, 1 AS a1, 2 AS a2, 3 AS a3", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 0 AS a0, 1 AS a1, 2 AS a2, 3 AS a3", adapter: adapter)! XCTAssertEqual(Set(row.scopes.names), ["sub1"]) XCTAssertEqual(row.scopes.count, 1) @@ -519,27 +517,27 @@ class AdapterRowTests : RowTestCase { try dbQueue.inDatabase { db in let sql = "SELECT 0 AS a0, 1 AS a1, 2 AS a2, 3 AS a3" do { - let row = try Row.fetchOne(db, sql, adapter: RangeRowAdapter(0..<0))! + let row = try Row.fetchOne(db, sql: sql, adapter: RangeRowAdapter(0..<0))! XCTAssertEqual(Array(row.columnNames), []) XCTAssertEqual(Array(row.databaseValues), []) } do { - let row = try Row.fetchOne(db, sql, adapter: RangeRowAdapter(0..<1))! + let row = try Row.fetchOne(db, sql: sql, adapter: RangeRowAdapter(0..<1))! XCTAssertEqual(Array(row.columnNames), ["a0"]) XCTAssertEqual(Array(row.databaseValues), [0.databaseValue]) } do { - let row = try Row.fetchOne(db, sql, adapter: RangeRowAdapter(1..<3))! + let row = try Row.fetchOne(db, sql: sql, adapter: RangeRowAdapter(1..<3))! XCTAssertEqual(Array(row.columnNames), ["a1", "a2"]) XCTAssertEqual(Array(row.databaseValues), [1.databaseValue, 2.databaseValue]) } do { - let row = try Row.fetchOne(db, sql, adapter: RangeRowAdapter(0..<4))! + let row = try Row.fetchOne(db, sql: sql, adapter: RangeRowAdapter(0..<4))! XCTAssertEqual(Array(row.columnNames), ["a0", "a1", "a2", "a3"]) XCTAssertEqual(Array(row.databaseValues), [0.databaseValue, 1.databaseValue, 2.databaseValue, 3.databaseValue]) } do { - let row = try Row.fetchOne(db, sql, adapter: RangeRowAdapter(4..<4))! + let row = try Row.fetchOne(db, sql: sql, adapter: RangeRowAdapter(4..<4))! XCTAssertEqual(Array(row.columnNames), []) XCTAssertEqual(Array(row.databaseValues), []) } @@ -551,27 +549,27 @@ class AdapterRowTests : RowTestCase { try dbQueue.inDatabase { db in let sql = "SELECT 0 AS a0, 1 AS a1, 2 AS a2, 3 AS a3" do { - let row = try Row.fetchOne(db, sql, adapter: RangeRowAdapter(0...0))! + let row = try Row.fetchOne(db, sql: sql, adapter: RangeRowAdapter(0...0))! XCTAssertEqual(Array(row.columnNames), ["a0"]) XCTAssertEqual(Array(row.databaseValues), [0.databaseValue]) } do { - let row = try Row.fetchOne(db, sql, adapter: RangeRowAdapter(0...1))! + let row = try Row.fetchOne(db, sql: sql, adapter: RangeRowAdapter(0...1))! XCTAssertEqual(Array(row.columnNames), ["a0", "a1"]) XCTAssertEqual(Array(row.databaseValues), [0.databaseValue, 1.databaseValue]) } do { - let row = try Row.fetchOne(db, sql, adapter: RangeRowAdapter(1...2))! + let row = try Row.fetchOne(db, sql: sql, adapter: RangeRowAdapter(1...2))! XCTAssertEqual(Array(row.columnNames), ["a1", "a2"]) XCTAssertEqual(Array(row.databaseValues), [1.databaseValue, 2.databaseValue]) } do { - let row = try Row.fetchOne(db, sql, adapter: RangeRowAdapter(0...3))! + let row = try Row.fetchOne(db, sql: sql, adapter: RangeRowAdapter(0...3))! XCTAssertEqual(Array(row.columnNames), ["a0", "a1", "a2", "a3"]) XCTAssertEqual(Array(row.databaseValues), [0.databaseValue, 1.databaseValue, 2.databaseValue, 3.databaseValue]) } do { - let row = try Row.fetchOne(db, sql, adapter: RangeRowAdapter(3...3))! + let row = try Row.fetchOne(db, sql: sql, adapter: RangeRowAdapter(3...3))! XCTAssertEqual(Array(row.columnNames), ["a3"]) XCTAssertEqual(Array(row.databaseValues), [3.databaseValue]) } @@ -585,7 +583,7 @@ class AdapterRowTests : RowTestCase { "sub1": RangeRowAdapter(1..<3) .addingScopes([ "sub2": RangeRowAdapter(1..<3)])]) - let row = try Row.fetchOne(db, "SELECT 0 AS a0, 1 AS a1, 2 AS a2, 3 AS a3", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 0 AS a0, 1 AS a1, 2 AS a2, 3 AS a3", adapter: adapter)! XCTAssertEqual(Set(row.scopes.names), ["sub1"]) XCTAssertEqual(row.scopes.count, 1) @@ -629,7 +627,7 @@ class AdapterRowTests : RowTestCase { let adapter = ColumnMapping(["a": "basea", "b": "baseb", "c": "basec"]) .addingScopes(["sub": ColumnMapping(["a": "baseb"])]) var copiedRow: Row? = nil - let baseRows = try Row.fetchCursor(db, "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 2 as basec", adapter: adapter) + let baseRows = try Row.fetchCursor(db, sql: "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 2 as basec", adapter: adapter) while let baseRow = try baseRows.next() { copiedRow = baseRow.copy() } @@ -666,7 +664,7 @@ class AdapterRowTests : RowTestCase { try dbQueue.inDatabase { db in let adapter = ColumnMapping(["a": "basea", "b": "baseb", "c": "basec"]) var row: Row? = nil - let baseRows = try Row.fetchCursor(db, "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 2 as basec", adapter: adapter) + let baseRows = try Row.fetchCursor(db, sql: "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 2 as basec", adapter: adapter) while let baseRow = try baseRows.next() { row = baseRow.copy() XCTAssertEqual(row, baseRow) @@ -692,11 +690,11 @@ class AdapterRowTests : RowTestCase { .addingScopes(["sub": ColumnMapping(["b": "baseb"]), "altSub": ColumnMapping(["a": "baseb2"])]) let adapter5 = ColumnMapping(["a": "basea", "b": "baseb", "c": "basec"]) .addingScopes(["sub": ColumnMapping(["b": "baseb", "c": "basec"])]) - let row1 = try Row.fetchOne(db, "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 1 AS baseb2, 2 as basec", adapter: adapter1)! - let row2 = try Row.fetchOne(db, "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 1 AS baseb2, 2 as basec", adapter: adapter2)! - let row3 = try Row.fetchOne(db, "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 1 AS baseb2, 2 as basec", adapter: adapter3)! - let row4 = try Row.fetchOne(db, "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 1 AS baseb2, 2 as basec", adapter: adapter4)! - let row5 = try Row.fetchOne(db, "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 1 AS baseb2, 2 as basec", adapter: adapter5)! + let row1 = try Row.fetchOne(db, sql: "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 1 AS baseb2, 2 as basec", adapter: adapter1)! + let row2 = try Row.fetchOne(db, sql: "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 1 AS baseb2, 2 as basec", adapter: adapter2)! + let row3 = try Row.fetchOne(db, sql: "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 1 AS baseb2, 2 as basec", adapter: adapter3)! + let row4 = try Row.fetchOne(db, sql: "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 1 AS baseb2, 2 as basec", adapter: adapter4)! + let row5 = try Row.fetchOne(db, sql: "SELECT 0 AS basea, 'XXX' AS extra, 1 AS baseb, 1 AS baseb2, 2 as basec", adapter: adapter5)! let tests = [ (row1, row2, false), @@ -720,10 +718,10 @@ class AdapterRowTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let adapter = ColumnMapping(["id": "baseid", "val": "baseval"]) - let mappedRow1 = try Row.fetchOne(db, "SELECT 1 AS baseid, 'XXX' AS extra, 'foo' AS baseval", adapter: adapter)! - let mappedRow2 = try Row.fetchOne(db, "SELECT 'foo' AS baseval, 'XXX' AS extra, 1 AS baseid", adapter: adapter)! - let nonMappedRow1 = try Row.fetchOne(db, "SELECT 1 AS id, 'foo' AS val")! - let nonMappedRow2 = try Row.fetchOne(db, "SELECT 'foo' AS val, 1 AS id")! + let mappedRow1 = try Row.fetchOne(db, sql: "SELECT 1 AS baseid, 'XXX' AS extra, 'foo' AS baseval", adapter: adapter)! + let mappedRow2 = try Row.fetchOne(db, sql: "SELECT 'foo' AS baseval, 'XXX' AS extra, 1 AS baseid", adapter: adapter)! + let nonMappedRow1 = try Row.fetchOne(db, sql: "SELECT 1 AS id, 'foo' AS val")! + let nonMappedRow2 = try Row.fetchOne(db, sql: "SELECT 'foo' AS val, 1 AS id")! // All rows contain the same values. But they differ by column ordering. XCTAssertEqual(Array(mappedRow1.columnNames), ["id", "val"]) @@ -744,7 +742,7 @@ class AdapterRowTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let adapter = ColumnMapping([:]) - let row = try Row.fetchOne(db, "SELECT 'foo' AS foo", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 'foo' AS foo", adapter: adapter)! XCTAssertTrue(row.isEmpty) XCTAssertEqual(row.count, 0) @@ -758,34 +756,34 @@ class AdapterRowTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in do { - let row = try SQLRequest("SELECT 0 AS a0, 1 AS a1, 2 AS a2", adapter: SuffixRowAdapter(fromIndex: 1)) + let row = try SQLRequest(sql: "SELECT 0 AS a0, 1 AS a1, 2 AS a2", adapter: SuffixRowAdapter(fromIndex: 1)) .fetchOne(db)! XCTAssertEqual(Array(row.columnNames), ["a1", "a2"]) XCTAssertEqual(Array(row.databaseValues), [1.databaseValue, 2.databaseValue]) } do { - let row = try SQLRequest("SELECT 0 AS a0, 1 AS a1, 2 AS a2") + let row = try SQLRequest(sql: "SELECT 0 AS a0, 1 AS a1, 2 AS a2") .adapted { _ in SuffixRowAdapter(fromIndex: 1) } .fetchOne(db)! XCTAssertEqual(Array(row.columnNames), ["a1", "a2"]) XCTAssertEqual(Array(row.databaseValues), [1.databaseValue, 2.databaseValue]) } do { - let row = try SQLRequest("SELECT 0 AS a0, 1 AS a1, 2 AS a2", adapter: SuffixRowAdapter(fromIndex: 1)) + let row = try SQLRequest(sql: "SELECT 0 AS a0, 1 AS a1, 2 AS a2", adapter: SuffixRowAdapter(fromIndex: 1)) .adapted { _ in SuffixRowAdapter(fromIndex: 1) } .fetchOne(db)! XCTAssertEqual(Array(row.columnNames), ["a2"]) XCTAssertEqual(Array(row.databaseValues), [2.databaseValue]) } do { - let row = try SQLRequest("SELECT 0 AS a0", adapter: ColumnMapping(["a1": "a0"])) + let row = try SQLRequest(sql: "SELECT 0 AS a0", adapter: ColumnMapping(["a1": "a0"])) .adapted { _ in ColumnMapping(["a2": "a1"]) } .fetchOne(db)! XCTAssertEqual(Array(row.columnNames), ["a2"]) XCTAssertEqual(Array(row.databaseValues), [0.databaseValue]) } do { - let row = try SQLRequest("SELECT 0 AS a0", adapter: ColumnMapping(["a1": "a0"])) + let row = try SQLRequest(sql: "SELECT 0 AS a0", adapter: ColumnMapping(["a1": "a0"])) .adapted { _ in ColumnMapping(["a2": "a1"]) } .adapted { _ in ColumnMapping(["a3": "a2"]) } .fetchOne(db)! @@ -809,7 +807,7 @@ class AdapterRowTests : RowTestCase { "b": ColumnMapping(["id": "id1", "val": "val1"]) .addingScopes([ "ba": ColumnMapping(["id": "id2", "val": "val2"])])]) - let row = try Row.fetchOne(db, "SELECT 0 AS id0, 'foo0' AS val0, 1 AS id1, 'foo1' AS val1, 2 as id2, 'foo2' AS val2", adapter: adapter)! + let row = try Row.fetchOne(db, sql: "SELECT 0 AS id0, 'foo0' AS val0, 1 AS id1, 'foo1' AS val1, 2 as id2, 'foo2' AS val2", adapter: adapter)! XCTAssertEqual(row.description, "[id:0 val:\"foo0\"]") XCTAssertEqual(row.debugDescription, """ diff --git a/Tests/GRDBTests/RowCopiedFromStatementTests.swift b/Tests/GRDBTests/RowCopiedFromStatementTests.swift index 10bd99e55..f11e34d34 100644 --- a/Tests/GRDBTests/RowCopiedFromStatementTests.swift +++ b/Tests/GRDBTests/RowCopiedFromStatementTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -18,9 +16,9 @@ class RowCopiedFromStatementTests: RowTestCase { func testRowAsSequence() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") - try db.execute("INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") - let row = try Row.fetchOne(db, "SELECT * FROM ints")! + try db.execute(sql: "CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") + try db.execute(sql: "INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") + let row = try Row.fetchOne(db, sql: "SELECT * FROM ints")! var columnNames = [String]() var ints = [Int]() @@ -40,9 +38,9 @@ class RowCopiedFromStatementTests: RowTestCase { func testRowValueAtIndex() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") - try db.execute("INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") - let row = try Row.fetchOne(db, "SELECT * FROM ints")! + try db.execute(sql: "CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") + try db.execute(sql: "INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") + let row = try Row.fetchOne(db, sql: "SELECT * FROM ints")! // Raw extraction assertRowRawValueEqual(row, index: 0, value: 0 as Int64) @@ -69,9 +67,9 @@ class RowCopiedFromStatementTests: RowTestCase { func testRowValueNamed() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") - try db.execute("INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") - let row = try Row.fetchOne(db, "SELECT * FROM ints")! + try db.execute(sql: "CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") + try db.execute(sql: "INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") + let row = try Row.fetchOne(db, sql: "SELECT * FROM ints")! // Raw extraction assertRowRawValueEqual(row, name: "a", value: 0 as Int64) @@ -93,9 +91,9 @@ class RowCopiedFromStatementTests: RowTestCase { func testRowValueFromColumn() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") - try db.execute("INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") - let row = try Row.fetchOne(db, "SELECT * FROM ints")! + try db.execute(sql: "CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") + try db.execute(sql: "INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") + let row = try Row.fetchOne(db, sql: "SELECT * FROM ints")! // Raw extraction assertRowRawValueEqual(row, column: Column("a"), value: 0 as Int64) @@ -119,7 +117,7 @@ class RowCopiedFromStatementTests: RowTestCase { try dbQueue.inDatabase { db in let data = "foo".data(using: .utf8)! let emptyData = Data() - let row = try Row.fetchOne(db, "SELECT ? AS a, ? AS b, ? AS c", arguments: [data, emptyData, nil])! + let row = try Row.fetchOne(db, sql: "SELECT ? AS a, ? AS b, ? AS c", arguments: [data, emptyData, nil])! XCTAssertEqual(row.dataNoCopy(atIndex: 0), data) XCTAssertEqual(row.dataNoCopy(named: "a"), data) @@ -138,7 +136,7 @@ class RowCopiedFromStatementTests: RowTestCase { func testRowDatabaseValueAtIndex() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let row = try Row.fetchOne(db, "SELECT NULL, 1, 1.1, 'foo', x'53514C697465'")! + let row = try Row.fetchOne(db, sql: "SELECT NULL, 1, 1.1, 'foo', x'53514C697465'")! guard case .null = (row[0] as DatabaseValue).storage else { XCTFail(); return } guard case .int64(let int64) = (row[1] as DatabaseValue).storage, int64 == 1 else { XCTFail(); return } @@ -151,7 +149,7 @@ class RowCopiedFromStatementTests: RowTestCase { func testRowDatabaseValueNamed() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let row = try Row.fetchOne(db, "SELECT NULL AS \"null\", 1 AS \"int64\", 1.1 AS \"double\", 'foo' AS \"string\", x'53514C697465' AS \"blob\"")! + let row = try Row.fetchOne(db, sql: "SELECT NULL AS \"null\", 1 AS \"int64\", 1.1 AS \"double\", 'foo' AS \"string\", x'53514C697465' AS \"blob\"")! guard case .null = (row["null"] as DatabaseValue).storage else { XCTFail(); return } guard case .int64(let int64) = (row["int64"] as DatabaseValue).storage, int64 == 1 else { XCTFail(); return } @@ -164,9 +162,9 @@ class RowCopiedFromStatementTests: RowTestCase { func testRowCount() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") - try db.execute("INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") - let row = try Row.fetchOne(db, "SELECT * FROM ints")! + try db.execute(sql: "CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") + try db.execute(sql: "INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") + let row = try Row.fetchOne(db, sql: "SELECT * FROM ints")! XCTAssertEqual(row.count, 3) } @@ -175,9 +173,9 @@ class RowCopiedFromStatementTests: RowTestCase { func testRowColumnNames() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") - try db.execute("INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") - let row = try Row.fetchOne(db, "SELECT a, b, c FROM ints")! + try db.execute(sql: "CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") + try db.execute(sql: "INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") + let row = try Row.fetchOne(db, sql: "SELECT a, b, c FROM ints")! XCTAssertEqual(Array(row.columnNames), ["a", "b", "c"]) } @@ -186,9 +184,9 @@ class RowCopiedFromStatementTests: RowTestCase { func testRowDatabaseValues() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") - try db.execute("INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") - let row = try Row.fetchOne(db, "SELECT a, b, c FROM ints")! + try db.execute(sql: "CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") + try db.execute(sql: "INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") + let row = try Row.fetchOne(db, sql: "SELECT a, b, c FROM ints")! XCTAssertEqual(Array(row.databaseValues), [0.databaseValue, 1.databaseValue, 2.databaseValue]) } @@ -197,7 +195,7 @@ class RowCopiedFromStatementTests: RowTestCase { func testRowIsCaseInsensitive() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let row = try Row.fetchOne(db, "SELECT 'foo' AS nAmE")! + let row = try Row.fetchOne(db, sql: "SELECT 'foo' AS nAmE")! XCTAssertEqual(row["name"] as DatabaseValue, "foo".databaseValue) XCTAssertEqual(row["NAME"] as DatabaseValue, "foo".databaseValue) XCTAssertEqual(row["NaMe"] as DatabaseValue, "foo".databaseValue) @@ -210,7 +208,7 @@ class RowCopiedFromStatementTests: RowTestCase { func testRowIsCaseInsensitiveAndReturnsLeftmostMatchingColumn() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let row = try Row.fetchOne(db, "SELECT 1 AS name, 2 AS NAME")! + let row = try Row.fetchOne(db, sql: "SELECT 1 AS name, 2 AS NAME")! XCTAssertEqual(row["name"] as DatabaseValue, 1.databaseValue) XCTAssertEqual(row["NAME"] as DatabaseValue, 1.databaseValue) XCTAssertEqual(row["NaMe"] as DatabaseValue, 1.databaseValue) @@ -223,7 +221,7 @@ class RowCopiedFromStatementTests: RowTestCase { func testMissingColumn() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let row = try Row.fetchOne(db, "SELECT 'foo' AS name")! + let row = try Row.fetchOne(db, sql: "SELECT 'foo' AS name")! XCTAssertFalse(row.hasColumn("missing")) XCTAssertTrue(row["missing"] as DatabaseValue? == nil) @@ -234,7 +232,7 @@ class RowCopiedFromStatementTests: RowTestCase { func testRowHasColumnIsCaseInsensitive() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let row = try Row.fetchOne(db, "SELECT 'foo' AS nAmE, 1 AS foo")! + let row = try Row.fetchOne(db, sql: "SELECT 'foo' AS nAmE, 1 AS foo")! XCTAssertTrue(row.hasColumn("name")) XCTAssertTrue(row.hasColumn("NAME")) XCTAssertTrue(row.hasColumn("Name")) @@ -248,7 +246,7 @@ class RowCopiedFromStatementTests: RowTestCase { func testScopes() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let row = try Row.fetchOne(db, "SELECT 'foo' AS nAmE, 1 AS foo")! + let row = try Row.fetchOne(db, sql: "SELECT 'foo' AS nAmE, 1 AS foo")! XCTAssertTrue(row.scopes.isEmpty) XCTAssertTrue(row.scopes["missing"] == nil) XCTAssertTrue(row.scopesTree["missing"] == nil) @@ -258,9 +256,9 @@ class RowCopiedFromStatementTests: RowTestCase { func testCopy() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") - try db.execute("INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") - let row = try Row.fetchOne(db, "SELECT * FROM ints")! + try db.execute(sql: "CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") + try db.execute(sql: "INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") + let row = try Row.fetchOne(db, sql: "SELECT * FROM ints")! let copiedRow = row.copy() XCTAssertEqual(copiedRow.count, 3) @@ -273,9 +271,9 @@ class RowCopiedFromStatementTests: RowTestCase { func testEqualityWithCopy() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") - try db.execute("INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") - let row = try Row.fetchOne(db, "SELECT * FROM ints")! + try db.execute(sql: "CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") + try db.execute(sql: "INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") + let row = try Row.fetchOne(db, sql: "SELECT * FROM ints")! let copiedRow = row.copy() XCTAssertEqual(row, copiedRow) @@ -285,7 +283,7 @@ class RowCopiedFromStatementTests: RowTestCase { func testDescription() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let row = try Row.fetchOne(db, "SELECT NULL AS \"null\", 1 AS \"int\", 1.1 AS \"double\", 'foo' AS \"string\", x'53514C697465' AS \"data\"")! + let row = try Row.fetchOne(db, sql: "SELECT NULL AS \"null\", 1 AS \"int\", 1.1 AS \"double\", 'foo' AS \"string\", x'53514C697465' AS \"data\"")! XCTAssertEqual(row.description, "[null:NULL int:1 double:1.1 string:\"foo\" data:Data(6 bytes)]") XCTAssertEqual(row.debugDescription, "[null:NULL int:1 double:1.1 string:\"foo\" data:Data(6 bytes)]") } diff --git a/Tests/GRDBTests/RowFetchTests.swift b/Tests/GRDBTests/RowFetchTests.swift index 3b2857c7e..fac21dbfe 100644 --- a/Tests/GRDBTests/RowFetchTests.swift +++ b/Tests/GRDBTests/RowFetchTests.swift @@ -1,12 +1,12 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else - #if SWIFT_PACKAGE + #if GRDBCIPHER + import SQLCipher + #elseif SWIFT_PACKAGE import CSQLite - #else + #else import SQLite3 #endif import GRDB @@ -32,24 +32,36 @@ class RowFetchTests: GRDBTestCase { } do { let sql = "SELECT 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 'Barbara', 'Gourde'" - let statement = try db.makeSelectStatement(sql) - try test(Row.fetchCursor(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Row.fetchCursor(db, sql: sql)) try test(Row.fetchCursor(statement)) - try test(Row.fetchCursor(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchCursor(db)) + try test(Row.fetchCursor(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchCursor(db)) } do { let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 0, 'Barbara', 'Gourde'" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Row.fetchCursor(db, sql, adapter: adapter)) + try test(Row.fetchCursor(db, sql: sql, adapter: adapter)) try test(Row.fetchCursor(statement, adapter: adapter)) - try test(Row.fetchCursor(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchCursor(db)) + try test(Row.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db)) } } } + #if swift(>=5.0) + func testFetchCursorWithInterpolation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request: SQLRequest = "SELECT \("O'Brien")" + let cursor = try request.fetchCursor(db) + let row = try cursor.next()! + XCTAssertEqual(row[0], "O'Brien") + } + } + #endif + func testFetchCursorStepFailure() throws { let dbQueue = try makeDatabaseQueue() let customError = NSError(domain: "Custom", code: 0xDEAD) @@ -68,27 +80,25 @@ class RowFetchTests: GRDBTestCase { do { _ = try cursor.next() XCTFail() - } catch let error as DatabaseError { - XCTAssertEqual(error.resultCode, .SQLITE_MISUSE) - XCTAssertEqual(error.message, "\(customError)") - XCTAssertEqual(error.sql!, sql) - XCTAssertEqual(error.description, "SQLite error 21 with statement `\(sql)`: \(customError)") + } catch is DatabaseError { + // Various SQLite and SQLCipher versions don't emit the same + // error. What we care about is that there is an error. } } do { let sql = "SELECT throw(), NULL" - try test(Row.fetchCursor(db, sql), sql: sql) - try test(Row.fetchCursor(db.makeSelectStatement(sql)), sql: sql) - try test(Row.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchCursor(db), sql: sql) + try test(Row.fetchCursor(db, sql: sql), sql: sql) + try test(Row.fetchCursor(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Row.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchCursor(db), sql: sql) } do { let sql = "SELECT 0, throw(), NULL" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Row.fetchCursor(db, sql, adapter: adapter), sql: sql) - try test(Row.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Row.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchCursor(db), sql: sql) + try test(Row.fetchCursor(db, sql: sql, adapter: adapter), sql: sql) + try test(Row.fetchCursor(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Row.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db), sql: sql) } } } @@ -109,18 +119,18 @@ class RowFetchTests: GRDBTestCase { } do { let sql = "SELECT * FROM nonExistingTable" - try test(Row.fetchCursor(db, sql), sql: sql) - try test(Row.fetchCursor(db.makeSelectStatement(sql)), sql: sql) - try test(Row.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchCursor(db), sql: sql) + try test(Row.fetchCursor(db, sql: sql), sql: sql) + try test(Row.fetchCursor(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Row.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchCursor(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Row.fetchCursor(db, sql, adapter: adapter), sql: sql) - try test(Row.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Row.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchCursor(db), sql: sql) + try test(Row.fetchCursor(db, sql: sql, adapter: adapter), sql: sql) + try test(Row.fetchCursor(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Row.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db), sql: sql) } } } @@ -134,23 +144,34 @@ class RowFetchTests: GRDBTestCase { } do { let sql = "SELECT 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 'Barbara', 'Gourde'" - let statement = try db.makeSelectStatement(sql) - try test(Row.fetchAll(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Row.fetchAll(db, sql: sql)) try test(Row.fetchAll(statement)) - try test(Row.fetchAll(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchAll(db)) + try test(Row.fetchAll(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchAll(db)) } do { let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 0, 'Barbara', 'Gourde'" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Row.fetchAll(db, sql, adapter: adapter)) + try test(Row.fetchAll(db, sql: sql, adapter: adapter)) try test(Row.fetchAll(statement, adapter: adapter)) - try test(Row.fetchAll(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchAll(db)) + try test(Row.fetchAll(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db)) } } } + + #if swift(>=5.0) + func testFetchAllWithInterpolation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request: SQLRequest = "SELECT \("O'Brien")" + let rows = try request.fetchAll(db) + XCTAssertEqual(rows[0][0], "O'Brien") + } + } + #endif func testFetchAllStepFailure() throws { let dbQueue = try makeDatabaseQueue() @@ -170,18 +191,18 @@ class RowFetchTests: GRDBTestCase { } do { let sql = "SELECT throw()" - try test(Row.fetchAll(db, sql), sql: sql) - try test(Row.fetchAll(db.makeSelectStatement(sql)), sql: sql) - try test(Row.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchAll(db), sql: sql) + try test(Row.fetchAll(db, sql: sql), sql: sql) + try test(Row.fetchAll(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Row.fetchAll(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchAll(db), sql: sql) } do { let sql = "SELECT 0, throw()" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Row.fetchAll(db, sql, adapter: adapter), sql: sql) - try test(Row.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Row.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchAll(db), sql: sql) + try test(Row.fetchAll(db, sql: sql, adapter: adapter), sql: sql) + try test(Row.fetchAll(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Row.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db), sql: sql) } } } @@ -202,18 +223,18 @@ class RowFetchTests: GRDBTestCase { } do { let sql = "SELECT * FROM nonExistingTable" - try test(Row.fetchAll(db, sql), sql: sql) - try test(Row.fetchAll(db.makeSelectStatement(sql)), sql: sql) - try test(Row.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchAll(db), sql: sql) + try test(Row.fetchAll(db, sql: sql), sql: sql) + try test(Row.fetchAll(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Row.fetchAll(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchAll(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Row.fetchAll(db, sql, adapter: adapter), sql: sql) - try test(Row.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Row.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchAll(db), sql: sql) + try test(Row.fetchAll(db, sql: sql, adapter: adapter), sql: sql) + try test(Row.fetchAll(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Row.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db), sql: sql) } } } @@ -227,20 +248,20 @@ class RowFetchTests: GRDBTestCase { } do { let sql = "SELECT 1 WHERE 0" - let statement = try db.makeSelectStatement(sql) - try test(Row.fetchOne(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Row.fetchOne(db, sql: sql)) try test(Row.fetchOne(statement)) - try test(Row.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchOne(db)) + try test(Row.fetchOne(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchOne(db)) } do { let sql = "SELECT 0, 1 WHERE 0" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Row.fetchOne(db, sql, adapter: adapter)) + try test(Row.fetchOne(db, sql: sql, adapter: adapter)) try test(Row.fetchOne(statement, adapter: adapter)) - try test(Row.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchOne(db)) + try test(Row.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db)) } } do { @@ -250,24 +271,35 @@ class RowFetchTests: GRDBTestCase { } do { let sql = "SELECT 'Arthur' AS firstName, 'Martin' AS lastName" - let statement = try db.makeSelectStatement(sql) - try test(Row.fetchOne(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Row.fetchOne(db, sql: sql)) try test(Row.fetchOne(statement)) - try test(Row.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchOne(db)) + try test(Row.fetchOne(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchOne(db)) } do { let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Row.fetchOne(db, sql, adapter: adapter)) + try test(Row.fetchOne(db, sql: sql, adapter: adapter)) try test(Row.fetchOne(statement, adapter: adapter)) - try test(Row.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchOne(db)) + try test(Row.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db)) } } } } + + #if swift(>=5.0) + func testFetchOneWithInterpolation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request: SQLRequest = "SELECT \("O'Brien")" + let row = try request.fetchOne(db) + XCTAssertEqual(row![0], "O'Brien") + } + } + #endif func testFetchOneStepFailure() throws { let dbQueue = try makeDatabaseQueue() @@ -287,18 +319,18 @@ class RowFetchTests: GRDBTestCase { } do { let sql = "SELECT throw()" - try test(Row.fetchOne(db, sql), sql: sql) - try test(Row.fetchOne(db.makeSelectStatement(sql)), sql: sql) - try test(Row.fetchOne(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchOne(db), sql: sql) + try test(Row.fetchOne(db, sql: sql), sql: sql) + try test(Row.fetchOne(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Row.fetchOne(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchOne(db), sql: sql) } do { let sql = "SELECT 0, throw()" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Row.fetchOne(db, sql, adapter: adapter), sql: sql) - try test(Row.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Row.fetchOne(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchOne(db), sql: sql) + try test(Row.fetchOne(db, sql: sql, adapter: adapter), sql: sql) + try test(Row.fetchOne(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Row.fetchOne(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db), sql: sql) } } } @@ -319,18 +351,18 @@ class RowFetchTests: GRDBTestCase { } do { let sql = "SELECT * FROM nonExistingTable" - try test(Row.fetchOne(db, sql), sql: sql) - try test(Row.fetchOne(db.makeSelectStatement(sql)), sql: sql) - try test(Row.fetchOne(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchOne(db), sql: sql) + try test(Row.fetchOne(db, sql: sql), sql: sql) + try test(Row.fetchOne(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Row.fetchOne(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchOne(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Row.fetchOne(db, sql, adapter: adapter), sql: sql) - try test(Row.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Row.fetchOne(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchOne(db), sql: sql) + try test(Row.fetchOne(db, sql: sql, adapter: adapter), sql: sql) + try test(Row.fetchOne(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Row.fetchOne(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db), sql: sql) } } } diff --git a/Tests/GRDBTests/RowFromDictionaryLiteralTests.swift b/Tests/GRDBTests/RowFromDictionaryLiteralTests.swift index 33d959670..32ddc3347 100644 --- a/Tests/GRDBTests/RowFromDictionaryLiteralTests.swift +++ b/Tests/GRDBTests/RowFromDictionaryLiteralTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -48,9 +46,9 @@ class RowFromDictionaryLiteralTests : RowTestCase { func testRowValueAtIndex() { let row: Row = ["a": 0, "b": 1, "c": 2] - let aIndex = row.distance(from: row.startIndex, to: row.index(where: { (column, value) in column == "a" })!) - let bIndex = row.distance(from: row.startIndex, to: row.index(where: { (column, value) in column == "b" })!) - let cIndex = row.distance(from: row.startIndex, to: row.index(where: { (column, value) in column == "c" })!) + let aIndex = row.distance(from: row.startIndex, to: row.firstIndex(where: { (column, value) in column == "a" })!) + let bIndex = row.distance(from: row.startIndex, to: row.firstIndex(where: { (column, value) in column == "b" })!) + let cIndex = row.distance(from: row.startIndex, to: row.firstIndex(where: { (column, value) in column == "c" })!) // Raw extraction assertRowRawValueEqual(row, index: aIndex, value: 0 as Int64) @@ -140,11 +138,11 @@ class RowFromDictionaryLiteralTests : RowTestCase { func testRowDatabaseValueAtIndex() throws { let row: Row = ["null": nil, "int64": 1, "double": 1.1, "string": "foo", "blob": "SQLite".data(using: .utf8)] - let nullIndex = row.distance(from: row.startIndex, to: row.index(where: { (column, value) in column == "null" })!) - let int64Index = row.distance(from: row.startIndex, to: row.index(where: { (column, value) in column == "int64" })!) - let doubleIndex = row.distance(from: row.startIndex, to: row.index(where: { (column, value) in column == "double" })!) - let stringIndex = row.distance(from: row.startIndex, to: row.index(where: { (column, value) in column == "string" })!) - let blobIndex = row.distance(from: row.startIndex, to: row.index(where: { (column, value) in column == "blob" })!) + let nullIndex = row.distance(from: row.startIndex, to: row.firstIndex(where: { (column, value) in column == "null" })!) + let int64Index = row.distance(from: row.startIndex, to: row.firstIndex(where: { (column, value) in column == "int64" })!) + let doubleIndex = row.distance(from: row.startIndex, to: row.firstIndex(where: { (column, value) in column == "double" })!) + let stringIndex = row.distance(from: row.startIndex, to: row.firstIndex(where: { (column, value) in column == "string" })!) + let blobIndex = row.distance(from: row.startIndex, to: row.firstIndex(where: { (column, value) in column == "blob" })!) guard case .null = (row[nullIndex] as DatabaseValue).storage else { XCTFail(); return } guard case .int64(let int64) = (row[int64Index] as DatabaseValue).storage, int64 == 1 else { XCTFail(); return } diff --git a/Tests/GRDBTests/RowFromDictionaryTests.swift b/Tests/GRDBTests/RowFromDictionaryTests.swift index 2fe4e414b..71d5f90ca 100644 --- a/Tests/GRDBTests/RowFromDictionaryTests.swift +++ b/Tests/GRDBTests/RowFromDictionaryTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/RowFromStatementTests.swift b/Tests/GRDBTests/RowFromStatementTests.swift index 79a281c94..dcdcdd11d 100644 --- a/Tests/GRDBTests/RowFromStatementTests.swift +++ b/Tests/GRDBTests/RowFromStatementTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -18,10 +16,10 @@ class RowFromStatementTests : RowTestCase { func testRowAsSequence() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") - try db.execute("INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") + try db.execute(sql: "CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") + try db.execute(sql: "INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") var rowFetched = false - let rows = try Row.fetchCursor(db, "SELECT * FROM ints") + let rows = try Row.fetchCursor(db, sql: "SELECT * FROM ints") while let row = try rows.next() { rowFetched = true var columnNames = [String]() @@ -44,10 +42,10 @@ class RowFromStatementTests : RowTestCase { func testRowValueAtIndex() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") - try db.execute("INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") + try db.execute(sql: "CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") + try db.execute(sql: "INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") var rowFetched = false - let rows = try Row.fetchCursor(db, "SELECT * FROM ints") + let rows = try Row.fetchCursor(db, sql: "SELECT * FROM ints") while let row = try rows.next() { rowFetched = true @@ -78,10 +76,10 @@ class RowFromStatementTests : RowTestCase { func testRowValueNamed() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") - try db.execute("INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") + try db.execute(sql: "CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") + try db.execute(sql: "INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") var rowFetched = false - let rows = try Row.fetchCursor(db, "SELECT * FROM ints") + let rows = try Row.fetchCursor(db, sql: "SELECT * FROM ints") while let row = try rows.next() { rowFetched = true @@ -107,10 +105,10 @@ class RowFromStatementTests : RowTestCase { func testRowValueFromColumn() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") - try db.execute("INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") + try db.execute(sql: "CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") + try db.execute(sql: "INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") var rowFetched = false - let rows = try Row.fetchCursor(db, "SELECT * FROM ints") + let rows = try Row.fetchCursor(db, sql: "SELECT * FROM ints") while let row = try rows.next() { rowFetched = true @@ -139,7 +137,7 @@ class RowFromStatementTests : RowTestCase { let data = "foo".data(using: .utf8)! let emptyData = Data() var rowFetched = false - let rows = try Row.fetchCursor(db, "SELECT ? AS a, ? AS b, ? AS c", arguments: [data, emptyData, nil]) + let rows = try Row.fetchCursor(db, sql: "SELECT ? AS a, ? AS b, ? AS c", arguments: [data, emptyData, nil]) while let row = try rows.next() { rowFetched = true @@ -163,7 +161,7 @@ class RowFromStatementTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in var rowFetched = false - let rows = try Row.fetchCursor(db, "SELECT NULL, 1, 1.1, 'foo', x'53514C697465'") + let rows = try Row.fetchCursor(db, sql: "SELECT NULL, 1, 1.1, 'foo', x'53514C697465'") while let row = try rows.next() { rowFetched = true guard case .null = (row[0] as DatabaseValue).storage else { XCTFail(); return } @@ -180,7 +178,7 @@ class RowFromStatementTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in var rowFetched = false - let rows = try Row.fetchCursor(db, "SELECT NULL AS \"null\", 1 AS \"int64\", 1.1 AS \"double\", 'foo' AS \"string\", x'53514C697465' AS \"blob\"") + let rows = try Row.fetchCursor(db, sql: "SELECT NULL AS \"null\", 1 AS \"int64\", 1.1 AS \"double\", 'foo' AS \"string\", x'53514C697465' AS \"blob\"") while let row = try rows.next() { rowFetched = true guard case .null = (row["null"] as DatabaseValue).storage else { XCTFail(); return } @@ -196,10 +194,10 @@ class RowFromStatementTests : RowTestCase { func testRowCount() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") - try db.execute("INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") + try db.execute(sql: "CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") + try db.execute(sql: "INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") var rowFetched = false - let rows = try Row.fetchCursor(db, "SELECT * FROM ints") + let rows = try Row.fetchCursor(db, sql: "SELECT * FROM ints") while let row = try rows.next() { rowFetched = true XCTAssertEqual(row.count, 3) @@ -211,10 +209,10 @@ class RowFromStatementTests : RowTestCase { func testRowColumnNames() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") - try db.execute("INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") + try db.execute(sql: "CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") + try db.execute(sql: "INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") var rowFetched = false - let rows = try Row.fetchCursor(db, "SELECT a, b, c FROM ints") + let rows = try Row.fetchCursor(db, sql: "SELECT a, b, c FROM ints") while let row = try rows.next() { rowFetched = true XCTAssertEqual(Array(row.columnNames), ["a", "b", "c"]) @@ -226,10 +224,10 @@ class RowFromStatementTests : RowTestCase { func testRowDatabaseValues() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") - try db.execute("INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") + try db.execute(sql: "CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") + try db.execute(sql: "INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") var rowFetched = false - let rows = try Row.fetchCursor(db, "SELECT a, b, c FROM ints") + let rows = try Row.fetchCursor(db, sql: "SELECT a, b, c FROM ints") while let row = try rows.next() { rowFetched = true XCTAssertEqual(Array(row.databaseValues), [0.databaseValue, 1.databaseValue, 2.databaseValue]) @@ -242,7 +240,7 @@ class RowFromStatementTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in var rowFetched = false - let rows = try Row.fetchCursor(db, "SELECT 'foo' AS nAmE") + let rows = try Row.fetchCursor(db, sql: "SELECT 'foo' AS nAmE") while let row = try rows.next() { rowFetched = true XCTAssertEqual(row["name"] as DatabaseValue, "foo".databaseValue) @@ -260,7 +258,7 @@ class RowFromStatementTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in var rowFetched = false - let rows = try Row.fetchCursor(db, "SELECT 1 AS name, 2 AS NAME") + let rows = try Row.fetchCursor(db, sql: "SELECT 1 AS name, 2 AS NAME") while let row = try rows.next() { rowFetched = true XCTAssertEqual(row["name"] as DatabaseValue, 1.databaseValue) @@ -278,7 +276,7 @@ class RowFromStatementTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in var rowFetched = false - let rows = try Row.fetchCursor(db, "SELECT 'foo' AS name") + let rows = try Row.fetchCursor(db, sql: "SELECT 'foo' AS name") while let row = try rows.next() { rowFetched = true XCTAssertFalse(row.hasColumn("missing")) @@ -293,7 +291,7 @@ class RowFromStatementTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in var rowFetched = false - let rows = try Row.fetchCursor(db, "SELECT 'foo' AS nAmE, 1 AS foo") + let rows = try Row.fetchCursor(db, sql: "SELECT 'foo' AS nAmE, 1 AS foo") while let row = try rows.next() { rowFetched = true XCTAssertTrue(row.hasColumn("name")) @@ -312,7 +310,7 @@ class RowFromStatementTests : RowTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in var rowFetched = false - let rows = try Row.fetchCursor(db, "SELECT 'foo' AS nAmE, 1 AS foo") + let rows = try Row.fetchCursor(db, sql: "SELECT 'foo' AS nAmE, 1 AS foo") while let row = try rows.next() { rowFetched = true XCTAssertTrue(row.scopes.isEmpty) @@ -326,10 +324,10 @@ class RowFromStatementTests : RowTestCase { func testCopy() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") - try db.execute("INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") + try db.execute(sql: "CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") + try db.execute(sql: "INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") var rowFetched = false - let rows = try Row.fetchCursor(db, "SELECT * FROM ints") + let rows = try Row.fetchCursor(db, sql: "SELECT * FROM ints") while let row = try rows.next() { rowFetched = true let copiedRow = row.copy() @@ -345,10 +343,10 @@ class RowFromStatementTests : RowTestCase { func testEqualityWithCopy() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") - try db.execute("INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") + try db.execute(sql: "CREATE TABLE ints (a INTEGER, b INTEGER, c INTEGER)") + try db.execute(sql: "INSERT INTO ints (a,b,c) VALUES (0, 1, 2)") var rowFetched = false - let rows = try Row.fetchCursor(db, "SELECT * FROM ints") + let rows = try Row.fetchCursor(db, sql: "SELECT * FROM ints") while let row = try rows.next() { rowFetched = true let copiedRow = row.copy() @@ -361,7 +359,7 @@ class RowFromStatementTests : RowTestCase { func testDatabaseCursorMap() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let cursor = try Row.fetchCursor(db, "SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3") + let cursor = try Row.fetchCursor(db, sql: "SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3") let values = cursor.map { $0[0] as Int } XCTAssertEqual(try values.next()!, 1) XCTAssertEqual(try values.next()!, 2) @@ -373,7 +371,7 @@ class RowFromStatementTests : RowTestCase { func testDescription() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let rows = try Row.fetchCursor(db, "SELECT NULL AS \"null\", 1 AS \"int\", 1.1 AS \"double\", 'foo' AS \"string\", x'53514C697465' AS \"data\"") + let rows = try Row.fetchCursor(db, sql: "SELECT NULL AS \"null\", 1 AS \"int\", 1.1 AS \"double\", 'foo' AS \"string\", x'53514C697465' AS \"data\"") var rowFetched = false while let row = try rows.next() { rowFetched = true diff --git a/Tests/GRDBTests/RowTestCase.swift b/Tests/GRDBTests/RowTestCase.swift index baa5fd916..0fdcdf758 100644 --- a/Tests/GRDBTests/RowTestCase.swift +++ b/Tests/GRDBTests/RowTestCase.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/GRDBTests/SQLExpressionLiteralTests.swift b/Tests/GRDBTests/SQLExpressionLiteralTests.swift index fff8c41fa..bc827cb29 100644 --- a/Tests/GRDBTests/SQLExpressionLiteralTests.swift +++ b/Tests/GRDBTests/SQLExpressionLiteralTests.swift @@ -1,8 +1,6 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else @testable import GRDB diff --git a/Tests/GRDBTests/SQLInterpolationTests.swift b/Tests/GRDBTests/SQLInterpolationTests.swift new file mode 100644 index 000000000..3f83b825b --- /dev/null +++ b/Tests/GRDBTests/SQLInterpolationTests.swift @@ -0,0 +1,173 @@ +#if swift(>=5.0) +import XCTest +#if GRDBCUSTOMSQLITE + @testable import GRDBCustomSQLite +#else + @testable import GRDB +#endif + +class SQLInterpolationTests: GRDBTestCase { + func testSQLInterpolation() { + var sql = SQLInterpolation(literalCapacity: 0, interpolationCount: 2) + + sql.appendInterpolation(sql: "\(1)"); sql.appendLiteral("\n") + sql.appendInterpolation(sql: ":name", arguments: ["name": "Arthur"]) + + XCTAssertEqual(sql.sql, """ + 1 + :name + """) + XCTAssertEqual(sql.arguments, ["name": "Arthur"]) + } + + func testSelectableInterpolation() { + var sql = SQLInterpolation(literalCapacity: 0, interpolationCount: 2) + + // Non-existential + sql.appendInterpolation(AllColumns()); sql.appendLiteral("\n") + // Existential + sql.appendInterpolation(AllColumns() as SQLSelectable) + + XCTAssertEqual(sql.sql, """ + * + * + """) + XCTAssert(sql.arguments.isEmpty) + } + + func testTableInterpolation() { + var sql = SQLInterpolation(literalCapacity: 0, interpolationCount: 1) + + struct Player: TableRecord { } + sql.appendInterpolation(Player.self); sql.appendLiteral("\n") + sql.appendInterpolation(tableOf: Player()) + + XCTAssertEqual(sql.sql, """ + "player" + "player" + """) + XCTAssert(sql.arguments.isEmpty) + } + + func testExpressibleInterpolation() { + var sql = SQLInterpolation(literalCapacity: 0, interpolationCount: 7) + + let a = Column("a") + let b = Column("b") + let integer: Int = 1 + let optionalInteger: Int? = 2 + let nilInteger: Int? = nil + sql.appendInterpolation(a); sql.appendLiteral("\n") + sql.appendInterpolation(a + 1); sql.appendLiteral("\n") + sql.appendInterpolation(a < b); sql.appendLiteral("\n") + sql.appendInterpolation(integer); sql.appendLiteral("\n") + sql.appendInterpolation(optionalInteger); sql.appendLiteral("\n") + sql.appendInterpolation(nilInteger); sql.appendLiteral("\n") + sql.appendInterpolation(a == nilInteger) + + XCTAssertEqual(sql.sql, """ + "a" + ("a" + ?) + ("a" < "b") + ? + ? + NULL + ("a" IS NULL) + """) + XCTAssertEqual(sql.arguments, [1, 1, 2]) + } + + func testQualifiedExpressionInterpolation() { + var sql = SQLInterpolation(literalCapacity: 0, interpolationCount: 1) + + sql.appendInterpolation(Column("name").aliased("foo")); sql.appendLiteral("\n") + sql.appendInterpolation(1.databaseValue.aliased("bar")) + + XCTAssertEqual(sql.sql, """ + "name" AS "foo" + ? AS "bar" + """) + XCTAssertEqual(sql.arguments, [1]) + } + + func testCodingKeyInterpolation() { + var sql = SQLInterpolation(literalCapacity: 0, interpolationCount: 1) + + enum CodingKeys: String, CodingKey { + case name + } + sql.appendInterpolation(CodingKeys.name) + + XCTAssertEqual(sql.sql, """ + "name" + """) + XCTAssert(sql.arguments.isEmpty) + } + + func testCodingKeyColumnInterpolation() { + var sql = SQLInterpolation(literalCapacity: 0, interpolationCount: 1) + + enum CodingKeys: String, CodingKey, ColumnExpression { + case name + } + sql.appendInterpolation(CodingKeys.name) + + XCTAssertEqual(sql.sql, """ + "name" + """) + XCTAssert(sql.arguments.isEmpty) + } + + func testExpressibleSequenceInterpolation() throws { + var sql = SQLInterpolation(literalCapacity: 0, interpolationCount: 3) + + let set: Set = [1] + let array = ["foo", "bar", "baz"] + let expressions = [Column("a"), Column("b") + 2] + sql.appendInterpolation(set); sql.appendLiteral("\n") + sql.appendInterpolation(array); sql.appendLiteral("\n") + sql.appendInterpolation(expressions); sql.appendLiteral("\n") + sql.appendInterpolation([]) + + XCTAssertEqual(sql.sql, """ + (?) + (?,?,?) + ("a",("b" + ?)) + (SELECT NULL WHERE NULL) + """) + XCTAssertEqual(sql.arguments, [1, "foo", "bar", "baz", 2]) + } + + func testOrderingTermInterpolation() { + var sql = SQLInterpolation(literalCapacity: 0, interpolationCount: 1) + + sql.appendInterpolation(Column("name").desc) + + XCTAssertEqual(sql.sql, """ + "name" DESC + """) + XCTAssert(sql.arguments.isEmpty) + } + + func testSQLLiteralInterpolation() { + var sql = SQLInterpolation(literalCapacity: 0, interpolationCount: 3) + + sql.appendInterpolation(1) + sql.appendInterpolation(literal: " + \(2) + ") + sql.appendInterpolation(3) + + XCTAssertEqual(sql.sql, "? + ? + ?") + XCTAssertEqual(sql.arguments, [1, 2, 3]) + } + + func testSQLRequestInterpolation() { + var sql = SQLInterpolation(literalCapacity: 0, interpolationCount: 3) + + sql.appendInterpolation(SQLRequest(sql: "SELECT * FROM player WHERE id = ?", arguments: [42])) + sql.appendInterpolation(SQLRequest(sql: "SELECT * FROM teams WHERE name = ?", arguments: ["Red"])) + + XCTAssertEqual(sql.sql, "(SELECT * FROM player WHERE id = ?)(SELECT * FROM teams WHERE name = ?)") + XCTAssertEqual(sql.arguments, [42, "Red"]) + } +} +#endif diff --git a/Tests/GRDBTests/SQLLiteralTests.swift b/Tests/GRDBTests/SQLLiteralTests.swift new file mode 100644 index 000000000..a2bc10af4 --- /dev/null +++ b/Tests/GRDBTests/SQLLiteralTests.swift @@ -0,0 +1,353 @@ +import XCTest +#if GRDBCUSTOMSQLITE + @testable import GRDBCustomSQLite +#else + @testable import GRDB +#endif + +class SQLLiteralTests: GRDBTestCase { + func testSQLInitializer() { + let query = SQLLiteral(sql: """ + SELECT * FROM player + WHERE id = \("?") + """, arguments: [1]) + XCTAssertEqual(query.sql, """ + SELECT * FROM player + WHERE id = ? + """) + XCTAssertEqual(query.arguments, [1]) + } + + func testPlusOperator() { + var query = SQLLiteral(sql: "SELECT * ") + query = query + SQLLiteral(sql: "FROM player ") + query = query + SQLLiteral(sql: "WHERE id = ? ", arguments: [1]) + query = query + SQLLiteral(sql: "AND name = ?", arguments: ["Arthur"]) + XCTAssertEqual(query.sql, """ + SELECT * FROM player WHERE id = ? AND name = ? + """) + XCTAssertEqual(query.arguments, [1, "Arthur"]) + } + + func testPlusEqualOperator() { + var query = SQLLiteral(sql: "SELECT * ") + query += SQLLiteral(sql: "FROM player ") + query += SQLLiteral(sql: "WHERE id = ? ", arguments: [1]) + query += SQLLiteral(sql: "AND name = ?", arguments: ["Arthur"]) + XCTAssertEqual(query.sql, """ + SELECT * FROM player WHERE id = ? AND name = ? + """) + XCTAssertEqual(query.arguments, [1, "Arthur"]) + } + + func testAppendLiteral() { + var query = SQLLiteral(sql: "SELECT * ") + query.append(literal: SQLLiteral(sql: "FROM player ")) + query.append(literal: SQLLiteral(sql: "WHERE id = ? ", arguments: [1])) + query.append(literal: SQLLiteral(sql: "AND name = ?", arguments: ["Arthur"])) + XCTAssertEqual(query.sql, """ + SELECT * FROM player WHERE id = ? AND name = ? + """) + XCTAssertEqual(query.arguments, [1, "Arthur"]) + } + + func testAppendRawSQL() { + var query = SQLLiteral(sql: "SELECT * ") + query.append(sql: "FROM player ") + query.append(sql: "WHERE score > \(1000) ") + query.append(sql: "AND \("name") = :name", arguments: ["name": "Arthur"]) + XCTAssertEqual(query.sql, """ + SELECT * FROM player WHERE score > 1000 AND name = :name + """) + XCTAssertEqual(query.arguments, ["name": "Arthur"]) + } + + func testSequenceJoined() { + // A sequence that can't be consumed twice + var i = 0 + let sequence = AnySequence { + return AnyIterator { + guard i < 3 else { return nil } + i += 1 + return SQLLiteral(sql: "(\(i) = ?)", arguments: [i]) + } + } + do { + i = 0 + let joined = sequence.joined() + XCTAssertEqual(joined.sql, "(1 = ?)(2 = ?)(3 = ?)") + XCTAssertEqual(joined.arguments, [1, 2, 3]) + } + do { + i = 0 + let joined = sequence.joined(separator: " AND ") + XCTAssertEqual(joined.sql, "(1 = ?) AND (2 = ?) AND (3 = ?)") + XCTAssertEqual(joined.arguments, [1, 2, 3]) + } + } + + func testCollectionJoined() { + let collection = AnyCollection([ + SQLLiteral(sql: "SELECT * "), + SQLLiteral(sql: "FROM player "), + SQLLiteral(sql: "WHERE score > ? ", arguments: [1000]), + SQLLiteral(sql: "AND name = :name", arguments: ["name": "Arthur"]), + ]) + do { + let joined = collection.joined() + XCTAssertEqual(joined.sql, """ + SELECT * FROM player WHERE score > ? AND name = :name + """) + XCTAssertEqual(joined.arguments, [1000] + ["name": "Arthur"]) + } + do { + let joined = collection.joined(separator: " ") + XCTAssertEqual(joined.sql, """ + SELECT * FROM player WHERE score > ? AND name = :name + """) + XCTAssertEqual(joined.arguments, [1000] + ["name": "Arthur"]) + } + } +} + +#if swift(>=5.0) +extension SQLLiteralTests { + func testRawSQLInterpolation() { + let query: SQLLiteral = """ + SELECT * + \(sql: "FROM player") + \(sql: "WHERE score > \(1000)") + \(sql: "AND \("name") = :name", arguments: ["name": "Arthur"]) + """ + XCTAssertEqual(query.sql, """ + SELECT * + FROM player + WHERE score > 1000 + AND name = :name + """) + XCTAssertEqual(query.arguments, ["name": "Arthur"]) + } + + func testSelectableInterpolation() { + do { + // Non-existential + let query: SQLLiteral = """ + SELECT \(AllColumns()) + FROM player + """ + XCTAssertEqual(query.sql, """ + SELECT * + FROM player + """) + XCTAssert(query.arguments.isEmpty) + } + do { + // Existential + let query: SQLLiteral = """ + SELECT \(AllColumns() as SQLSelectable) + FROM player + """ + XCTAssertEqual(query.sql, """ + SELECT * + FROM player + """) + XCTAssert(query.arguments.isEmpty) + } + } + + func testTableInterpolation() { + struct Player: TableRecord { } + do { + let query: SQLLiteral = """ + SELECT * + FROM \(Player.self) + """ + XCTAssertEqual(query.sql, """ + SELECT * + FROM "player" + """) + XCTAssert(query.arguments.isEmpty) + } + do { + let query: SQLLiteral = """ + INSERT INTO \(tableOf: Player()) DEFAULT VALUES + """ + XCTAssertEqual(query.sql, """ + INSERT INTO "player" DEFAULT VALUES + """) + XCTAssert(query.arguments.isEmpty) + } + } + + func testExpressibleInterpolation() { + let a = Column("a") + let b = Column("b") + let integer: Int = 1 + let optionalInteger: Int? = 2 + let nilInteger: Int? = nil + let query: SQLLiteral = """ + SELECT + \(a), + \(a + 1), + \(a < b), + \(integer), + \(optionalInteger), + \(nilInteger), + \(a == nilInteger) + """ + XCTAssertEqual(query.sql, """ + SELECT + "a", + ("a" + ?), + ("a" < "b"), + ?, + ?, + NULL, + ("a" IS NULL) + """) + XCTAssertEqual(query.arguments, [1, 1, 2]) + } + + func testQualifiedExpressionInterpolation() { + let query: SQLLiteral = """ + SELECT \(Column("name").aliased("foo")) + FROM player + """ + XCTAssertEqual(query.sql, """ + SELECT "name" AS "foo" + FROM player + """) + XCTAssert(query.arguments.isEmpty) + } + + func testCodingKeyInterpolation() { + enum CodingKeys: String, CodingKey { + case name + } + let query: SQLLiteral = """ + SELECT \(CodingKeys.name) + FROM player + """ + XCTAssertEqual(query.sql, """ + SELECT "name" + FROM player + """) + XCTAssert(query.arguments.isEmpty) + } + + func testCodingKeyColumnInterpolation() { + enum CodingKeys: String, CodingKey, ColumnExpression { + case name + } + let query: SQLLiteral = """ + SELECT \(CodingKeys.name) + FROM player + """ + XCTAssertEqual(query.sql, """ + SELECT "name" + FROM player + """) + XCTAssert(query.arguments.isEmpty) + } + + func testExpressibleSequenceInterpolation() { + let set: Set = [1] + let array = ["foo", "bar", "baz"] + let expressions = [Column("a"), Column("b") + 2] + let query: SQLLiteral = """ + SELECT * FROM player + WHERE teamId IN \(set) + AND name IN \(array) + AND c IN \(expressions) + AND d IN \([]) + """ + XCTAssertEqual(query.sql, """ + SELECT * FROM player + WHERE teamId IN (?) + AND name IN (?,?,?) + AND c IN ("a",("b" + ?)) + AND d IN (SELECT NULL WHERE NULL) + """) + XCTAssertEqual(query.arguments, [1, "foo", "bar", "baz", 2]) + } + + func testOrderingTermInterpolation() { + let query: SQLLiteral = """ + SELECT * FROM player + ORDER BY \(Column("name").desc) + """ + XCTAssertEqual(query.sql, """ + SELECT * FROM player + ORDER BY "name" DESC + """) + XCTAssert(query.arguments.isEmpty) + } + + func testSQLLiteralInterpolation() { + let condition: SQLLiteral = "name = \("Arthur")" + let query: SQLLiteral = """ + SELECT *, \(true) FROM player + WHERE \(literal: condition) AND score > \(1000) + """ + XCTAssertEqual(query.sql, """ + SELECT *, ? FROM player + WHERE name = ? AND score > ? + """) + XCTAssertEqual(query.arguments, [true, "Arthur", 1000]) + } + + func testSQLRequestInterpolation() { + let subQuery: SQLRequest = "SELECT MAX(score) - \(10) FROM player" + let query: SQLLiteral = """ + SELECT * FROM player + WHERE score = \(subQuery) + """ + XCTAssertEqual(query.sql, """ + SELECT * FROM player + WHERE score = (SELECT MAX(score) - ? FROM player) + """) + XCTAssertEqual(query.arguments, [10]) + } + + func testPlusOperatorWithInterpolation() { + var query: SQLLiteral = "SELECT \(AllColumns()) " + query = query + "FROM player " + query = query + "WHERE id = \(1)" + XCTAssertEqual(query.sql, """ + SELECT * FROM player WHERE id = ? + """) + XCTAssertEqual(query.arguments, [1]) + } + + func testPlusEqualOperatorWithInterpolation() { + var query: SQLLiteral = "SELECT \(AllColumns()) " + query += "FROM player " + query += "WHERE id = \(1)" + XCTAssertEqual(query.sql, """ + SELECT * FROM player WHERE id = ? + """) + XCTAssertEqual(query.arguments, [1]) + } + + func testAppendLiteralWithInterpolation() { + var query: SQLLiteral = "SELECT \(AllColumns()) " + query.append(literal: "FROM player ") + query.append(literal: "WHERE id = \(1)") + XCTAssertEqual(query.sql, """ + SELECT * FROM player WHERE id = ? + """) + XCTAssertEqual(query.arguments, [1]) + } + + func testAppendRawSQLWithInterpolation() { + var query: SQLLiteral = "SELECT \(AllColumns()) " + query.append(sql: "FROM player ") + query.append(sql: "WHERE score > \(1000) ") + query.append(sql: "AND \("name") = :name", arguments: ["name": "Arthur"]) + XCTAssertEqual(query.sql, """ + SELECT * FROM player WHERE score > 1000 AND name = :name + """) + XCTAssertEqual(query.arguments, ["name": "Arthur"]) + } +} +#endif diff --git a/Tests/GRDBTests/SQLRequestTests.swift b/Tests/GRDBTests/SQLRequestTests.swift index d54e3d1ab..fb05a6d94 100644 --- a/Tests/GRDBTests/SQLRequestTests.swift +++ b/Tests/GRDBTests/SQLRequestTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,8 +10,8 @@ class SQLRequestTests: GRDBTestCase { func testSQLRequest() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let request = SQLRequest("SELECT 1") - let (statement, adapter) = try request.prepare(db) + let request = SQLRequest(sql: "SELECT 1") + let (statement, adapter) = try request.prepare(db, forSingleResult: false) XCTAssertEqual(statement.sql, "SELECT 1") XCTAssertNil(adapter) let row = try request.fetchOne(db) @@ -24,8 +22,8 @@ class SQLRequestTests: GRDBTestCase { func testSQLRequestWithArgumentsAndAdapter() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let request = SQLRequest("SELECT ?, ?", arguments: [1, 2], adapter: SuffixRowAdapter(fromIndex: 1)) - let (statement, adapter) = try request.prepare(db) + let request = SQLRequest(sql: "SELECT ?, ?", arguments: [1, 2], adapter: SuffixRowAdapter(fromIndex: 1)) + let (statement, adapter) = try request.prepare(db, forSingleResult: false) XCTAssertEqual(statement.sql, "SELECT ?, ?") XCTAssertNotNil(adapter) let int = try request.fetchOne(db)! @@ -36,9 +34,9 @@ class SQLRequestTests: GRDBTestCase { func testNotCachedSQLRequest() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let request = SQLRequest("SELECT 1") - let (statement1, _) = try request.prepare(db) - let (statement2, _) = try request.prepare(db) + let request = SQLRequest(sql: "SELECT 1") + let (statement1, _) = try request.prepare(db, forSingleResult: false) + let (statement2, _) = try request.prepare(db, forSingleResult: false) XCTAssertTrue(statement1 !== statement2) } } @@ -46,9 +44,9 @@ class SQLRequestTests: GRDBTestCase { func testCachedSQLRequest() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let request = SQLRequest("SELECT 1", cached: true) - let (statement1, _) = try request.prepare(db) - let (statement2, _) = try request.prepare(db) + let request = SQLRequest(sql: "SELECT 1", cached: true) + let (statement1, _) = try request.prepare(db, forSingleResult: false) + let (statement2, _) = try request.prepare(db, forSingleResult: false) XCTAssertTrue(statement1 === statement2) } } @@ -56,8 +54,8 @@ class SQLRequestTests: GRDBTestCase { func testRequestInitializer() throws { struct CustomRequest: FetchRequest { typealias RowDecoder = Row - func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) { - let statement = try db.makeSelectStatement("SELECT ? AS a, ? AS b") + func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) { + let statement = try db.makeSelectStatement(sql: "SELECT ? AS a, ? AS b") statement.arguments = [1, "foo"] return (statement, nil) } @@ -71,4 +69,182 @@ class SQLRequestTests: GRDBTestCase { XCTAssertEqual(try sqlRequest.fetchOne(db)!, ["a": 1, "b": "foo"]) } } + + func testRequestInitializerAndSingleResultHint() throws { + struct CustomRequest: FetchRequest { + typealias RowDecoder = Row + func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) { + if singleResult { fatalError("not implemented") } + return try (db.makeSelectStatement(sql: "SELECT 'multiple'"), nil) + } + } + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + let request = try SQLRequest(db, request: CustomRequest()) + XCTAssertEqual(request.sql, "SELECT 'multiple'") + } + } + + func testSQLLiteralInitializer() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request = SQLRequest(literal: SQLLiteral(sql: """ + SELECT ? + """, arguments: ["O'Brien"])) + XCTAssertEqual(request.sql, """ + SELECT ? + """) + let string = try request.fetchOne(db)! + XCTAssertEqual(string, "O'Brien") + } + } + + #if swift(>=5.0) + func testSQLLiteralInitializerWithInterpolation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request = SQLRequest(literal: """ + SELECT \("O'Brien") + """) + XCTAssertEqual(request.sql, """ + SELECT ? + """) + let string = try request.fetchOne(db)! + XCTAssertEqual(string, "O'Brien") + } + } + + func testSQLInterpolation() throws { + // This test assumes SQLRequest interpolation is based on + // SQLInterpolation, just like SQLLiteral. We thus test much less + // cases. + struct Player: Codable, TableRecord, FetchableRecord, PersistableRecord { + var id: Int64 + var name: String + + static func filter(id: Int64) -> SQLRequest { + return """ + SELECT * + FROM \(self) + WHERE \(CodingKeys.id) = \(id) + """ + } + + static func filter(ids: [Int64]) -> SQLRequest { + return """ + SELECT * + FROM \(self) + WHERE \(CodingKeys.id) IN \(ids) + """ + } + + static func filter(excludedIds: S) -> SQLRequest where S: Sequence, S.Element == Int64 { + return """ + SELECT * + FROM \(self) + WHERE \(CodingKeys.id) NOT IN \(excludedIds) + """ + } + + // The test pass if this method compiles. + static func complexRequest() -> SQLRequest { + let query: SQLLiteral = "SELECT * FROM \(self)" + return SQLRequest(literal: query) + } + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try db.create(table: "player") { t in + t.autoIncrementedPrimaryKey("id") + t.column("name", .text) + } + + try Player(id: 1, name: "Arthur").insert(db) + try Player(id: 42, name: "Barbara").insert(db) + + do { + let request = Player.filter(id: 42) + XCTAssertEqual(request.sql, """ + SELECT * + FROM "player" + WHERE "id" = ? + """) + let player = try request.fetchOne(db)! + XCTAssertEqual(player.name, "Barbara") + XCTAssertEqual(lastSQLQuery, """ + SELECT * + FROM "player" + WHERE "id" = 42 + """) + } + + do { + let request = Player.filter(ids: [1, 2, 3]) + XCTAssertEqual(request.sql, """ + SELECT * + FROM "player" + WHERE "id" IN (?,?,?) + """) + let players = try request.fetchAll(db) + XCTAssertEqual(players.count, 1) + XCTAssertEqual(players[0].name, "Arthur") + XCTAssertEqual(lastSQLQuery, """ + SELECT * + FROM "player" + WHERE "id" IN (1,2,3) + """) + } + + do { + let request = Player.filter(ids: []) + XCTAssertEqual(request.sql, """ + SELECT * + FROM "player" + WHERE "id" IN (SELECT NULL WHERE NULL) + """) + let players = try request.fetchAll(db) + XCTAssert(players.isEmpty) + XCTAssertEqual(lastSQLQuery, """ + SELECT * + FROM "player" + WHERE "id" IN (SELECT NULL WHERE NULL) + """) + } + + do { + let request = Player.filter(excludedIds: [42, 666]) + XCTAssertEqual(request.sql, """ + SELECT * + FROM "player" + WHERE "id" NOT IN (?,?) + """) + let players = try request.fetchAll(db) + XCTAssertEqual(players.count, 1) + XCTAssertEqual(players[0].name, "Arthur") + XCTAssertEqual(lastSQLQuery, """ + SELECT * + FROM "player" + WHERE "id" NOT IN (42,666) + """) + } + + do { + let request = Player.filter(excludedIds: []) + XCTAssertEqual(request.sql, """ + SELECT * + FROM "player" + WHERE "id" NOT IN (SELECT NULL WHERE NULL) + """) + let players = try request.fetchAll(db) + XCTAssertEqual(players.count, 2) + XCTAssertEqual(lastSQLQuery, """ + SELECT * + FROM "player" + WHERE "id" NOT IN (SELECT NULL WHERE NULL) + """) + } + } + } + #endif } diff --git a/Tests/GRDBTests/SchedulingWatchdogTests.swift b/Tests/GRDBTests/SchedulingWatchdogTests.swift index a55fc7521..50d0086ca 100644 --- a/Tests/GRDBTests/SchedulingWatchdogTests.swift +++ b/Tests/GRDBTests/SchedulingWatchdogTests.swift @@ -1,10 +1,8 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher // @testable so that we can test SchedulingWatchdog -#elseif GRDBCUSTOMSQLITE - @testable import GRDBCustomSQLite // @testable so that we can test SchedulingWatchdog +#if GRDBCUSTOMSQLITE + @testable import GRDBCustomSQLite #else - @testable import GRDB // @testable so that we can test SchedulingWatchdog + @testable import GRDB #endif class SchedulingWatchdogTests: GRDBTestCase { @@ -50,18 +48,18 @@ class SchedulingWatchdogTests: GRDBTestCase { let dbQueue1 = try makeDatabaseQueue() let dbQueue2 = try makeDatabaseQueue() try dbQueue1.inDatabase { db1 in - try db1.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") - try db1.execute("INSERT INTO items (id) VALUES (NULL)") + try db1.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db1.execute(sql: "INSERT INTO items (id) VALUES (NULL)") try dbQueue2.inDatabase { db2 in - try db2.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") - let rows = try Row.fetchCursor(db1, "SELECT * FROM items") + try db2.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") + let rows = try Row.fetchCursor(db1, sql: "SELECT * FROM items") while let row = try rows.next() { - try db2.execute("INSERT INTO items (id) VALUES (?)", arguments: [row["id"]]) + try db2.execute(sql: "INSERT INTO items (id) VALUES (?)", arguments: [row["id"]]) } } } let count = try dbQueue2.inDatabase { db2 in - try Int.fetchOne(db2, "SELECT COUNT(*) FROM items")! + try Int.fetchOne(db2, sql: "SELECT COUNT(*) FROM items")! } XCTAssertEqual(count, 1) } @@ -70,18 +68,18 @@ class SchedulingWatchdogTests: GRDBTestCase { let dbPool1 = try makeDatabasePool() let dbQueue2 = try makeDatabaseQueue() try dbPool1.write { db1 in - try db1.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") - try db1.execute("INSERT INTO items (id) VALUES (NULL)") + try db1.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db1.execute(sql: "INSERT INTO items (id) VALUES (NULL)") try dbQueue2.inDatabase { db2 in - try db2.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") - let rows = try Row.fetchCursor(db1, "SELECT * FROM items") + try db2.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") + let rows = try Row.fetchCursor(db1, sql: "SELECT * FROM items") while let row = try rows.next() { - try db2.execute("INSERT INTO items (id) VALUES (?)", arguments: [row["id"]]) + try db2.execute(sql: "INSERT INTO items (id) VALUES (?)", arguments: [row["id"]]) } } } let count = try dbQueue2.inDatabase { db2 in - try Int.fetchOne(db2, "SELECT COUNT(*) FROM items")! + try Int.fetchOne(db2, sql: "SELECT COUNT(*) FROM items")! } XCTAssertEqual(count, 1) } @@ -90,18 +88,18 @@ class SchedulingWatchdogTests: GRDBTestCase { let dbQueue1 = try makeDatabaseQueue() let dbPool2 = try makeDatabasePool() try dbQueue1.inDatabase { db1 in - try db1.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") - try db1.execute("INSERT INTO items (id) VALUES (NULL)") + try db1.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db1.execute(sql: "INSERT INTO items (id) VALUES (NULL)") try dbPool2.write { db2 in - try db2.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") - let rows = try Row.fetchCursor(db1, "SELECT * FROM items") + try db2.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") + let rows = try Row.fetchCursor(db1, sql: "SELECT * FROM items") while let row = try rows.next() { - try db2.execute("INSERT INTO items (id) VALUES (?)", arguments: [row["id"]]) + try db2.execute(sql: "INSERT INTO items (id) VALUES (?)", arguments: [row["id"]]) } } } let count = try dbPool2.read { db2 in - try Int.fetchOne(db2, "SELECT COUNT(*) FROM items")! + try Int.fetchOne(db2, sql: "SELECT COUNT(*) FROM items")! } XCTAssertEqual(count, 1) } @@ -110,18 +108,18 @@ class SchedulingWatchdogTests: GRDBTestCase { let dbPool1 = try makeDatabasePool() let dbPool2 = try makeDatabasePool() try dbPool1.write { db1 in - try db1.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") - try db1.execute("INSERT INTO items (id) VALUES (NULL)") + try db1.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") + try db1.execute(sql: "INSERT INTO items (id) VALUES (NULL)") try dbPool2.write { db2 in - try db2.execute("CREATE TABLE items (id INTEGER PRIMARY KEY)") - let rows = try Row.fetchCursor(db1, "SELECT * FROM items") + try db2.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") + let rows = try Row.fetchCursor(db1, sql: "SELECT * FROM items") while let row = try rows.next() { - try db2.execute("INSERT INTO items (id) VALUES (?)", arguments: [row["id"]]) + try db2.execute(sql: "INSERT INTO items (id) VALUES (?)", arguments: [row["id"]]) } } } let count = try dbPool2.write { db2 in - try Int.fetchOne(db2, "SELECT COUNT(*) FROM items")! + try Int.fetchOne(db2, sql: "SELECT COUNT(*) FROM items")! } XCTAssertEqual(count, 1) } diff --git a/Tests/GRDBTests/SelectStatementTests.swift b/Tests/GRDBTests/SelectStatementTests.swift index 521770fbd..b2b088478 100644 --- a/Tests/GRDBTests/SelectStatementTests.swift +++ b/Tests/GRDBTests/SelectStatementTests.swift @@ -1,10 +1,10 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else - #if SWIFT_PACKAGE + #if GRDBCIPHER + import SQLCipher + #elseif SWIFT_PACKAGE import CSQLite #else import SQLite3 @@ -17,7 +17,7 @@ class SelectStatementTests : GRDBTestCase { override func setup(_ dbWriter: DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("createPersons") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE persons ( id INTEGER PRIMARY KEY, creationDate TEXT, @@ -25,9 +25,9 @@ class SelectStatementTests : GRDBTestCase { age INT) """) - try db.execute("INSERT INTO persons (name, age) VALUES (?,?)", arguments: ["Arthur", 41]) - try db.execute("INSERT INTO persons (name, age) VALUES (?,?)", arguments: ["Barbara", 26]) - try db.execute("INSERT INTO persons (name, age) VALUES (?,?)", arguments: ["Craig", 13]) + try db.execute(sql: "INSERT INTO persons (name, age) VALUES (?,?)", arguments: ["Arthur", 41]) + try db.execute(sql: "INSERT INTO persons (name, age) VALUES (?,?)", arguments: ["Barbara", 26]) + try db.execute(sql: "INSERT INTO persons (name, age) VALUES (?,?)", arguments: ["Craig", 13]) } try migrator.migrate(dbWriter) } @@ -36,11 +36,11 @@ class SelectStatementTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let sql = "SELECT 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 'Barbara', 'Gourde'" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let cursor = statement.makeCursor() // Check that StatementCursor gives access to the raw SQLite API - XCTAssertEqual(String(cString: sqlite3_column_name(cursor.statement.sqliteStatement, 0)), "firstName") + XCTAssertEqual(String(cString: sqlite3_column_name(cursor._statement.sqliteStatement, 0)), "firstName") XCTAssertFalse(try cursor.next() == nil) XCTAssertFalse(try cursor.next() == nil) @@ -55,7 +55,7 @@ class SelectStatementTests : GRDBTestCase { dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError }) try dbQueue.inDatabase { db in func test(_ cursor: StatementCursor) throws { - let sql = cursor.statement.sql + let sql = cursor._statement.sql do { _ = try cursor.next() XCTFail() @@ -68,22 +68,20 @@ class SelectStatementTests : GRDBTestCase { do { _ = try cursor.next() XCTFail() - } catch let error as DatabaseError { - XCTAssertEqual(error.resultCode, .SQLITE_MISUSE) - XCTAssertEqual(error.message, "\(customError)") - XCTAssertEqual(error.sql!, sql) - XCTAssertEqual(error.description, "SQLite error 21 with statement `\(sql)`: \(customError)") + } catch is DatabaseError { + // Various SQLite and SQLCipher versions don't emit the same + // error. What we care about is that there is an error. } } - try test(db.makeSelectStatement("SELECT throw(), NULL").makeCursor()) - try test(db.makeSelectStatement("SELECT 0, throw(), NULL").makeCursor()) + try test(db.makeSelectStatement(sql: "SELECT throw(), NULL").makeCursor()) + try test(db.makeSelectStatement(sql: "SELECT 0, throw(), NULL").makeCursor()) } } func testArrayStatementArguments() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM persons WHERE age < ?") + let statement = try db.makeSelectStatement(sql: "SELECT COUNT(*) FROM persons WHERE age < ?") let ages = [20, 30, 40, 50] let counts = try ages.map { try Int.fetchOne(statement, arguments: [$0])! } XCTAssertEqual(counts, [1,2,2,3]) @@ -93,7 +91,7 @@ class SelectStatementTests : GRDBTestCase { func testStatementArgumentsSetterWithArray() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM persons WHERE age < ?") + let statement = try db.makeSelectStatement(sql: "SELECT COUNT(*) FROM persons WHERE age < ?") let ages = [20, 30, 40, 50] let counts = try ages.map { (age: Int) -> Int in statement.arguments = [age] @@ -106,7 +104,7 @@ class SelectStatementTests : GRDBTestCase { func testDictionaryStatementArguments() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM persons WHERE age < :age") + let statement = try db.makeSelectStatement(sql: "SELECT COUNT(*) FROM persons WHERE age < :age") let ageDicts: [[String: DatabaseValueConvertible?]] = [["age": 20], ["age": 30], ["age": 40], ["age": 50]] let counts = try ageDicts.map { dic -> Int in // Make sure we don't trigger a failible initializer @@ -120,7 +118,7 @@ class SelectStatementTests : GRDBTestCase { func testStatementArgumentsSetterWithDictionary() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM persons WHERE age < :age") + let statement = try db.makeSelectStatement(sql: "SELECT COUNT(*) FROM persons WHERE age < :age") let ageDicts: [[String: DatabaseValueConvertible?]] = [["age": 20], ["age": 30], ["age": 40], ["age": 50]] let counts = try ageDicts.map { ageDict -> Int in statement.arguments = StatementArguments(ageDict) @@ -134,7 +132,7 @@ class SelectStatementTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in do { - _ = try db.makeSelectStatement("SELECT * FROM blah") + _ = try db.makeSelectStatement(sql: "SELECT * FROM blah") XCTFail() } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) @@ -158,11 +156,11 @@ class SelectStatementTests : GRDBTestCase { let sql = "SELECT bomb()" needsThrow = false - XCTAssertEqual(try String.fetchAll(db.cachedSelectStatement(sql)), ["success"]) + XCTAssertEqual(try String.fetchAll(db.cachedSelectStatement(sql: sql)), ["success"]) do { needsThrow = true - _ = try String.fetchAll(db.cachedSelectStatement(sql)) + _ = try String.fetchAll(db.cachedSelectStatement(sql: sql)) XCTFail() } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) @@ -172,7 +170,7 @@ class SelectStatementTests : GRDBTestCase { } needsThrow = false - XCTAssertEqual(try String.fetchAll(db.cachedSelectStatement(sql)), ["success"]) + XCTAssertEqual(try String.fetchAll(db.cachedSelectStatement(sql: sql)), ["success"]) } } @@ -227,19 +225,19 @@ class SelectStatementTests : GRDBTestCase { try db.create(table: "table5") { t in t.column("id", .integer).primaryKey() } - try db.execute("CREATE TRIGGER table5trigger AFTER INSERT ON table5 BEGIN INSERT INTO table1 (id3, id4, a, b) VALUES (NULL, NULL, 0, 0); END") + try db.execute(sql: "CREATE TRIGGER table5trigger AFTER INSERT ON table5 BEGIN INSERT INTO table1 (id3, id4, a, b) VALUES (NULL, NULL, 0, 0); END") let statements = try [ - db.makeSelectStatement("SELECT * FROM table1"), - db.makeSelectStatement("SELECT id, id3, a FROM table1"), - db.makeSelectStatement("SELECT table1.id, table1.a, table2.a FROM table1 JOIN table2 ON table1.id = table2.id"), + db.makeSelectStatement(sql: "SELECT * FROM table1"), + db.makeSelectStatement(sql: "SELECT id, id3, a FROM table1"), + db.makeSelectStatement(sql: "SELECT table1.id, table1.a, table2.a FROM table1 JOIN table2 ON table1.id = table2.id"), // This last request triggers its observer or not, depending on the SQLite version. // Before SQLite 3.19.0, its region is doubtful, and every database change is deemed impactful. // Starting SQLite 3.19.0, it knows that only table1 is involved. // // See doubtfulCountFunction below - db.makeSelectStatement("SELECT COUNT(*) FROM table1"), + db.makeSelectStatement(sql: "SELECT COUNT(*) FROM table1"), ] let doubtfulCountFunction = (sqlite3_libversion_number() < 3019000) @@ -255,43 +253,43 @@ class SelectStatementTests : GRDBTestCase { db.add(transactionObserver: observer) } - try db.execute("INSERT INTO table3 (id) VALUES (1)") - try db.execute("INSERT INTO table4 (id) VALUES (1)") - try db.execute("INSERT INTO table1 (id, a, b, id3, id4) VALUES (NULL, 0, 0, 1, 1)") + try db.execute(sql: "INSERT INTO table3 (id) VALUES (1)") + try db.execute(sql: "INSERT INTO table4 (id) VALUES (1)") + try db.execute(sql: "INSERT INTO table1 (id, a, b, id3, id4) VALUES (NULL, 0, 0, 1, 1)") XCTAssertEqual(observers.map { $0.triggered }, [true, true, true, true]) - try db.execute("INSERT INTO table2 (id, a, b) VALUES (NULL, 0, 0)") + try db.execute(sql: "INSERT INTO table2 (id, a, b) VALUES (NULL, 0, 0)") XCTAssertEqual(observers.map { $0.triggered }, [false, false, true, doubtfulCountFunction]) - try db.execute("UPDATE table1 SET a = 1") + try db.execute(sql: "UPDATE table1 SET a = 1") XCTAssertEqual(observers.map { $0.triggered }, [true, true, true, true]) - try db.execute("UPDATE table1 SET b = 1") + try db.execute(sql: "UPDATE table1 SET b = 1") XCTAssertEqual(observers.map { $0.triggered }, [true, false, false, true]) - try db.execute("UPDATE table2 SET a = 1") + try db.execute(sql: "UPDATE table2 SET a = 1") XCTAssertEqual(observers.map { $0.triggered }, [false, false, true, doubtfulCountFunction]) - try db.execute("UPDATE table2 SET b = 1") + try db.execute(sql: "UPDATE table2 SET b = 1") XCTAssertEqual(observers.map { $0.triggered }, [false, false, false, doubtfulCountFunction]) - try db.execute("UPDATE table3 SET id = 2 WHERE id = 1") + try db.execute(sql: "UPDATE table3 SET id = 2 WHERE id = 1") XCTAssertEqual(observers.map { $0.triggered }, [true, true, false, true]) - try db.execute("UPDATE table4 SET id = 2 WHERE id = 1") + try db.execute(sql: "UPDATE table4 SET id = 2 WHERE id = 1") XCTAssertEqual(observers.map { $0.triggered }, [true, false, false, true]) - try db.execute("DELETE FROM table4") + try db.execute(sql: "DELETE FROM table4") XCTAssertEqual(observers.map { $0.triggered }, [true, false, false, true]) - try db.execute("INSERT INTO table4 (id) VALUES (1)") - try db.execute("DELETE FROM table4") + try db.execute(sql: "INSERT INTO table4 (id) VALUES (1)") + try db.execute(sql: "DELETE FROM table4") XCTAssertEqual(observers.map { $0.triggered }, [false, false, false, doubtfulCountFunction]) - try db.execute("DELETE FROM table3") + try db.execute(sql: "DELETE FROM table3") XCTAssertEqual(observers.map { $0.triggered }, [true, true, true, true]) - try db.execute("INSERT INTO table5 (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO table5 (id) VALUES (NULL)") XCTAssertEqual(observers.map { $0.triggered }, [true, true, true, true]) } } diff --git a/Tests/GRDBTests/StatementArguments+FoundationTests.swift b/Tests/GRDBTests/StatementArguments+FoundationTests.swift index 7ac4a4888..85e863d35 100644 --- a/Tests/GRDBTests/StatementArguments+FoundationTests.swift +++ b/Tests/GRDBTests/StatementArguments+FoundationTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -15,7 +13,7 @@ class StatementArgumentsFoundationTests: GRDBTestCase { override func setup(_ dbWriter: DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("createPersons") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE persons ( id INTEGER PRIMARY KEY, creationDate TEXT, @@ -31,7 +29,7 @@ class StatementArgumentsFoundationTests: GRDBTestCase { try dbQueue.inTransaction { db in - let statement = try db.makeUpdateStatement("INSERT INTO persons (name, age) VALUES (?, ?)") + let statement = try db.makeUpdateStatement(sql: "INSERT INTO persons (name, age) VALUES (?, ?)") let persons: [[Any]] = [ ["Arthur", 41], ["Barbara", 38], @@ -44,7 +42,7 @@ class StatementArgumentsFoundationTests: GRDBTestCase { } try dbQueue.inDatabase { db in - let rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY name") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY name") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["name"] as String, "Arthur") XCTAssertEqual(rows[0]["age"] as Int, 41) @@ -69,7 +67,7 @@ class StatementArgumentsFoundationTests: GRDBTestCase { try dbQueue.inTransaction { db in - let statement = try db.makeUpdateStatement("INSERT INTO persons (name, age) VALUES (:name, :age)") + let statement = try db.makeUpdateStatement(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)") let persons: [[AnyHashable: Any]] = [ ["name": "Arthur", "age": 41], ["name": "Barbara", "age": 38], @@ -82,7 +80,7 @@ class StatementArgumentsFoundationTests: GRDBTestCase { } try dbQueue.inDatabase { db in - let rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY name") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY name") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["name"] as String, "Arthur") XCTAssertEqual(rows[0]["age"] as Int, 41) diff --git a/Tests/GRDBTests/StatementArgumentsTests.swift b/Tests/GRDBTests/StatementArgumentsTests.swift index 8457d7c40..cfb887c27 100644 --- a/Tests/GRDBTests/StatementArgumentsTests.swift +++ b/Tests/GRDBTests/StatementArgumentsTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,7 +10,7 @@ class StatementArgumentsTests: GRDBTestCase { override func setup(_ dbWriter: DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("createPersons") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE persons ( id INTEGER PRIMARY KEY, firstName TEXT, @@ -26,7 +24,7 @@ class StatementArgumentsTests: GRDBTestCase { func testPositionalStatementArgumentsValidation() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let statement = try db.makeUpdateStatement("INSERT INTO persons (firstName, age) VALUES (?, ?)") + let statement = try db.makeUpdateStatement(sql: "INSERT INTO persons (firstName, age) VALUES (?, ?)") do { // Correct number of arguments @@ -89,11 +87,11 @@ class StatementArgumentsTests: GRDBTestCase { let age = 42 let arguments = StatementArguments([name, age] as [DatabaseValueConvertible?]) - let updateStatement = try db.makeUpdateStatement("INSERT INTO persons (firstName, age) VALUES (?, ?)") + let updateStatement = try db.makeUpdateStatement(sql: "INSERT INTO persons (firstName, age) VALUES (?, ?)") updateStatement.arguments = arguments try updateStatement.execute() - let selectStatement = try db.makeSelectStatement("SELECT * FROM persons WHERE firstName = ? AND age = ?") + let selectStatement = try db.makeSelectStatement(sql: "SELECT * FROM persons WHERE firstName = ? AND age = ?") selectStatement.arguments = arguments let row = try Row.fetchOne(selectStatement)! @@ -109,11 +107,11 @@ class StatementArgumentsTests: GRDBTestCase { let age = 42 let arguments = StatementArguments([name, age] as [DatabaseValueConvertible?]) - let updateStatement = try db.makeUpdateStatement("INSERT INTO persons (firstName, age) VALUES (?, ?)") + let updateStatement = try db.makeUpdateStatement(sql: "INSERT INTO persons (firstName, age) VALUES (?, ?)") updateStatement.unsafeSetArguments(arguments) try updateStatement.execute() - let selectStatement = try db.makeSelectStatement("SELECT * FROM persons WHERE firstName = ? AND age = ?") + let selectStatement = try db.makeSelectStatement(sql: "SELECT * FROM persons WHERE firstName = ? AND age = ?") selectStatement.unsafeSetArguments(arguments) let row = try Row.fetchOne(selectStatement)! @@ -125,7 +123,7 @@ class StatementArgumentsTests: GRDBTestCase { func testNamedStatementArgumentsValidation() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let statement = try db.makeUpdateStatement("INSERT INTO persons (firstName, age) VALUES (:firstName, :age)") + let statement = try db.makeUpdateStatement(sql: "INSERT INTO persons (firstName, age) VALUES (:firstName, :age)") do { // Correct number of arguments @@ -202,11 +200,11 @@ class StatementArgumentsTests: GRDBTestCase { let age = 42 let arguments = StatementArguments(["name": name, "age": age] as [String: DatabaseValueConvertible?]) - let updateStatement = try db.makeUpdateStatement("INSERT INTO persons (firstName, age) VALUES (:name, :age)") + let updateStatement = try db.makeUpdateStatement(sql: "INSERT INTO persons (firstName, age) VALUES (:name, :age)") updateStatement.arguments = arguments try updateStatement.execute() - let selectStatement = try db.makeSelectStatement("SELECT * FROM persons WHERE firstName = :name AND age = :age") + let selectStatement = try db.makeSelectStatement(sql: "SELECT * FROM persons WHERE firstName = :name AND age = :age") selectStatement.arguments = arguments let row = try Row.fetchOne(selectStatement)! @@ -222,11 +220,11 @@ class StatementArgumentsTests: GRDBTestCase { let age = 42 let arguments = StatementArguments(["name": name, "age": age] as [String: DatabaseValueConvertible?]) - let updateStatement = try db.makeUpdateStatement("INSERT INTO persons (firstName, age) VALUES (:name, :age)") + let updateStatement = try db.makeUpdateStatement(sql: "INSERT INTO persons (firstName, age) VALUES (:name, :age)") updateStatement.unsafeSetArguments(arguments) try updateStatement.execute() - let selectStatement = try db.makeSelectStatement("SELECT * FROM persons WHERE firstName = :name AND age = :age") + let selectStatement = try db.makeSelectStatement(sql: "SELECT * FROM persons WHERE firstName = :name AND age = :age") selectStatement.unsafeSetArguments(arguments) let row = try Row.fetchOne(selectStatement)! @@ -238,11 +236,11 @@ class StatementArgumentsTests: GRDBTestCase { func testReusedNamedStatementArgumentsValidation() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - let statement = try db.makeUpdateStatement("INSERT INTO persons (firstName, lastName, age) VALUES (:name, :name, :age)") + let statement = try db.makeUpdateStatement(sql: "INSERT INTO persons (firstName, lastName, age) VALUES (:name, :name, :age)") do { try statement.execute(arguments: ["name": "foo", "age": 1]) - let row = try Row.fetchOne(db, "SELECT * FROM persons")! + let row = try Row.fetchOne(db, sql: "SELECT * FROM persons")! XCTAssertEqual(row["firstName"] as String, "foo") XCTAssertEqual(row["lastName"] as String, "foo") XCTAssertEqual(row["age"] as Int, 1) @@ -324,11 +322,11 @@ class StatementArgumentsTests: GRDBTestCase { let age = 42 let arguments = StatementArguments(["name": name, "age": age] as [String: DatabaseValueConvertible?]) - let updateStatement = try db.makeUpdateStatement("INSERT INTO persons (firstName, lastName, age) VALUES (:name, :name, :age)") + let updateStatement = try db.makeUpdateStatement(sql: "INSERT INTO persons (firstName, lastName, age) VALUES (:name, :name, :age)") updateStatement.arguments = arguments try updateStatement.execute() - let selectStatement = try db.makeSelectStatement("SELECT * FROM persons WHERE firstName = :name AND lastName = :name AND age = :age") + let selectStatement = try db.makeSelectStatement(sql: "SELECT * FROM persons WHERE firstName = :name AND lastName = :name AND age = :age") selectStatement.arguments = arguments let row = try Row.fetchOne(selectStatement)! @@ -344,11 +342,11 @@ class StatementArgumentsTests: GRDBTestCase { let age = 42 let arguments = StatementArguments(["name": name, "age": age] as [String: DatabaseValueConvertible?]) - let updateStatement = try db.makeUpdateStatement("INSERT INTO persons (firstName, lastName, age) VALUES (:name, :name, :age)") + let updateStatement = try db.makeUpdateStatement(sql: "INSERT INTO persons (firstName, lastName, age) VALUES (:name, :name, :age)") updateStatement.unsafeSetArguments(arguments) try updateStatement.execute() - let selectStatement = try db.makeSelectStatement("SELECT * FROM persons WHERE firstName = :name AND lastName = :name AND age = :age") + let selectStatement = try db.makeSelectStatement(sql: "SELECT * FROM persons WHERE firstName = :name AND lastName = :name AND age = :age") selectStatement.unsafeSetArguments(arguments) let row = try Row.fetchOne(selectStatement)! @@ -361,7 +359,7 @@ class StatementArgumentsTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in let sql = "SELECT ?2 AS two, :foo AS foo, ?1 AS one, :foo AS foo2, :bar AS bar" - let row = try Row.fetchOne(db, sql, arguments: [1, 2, "bar"] + ["foo": "foo"])! + let row = try Row.fetchOne(db, sql: sql, arguments: [1, 2, "bar"] + ["foo": "foo"])! XCTAssertEqual(row, ["two": 2, "foo": "foo", "one": 1, "foo2": "foo", "bar": "bar"]) } } @@ -374,7 +372,7 @@ class StatementArgumentsTests: GRDBTestCase { let replacedValues = arguments.append(contentsOf: [3, 4]) XCTAssert(replacedValues.isEmpty) - let row = try Row.fetchOne(db, "SELECT ?, ?, ?, ?", arguments: arguments)! + let row = try Row.fetchOne(db, sql: "SELECT ?, ?, ?, ?", arguments: arguments)! XCTAssertEqual(row, ["?": 1, "?": 2, "?": 3, "?": 4]) } @@ -383,7 +381,7 @@ class StatementArgumentsTests: GRDBTestCase { let replacedValues = arguments.append(contentsOf: ["foo": "qux", "bar": "baz", "tata": "tutu"]) XCTAssertEqual(replacedValues, ["foo": "foo".databaseValue, "bar": "bar".databaseValue]) - let row = try Row.fetchOne(db, "SELECT :foo, :bar, :toto, :tata", arguments: arguments)! + let row = try Row.fetchOne(db, sql: "SELECT :foo, :bar, :toto, :tata", arguments: arguments)! XCTAssertEqual(row, [":foo": "qux", ":bar": "baz", ":toto": "titi", ":tata": "tutu"]) } @@ -392,7 +390,7 @@ class StatementArgumentsTests: GRDBTestCase { let replacedValues = arguments.append(contentsOf: ["foo": "qux", "bar": "baz", "tata": "tutu"]) XCTAssert(replacedValues.isEmpty) - let row = try Row.fetchOne(db, "SELECT ?, :foo, :bar, ?, :tata", arguments: arguments)! + let row = try Row.fetchOne(db, sql: "SELECT ?, :foo, :bar, ?, :tata", arguments: arguments)! XCTAssertEqual(row, ["?": 1, ":foo": "qux", ":bar": "baz", "?": 2, ":tata": "tutu"]) } } @@ -403,20 +401,20 @@ class StatementArgumentsTests: GRDBTestCase { try dbQueue.inDatabase { db in do { let arguments: StatementArguments = [1, 2] + [3, 4] - let row = try Row.fetchOne(db, "SELECT ?, ?, ?, ?", arguments: arguments)! + let row = try Row.fetchOne(db, sql: "SELECT ?, ?, ?, ?", arguments: arguments)! XCTAssertEqual(row, ["?": 1, "?": 2, "?": 3, "?": 4]) } do { // + does not allow overrides let arguments: StatementArguments = ["foo": "foo", "bar": "bar", "toto": "titi"] + ["tata": "tutu"] - let row = try Row.fetchOne(db, "SELECT :foo, :bar, :toto, :tata", arguments: arguments)! + let row = try Row.fetchOne(db, sql: "SELECT :foo, :bar, :toto, :tata", arguments: arguments)! XCTAssertEqual(row, [":foo": "foo", ":bar": "bar", ":toto": "titi", ":tata": "tutu"]) } do { let arguments: StatementArguments = [1, 2] + ["foo": "qux", "bar": "baz", "tata": "tutu"] - let row = try Row.fetchOne(db, "SELECT ?, :foo, :bar, ?, :tata", arguments: arguments)! + let row = try Row.fetchOne(db, sql: "SELECT ?, :foo, :bar, ?, :tata", arguments: arguments)! XCTAssertEqual(row, ["?": 1, ":foo": "qux", ":bar": "baz", "?": 2, ":tata": "tutu"]) } } @@ -427,20 +425,20 @@ class StatementArgumentsTests: GRDBTestCase { try dbQueue.inDatabase { db in do { let arguments: StatementArguments = [1, 2] &+ [3, 4] - let row = try Row.fetchOne(db, "SELECT ?, ?, ?, ?", arguments: arguments)! + let row = try Row.fetchOne(db, sql: "SELECT ?, ?, ?, ?", arguments: arguments)! XCTAssertEqual(row, ["?": 1, "?": 2, "?": 3, "?": 4]) } do { // &+ does not allow overrides let arguments: StatementArguments = ["foo": "foo", "bar": "bar", "toto": "titi"] &+ ["foo": "qux", "bar": "baz", "tata": "tutu"] - let row = try Row.fetchOne(db, "SELECT :foo, :bar, :toto, :tata", arguments: arguments)! + let row = try Row.fetchOne(db, sql: "SELECT :foo, :bar, :toto, :tata", arguments: arguments)! XCTAssertEqual(row, [":foo": "qux", ":bar": "baz", ":toto": "titi", ":tata": "tutu"]) } do { let arguments: StatementArguments = [1, 2] &+ ["foo": "qux", "bar": "baz", "tata": "tutu"] - let row = try Row.fetchOne(db, "SELECT ?, :foo, :bar, ?, :tata", arguments: arguments)! + let row = try Row.fetchOne(db, sql: "SELECT ?, :foo, :bar, ?, :tata", arguments: arguments)! XCTAssertEqual(row, ["?": 1, ":foo": "qux", ":bar": "baz", "?": 2, ":tata": "tutu"]) } } @@ -452,7 +450,7 @@ class StatementArgumentsTests: GRDBTestCase { do { var arguments: StatementArguments = [1, 2] arguments += [3, 4] - let row = try Row.fetchOne(db, "SELECT ?, ?, ?, ?", arguments: arguments)! + let row = try Row.fetchOne(db, sql: "SELECT ?, ?, ?, ?", arguments: arguments)! XCTAssertEqual(row, ["?": 1, "?": 2, "?": 3, "?": 4]) } @@ -460,14 +458,14 @@ class StatementArgumentsTests: GRDBTestCase { // += does not allow overrides var arguments: StatementArguments = ["foo": "foo", "bar": "bar", "toto": "titi"] arguments += ["tata": "tutu"] - let row = try Row.fetchOne(db, "SELECT :foo, :bar, :toto, :tata", arguments: arguments)! + let row = try Row.fetchOne(db, sql: "SELECT :foo, :bar, :toto, :tata", arguments: arguments)! XCTAssertEqual(row, [":foo": "foo", ":bar": "bar", ":toto": "titi", ":tata": "tutu"]) } do { var arguments: StatementArguments = [1, 2] arguments += ["foo": "qux", "bar": "baz", "tata": "tutu"] - let row = try Row.fetchOne(db, "SELECT ?, :foo, :bar, ?, :tata", arguments: arguments)! + let row = try Row.fetchOne(db, sql: "SELECT ?, :foo, :bar, ?, :tata", arguments: arguments)! XCTAssertEqual(row, ["?": 1, ":foo": "qux", ":bar": "baz", "?": 2, ":tata": "tutu"]) } } diff --git a/Tests/GRDBTests/StatementColumnConvertibleFetchTests.swift b/Tests/GRDBTests/StatementColumnConvertibleFetchTests.swift index 0e65863f5..cb1799272 100644 --- a/Tests/GRDBTests/StatementColumnConvertibleFetchTests.swift +++ b/Tests/GRDBTests/StatementColumnConvertibleFetchTests.swift @@ -1,10 +1,10 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else - #if SWIFT_PACKAGE + #if GRDBCIPHER + import SQLCipher + #elseif SWIFT_PACKAGE import CSQLite #else import SQLite3 @@ -49,30 +49,30 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { func testRowExtraction() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - var rows = try Row.fetchCursor(db, "SELECT NULL") + var rows = try Row.fetchCursor(db, sql: "SELECT NULL") while let row = try rows.next() { let one: Fetched? = row[0] XCTAssertTrue(one == nil) } - rows = try Row.fetchCursor(db, "SELECT 1") + rows = try Row.fetchCursor(db, sql: "SELECT 1") while let row = try rows.next() { let one: Fetched? = row[0] XCTAssertEqual(one!.int, 1) XCTAssertEqual(one!.fast, true) } - rows = try Row.fetchCursor(db, "SELECT 1 AS int") + rows = try Row.fetchCursor(db, sql: "SELECT 1 AS int") while let row = try rows.next() { let one: Fetched? = row["int"] XCTAssertEqual(one!.int, 1) XCTAssertEqual(one!.fast, true) } - rows = try Row.fetchCursor(db, "SELECT 1") + rows = try Row.fetchCursor(db, sql: "SELECT 1") while let row = try rows.next() { let one: Fetched = row[0] XCTAssertEqual(one.int, 1) XCTAssertEqual(one.fast, true) } - rows = try Row.fetchCursor(db, "SELECT 1 AS int") + rows = try Row.fetchCursor(db, sql: "SELECT 1 AS int") while let row = try rows.next() { let one: Fetched = row["int"] XCTAssertEqual(one.int, 1) @@ -98,24 +98,37 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT 1 UNION ALL SELECT 2" - let statement = try db.makeSelectStatement(sql) - try test(Fetched.fetchCursor(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Fetched.fetchCursor(db, sql: sql)) try test(Fetched.fetchCursor(statement)) - try test(Fetched.fetchCursor(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchCursor(db)) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchCursor(db)) } do { let sql = "SELECT 0, 1 UNION ALL SELECT 0, 2" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchCursor(db, sql, adapter: adapter)) + try test(Fetched.fetchCursor(db, sql: sql, adapter: adapter)) try test(Fetched.fetchCursor(statement, adapter: adapter)) - try test(Fetched.fetchCursor(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchCursor(db)) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db)) } } } + #if swift(>=5.0) + func testFetchCursorWithInterpolation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request: SQLRequest = "SELECT \(42)" + let cursor = try request.fetchCursor(db) + let fetched = try cursor.next()! + XCTAssertEqual(fetched.int, 42) + XCTAssertTrue(fetched.fast) + } + } + #endif + func testFetchCursorStepFailure() throws { let dbQueue = try makeDatabaseQueue() let customError = NSError(domain: "Custom", code: 0xDEAD) @@ -134,27 +147,25 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { do { _ = try cursor.next() XCTFail() - } catch let error as DatabaseError { - XCTAssertEqual(error.resultCode, .SQLITE_MISUSE) - XCTAssertEqual(error.message, "\(customError)") - XCTAssertEqual(error.sql!, sql) - XCTAssertEqual(error.description, "SQLite error 21 with statement `\(sql)`: \(customError)") + } catch is DatabaseError { + // Various SQLite and SQLCipher versions don't emit the same + // error. What we care about is that there is an error. } } do { let sql = "SELECT throw()" - try test(Fetched.fetchCursor(db, sql), sql: sql) - try test(Fetched.fetchCursor(db.makeSelectStatement(sql)), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchCursor(db), sql: sql) + try test(Fetched.fetchCursor(db, sql: sql), sql: sql) + try test(Fetched.fetchCursor(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchCursor(db), sql: sql) } do { let sql = "SELECT 0, throw()" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchCursor(db, sql, adapter: adapter), sql: sql) - try test(Fetched.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchCursor(db), sql: sql) + try test(Fetched.fetchCursor(db, sql: sql, adapter: adapter), sql: sql) + try test(Fetched.fetchCursor(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db), sql: sql) } } } @@ -175,18 +186,18 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT * FROM nonExistingTable" - try test(Fetched.fetchCursor(db, sql), sql: sql) - try test(Fetched.fetchCursor(db.makeSelectStatement(sql)), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchCursor(db), sql: sql) + try test(Fetched.fetchCursor(db, sql: sql), sql: sql) + try test(Fetched.fetchCursor(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchCursor(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchCursor(db, sql, adapter: adapter), sql: sql) - try test(Fetched.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchCursor(db), sql: sql) + try test(Fetched.fetchCursor(db, sql: sql, adapter: adapter), sql: sql) + try test(Fetched.fetchCursor(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db), sql: sql) } } } @@ -200,24 +211,36 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT 1 UNION ALL SELECT 2" - let statement = try db.makeSelectStatement(sql) - try test(Fetched.fetchAll(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Fetched.fetchAll(db, sql: sql)) try test(Fetched.fetchAll(statement)) - try test(Fetched.fetchAll(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchAll(db)) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchAll(db)) } do { let sql = "SELECT 0, 1 UNION ALL SELECT 0, 2" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchAll(db, sql, adapter: adapter)) + try test(Fetched.fetchAll(db, sql: sql, adapter: adapter)) try test(Fetched.fetchAll(statement, adapter: adapter)) - try test(Fetched.fetchAll(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchAll(db)) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db)) } } } + #if swift(>=5.0) + func testFetchAllWithInterpolation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request: SQLRequest = "SELECT \(42)" + let array = try request.fetchAll(db) + XCTAssertEqual(array[0].int, 42) + XCTAssertTrue(array[0].fast) + } + } + #endif + func testFetchAllStepFailure() throws { let dbQueue = try makeDatabaseQueue() let customError = NSError(domain: "Custom", code: 0xDEAD) @@ -236,18 +259,18 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT throw()" - try test(Fetched.fetchAll(db, sql), sql: sql) - try test(Fetched.fetchAll(db.makeSelectStatement(sql)), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchAll(db), sql: sql) + try test(Fetched.fetchAll(db, sql: sql), sql: sql) + try test(Fetched.fetchAll(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchAll(db), sql: sql) } do { let sql = "SELECT 0, throw()" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchAll(db, sql, adapter: adapter), sql: sql) - try test(Fetched.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchAll(db), sql: sql) + try test(Fetched.fetchAll(db, sql: sql, adapter: adapter), sql: sql) + try test(Fetched.fetchAll(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db), sql: sql) } } } @@ -268,18 +291,18 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT * FROM nonExistingTable" - try test(Fetched.fetchAll(db, sql), sql: sql) - try test(Fetched.fetchAll(db.makeSelectStatement(sql)), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchAll(db), sql: sql) + try test(Fetched.fetchAll(db, sql: sql), sql: sql) + try test(Fetched.fetchAll(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchAll(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchAll(db, sql, adapter: adapter), sql: sql) - try test(Fetched.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchAll(db), sql: sql) + try test(Fetched.fetchAll(db, sql: sql, adapter: adapter), sql: sql) + try test(Fetched.fetchAll(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db), sql: sql) } } } @@ -293,20 +316,20 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT 1 WHERE 0" - let statement = try db.makeSelectStatement(sql) - try test(Fetched.fetchOne(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Fetched.fetchOne(db, sql: sql)) try test(Fetched.fetchOne(statement)) - try test(Fetched.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchOne(db)) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchOne(db)) } do { let sql = "SELECT 0, 1 WHERE 0" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchOne(db, sql, adapter: adapter)) + try test(Fetched.fetchOne(db, sql: sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) - try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchOne(db)) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db)) } } do { @@ -315,20 +338,20 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT NULL" - let statement = try db.makeSelectStatement(sql) - try test(Fetched.fetchOne(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Fetched.fetchOne(db, sql: sql)) try test(Fetched.fetchOne(statement)) - try test(Fetched.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchOne(db)) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchOne(db)) } do { let sql = "SELECT 0, NULL" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchOne(db, sql, adapter: adapter)) + try test(Fetched.fetchOne(db, sql: sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) - try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchOne(db)) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db)) } } do { @@ -337,25 +360,37 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT 1" - let statement = try db.makeSelectStatement(sql) - try test(Fetched.fetchOne(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Fetched.fetchOne(db, sql: sql)) try test(Fetched.fetchOne(statement)) - try test(Fetched.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchOne(db)) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchOne(db)) } do { let sql = "SELECT 0, 1" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchOne(db, sql, adapter: adapter)) + try test(Fetched.fetchOne(db, sql: sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) - try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchOne(db)) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db)) } } } } - + + #if swift(>=5.0) + func testFetchOneWithInterpolation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request: SQLRequest = "SELECT \(42)" + let fetched = try request.fetchOne(db) + XCTAssertEqual(fetched!.int, 42) + XCTAssertTrue(fetched!.fast) + } + } + #endif + func testFetchOneStepFailure() throws { let dbQueue = try makeDatabaseQueue() let customError = NSError(domain: "Custom", code: 0xDEAD) @@ -374,18 +409,18 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT throw()" - try test(Fetched.fetchOne(db, sql), sql: sql) - try test(Fetched.fetchOne(db.makeSelectStatement(sql)), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchOne(db), sql: sql) + try test(Fetched.fetchOne(db, sql: sql), sql: sql) + try test(Fetched.fetchOne(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchOne(db), sql: sql) } do { let sql = "SELECT 0, throw()" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchOne(db, sql, adapter: adapter), sql: sql) - try test(Fetched.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchOne(db), sql: sql) + try test(Fetched.fetchOne(db, sql: sql, adapter: adapter), sql: sql) + try test(Fetched.fetchOne(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db), sql: sql) } } } @@ -406,18 +441,18 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT * FROM nonExistingTable" - try test(Fetched.fetchOne(db, sql), sql: sql) - try test(Fetched.fetchOne(db.makeSelectStatement(sql)), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchOne(db), sql: sql) + try test(Fetched.fetchOne(db, sql: sql), sql: sql) + try test(Fetched.fetchOne(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchOne(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Fetched.fetchOne(db, sql, adapter: adapter), sql: sql) - try test(Fetched.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchOne(db), sql: sql) + try test(Fetched.fetchOne(db, sql: sql, adapter: adapter), sql: sql) + try test(Fetched.fetchOne(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db), sql: sql) } } } @@ -437,24 +472,37 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT 1 UNION ALL SELECT NULL" - let statement = try db.makeSelectStatement(sql) - try test(Optional.fetchCursor(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Optional.fetchCursor(db, sql: sql)) try test(Optional.fetchCursor(statement)) - try test(Optional.fetchCursor(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchCursor(db)) + try test(Optional.fetchCursor(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchCursor(db)) } do { let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Optional.fetchCursor(db, sql, adapter: adapter)) + try test(Optional.fetchCursor(db, sql: sql, adapter: adapter)) try test(Optional.fetchCursor(statement, adapter: adapter)) - try test(Optional.fetchCursor(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchCursor(db)) + try test(Optional.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db)) } } } - + + #if swift(>=5.0) + func testOptionalFetchCursorWithInterpolation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request: SQLRequest = "SELECT \(42)" + let cursor = try request.fetchCursor(db) + let fetched = try cursor.next()! + XCTAssertEqual(fetched!.int, 42) + XCTAssert(fetched!.fast) + } + } + #endif + func testOptionalFetchCursorCompilationFailure() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in @@ -471,18 +519,18 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT * FROM nonExistingTable" - try test(Optional.fetchCursor(db, sql), sql: sql) - try test(Optional.fetchCursor(db.makeSelectStatement(sql)), sql: sql) - try test(Optional.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchCursor(db), sql: sql) + try test(Optional.fetchCursor(db, sql: sql), sql: sql) + try test(Optional.fetchCursor(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Optional.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchCursor(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Optional.fetchCursor(db, sql, adapter: adapter), sql: sql) - try test(Optional.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Optional.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchCursor(db), sql: sql) + try test(Optional.fetchCursor(db, sql: sql, adapter: adapter), sql: sql) + try test(Optional.fetchCursor(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Optional.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db), sql: sql) } } } @@ -498,24 +546,36 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT 1 UNION ALL SELECT NULL" - let statement = try db.makeSelectStatement(sql) - try test(Optional.fetchAll(db, sql)) + let statement = try db.makeSelectStatement(sql: sql) + try test(Optional.fetchAll(db, sql: sql)) try test(Optional.fetchAll(statement)) - try test(Optional.fetchAll(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetchAll(db)) + try test(Optional.fetchAll(db, SQLRequest(sql: sql))) + try test(SQLRequest(sql: sql).fetchAll(db)) } do { let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL" - let statement = try db.makeSelectStatement(sql) + let statement = try db.makeSelectStatement(sql: sql) let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Optional.fetchAll(db, sql, adapter: adapter)) + try test(Optional.fetchAll(db, sql: sql, adapter: adapter)) try test(Optional.fetchAll(statement, adapter: adapter)) - try test(Optional.fetchAll(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetchAll(db)) + try test(Optional.fetchAll(db, SQLRequest(sql: sql, adapter: adapter))) + try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db)) } } } + #if swift(>=5.0) + func testOptionalFetchAllWithInterpolation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + let request: SQLRequest = "SELECT \(42)" + let array = try request.fetchAll(db) + XCTAssertEqual(array[0]!.int, 42) + XCTAssert(array[0]!.fast) + } + } + #endif + func testOptionalFetchAllStepFailure() throws { let dbQueue = try makeDatabaseQueue() let customError = NSError(domain: "Custom", code: 0xDEAD) @@ -534,18 +594,18 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT throw()" - try test(Optional.fetchAll(db, sql), sql: sql) - try test(Optional.fetchAll(db.makeSelectStatement(sql)), sql: sql) - try test(Optional.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchAll(db), sql: sql) + try test(Optional.fetchAll(db, sql: sql), sql: sql) + try test(Optional.fetchAll(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Optional.fetchAll(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchAll(db), sql: sql) } do { let sql = "SELECT 0, throw()" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Optional.fetchAll(db, sql, adapter: adapter), sql: sql) - try test(Optional.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Optional.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchAll(db), sql: sql) + try test(Optional.fetchAll(db, sql: sql, adapter: adapter), sql: sql) + try test(Optional.fetchAll(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Optional.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db), sql: sql) } } } @@ -566,18 +626,18 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { } do { let sql = "SELECT * FROM nonExistingTable" - try test(Optional.fetchAll(db, sql), sql: sql) - try test(Optional.fetchAll(db.makeSelectStatement(sql)), sql: sql) - try test(Optional.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetchAll(db), sql: sql) + try test(Optional.fetchAll(db, sql: sql), sql: sql) + try test(Optional.fetchAll(db.makeSelectStatement(sql: sql)), sql: sql) + try test(Optional.fetchAll(db, SQLRequest(sql: sql)), sql: sql) + try test(SQLRequest(sql: sql).fetchAll(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" let adapter = SuffixRowAdapter(fromIndex: 1) - try test(Optional.fetchAll(db, sql, adapter: adapter), sql: sql) - try test(Optional.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) - try test(Optional.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetchAll(db), sql: sql) + try test(Optional.fetchAll(db, sql: sql, adapter: adapter), sql: sql) + try test(Optional.fetchAll(db.makeSelectStatement(sql: sql), adapter: adapter), sql: sql) + try test(Optional.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db), sql: sql) } } } diff --git a/Tests/GRDBTests/TableDefinitionTests.swift b/Tests/GRDBTests/TableDefinitionTests.swift index b85dda3f1..04334217d 100644 --- a/Tests/GRDBTests/TableDefinitionTests.swift +++ b/Tests/GRDBTests/TableDefinitionTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -196,9 +194,9 @@ class TableDefinitionTests: GRDBTestCase { ")") as String) // Sanity check - try db.execute("INSERT INTO test (a, b, c) VALUES (1, 0, 1)") + try db.execute(sql: "INSERT INTO test (a, b, c) VALUES (1, 0, 1)") do { - try db.execute("INSERT INTO test (a, b, c) VALUES (0, 0, 1)") + try db.execute(sql: "INSERT INTO test (a, b, c) VALUES (0, 0, 1)") XCTFail() } catch { } @@ -226,9 +224,9 @@ class TableDefinitionTests: GRDBTestCase { ")") as String) // Sanity check - try db.execute("INSERT INTO test DEFAULT VALUES") - XCTAssertEqual(try Int.fetchOne(db, "SELECT a FROM test")!, 1) - XCTAssertEqual(try String.fetchOne(db, "SELECT c FROM test")!, "'fooéı👨👨🏿🇫🇷🇨🇮'") + try db.execute(sql: "INSERT INTO test DEFAULT VALUES") + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT a FROM test")!, 1) + XCTAssertEqual(try String.fetchOne(db, sql: "SELECT c FROM test")!, "'fooéı👨👨🏿🇫🇷🇨🇮'") } } @@ -390,9 +388,9 @@ class TableDefinitionTests: GRDBTestCase { ")") as String) // Sanity check - try db.execute("INSERT INTO test (a, b) VALUES (1, 0)") + try db.execute(sql: "INSERT INTO test (a, b) VALUES (1, 0)") do { - try db.execute("INSERT INTO test (a, b) VALUES (5, 5)") + try db.execute(sql: "INSERT INTO test (a, b) VALUES (5, 5)") XCTFail() } catch { } diff --git a/Tests/GRDBTests/TableRecord+QueryInterfaceRequestTests.swift b/Tests/GRDBTests/TableRecord+QueryInterfaceRequestTests.swift index 52bee069f..601db4412 100644 --- a/Tests/GRDBTests/TableRecord+QueryInterfaceRequestTests.swift +++ b/Tests/GRDBTests/TableRecord+QueryInterfaceRequestTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -24,7 +22,7 @@ class TableRecordQueryInterfaceRequestTests: GRDBTestCase { override func setup(_ dbWriter: DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("createReaders") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE readers ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, @@ -87,8 +85,8 @@ class TableRecordQueryInterfaceRequestTests: GRDBTestCase { func testSelectLiteral() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) let request = Reader.select(sql: "name, id - 1") let rows = try Row.fetchAll(db, request) @@ -104,8 +102,8 @@ class TableRecordQueryInterfaceRequestTests: GRDBTestCase { func testSelectLiteralWithPositionalArguments() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) let request = Reader.select(sql: "name, id - ?", arguments: [1]) let rows = try Row.fetchAll(db, request) @@ -121,8 +119,8 @@ class TableRecordQueryInterfaceRequestTests: GRDBTestCase { func testSelectLiteralWithNamedArguments() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) let request = Reader.select(sql: "name, id - :n", arguments: ["n": 1]) let rows = try Row.fetchAll(db, request) @@ -134,12 +132,34 @@ class TableRecordQueryInterfaceRequestTests: GRDBTestCase { XCTAssertEqual(rows[1][1] as Int64, 1) } } - + + func testSelectSQLLiteral() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) + + func test(_ request: QueryInterfaceRequest) throws { + let rows = try Row.fetchAll(db, request) + XCTAssertEqual(rows.count, 2) + XCTAssertEqual(rows[0][0] as String, "O'Brien") + XCTAssertEqual(rows[0][1] as Int64, 0) + XCTAssertEqual(rows[1][0] as String, "O'Brien") + XCTAssertEqual(rows[1][1] as Int64, 1) + } + try test(Reader.select(literal: SQLLiteral(sql: ":name, id - :value", arguments: ["name": "O'Brien", "value": 1]))) + #if swift(>=5) + // Interpolation + try test(Reader.select(literal: "\("O'Brien"), id - \(1)")) + #endif + } + } + func testSelect() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) - try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42]) + try db.execute(sql: "INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36]) let request = Reader.select(Col.name, Col.id - 1) let rows = try Row.fetchAll(db, request) diff --git a/Tests/GRDBTests/TableRecordTests.swift b/Tests/GRDBTests/TableRecordTests.swift index e33b18046..760034fac 100644 --- a/Tests/GRDBTests/TableRecordTests.swift +++ b/Tests/GRDBTests/TableRecordTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -102,7 +100,7 @@ class TableRecordTests: GRDBTestCase { } let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE t1(a,b,c)") + try db.execute(sql: "CREATE TABLE t1(a,b,c)") _ = try Row.fetchAll(db, Record.all()) XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"t1\"") } @@ -115,7 +113,7 @@ class TableRecordTests: GRDBTestCase { } let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE t1(a,b,c)") + try db.execute(sql: "CREATE TABLE t1(a,b,c)") _ = try Row.fetchAll(db, Record.all()) XCTAssertEqual(lastSQLQuery, "SELECT *, \"rowid\" FROM \"t1\"") } @@ -128,7 +126,7 @@ class TableRecordTests: GRDBTestCase { } let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE t1(a,b,c)") + try db.execute(sql: "CREATE TABLE t1(a,b,c)") _ = try Row.fetchAll(db, Record.all()) XCTAssertEqual(lastSQLQuery, "SELECT \"a\", \"b\" FROM \"t1\"") } diff --git a/Tests/GRDBTests/TransactionObserverSavepointsTests.swift b/Tests/GRDBTests/TransactionObserverSavepointsTests.swift index 66cfdd935..c2ac13edd 100644 --- a/Tests/GRDBTests/TransactionObserverSavepointsTests.swift +++ b/Tests/GRDBTests/TransactionObserverSavepointsTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -81,19 +79,19 @@ class TransactionObserverSavepointsTests: GRDBTestCase { dbQueue.add(transactionObserver: observer) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE items1 (id INTEGER PRIMARY KEY)") - try db.execute("CREATE TABLE items2 (id INTEGER PRIMARY KEY)") - try db.execute("SAVEPOINT sp1") + try db.execute(sql: "CREATE TABLE items1 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items2 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "SAVEPOINT sp1") XCTAssertTrue(db.isInsideTransaction) - try db.execute("INSERT INTO items1 (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items1 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 0) - try db.execute("INSERT INTO items2 (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items2 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 0) - try db.execute("RELEASE SAVEPOINT sp1") + try db.execute(sql: "RELEASE SAVEPOINT sp1") XCTAssertFalse(db.isInsideTransaction) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items1"), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items2"), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items1"), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items2"), 1) } XCTAssertEqual(observer.lastCommittedEvents.count, 2) @@ -113,18 +111,18 @@ class TransactionObserverSavepointsTests: GRDBTestCase { dbQueue.add(transactionObserver: observer) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE items1 (id INTEGER PRIMARY KEY)") - try db.execute("CREATE TABLE items2 (id INTEGER PRIMARY KEY)") - try db.execute("BEGIN TRANSACTION") - try db.execute("INSERT INTO items1 (id) VALUES (NULL)") + try db.execute(sql: "CREATE TABLE items1 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items2 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "BEGIN TRANSACTION") + try db.execute(sql: "INSERT INTO items1 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 1) - try db.execute("SAVEPOINT sp1") - try db.execute("INSERT INTO items2 (id) VALUES (NULL)") + try db.execute(sql: "SAVEPOINT sp1") + try db.execute(sql: "INSERT INTO items2 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 1) - try db.execute("COMMIT") + try db.execute(sql: "COMMIT") - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items1"), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items2"), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items1"), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items2"), 1) } XCTAssertEqual(observer.lastCommittedEvents.count, 2) @@ -144,31 +142,31 @@ class TransactionObserverSavepointsTests: GRDBTestCase { dbQueue.add(transactionObserver: observer) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE items1 (id INTEGER PRIMARY KEY)") - try db.execute("CREATE TABLE items2 (id INTEGER PRIMARY KEY)") - try db.execute("CREATE TABLE items3 (id INTEGER PRIMARY KEY)") - try db.execute("CREATE TABLE items4 (id INTEGER PRIMARY KEY)") - try db.execute("BEGIN TRANSACTION") - try db.execute("INSERT INTO items1 (id) VALUES (NULL)") + try db.execute(sql: "CREATE TABLE items1 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items2 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items3 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items4 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "BEGIN TRANSACTION") + try db.execute(sql: "INSERT INTO items1 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 1) - try db.execute("SAVEPOINT sp1") - try db.execute("INSERT INTO items2 (id) VALUES (NULL)") + try db.execute(sql: "SAVEPOINT sp1") + try db.execute(sql: "INSERT INTO items2 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 1) - try db.execute("SAVEPOINT sp1") - try db.execute("INSERT INTO items3 (id) VALUES (NULL)") + try db.execute(sql: "SAVEPOINT sp1") + try db.execute(sql: "INSERT INTO items3 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 1) - try db.execute("RELEASE SAVEPOINT sp1") + try db.execute(sql: "RELEASE SAVEPOINT sp1") XCTAssertEqual(observer.events.count, 1) - try db.execute("RELEASE SAVEPOINT sp1") + try db.execute(sql: "RELEASE SAVEPOINT sp1") XCTAssertEqual(observer.events.count, 3) - try db.execute("INSERT INTO items4 (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items4 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 4) - try db.execute("COMMIT") + try db.execute(sql: "COMMIT") - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items1"), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items2"), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items3"), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items4"), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items1"), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items2"), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items3"), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items4"), 1) } XCTAssertEqual(observer.lastCommittedEvents.count, 4) @@ -192,30 +190,30 @@ class TransactionObserverSavepointsTests: GRDBTestCase { dbQueue.add(transactionObserver: observer) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE items1 (id INTEGER PRIMARY KEY)") - try db.execute("CREATE TABLE items2 (id INTEGER PRIMARY KEY)") - try db.execute("CREATE TABLE items3 (id INTEGER PRIMARY KEY)") - try db.execute("CREATE TABLE items4 (id INTEGER PRIMARY KEY)") - try db.execute("BEGIN TRANSACTION") - try db.execute("INSERT INTO items1 (id) VALUES (NULL)") + try db.execute(sql: "CREATE TABLE items1 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items2 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items3 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items4 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "BEGIN TRANSACTION") + try db.execute(sql: "INSERT INTO items1 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 1) - try db.execute("SAVEPOINT sp1") - try db.execute("INSERT INTO items2 (id) VALUES (NULL)") + try db.execute(sql: "SAVEPOINT sp1") + try db.execute(sql: "INSERT INTO items2 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 1) - try db.execute("INSERT INTO items3 (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items3 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 1) - try db.execute("ROLLBACK TO SAVEPOINT sp1") - try db.execute("INSERT INTO items4 (id) VALUES (NULL)") + try db.execute(sql: "ROLLBACK TO SAVEPOINT sp1") + try db.execute(sql: "INSERT INTO items4 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 1) - try db.execute("ROLLBACK TO SAVEPOINT sp1") - try db.execute("INSERT INTO items4 (id) VALUES (NULL)") + try db.execute(sql: "ROLLBACK TO SAVEPOINT sp1") + try db.execute(sql: "INSERT INTO items4 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 1) - try db.execute("COMMIT") + try db.execute(sql: "COMMIT") - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items1"), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items2"), 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items3"), 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items4"), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items1"), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items2"), 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items3"), 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items4"), 1) } XCTAssertEqual(observer.lastCommittedEvents.count, 2) @@ -235,27 +233,27 @@ class TransactionObserverSavepointsTests: GRDBTestCase { dbQueue.add(transactionObserver: observer) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE items1 (id INTEGER PRIMARY KEY)") - try db.execute("CREATE TABLE items2 (id INTEGER PRIMARY KEY)") - try db.execute("CREATE TABLE items3 (id INTEGER PRIMARY KEY)") - try db.execute("CREATE TABLE items4 (id INTEGER PRIMARY KEY)") - try db.execute("BEGIN TRANSACTION") - try db.execute("INSERT INTO items1 (id) VALUES (NULL)") + try db.execute(sql: "CREATE TABLE items1 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items2 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items3 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items4 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "BEGIN TRANSACTION") + try db.execute(sql: "INSERT INTO items1 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 1) - try db.execute("SAVEPOINT sp1") - try db.execute("INSERT INTO items2 (id) VALUES (NULL)") - try db.execute("INSERT INTO items3 (id) VALUES (NULL)") + try db.execute(sql: "SAVEPOINT sp1") + try db.execute(sql: "INSERT INTO items2 (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items3 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 1) - try db.execute("RELEASE SAVEPOINT sp1") + try db.execute(sql: "RELEASE SAVEPOINT sp1") XCTAssertEqual(observer.events.count, 3) - try db.execute("INSERT INTO items4 (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items4 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 4) - try db.execute("COMMIT") + try db.execute(sql: "COMMIT") - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items1"), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items2"), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items3"), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items4"), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items1"), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items2"), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items3"), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items4"), 1) } XCTAssertEqual(observer.lastCommittedEvents.count, 4) @@ -279,31 +277,31 @@ class TransactionObserverSavepointsTests: GRDBTestCase { dbQueue.add(transactionObserver: observer) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE items1 (id INTEGER PRIMARY KEY)") - try db.execute("CREATE TABLE items2 (id INTEGER PRIMARY KEY)") - try db.execute("CREATE TABLE items3 (id INTEGER PRIMARY KEY)") - try db.execute("CREATE TABLE items4 (id INTEGER PRIMARY KEY)") - try db.execute("BEGIN TRANSACTION") - try db.execute("INSERT INTO items1 (id) VALUES (NULL)") + try db.execute(sql: "CREATE TABLE items1 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items2 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items3 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "CREATE TABLE items4 (id INTEGER PRIMARY KEY)") + try db.execute(sql: "BEGIN TRANSACTION") + try db.execute(sql: "INSERT INTO items1 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 1) - try db.execute("SAVEPOINT sp1") - try db.execute("INSERT INTO items2 (id) VALUES (NULL)") + try db.execute(sql: "SAVEPOINT sp1") + try db.execute(sql: "INSERT INTO items2 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 1) - try db.execute("SAVEPOINT sp2") - try db.execute("INSERT INTO items3 (id) VALUES (NULL)") + try db.execute(sql: "SAVEPOINT sp2") + try db.execute(sql: "INSERT INTO items3 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 1) - try db.execute("RELEASE SAVEPOINT sp2") + try db.execute(sql: "RELEASE SAVEPOINT sp2") XCTAssertEqual(observer.events.count, 1) - try db.execute("ROLLBACK TO SAVEPOINT sp1") + try db.execute(sql: "ROLLBACK TO SAVEPOINT sp1") XCTAssertEqual(observer.events.count, 1) - try db.execute("INSERT INTO items4 (id) VALUES (NULL)") + try db.execute(sql: "INSERT INTO items4 (id) VALUES (NULL)") XCTAssertEqual(observer.events.count, 1) - try db.execute("COMMIT") + try db.execute(sql: "COMMIT") - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items1"), 1) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items2"), 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items3"), 0) - XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM items4"), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items1"), 1) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items2"), 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items3"), 0) + XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items4"), 1) } XCTAssertEqual(observer.lastCommittedEvents.count, 2) diff --git a/Tests/GRDBTests/TransactionObserverTests.swift b/Tests/GRDBTests/TransactionObserverTests.swift index 2631b1bc4..079683086 100644 --- a/Tests/GRDBTests/TransactionObserverTests.swift +++ b/Tests/GRDBTests/TransactionObserverTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -129,7 +127,7 @@ extension Artwork : FetchableRecord, PersistableRecord { class TransactionObserverTests: GRDBTestCase { private func setupArtistDatabase(in dbWriter: DatabaseWriter) throws { try dbWriter.write { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE artists ( id INTEGER PRIMARY KEY, name TEXT); @@ -225,8 +223,8 @@ class TransactionObserverTests: GRDBTestCase { let observer = Observer() dbQueue.add(transactionObserver: observer, extent: extent) try dbQueue.writeWithoutTransaction { db in - try db.execute(startSQL) - try db.execute(endSQL) + try db.execute(sql: startSQL) + try db.execute(sql: endSQL) } switch expectedCompletion { case .commit: @@ -247,9 +245,9 @@ class TransactionObserverTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() let observer = Observer() try dbQueue.writeWithoutTransaction { db in - try db.execute(startSQL) + try db.execute(sql: startSQL) db.add(transactionObserver: observer, extent: extent) - try db.execute(endSQL) + try db.execute(sql: endSQL) } switch expectedCompletion { case .commit: @@ -272,8 +270,8 @@ class TransactionObserverTests: GRDBTestCase { weakObserver = observer dbQueue.add(transactionObserver: observer) try dbQueue.writeWithoutTransaction { db in - try db.execute(startSQL) - try db.execute(endSQL) + try db.execute(sql: startSQL) + try db.execute(sql: endSQL) } switch expectedCompletion { case .commit: @@ -286,7 +284,7 @@ class TransactionObserverTests: GRDBTestCase { XCTAssertEqual(observer.didRollbackCount, 1, "\(startSQL); \(endSQL)") } try dbQueue.inTransaction { db in - try db.execute("DROP TABLE IF EXISTS t; CREATE TABLE t(a)") + try db.execute(sql: "DROP TABLE IF EXISTS t; CREATE TABLE t(a)") return .commit } switch expectedCompletion { @@ -311,8 +309,8 @@ class TransactionObserverTests: GRDBTestCase { weakObserver = observer dbQueue.add(transactionObserver: observer, extent: .observerLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute(startSQL) - try db.execute(endSQL) + try db.execute(sql: startSQL) + try db.execute(sql: endSQL) } switch expectedCompletion { case .commit: @@ -325,7 +323,7 @@ class TransactionObserverTests: GRDBTestCase { XCTAssertEqual(observer.didRollbackCount, 1, "\(startSQL); \(endSQL)") } try dbQueue.inTransaction { db in - try db.execute("DROP TABLE IF EXISTS t; CREATE TABLE t(a)") + try db.execute(sql: "DROP TABLE IF EXISTS t; CREATE TABLE t(a)") return .commit } switch expectedCompletion { @@ -352,8 +350,8 @@ class TransactionObserverTests: GRDBTestCase { } if let observer = weakObserver { try dbQueue.writeWithoutTransaction { db in - try db.execute(startSQL) - try db.execute(endSQL) + try db.execute(sql: startSQL) + try db.execute(sql: endSQL) } switch expectedCompletion { case .commit: @@ -377,8 +375,8 @@ class TransactionObserverTests: GRDBTestCase { dbQueue.add(transactionObserver: observer, extent: .nextTransaction) try dbQueue.writeWithoutTransaction { db in - try db.execute(startSQL) - try db.execute(endSQL) + try db.execute(sql: startSQL) + try db.execute(sql: endSQL) } switch expectedCompletion { case .commit: @@ -391,7 +389,7 @@ class TransactionObserverTests: GRDBTestCase { XCTAssertEqual(observer.didRollbackCount, 1, "\(startSQL); \(endSQL)") } try dbQueue.inTransaction { db in - try db.execute("DROP TABLE IF EXISTS t; CREATE TABLE t(a)") + try db.execute(sql: "DROP TABLE IF EXISTS t; CREATE TABLE t(a)") return .commit } switch expectedCompletion { @@ -411,7 +409,7 @@ class TransactionObserverTests: GRDBTestCase { let witness = Observer() let observer = Observer(didCommitBlock: { db in try! db.inTransaction { - try db.execute("DROP TABLE IF EXISTS t; CREATE TABLE t(a)") + try db.execute(sql: "DROP TABLE IF EXISTS t; CREATE TABLE t(a)") return .commit } }) @@ -419,8 +417,8 @@ class TransactionObserverTests: GRDBTestCase { dbQueue.add(transactionObserver: observer, extent: .nextTransaction) try dbQueue.writeWithoutTransaction { db in - try db.execute(startSQL) - try db.execute(endSQL) + try db.execute(sql: startSQL) + try db.execute(sql: endSQL) } switch expectedCompletion { case .commit: @@ -440,7 +438,7 @@ class TransactionObserverTests: GRDBTestCase { } try dbQueue.inTransaction { db in - try db.execute("DROP TABLE IF EXISTS t; CREATE TABLE t(a)") + try db.execute(sql: "DROP TABLE IF EXISTS t; CREATE TABLE t(a)") return .commit } switch expectedCompletion { @@ -485,8 +483,8 @@ class TransactionObserverTests: GRDBTestCase { if let observer = weakObserver { try dbQueue.writeWithoutTransaction { db in - try db.execute(startSQL) - try db.execute(endSQL) + try db.execute(sql: startSQL) + try db.execute(sql: endSQL) } switch expectedCompletion { case .commit: @@ -504,7 +502,7 @@ class TransactionObserverTests: GRDBTestCase { if let observer = weakObserver { try dbQueue.inTransaction { db in - try db.execute("DROP TABLE IF EXISTS t; CREATE TABLE t(a)") + try db.execute(sql: "DROP TABLE IF EXISTS t; CREATE TABLE t(a)") return .commit } switch expectedCompletion { @@ -547,8 +545,8 @@ class TransactionObserverTests: GRDBTestCase { do { try dbQueue.writeWithoutTransaction { db in - try db.execute(startSQL) - try db.execute(endSQL) + try db.execute(sql: startSQL) + try db.execute(sql: endSQL) } switch expectedCompletion { case .commit: @@ -1574,7 +1572,7 @@ class TransactionObserverTests: GRDBTestCase { // Delete from a and trigger b deletion try dbQueue.inTransaction { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE a(id INTEGER PRIMARY KEY); CREATE TABLE b(id INTEGER PRIMARY KEY REFERENCES a(id) ON DELETE CASCADE); INSERT INTO a (id) VALUES (42); @@ -1606,7 +1604,7 @@ class TransactionObserverTests: GRDBTestCase { // Insert into c and trigger b deletion try dbQueue.inTransaction { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE a(id INTEGER PRIMARY KEY); CREATE TABLE b(id INTEGER PRIMARY KEY); CREATE TABLE c(id INTEGER); @@ -1695,8 +1693,8 @@ class TransactionObserverTests: GRDBTestCase { do { observer.resetCounts() try db.inTransaction { - try db.execute("INSERT INTO persons (name) VALUES ('a')") - try db.execute("DELETE FROM persons") + try db.execute(sql: "INSERT INTO persons (name) VALUES ('a')") + try db.execute(sql: "DELETE FROM persons") return .commit } @@ -1713,9 +1711,9 @@ class TransactionObserverTests: GRDBTestCase { do { observer.resetCounts() try db.inTransaction { - try db.execute("INSERT INTO ignore DEFAULT VALUES") - try db.execute("INSERT INTO persons (name) VALUES ('a')") - try db.execute("DELETE FROM persons") + try db.execute(sql: "INSERT INTO ignore DEFAULT VALUES") + try db.execute(sql: "INSERT INTO persons (name) VALUES ('a')") + try db.execute(sql: "DELETE FROM persons") return .commit } @@ -1732,9 +1730,9 @@ class TransactionObserverTests: GRDBTestCase { do { observer.resetCounts() try db.inTransaction { - try db.execute("INSERT INTO persons (name) VALUES ('a')") - try db.execute("INSERT INTO ignore DEFAULT VALUES") - try db.execute("DELETE FROM persons") + try db.execute(sql: "INSERT INTO persons (name) VALUES ('a')") + try db.execute(sql: "INSERT INTO ignore DEFAULT VALUES") + try db.execute(sql: "DELETE FROM persons") return .commit } @@ -1751,9 +1749,9 @@ class TransactionObserverTests: GRDBTestCase { do { observer.resetCounts() try db.inTransaction { - try db.execute("INSERT INTO persons (name) VALUES ('a')") - try db.execute("DELETE FROM persons") - try db.execute("INSERT INTO ignore DEFAULT VALUES") + try db.execute(sql: "INSERT INTO persons (name) VALUES ('a')") + try db.execute(sql: "DELETE FROM persons") + try db.execute(sql: "INSERT INTO ignore DEFAULT VALUES") return .commit } diff --git a/Tests/GRDBTests/TruncateOptimizationTests.swift b/Tests/GRDBTests/TruncateOptimizationTests.swift index 7617539f0..8bc94adf0 100644 --- a/Tests/GRDBTests/TruncateOptimizationTests.swift +++ b/Tests/GRDBTests/TruncateOptimizationTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -76,18 +74,18 @@ class TruncateOptimizationTests: GRDBTestCase { dbQueue.add(transactionObserver: observer, extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") + try db.execute(sql: "CREATE TABLE t(a)") - try db.execute("INSERT INTO t VALUES (NULL)") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") deletionEvents = [] - try db.execute("DELETE FROM t") + try db.execute(sql: "DELETE FROM t") XCTAssertEqual(deletionEvents.count, 1) XCTAssertEqual(deletionEvents[0], ["t": 2]) - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") deletionEvents = [] - try db.execute("DELETE FROM t") + try db.execute(sql: "DELETE FROM t") XCTAssertEqual(deletionEvents.count, 1) XCTAssertEqual(deletionEvents[0], ["t": 1]) } @@ -101,17 +99,17 @@ class TruncateOptimizationTests: GRDBTestCase { dbQueue.add(transactionObserver: observer, extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - let deleteStatement = try db.makeUpdateStatement("DELETE FROM t") + try db.execute(sql: "CREATE TABLE t(a)") + let deleteStatement = try db.makeUpdateStatement(sql: "DELETE FROM t") - try db.execute("INSERT INTO t VALUES (NULL)") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") deletionEvents = [] try deleteStatement.execute() XCTAssertEqual(deletionEvents.count, 1) XCTAssertEqual(deletionEvents[0], ["t": 2]) - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") deletionEvents = [] try deleteStatement.execute() XCTAssertEqual(deletionEvents.count, 1) @@ -122,10 +120,10 @@ class TruncateOptimizationTests: GRDBTestCase { func testDropTable() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.tableExists("t")) - try db.execute("DROP TABLE t") // compile + execute + try db.execute(sql: "DROP TABLE t") // compile + execute try XCTAssertFalse(db.tableExists("t")) } } @@ -134,10 +132,10 @@ class TruncateOptimizationTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() dbQueue.add(transactionObserver: UniversalObserver(), extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.tableExists("t")) - try db.execute("DROP TABLE t") // compile + execute + try db.execute(sql: "DROP TABLE t") // compile + execute try XCTAssertFalse(db.tableExists("t")) } } @@ -145,10 +143,10 @@ class TruncateOptimizationTests: GRDBTestCase { func testDropTableWithPreparedStatement() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.tableExists("t")) - let dropStatement = try db.makeUpdateStatement("DROP TABLE t") // compile... + let dropStatement = try db.makeUpdateStatement(sql: "DROP TABLE t") // compile... try dropStatement.execute() // ... then execute try XCTAssertFalse(db.tableExists("t")) } @@ -158,10 +156,10 @@ class TruncateOptimizationTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() dbQueue.add(transactionObserver: UniversalObserver(), extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.tableExists("t")) - let dropStatement = try db.makeUpdateStatement("DROP TABLE t") // compile... + let dropStatement = try db.makeUpdateStatement(sql: "DROP TABLE t") // compile... try dropStatement.execute() // ... then execute try XCTAssertFalse(db.tableExists("t")) } @@ -170,10 +168,10 @@ class TruncateOptimizationTests: GRDBTestCase { func testDropTemporaryTable() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TEMPORARY TABLE t(a)") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE TEMPORARY TABLE t(a)") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.tableExists("t")) - try db.execute("DROP TABLE t") // compile + execute + try db.execute(sql: "DROP TABLE t") // compile + execute try XCTAssertFalse(db.tableExists("t")) } } @@ -182,10 +180,10 @@ class TruncateOptimizationTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() dbQueue.add(transactionObserver: UniversalObserver(), extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TEMPORARY TABLE t(a)") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE TEMPORARY TABLE t(a)") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.tableExists("t")) - try db.execute("DROP TABLE t") // compile + execute + try db.execute(sql: "DROP TABLE t") // compile + execute try XCTAssertFalse(db.tableExists("t")) } } @@ -193,10 +191,10 @@ class TruncateOptimizationTests: GRDBTestCase { func testDropTemporaryTableWithPreparedStatement() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TEMPORARY TABLE t(a)") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE TEMPORARY TABLE t(a)") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.tableExists("t")) - let dropStatement = try db.makeUpdateStatement("DROP TABLE t") // compile... + let dropStatement = try db.makeUpdateStatement(sql: "DROP TABLE t") // compile... try dropStatement.execute() // ... then execute try XCTAssertFalse(db.tableExists("t")) } @@ -206,10 +204,10 @@ class TruncateOptimizationTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() dbQueue.add(transactionObserver: UniversalObserver(), extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TEMPORARY TABLE t(a)") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE TEMPORARY TABLE t(a)") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.tableExists("t")) - let dropStatement = try db.makeUpdateStatement("DROP TABLE t") // compile... + let dropStatement = try db.makeUpdateStatement(sql: "DROP TABLE t") // compile... try dropStatement.execute() // ... then execute try XCTAssertFalse(db.tableExists("t")) } @@ -218,10 +216,10 @@ class TruncateOptimizationTests: GRDBTestCase { func testDropVirtualTable() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE VIRTUAL TABLE t USING fts3(a)") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE VIRTUAL TABLE t USING fts3(a)") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.tableExists("t")) - try db.execute("DROP TABLE t") // compile + execute + try db.execute(sql: "DROP TABLE t") // compile + execute try XCTAssertFalse(db.tableExists("t")) } } @@ -230,10 +228,10 @@ class TruncateOptimizationTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() dbQueue.add(transactionObserver: UniversalObserver(), extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE VIRTUAL TABLE t USING fts3(a)") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE VIRTUAL TABLE t USING fts3(a)") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.tableExists("t")) - try db.execute("DROP TABLE t") // compile + execute + try db.execute(sql: "DROP TABLE t") // compile + execute try XCTAssertFalse(db.tableExists("t")) } } @@ -241,10 +239,10 @@ class TruncateOptimizationTests: GRDBTestCase { func testDropVirtualTableWithPreparedStatement() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE VIRTUAL TABLE t USING fts3(a)") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE VIRTUAL TABLE t USING fts3(a)") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.tableExists("t")) - let dropStatement = try db.makeUpdateStatement("DROP TABLE t") // compile... + let dropStatement = try db.makeUpdateStatement(sql: "DROP TABLE t") // compile... try dropStatement.execute() // ... then execute try XCTAssertFalse(db.tableExists("t")) } @@ -254,10 +252,10 @@ class TruncateOptimizationTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() dbQueue.add(transactionObserver: UniversalObserver(), extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE VIRTUAL TABLE t USING fts3(a)") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE VIRTUAL TABLE t USING fts3(a)") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.tableExists("t")) - let dropStatement = try db.makeUpdateStatement("DROP TABLE t") // compile... + let dropStatement = try db.makeUpdateStatement(sql: "DROP TABLE t") // compile... try dropStatement.execute() // ... then execute try XCTAssertFalse(db.tableExists("t")) } @@ -266,11 +264,11 @@ class TruncateOptimizationTests: GRDBTestCase { func testDropView() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE VIEW v AS SELECT * FROM t") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE VIEW v AS SELECT * FROM t") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.viewExists("v")) - try db.execute("DROP VIEW v") // compile + execute + try db.execute(sql: "DROP VIEW v") // compile + execute try XCTAssertFalse(db.viewExists("v")) } } @@ -279,11 +277,11 @@ class TruncateOptimizationTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() dbQueue.add(transactionObserver: UniversalObserver(), extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE VIEW v AS SELECT * FROM t") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE VIEW v AS SELECT * FROM t") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.viewExists("v")) - try db.execute("DROP VIEW v") // compile + execute + try db.execute(sql: "DROP VIEW v") // compile + execute try XCTAssertFalse(db.viewExists("v")) } } @@ -291,11 +289,11 @@ class TruncateOptimizationTests: GRDBTestCase { func testDropViewWithPreparedStatement() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE VIEW v AS SELECT * FROM t") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE VIEW v AS SELECT * FROM t") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.viewExists("v")) - let dropStatement = try db.makeUpdateStatement("DROP VIEW v") // compile... + let dropStatement = try db.makeUpdateStatement(sql: "DROP VIEW v") // compile... try dropStatement.execute() // ... then execute try XCTAssertFalse(db.viewExists("v")) } @@ -305,11 +303,11 @@ class TruncateOptimizationTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() dbQueue.add(transactionObserver: UniversalObserver(), extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE VIEW v AS SELECT * FROM t") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE VIEW v AS SELECT * FROM t") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.viewExists("v")) - let dropStatement = try db.makeUpdateStatement("DROP VIEW v") // compile... + let dropStatement = try db.makeUpdateStatement(sql: "DROP VIEW v") // compile... try dropStatement.execute() // ... then execute try XCTAssertFalse(db.viewExists("v")) } @@ -318,11 +316,11 @@ class TruncateOptimizationTests: GRDBTestCase { func testDropTemporaryView() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE TEMPORARY VIEW v AS SELECT * FROM t") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE TEMPORARY VIEW v AS SELECT * FROM t") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.viewExists("v")) - try db.execute("DROP VIEW v") // compile + execute + try db.execute(sql: "DROP VIEW v") // compile + execute try XCTAssertFalse(db.viewExists("v")) } } @@ -331,11 +329,11 @@ class TruncateOptimizationTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() dbQueue.add(transactionObserver: UniversalObserver(), extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE TEMPORARY VIEW v AS SELECT * FROM t") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE TEMPORARY VIEW v AS SELECT * FROM t") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.viewExists("v")) - try db.execute("DROP VIEW v") // compile + execute + try db.execute(sql: "DROP VIEW v") // compile + execute try XCTAssertFalse(db.viewExists("v")) } } @@ -343,11 +341,11 @@ class TruncateOptimizationTests: GRDBTestCase { func testDropTemporaryViewWithPreparedStatement() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE TEMPORARY VIEW v AS SELECT * FROM t") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE TEMPORARY VIEW v AS SELECT * FROM t") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.viewExists("v")) - let dropStatement = try db.makeUpdateStatement("DROP VIEW v") // compile... + let dropStatement = try db.makeUpdateStatement(sql: "DROP VIEW v") // compile... try dropStatement.execute() // ... then execute try XCTAssertFalse(db.viewExists("v")) } @@ -357,11 +355,11 @@ class TruncateOptimizationTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() dbQueue.add(transactionObserver: UniversalObserver(), extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE TEMPORARY VIEW v AS SELECT * FROM t") - try db.execute("INSERT INTO t VALUES (NULL)") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE TEMPORARY VIEW v AS SELECT * FROM t") + try db.execute(sql: "INSERT INTO t VALUES (NULL)") try XCTAssertTrue(db.viewExists("v")) - let dropStatement = try db.makeUpdateStatement("DROP VIEW v") // compile... + let dropStatement = try db.makeUpdateStatement(sql: "DROP VIEW v") // compile... try dropStatement.execute() // ... then execute try XCTAssertFalse(db.viewExists("v")) } @@ -370,10 +368,10 @@ class TruncateOptimizationTests: GRDBTestCase { func testDropIndex() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE INDEX i ON t(a)") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE INDEX i ON t(a)") try XCTAssertFalse(db.indexes(on: "t").isEmpty) - try db.execute("DROP INDEX i") // compile + execute + try db.execute(sql: "DROP INDEX i") // compile + execute try XCTAssertTrue(db.indexes(on: "t").isEmpty) } } @@ -382,10 +380,10 @@ class TruncateOptimizationTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() dbQueue.add(transactionObserver: UniversalObserver(), extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE INDEX i ON t(a)") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE INDEX i ON t(a)") try XCTAssertFalse(db.indexes(on: "t").isEmpty) - try db.execute("DROP INDEX i") // compile + execute + try db.execute(sql: "DROP INDEX i") // compile + execute try XCTAssertTrue(db.indexes(on: "t").isEmpty) } } @@ -393,11 +391,11 @@ class TruncateOptimizationTests: GRDBTestCase { func testDropIndexViewWithPreparedStatement() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE INDEX i ON t(a)") - try db.execute("INSERT INTO t VALUES (1)") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE INDEX i ON t(a)") + try db.execute(sql: "INSERT INTO t VALUES (1)") try XCTAssertFalse(db.indexes(on: "t").isEmpty) - let dropStatement = try db.makeUpdateStatement("DROP INDEX i") // compile... + let dropStatement = try db.makeUpdateStatement(sql: "DROP INDEX i") // compile... try dropStatement.execute() // ... then execute try XCTAssertTrue(db.indexes(on: "t").isEmpty) } @@ -407,11 +405,11 @@ class TruncateOptimizationTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() dbQueue.add(transactionObserver: UniversalObserver(), extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE INDEX i ON t(a)") - try db.execute("INSERT INTO t VALUES (1)") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE INDEX i ON t(a)") + try db.execute(sql: "INSERT INTO t VALUES (1)") try XCTAssertFalse(db.indexes(on: "t").isEmpty) - let dropStatement = try db.makeUpdateStatement("DROP INDEX i") // compile... + let dropStatement = try db.makeUpdateStatement(sql: "DROP INDEX i") // compile... try dropStatement.execute() // ... then execute try XCTAssertTrue(db.indexes(on: "t").isEmpty) } @@ -420,10 +418,10 @@ class TruncateOptimizationTests: GRDBTestCase { func testDropTemporaryIndex() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TEMPORARY TABLE t(a)") - try db.execute("CREATE INDEX i ON t(a)") + try db.execute(sql: "CREATE TEMPORARY TABLE t(a)") + try db.execute(sql: "CREATE INDEX i ON t(a)") try XCTAssertFalse(db.indexes(on: "t").isEmpty) - try db.execute("DROP INDEX i") // compile + execute + try db.execute(sql: "DROP INDEX i") // compile + execute try XCTAssertTrue(db.indexes(on: "t").isEmpty) } } @@ -432,10 +430,10 @@ class TruncateOptimizationTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() dbQueue.add(transactionObserver: UniversalObserver(), extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TEMPORARY TABLE t(a)") - try db.execute("CREATE INDEX i ON t(a)") + try db.execute(sql: "CREATE TEMPORARY TABLE t(a)") + try db.execute(sql: "CREATE INDEX i ON t(a)") try XCTAssertFalse(db.indexes(on: "t").isEmpty) - try db.execute("DROP INDEX i") // compile + execute + try db.execute(sql: "DROP INDEX i") // compile + execute try XCTAssertTrue(db.indexes(on: "t").isEmpty) } } @@ -443,11 +441,11 @@ class TruncateOptimizationTests: GRDBTestCase { func testDropTemporaryIndexViewWithPreparedStatement() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TEMPORARY TABLE t(a)") - try db.execute("CREATE INDEX i ON t(a)") - try db.execute("INSERT INTO t VALUES (1)") + try db.execute(sql: "CREATE TEMPORARY TABLE t(a)") + try db.execute(sql: "CREATE INDEX i ON t(a)") + try db.execute(sql: "INSERT INTO t VALUES (1)") try XCTAssertFalse(db.indexes(on: "t").isEmpty) - let dropStatement = try db.makeUpdateStatement("DROP INDEX i") // compile... + let dropStatement = try db.makeUpdateStatement(sql: "DROP INDEX i") // compile... try dropStatement.execute() // ... then execute try XCTAssertTrue(db.indexes(on: "t").isEmpty) } @@ -457,11 +455,11 @@ class TruncateOptimizationTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() dbQueue.add(transactionObserver: UniversalObserver(), extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TEMPORARY TABLE t(a)") - try db.execute("CREATE INDEX i ON t(a)") - try db.execute("INSERT INTO t VALUES (1)") + try db.execute(sql: "CREATE TEMPORARY TABLE t(a)") + try db.execute(sql: "CREATE INDEX i ON t(a)") + try db.execute(sql: "INSERT INTO t VALUES (1)") try XCTAssertFalse(db.indexes(on: "t").isEmpty) - let dropStatement = try db.makeUpdateStatement("DROP INDEX i") // compile... + let dropStatement = try db.makeUpdateStatement(sql: "DROP INDEX i") // compile... try dropStatement.execute() // ... then execute try XCTAssertTrue(db.indexes(on: "t").isEmpty) } @@ -470,10 +468,10 @@ class TruncateOptimizationTests: GRDBTestCase { func testDropTrigger() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE TRIGGER r INSERT ON t BEGIN DELETE FROM t; END") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE TRIGGER r INSERT ON t BEGIN DELETE FROM t; END") try XCTAssertTrue(db.triggerExists("r")) - try db.execute("DROP TRIGGER r") // compile + execute + try db.execute(sql: "DROP TRIGGER r") // compile + execute try XCTAssertFalse(db.triggerExists("r")) } } @@ -482,10 +480,10 @@ class TruncateOptimizationTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() dbQueue.add(transactionObserver: UniversalObserver(), extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE TRIGGER r INSERT ON t BEGIN DELETE FROM t; END") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE TRIGGER r INSERT ON t BEGIN DELETE FROM t; END") try XCTAssertTrue(db.triggerExists("r")) - try db.execute("DROP TRIGGER r") // compile + execute + try db.execute(sql: "DROP TRIGGER r") // compile + execute try XCTAssertFalse(db.triggerExists("r")) } } @@ -493,10 +491,10 @@ class TruncateOptimizationTests: GRDBTestCase { func testDropTriggerWithPreparedStatement() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE TRIGGER r INSERT ON t BEGIN DELETE FROM t; END") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE TRIGGER r INSERT ON t BEGIN DELETE FROM t; END") try XCTAssertTrue(db.triggerExists("r")) - let dropStatement = try db.makeUpdateStatement("DROP TRIGGER r") // compile... + let dropStatement = try db.makeUpdateStatement(sql: "DROP TRIGGER r") // compile... try dropStatement.execute() // ... then execute try XCTAssertFalse(db.triggerExists("r")) } @@ -506,10 +504,10 @@ class TruncateOptimizationTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() dbQueue.add(transactionObserver: UniversalObserver(), extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE TRIGGER r INSERT ON t BEGIN DELETE FROM t; END") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE TRIGGER r INSERT ON t BEGIN DELETE FROM t; END") try XCTAssertTrue(db.triggerExists("r")) - let dropStatement = try db.makeUpdateStatement("DROP TRIGGER r") // compile... + let dropStatement = try db.makeUpdateStatement(sql: "DROP TRIGGER r") // compile... try dropStatement.execute() // ... then execute try XCTAssertFalse(db.triggerExists("r")) } @@ -518,10 +516,10 @@ class TruncateOptimizationTests: GRDBTestCase { func testDropTemporaryTrigger() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE TEMPORARY TRIGGER r INSERT ON t BEGIN DELETE FROM t; END") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE TEMPORARY TRIGGER r INSERT ON t BEGIN DELETE FROM t; END") try XCTAssertTrue(db.triggerExists("r")) - try db.execute("DROP TRIGGER r") // compile + execute + try db.execute(sql: "DROP TRIGGER r") // compile + execute try XCTAssertFalse(db.triggerExists("r")) } } @@ -530,10 +528,10 @@ class TruncateOptimizationTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() dbQueue.add(transactionObserver: UniversalObserver(), extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE TEMPORARY TRIGGER r INSERT ON t BEGIN DELETE FROM t; END") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE TEMPORARY TRIGGER r INSERT ON t BEGIN DELETE FROM t; END") try XCTAssertTrue(db.triggerExists("r")) - try db.execute("DROP TRIGGER r") // compile + execute + try db.execute(sql: "DROP TRIGGER r") // compile + execute try XCTAssertFalse(db.triggerExists("r")) } } @@ -541,10 +539,10 @@ class TruncateOptimizationTests: GRDBTestCase { func testDropTemporaryTriggerWithPreparedStatement() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE TEMPORARY TRIGGER r INSERT ON t BEGIN DELETE FROM t; END") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE TEMPORARY TRIGGER r INSERT ON t BEGIN DELETE FROM t; END") try XCTAssertTrue(db.triggerExists("r")) - let dropStatement = try db.makeUpdateStatement("DROP TRIGGER r") // compile... + let dropStatement = try db.makeUpdateStatement(sql: "DROP TRIGGER r") // compile... try dropStatement.execute() // ... then execute try XCTAssertFalse(db.triggerExists("r")) } @@ -554,10 +552,10 @@ class TruncateOptimizationTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() dbQueue.add(transactionObserver: UniversalObserver(), extent: .databaseLifetime) try dbQueue.writeWithoutTransaction { db in - try db.execute("CREATE TABLE t(a)") - try db.execute("CREATE TEMPORARY TRIGGER r INSERT ON t BEGIN DELETE FROM t; END") + try db.execute(sql: "CREATE TABLE t(a)") + try db.execute(sql: "CREATE TEMPORARY TRIGGER r INSERT ON t BEGIN DELETE FROM t; END") try XCTAssertTrue(db.triggerExists("r")) - let dropStatement = try db.makeUpdateStatement("DROP TRIGGER r") // compile... + let dropStatement = try db.makeUpdateStatement(sql: "DROP TRIGGER r") // compile... try dropStatement.execute() // ... then execute try XCTAssertFalse(db.triggerExists("r")) } diff --git a/Tests/GRDBTests/UpdateStatementTests.swift b/Tests/GRDBTests/UpdateStatementTests.swift index 661f48311..c2eecb056 100644 --- a/Tests/GRDBTests/UpdateStatementTests.swift +++ b/Tests/GRDBTests/UpdateStatementTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB @@ -12,7 +10,7 @@ class UpdateStatementTests : GRDBTestCase { override func setup(_ dbWriter: DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("createPersons") { db in - try db.execute(""" + try db.execute(sql: """ CREATE TABLE persons ( id INTEGER PRIMARY KEY, creationDate TEXT, @@ -26,14 +24,14 @@ class UpdateStatementTests : GRDBTestCase { func testTrailingSemicolonAndWhiteSpaceIsAcceptedAndOptional() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inTransaction { db in - try db.makeUpdateStatement("INSERT INTO persons (name) VALUES ('Arthur');").execute() - try db.makeUpdateStatement("INSERT INTO persons (name) VALUES ('Barbara')\n \t").execute() - try db.makeUpdateStatement("INSERT INTO persons (name) VALUES ('Craig'); ; ;").execute() - try db.makeUpdateStatement("INSERT INTO persons (name) VALUES ('Daniel');\n \t").execute() + try db.makeUpdateStatement(sql: "INSERT INTO persons (name) VALUES ('Arthur');").execute() + try db.makeUpdateStatement(sql: "INSERT INTO persons (name) VALUES ('Barbara')\n \t").execute() + try db.makeUpdateStatement(sql: "INSERT INTO persons (name) VALUES ('Craig'); ; ;").execute() + try db.makeUpdateStatement(sql: "INSERT INTO persons (name) VALUES ('Daniel');\n \t").execute() return .commit } try dbQueue.inDatabase { db in - let names = try String.fetchAll(db, "SELECT name FROM persons ORDER BY name") + let names = try String.fetchAll(db, sql: "SELECT name FROM persons ORDER BY name") XCTAssertEqual(names, ["Arthur", "Barbara", "Craig", "Daniel"]) } } @@ -41,8 +39,8 @@ class UpdateStatementTests : GRDBTestCase { func testStatementSQL() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try XCTAssertEqual(db.makeUpdateStatement("INSERT INTO persons (name, age) VALUES ('Arthur', ?)").sql, "INSERT INTO persons (name, age) VALUES ('Arthur', ?)") - try XCTAssertEqual(db.makeUpdateStatement(" INSERT INTO persons (name, age) VALUES ('Arthur', ?) ; ").sql, "INSERT INTO persons (name, age) VALUES ('Arthur', ?)") + try XCTAssertEqual(db.makeUpdateStatement(sql: "INSERT INTO persons (name, age) VALUES ('Arthur', ?)").sql, "INSERT INTO persons (name, age) VALUES ('Arthur', ?)") + try XCTAssertEqual(db.makeUpdateStatement(sql: " INSERT INTO persons (name, age) VALUES ('Arthur', ?) ; ").sql, "INSERT INTO persons (name, age) VALUES ('Arthur', ?)") } } @@ -51,7 +49,7 @@ class UpdateStatementTests : GRDBTestCase { try dbQueue.inTransaction { db in - let statement = try db.makeUpdateStatement("INSERT INTO persons (name, age) VALUES (?, ?)") + let statement = try db.makeUpdateStatement(sql: "INSERT INTO persons (name, age) VALUES (?, ?)") let persons: [[DatabaseValueConvertible?]] = [ ["Arthur", 41], ["Barbara", nil], @@ -64,7 +62,7 @@ class UpdateStatementTests : GRDBTestCase { } try dbQueue.inDatabase { db in - let rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY name") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY name") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["name"] as String, "Arthur") XCTAssertEqual(rows[0]["age"] as Int, 41) @@ -78,7 +76,7 @@ class UpdateStatementTests : GRDBTestCase { try dbQueue.inTransaction { db in - let statement = try db.makeUpdateStatement("INSERT INTO persons (name, age) VALUES (?, ?)") + let statement = try db.makeUpdateStatement(sql: "INSERT INTO persons (name, age) VALUES (?, ?)") let persons: [[DatabaseValueConvertible?]] = [ ["Arthur", 41], ["Barbara", nil], @@ -92,7 +90,7 @@ class UpdateStatementTests : GRDBTestCase { } try dbQueue.inDatabase { db in - let rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY name") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY name") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["name"] as String, "Arthur") XCTAssertEqual(rows[0]["age"] as Int, 41) @@ -106,7 +104,7 @@ class UpdateStatementTests : GRDBTestCase { try dbQueue.inTransaction { db in - let statement = try db.makeUpdateStatement("INSERT INTO persons (name, age) VALUES (:name, :age)") + let statement = try db.makeUpdateStatement(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)") let persons: [[String: DatabaseValueConvertible?]] = [ ["name": "Arthur", "age": 41], ["name": "Barbara", "age": nil], @@ -119,7 +117,7 @@ class UpdateStatementTests : GRDBTestCase { } try dbQueue.inDatabase { db in - let rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY name") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY name") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["name"] as String, "Arthur") XCTAssertEqual(rows[0]["age"] as Int, 41) @@ -133,7 +131,7 @@ class UpdateStatementTests : GRDBTestCase { try dbQueue.inTransaction { db in - let statement = try db.makeUpdateStatement("INSERT INTO persons (name, age) VALUES (:name, :age)") + let statement = try db.makeUpdateStatement(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)") let persons: [[String: DatabaseValueConvertible?]] = [ ["name": "Arthur", "age": 41], ["name": "Barbara", "age": nil], @@ -147,7 +145,7 @@ class UpdateStatementTests : GRDBTestCase { } try dbQueue.inDatabase { db in - let rows = try Row.fetchAll(db, "SELECT * FROM persons ORDER BY name") + let rows = try Row.fetchAll(db, sql: "SELECT * FROM persons ORDER BY name") XCTAssertEqual(rows.count, 2) XCTAssertEqual(rows[0]["name"] as String, "Arthur") XCTAssertEqual(rows[0]["age"] as Int, 41) @@ -161,8 +159,8 @@ class UpdateStatementTests : GRDBTestCase { // https://github.com/groue/GRDB.swift/issues/15 let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("SELECT 1") - let statement = try db.makeUpdateStatement("SELECT 1") + try db.execute(sql: "SELECT 1") + let statement = try db.makeUpdateStatement(sql: "SELECT 1") try statement.execute() } } @@ -175,8 +173,8 @@ class UpdateStatementTests : GRDBTestCase { return index }) try dbQueue.inDatabase { db in - try db.execute("SELECT seq() UNION ALL SELECT seq() UNION ALL SELECT seq()") - let statement = try db.makeUpdateStatement("SELECT seq() UNION ALL SELECT seq() UNION ALL SELECT seq()") + try db.execute(sql: "SELECT seq() UNION ALL SELECT seq() UNION ALL SELECT seq()") + let statement = try db.makeUpdateStatement(sql: "SELECT seq() UNION ALL SELECT seq() UNION ALL SELECT seq()") try statement.execute() } XCTAssertEqual(index, 3 + 3) @@ -185,20 +183,20 @@ class UpdateStatementTests : GRDBTestCase { func testExecuteNothing() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("") - try db.execute(" ") - try db.execute(";") - try db.execute(";;") - try db.execute(" \n;\t; ") - try db.execute("-- comment") - try db.execute("-- comment\\n; -----ignored") + try db.execute(sql: "") + try db.execute(sql: " ") + try db.execute(sql: ";") + try db.execute(sql: ";;") + try db.execute(sql: " \n;\t; ") + try db.execute(sql: "-- comment") + try db.execute(sql: "-- comment\\n; -----ignored") } } func testExecuteMultipleStatement() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE wines (name TEXT, color INT); CREATE TABLE books (name TEXT, age INT)") + try db.execute(sql: "CREATE TABLE wines (name TEXT, color INT); CREATE TABLE books (name TEXT, age INT)") XCTAssertTrue(try db.tableExists("wines")) XCTAssertTrue(try db.tableExists("books")) } @@ -207,7 +205,7 @@ class UpdateStatementTests : GRDBTestCase { func testExecuteMultipleStatementWithTrailingWhiteSpace() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE wines (name TEXT, color INT); CREATE TABLE books (name TEXT, age INT)\n \t") + try db.execute(sql: "CREATE TABLE wines (name TEXT, color INT); CREATE TABLE books (name TEXT, age INT)\n \t") XCTAssertTrue(try db.tableExists("wines")) XCTAssertTrue(try db.tableExists("books")) } @@ -216,7 +214,7 @@ class UpdateStatementTests : GRDBTestCase { func testExecuteMultipleStatementWithTrailingSemicolonAndWhiteSpace() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute("CREATE TABLE wines (name TEXT, color INT); CREATE TABLE books (name TEXT, age INT);\n \t") + try db.execute(sql: "CREATE TABLE wines (name TEXT, color INT); CREATE TABLE books (name TEXT, age INT);\n \t") XCTAssertTrue(try db.tableExists("wines")) XCTAssertTrue(try db.tableExists("books")) } @@ -225,7 +223,7 @@ class UpdateStatementTests : GRDBTestCase { func testExecuteMultipleStatementWithPlentyOfSemicolonsAndWhiteSpaceAndComments() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in - try db.execute(""" + try db.execute(sql: """ ;; CREATE TABLE wines ( -- create a table name TEXT, -- the name @@ -243,20 +241,20 @@ class UpdateStatementTests : GRDBTestCase { func testExecuteMultipleStatementWithNamedArguments() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inTransaction { db in - try db.execute(""" + try db.execute(sql: """ INSERT INTO persons (name, age) VALUES ('Arthur', :age1); INSERT INTO persons (name, age) VALUES ('Arthur', :age2); """, arguments: ["age1": 41, "age2": 32]) - XCTAssertEqual(try Int.fetchAll(db, "SELECT age FROM persons ORDER BY age"), [32, 41]) + XCTAssertEqual(try Int.fetchAll(db, sql: "SELECT age FROM persons ORDER BY age"), [32, 41]) return .rollback } try dbQueue.inTransaction { db in - try db.execute(""" + try db.execute(sql: """ INSERT INTO persons (name, age) VALUES ('Arthur', :age1); INSERT INTO persons (name, age) VALUES ('Arthur', :age2); """, arguments: [41, 32]) - XCTAssertEqual(try Int.fetchAll(db, "SELECT age FROM persons ORDER BY age"), [32, 41]) + XCTAssertEqual(try Int.fetchAll(db, sql: "SELECT age FROM persons ORDER BY age"), [32, 41]) return .rollback } } @@ -264,20 +262,20 @@ class UpdateStatementTests : GRDBTestCase { func testExecuteMultipleStatementWithReusedNamedArguments() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inTransaction { db in - try db.execute(""" + try db.execute(sql: """ INSERT INTO persons (name, age) VALUES ('Arthur', :age); INSERT INTO persons (name, age) VALUES ('Arthur', :age); """, arguments: ["age": 41]) - XCTAssertEqual(try Int.fetchAll(db, "SELECT age FROM persons"), [41, 41]) + XCTAssertEqual(try Int.fetchAll(db, sql: "SELECT age FROM persons"), [41, 41]) return .rollback } try dbQueue.inTransaction { db in - try db.execute(""" + try db.execute(sql: """ INSERT INTO persons (name, age) VALUES ('Arthur', :age); INSERT INTO persons (name, age) VALUES ('Arthur', :age); """, arguments: ["age": 41]) - XCTAssertEqual(try Int.fetchAll(db, "SELECT age FROM persons"), [41, 41]) + XCTAssertEqual(try Int.fetchAll(db, sql: "SELECT age FROM persons"), [41, 41]) return .rollback } } @@ -285,11 +283,29 @@ class UpdateStatementTests : GRDBTestCase { func testExecuteMultipleStatementWithPositionalArguments() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inTransaction { db in - try db.execute(""" + try db.execute(sql: """ INSERT INTO persons (name, age) VALUES ('Arthur', ?); INSERT INTO persons (name, age) VALUES ('Arthur', ?); """, arguments: [41, 32]) - XCTAssertEqual(try Int.fetchAll(db, "SELECT age FROM persons ORDER BY age"), [32, 41]) + XCTAssertEqual(try Int.fetchAll(db, sql: "SELECT age FROM persons ORDER BY age"), [32, 41]) + return .rollback + } + } + + func testExecuteMultipleStatementWithTooManyArguments() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.inTransaction { db in + do { + try db.execute(sql: """ + INSERT INTO persons (name, age) VALUES ('Arthur', ?); + INSERT INTO persons (name, age) VALUES ('Arthur', ?); + """, arguments: [41, 32, 666]) + XCTFail() + } catch let error as DatabaseError { + XCTAssertEqual(error.resultCode, .SQLITE_MISUSE) + XCTAssertEqual(error.message!, "wrong number of statement arguments: 3") + XCTAssertEqual(error.description, "SQLite error 21: wrong number of statement arguments: 3") + } return .rollback } } @@ -298,7 +314,7 @@ class UpdateStatementTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in do { - _ = try db.makeUpdateStatement("UPDATE blah SET id = 12") + _ = try db.makeUpdateStatement(sql: "UPDATE blah SET id = 12") XCTFail() } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) @@ -313,13 +329,13 @@ class UpdateStatementTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in do { - _ = try db.makeUpdateStatement("UPDATE persons SET age = 1; UPDATE persons SET age = 2;") + _ = try db.makeUpdateStatement(sql: "UPDATE persons SET age = 1; UPDATE persons SET age = 2;") XCTFail("Expected error") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_MISUSE) - XCTAssertEqual(error.message!, "Multiple statements found. To execute multiple statements, use Database.execute() instead.") + XCTAssertEqual(error.message!, "Multiple statements found. To execute multiple statements, use Database.execute(sql:) instead.") XCTAssertEqual(error.sql!, "UPDATE persons SET age = 1; UPDATE persons SET age = 2;") - XCTAssertEqual(error.description, "SQLite error 21 with statement `UPDATE persons SET age = 1; UPDATE persons SET age = 2;`: Multiple statements found. To execute multiple statements, use Database.execute() instead.") + XCTAssertEqual(error.description, "SQLite error 21 with statement `UPDATE persons SET age = 1; UPDATE persons SET age = 2;`: Multiple statements found. To execute multiple statements, use Database.execute(sql:) instead.") } } } @@ -328,14 +344,42 @@ class UpdateStatementTests : GRDBTestCase { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in do { - _ = try db.makeUpdateStatement("UPDATE persons SET age = 1;x") + _ = try db.makeUpdateStatement(sql: "UPDATE persons SET age = 1;x") XCTFail("Expected error") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_MISUSE) - XCTAssertEqual(error.message!, "Multiple statements found. To execute multiple statements, use Database.execute() instead.") + XCTAssertEqual(error.message!, "Multiple statements found. To execute multiple statements, use Database.execute(sql:) instead.") XCTAssertEqual(error.sql!, "UPDATE persons SET age = 1;x") - XCTAssertEqual(error.description, "SQLite error 21 with statement `UPDATE persons SET age = 1;x`: Multiple statements found. To execute multiple statements, use Database.execute() instead.") + XCTAssertEqual(error.description, "SQLite error 21 with statement `UPDATE persons SET age = 1;x`: Multiple statements found. To execute multiple statements, use Database.execute(sql:) instead.") } } } + + func testExecuteSQLLiteral() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.execute(literal: SQLLiteral(sql: """ + CREATE TABLE t(a); + INSERT INTO t(a) VALUES (?); + INSERT INTO t(a) VALUES (?); + """, arguments: [1, 2])) + let value = try Int.fetchOne(db, sql: "SELECT SUM(a) FROM t") + XCTAssertEqual(value, 3) + } + } + + #if swift(>=5.0) + func testExecuteSQLLiteralWithInterpolation() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.execute(literal: """ + CREATE TABLE t(a); + INSERT INTO t(a) VALUES (\(1)); + INSERT INTO t(a) VALUES (\(2)); + """) + let value = try Int.fetchOne(db, sql: "SELECT SUM(a) FROM t") + XCTAssertEqual(value, 3) + } + } + #endif } diff --git a/Tests/GRDBTests/ValueObservationCombineTests.swift b/Tests/GRDBTests/ValueObservationCombineTests.swift index 32b89c860..c3237a3f5 100644 --- a/Tests/GRDBTests/ValueObservationCombineTests.swift +++ b/Tests/GRDBTests/ValueObservationCombineTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else #if SWIFT_PACKAGE @@ -16,7 +14,7 @@ class ValueObservationCombineTests: GRDBTestCase { func testCombine2() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.write { - try $0.execute(""" + try $0.execute(sql: """ CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT); CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT); """) @@ -31,49 +29,49 @@ class ValueObservationCombineTests: GRDBTestCase { struct T2: TableRecord { } let observation1 = ValueObservation.trackingCount(T1.all()) let observation2 = ValueObservation.trackingCount(T2.all()) - var observation = ValueObservation.combine(observation1, observation2) - observation.extent = .databaseLifetime - _ = try observation.start(in: dbQueue) { value in + let observation = ValueObservation.combine(observation1, observation2) + let observer = try observation.start(in: dbQueue) { value in values.append(value) notificationExpectation.fulfill() } - - try dbQueue.write { db in - try db.execute("INSERT INTO t1 DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbQueue.write { db in + try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "DELETE FROM t1") + try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "DELETE FROM t2") + try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "DELETE FROM t1") + try db.execute(sql: "DELETE FROM t2") + try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") + } + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(values.count, 4) + XCTAssert(values[0] == (0, 0)) + XCTAssert(values[1] == (1, 0)) + XCTAssert(values[2] == (1, 1)) + XCTAssert(values[3] == (2, 2)) } - try dbQueue.write { db in - try db.execute("INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("DELETE FROM t1") - try db.execute("INSERT INTO t1 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("DELETE FROM t2") - try db.execute("INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("DELETE FROM t1") - try db.execute("DELETE FROM t2") - try db.execute("INSERT INTO t1 DEFAULT VALUES") - try db.execute("INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("INSERT INTO t1 DEFAULT VALUES") - try db.execute("INSERT INTO t2 DEFAULT VALUES") - } - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(values.count, 4) - XCTAssert(values[0] == (0, 0)) - XCTAssert(values[1] == (1, 0)) - XCTAssert(values[2] == (1, 1)) - XCTAssert(values[3] == (2, 2)) } func testCombine3() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.write { - try $0.execute(""" + try $0.execute(sql: """ CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT); CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT); CREATE TABLE t3(id INTEGER PRIMARY KEY AUTOINCREMENT); @@ -91,60 +89,60 @@ class ValueObservationCombineTests: GRDBTestCase { let observation1 = ValueObservation.trackingCount(T1.all()) let observation2 = ValueObservation.trackingCount(T2.all()) let observation3 = ValueObservation.trackingCount(T3.all()) - var observation = ValueObservation.combine(observation1, observation2, observation3) - observation.extent = .databaseLifetime - _ = try observation.start(in: dbQueue) { value in + let observation = ValueObservation.combine(observation1, observation2, observation3) + let observer = try observation.start(in: dbQueue) { value in values.append(value) notificationExpectation.fulfill() } - - try dbQueue.write { db in - try db.execute("INSERT INTO t1 DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbQueue.write { db in + try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "DELETE FROM t1") + try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "DELETE FROM t2") + try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "DELETE FROM t3") + try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "DELETE FROM t1") + try db.execute(sql: "DELETE FROM t2") + try db.execute(sql: "DELETE FROM t3") + try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") + } + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(values.count, 5) + XCTAssert(values[0] == (0, 0, 0)) + XCTAssert(values[1] == (1, 0, 0)) + XCTAssert(values[2] == (1, 1, 0)) + XCTAssert(values[3] == (1, 1, 1)) + XCTAssert(values[4] == (2, 2, 2)) } - try dbQueue.write { db in - try db.execute("INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("DELETE FROM t1") - try db.execute("INSERT INTO t1 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("DELETE FROM t2") - try db.execute("INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("DELETE FROM t3") - try db.execute("INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("DELETE FROM t1") - try db.execute("DELETE FROM t2") - try db.execute("DELETE FROM t3") - try db.execute("INSERT INTO t1 DEFAULT VALUES") - try db.execute("INSERT INTO t2 DEFAULT VALUES") - try db.execute("INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("INSERT INTO t1 DEFAULT VALUES") - try db.execute("INSERT INTO t2 DEFAULT VALUES") - try db.execute("INSERT INTO t3 DEFAULT VALUES") - } - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(values.count, 5) - XCTAssert(values[0] == (0, 0, 0)) - XCTAssert(values[1] == (1, 0, 0)) - XCTAssert(values[2] == (1, 1, 0)) - XCTAssert(values[3] == (1, 1, 1)) - XCTAssert(values[4] == (2, 2, 2)) } func testCombine4() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.write { - try $0.execute(""" + try $0.execute(sql: """ CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT); CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT); CREATE TABLE t3(id INTEGER PRIMARY KEY AUTOINCREMENT); @@ -165,71 +163,71 @@ class ValueObservationCombineTests: GRDBTestCase { let observation2 = ValueObservation.trackingCount(T2.all()) let observation3 = ValueObservation.trackingCount(T3.all()) let observation4 = ValueObservation.trackingCount(T4.all()) - var observation = ValueObservation.combine(observation1, observation2, observation3, observation4) - observation.extent = .databaseLifetime - _ = try observation.start(in: dbQueue) { value in + let observation = ValueObservation.combine(observation1, observation2, observation3, observation4) + let observer = try observation.start(in: dbQueue) { value in values.append(value) notificationExpectation.fulfill() } - - try dbQueue.write { db in - try db.execute("INSERT INTO t1 DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbQueue.write { db in + try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "DELETE FROM t1") + try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "DELETE FROM t2") + try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "DELETE FROM t3") + try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "DELETE FROM t4") + try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "DELETE FROM t1") + try db.execute(sql: "DELETE FROM t2") + try db.execute(sql: "DELETE FROM t3") + try db.execute(sql: "DELETE FROM t4") + try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") + } + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(values.count, 6) + XCTAssert(values[0] == (0, 0, 0, 0)) + XCTAssert(values[1] == (1, 0, 0, 0)) + XCTAssert(values[2] == (1, 1, 0, 0)) + XCTAssert(values[3] == (1, 1, 1, 0)) + XCTAssert(values[4] == (1, 1, 1, 1)) + XCTAssert(values[5] == (2, 2, 2, 2)) } - try dbQueue.write { db in - try db.execute("INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("INSERT INTO t4 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("DELETE FROM t1") - try db.execute("INSERT INTO t1 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("DELETE FROM t2") - try db.execute("INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("DELETE FROM t3") - try db.execute("INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("DELETE FROM t4") - try db.execute("INSERT INTO t4 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("DELETE FROM t1") - try db.execute("DELETE FROM t2") - try db.execute("DELETE FROM t3") - try db.execute("DELETE FROM t4") - try db.execute("INSERT INTO t1 DEFAULT VALUES") - try db.execute("INSERT INTO t2 DEFAULT VALUES") - try db.execute("INSERT INTO t3 DEFAULT VALUES") - try db.execute("INSERT INTO t4 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("INSERT INTO t1 DEFAULT VALUES") - try db.execute("INSERT INTO t2 DEFAULT VALUES") - try db.execute("INSERT INTO t3 DEFAULT VALUES") - try db.execute("INSERT INTO t4 DEFAULT VALUES") - } - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(values.count, 6) - XCTAssert(values[0] == (0, 0, 0, 0)) - XCTAssert(values[1] == (1, 0, 0, 0)) - XCTAssert(values[2] == (1, 1, 0, 0)) - XCTAssert(values[3] == (1, 1, 1, 0)) - XCTAssert(values[4] == (1, 1, 1, 1)) - XCTAssert(values[5] == (2, 2, 2, 2)) } func testCombine5() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.write { - try $0.execute(""" + try $0.execute(sql: """ CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT); CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT); CREATE TABLE t3(id INTEGER PRIMARY KEY AUTOINCREMENT); @@ -253,76 +251,76 @@ class ValueObservationCombineTests: GRDBTestCase { let observation3 = ValueObservation.trackingCount(T3.all()) let observation4 = ValueObservation.trackingCount(T4.all()) let observation5 = ValueObservation.trackingCount(T5.all()) - var observation = ValueObservation.combine(observation1, observation2, observation3, observation4, observation5) - observation.extent = .databaseLifetime - _ = try observation.start(in: dbQueue) { value in + let observation = ValueObservation.combine(observation1, observation2, observation3, observation4, observation5) + let observer = try observation.start(in: dbQueue) { value in values.append(value) notificationExpectation.fulfill() } - - try dbQueue.write { db in - try db.execute("INSERT INTO t1 DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbQueue.write { db in + try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "DELETE FROM t1") + try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "DELETE FROM t2") + try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "DELETE FROM t3") + try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "DELETE FROM t4") + try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "DELETE FROM t5") + try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "DELETE FROM t1") + try db.execute(sql: "DELETE FROM t2") + try db.execute(sql: "DELETE FROM t3") + try db.execute(sql: "DELETE FROM t4") + try db.execute(sql: "DELETE FROM t5") + try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") + } + try dbQueue.write { db in + try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") + } + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(values.count, 7) + XCTAssert(values[0] == (0, 0, 0, 0, 0)) + XCTAssert(values[1] == (1, 0, 0, 0, 0)) + XCTAssert(values[2] == (1, 1, 0, 0, 0)) + XCTAssert(values[3] == (1, 1, 1, 0, 0)) + XCTAssert(values[4] == (1, 1, 1, 1, 0)) + XCTAssert(values[5] == (1, 1, 1, 1, 1)) + XCTAssert(values[6] == (2, 2, 2, 2, 2)) } - try dbQueue.write { db in - try db.execute("INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("INSERT INTO t4 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("INSERT INTO t5 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("DELETE FROM t1") - try db.execute("INSERT INTO t1 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("DELETE FROM t2") - try db.execute("INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("DELETE FROM t3") - try db.execute("INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("DELETE FROM t4") - try db.execute("INSERT INTO t4 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("DELETE FROM t5") - try db.execute("INSERT INTO t5 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("DELETE FROM t1") - try db.execute("DELETE FROM t2") - try db.execute("DELETE FROM t3") - try db.execute("DELETE FROM t4") - try db.execute("DELETE FROM t5") - try db.execute("INSERT INTO t1 DEFAULT VALUES") - try db.execute("INSERT INTO t2 DEFAULT VALUES") - try db.execute("INSERT INTO t3 DEFAULT VALUES") - try db.execute("INSERT INTO t4 DEFAULT VALUES") - try db.execute("INSERT INTO t5 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute("INSERT INTO t1 DEFAULT VALUES") - try db.execute("INSERT INTO t2 DEFAULT VALUES") - try db.execute("INSERT INTO t3 DEFAULT VALUES") - try db.execute("INSERT INTO t4 DEFAULT VALUES") - try db.execute("INSERT INTO t5 DEFAULT VALUES") - } - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(values.count, 7) - XCTAssert(values[0] == (0, 0, 0, 0, 0)) - XCTAssert(values[1] == (1, 0, 0, 0, 0)) - XCTAssert(values[2] == (1, 1, 0, 0, 0)) - XCTAssert(values[3] == (1, 1, 1, 0, 0)) - XCTAssert(values[4] == (1, 1, 1, 1, 0)) - XCTAssert(values[5] == (1, 1, 1, 1, 1)) - XCTAssert(values[6] == (2, 2, 2, 2, 2)) } func testHeterogeneusCombine2() throws { diff --git a/Tests/GRDBTests/ValueObservationCompactMapTests.swift b/Tests/GRDBTests/ValueObservationCompactMapTests.swift index 5d3d91f94..fc5da1ae0 100644 --- a/Tests/GRDBTests/ValueObservationCompactMapTests.swift +++ b/Tests/GRDBTests/ValueObservationCompactMapTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else #if SWIFT_PACKAGE @@ -16,7 +14,7 @@ class ValueObservationCompactMapTests: GRDBTestCase { func testCompactMap() throws { func test(_ dbWriter: DatabaseWriter) throws { // We need something to change - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } var counts: [String] = [] let notificationExpectation = expectation(description: "notification") @@ -33,27 +31,27 @@ class ValueObservationCompactMapTests: GRDBTestCase { }) // Create an observation - var observation = ValueObservation + let observation = ValueObservation .tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer }) .compactMap { count -> String? in if count % 2 == 0 { return nil } return "\(count)" } - observation.extent = .databaseLifetime // Start observation - _ = try observation.start(in: dbWriter) { count in + let observer = try observation.start(in: dbWriter) { count in counts.append(count) notificationExpectation.fulfill() } - - try dbWriter.writeWithoutTransaction { db in - try db.execute("INSERT INTO t DEFAULT VALUES") - try db.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbWriter.writeWithoutTransaction { db in + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(counts, ["1", "3"]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, ["1", "3"]) } try test(makeDatabaseQueue()) @@ -62,12 +60,10 @@ class ValueObservationCompactMapTests: GRDBTestCase { func testCompactMapPreservesConfiguration() { var observation = ValueObservation.tracking(DatabaseRegion(), fetch: { _ in }) - observation.extent = .nextTransaction observation.requiresWriteAccess = true observation.scheduling = .unsafe(startImmediately: true) let mappedObservation = observation.compactMap { _ in } - XCTAssertEqual(mappedObservation.extent, observation.extent) XCTAssertEqual(mappedObservation.requiresWriteAccess, observation.requiresWriteAccess) switch mappedObservation.scheduling { case .unsafe: diff --git a/Tests/GRDBTests/ValueObservationCountTests.swift b/Tests/GRDBTests/ValueObservationCountTests.swift index 70a9f7eca..6b45ca1a3 100644 --- a/Tests/GRDBTests/ValueObservationCountTests.swift +++ b/Tests/GRDBTests/ValueObservationCountTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else #if SWIFT_PACKAGE @@ -15,7 +13,7 @@ import XCTest class ValueObservationCountTests: GRDBTestCase { func testCount() throws { let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } var counts: [Int] = [] let notificationExpectation = expectation(description: "notification") @@ -23,27 +21,27 @@ class ValueObservationCountTests: GRDBTestCase { notificationExpectation.expectedFulfillmentCount = 5 struct T: TableRecord { } - var observation = ValueObservation.trackingCount(T.all()) - observation.extent = .databaseLifetime - _ = try observation.start(in: dbQueue) { count in + let observation = ValueObservation.trackingCount(T.all()) + let observer = try observation.start(in: dbQueue) { count in counts.append(count) notificationExpectation.fulfill() } - - try dbQueue.inDatabase { db in - try db.execute("INSERT INTO t DEFAULT VALUES") // +1 - try db.execute("UPDATE t SET id = id") // = - try db.execute("INSERT INTO t DEFAULT VALUES") // +1 - try db.inTransaction { // +1 - try db.execute("INSERT INTO t DEFAULT VALUES") - try db.execute("INSERT INTO t DEFAULT VALUES") - try db.execute("DELETE FROM t WHERE id = 1") - return .commit + try withExtendedLifetime(observer) { + try dbQueue.inDatabase { db in + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") // +1 + try db.execute(sql: "UPDATE t SET id = id") // = + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") // +1 + try db.inTransaction { // +1 + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "DELETE FROM t WHERE id = 1") + return .commit + } + try db.execute(sql: "DELETE FROM t WHERE id = 2") // -1 } - try db.execute("DELETE FROM t WHERE id = 2") // -1 + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(counts, [0, 1, 2, 3, 2]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, [0, 1, 2, 3, 2]) } } diff --git a/Tests/GRDBTests/ValueObservationDatabaseValueConvertibleTests.swift b/Tests/GRDBTests/ValueObservationDatabaseValueConvertibleTests.swift index bc996d858..e9aeed8f2 100644 --- a/Tests/GRDBTests/ValueObservationDatabaseValueConvertibleTests.swift +++ b/Tests/GRDBTests/ValueObservationDatabaseValueConvertibleTests.swift @@ -1,10 +1,10 @@ import XCTest -#if GRDBCIPHER - @testable import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE @testable import GRDBCustomSQLite #else - #if SWIFT_PACKAGE + #if GRDBCIPHER + import SQLCipher + #elseif SWIFT_PACKAGE import CSQLite #else import SQLite3 @@ -30,124 +30,124 @@ private struct Name: DatabaseValueConvertible { class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase { func testAll() throws { let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } + try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } var results: [[Name]] = [] let notificationExpectation = expectation(description: "notification") notificationExpectation.assertForOverFulfill = true notificationExpectation.expectedFulfillmentCount = 4 - var observation = ValueObservation.trackingAll(SQLRequest("SELECT name FROM t ORDER BY id")) - observation.extent = .databaseLifetime - _ = try observation.start(in: dbQueue) { names in + let observation = ValueObservation.trackingAll(SQLRequest(sql: "SELECT name FROM t ORDER BY id")) + let observer = try observation.start(in: dbQueue) { names in results.append(names) notificationExpectation.fulfill() } - - try dbQueue.inDatabase { db in - try db.execute("INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 - try db.execute("UPDATE t SET name = 'foo' WHERE id = 1") // = - try db.inTransaction { // +1 - try db.execute("INSERT INTO t (id, name) VALUES (2, 'bar')") - try db.execute("INSERT INTO t (id, name) VALUES (3, 'baz')") - try db.execute("DELETE FROM t WHERE id = 3") - return .commit + try withExtendedLifetime(observer) { + try dbQueue.inDatabase { db in + try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 + try db.execute(sql: "UPDATE t SET name = 'foo' WHERE id = 1") // = + try db.inTransaction { // +1 + try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, 'bar')") + try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'baz')") + try db.execute(sql: "DELETE FROM t WHERE id = 3") + return .commit + } + try db.execute(sql: "DELETE FROM t WHERE id = 1") // -1 } - try db.execute("DELETE FROM t WHERE id = 1") // -1 + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(results.map { $0.map { $0.rawValue }}, [ + [], + ["foo"], + ["foo", "bar"], + ["bar"]]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(results.map { $0.map { $0.rawValue }}, [ - [], - ["foo"], - ["foo", "bar"], - ["bar"]]) } func testOne() throws { let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } + try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } var results: [Name?] = [] let notificationExpectation = expectation(description: "notification") notificationExpectation.assertForOverFulfill = true notificationExpectation.expectedFulfillmentCount = 7 - var observation = ValueObservation.trackingOne(SQLRequest("SELECT name FROM t ORDER BY id DESC")) - observation.extent = .databaseLifetime - _ = try observation.start(in: dbQueue) { name in + let observation = ValueObservation.trackingOne(SQLRequest(sql: "SELECT name FROM t ORDER BY id DESC")) + let observer = try observation.start(in: dbQueue) { name in results.append(name) notificationExpectation.fulfill() } - - try dbQueue.inDatabase { db in - try db.execute("INSERT INTO t (id, name) VALUES (1, 'foo')") - try db.execute("UPDATE t SET name = 'foo' WHERE id = 1") - try db.inTransaction { - try db.execute("INSERT INTO t (id, name) VALUES (2, 'bar')") - try db.execute("INSERT INTO t (id, name) VALUES (3, 'baz')") - try db.execute("DELETE FROM t WHERE id = 3") - return .commit + try withExtendedLifetime(observer) { + try dbQueue.inDatabase { db in + try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')") + try db.execute(sql: "UPDATE t SET name = 'foo' WHERE id = 1") + try db.inTransaction { + try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, 'bar')") + try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'baz')") + try db.execute(sql: "DELETE FROM t WHERE id = 3") + return .commit + } + try db.execute(sql: "DELETE FROM t") + try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'baz')") + try db.execute(sql: "UPDATE t SET name = NULL") + try db.execute(sql: "DELETE FROM t") + try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, NULL)") + try db.execute(sql: "UPDATE t SET name = 'qux'") } - try db.execute("DELETE FROM t") - try db.execute("INSERT INTO t (id, name) VALUES (1, 'baz')") - try db.execute("UPDATE t SET name = NULL") - try db.execute("DELETE FROM t") - try db.execute("INSERT INTO t (id, name) VALUES (1, NULL)") - try db.execute("UPDATE t SET name = 'qux'") + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(results.map { $0.map { $0.rawValue }}, [ + nil, + "foo", + "bar", + nil, + "baz", + nil, + "qux"]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(results.map { $0.map { $0.rawValue }}, [ - nil, - "foo", - "bar", - nil, - "baz", - nil, - "qux"]) } func testAllOptional() throws { let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } + try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } var results: [[Name?]] = [] let notificationExpectation = expectation(description: "notification") notificationExpectation.assertForOverFulfill = true notificationExpectation.expectedFulfillmentCount = 4 - var observation = ValueObservation.trackingAll(SQLRequest("SELECT name FROM t ORDER BY id")) - observation.extent = .databaseLifetime - _ = try observation.start(in: dbQueue) { names in + let observation = ValueObservation.trackingAll(SQLRequest(sql: "SELECT name FROM t ORDER BY id")) + let observer = try observation.start(in: dbQueue) { names in results.append(names) notificationExpectation.fulfill() } - - try dbQueue.inDatabase { db in - try db.execute("INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 - try db.execute("UPDATE t SET name = 'foo' WHERE id = 1") // = - try db.inTransaction { // +1 - try db.execute("INSERT INTO t (id, name) VALUES (2, NULL)") - try db.execute("INSERT INTO t (id, name) VALUES (3, 'baz')") - try db.execute("DELETE FROM t WHERE id = 3") - return .commit + try withExtendedLifetime(observer) { + try dbQueue.inDatabase { db in + try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 + try db.execute(sql: "UPDATE t SET name = 'foo' WHERE id = 1") // = + try db.inTransaction { // +1 + try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, NULL)") + try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'baz')") + try db.execute(sql: "DELETE FROM t WHERE id = 3") + return .commit + } + try db.execute(sql: "DELETE FROM t WHERE id = 1") // -1 } - try db.execute("DELETE FROM t WHERE id = 1") // -1 + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(results.map { $0.map { $0?.rawValue }}, [ + [], + ["foo"], + ["foo", nil], + [nil]]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(results.map { $0.map { $0?.rawValue }}, [ - [], - ["foo"], - ["foo", nil], - [nil]]) } func testViewOptimization() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.write { - try $0.execute(""" + try $0.execute(sql: """ CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT); CREATE VIEW v AS SELECT * FROM t """) @@ -159,7 +159,7 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase { notificationExpectation.expectedFulfillmentCount = 4 // Test that view v is included in the request region - let request = SQLRequest("SELECT name FROM v ORDER BY id") + let request = SQLRequest(sql: "SELECT name FROM v ORDER BY id") try dbQueue.inDatabase { db in let region = try request.databaseRegion(db) XCTAssertEqual(region.description, "t(id,name),v(id,name)") @@ -168,33 +168,33 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase { // Test that view v is not included in the observed region. // This optimization helps observation of views that feed from a // single table. - var observation = ValueObservation.trackingAll(request) - observation.extent = .databaseLifetime - let transactionObserver = try observation.start(in: dbQueue) { names in + let observation = ValueObservation.trackingAll(request) + let observer = try observation.start(in: dbQueue) { names in results.append(names) notificationExpectation.fulfill() } - let valueObserver = transactionObserver as! ValueObserver>> + let valueObserver = observer as! ValueObserver>> XCTAssertEqual(valueObserver.region.description, "t(id,name)") // view is not tracked - - // Test view observation - try dbQueue.inDatabase { db in - try db.execute("INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 - try db.execute("UPDATE t SET name = 'foo' WHERE id = 1") // = - try db.inTransaction { // +1 - try db.execute("INSERT INTO t (id, name) VALUES (2, 'bar')") - try db.execute("INSERT INTO t (id, name) VALUES (3, 'baz')") - try db.execute("DELETE FROM t WHERE id = 3") - return .commit + try withExtendedLifetime(observer) { + // Test view observation + try dbQueue.inDatabase { db in + try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 + try db.execute(sql: "UPDATE t SET name = 'foo' WHERE id = 1") // = + try db.inTransaction { // +1 + try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, 'bar')") + try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'baz')") + try db.execute(sql: "DELETE FROM t WHERE id = 3") + return .commit + } + try db.execute(sql: "DELETE FROM t WHERE id = 1") // -1 } - try db.execute("DELETE FROM t WHERE id = 1") // -1 + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(results.map { $0.map { $0.rawValue }}, [ + [], + ["foo"], + ["foo", "bar"], + ["bar"]]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(results.map { $0.map { $0.rawValue }}, [ - [], - ["foo"], - ["foo", "bar"], - ["bar"]]) } } diff --git a/Tests/GRDBTests/ValueObservationExtentTests.swift b/Tests/GRDBTests/ValueObservationExtentTests.swift index 47fef4251..2a2b6c724 100644 --- a/Tests/GRDBTests/ValueObservationExtentTests.swift +++ b/Tests/GRDBTests/ValueObservationExtentTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else #if SWIFT_PACKAGE @@ -13,52 +11,10 @@ import XCTest #endif class ValueObservationExtentTests: GRDBTestCase { - func testDefaultExtentIsObserverLifetime() { - let observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { _ in }) - XCTAssertEqual(observation.extent, .observerLifetime) - } - - func testExtentDatabaseLifetime() throws { - // We need something to change - let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } - - // Track reducer process - let notificationExpectation = expectation(description: "notification") - notificationExpectation.assertForOverFulfill = true - notificationExpectation.expectedFulfillmentCount = 3 - - // A reducer - let reducer = AnyValueReducer( - fetch: { _ in }, - value: { $0 }) - - // Create an observation - var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer }) - observation.extent = .databaseLifetime - - // Start observation - _ = try observation.start(in: dbQueue) { - notificationExpectation.fulfill() - } - - // notified - try dbQueue.write { db in - try db.execute("INSERT INTO t DEFAULT VALUES") - } - - // notified - try dbQueue.write { db in - try db.execute("INSERT INTO t DEFAULT VALUES") - } - - waitForExpectations(timeout: 1, handler: nil) - } - func testExtentObserverLifetime() throws { // We need something to change let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } // Track reducer process var changesCount = 0 @@ -72,8 +28,7 @@ class ValueObservationExtentTests: GRDBTestCase { value: { $0 }) // Create an observation - var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer }) - observation.extent = .observerLifetime + let observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer }) // Start observation and deallocate observer after second change var observer: TransactionObserver? @@ -87,12 +42,12 @@ class ValueObservationExtentTests: GRDBTestCase { // notified try dbQueue.write { db in - try db.execute("INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") } // not notified try dbQueue.write { db in - try db.execute("INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") } // Avoid "Variable 'observer' was written to, but never read" warning @@ -101,43 +56,4 @@ class ValueObservationExtentTests: GRDBTestCase { waitForExpectations(timeout: 1, handler: nil) XCTAssertEqual(changesCount, 2) } - - func testExtentNextTransaction() throws { - // We need something to change - let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } - - // Track reducer process - let notificationExpectation = expectation(description: "notification") - notificationExpectation.assertForOverFulfill = true - notificationExpectation.expectedFulfillmentCount = 2 - - // A reducer - let reducer = AnyValueReducer( - fetch: { _ in }, - value: { $0 }) - - // Create an observation - var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer }) - observation.extent = .nextTransaction - - // Start observation - let observer = try observation.start(in: dbQueue) { - notificationExpectation.fulfill() - } - - try withExtendedLifetime(observer) { - // notified - try dbQueue.write { db in - try db.execute("INSERT INTO t DEFAULT VALUES") - } - - // not notified - try dbQueue.write { db in - try db.execute("INSERT INTO t DEFAULT VALUES") - } - - waitForExpectations(timeout: 1, handler: nil) - } - } } diff --git a/Tests/GRDBTests/ValueObservationFetchTests.swift b/Tests/GRDBTests/ValueObservationFetchTests.swift index e4755699a..9fcb4e081 100644 --- a/Tests/GRDBTests/ValueObservationFetchTests.swift +++ b/Tests/GRDBTests/ValueObservationFetchTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else #if SWIFT_PACKAGE @@ -16,105 +14,70 @@ class ValueObservationFetchTests: GRDBTestCase { func testRegionsAPI() { // single region _ = ValueObservation.tracking(DatabaseRegion(), fetch: { _ in }) - _ = ValueObservation.tracking(DatabaseRegion(), fetchDistinct: { _ in 0 }) // variadic _ = ValueObservation.tracking(DatabaseRegion(), DatabaseRegion(), fetch: { _ in }) - _ = ValueObservation.tracking(DatabaseRegion(), DatabaseRegion(), fetchDistinct: { _ in 0 }) // array _ = ValueObservation.tracking([DatabaseRegion()], fetch: { _ in }) } func testFetch() throws { func test(_ dbWriter: DatabaseWriter) throws { - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } var counts: [Int] = [] let notificationExpectation = expectation(description: "notification") notificationExpectation.assertForOverFulfill = true notificationExpectation.expectedFulfillmentCount = 4 - var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { - try Int.fetchOne($0, "SELECT COUNT(*) FROM t")! + let observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { + try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM t")! }) - observation.extent = .databaseLifetime - _ = try observation.start(in: dbWriter) { count in + let observer = try observation.start(in: dbWriter) { count in counts.append(count) notificationExpectation.fulfill() } - - try dbWriter.writeWithoutTransaction { db in - try db.execute("INSERT INTO t DEFAULT VALUES") - try db.execute("UPDATE t SET id = id") - try db.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbWriter.writeWithoutTransaction { db in + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "UPDATE t SET id = id") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(counts, [0, 1, 1, 2]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, [0, 1, 1, 2]) } try test(makeDatabaseQueue()) try test(makeDatabasePool()) } - // Test for a deprecated API - func testFetchDistinct() throws { - func test(_ dbWriter: DatabaseWriter) throws { - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } - - var counts: [Int] = [] - let notificationExpectation = expectation(description: "notification") - notificationExpectation.assertForOverFulfill = true - notificationExpectation.expectedFulfillmentCount = 3 - - var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetchDistinct: { - try Int.fetchOne($0, "SELECT COUNT(*) FROM t")! - }) - observation.extent = .databaseLifetime - _ = try observation.start(in: dbWriter) { count in - counts.append(count) - notificationExpectation.fulfill() - } - - try dbWriter.writeWithoutTransaction { db in - try db.execute("INSERT INTO t DEFAULT VALUES") - try db.execute("UPDATE t SET id = id") - try db.execute("INSERT INTO t DEFAULT VALUES") - } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, [0, 1, 2]) - } - - try test(makeDatabaseQueue()) - try test(makeDatabasePool()) - } - func testDistinctUntilChanged() throws { func test(_ dbWriter: DatabaseWriter) throws { - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } var counts: [Int] = [] let notificationExpectation = expectation(description: "notification") notificationExpectation.assertForOverFulfill = true notificationExpectation.expectedFulfillmentCount = 3 - var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { - try Int.fetchOne($0, "SELECT COUNT(*) FROM t")! + let observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { + try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM t")! }).distinctUntilChanged() - observation.extent = .databaseLifetime - _ = try observation.start(in: dbWriter) { count in + let observer = try observation.start(in: dbWriter) { count in counts.append(count) notificationExpectation.fulfill() } - - try dbWriter.writeWithoutTransaction { db in - try db.execute("INSERT INTO t DEFAULT VALUES") - try db.execute("UPDATE t SET id = id") - try db.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbWriter.writeWithoutTransaction { db in + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "UPDATE t SET id = id") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(counts, [0, 1, 2]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, [0, 1, 2]) } try test(makeDatabaseQueue()) diff --git a/Tests/GRDBTests/ValueObservationMapTests.swift b/Tests/GRDBTests/ValueObservationMapTests.swift index 16a8c08b5..c2f2ab28c 100644 --- a/Tests/GRDBTests/ValueObservationMapTests.swift +++ b/Tests/GRDBTests/ValueObservationMapTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else #if SWIFT_PACKAGE @@ -16,7 +14,7 @@ class ValueObservationMapTests: GRDBTestCase { func testMap() throws { func test(_ dbWriter: DatabaseWriter) throws { // We need something to change - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } var counts: [String] = [] let notificationExpectation = expectation(description: "notification") @@ -33,24 +31,24 @@ class ValueObservationMapTests: GRDBTestCase { }) // Create an observation - var observation = ValueObservation + let observation = ValueObservation .tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer }) .map { count -> String in return "\(count)" } - observation.extent = .databaseLifetime // Start observation - _ = try observation.start(in: dbWriter) { count in + let observer = try observation.start(in: dbWriter) { count in counts.append(count) notificationExpectation.fulfill() } - - try dbWriter.writeWithoutTransaction { db in - try db.execute("INSERT INTO t DEFAULT VALUES") - try db.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbWriter.writeWithoutTransaction { db in + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(counts, ["1", "2", "3"]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, ["1", "2", "3"]) } try test(makeDatabaseQueue()) @@ -59,12 +57,10 @@ class ValueObservationMapTests: GRDBTestCase { func testMapPreservesConfiguration() { var observation = ValueObservation.tracking(DatabaseRegion(), fetch: { _ in }) - observation.extent = .nextTransaction observation.requiresWriteAccess = true observation.scheduling = .unsafe(startImmediately: true) let mappedObservation = observation.map { _ in } - XCTAssertEqual(mappedObservation.extent, observation.extent) XCTAssertEqual(mappedObservation.requiresWriteAccess, observation.requiresWriteAccess) switch mappedObservation.scheduling { case .unsafe: diff --git a/Tests/GRDBTests/ValueObservationQueryInterfaceRequestTests.swift b/Tests/GRDBTests/ValueObservationQueryInterfaceRequestTests.swift new file mode 100644 index 000000000..cc0bb7a70 --- /dev/null +++ b/Tests/GRDBTests/ValueObservationQueryInterfaceRequestTests.swift @@ -0,0 +1,214 @@ +import XCTest +#if GRDBCUSTOMSQLITE + import GRDBCustomSQLite +#else + #if SWIFT_PACKAGE + import CSQLite + #else + import SQLite3 + #endif + import GRDB +#endif + +private struct Parent: TableRecord, FetchableRecord, Decodable, Equatable { + static let children = hasMany(Child.self) + var id: Int64 + var name: String +} + +private struct Child: TableRecord, FetchableRecord, Decodable, Equatable { + var id: Int64 + var parentId: Int64 + var name: String +} + +private struct ParentInfo: FetchableRecord, Decodable, Equatable { + var parent: Parent + var children: [Child] +} + +class ValueObservationQueryInterfaceRequestTests: GRDBTestCase { + override func setup(_ dbWriter: DatabaseWriter) throws { + try dbWriter.write { db in + try db.create(table: "parent") { t in + t.autoIncrementedPrimaryKey("id") + t.column("name", .text) + } + try db.create(table: "child") { t in + t.autoIncrementedPrimaryKey("id") + t.column("parentId", .integer).references("parent", onDelete: .cascade) + t.column("name", .text) + } + try db.execute(sql: """ + INSERT INTO parent (id, name) VALUES (1, 'foo'); + INSERT INTO parent (id, name) VALUES (2, 'bar'); + INSERT INTO child (id, parentId, name) VALUES (1, 1, 'fooA'); + INSERT INTO child (id, parentId, name) VALUES (2, 1, 'fooB'); + INSERT INTO child (id, parentId, name) VALUES (3, 2, 'barA'); + """) + } + } + + func testOneRowWithPrefetchedRows() throws { + let dbQueue = try makeDatabaseQueue() + + var results: [Row?] = [] + let notificationExpectation = expectation(description: "notification") + notificationExpectation.assertForOverFulfill = true + notificationExpectation.expectedFulfillmentCount = 2 + + let request = Parent + .including(all: Parent.children.orderByPrimaryKey()) + .orderByPrimaryKey() + .asRequest(of: Row.self) + let observation = ValueObservation.trackingOne(request) + let observer = try observation.start(in: dbQueue) { row in + results.append(row) + notificationExpectation.fulfill() + } + try withExtendedLifetime(observer) { + try dbQueue.inDatabase { db in + try db.execute(sql: "DELETE FROM child") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(results.count, 2) + + XCTAssertEqual(results[0]!.unscoped, ["id": 1, "name": "foo"]) + XCTAssertEqual(results[0]!.prefetchedRows["children"], [ + ["id": 1, "parentId": 1, "name": "fooA", "grdb_parentId": 1], + ["id": 2, "parentId": 1, "name": "fooB", "grdb_parentId": 1]]) + + XCTAssertEqual(results[1]!.unscoped, ["id": 1, "name": "foo"]) + XCTAssertEqual(results[1]!.prefetchedRows["children"], []) + } + } + + func testAllRowsWithPrefetchedRows() throws { + let dbQueue = try makeDatabaseQueue() + + var results: [[Row]] = [] + let notificationExpectation = expectation(description: "notification") + notificationExpectation.assertForOverFulfill = true + notificationExpectation.expectedFulfillmentCount = 2 + + let request = Parent + .including(all: Parent.children.orderByPrimaryKey()) + .orderByPrimaryKey() + .asRequest(of: Row.self) + let observation = ValueObservation.trackingAll(request) + let observer = try observation.start(in: dbQueue) { rows in + results.append(rows) + notificationExpectation.fulfill() + } + try withExtendedLifetime(observer) { + try dbQueue.inDatabase { db in + try db.execute(sql: "DELETE FROM child") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(results.count, 2) + + XCTAssertEqual(results[0].count, 2) + XCTAssertEqual(results[0][0].unscoped, ["id": 1, "name": "foo"]) + XCTAssertEqual(results[0][0].prefetchedRows["children"], [ + ["id": 1, "parentId": 1, "name": "fooA", "grdb_parentId": 1], + ["id": 2, "parentId": 1, "name": "fooB", "grdb_parentId": 1]]) + XCTAssertEqual(results[0][1].unscoped, ["id": 2, "name": "bar"]) + XCTAssertEqual(results[0][1].prefetchedRows["children"], [ + ["id": 3, "parentId": 2, "name": "barA", "grdb_parentId": 2]]) + + XCTAssertEqual(results[1].count, 2) + XCTAssertEqual(results[1][0].unscoped, ["id": 1, "name": "foo"]) + XCTAssertEqual(results[1][0].prefetchedRows["children"], []) + XCTAssertEqual(results[1][1].unscoped, ["id": 2, "name": "bar"]) + XCTAssertEqual(results[1][1].prefetchedRows["children"], []) + } + } + + func testOneRecordWithPrefetchedRows() throws { + let dbQueue = try makeDatabaseQueue() + + var results: [ParentInfo?] = [] + let notificationExpectation = expectation(description: "notification") + notificationExpectation.assertForOverFulfill = true + notificationExpectation.expectedFulfillmentCount = 2 + + let request = Parent + .including(all: Parent.children.orderByPrimaryKey()) + .orderByPrimaryKey() + .asRequest(of: ParentInfo.self) + let observation = ValueObservation.trackingOne(request) + let observer = try observation.start(in: dbQueue) { parentInfo in + results.append(parentInfo) + notificationExpectation.fulfill() + } + try withExtendedLifetime(observer) { + try dbQueue.inDatabase { db in + try db.execute(sql: "DELETE FROM child") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(results, [ + ParentInfo( + parent: Parent(id: 1, name: "foo"), + children: [ + Child(id: 1, parentId: 1, name: "fooA"), + Child(id: 2, parentId: 1, name: "fooB"), + ]), + ParentInfo( + parent: Parent(id: 1, name: "foo"), + children: []), + ]) + } + } + + func testAllRecordsWithPrefetchedRows() throws { + let dbQueue = try makeDatabaseQueue() + + var results: [[ParentInfo]] = [] + let notificationExpectation = expectation(description: "notification") + notificationExpectation.assertForOverFulfill = true + notificationExpectation.expectedFulfillmentCount = 2 + + let request = Parent + .including(all: Parent.children.orderByPrimaryKey()) + .orderByPrimaryKey() + .asRequest(of: ParentInfo.self) + let observation = ValueObservation.trackingAll(request) + let observer = try observation.start(in: dbQueue) { parentInfos in + results.append(parentInfos) + notificationExpectation.fulfill() + } + try withExtendedLifetime(observer) { + try dbQueue.inDatabase { db in + try db.execute(sql: "DELETE FROM child") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(results, [ + [ + ParentInfo( + parent: Parent(id: 1, name: "foo"), + children: [ + Child(id: 1, parentId: 1, name: "fooA"), + Child(id: 2, parentId: 1, name: "fooB"), + ]), + ParentInfo( + parent: Parent(id: 2, name: "bar"), + children: [ + Child(id: 3, parentId: 2, name: "barA"), + ]), + ], + [ + ParentInfo( + parent: Parent(id: 1, name: "foo"), + children: []), + ParentInfo( + parent: Parent(id: 2, name: "bar"), + children: []), + ], + ]) + } + } +} diff --git a/Tests/GRDBTests/ValueObservationReadonlyTests.swift b/Tests/GRDBTests/ValueObservationReadonlyTests.swift index c5bc764c5..4698dc541 100644 --- a/Tests/GRDBTests/ValueObservationReadonlyTests.swift +++ b/Tests/GRDBTests/ValueObservationReadonlyTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else #if SWIFT_PACKAGE @@ -16,36 +14,36 @@ class ValueObservationReadonlyTests: GRDBTestCase { func testReadOnlyObservation() throws { let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } var counts: [Int] = [] let notificationExpectation = expectation(description: "notification") notificationExpectation.assertForOverFulfill = true notificationExpectation.expectedFulfillmentCount = 2 - var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { - try Int.fetchOne($0, "SELECT COUNT(*) FROM t")! + let observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { + try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM t")! }) - observation.extent = .databaseLifetime - _ = try observation.start(in: dbQueue) { count in + let observer = try observation.start(in: dbQueue) { count in counts.append(count) notificationExpectation.fulfill() } - - try dbQueue.write { - try $0.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbQueue.write { + try $0.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(counts, [0, 1]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, [0, 1]) } func testWriteObservationFailsByDefault() throws { let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } let observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { db -> Int in - try db.execute("INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") return 0 }) @@ -65,7 +63,7 @@ class ValueObservationReadonlyTests: GRDBTestCase { func testWriteObservation() throws { let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } var counts: [Int] = [] let notificationExpectation = expectation(description: "notification") @@ -74,35 +72,35 @@ class ValueObservationReadonlyTests: GRDBTestCase { var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { db -> Int in XCTAssert(db.isInsideTransaction, "expected a wrapping transaction") - try db.execute("CREATE TEMPORARY TABLE temp AS SELECT * FROM t") - let result = try Int.fetchOne(db, "SELECT COUNT(*) FROM temp")! - try db.execute("DROP TABLE temp") + try db.execute(sql: "CREATE TEMPORARY TABLE temp AS SELECT * FROM t") + let result = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM temp")! + try db.execute(sql: "DROP TABLE temp") return result }) - observation.extent = .databaseLifetime observation.requiresWriteAccess = true - _ = try observation.start(in: dbQueue) { count in + let observer = try observation.start(in: dbQueue) { count in counts.append(count) notificationExpectation.fulfill() } - - try dbQueue.write { - try $0.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbQueue.write { + try $0.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(counts, [0, 1]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, [0, 1]) } func testWriteObservationIsWrappedInSavepoint() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.write { - try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") + try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } struct TestError: Error { } var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { db in - try db.execute("INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") throw TestError() }) observation.requiresWriteAccess = true @@ -116,7 +114,7 @@ class ValueObservationReadonlyTests: GRDBTestCase { } catch is TestError { } - let count = try dbQueue.read { try Int.fetchOne($0, "SELECT COUNT(*) FROM t")! } + let count = try dbQueue.read { try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM t")! } XCTAssertEqual(count, 0) } } diff --git a/Tests/GRDBTests/ValueObservationRecordTests.swift b/Tests/GRDBTests/ValueObservationRecordTests.swift index d145b85ee..304a8c50c 100644 --- a/Tests/GRDBTests/ValueObservationRecordTests.swift +++ b/Tests/GRDBTests/ValueObservationRecordTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else #if SWIFT_PACKAGE @@ -29,73 +27,73 @@ private struct Player: FetchableRecord { class ValueObservationRecordTests: GRDBTestCase { func testAll() throws { let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } + try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } var results: [[Player]] = [] let notificationExpectation = expectation(description: "notification") notificationExpectation.assertForOverFulfill = true notificationExpectation.expectedFulfillmentCount = 4 - var observation = ValueObservation.trackingAll(SQLRequest("SELECT * FROM t ORDER BY id")) - observation.extent = .databaseLifetime - _ = try observation.start(in: dbQueue) { players in + let observation = ValueObservation.trackingAll(SQLRequest(sql: "SELECT * FROM t ORDER BY id")) + let observer = try observation.start(in: dbQueue) { players in results.append(players) notificationExpectation.fulfill() } - - try dbQueue.inDatabase { db in - try db.execute("INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 - try db.execute("UPDATE t SET name = 'foo' WHERE id = 1") // = - try db.inTransaction { // +1 - try db.execute("INSERT INTO t (id, name) VALUES (2, 'bar')") - try db.execute("INSERT INTO t (id, name) VALUES (3, 'baz')") - try db.execute("DELETE FROM t WHERE id = 3") - return .commit + try withExtendedLifetime(observer) { + try dbQueue.inDatabase { db in + try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 + try db.execute(sql: "UPDATE t SET name = 'foo' WHERE id = 1") // = + try db.inTransaction { // +1 + try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, 'bar')") + try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'baz')") + try db.execute(sql: "DELETE FROM t WHERE id = 3") + return .commit + } + try db.execute(sql: "DELETE FROM t WHERE id = 1") // -1 } - try db.execute("DELETE FROM t WHERE id = 1") // -1 + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(results.map { $0.map { $0.row }}, [ + [], + [["id":1, "name":"foo"]], + [["id":1, "name":"foo"], ["id":2, "name":"bar"]], + [["id":2, "name":"bar"]]]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(results.map { $0.map { $0.row }}, [ - [], - [["id":1, "name":"foo"]], - [["id":1, "name":"foo"], ["id":2, "name":"bar"]], - [["id":2, "name":"bar"]]]) } func testOne() throws { let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } + try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } var results: [Player?] = [] let notificationExpectation = expectation(description: "notification") notificationExpectation.assertForOverFulfill = true notificationExpectation.expectedFulfillmentCount = 4 - var observation = ValueObservation.trackingOne(SQLRequest("SELECT * FROM t ORDER BY id DESC")) - observation.extent = .databaseLifetime - _ = try observation.start(in: dbQueue) { player in + let observation = ValueObservation.trackingOne(SQLRequest(sql: "SELECT * FROM t ORDER BY id DESC")) + let observer = try observation.start(in: dbQueue) { player in results.append(player) notificationExpectation.fulfill() } - - try dbQueue.inDatabase { db in - try db.execute("INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 - try db.execute("UPDATE t SET name = 'foo' WHERE id = 1") // = - try db.inTransaction { // +1 - try db.execute("INSERT INTO t (id, name) VALUES (2, 'bar')") - try db.execute("INSERT INTO t (id, name) VALUES (3, 'baz')") - try db.execute("DELETE FROM t WHERE id = 3") - return .commit + try withExtendedLifetime(observer) { + try dbQueue.inDatabase { db in + try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 + try db.execute(sql: "UPDATE t SET name = 'foo' WHERE id = 1") // = + try db.inTransaction { // +1 + try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, 'bar')") + try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'baz')") + try db.execute(sql: "DELETE FROM t WHERE id = 3") + return .commit + } + try db.execute(sql: "DELETE FROM t") // -1 } - try db.execute("DELETE FROM t") // -1 + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(results.map { $0.map { $0.row }}, [ + nil, + ["id":1, "name":"foo"], + ["id":2, "name":"bar"], + nil]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(results.map { $0.map { $0.row }}, [ - nil, - ["id":1, "name":"foo"], - ["id":2, "name":"bar"], - nil]) } } diff --git a/Tests/GRDBTests/ValueObservationReducerTests.swift b/Tests/GRDBTests/ValueObservationReducerTests.swift index af94a5180..5621fb251 100644 --- a/Tests/GRDBTests/ValueObservationReducerTests.swift +++ b/Tests/GRDBTests/ValueObservationReducerTests.swift @@ -1,8 +1,6 @@ import XCTest import Dispatch -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else #if SWIFT_PACKAGE @@ -28,7 +26,7 @@ class ValueObservationReducerTests: GRDBTestCase { func testReducer() throws { func test(_ dbWriter: DatabaseWriter) throws { // We need something to change - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } // Track reducer process var fetchCount = 0 @@ -44,7 +42,7 @@ class ValueObservationReducerTests: GRDBTestCase { fetch: { db -> Int in fetchCount += 1 // test for database access - return try Int.fetchOne(db, "SELECT COUNT(*) FROM t")! + return try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")! }, value: { count -> String? in reduceCount += 1 @@ -57,12 +55,11 @@ class ValueObservationReducerTests: GRDBTestCase { }) // Create an observation - let request = SQLRequest("SELECT * FROM t") - var observation = ValueObservation.tracking(request, reducer: { _ in reducer }) - observation.extent = .databaseLifetime + let request = SQLRequest(sql: "SELECT * FROM t") + let observation = ValueObservation.tracking(request, reducer: { _ in reducer }) // Start observation - _ = try observation.start( + let observer = try observation.start( in: dbWriter, onError: { errors.append($0) @@ -72,53 +69,53 @@ class ValueObservationReducerTests: GRDBTestCase { changes.append($0) notificationExpectation.fulfill() }) - - - // Test that default config synchronously notifies initial value - XCTAssertEqual(fetchCount, 1) - XCTAssertEqual(reduceCount, 1) - XCTAssertEqual(errors.count, 0) - XCTAssertEqual(changes, ["0"]) - - try dbWriter.writeWithoutTransaction { db in - // Test a 1st notified transaction - try db.inTransaction { - try db.execute("INSERT INTO t DEFAULT VALUES") - return .commit + try withExtendedLifetime(observer) { + // Test that default config synchronously notifies initial value + XCTAssertEqual(fetchCount, 1) + XCTAssertEqual(reduceCount, 1) + XCTAssertEqual(errors.count, 0) + XCTAssertEqual(changes, ["0"]) + + try dbWriter.writeWithoutTransaction { db in + // Test a 1st notified transaction + try db.inTransaction { + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + return .commit + } + + // Test an untracked transaction + try db.inTransaction { + try db.execute(sql: "CREATE TABLE ignored(a)") + return .commit + } + + // Test a dropped transaction + try db.inTransaction { + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + return .commit + } + + // Test a rollbacked transaction + try db.inTransaction { + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + return .rollback + } + + // Test a 2nd notified transaction + try db.inTransaction { + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + return .commit + } } - // Test an untracked transaction - try db.inTransaction { - try db.execute("CREATE TABLE ignored(a)") - return .commit - } - - // Test a dropped transaction - try db.inTransaction { - try db.execute("INSERT INTO t DEFAULT VALUES") - try db.execute("INSERT INTO t DEFAULT VALUES") - return .commit - } - - // Test a rollbacked transaction - try db.inTransaction { - try db.execute("INSERT INTO t DEFAULT VALUES") - return .rollback - } - - // Test a 2nd notified transaction - try db.inTransaction { - try db.execute("INSERT INTO t DEFAULT VALUES") - try db.execute("INSERT INTO t DEFAULT VALUES") - return .commit - } + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(fetchCount, 4) + XCTAssertEqual(reduceCount, 4) + XCTAssertEqual(errors.count, 0) + XCTAssertEqual(changes, ["0", "1", "5"]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(fetchCount, 4) - XCTAssertEqual(reduceCount, 4) - XCTAssertEqual(errors.count, 0) - XCTAssertEqual(changes, ["0", "1", "5"]) } try test(makeDatabaseQueue()) @@ -153,7 +150,7 @@ class ValueObservationReducerTests: GRDBTestCase { func testSuccessThenErrorThenSuccess() throws { func test(_ dbWriter: DatabaseWriter) throws { // We need something to change - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } // Track reducer process var errors: [Error] = [] @@ -174,11 +171,10 @@ class ValueObservationReducerTests: GRDBTestCase { value: { $0 }) // Create an observation - var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer }) - observation.extent = .databaseLifetime + let observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer }) // Start observation - _ = try observation.start( + let observer = try observation.start( in: dbWriter, onError: { errors.append($0) @@ -189,69 +185,30 @@ class ValueObservationReducerTests: GRDBTestCase { notificationExpectation.fulfill() }) - struct TestError: Error { } - nextError = TestError() - try dbWriter.writeWithoutTransaction { db in - try db.execute("INSERT INTO t DEFAULT VALUES") - try db.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + struct TestError: Error { } + nextError = TestError() + try dbWriter.writeWithoutTransaction { db in + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(errors.count, 1) + XCTAssertEqual(changes.count, 2) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(errors.count, 1) - XCTAssertEqual(changes.count, 2) } try test(makeDatabaseQueue()) try test(makeDatabasePool()) } - func testDeprecatedReadMeReducer() throws { - func test(_ dbWriter: DatabaseWriter) throws { - // Test for the reducer documented in the main README - - // We need something to change - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } - - // Track reducer process - var counts: [Int] = [] - let notificationExpectation = expectation(description: "notification") - notificationExpectation.assertForOverFulfill = true - notificationExpectation.expectedFulfillmentCount = 2 - - // Create an observation - var count = 0 - let reducer = AnyValueReducer( - fetch: { _ in /* don't fetch anything */ }, - value: { _ -> Int? in - defer { count += 1 } - return count }) - var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: reducer) - observation.extent = .databaseLifetime - - // Start observation - _ = try observation.start(in: dbWriter) { count in - counts.append(count) - notificationExpectation.fulfill() - } - - try dbWriter.write { db in - try db.execute("INSERT INTO t DEFAULT VALUES") - } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, [0, 1]) - } - - try test(makeDatabaseQueue()) - try test(makeDatabasePool()) - } - func testReadMeReducer() throws { func test(_ dbWriter: DatabaseWriter) throws { // Test for the reducer documented in the main README // We need something to change - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } // Track reducer process var counts: [Int] = [] @@ -266,21 +223,21 @@ class ValueObservationReducerTests: GRDBTestCase { value: { _ -> Int? in defer { count += 1 } return count }) - var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer}) - observation.extent = .databaseLifetime + let observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer}) // Start observation - _ = try observation.start(in: dbWriter) { count in + let observer = try observation.start(in: dbWriter) { count in counts.append(count) notificationExpectation.fulfill() } - - try dbWriter.write { db in - try db.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbWriter.write { db in + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(counts, [0, 1]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, [0, 1]) } try test(makeDatabaseQueue()) @@ -290,7 +247,7 @@ class ValueObservationReducerTests: GRDBTestCase { func testMapValueReducer() throws { func test(_ dbWriter: DatabaseWriter) throws { // We need something to change - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } // Track reducer process var counts: [String] = [] @@ -313,22 +270,22 @@ class ValueObservationReducerTests: GRDBTestCase { } // Create an observation - var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer }) - observation.extent = .databaseLifetime + let observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer }) // Start observation - _ = try observation.start(in: dbWriter) { count in + let observer = try observation.start(in: dbWriter) { count in counts.append(count) notificationExpectation.fulfill() } - - try dbWriter.writeWithoutTransaction { db in - try db.execute("INSERT INTO t DEFAULT VALUES") - try db.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbWriter.writeWithoutTransaction { db in + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(counts, ["1", "2", "3"]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, ["1", "2", "3"]) } try test(makeDatabaseQueue()) @@ -338,7 +295,7 @@ class ValueObservationReducerTests: GRDBTestCase { func testCompactMapValueReducer() throws { func test(_ dbWriter: DatabaseWriter) throws { // We need something to change - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } // Track reducer process var counts: [String] = [] @@ -362,22 +319,22 @@ class ValueObservationReducerTests: GRDBTestCase { } // Create an observation - var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer }) - observation.extent = .databaseLifetime + let observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer }) // Start observation - _ = try observation.start(in: dbWriter) { count in + let observer = try observation.start(in: dbWriter) { count in counts.append(count) notificationExpectation.fulfill() } - - try dbWriter.writeWithoutTransaction { db in - try db.execute("INSERT INTO t DEFAULT VALUES") - try db.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbWriter.writeWithoutTransaction { db in + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(counts, ["1", "3"]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, ["1", "3"]) } try test(makeDatabaseQueue()) @@ -386,7 +343,7 @@ class ValueObservationReducerTests: GRDBTestCase { func testValueObservationMap() throws { func test(_ dbWriter: DatabaseWriter) throws { - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } var counts: [String] = [] let notificationExpectation = expectation(description: "notification") @@ -394,22 +351,22 @@ class ValueObservationReducerTests: GRDBTestCase { notificationExpectation.expectedFulfillmentCount = 3 struct T: TableRecord { } - var observation = ValueObservation + let observation = ValueObservation .trackingCount(T.all()) .map { "\($0)" } - observation.extent = .databaseLifetime - _ = try observation.start(in: dbWriter) { count in + let observer = try observation.start(in: dbWriter) { count in counts.append(count) notificationExpectation.fulfill() } - - try dbWriter.writeWithoutTransaction { db in - try db.execute("INSERT INTO t DEFAULT VALUES") - try db.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbWriter.writeWithoutTransaction { db in + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(counts, ["0", "1", "2"]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, ["0", "1", "2"]) } try test(makeDatabaseQueue()) @@ -418,7 +375,7 @@ class ValueObservationReducerTests: GRDBTestCase { func testReducerQueueLabel() throws { func test(_ dbWriter: DatabaseWriter, expectedLabels: [String]) throws { - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } let reduceExpectation = expectation(description: "notification") reduceExpectation.assertForOverFulfill = true @@ -433,16 +390,16 @@ class ValueObservationReducerTests: GRDBTestCase { } reduceExpectation.fulfill() }) - var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer }) - observation.extent = .databaseLifetime - _ = try observation.start(in: dbWriter, onChange: { _ in }) - - try dbWriter.write { db in - try db.execute("INSERT INTO t DEFAULT VALUES") + let observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer }) + let observer = try observation.start(in: dbWriter, onChange: { _ in }) + try withExtendedLifetime(observer) { + try dbWriter.write { db in + try db.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(labels, expectedLabels) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(labels, expectedLabels) } do { // dbQueue with default label @@ -473,7 +430,7 @@ class ValueObservationReducerTests: GRDBTestCase { // TODO: make this test pass reliably // func testObserverInvalidation1() throws { // func test(_ dbWriter: DatabaseWriter) throws { -// try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } +// try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } // // let notificationExpectation = expectation(description: "notification") // notificationExpectation.isInverted = true @@ -494,7 +451,7 @@ class ValueObservationReducerTests: GRDBTestCase { // } // // try dbWriter.write { db in -// try db.execute("INSERT INTO t DEFAULT VALUES") +// try db.execute(sql: "INSERT INTO t DEFAULT VALUES") // } // waitForExpectations(timeout: 0.1, handler: nil) // } @@ -506,7 +463,7 @@ class ValueObservationReducerTests: GRDBTestCase { // TODO: make this test pass reliably // func testObserverInvalidation2() throws { // func test(_ dbWriter: DatabaseWriter) throws { -// try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } +// try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } // // let notificationExpectation = expectation(description: "notification") // notificationExpectation.isInverted = true @@ -527,7 +484,7 @@ class ValueObservationReducerTests: GRDBTestCase { // } // // try dbWriter.write { db in -// try db.execute("INSERT INTO t DEFAULT VALUES") +// try db.execute(sql: "INSERT INTO t DEFAULT VALUES") // } // waitForExpectations(timeout: 0.1, handler: nil) // } diff --git a/Tests/GRDBTests/ValueObservationRowTests.swift b/Tests/GRDBTests/ValueObservationRowTests.swift index 1b6656ebf..25380deab 100644 --- a/Tests/GRDBTests/ValueObservationRowTests.swift +++ b/Tests/GRDBTests/ValueObservationRowTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else #if SWIFT_PACKAGE @@ -15,66 +13,66 @@ import XCTest class ValueObservationRowTests: GRDBTestCase { func testAll() throws { let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } + try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } var results: [[Row]] = [] let notificationExpectation = expectation(description: "notification") notificationExpectation.assertForOverFulfill = true notificationExpectation.expectedFulfillmentCount = 4 - var observation = ValueObservation.trackingAll(SQLRequest("SELECT * FROM t ORDER BY id")) - observation.extent = .databaseLifetime - _ = try observation.start(in: dbQueue) { rows in + let observation = ValueObservation.trackingAll(SQLRequest(sql: "SELECT * FROM t ORDER BY id")) + let observer = try observation.start(in: dbQueue) { rows in results.append(rows) notificationExpectation.fulfill() } - - try dbQueue.inDatabase { db in - try db.execute("INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 - try db.execute("UPDATE t SET name = 'foo' WHERE id = 1") // = - try db.inTransaction { // +1 - try db.execute("INSERT INTO t (id, name) VALUES (2, 'bar')") - try db.execute("INSERT INTO t (id, name) VALUES (3, 'baz')") - try db.execute("DELETE FROM t WHERE id = 3") - return .commit + try withExtendedLifetime(observer) { + try dbQueue.inDatabase { db in + try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 + try db.execute(sql: "UPDATE t SET name = 'foo' WHERE id = 1") // = + try db.inTransaction { // +1 + try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, 'bar')") + try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'baz')") + try db.execute(sql: "DELETE FROM t WHERE id = 3") + return .commit + } + try db.execute(sql: "DELETE FROM t WHERE id = 1") // -1 } - try db.execute("DELETE FROM t WHERE id = 1") // -1 + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(results, [ + [], + [["id":1, "name":"foo"]], + [["id":1, "name":"foo"], ["id":2, "name":"bar"]], + [["id":2, "name":"bar"]]]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(results, [ - [], - [["id":1, "name":"foo"]], - [["id":1, "name":"foo"], ["id":2, "name":"bar"]], - [["id":2, "name":"bar"]]]) } func testOne() throws { let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } + try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } var results: [Row?] = [] let notificationExpectation = expectation(description: "notification") notificationExpectation.assertForOverFulfill = true notificationExpectation.expectedFulfillmentCount = 4 - var observation = ValueObservation.trackingOne(SQLRequest("SELECT * FROM t ORDER BY id DESC")) - observation.extent = .databaseLifetime - _ = try observation.start(in: dbQueue) { row in + let observation = ValueObservation.trackingOne(SQLRequest(sql: "SELECT * FROM t ORDER BY id DESC")) + let observer = try observation.start(in: dbQueue) { row in results.append(row) notificationExpectation.fulfill() } - - try dbQueue.inDatabase { db in - try db.execute("INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 - try db.execute("UPDATE t SET name = 'foo' WHERE id = 1") // = - try db.inTransaction { // +1 - try db.execute("INSERT INTO t (id, name) VALUES (2, 'bar')") - try db.execute("INSERT INTO t (id, name) VALUES (3, 'baz')") - try db.execute("DELETE FROM t WHERE id = 3") - return .commit + try withExtendedLifetime(observer) { + try dbQueue.inDatabase { db in + try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 + try db.execute(sql: "UPDATE t SET name = 'foo' WHERE id = 1") // = + try db.inTransaction { // +1 + try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, 'bar')") + try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'baz')") + try db.execute(sql: "DELETE FROM t WHERE id = 3") + return .commit + } + try db.execute(sql: "DELETE FROM t") // -1 } - try db.execute("DELETE FROM t") // -1 } waitForExpectations(timeout: 1, handler: nil) diff --git a/Tests/GRDBTests/ValueObservationSchedulingTests.swift b/Tests/GRDBTests/ValueObservationSchedulingTests.swift index fe1251eba..65ee381b4 100644 --- a/Tests/GRDBTests/ValueObservationSchedulingTests.swift +++ b/Tests/GRDBTests/ValueObservationSchedulingTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else #if SWIFT_PACKAGE @@ -16,7 +14,7 @@ class ValueObservationSchedulingTests: GRDBTestCase { func testMainQueueObservationStartedFromMainQueue() throws { func test(_ dbWriter: DatabaseWriter) throws { // We need something to change - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } var counts: [Int] = [] let notificationExpectation = expectation(description: "notification") @@ -26,12 +24,10 @@ class ValueObservationSchedulingTests: GRDBTestCase { let key = DispatchSpecificKey<()>() DispatchQueue.main.setSpecific(key: key, value: ()) - var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { - try Int.fetchOne($0, "SELECT COUNT(*) FROM t")! + let observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { + try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM t")! }) - observation.extent = .databaseLifetime - - _ = try observation.start(in: dbWriter) { count in + let observer = try observation.start(in: dbWriter) { count in XCTAssertNotNil(DispatchQueue.getSpecific(key: key)) counts.append(count) notificationExpectation.fulfill() @@ -40,12 +36,14 @@ class ValueObservationSchedulingTests: GRDBTestCase { // dispatched when observation is started from the main queue XCTAssertEqual(counts, [0]) - try dbWriter.write { - try $0.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbWriter.write { + try $0.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(counts, [0, 1]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, [0, 1]) } try test(makeDatabaseQueue()) @@ -56,7 +54,7 @@ class ValueObservationSchedulingTests: GRDBTestCase { func testMainQueueObservationStartedFromAnotherQueue() throws { func test(_ dbWriter: DatabaseWriter) throws { // We need something to change - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } var counts: [Int] = [] let notificationExpectation = expectation(description: "notification") @@ -66,25 +64,25 @@ class ValueObservationSchedulingTests: GRDBTestCase { let key = DispatchSpecificKey<()>() DispatchQueue.main.setSpecific(key: key, value: ()) - var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { - try Int.fetchOne($0, "SELECT COUNT(*) FROM t")! + let observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { + try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM t")! }) - observation.extent = .databaseLifetime - + var observer: TransactionObserver? DispatchQueue.global(qos: .default).async { - _ = try! observation.start(in: dbWriter) { count in + observer = try! observation.start(in: dbWriter) { count in XCTAssertNotNil(DispatchQueue.getSpecific(key: key)) counts.append(count) notificationExpectation.fulfill() } - try! dbWriter.write { - try $0.execute("INSERT INTO t DEFAULT VALUES") + try $0.execute(sql: "INSERT INTO t DEFAULT VALUES") } } - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, [0, 1]) + withExtendedLifetime(observer) { + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(counts, [0, 1]) + } } try test(makeDatabaseQueue()) @@ -94,7 +92,7 @@ class ValueObservationSchedulingTests: GRDBTestCase { func testMainQueueError() throws { func test(_ dbWriter: DatabaseWriter) throws { // We need something to change - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } var errorCount = 0 let notificationExpectation = expectation(description: "notification") @@ -113,10 +111,9 @@ class ValueObservationSchedulingTests: GRDBTestCase { } }, value: { $0 }) - var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer }) - observation.extent = .databaseLifetime + let observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer }) - _ = try observation.start( + let observer = try observation.start( in: dbWriter, onError: { error in XCTAssertNotNil(DispatchQueue.getSpecific(key: key)) @@ -127,15 +124,16 @@ class ValueObservationSchedulingTests: GRDBTestCase { XCTAssertNotNil(DispatchQueue.getSpecific(key: key)) notificationExpectation.fulfill() }) - - struct TestError: Error { } - nextError = TestError() - try dbWriter.write { - try $0.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + struct TestError: Error { } + nextError = TestError() + try dbWriter.write { + try $0.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(errorCount, 1) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(errorCount, 1) } try test(makeDatabaseQueue()) @@ -145,7 +143,7 @@ class ValueObservationSchedulingTests: GRDBTestCase { func testCustomQueueStartImmediately() throws { func test(_ dbWriter: DatabaseWriter) throws { // We need something to change - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } var counts: [Int] = [] let notificationExpectation = expectation(description: "notification") @@ -157,23 +155,23 @@ class ValueObservationSchedulingTests: GRDBTestCase { queue.setSpecific(key: key, value: ()) var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { - try Int.fetchOne($0, "SELECT COUNT(*) FROM t")! + try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM t")! }) - observation.extent = .databaseLifetime - observation.scheduling = .onQueue(queue, startImmediately: true) + observation.scheduling = .async(onQueue: queue, startImmediately: true) - _ = try observation.start(in: dbWriter) { count in + let observer = try observation.start(in: dbWriter) { count in XCTAssertNotNil(DispatchQueue.getSpecific(key: key)) counts.append(count) notificationExpectation.fulfill() } - - try dbWriter.write { - try $0.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbWriter.write { + try $0.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(counts, [0, 1]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, [0, 1]) } try test(makeDatabaseQueue()) @@ -183,7 +181,7 @@ class ValueObservationSchedulingTests: GRDBTestCase { func testCustomQueueDontStartImmediately() throws { func test(_ dbWriter: DatabaseWriter) throws { // We need something to change - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } var counts: [Int] = [] let notificationExpectation = expectation(description: "notification") @@ -195,23 +193,23 @@ class ValueObservationSchedulingTests: GRDBTestCase { queue.setSpecific(key: key, value: ()) var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { - try Int.fetchOne($0, "SELECT COUNT(*) FROM t")! + try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM t")! }) - observation.extent = .databaseLifetime - observation.scheduling = .onQueue(queue, startImmediately: false) + observation.scheduling = .async(onQueue: queue, startImmediately: false) - _ = try observation.start(in: dbWriter) { count in + let observer = try observation.start(in: dbWriter) { count in XCTAssertNotNil(DispatchQueue.getSpecific(key: key)) counts.append(count) notificationExpectation.fulfill() } - - try dbWriter.write { - try $0.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbWriter.write { + try $0.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(counts, [1]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, [1]) } try test(makeDatabaseQueue()) @@ -221,7 +219,7 @@ class ValueObservationSchedulingTests: GRDBTestCase { func testCustomQueueError() throws { func test(_ dbWriter: DatabaseWriter) throws { // We need something to change - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } var errorCount = 0 let notificationExpectation = expectation(description: "notification") @@ -237,10 +235,9 @@ class ValueObservationSchedulingTests: GRDBTestCase { fetch: { _ in throw TestError() }, value: { $0 }) var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer }) - observation.extent = .databaseLifetime - observation.scheduling = .onQueue(queue, startImmediately: false) + observation.scheduling = .async(onQueue: queue, startImmediately: false) - _ = try observation.start( + let observer = try observation.start( in: dbWriter, onError: { error in XCTAssertNotNil(DispatchQueue.getSpecific(key: key)) @@ -248,13 +245,14 @@ class ValueObservationSchedulingTests: GRDBTestCase { notificationExpectation.fulfill() }, onChange: { _ in fatalError() }) - - try dbWriter.write { - try $0.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbWriter.write { + try $0.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(errorCount, 1) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(errorCount, 1) } try test(makeDatabaseQueue()) @@ -264,7 +262,7 @@ class ValueObservationSchedulingTests: GRDBTestCase { func testUnsafeStartImmediatelyFromMainQueue() throws { func test(_ dbWriter: DatabaseWriter) throws { // We need something to change - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } var counts: [Int] = [] let notificationExpectation = expectation(description: "notification") @@ -275,12 +273,11 @@ class ValueObservationSchedulingTests: GRDBTestCase { DispatchQueue.main.setSpecific(key: key, value: ()) var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { - try Int.fetchOne($0, "SELECT COUNT(*) FROM t")! + try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM t")! }) - observation.extent = .databaseLifetime observation.scheduling = .unsafe(startImmediately: true) - _ = try observation.start(in: dbWriter) { count in + let observer = try observation.start(in: dbWriter) { count in if counts.isEmpty { // require main queue on first element XCTAssertNotNil(DispatchQueue.getSpecific(key: key)) @@ -288,13 +285,14 @@ class ValueObservationSchedulingTests: GRDBTestCase { counts.append(count) notificationExpectation.fulfill() } - - try dbWriter.write { - try $0.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbWriter.write { + try $0.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(counts, [0, 1]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, [0, 1]) } try test(makeDatabaseQueue()) @@ -304,7 +302,7 @@ class ValueObservationSchedulingTests: GRDBTestCase { func testUnsafeStartImmediatelyFromCustomQueue() throws { func test(_ dbWriter: DatabaseWriter) throws { // We need something to change - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } var counts: [Int] = [] let notificationExpectation = expectation(description: "notification") @@ -316,13 +314,12 @@ class ValueObservationSchedulingTests: GRDBTestCase { queue.setSpecific(key: key, value: ()) var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { - try Int.fetchOne($0, "SELECT COUNT(*) FROM t")! + try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM t")! }) - observation.extent = .databaseLifetime observation.scheduling = .unsafe(startImmediately: true) - + var observer: TransactionObserver? queue.async { - _ = try! observation.start(in: dbWriter) { count in + observer = try! observation.start(in: dbWriter) { count in if counts.isEmpty { // require custom queue on first notification XCTAssertNotNil(DispatchQueue.getSpecific(key: key)) @@ -330,14 +327,15 @@ class ValueObservationSchedulingTests: GRDBTestCase { counts.append(count) notificationExpectation.fulfill() } - try! dbWriter.write { - try $0.execute("INSERT INTO t DEFAULT VALUES") + try $0.execute(sql: "INSERT INTO t DEFAULT VALUES") } } - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, [0, 1]) + withExtendedLifetime(observer) { + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(counts, [0, 1]) + } } try test(makeDatabaseQueue()) @@ -347,7 +345,7 @@ class ValueObservationSchedulingTests: GRDBTestCase { func testUnsafeDontStartImmediately() throws { func test(_ dbWriter: DatabaseWriter) throws { // We need something to change - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } var counts: [Int] = [] let notificationExpectation = expectation(description: "notification") @@ -355,22 +353,22 @@ class ValueObservationSchedulingTests: GRDBTestCase { notificationExpectation.expectedFulfillmentCount = 1 var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { - try Int.fetchOne($0, "SELECT COUNT(*) FROM t")! + try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM t")! }) - observation.extent = .databaseLifetime observation.scheduling = .unsafe(startImmediately: false) - _ = try observation.start(in: dbWriter) { count in + let observer = try observation.start(in: dbWriter) { count in counts.append(count) notificationExpectation.fulfill() } - - try dbWriter.write { - try $0.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbWriter.write { + try $0.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(counts, [1]) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, [1]) } try test(makeDatabaseQueue()) @@ -380,7 +378,7 @@ class ValueObservationSchedulingTests: GRDBTestCase { func testUnsafeError() throws { func test(_ dbWriter: DatabaseWriter) throws { // We need something to change - try dbWriter.write { try $0.execute("CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } + try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } var errorCount = 0 let notificationExpectation = expectation(description: "notification") @@ -392,23 +390,23 @@ class ValueObservationSchedulingTests: GRDBTestCase { fetch: { _ in throw TestError() }, value: { $0 }) var observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, reducer: { _ in reducer }) - observation.extent = .databaseLifetime observation.scheduling = .unsafe(startImmediately: false) - _ = try observation.start( + let observer = try observation.start( in: dbWriter, onError: { error in errorCount += 1 notificationExpectation.fulfill() }, onChange: { _ in fatalError() }) - - try dbWriter.write { - try $0.execute("INSERT INTO t DEFAULT VALUES") + try withExtendedLifetime(observer) { + try dbWriter.write { + try $0.execute(sql: "INSERT INTO t DEFAULT VALUES") + } + + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(errorCount, 1) } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(errorCount, 1) } try test(makeDatabaseQueue()) diff --git a/Tests/GRDBTests/VirtualTableModuleTests.swift b/Tests/GRDBTests/VirtualTableModuleTests.swift index d17f91f2c..d2ba6ca57 100644 --- a/Tests/GRDBTests/VirtualTableModuleTests.swift +++ b/Tests/GRDBTests/VirtualTableModuleTests.swift @@ -1,7 +1,5 @@ import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE +#if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else import GRDB diff --git a/Tests/Performance/DateParsingTests.swift b/Tests/Performance/DateParsingTests.swift index 35d74cf09..f6e0d15fa 100644 --- a/Tests/Performance/DateParsingTests.swift +++ b/Tests/Performance/DateParsingTests.swift @@ -18,7 +18,7 @@ class DateParsingTests: XCTestCase { func testParseDateComponents() { measure { try! DatabaseQueue().inDatabase { db in - let cursor = try DatabaseDateComponents.fetchCursor(db, request) + let cursor = try DatabaseDateComponents.fetchCursor(db, sql: request) while try cursor.next() != nil { } } } @@ -27,7 +27,7 @@ class DateParsingTests: XCTestCase { func testParseDate() { measure { try! DatabaseQueue().inDatabase { db in - let cursor = try Date.fetchCursor(db, request) + let cursor = try Date.fetchCursor(db, sql: request) while try cursor.next() != nil { } } } diff --git a/Tests/Performance/FetchNamedValuesTests.swift b/Tests/Performance/FetchNamedValuesTests.swift index 13d411155..77adee3cf 100644 --- a/Tests/Performance/FetchNamedValuesTests.swift +++ b/Tests/Performance/FetchNamedValuesTests.swift @@ -17,7 +17,7 @@ class FetchNamedValuesTests: XCTestCase { var count = 0 try! dbQueue.inDatabase { db in - let rows = try Row.fetchCursor(db, "SELECT * FROM items") + let rows = try Row.fetchCursor(db, sql: "SELECT * FROM items") while let row = try rows.next() { _ = row["i0"] as Int _ = row["i1"] as Int @@ -41,7 +41,7 @@ class FetchNamedValuesTests: XCTestCase { #if GRDB_COMPARE func testFMDB() { let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")! - let dbQueue = FMDatabaseQueue(path: databasePath) + let dbQueue = FMDatabaseQueue(path: databasePath)! measure { var count = 0 diff --git a/Tests/Performance/FetchPositionalValuesTests.swift b/Tests/Performance/FetchPositionalValuesTests.swift index 5c364250d..e9f3d8204 100644 --- a/Tests/Performance/FetchPositionalValuesTests.swift +++ b/Tests/Performance/FetchPositionalValuesTests.swift @@ -59,7 +59,7 @@ class FetchPositionalValuesTests: XCTestCase { var count = 0 try! dbQueue.inDatabase { db in - let rows = try Row.fetchCursor(db, "SELECT * FROM items") + let rows = try Row.fetchCursor(db, sql: "SELECT * FROM items") while let row = try rows.next() { _ = row[0] as Int _ = row[1] as Int @@ -83,7 +83,7 @@ class FetchPositionalValuesTests: XCTestCase { #if GRDB_COMPARE func testFMDB() { let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")! - let dbQueue = FMDatabaseQueue(path: databasePath) + let dbQueue = FMDatabaseQueue(path: databasePath)! measure { var count = 0 diff --git a/Tests/Performance/FetchRecordClassTests.swift b/Tests/Performance/FetchRecordClassTests.swift index 900a97750..54bbd0407 100644 --- a/Tests/Performance/FetchRecordClassTests.swift +++ b/Tests/Performance/FetchRecordClassTests.swift @@ -17,7 +17,7 @@ class FetchRecordClassTests: XCTestCase { measure { let items = try! dbQueue.inDatabase { db in - try ItemClass.fetchAll(db, "SELECT * FROM items") + try ItemClass.fetchAll(db, sql: "SELECT * FROM items") } XCTAssertEqual(items.count, expectedRowCount) XCTAssertEqual(items[0].i0, 0) diff --git a/Tests/Performance/FetchRecordCodableTests.swift b/Tests/Performance/FetchRecordCodableTests.swift index 6cf76cec4..d68db5287 100644 --- a/Tests/Performance/FetchRecordCodableTests.swift +++ b/Tests/Performance/FetchRecordCodableTests.swift @@ -16,7 +16,7 @@ class FetchRecordCodableTests: XCTestCase { measure { let items = try! dbQueue.inDatabase { db in - try ItemCodable.fetchAll(db, "SELECT * FROM items") + try ItemCodable.fetchAll(db, sql: "SELECT * FROM items") } XCTAssertEqual(items.count, expectedRowCount) XCTAssertEqual(items[0].i0, 0) diff --git a/Tests/Performance/FetchRecordStructTests.swift b/Tests/Performance/FetchRecordStructTests.swift index d3832bdec..7cbc924bc 100644 --- a/Tests/Performance/FetchRecordStructTests.swift +++ b/Tests/Performance/FetchRecordStructTests.swift @@ -72,7 +72,7 @@ class FetchRecordStructTests: XCTestCase { measure { let items = try! dbQueue.inDatabase { db in - try ItemStruct.fetchAll(db, "SELECT * FROM items") + try ItemStruct.fetchAll(db, sql: "SELECT * FROM items") } XCTAssertEqual(items.count, expectedRowCount) XCTAssertEqual(items[0].i0, 0) @@ -86,7 +86,7 @@ class FetchRecordStructTests: XCTestCase { // Here we test the loading of an array of Records. let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")! - let dbQueue = FMDatabaseQueue(path: databasePath) + let dbQueue = FMDatabaseQueue(path: databasePath)! measure { var items = [ItemStruct]() diff --git a/Tests/Performance/GRDBProfiling/GRDBProfiling.xcodeproj/project.pbxproj b/Tests/Performance/GRDBProfiling/GRDBProfiling.xcodeproj/project.pbxproj index 3ed309c43..07f908730 100644 --- a/Tests/Performance/GRDBProfiling/GRDBProfiling.xcodeproj/project.pbxproj +++ b/Tests/Performance/GRDBProfiling/GRDBProfiling.xcodeproj/project.pbxproj @@ -186,7 +186,7 @@ 56537C6A1BA8871A00E87787 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0930; + LastUpgradeCheck = 1020; ORGANIZATIONNAME = "Gwendal Roué"; TargetAttributes = { 56537C711BA8871A00E87787 = { @@ -197,7 +197,7 @@ }; buildConfigurationList = 56537C6D1BA8871A00E87787 /* Build configuration list for PBXProject "GRDBProfiling" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, @@ -319,6 +319,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -374,6 +375,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; diff --git a/Tests/Carthage/GRDBiOS/iOS.xcodeproj/xcshareddata/xcschemes/iOS.xcscheme b/Tests/Performance/GRDBProfiling/GRDBProfiling.xcodeproj/xcshareddata/xcschemes/GRDBProfiling.xcscheme similarity index 72% rename from Tests/Carthage/GRDBiOS/iOS.xcodeproj/xcshareddata/xcschemes/iOS.xcscheme rename to Tests/Performance/GRDBProfiling/GRDBProfiling.xcodeproj/xcshareddata/xcschemes/GRDBProfiling.xcscheme index db3aaf4eb..f56ee5c19 100644 --- a/Tests/Carthage/GRDBiOS/iOS.xcodeproj/xcshareddata/xcschemes/iOS.xcscheme +++ b/Tests/Performance/GRDBProfiling/GRDBProfiling.xcodeproj/xcshareddata/xcschemes/GRDBProfiling.xcscheme @@ -1,6 +1,6 @@ + BlueprintIdentifier = "56537C711BA8871A00E87787" + BuildableName = "GRDBProfiling.app" + BlueprintName = "GRDBProfiling" + ReferencedContainer = "container:GRDBProfiling.xcodeproj"> @@ -26,17 +26,16 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" shouldUseLaunchSchemeArgsEnv = "YES"> + BlueprintIdentifier = "56537C711BA8871A00E87787" + BuildableName = "GRDBProfiling.app" + BlueprintName = "GRDBProfiling" + ReferencedContainer = "container:GRDBProfiling.xcodeproj"> @@ -46,7 +45,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" @@ -57,10 +55,10 @@ runnableDebuggingMode = "0"> + BlueprintIdentifier = "56537C711BA8871A00E87787" + BuildableName = "GRDBProfiling.app" + BlueprintName = "GRDBProfiling" + ReferencedContainer = "container:GRDBProfiling.xcodeproj"> @@ -76,10 +74,10 @@ runnableDebuggingMode = "0"> + BlueprintIdentifier = "56537C711BA8871A00E87787" + BuildableName = "GRDBProfiling.app" + BlueprintName = "GRDBProfiling" + ReferencedContainer = "container:GRDBProfiling.xcodeproj"> diff --git a/Tests/Performance/GRDBProfiling/GRDBProfiling/AppDelegate.swift b/Tests/Performance/GRDBProfiling/GRDBProfiling/AppDelegate.swift index d28fcb6f4..3eb6bc4cb 100644 --- a/Tests/Performance/GRDBProfiling/GRDBProfiling/AppDelegate.swift +++ b/Tests/Performance/GRDBProfiling/GRDBProfiling/AppDelegate.swift @@ -7,177 +7,284 @@ let insertedRowCount = 20_000 @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ aNotification: Notification) { - fetchPositionalValues() - fetchNamedValues() - fetchStructs() - fetchRecords() - insertPositionalValues() - insertNamedValues() - insertRecords() + try! fetchValues() + try! fetchPositionalValues() + try! fetchNamedValues() + try! fetchStructs() + try! fetchCodables() + try! fetchRecords() + try! insertPositionalValues() + try! insertNamedValues() + try! insertStructs() + try! insertCodables() + try! insertRecords() } - func fetchPositionalValues() { + // MARK: - + + func fetchValues() throws { let databasePath = Bundle(for: type(of: self)).path(forResource: "ProfilingDatabase", ofType: "sqlite")! - let dbQueue = try! DatabaseQueue(path: databasePath) - + let dbQueue = try DatabaseQueue(path: databasePath) + try dbQueue.read(_fetchValues) + } + + func _fetchValues(_ db: Database) throws { var count = 0 - dbQueue.inDatabase { db in - let rows = try! Row.fetchCursor(db, "SELECT * FROM items") - while let row = try! rows.next() { - let _: Int = row[0] - let _: Int = row[1] - let _: Int = row[2] - let _: Int = row[3] - let _: Int = row[4] - let _: Int = row[5] - let _: Int = row[6] - let _: Int = row[7] - let _: Int = row[8] - let _: Int = row[9] - - count += 1 - } + let cursor = try Int.fetchCursor(db, sql: "SELECT i0 FROM items") + while try cursor.next() != nil { + count += 1 } assert(count == expectedRowCount) } - func fetchNamedValues() { + // MARK: - + + func fetchPositionalValues() throws { let databasePath = Bundle(for: type(of: self)).path(forResource: "ProfilingDatabase", ofType: "sqlite")! - let dbQueue = try! DatabaseQueue(path: databasePath) - + let dbQueue = try DatabaseQueue(path: databasePath) + try dbQueue.read(_fetchPositionalValues) + } + + func _fetchPositionalValues(_ db: Database) throws { var count = 0 - dbQueue.inDatabase { db in - let rows = try! Row.fetchCursor(db, "SELECT * FROM items") - while let row = try! rows.next() { - let _: Int = row["i0"] - let _: Int = row["i1"] - let _: Int = row["i2"] - let _: Int = row["i3"] - let _: Int = row["i4"] - let _: Int = row["i5"] - let _: Int = row["i6"] - let _: Int = row["i7"] - let _: Int = row["i8"] - let _: Int = row["i9"] - - count += 1 - } + let rows = try Row.fetchCursor(db, sql: "SELECT * FROM items") + while let row = try rows.next() { + let _: Int = row[0] + let _: Int = row[1] + let _: Int = row[2] + let _: Int = row[3] + let _: Int = row[4] + let _: Int = row[5] + let _: Int = row[6] + let _: Int = row[7] + let _: Int = row[8] + let _: Int = row[9] + count += 1 } assert(count == expectedRowCount) } - func fetchStructs() { + // MARK: - + + func fetchNamedValues() throws { let databasePath = Bundle(for: type(of: self)).path(forResource: "ProfilingDatabase", ofType: "sqlite")! - let dbQueue = try! DatabaseQueue(path: databasePath) - let items = dbQueue.inDatabase { db in - try! ItemStruct.fetchAll(db) + let dbQueue = try DatabaseQueue(path: databasePath) + try dbQueue.read(_fetchNamedValues) + } + + func _fetchNamedValues(_ db: Database) throws { + var count = 0 + + let rows = try Row.fetchCursor(db, sql: "SELECT * FROM items") + while let row = try rows.next() { + let _: Int = row["i0"] + let _: Int = row["i1"] + let _: Int = row["i2"] + let _: Int = row["i3"] + let _: Int = row["i4"] + let _: Int = row["i5"] + let _: Int = row["i6"] + let _: Int = row["i7"] + let _: Int = row["i8"] + let _: Int = row["i9"] + + count += 1 } + + assert(count == expectedRowCount) + } + + // MARK: - + + func fetchStructs() throws { + let databasePath = Bundle(for: type(of: self)).path(forResource: "ProfilingDatabase", ofType: "sqlite")! + let dbQueue = try DatabaseQueue(path: databasePath) + let items = try dbQueue.read(_fetchStructs) assert(items.count == expectedRowCount) assert(items[0].i0 == 0) assert(items[1].i1 == 1) assert(items[expectedRowCount-1].i9 == expectedRowCount-1) } - func fetchRecords() { + func _fetchStructs(_ db: Database) throws -> [ItemStruct] { + return try ItemStruct.fetchAll(db) + } + + // MARK: - + + func fetchCodables() throws { let databasePath = Bundle(for: type(of: self)).path(forResource: "ProfilingDatabase", ofType: "sqlite")! - let dbQueue = try! DatabaseQueue(path: databasePath) - let items = dbQueue.inDatabase { db in - try! ItemRecord.fetchAll(db) - } + let dbQueue = try DatabaseQueue(path: databasePath) + let items = try dbQueue.read(_fetchCodables) assert(items.count == expectedRowCount) assert(items[0].i0 == 0) assert(items[1].i1 == 1) assert(items[expectedRowCount-1].i9 == expectedRowCount-1) } - func insertPositionalValues() { + func _fetchCodables(_ db: Database) throws -> [ItemCodable] { + return try ItemCodable.fetchAll(db) + } + + // MARK: - + + func fetchRecords() throws { + let databasePath = Bundle(for: type(of: self)).path(forResource: "ProfilingDatabase", ofType: "sqlite")! + let dbQueue = try DatabaseQueue(path: databasePath) + let items = try dbQueue.read(_fetchRecords) + assert(items.count == expectedRowCount) + assert(items[0].i0 == 0) + assert(items[1].i1 == 1) + assert(items[expectedRowCount-1].i9 == expectedRowCount-1) + } + + func _fetchRecords(_ db: Database) throws -> [ItemRecord] { + return try ItemRecord.fetchAll(db) + } + + // MARK: - + + func insertPositionalValues() throws { let databaseFileName = "GRDBPerformanceTests-\(ProcessInfo.processInfo.globallyUniqueString).sqlite" let databasePath = (NSTemporaryDirectory() as NSString).appendingPathComponent(databaseFileName) - defer { - let dbQueue = try! DatabaseQueue(path: databasePath) - dbQueue.inDatabase { db in - assert(try! Int.fetchOne(db, "SELECT COUNT(*) FROM items")! == insertedRowCount) - assert(try! Int.fetchOne(db, "SELECT MIN(i0) FROM items")! == 0) - assert(try! Int.fetchOne(db, "SELECT MAX(i9) FROM items")! == insertedRowCount - 1) - } - try! FileManager.default.removeItem(atPath: databasePath) - } - _ = try? FileManager.default.removeItem(atPath: databasePath) - let dbQueue = try! DatabaseQueue(path: databasePath) - try! dbQueue.inDatabase { db in - try db.execute("CREATE TABLE items (i0 INT, i1 INT, i2 INT, i3 INT, i4 INT, i5 INT, i6 INT, i7 INT, i8 INT, i9 INT)") + let dbQueue = try DatabaseQueue(path: databasePath) + try dbQueue.write { db in + try db.execute(sql: "CREATE TABLE items (i0 INT, i1 INT, i2 INT, i3 INT, i4 INT, i5 INT, i6 INT, i7 INT, i8 INT, i9 INT)") } - try! dbQueue.inTransaction { db in - let statement = try! db.makeUpdateStatement("INSERT INTO items (i0, i1, i2, i3, i4, i5, i6, i7, i8, i9) VALUES (?,?,?,?,?,?,?,?,?,?)") - for i in 0..=5.0) +try! DatabaseQueue().write { db in + try db.execute(literal: """ + CREATE TABLE t(a); + INSERT INTO t VALUES(\("5")); + """) + let swiftVersion = String.fetchOne(db, sql: "SELECT a FROM t")! + print("Swift version from SQL: \(swiftVersion)") +} +#endif diff --git a/Tests/generatePerformanceReport.rb b/Tests/generatePerformanceReport.rb index 94946e9fd..d803520d1 100755 --- a/Tests/generatePerformanceReport.rb +++ b/Tests/generatePerformanceReport.rb @@ -27,7 +27,7 @@ end samples = JSON.parse(STDIN.read) grdb_version = info_plist_version('Support/Info.plist') fmdb_version = info_plist_version('Tests/Performance/fmdb/src/fmdb/Info.plist') -sqlite_swift_version = '0.11.5' # not up-to-date: info_plist_version('Tests/Performance/SQLite.swift/Sources/SQLite/Info.plist') +sqlite_swift_version = '0.12.0' # not up-to-date: info_plist_version('Tests/Performance/SQLite.swift/Sources/SQLite/Info.plist') realm_version = info_plist_version('Tests/Performance/Realm/build/osx/Realm.framework/Versions/A/Resources/Info.plist') puts <<-REPORT @@ -37,7 +37,7 @@ puts <<-REPORT Below are performance benchmarks made on for [GRDB #{grdb_version}](https://github.com/groue/GRDB.swift), [FMDB #{fmdb_version}](https://github.com/ccgus/fmdb), and [SQLite.swift #{sqlite_swift_version}](https://github.com/stephencelis/SQLite.swift). They are compared to Core Data, [Realm #{realm_version}](https://realm.io) and the raw use of the SQLite C API from Swift. -This report was generated on a MacBook Pro (15-inch, Late 2016), with Xcode 9.4.1, by running the following command: +This report was generated on a MacBook Pro (15-inch, Late 2016), with Xcode 10.2.1, by running the following command: ```sh make test_performance | Tests/parsePerformanceTests.rb | Tests/generatePerformanceReport.rb