diff --git a/CHANGELOG.md b/CHANGELOG.md index b87d3f123..c2d48ac21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,38 @@ Release Notes ============= +## 0.53.0 + +Released March 25, 2016 + +**Fixed** + +- `Row.value()` and `DatabaseValue.value()` now raise a fatal error when they can not convert a non-NULL value to the requested type ([documentation](https://github.com/groue/GRDB.swift/#column-values)), effectively preventing silent data loss. + + Use the new `DatabaseValue.failableValue()` method if you need the old behavior that returned nil for failed conversions. + +**New** + +- `Row.databaseValue(atIndex:)` and `Row.databaseValue(named:)` expose the [DatabaseValues](https://github.com/groue/GRDB.swift/#databasevalue) of a row. +- `DatabaseValue.failableValue()` returns nil when a non-NULL value can not be converted to the requested type. + + +## 0.52.1 + +Released March 24, 2016 + +**Fixed** + +- The [query interface](https://github.com/groue/GRDB.swift/#the-query-interface) now generates robust SQL for explicit boolean comparisons. + + ```swift + // SELECT * FROM "pointOfInterests" WHERE "favorite" + PointOfInterest.filter(favorite == true).fetchAll(db) + ``` + + Previous versions used to generate fragile comparisons to 0 and 1 which did badly interpret true values such as 2. + + ## 0.52.0 Released March 21, 2016 @@ -8,7 +40,7 @@ Released March 21, 2016 **New** - Swift 2.2, and Xcode 7.3 -- `Row` adopts Equatable +- `Row` adopts the standard `Equatable` protocol. ## 0.51.2 @@ -17,7 +49,7 @@ Released March 14, 2016 **Fixed** -- A race condition that could prevent `Configuration.fileAttributes` to apply to some database files. +- A race condition that could prevent `Configuration.fileAttributes` from being applied to some database files. ## 0.51.1 diff --git a/GRDB.swift.podspec b/GRDB.swift.podspec index a69de0128..7bda36dda 100644 --- a/GRDB.swift.podspec +++ b/GRDB.swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GRDB.swift' - s.version = '0.52.0' + s.version = '0.53.0' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'A versatile SQLite toolkit for Swift, with WAL mode support.' s.homepage = 'https://github.com/groue/GRDB.swift' diff --git a/GRDB/Core/DatabaseValue.swift b/GRDB/Core/DatabaseValue.swift index 6c051cb28..612ed7dd6 100644 --- a/GRDB/Core/DatabaseValue.swift +++ b/GRDB/Core/DatabaseValue.swift @@ -72,21 +72,23 @@ public struct DatabaseValue { /// Returns the value, converted to the requested type. /// - /// The result is nil if the SQLite value is NULL, or if the SQLite value - /// can not be converted to `Value`. + /// 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. /// - /// Successful conversions include: - /// - /// - Integer and real SQLite values to Swift Int, Int32, Int64, Double and - /// Bool (zero is the only false boolean). - /// - Text SQLite values to Swift String. - /// - Blob SQLite values to NSData. - /// - /// Types that adopt DatabaseValueConvertible can provide more conversions. + /// If this fatal error is unacceptable to you, use the + /// failableValue() method. /// /// - returns: An optional *Value*. + @warn_unused_result public func value() -> Value? { - return Value.fromDatabaseValue(self) + if let value = Value.fromDatabaseValue(self) { + return value + } + guard isNull else { + fatalError("could not convert \(self) to \(Value.self).") + } + return nil } /// Returns the value, converted to the requested type. @@ -94,16 +96,8 @@ public struct DatabaseValue { /// This method crashes if the SQLite value is NULL, or if the SQLite value /// can not be converted to `Value`. /// - /// Successful conversions include: - /// - /// - Integer and real SQLite values to Swift Int, Int32, Int64, Double and - /// Bool (zero is the only false boolean). - /// - Text SQLite values to Swift String. - /// - Blob SQLite values to NSData. - /// - /// Types that adopt DatabaseValueConvertible can provide more conversions. - /// /// - returns: A *Value*. + @warn_unused_result public func value() -> Value { guard let value = Value.fromDatabaseValue(self) as Value? else { fatalError("could not convert \(self) to \(Value.self).") @@ -111,6 +105,20 @@ public struct DatabaseValue { return value } + /// Returns the value, converted to the requested type. + /// + /// The result is nil if the SQLite value is NULL, or if the SQLite value + /// can not be converted to `Value`. + /// + /// This method can return nil for non-NULL values. If this is unacceptable + /// to you, use the value() method. + /// + /// - returns: An optional *Value*. + @warn_unused_result + public func failableValue() -> Value? { + return Value.fromDatabaseValue(self) + } + // MARK: - Not Public diff --git a/GRDB/Core/Row.swift b/GRDB/Core/Row.swift index 5c4c70c06..705124ee7 100644 --- a/GRDB/Core/Row.swift +++ b/GRDB/Core/Row.swift @@ -125,12 +125,9 @@ extension Row { /// /// Indexes span from 0 for the leftmost column to (row.count - 1) for the /// righmost column. + @warn_unused_result public func value(atIndex index: Int) -> DatabaseValueConvertible? { precondition(index >= 0 && index < count, "row index out of range") - return unsafeValue(atIndex: index) - } - - private func unsafeValue(atIndex index: Int) -> DatabaseValueConvertible? { return impl.databaseValue(atIndex: index).value() } @@ -139,23 +136,12 @@ extension Row { /// Indexes span from 0 for the leftmost column to (row.count - 1) for the /// righmost column. /// - /// The result is nil if the fetched SQLite value is NULL, or if the SQLite - /// value can not be converted to `Value`. - /// - /// Successful conversions include: - /// - /// - Integer and real SQLite values to Swift Int, Int32, Int64, Double and - /// Bool (zero is the only false boolean). - /// - Text SQLite values to Swift String. - /// - Blob SQLite values to NSData. - /// - /// Types that adopt DatabaseValueConvertible can provide more conversions. + /// 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. + @warn_unused_result public func value(atIndex index: Int) -> Value? { precondition(index >= 0 && index < count, "row index out of range") - return unsafeValue(atIndex: index) - } - - private func unsafeValue(atIndex index: Int) -> Value? { return impl.databaseValue(atIndex: index).value() } @@ -164,36 +150,17 @@ extension Row { /// Indexes span from 0 for the leftmost column to (row.count - 1) for the /// righmost column. /// - /// The result is nil if the fetched SQLite value is NULL, or if the SQLite - /// value can not be converted to `Value`. - /// - /// Successful conversions include: - /// - /// - Integer and real SQLite values to Swift Int, Int32, Int64, Double and - /// Bool (zero is the only false boolean). - /// - Text SQLite values to Swift String. - /// - Blob SQLite values to NSData. - /// - /// Types that adopt DatabaseValueConvertible and StatementColumnConvertible - /// can provide more conversions. + /// 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. /// /// 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). + @warn_unused_result public func value>(atIndex index: Int) -> Value? { precondition(index >= 0 && index < count, "row index out of range") - return unsafeValue(atIndex: index) - } - - private func unsafeValue>(atIndex index: Int) -> Value? { - let sqliteStatement = self.sqliteStatement - guard sqliteStatement != nil else { - return impl.databaseValue(atIndex: index).value() - } - guard sqlite3_column_type(sqliteStatement, Int32(index)) != SQLITE_NULL else { - return nil - } - return Value.init(sqliteStatement: sqliteStatement, index: Int32(index)) + return fastValue(atUncheckedIndex: index) } /// Returns the value at given index, converted to the requested type. @@ -203,21 +170,9 @@ extension Row { /// /// This method crashes if the fetched SQLite value is NULL, or if the /// SQLite value can not be converted to `Value`. - /// - /// Successful conversions include: - /// - /// - Integer and real SQLite values to Swift Int, Int32, Int64, Double and - /// Bool (zero is the only false boolean). - /// - Text SQLite values to Swift String. - /// - Blob SQLite values to NSData. - /// - /// Types that adopt DatabaseValueConvertible can provide more conversions. + @warn_unused_result public func value(atIndex index: Int) -> Value { precondition(index >= 0 && index < count, "row index out of range") - return unsafeValue(atIndex: index) - } - - private func unsafeValue(atIndex index: Int) -> Value { return impl.databaseValue(atIndex: index).value() } @@ -229,40 +184,23 @@ extension Row { /// This method crashes if the fetched SQLite value is NULL, or if the /// SQLite value can not be converted to `Value`. /// - /// Successful conversions include: - /// - /// - Integer and real SQLite values to Swift Int, Int32, Int64, Double and - /// Bool (zero is the only false boolean). - /// - Text SQLite values to Swift String. - /// - Blob SQLite values to NSData. - /// - /// Types that adopt DatabaseValueConvertible and StatementColumnConvertible - /// can provide more conversions. - /// /// 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). + @warn_unused_result public func value>(atIndex index: Int) -> Value { precondition(index >= 0 && index < count, "row index out of range") - return unsafeValue(atIndex: index) - } - - private func unsafeValue>(atIndex index: Int) -> Value { - let sqliteStatement = self.sqliteStatement - guard sqliteStatement != nil else { - return impl.databaseValue(atIndex: index).value() - } - guard sqlite3_column_type(sqliteStatement, Int32(index)) != SQLITE_NULL else { - fatalError("could not convert NULL to \(Value.self).") - } - return Value.init(sqliteStatement: sqliteStatement, index: Int32(index)) + return fastValue(atUncheckedIndex: index) } /// Returns Int64, Double, String, NSData or nil, depending on the value /// stored at the given column. /// - /// Column name is case-insensitive. The result is nil if the row does not - /// contain the column. + /// Column name lookup is case-insensitive, and when several columns have + /// the same name, the leftmost column is considered. + /// + /// The result is nil if the row does not contain the column. + @warn_unused_result public func value(named columnName: String) -> DatabaseValueConvertible? { // IMPLEMENTATION NOTE // This method has a single know use case: checking if the value is nil, @@ -274,105 +212,81 @@ extension Row { guard let index = impl.indexOfColumn(named: columnName) else { return nil } - return unsafeValue(atIndex: index) + return impl.databaseValue(atIndex: index).value() } /// Returns the value at given column, converted to the requested type. /// - /// Column name is case-insensitive. The result is nil if the row does not - /// contain the column, or if the fetched SQLite value is NULL, or if the - /// SQLite value can not be converted to `Value`. + /// Column name lookup is case-insensitive, and when several columns have + /// the same name, the leftmost column is considered. /// - /// Successful conversions include: - /// - /// - Integer and real SQLite values to Swift Int, Int32, Int64, Double and - /// Bool (zero is the only false boolean). - /// - Text SQLite values to Swift String. - /// - Blob SQLite values to NSData. - /// - /// Types that adopt DatabaseValueConvertible can provide more conversions. + /// 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. + @warn_unused_result public func value(named columnName: String) -> Value? { guard let index = impl.indexOfColumn(named: columnName) else { return nil } - return unsafeValue(atIndex: index) + return impl.databaseValue(atIndex: index).value() } /// Returns the value at given column, converted to the requested type. /// - /// Column name is case-insensitive. The result is nil if the row does not - /// contain the column, or if the fetched SQLite value is NULL, or if the - /// SQLite value can not be converted to `Value`. + /// Column name lookup is case-insensitive, and when several columns have + /// the same name, the leftmost column is considered. /// - /// Successful conversions include: - /// - /// - Integer and real SQLite values to Swift Int, Int32, Int64, Double and - /// Bool (zero is the only false boolean). - /// - Text SQLite values to Swift String. - /// - Blob SQLite values to NSData. - /// - /// Types that adopt DatabaseValueConvertible and StatementColumnConvertible - /// can provide more conversions. + /// 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. /// /// 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). + @warn_unused_result public func value>(named columnName: String) -> Value? { guard let index = impl.indexOfColumn(named: columnName) else { return nil } - return unsafeValue(atIndex: index) + return fastValue(atUncheckedIndex: index) } /// Returns the value at given column, converted to the requested type. /// - /// Column name is case-insensitive. If the row does not contain the column, - /// a fatal error is raised. + /// Column name lookup is case-insensitive, and when several columns have + /// the same name, the leftmost column is considered. + /// + /// If the row does not contain the column, a fatal error is raised. /// /// This method crashes if the fetched SQLite value is NULL, or if the /// SQLite value can not be converted to `Value`. - /// - /// Successful conversions include: - /// - /// - Integer and real SQLite values to Swift Int, Int32, Int64, Double and - /// Bool (zero is the only false boolean). - /// - Text SQLite values to Swift String. - /// - Blob SQLite values to NSData. - /// - /// Types that adopt DatabaseValueConvertible can provide more conversions. + @warn_unused_result public func value(named columnName: String) -> Value { guard let index = impl.indexOfColumn(named: columnName) else { fatalError("no such column: \(columnName)") } - return unsafeValue(atIndex: index) + return impl.databaseValue(atIndex: index).value() } /// Returns the value at given column, converted to the requested type. /// - /// Column name is case-insensitive. If the row does not contain the column, - /// a fatal error is raised. + /// Column name lookup is case-insensitive, and when several columns have + /// the same name, the leftmost column is considered. + /// + /// If the row does not contain the column, a fatal error is raised. /// /// This method crashes if the fetched SQLite value is NULL, or if the /// SQLite value can not be converted to `Value`. /// - /// Successful conversions include: - /// - /// - Integer and real SQLite values to Swift Int, Int32, Int64, Double and - /// Bool (zero is the only false boolean). - /// - Text SQLite values to Swift String. - /// - Blob SQLite values to NSData. - /// - /// Types that adopt DatabaseValueConvertible and StatementColumnConvertible - /// can provide more conversions. - /// /// 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). + @warn_unused_result public func value>(named columnName: String) -> Value { guard let index = impl.indexOfColumn(named: columnName) else { fatalError("no such column: \(columnName)") } - return unsafeValue(atIndex: index) + return fastValue(atUncheckedIndex: index) } /// Returns the optional `NSData` at given index. @@ -380,11 +294,12 @@ extension Row { /// Indexes span from 0 for the leftmost column to (row.count - 1) for the /// righmost column. /// - /// The result is nil if the fetched SQLite value is NULL, or if the SQLite - /// value is not a blob. + /// If the SQLite value is NULL, the result is nil. If the SQLite value can + /// not be converted to NSData, a fatal error is raised. /// - /// Otherwise, the returned data does not owns its bytes: it must not be - /// used longer than the row's lifetime. + /// The returned data does not owns its bytes: it must not be used longer + /// than the row's lifetime. + @warn_unused_result public func dataNoCopy(atIndex index: Int) -> NSData? { precondition(index >= 0 && index < count, "row index out of range") return impl.dataNoCopy(atIndex: index) @@ -392,17 +307,73 @@ extension Row { /// Returns the optional `NSData` at given column. /// - /// Column name is case-insensitive. The result is nil if the row does not - /// contain the column, or if the fetched SQLite value is NULL, or if the - /// SQLite value can not be converted to NSData. + /// Column name lookup is case-insensitive, and when several columns have + /// the same name, the leftmost column is considered. /// - /// Otherwise, the returned data does not owns its bytes: it must not be - /// used longer than the row's lifetime. + /// If the column is missing or if the SQLite value is NULL, the result is + /// nil. If the SQLite value can not be converted to NSData, a fatal error + /// is raised. + /// + /// The returned data does not owns its bytes: it must not be used longer + /// than the row's lifetime. + @warn_unused_result public func dataNoCopy(named columnName: String) -> NSData? { guard let index = impl.indexOfColumn(named: columnName) else { return nil } - return dataNoCopy(atIndex: index) + return impl.dataNoCopy(atIndex: index) + } + + + // MARK: - Extracting DatabaseValue + + /// Returns the `DatabaseValue` at given index. + /// + /// Indexes span from 0 for the leftmost column to (row.count - 1) for the + /// righmost column. + @warn_unused_result + public func databaseValue(atIndex index: Int) -> DatabaseValue { + precondition(index >= 0 && index < count, "row index out of range") + return impl.databaseValue(atIndex: index) + } + + /// Returns the `DatabaseValue` at given column. + /// + /// Column name lookup is case-insensitive, and when several columns have + /// the same name, the leftmost column is considered. + @warn_unused_result + public func databaseValue(named columnName: String) -> DatabaseValue { + guard let index = impl.indexOfColumn(named: columnName) else { + fatalError("no such column: \(columnName)") + } + return impl.databaseValue(atIndex: index) + } + + + // MARK: - Helpers + + @warn_unused_result + private func fastValue>(atUncheckedIndex index: Int) -> Value? { + let sqliteStatement = self.sqliteStatement + guard sqliteStatement != nil else { + return impl.databaseValue(atIndex: index).value() + } + guard sqlite3_column_type(sqliteStatement, Int32(index)) != SQLITE_NULL else { + return nil + } + return Value.init(sqliteStatement: sqliteStatement, index: Int32(index)) + } + + @warn_unused_result + private func fastValue>(atUncheckedIndex index: Int) -> Value { + let sqliteStatement = self.sqliteStatement + guard sqliteStatement != nil else { + return impl.databaseValue(atIndex: index).value() + } + guard sqlite3_column_type(sqliteStatement, Int32(index)) != SQLITE_NULL else { + fatalError("could not convert NULL to \(Value.self).") + } + return Value.init(sqliteStatement: sqliteStatement, index: Int32(index)) } } @@ -410,15 +381,11 @@ extension Row { // MARK: - Extracting DatabaseValue - /// Returns a DatabaseValue, the intermediate type between SQLite and your - /// values, if and only if the row contains the requested column. + /// Returns the `DatabaseValue` at given column, if the row contains the + /// requested column. /// - /// // Test if the column `name` is present: - /// if let databaseValue = row["name"] { - /// let name: String? = databaseValue.value() - /// } - /// - /// This method is case-insensitive. + /// Column name lookup is case-insensitive, and when several columns have + /// the same name, the leftmost column is considered. /// /// - parameter columnName: A column name. /// - returns: A DatabaseValue if the row contains the requested column. diff --git a/GRDB/FetchRequest/SQLOperator.swift b/GRDB/FetchRequest/SQLOperator.swift index ce1f28ae6..50c9630f8 100644 --- a/GRDB/FetchRequest/SQLOperator.swift +++ b/GRDB/FetchRequest/SQLOperator.swift @@ -7,6 +7,21 @@ public func == (lhs: _SQLDerivedExpressionType, rhs: _SQLExpressionType?) -> _SQ return .Equal(lhs.sqlExpression, rhs?.sqlExpression ?? .Value(nil)) } +/// Returns an SQL expression that compares two values. +/// +/// See https://github.com/groue/GRDB.swift/#sql-operators +public func == (lhs: _SQLDerivedExpressionType, rhs: protocol<_SQLExpressionType, BooleanType>?) -> _SQLExpression { + if let rhs = rhs { + if rhs.boolValue { + return lhs.sqlExpression + } else { + return .Not(lhs.sqlExpression) + } + } else { + return .Equal(lhs.sqlExpression, .Value(nil)) + } +} + /// Returns an SQL expression that compares two values. /// /// See https://github.com/groue/GRDB.swift/#sql-operators @@ -14,6 +29,21 @@ public func == (lhs: _SQLExpressionType?, rhs: _SQLDerivedExpressionType) -> _SQ return .Equal(lhs?.sqlExpression ?? .Value(nil), rhs.sqlExpression) } +/// Returns an SQL expression that compares two values. +/// +/// See https://github.com/groue/GRDB.swift/#sql-operators +public func == (lhs: protocol<_SQLExpressionType, BooleanType>?, rhs: _SQLDerivedExpressionType) -> _SQLExpression { + if let lhs = lhs { + if lhs.boolValue { + return rhs.sqlExpression + } else { + return .Not(rhs.sqlExpression) + } + } else { + return .Equal(.Value(nil), rhs.sqlExpression) + } +} + /// Returns an SQL expression that compares two values. /// /// See https://github.com/groue/GRDB.swift/#sql-operators @@ -31,6 +61,21 @@ public func != (lhs: _SQLDerivedExpressionType, rhs: _SQLExpressionType?) -> _SQ return .NotEqual(lhs.sqlExpression, rhs?.sqlExpression ?? .Value(nil)) } +/// Returns an SQL expression that compares two values. +/// +/// See https://github.com/groue/GRDB.swift/#sql-operators +public func != (lhs: _SQLDerivedExpressionType, rhs: protocol<_SQLExpressionType, BooleanType>?) -> _SQLExpression { + if let rhs = rhs { + if rhs.boolValue { + return .Not(lhs.sqlExpression) + } else { + return lhs.sqlExpression + } + } else { + return .NotEqual(lhs.sqlExpression, .Value(nil)) + } +} + /// Returns an SQL expression that compares two values. /// /// See https://github.com/groue/GRDB.swift/#sql-operators @@ -38,6 +83,21 @@ public func != (lhs: _SQLExpressionType?, rhs: _SQLDerivedExpressionType) -> _SQ return .NotEqual(lhs?.sqlExpression ?? .Value(nil), rhs.sqlExpression) } +/// Returns an SQL expression that compares two values. +/// +/// See https://github.com/groue/GRDB.swift/#sql-operators +public func != (lhs: protocol<_SQLExpressionType, BooleanType>?, rhs: _SQLDerivedExpressionType) -> _SQLExpression { + if let lhs = lhs { + if lhs.boolValue { + return .Not(rhs.sqlExpression) + } else { + return rhs.sqlExpression + } + } else { + return .NotEqual(.Value(nil), rhs.sqlExpression) + } +} + /// Returns an SQL expression that compares two values. /// /// See https://github.com/groue/GRDB.swift/#sql-operators diff --git a/README.md b/README.md index 0e2602f28..055e2705d 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ You should give it a try. --- -**March 14, 2016: GRDB.swift 0.52.0 is out** ([changelog](CHANGELOG.md)). Follow [@groue](http://twitter.com/groue) on Twitter for release announcements and usage tips. +**March 25, 2016: GRDB.swift 0.53.0 is out** ([changelog](CHANGELOG.md)). Follow [@groue](http://twitter.com/groue) on Twitter for release announcements and usage tips. -**Requirements**: iOS 7.0+ / OSX 10.9+, Xcode 7+ +**Requirements**: iOS 7.0+ / OSX 10.9+, Xcode 7.3+ ### Usage @@ -97,7 +97,7 @@ let favorite = SQLColumn("favorite") let paris = PointOfInterest.fetchOne(dbQueue, key: 1) // PointOfInterest? let berlin = PointOfInterest.filter(title == "Berlin").fetchOne(dbQueue) // PointOfInterest? let favoritePois = PointOfInterest // [PointOfInterest] - .filter(favorite) + .filter(favorite == true) .order(title) .fetchAll(dbQueue) ``` @@ -110,7 +110,7 @@ Documentation **Reference** -- [GRDB Reference](http://cocoadocs.org/docsets/GRDB.swift/0.52.0/index.html) (on cocoadocs.org) +- [GRDB Reference](http://cocoadocs.org/docsets/GRDB.swift/0.53.0/index.html) (on cocoadocs.org) **Getting started** @@ -157,7 +157,7 @@ To use GRDB with CocoaPods, specify in your Podfile: source 'https://github.com/CocoaPods/Specs.git' use_frameworks! -pod 'GRDB.swift', '~> 0.52.0' +pod 'GRDB.swift', '~> 0.53.0' ``` @@ -168,7 +168,7 @@ pod 'GRDB.swift', '~> 0.52.0' To use GRDB with Carthage, specify in your Cartfile: ``` -github "groue/GRDB.swift" ~> 0.52.0 +github "groue/GRDB.swift" ~> 0.53.0 ``` @@ -271,7 +271,7 @@ let dbQueue = try DatabaseQueue( configuration: config) ``` -See [Configuration](http://cocoadocs.org/docsets/GRDB.swift/0.52.0/Structs/Configuration.html) for more details. +See [Configuration](http://cocoadocs.org/docsets/GRDB.swift/0.53.0/Structs/Configuration.html) for more details. > :bowtie: **Tip**: see [DemoApps/GRDBDemoiOS/Database.swift](DemoApps/GRDBDemoiOS/GRDBDemoiOS/Database.swift) for a sample code that sets up a database queue. @@ -350,7 +350,7 @@ let dbPool = try DatabasePool( maximumReaderCount: 10) // The default is 5 ``` -See [Configuration](http://cocoadocs.org/docsets/GRDB.swift/0.52.0/Structs/Configuration.html) for more details. +See [Configuration](http://cocoadocs.org/docsets/GRDB.swift/0.53.0/Structs/Configuration.html) for more details. Database pools are more memory-hungry than database queues. See [Memory Management](#memory-management) for more information. @@ -547,6 +547,7 @@ Type.fetchOne(...) // Type? - [Fetching Rows](#fetching-rows) - [Column Values](#column-values) +- [DatabaseValue](#databasevalue) - [Rows as Dictionaries](#rows-as-dictionaries) @@ -591,7 +592,7 @@ See [Values](#values) for more information on supported arguments types (Bool, I ```swift let name: String = row.value(atIndex: 0) // 0 is the leftmost column -let name: String = row.value(named: "name") +let name: String = row.value(named: "name") // lookup is case-insensitive ``` Make sure to ask for an optional when the value may be NULL: @@ -607,7 +608,7 @@ let bookCount: Int = row.value(named: "bookCount") let bookCount64: Int64 = row.value(named: "bookCount") let hasBooks: Bool = row.value(named: "bookCount") // false when 0 -let dateString: String = row.value(named: "date") // "2015-09-11 18:14:15.123" +let string: String = row.value(named: "date") // "2015-09-11 18:14:15.123" let date: NSDate = row.value(named: "date") // NSDate self.date = row.value(named: "date") // Depends on the type of the property. ``` @@ -631,29 +632,33 @@ Generally speaking, you can extract the type you need, *provided it can be conve - **Successful conversions include:** - - All numeric (integer and real) SQLite values to Swift Int, Int32, Int64, Double and Bool (zero is the only false boolean). + - All numeric (integer and real) SQLite values to numeric Swift types (Int, Int32, Int64, Double), plus Bool (zero is the only false boolean). - Text SQLite values to Swift String. - Blob SQLite values to NSData. See [Values](#values) for more information on supported types (Bool, Int, String, NSDate, Swift enums, etc.) -- **Invalid conversions return nil.** +- **Invalid conversions throw a fatal error.** + + NULL can not be turned into a non-optional: - ```swift - let row = Row.fetchOne(db, "SELECT 'foo'")! - row.value(atIndex: 0) as String // "foo" - row.value(atIndex: 0) as NSDate? // nil - row.value(atIndex: 0) as NSDate // fatal error: could not convert "foo" to NSDate. - ``` - - Notably, NULL won't turn to anything: - ```swift let row = Row.fetchOne(db, "SELECT NULL")! row.value(atIndex: 0) as Int? // nil row.value(atIndex: 0) as Int // fatal error: could not convert NULL to Int. ``` - + + Non-NULL values are not silently discarded: + + ```swift + let row = Row.fetchOne(db, "SELECT 'foo'")! + row.value(atIndex: 0) as String // "foo" + row.value(atIndex: 0) as NSDate? // fatal error: could not convert "foo" to NSDate. + row.value(atIndex: 0) as NSDate // fatal error: could not convert "foo" to NSDate. + ``` + + See [DatabaseValue.failableValue()](#databasevalue) method below if you need weak conversions. + - **Missing columns return nil.** ```swift @@ -664,56 +669,74 @@ Generally speaking, you can extract the type you need, *provided it can be conve You can explicitly check for a column presence with the `hasColumn` method. -- **The convenience conversions of SQLite, such as Blob to String, String to Int, or huge Double values to Int, are not guaranteed to apply.** You must not rely on them. +- **SQLite has a weak type system, and provides [convenience conversions](https://www.sqlite.org/c3ref/column_blob.html) that can turn Blob to String, String to Int, etc.** + + GRDB will sometimes let those conversions go through: + + ```swift + dbQueue.inDatabase { db in + for row in Row.fetch(db, "SELECT 'foo'") { + row.value(atIndex: 0) as Int // 0 + } + } + ``` + + Don't freak out: those conversions did not prevent SQLite from becoming the immensely successful database engine you want to use. And GRDB adds safety checks described just above. You can also prevent those convenience conversions altogether by using the [DatabaseValue](#databasevalue) type. -#### Rows as Dictionaries +#### DatabaseValue -**Rows can be seen as dictionaries** of `DatabaseValue`, an intermediate type between SQLite and your values: +**DatabaseValue is an intermediate type between SQLite and your values, which gives information about the raw value stored in the database.** ```swift -// Test if the column `date` is present: -if let databaseValue = row["date"] { - - // Pick the type you need: - let dateString: String = databaseValue.value() // "2015-09-11 18:14:15.123" - let date: NSDate = databaseValue.value() // NSDate - self.date = databaseValue.value() // Depends on the type of the property. - - // Check for NULL: - if databaseValue.isNull { - print("NULL") - } - - // The five SQLite storage classes: - switch databaseValue.storage { - case .Null: - print("NULL") - case .Int64(let int64): - print("Int64: \(int64)") - case .Double(let double): - print("Double: \(double)") - case .String(let string): - print("String: \(string)") - case .Blob(let data): - print("NSData: \(data)") - } +let dbv = row.databaseValue(atIndex: 0) // 0 is the leftmost column +let dbv = row.databaseValue(named: "name") // lookup is case-insensitive + +// Check for NULL: +dbv.isNull // Bool + +// All the five storage classes supported by SQLite: +switch dbv.storage { +case .Null: print("NULL") +case .Int64(let int64): print("Int64: \(int64)") +case .Double(let double): print("Double: \(double)") +case .String(let string): print("String: \(string)") +case .Blob(let data): print("NSData: \(data)") +} +``` + +You can extract [values](#values) (Bool, Int, String, NSDate, Swift enums, etc.) from DatabaseValue, just like you do from [rows](#column-values): + +```swift +let dbv = row.databaseValue(named: "bookCount") +let bookCount: Int = dbv.value() +let bookCount64: Int64 = dbv.value() +let hasBooks: Bool = dbv.value() // false when 0 + +let dbv = row.databaseValue(named: "date") +let string: String = dbv.value() // "2015-09-11 18:14:15.123" +let date: NSDate = dbv.value() // NSDate +self.date = dbv.value() // Depends on the type of the property. +``` + +Use the `failableValue()` method when you want to check if the value can be converted to the requested type: + +```swift +if let date: NSDate? = dbv.failableValue() { + // conversion successful } ``` -**You can build rows from scratch** using the dictionary and NSDictionary initializers (see [Values](#values) for more information on supported types): +#### Rows as Dictionaries + +Row adopts the standard [CollectionType](https://developer.apple.com/library/ios/documentation/Swift/Reference/Swift_CollectionType_Protocol/index.html) protocol, and can be seen as a dictionary of [DatabaseValue](#databasevalue): ```swift -let row = Row(["name": "foo", "date": nil]) -``` - - -**Rows are standard [collections](https://developer.apple.com/library/ios/documentation/Swift/Reference/Swift_CollectionType_Protocol/index.html)**: - -```swift -// the number of columns -row.count +// Test if the column `date` is present: +if let databaseValue = row["date"] { + ... +} // All the (columnName, databaseValue) tuples, from left to right: for (columnName, databaseValue) in row { @@ -721,8 +744,13 @@ for (columnName, databaseValue) in row { } ``` +**You can build rows from dictionaries** (standard Swift dictionaries and NSDictionary). See [Values](#values) for more information on supported types: -**Rows may contain duplicate keys**: +```swift +let row = Row(["name": "foo", "date": nil]) +``` + +Yet rows are not real dictionaries, because they may contain duplicate keys: ```swift let row = Row.fetchOne(db, "SELECT 1 AS foo, 2 AS foo")! @@ -1004,12 +1032,12 @@ for rows in Row.fetch(db, "SELECT * FROM wines") { } ``` -Database values that do not match any enum case are extracted as nil: +When a database value does not match any enum case, you get a fatal error: ```swift let row = Row.fetchOne(db, "SELECT 'Syrah'")! row.value(atIndex: 0) as String // "Syrah" -row.value(atIndex: 0) as Grape? // nil +row.value(atIndex: 0) as Grape? // fatal error: could not convert "Syrah" to Grape. row.value(atIndex: 0) as Grape // fatal error: could not convert "Syrah" to Grape. ``` @@ -1142,7 +1170,8 @@ let unicodeUpper = DatabaseFunction( argumentCount: 1, // Number of arguments pure: true, // True means that the result only depends on input function: { (databaseValues: [DatabaseValue]) in - guard let string: String = databaseValues[0].value() else { + // Return NULL for everything that is not a string: + guard let string: String = databaseValues[0].failableValue() else { return nil } return string.uppercaseString @@ -1156,7 +1185,7 @@ String.fetchOne(dbQueue, "SELECT unicodeUpper(?)", arguments: ["Jérôme"])! String.fetchOne(dbQueue, "SELECT upper(?)", arguments: ["Jérôme"])! ``` -The *function* argument takes an array of [DatabaseValue](#rows-as-dictionaries), and returns any valid [value](#values) (Bool, Int, String, NSDate, Swift enums, etc.) The number of database values is guaranteed to be *argumentCount*. +The *function* argument takes an array of [DatabaseValue](#databasevalue), and returns any valid [value](#values) (Bool, Int, String, NSDate, Swift enums, etc.) The number of database values is guaranteed to be *argumentCount*. SQLite has the opportunity to perform additional optimizations when functions are "pure", which means that their result only depends on their arguments. So make sure to set the *pure* argument to true when possible. @@ -2023,7 +2052,7 @@ Feed [requests](#requests) with SQL expressions built from your Swift code: ```swift // SELECT * FROM "events" // WHERE ("userId" IN (SELECT "id" FROM "persons" WHERE "verified")) - let verifiedUsers = User.filter(Col.verified) + let verifiedUsers = User.filter(Col.verified == true) Event.filter(verifiedUsers.select(Col.id).contains(Col.userId)) ``` @@ -2516,7 +2545,7 @@ GRDB ships with support for two concurrency modes: **Rule 1: Your application should have a unique instance of DatabaseQueue or DatabasePool connected to a database file. You may experience concurrency trouble if you do otherwise.** -Now let's talk about the consistency of your data: you generally want to prevent you application threads to conflict. +Now let's talk about the consistency of your data: you generally want to prevent your application threads from any conflict. Since it is difficult to synchronize threads, both [DatabaseQueue](#database-queues) and [DatabasePool](#database-pools) offer methods that isolate your statements, and guarantee a stable database state regardless of parallel threads: @@ -2533,7 +2562,7 @@ dbQueue.inDatabase { db in // or dbPool.read, or dbPool.write } ``` -*The unprotected access to queue and pools is very different.* The two lines below are equivalent to two consecutive calls to `dbQueue.inDatabase` or `dbPool.read`, with the opportunity for other threads to sneak in the middle: +*However, isolation is lost when you access database queues and pools in an unprotected fashion.* The two lines below are equivalent to two consecutive calls to `dbQueue.inDatabase` or `dbPool.read`, with the opportunity for other threads to sneak in between: ```swift // Those two values may be different because some other thread may have inserted @@ -2545,10 +2574,11 @@ let count2 = PointOfInterest.fetchCount(dbQueue) // or dbPool That being said, unprotected access can do everything but iterate the memory-efficient [database sequences](#fetching-methods): ```swift +// Unprotected access, for advanced users only: try dbQueue.execute("INSERT ...") let rows = Row.fetchAll(dbQueue, "SELECT ...") try PointOfInterest(...).insert(dbQueue) -let pois = PointOfInterest.filter(favorite).order(title).fetchAll(dbQueue) +let pois = PointOfInterest.filter(favorite == true).order(title).fetchAll(dbQueue) ``` **Rule 2: Use the safe `inDatabase`, `inTransaction`, `read`, `write` and `writeInTransaction` methods unless you know what you are doing.** @@ -2558,7 +2588,7 @@ let pois = PointOfInterest.filter(favorite).order(title).fetchAll(dbQueue) SQLite concurrency is a wiiide topic. -First have a detailed look at the full API of [DatabaseQueue](http://cocoadocs.org/docsets/GRDB.swift/0.52.0/Classes/DatabaseQueue.html) and [DatabasePool](http://cocoadocs.org/docsets/GRDB.swift/0.52.0/Classes/DatabasePool.html). Both adopt the [DatabaseReader](http://cocoadocs.org/docsets/GRDB.swift/0.52.0/Protocols/DatabaseReader.html) and [DatabaseWriter](http://cocoadocs.org/docsets/GRDB.swift/0.52.0/Protocols/DatabaseWriter.html) protocols. +First have a detailed look at the full API of [DatabaseQueue](http://cocoadocs.org/docsets/GRDB.swift/0.53.0/Classes/DatabaseQueue.html) and [DatabasePool](http://cocoadocs.org/docsets/GRDB.swift/0.53.0/Classes/DatabasePool.html). Both adopt the [DatabaseReader](http://cocoadocs.org/docsets/GRDB.swift/0.53.0/Protocols/DatabaseReader.html) and [DatabaseWriter](http://cocoadocs.org/docsets/GRDB.swift/0.53.0/Protocols/DatabaseWriter.html) protocols. If the built-in queues and pools do not fit your needs, or if you can not guarantee that a single queue or pool is accessing your database file, you may have a look at: diff --git a/Support/Info.plist b/Support/Info.plist index 2f4db157a..e9ece2051 100644 --- a/Support/Info.plist +++ b/Support/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.52.0 + 0.53.0 CFBundleSignature ???? CFBundleVersion diff --git a/TODO.md b/TODO.md index 04cfcc215..9fb6a0554 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,5 @@ - [ ] Document the change in awakeFromFetch() in CHANGELOG.md +- [ ] Support for resource values (see https://developer.apple.com/library/ios/qa/qa1719/_index.html) - [ ] DOC: Write an app like http://www.appcoda.com/swiftydb/ ? - [ ] DOC: Since commit e6010e334abdf98eb9f62c1d6abbb2a9e8cd7d19, one can not use the raw SQLite API without importing the SQLite module for the platform. We need to document that. - [ ] Query builder @@ -18,7 +19,6 @@ Not sure: - [ ] Refactor errors in a single type? - [ ] Since Records' primary key are infered, no operation is possible on the primary key unless we have a Database instance. It's impossible to define the record.primaryKey property, or to provide a copy() function that does not clone the primary key: they miss the database that is the only object aware of the primary key. Should we change our mind, and have Record explicitly expose their primary key again? - [ ] Have Record adopt Hashable and Equatable, based on primary key. Problem: we can't do it know because we don't know the primary key until we have a database connection. -- [ ] Conversion should crash when type mismatch (Optional.fetchOne(db, "SELECT 1")) Require changes in the Swift language: diff --git a/Tests/Public/Core/DatabaseValueConvertible/DatabaseValueConversionTests.swift b/Tests/Public/Core/DatabaseValueConvertible/DatabaseValueConversionTests.swift index 816d01ea2..00d7639ae 100644 --- a/Tests/Public/Core/DatabaseValueConvertible/DatabaseValueConversionTests.swift +++ b/Tests/Public/Core/DatabaseValueConvertible/DatabaseValueConversionTests.swift @@ -68,15 +68,17 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Text) // Check GRDB conversions from Text storage: - XCTAssertTrue((dbv.value() as Bool?) == nil) - XCTAssertTrue((dbv.value() as Int?) == nil) - XCTAssertTrue((dbv.value() as Int32?) == nil) - XCTAssertTrue((dbv.value() as Int64?) == nil) - XCTAssertTrue((dbv.value() as Double?) == nil) + XCTAssertTrue((dbv.failableValue() as Bool?) == nil) + XCTAssertTrue((dbv.failableValue() as Int?) == nil) + XCTAssertTrue((dbv.failableValue() as Int32?) == nil) + XCTAssertTrue((dbv.failableValue() as Int64?) == nil) + XCTAssertTrue((dbv.failableValue() as Double?) == nil) + XCTAssertEqual((dbv.failableValue() as String?)!, "0") + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as String?)!, "0") XCTAssertEqual((dbv.value() as String), "0") - XCTAssertTrue((dbv.value() as NSData?) == nil) - + return .Rollback } @@ -88,14 +90,16 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Text) // Check GRDB conversions from Text storage: - XCTAssertTrue((dbv.value() as Bool?) == nil) - XCTAssertTrue((dbv.value() as Int?) == nil) - XCTAssertTrue((dbv.value() as Int32?) == nil) - XCTAssertTrue((dbv.value() as Int64?) == nil) - XCTAssertTrue((dbv.value() as Double?) == nil) + XCTAssertTrue((dbv.failableValue() as Bool?) == nil) + XCTAssertTrue((dbv.failableValue() as Int?) == nil) + XCTAssertTrue((dbv.failableValue() as Int32?) == nil) + XCTAssertTrue((dbv.failableValue() as Int64?) == nil) + XCTAssertTrue((dbv.failableValue() as Double?) == nil) + XCTAssertEqual((dbv.failableValue() as String?)!, "0") + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as String?)!, "0") XCTAssertEqual((dbv.value() as String), "0") - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -108,14 +112,16 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Text) // Check GRDB conversions from Text storage: - XCTAssertTrue((dbv.value() as Bool?) == nil) - XCTAssertTrue((dbv.value() as Int?) == nil) - XCTAssertTrue((dbv.value() as Int32?) == nil) - XCTAssertTrue((dbv.value() as Int64?) == nil) - XCTAssertTrue((dbv.value() as Double?) == nil) + XCTAssertTrue((dbv.failableValue() as Bool?) == nil) + XCTAssertTrue((dbv.failableValue() as Int?) == nil) + XCTAssertTrue((dbv.failableValue() as Int32?) == nil) + XCTAssertTrue((dbv.failableValue() as Int64?) == nil) + XCTAssertTrue((dbv.failableValue() as Double?) == nil) + XCTAssertEqual((dbv.failableValue() as String?)!, "0") + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as String?)!, "0") XCTAssertEqual((dbv.value() as String), "0") - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -128,14 +134,16 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Text) // Check GRDB conversions from Text storage: - XCTAssertTrue((dbv.value() as Bool?) == nil) - XCTAssertTrue((dbv.value() as Int?) == nil) - XCTAssertTrue((dbv.value() as Int32?) == nil) - XCTAssertTrue((dbv.value() as Int64?) == nil) - XCTAssertTrue((dbv.value() as Double?) == nil) + XCTAssertTrue((dbv.failableValue() as Bool?) == nil) + XCTAssertTrue((dbv.failableValue() as Int?) == nil) + XCTAssertTrue((dbv.failableValue() as Int32?) == nil) + XCTAssertTrue((dbv.failableValue() as Int64?) == nil) + XCTAssertTrue((dbv.failableValue() as Double?) == nil) + XCTAssertEqual((dbv.failableValue() as String?)!, "0.0") + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as String?)!, "0.0") XCTAssertEqual((dbv.value() as String), "0.0") - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -148,15 +156,17 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Text) // Check GRDB conversions from Text storage: - XCTAssertTrue((dbv.value() as Bool?) == nil) - XCTAssertTrue((dbv.value() as Int?) == nil) - XCTAssertTrue((dbv.value() as Int32?) == nil) - XCTAssertTrue((dbv.value() as Int64?) == nil) - XCTAssertTrue((dbv.value() as Double?) == nil) + XCTAssertTrue((dbv.failableValue() as Bool?) == nil) + XCTAssertTrue((dbv.failableValue() as Int?) == nil) + XCTAssertTrue((dbv.failableValue() as Int32?) == nil) + XCTAssertTrue((dbv.failableValue() as Int64?) == nil) + XCTAssertTrue((dbv.failableValue() as Double?) == nil) + XCTAssertEqual((dbv.failableValue() as String?)!, "3.0e+5") + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as String?)!, "3.0e+5") XCTAssertEqual((dbv.value() as String), "3.0e+5") - XCTAssertTrue((dbv.value() as NSData?) == nil) - + return .Rollback } @@ -168,14 +178,16 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Text) // Check GRDB conversions from Text storage: - XCTAssertTrue((dbv.value() as Bool?) == nil) - XCTAssertTrue((dbv.value() as Int?) == nil) - XCTAssertTrue((dbv.value() as Int32?) == nil) - XCTAssertTrue((dbv.value() as Int64?) == nil) - XCTAssertTrue((dbv.value() as Double?) == nil) + XCTAssertTrue((dbv.failableValue() as Bool?) == nil) + XCTAssertTrue((dbv.failableValue() as Int?) == nil) + XCTAssertTrue((dbv.failableValue() as Int32?) == nil) + XCTAssertTrue((dbv.failableValue() as Int64?) == nil) + XCTAssertTrue((dbv.failableValue() as Double?) == nil) + XCTAssertEqual((dbv.failableValue() as String?)!, "foo") + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as String?)!, "foo") XCTAssertEqual((dbv.value() as String), "foo") - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -188,13 +200,16 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Blob) // Check GRDB conversions from Blob storage: - XCTAssertTrue((dbv.value() as Bool?) == nil) - XCTAssertTrue((dbv.value() as Int?) == nil) - XCTAssertTrue((dbv.value() as Int32?) == nil) - XCTAssertTrue((dbv.value() as Int64?) == nil) - XCTAssertTrue((dbv.value() as Double?) == nil) - XCTAssertTrue((dbv.value() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as Bool?) == nil) + XCTAssertTrue((dbv.failableValue() as Int?) == nil) + XCTAssertTrue((dbv.failableValue() as Int32?) == nil) + XCTAssertTrue((dbv.failableValue() as Int64?) == nil) + XCTAssertTrue((dbv.failableValue() as Double?) == nil) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertEqual((dbv.failableValue() as NSData?), "foo".dataUsingEncoding(NSUTF8StringEncoding)) + XCTAssertEqual((dbv.value() as NSData?), "foo".dataUsingEncoding(NSUTF8StringEncoding)) + XCTAssertTrue((dbv.value() as NSData).isEqualToData("foo".dataUsingEncoding(NSUTF8StringEncoding)!)) return .Rollback } @@ -258,6 +273,14 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Real) // Check GRDB conversions from Real storage + XCTAssertEqual((dbv.failableValue() as Bool?)!, false) + XCTAssertEqual((dbv.failableValue() as Int?)!, 0) + XCTAssertEqual((dbv.failableValue() as Int32?)!, Int32(0)) + XCTAssertEqual((dbv.failableValue() as Int64?)!, Int64(0)) + XCTAssertEqual((dbv.failableValue() as Double?)!, 0.0) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as Bool?)!, false) XCTAssertEqual((dbv.value() as Bool), false) XCTAssertEqual((dbv.value() as Int?)!, 0) @@ -268,8 +291,6 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual((dbv.value() as Int64), Int64(0)) XCTAssertEqual((dbv.value() as Double?)!, 0.0) XCTAssertEqual((dbv.value() as Double), 0.0) - XCTAssertTrue((dbv.value() as String?) == nil) - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -282,6 +303,14 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Real) // Check GRDB conversions from Real storage + XCTAssertEqual((dbv.failableValue() as Bool?)!, false) + XCTAssertEqual((dbv.failableValue() as Int?)!, 0) + XCTAssertEqual((dbv.failableValue() as Int32?)!, Int32(0)) + XCTAssertEqual((dbv.failableValue() as Int64?)!, Int64(0)) + XCTAssertEqual((dbv.failableValue() as Double?)!, 0.0) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as Bool?)!, false) XCTAssertEqual((dbv.value() as Bool), false) XCTAssertEqual((dbv.value() as Int?)!, 0) @@ -292,8 +321,6 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual((dbv.value() as Int64), Int64(0)) XCTAssertEqual((dbv.value() as Double?)!, 0.0) XCTAssertEqual((dbv.value() as Double), 0.0) - XCTAssertTrue((dbv.value() as String?) == nil) - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -306,6 +333,14 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Real) // Check GRDB conversions from Real storage + XCTAssertEqual((dbv.failableValue() as Bool?)!, false) + XCTAssertEqual((dbv.failableValue() as Int?)!, 0) + XCTAssertEqual((dbv.failableValue() as Int32?)!, Int32(0)) + XCTAssertEqual((dbv.failableValue() as Int64?)!, Int64(0)) + XCTAssertEqual((dbv.failableValue() as Double?)!, 0.0) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as Bool?)!, false) XCTAssertEqual((dbv.value() as Bool), false) XCTAssertEqual((dbv.value() as Int?)!, 0) @@ -316,8 +351,6 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual((dbv.value() as Int64), Int64(0)) XCTAssertEqual((dbv.value() as Double?)!, 0.0) XCTAssertEqual((dbv.value() as Double), 0.0) - XCTAssertTrue((dbv.value() as String?) == nil) - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -330,6 +363,14 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Real) // Check GRDB conversions from Real storage + XCTAssertEqual((dbv.failableValue() as Bool?)!, true) + XCTAssertEqual((dbv.failableValue() as Int?)!, 300000) + XCTAssertEqual((dbv.failableValue() as Int32?)!, Int32(300000)) + XCTAssertEqual((dbv.failableValue() as Int64?)!, Int64(300000)) + XCTAssertEqual((dbv.failableValue() as Double?)!, Double(300000)) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as Bool?)!, true) XCTAssertEqual((dbv.value() as Bool), true) XCTAssertEqual((dbv.value() as Int?)!, 300000) @@ -340,8 +381,6 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual((dbv.value() as Int64), Int64(300000)) XCTAssertEqual((dbv.value() as Double?)!, Double(300000)) XCTAssertEqual((dbv.value() as Double), Double(300000)) - XCTAssertTrue((dbv.value() as String?) == nil) - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -354,13 +393,16 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Real) // Check GRDB conversions from Real storage (avoid Int, Int32 and Int64 since 1.0e20 does not fit) + XCTAssertEqual((dbv.failableValue() as Bool?)!, true) + XCTAssertEqual((dbv.failableValue() as Double?)!, 1e20) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as Bool?)!, true) XCTAssertEqual((dbv.value() as Bool), true) XCTAssertEqual((dbv.value() as Double?)!, 1e20) XCTAssertEqual((dbv.value() as Double), 1e20) - XCTAssertTrue((dbv.value() as String?) == nil) - XCTAssertTrue((dbv.value() as NSData?) == nil) - + return .Rollback } @@ -372,6 +414,14 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Real) // Check GRDB conversions from Real storage + XCTAssertEqual((dbv.failableValue() as Bool?)!, true) + XCTAssertEqual((dbv.failableValue() as Int?)!, 300000) + XCTAssertEqual((dbv.failableValue() as Int32?)!, Int32(300000)) + XCTAssertEqual((dbv.failableValue() as Int64?)!, Int64(300000)) + XCTAssertEqual((dbv.failableValue() as Double?)!, Double(300000)) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as Bool?)!, true) XCTAssertEqual((dbv.value() as Bool), true) XCTAssertEqual((dbv.value() as Int?)!, 300000) @@ -382,8 +432,6 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual((dbv.value() as Int64), Int64(300000)) XCTAssertEqual((dbv.value() as Double?)!, Double(300000)) XCTAssertEqual((dbv.value() as Double), Double(300000)) - XCTAssertTrue((dbv.value() as String?) == nil) - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -396,12 +444,15 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Real) // Check GRDB conversions from Real storage: (avoid Int, Int32 and Int64 since 1.0e20 does not fit) + XCTAssertEqual((dbv.failableValue() as Bool?)!, true) + XCTAssertEqual((dbv.failableValue() as Double?)!, 1e20) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as Bool?)!, true) XCTAssertEqual((dbv.value() as Bool), true) XCTAssertEqual((dbv.value() as Double?)!, 1e20) XCTAssertEqual((dbv.value() as Double), 1e20) - XCTAssertTrue((dbv.value() as String?) == nil) - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -414,14 +465,16 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Text) // Check GRDB conversions from Text storage: - XCTAssertTrue((dbv.value() as Bool?) == nil) - XCTAssertTrue((dbv.value() as Int?) == nil) - XCTAssertTrue((dbv.value() as Int32?) == nil) - XCTAssertTrue((dbv.value() as Int64?) == nil) - XCTAssertTrue((dbv.value() as Double?) == nil) + XCTAssertTrue((dbv.failableValue() as Bool?) == nil) + XCTAssertTrue((dbv.failableValue() as Int?) == nil) + XCTAssertTrue((dbv.failableValue() as Int32?) == nil) + XCTAssertTrue((dbv.failableValue() as Int64?) == nil) + XCTAssertTrue((dbv.failableValue() as Double?) == nil) + XCTAssertEqual((dbv.failableValue() as String?)!, "foo") + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as String?)!, "foo") XCTAssertEqual((dbv.value() as String), "foo") - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -434,13 +487,16 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Blob) // Check GRDB conversions from Blob storage: - XCTAssertTrue((dbv.value() as Bool?) == nil) - XCTAssertTrue((dbv.value() as Int?) == nil) - XCTAssertTrue((dbv.value() as Int32?) == nil) - XCTAssertTrue((dbv.value() as Int64?) == nil) - XCTAssertTrue((dbv.value() as Double?) == nil) - XCTAssertTrue((dbv.value() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as Bool?) == nil) + XCTAssertTrue((dbv.failableValue() as Int?) == nil) + XCTAssertTrue((dbv.failableValue() as Int32?) == nil) + XCTAssertTrue((dbv.failableValue() as Int64?) == nil) + XCTAssertTrue((dbv.failableValue() as Double?) == nil) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertEqual((dbv.failableValue() as NSData?), "foo".dataUsingEncoding(NSUTF8StringEncoding)) + XCTAssertEqual((dbv.value() as NSData?), "foo".dataUsingEncoding(NSUTF8StringEncoding)) + XCTAssertTrue((dbv.value() as NSData).isEqualToData("foo".dataUsingEncoding(NSUTF8StringEncoding)!)) return .Rollback } @@ -464,6 +520,14 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Integer) // Check GRDB conversions from Integer storage + XCTAssertEqual((dbv.failableValue() as Bool?)!, false) + XCTAssertEqual((dbv.failableValue() as Int?)!, 0) + XCTAssertEqual((dbv.failableValue() as Int32?)!, Int32(0)) + XCTAssertEqual((dbv.failableValue() as Int64?)!, Int64(0)) + XCTAssertEqual((dbv.failableValue() as Double?)!, 0.0) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as Bool?)!, false) XCTAssertEqual((dbv.value() as Bool), false) XCTAssertEqual((dbv.value() as Int?)!, 0) @@ -474,8 +538,6 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual((dbv.value() as Int64), Int64(0)) XCTAssertEqual((dbv.value() as Double?)!, 0.0) XCTAssertEqual((dbv.value() as Double), 0.0) - XCTAssertTrue((dbv.value() as String?) == nil) - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -488,6 +550,14 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Integer) // Check GRDB conversions from Integer storage + XCTAssertEqual((dbv.failableValue() as Bool?)!, false) + XCTAssertEqual((dbv.failableValue() as Int?)!, 0) + XCTAssertEqual((dbv.failableValue() as Int32?)!, Int32(0)) + XCTAssertEqual((dbv.failableValue() as Int64?)!, Int64(0)) + XCTAssertEqual((dbv.failableValue() as Double?)!, 0.0) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as Bool?)!, false) XCTAssertEqual((dbv.value() as Bool), false) XCTAssertEqual((dbv.value() as Int?)!, 0) @@ -498,8 +568,6 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual((dbv.value() as Int64), Int64(0)) XCTAssertEqual((dbv.value() as Double?)!, 0.0) XCTAssertEqual((dbv.value() as Double), 0.0) - XCTAssertTrue((dbv.value() as String?) == nil) - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -512,6 +580,14 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Integer) // Check GRDB conversions from Integer storage + XCTAssertEqual((dbv.failableValue() as Bool?)!, false) + XCTAssertEqual((dbv.failableValue() as Int?)!, 0) + XCTAssertEqual((dbv.failableValue() as Int32?)!, Int32(0)) + XCTAssertEqual((dbv.failableValue() as Int64?)!, Int64(0)) + XCTAssertEqual((dbv.failableValue() as Double?)!, 0.0) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as Bool?)!, false) XCTAssertEqual((dbv.value() as Bool), false) XCTAssertEqual((dbv.value() as Int?)!, 0) @@ -522,8 +598,6 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual((dbv.value() as Int64), Int64(0)) XCTAssertEqual((dbv.value() as Double?)!, 0.0) XCTAssertEqual((dbv.value() as Double), 0.0) - XCTAssertTrue((dbv.value() as String?) == nil) - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -536,6 +610,14 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Real) // Check GRDB conversions from Real storage + XCTAssertEqual((dbv.failableValue() as Bool?)!, false) + XCTAssertEqual((dbv.failableValue() as Int?)!, 0) + XCTAssertEqual((dbv.failableValue() as Int32?)!, Int32(0)) + XCTAssertEqual((dbv.failableValue() as Int64?)!, Int64(0)) + XCTAssertEqual((dbv.failableValue() as Double?)!, 0.0) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as Bool?)!, false) XCTAssertEqual((dbv.value() as Bool), false) XCTAssertEqual((dbv.value() as Int?)!, 0) @@ -546,8 +628,6 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual((dbv.value() as Int64), Int64(0)) XCTAssertEqual((dbv.value() as Double?)!, 0.0) XCTAssertEqual((dbv.value() as Double), 0.0) - XCTAssertTrue((dbv.value() as String?) == nil) - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -560,14 +640,16 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Text) // Check GRDB conversions from Text storage - XCTAssertTrue((dbv.value() as Bool?) == nil) - XCTAssertTrue((dbv.value() as Int?) == nil) - XCTAssertTrue((dbv.value() as Int32?) == nil) - XCTAssertTrue((dbv.value() as Int64?) == nil) - XCTAssertTrue((dbv.value() as Double?) == nil) + XCTAssertTrue((dbv.failableValue() as Bool?) == nil) + XCTAssertTrue((dbv.failableValue() as Int?) == nil) + XCTAssertTrue((dbv.failableValue() as Int32?) == nil) + XCTAssertTrue((dbv.failableValue() as Int64?) == nil) + XCTAssertTrue((dbv.failableValue() as Double?) == nil) + XCTAssertEqual((dbv.failableValue() as String?)!, "3.0e+5") + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as String?)!, "3.0e+5") XCTAssertEqual((dbv.value() as String), "3.0e+5") - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -580,13 +662,16 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Blob) // Check GRDB conversions from Blob storage - XCTAssertTrue((dbv.value() as Bool?) == nil) - XCTAssertTrue((dbv.value() as Int?) == nil) - XCTAssertTrue((dbv.value() as Int32?) == nil) - XCTAssertTrue((dbv.value() as Int64?) == nil) - XCTAssertTrue((dbv.value() as Double?) == nil) - XCTAssertTrue((dbv.value() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as Bool?) == nil) + XCTAssertTrue((dbv.failableValue() as Int?) == nil) + XCTAssertTrue((dbv.failableValue() as Int32?) == nil) + XCTAssertTrue((dbv.failableValue() as Int64?) == nil) + XCTAssertTrue((dbv.failableValue() as Double?) == nil) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertEqual((dbv.failableValue() as NSData?), "foo".dataUsingEncoding(NSUTF8StringEncoding)) + XCTAssertEqual((dbv.value() as NSData?), "foo".dataUsingEncoding(NSUTF8StringEncoding)) + XCTAssertTrue((dbv.value() as NSData).isEqualToData("foo".dataUsingEncoding(NSUTF8StringEncoding)!)) return .Rollback } @@ -624,6 +709,14 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Integer) // Check GRDB conversions from Integer storage + XCTAssertEqual((dbv.failableValue() as Bool?)!, false) + XCTAssertEqual((dbv.failableValue() as Int?)!, 0) + XCTAssertEqual((dbv.failableValue() as Int32?)!, Int32(0)) + XCTAssertEqual((dbv.failableValue() as Int64?)!, Int64(0)) + XCTAssertEqual((dbv.failableValue() as Double?)!, 0.0) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as Bool?)!, false) XCTAssertEqual((dbv.value() as Bool), false) XCTAssertEqual((dbv.value() as Int?)!, 0) @@ -634,8 +727,6 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual((dbv.value() as Int64), Int64(0)) XCTAssertEqual((dbv.value() as Double?)!, 0.0) XCTAssertEqual((dbv.value() as Double), 0.0) - XCTAssertTrue((dbv.value() as String?) == nil) - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -648,6 +739,14 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Integer) // Check GRDB conversions from Integer storage + XCTAssertEqual((dbv.failableValue() as Bool?)!, false) + XCTAssertEqual((dbv.failableValue() as Int?)!, 0) + XCTAssertEqual((dbv.failableValue() as Int32?)!, Int32(0)) + XCTAssertEqual((dbv.failableValue() as Int64?)!, Int64(0)) + XCTAssertEqual((dbv.failableValue() as Double?)!, 0.0) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as Bool?)!, false) XCTAssertEqual((dbv.value() as Bool), false) XCTAssertEqual((dbv.value() as Int?)!, 0) @@ -658,8 +757,6 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual((dbv.value() as Int64), Int64(0)) XCTAssertEqual((dbv.value() as Double?)!, 0.0) XCTAssertEqual((dbv.value() as Double), 0.0) - XCTAssertTrue((dbv.value() as String?) == nil) - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -672,6 +769,14 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Integer) // Check GRDB conversions from Integer storage + XCTAssertEqual((dbv.failableValue() as Bool?)!, false) + XCTAssertEqual((dbv.failableValue() as Int?)!, 0) + XCTAssertEqual((dbv.failableValue() as Int32?)!, Int32(0)) + XCTAssertEqual((dbv.failableValue() as Int64?)!, Int64(0)) + XCTAssertEqual((dbv.failableValue() as Double?)!, 0.0) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as Bool?)!, false) XCTAssertEqual((dbv.value() as Bool), false) XCTAssertEqual((dbv.value() as Int?)!, 0) @@ -682,8 +787,6 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual((dbv.value() as Int64), Int64(0)) XCTAssertEqual((dbv.value() as Double?)!, 0.0) XCTAssertEqual((dbv.value() as Double), 0.0) - XCTAssertTrue((dbv.value() as String?) == nil) - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -696,6 +799,14 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Integer) // Check GRDB conversions from Integer storage + XCTAssertEqual((dbv.failableValue() as Bool?)!, true) + XCTAssertEqual((dbv.failableValue() as Int?)!, 300000) + XCTAssertEqual((dbv.failableValue() as Int32?)!, Int32(300000)) + XCTAssertEqual((dbv.failableValue() as Int64?)!, Int64(300000)) + XCTAssertEqual((dbv.failableValue() as Double?)!, Double(300000)) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as Bool?)!, true) XCTAssertEqual((dbv.value() as Bool), true) XCTAssertEqual((dbv.value() as Int?)!, 300000) @@ -706,8 +817,6 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual((dbv.value() as Int64), Int64(300000)) XCTAssertEqual((dbv.value() as Double?)!, Double(300000)) XCTAssertEqual((dbv.value() as Double), Double(300000)) - XCTAssertTrue((dbv.value() as String?) == nil) - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -720,12 +829,15 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Real) // Check GRDB conversions from Real storage (avoid Int, Int32 and Int64 since 1.0e20 does not fit) + XCTAssertEqual((dbv.failableValue() as Bool?)!, true) + XCTAssertEqual((dbv.failableValue() as Double?)!, 1e20) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as Bool?)!, true) XCTAssertEqual((dbv.value() as Bool), true) XCTAssertEqual((dbv.value() as Double?)!, 1e20) XCTAssertEqual((dbv.value() as Double), 1e20) - XCTAssertTrue((dbv.value() as String?) == nil) - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -738,6 +850,14 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Integer) // Check GRDB conversions from Integer storage + XCTAssertEqual((dbv.failableValue() as Bool?)!, true) + XCTAssertEqual((dbv.failableValue() as Int?)!, 300000) + XCTAssertEqual((dbv.failableValue() as Int32?)!, Int32(300000)) + XCTAssertEqual((dbv.failableValue() as Int64?)!, Int64(300000)) + XCTAssertEqual((dbv.failableValue() as Double?)!, Double(300000)) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as Bool?)!, true) XCTAssertEqual((dbv.value() as Bool), true) XCTAssertEqual((dbv.value() as Int?)!, 300000) @@ -748,8 +868,6 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual((dbv.value() as Int64), Int64(300000)) XCTAssertEqual((dbv.value() as Double?)!, Double(300000)) XCTAssertEqual((dbv.value() as Double), Double(300000)) - XCTAssertTrue((dbv.value() as String?) == nil) - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -762,12 +880,15 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Real) // Check GRDB conversions from Real storage: (avoid Int, Int32 and Int64 since 1.0e20 does not fit) + XCTAssertEqual((dbv.failableValue() as Bool?)!, true) + XCTAssertEqual((dbv.failableValue() as Double?)!, 1e20) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as Bool?)!, true) XCTAssertEqual((dbv.value() as Bool), true) XCTAssertEqual((dbv.value() as Double?)!, 1e20) XCTAssertEqual((dbv.value() as Double), 1e20) - XCTAssertTrue((dbv.value() as String?) == nil) - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -780,14 +901,16 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Text) // Check GRDB conversions from Text storage: - XCTAssertTrue((dbv.value() as Bool?) == nil) - XCTAssertTrue((dbv.value() as Int?) == nil) - XCTAssertTrue((dbv.value() as Int32?) == nil) - XCTAssertTrue((dbv.value() as Int64?) == nil) - XCTAssertTrue((dbv.value() as Double?) == nil) + XCTAssertTrue((dbv.failableValue() as Bool?) == nil) + XCTAssertTrue((dbv.failableValue() as Int?) == nil) + XCTAssertTrue((dbv.failableValue() as Int32?) == nil) + XCTAssertTrue((dbv.failableValue() as Int64?) == nil) + XCTAssertTrue((dbv.failableValue() as Double?) == nil) + XCTAssertEqual((dbv.failableValue() as String?)!, "foo") + XCTAssertTrue((dbv.failableValue() as NSData?) == nil) + XCTAssertEqual((dbv.value() as String?)!, "foo") XCTAssertEqual((dbv.value() as String), "foo") - XCTAssertTrue((dbv.value() as NSData?) == nil) return .Rollback } @@ -800,13 +923,16 @@ class DatabaseValueConversionTests : GRDBTestCase { XCTAssertEqual(dbv.storageClass, SQLiteStorageClass.Blob) // Check GRDB conversions from Blob storage: - XCTAssertTrue((dbv.value() as Bool?) == nil) - XCTAssertTrue((dbv.value() as Int?) == nil) - XCTAssertTrue((dbv.value() as Int32?) == nil) - XCTAssertTrue((dbv.value() as Int64?) == nil) - XCTAssertTrue((dbv.value() as Double?) == nil) - XCTAssertTrue((dbv.value() as String?) == nil) + XCTAssertTrue((dbv.failableValue() as Bool?) == nil) + XCTAssertTrue((dbv.failableValue() as Int?) == nil) + XCTAssertTrue((dbv.failableValue() as Int32?) == nil) + XCTAssertTrue((dbv.failableValue() as Int64?) == nil) + XCTAssertTrue((dbv.failableValue() as Double?) == nil) + XCTAssertTrue((dbv.failableValue() as String?) == nil) + XCTAssertEqual((dbv.failableValue() as NSData?), "foo".dataUsingEncoding(NSUTF8StringEncoding)) + XCTAssertEqual((dbv.value() as NSData?), "foo".dataUsingEncoding(NSUTF8StringEncoding)) + XCTAssertTrue((dbv.value() as NSData).isEqualToData("foo".dataUsingEncoding(NSUTF8StringEncoding)!)) return .Rollback } diff --git a/Tests/Public/Core/DatabaseValueConvertible/RawRepresentableTests.swift b/Tests/Public/Core/DatabaseValueConvertible/RawRepresentableTests.swift index 53ff25538..13e923a38 100644 --- a/Tests/Public/Core/DatabaseValueConvertible/RawRepresentableTests.swift +++ b/Tests/Public/Core/DatabaseValueConvertible/RawRepresentableTests.swift @@ -52,7 +52,6 @@ class RawRepresentableTests: GRDBTestCase { for color in [Color32.Red, Color32.White, Color32.Rose] { try db.execute("INSERT INTO wines (color) VALUES (?)", arguments: [color]) } - try db.execute("INSERT INTO wines (color) VALUES (?)", arguments: [4]) try db.execute("INSERT INTO wines (color) VALUES (NULL)") } @@ -63,7 +62,6 @@ class RawRepresentableTests: GRDBTestCase { XCTAssertEqual(colors[1]!, Color32.Red) XCTAssertEqual(colors[2]!, Color32.White) XCTAssertEqual(colors[3]!, Color32.Rose) - XCTAssertTrue(colors[4] == nil) } do { @@ -72,7 +70,6 @@ class RawRepresentableTests: GRDBTestCase { XCTAssertEqual(colors[1]!, Color32.Red) XCTAssertEqual(colors[2]!, Color32.White) XCTAssertEqual(colors[3]!, Color32.Rose) - XCTAssertTrue(colors[4] == nil) } return .Rollback @@ -88,7 +85,6 @@ class RawRepresentableTests: GRDBTestCase { for color in [Color64.Red, Color64.White, Color64.Rose] { try db.execute("INSERT INTO wines (color) VALUES (?)", arguments: [color]) } - try db.execute("INSERT INTO wines (color) VALUES (?)", arguments: [4]) try db.execute("INSERT INTO wines (color) VALUES (NULL)") } @@ -99,7 +95,6 @@ class RawRepresentableTests: GRDBTestCase { XCTAssertEqual(colors[1]!, Color64.Red) XCTAssertEqual(colors[2]!, Color64.White) XCTAssertEqual(colors[3]!, Color64.Rose) - XCTAssertTrue(colors[4] == nil) } do { @@ -108,7 +103,6 @@ class RawRepresentableTests: GRDBTestCase { XCTAssertEqual(colors[1]!, Color64.Red) XCTAssertEqual(colors[2]!, Color64.White) XCTAssertEqual(colors[3]!, Color64.Rose) - XCTAssertTrue(colors[4] == nil) } return .Rollback @@ -124,7 +118,6 @@ class RawRepresentableTests: GRDBTestCase { for color in [Color.Red, Color.White, Color.Rose] { try db.execute("INSERT INTO wines (color) VALUES (?)", arguments: [color]) } - try db.execute("INSERT INTO wines (color) VALUES (?)", arguments: [4]) try db.execute("INSERT INTO wines (color) VALUES (NULL)") } @@ -135,7 +128,6 @@ class RawRepresentableTests: GRDBTestCase { XCTAssertEqual(colors[1]!, Color.Red) XCTAssertEqual(colors[2]!, Color.White) XCTAssertEqual(colors[3]!, Color.Rose) - XCTAssertTrue(colors[4] == nil) } do { @@ -144,7 +136,6 @@ class RawRepresentableTests: GRDBTestCase { XCTAssertEqual(colors[1]!, Color.Red) XCTAssertEqual(colors[2]!, Color.White) XCTAssertEqual(colors[3]!, Color.Rose) - XCTAssertTrue(colors[4] == nil) } return .Rollback @@ -160,7 +151,6 @@ class RawRepresentableTests: GRDBTestCase { for grape in [Grape.Chardonnay, Grape.Merlot, Grape.Riesling] { try db.execute("INSERT INTO wines (grape) VALUES (?)", arguments: [grape]) } - try db.execute("INSERT INTO wines (grape) VALUES (?)", arguments: ["Syrah"]) try db.execute("INSERT INTO wines (grape) VALUES (NULL)") } @@ -171,7 +161,6 @@ class RawRepresentableTests: GRDBTestCase { XCTAssertEqual(grapes[1]!, Grape.Chardonnay) XCTAssertEqual(grapes[2]!, Grape.Merlot) XCTAssertEqual(grapes[3]!, Grape.Riesling) - XCTAssertTrue(grapes[4] == nil) } do { @@ -180,7 +169,6 @@ class RawRepresentableTests: GRDBTestCase { XCTAssertEqual(grapes[1]!, Grape.Chardonnay) XCTAssertEqual(grapes[2]!, Grape.Merlot) XCTAssertEqual(grapes[3]!, Grape.Riesling) - XCTAssertTrue(grapes[4] == nil) } return .Rollback diff --git a/Tests/Public/Core/Function/FunctionTests.swift b/Tests/Public/Core/Function/FunctionTests.swift index 7962a7fd5..5dcb0f7a9 100644 --- a/Tests/Public/Core/Function/FunctionTests.swift +++ b/Tests/Public/Core/Function/FunctionTests.swift @@ -117,8 +117,6 @@ class FunctionTests: GRDBTestCase { XCTAssertTrue(Int64.fetchOne(db, "SELECT asInt64(NULL)") == nil) XCTAssertEqual(Int64.fetchOne(db, "SELECT asInt64(1)")!, 1) XCTAssertEqual(Int64.fetchOne(db, "SELECT asInt64(1.1)")!, 1) - XCTAssertTrue(Int64.fetchOne(db, "SELECT asInt64('foo')") == nil) - XCTAssertTrue(Int64.fetchOne(db, "SELECT asInt64(?)", arguments: ["foo".dataUsingEncoding(NSUTF8StringEncoding)]) == nil) } } } @@ -133,8 +131,6 @@ class FunctionTests: GRDBTestCase { XCTAssertTrue(Double.fetchOne(db, "SELECT asDouble(NULL)") == nil) XCTAssertEqual(Double.fetchOne(db, "SELECT asDouble(1)")!, 1.0) XCTAssertEqual(Double.fetchOne(db, "SELECT asDouble(1.1)")!, 1.1) - XCTAssertTrue(Double.fetchOne(db, "SELECT asDouble('foo')") == nil) - XCTAssertTrue(Double.fetchOne(db, "SELECT asDouble(?)", arguments: ["foo".dataUsingEncoding(NSUTF8StringEncoding)]) == nil) } } } @@ -147,10 +143,7 @@ class FunctionTests: GRDBTestCase { dbQueue.addFunction(fn) dbQueue.inDatabase { db in XCTAssertTrue(String.fetchOne(db, "SELECT asString(NULL)") == nil) - XCTAssertTrue(String.fetchOne(db, "SELECT asString(1)") == nil) - XCTAssertTrue(String.fetchOne(db, "SELECT asString(1.1)") == nil) XCTAssertEqual(String.fetchOne(db, "SELECT asString('foo')")!, "foo") - XCTAssertTrue(String.fetchOne(db, "SELECT asString(?)", arguments: ["foo".dataUsingEncoding(NSUTF8StringEncoding)]) == nil) } } } @@ -163,9 +156,6 @@ class FunctionTests: GRDBTestCase { dbQueue.addFunction(fn) dbQueue.inDatabase { db in XCTAssertTrue(NSData.fetchOne(db, "SELECT asData(NULL)") == nil) - XCTAssertTrue(NSData.fetchOne(db, "SELECT asData(1)") == nil) - XCTAssertTrue(NSData.fetchOne(db, "SELECT asData(1.1)") == nil) - XCTAssertTrue(NSData.fetchOne(db, "SELECT asData('foo')") == nil) XCTAssertEqual(NSData.fetchOne(db, "SELECT asData(?)", arguments: ["foo".dataUsingEncoding(NSUTF8StringEncoding)])!, "foo".dataUsingEncoding(NSUTF8StringEncoding)) } } @@ -179,11 +169,7 @@ class FunctionTests: GRDBTestCase { dbQueue.addFunction(fn) dbQueue.inDatabase { db in XCTAssertTrue(CustomValueType.fetchOne(db, "SELECT asCustomValueType(NULL)") == nil) - XCTAssertTrue(CustomValueType.fetchOne(db, "SELECT asCustomValueType(1)") == nil) - XCTAssertTrue(CustomValueType.fetchOne(db, "SELECT asCustomValueType(1.1)") == nil) - XCTAssertTrue(CustomValueType.fetchOne(db, "SELECT asCustomValueType('foo')") == nil) XCTAssertTrue(CustomValueType.fetchOne(db, "SELECT asCustomValueType('CustomValueType')") != nil) - XCTAssertTrue(CustomValueType.fetchOne(db, "SELECT asCustomValueType(?)", arguments: ["foo".dataUsingEncoding(NSUTF8StringEncoding)]) == nil) } } } diff --git a/Tests/Public/Core/Row/DetachedRowTests.swift b/Tests/Public/Core/Row/DetachedRowTests.swift index 0d55c451b..c2cfd19c1 100644 --- a/Tests/Public/Core/Row/DetachedRowTests.swift +++ b/Tests/Public/Core/Row/DetachedRowTests.swift @@ -118,6 +118,36 @@ class DetachedRowTests: GRDBTestCase { } } + func testRowDatabaseValueAtIndex() { + assertNoError { + let dbQueue = DatabaseQueue() + dbQueue.inDatabase { db in + let row = Row.fetchOne(db, "SELECT NULL, 1, 1.1, 'foo', x'53514C697465'")! + + guard case .Null = row.databaseValue(atIndex: 0).storage else { XCTFail(); return } + guard case .Int64(let int64) = row.databaseValue(atIndex: 1).storage where int64 == 1 else { XCTFail(); return } + guard case .Double(let double) = row.databaseValue(atIndex: 2).storage where double == 1.1 else { XCTFail(); return } + guard case .String(let string) = row.databaseValue(atIndex: 3).storage where string == "foo" else { XCTFail(); return } + guard case .Blob(let data) = row.databaseValue(atIndex: 4).storage where data == "SQLite".dataUsingEncoding(NSUTF8StringEncoding) else { XCTFail(); return } + } + } + } + + func testRowDatabaseValueNamed() { + assertNoError { + let dbQueue = DatabaseQueue() + dbQueue.inDatabase { db in + let row = Row.fetchOne(db, "SELECT NULL AS \"null\", 1 AS \"int64\", 1.1 AS \"double\", 'foo' AS \"string\", x'53514C697465' AS \"blob\"")! + + guard case .Null = row.databaseValue(named: "null").storage else { XCTFail(); return } + guard case .Int64(let int64) = row.databaseValue(named: "int64").storage where int64 == 1 else { XCTFail(); return } + guard case .Double(let double) = row.databaseValue(named: "double").storage where double == 1.1 else { XCTFail(); return } + guard case .String(let string) = row.databaseValue(named: "string").storage where string == "foo" else { XCTFail(); return } + guard case .Blob(let data) = row.databaseValue(named: "blob").storage where data == "SQLite".dataUsingEncoding(NSUTF8StringEncoding) else { XCTFail(); return } + } + } + } + func testRowCount() { assertNoError { let dbQueue = DatabaseQueue() diff --git a/Tests/Public/Core/Row/DictionaryRowTests.swift b/Tests/Public/Core/Row/DictionaryRowTests.swift index a80a0ac45..b3f330859 100644 --- a/Tests/Public/Core/Row/DictionaryRowTests.swift +++ b/Tests/Public/Core/Row/DictionaryRowTests.swift @@ -102,6 +102,38 @@ class DictionaryRowTests: GRDBTestCase { // row.value(named: "foo") as Int? } + func testRowDatabaseValueAtIndex() { + assertNoError { + let dictionary: [String: DatabaseValueConvertible?] = ["null": nil, "int64": 1, "double": 1.1, "string": "foo", "blob": "SQLite".dataUsingEncoding(NSUTF8StringEncoding)] + let row = Row(dictionary) + + let nullIndex = dictionary.startIndex.distanceTo(dictionary.indexForKey("null")!) + let int64Index = dictionary.startIndex.distanceTo(dictionary.indexForKey("int64")!) + let doubleIndex = dictionary.startIndex.distanceTo(dictionary.indexForKey("double")!) + let stringIndex = dictionary.startIndex.distanceTo(dictionary.indexForKey("string")!) + let blobIndex = dictionary.startIndex.distanceTo(dictionary.indexForKey("blob")!) + + guard case .Null = row.databaseValue(atIndex: nullIndex).storage else { XCTFail(); return } + guard case .Int64(let int64) = row.databaseValue(atIndex: int64Index).storage where int64 == 1 else { XCTFail(); return } + guard case .Double(let double) = row.databaseValue(atIndex: doubleIndex).storage where double == 1.1 else { XCTFail(); return } + guard case .String(let string) = row.databaseValue(atIndex: stringIndex).storage where string == "foo" else { XCTFail(); return } + guard case .Blob(let data) = row.databaseValue(atIndex: blobIndex).storage where data == "SQLite".dataUsingEncoding(NSUTF8StringEncoding) else { XCTFail(); return } + } + } + + func testRowDatabaseValueNamed() { + assertNoError { + let dictionary: [String: DatabaseValueConvertible?] = ["null": nil, "int64": 1, "double": 1.1, "string": "foo", "blob": "SQLite".dataUsingEncoding(NSUTF8StringEncoding)] + let row = Row(dictionary) + + guard case .Null = row.databaseValue(named: "null").storage else { XCTFail(); return } + guard case .Int64(let int64) = row.databaseValue(named: "int64").storage where int64 == 1 else { XCTFail(); return } + guard case .Double(let double) = row.databaseValue(named: "double").storage where double == 1.1 else { XCTFail(); return } + guard case .String(let string) = row.databaseValue(named: "string").storage where string == "foo" else { XCTFail(); return } + guard case .Blob(let data) = row.databaseValue(named: "blob").storage where data == "SQLite".dataUsingEncoding(NSUTF8StringEncoding) else { XCTFail(); return } + } + } + func testRowCount() { let row = Row(["a": 0, "b": 1, "c": 2]) XCTAssertEqual(row.count, 3) diff --git a/Tests/Public/Core/Row/MetalRowTests.swift b/Tests/Public/Core/Row/MetalRowTests.swift index 5c0ef0ae0..5c9ae690b 100644 --- a/Tests/Public/Core/Row/MetalRowTests.swift +++ b/Tests/Public/Core/Row/MetalRowTests.swift @@ -129,6 +129,42 @@ class MetalRowTests: GRDBTestCase { } } + func testRowDatabaseValueAtIndex() { + assertNoError { + let dbQueue = DatabaseQueue() + dbQueue.inDatabase { db in + var rowFetched = false + for row in Row.fetch(db, "SELECT NULL, 1, 1.1, 'foo', x'53514C697465'") { + rowFetched = true + guard case .Null = row.databaseValue(atIndex: 0).storage else { XCTFail(); return } + guard case .Int64(let int64) = row.databaseValue(atIndex: 1).storage where int64 == 1 else { XCTFail(); return } + guard case .Double(let double) = row.databaseValue(atIndex: 2).storage where double == 1.1 else { XCTFail(); return } + guard case .String(let string) = row.databaseValue(atIndex: 3).storage where string == "foo" else { XCTFail(); return } + guard case .Blob(let data) = row.databaseValue(atIndex: 4).storage where data == "SQLite".dataUsingEncoding(NSUTF8StringEncoding) else { XCTFail(); return } + } + XCTAssertTrue(rowFetched) + } + } + } + + func testRowDatabaseValueNamed() { + assertNoError { + let dbQueue = DatabaseQueue() + dbQueue.inDatabase { db in + var rowFetched = false + for row in Row.fetch(db, "SELECT NULL AS \"null\", 1 AS \"int64\", 1.1 AS \"double\", 'foo' AS \"string\", x'53514C697465' AS \"blob\"") { + rowFetched = true + guard case .Null = row.databaseValue(named: "null").storage else { XCTFail(); return } + guard case .Int64(let int64) = row.databaseValue(named: "int64").storage where int64 == 1 else { XCTFail(); return } + guard case .Double(let double) = row.databaseValue(named: "double").storage where double == 1.1 else { XCTFail(); return } + guard case .String(let string) = row.databaseValue(named: "string").storage where string == "foo" else { XCTFail(); return } + guard case .Blob(let data) = row.databaseValue(named: "blob").storage where data == "SQLite".dataUsingEncoding(NSUTF8StringEncoding) else { XCTFail(); return } + } + XCTAssertTrue(rowFetched) + } + } + } + func testRowCount() { assertNoError { let dbQueue = DatabaseQueue() diff --git a/Tests/Public/Core/SQLiteStatementConvertible/SQLiteStatementConversionTests.swift b/Tests/Public/Core/SQLiteStatementConvertible/SQLiteStatementConversionTests.swift index 28ea28aa0..871d3a33b 100644 --- a/Tests/Public/Core/SQLiteStatementConvertible/SQLiteStatementConversionTests.swift +++ b/Tests/Public/Core/SQLiteStatementConvertible/SQLiteStatementConversionTests.swift @@ -41,19 +41,19 @@ class SQLiteStatementConversionTests : GRDBTestCase { try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0 as Int]) // Check SQLite conversions from Text storage: for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Bool?), false) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int32?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int64?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Double?), 0.0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as String?)!, "0") @@ -61,9 +61,10 @@ class SQLiteStatementConversionTests : GRDBTestCase { for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as String), "0") } - for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) - } + // NSData extraction: precondition failed: could not convert "0" to NSData +// for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -73,19 +74,19 @@ class SQLiteStatementConversionTests : GRDBTestCase { try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0 as Int64]) // Check SQLite conversions from Text storage: for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Bool?), false) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int32?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int64?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Double?), 0.0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as String?)!, "0") @@ -93,9 +94,10 @@ class SQLiteStatementConversionTests : GRDBTestCase { for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as String), "0") } - for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) - } + // NSData extraction: precondition failed: could not convert "0" to NSData +// for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -105,19 +107,19 @@ class SQLiteStatementConversionTests : GRDBTestCase { try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0 as Int32]) // Check SQLite conversions from Text storage: for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Bool?), false) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int32?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int64?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Double?), 0.0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as String?)!, "0") @@ -125,31 +127,32 @@ class SQLiteStatementConversionTests : GRDBTestCase { for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as String), "0") } - for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) - } + // NSData extraction: precondition failed: could not convert "0" to NSData +// for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } - // Double is turned to Real + // Double is turned to Text try dbQueue.inTransaction { db in try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0.0]) // Check SQLite conversions from Text storage: for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Bool?), false) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int32?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int64?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Double?), 0.0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as String?)!, "0.0") @@ -157,9 +160,10 @@ class SQLiteStatementConversionTests : GRDBTestCase { for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as String), "0.0") } - for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) - } + // NSData extraction: precondition failed: could not convert "0.0" to NSData +// for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -169,19 +173,19 @@ class SQLiteStatementConversionTests : GRDBTestCase { try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: ["3.0e+5"]) // Check SQLite conversions from Text storage: for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Bool?), true) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int?), 3) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int32?), 3) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int64?), 3) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Double?), 300000.0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as String?)!, "3.0e+5") @@ -189,9 +193,10 @@ class SQLiteStatementConversionTests : GRDBTestCase { for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as String), "3.0e+5") } - for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) - } + // NSData extraction: precondition failed: could not convert "3.0e+5" to NSData +// for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -201,19 +206,19 @@ class SQLiteStatementConversionTests : GRDBTestCase { try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: ["foo"]) // Check SQLite conversions from Text storage: for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Bool?), false) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int32?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int64?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Double?), 0.0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as String?)!, "foo") @@ -221,9 +226,10 @@ class SQLiteStatementConversionTests : GRDBTestCase { for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as String), "foo") } - for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) - } + // NSData extraction: precondition failed: could not convert "foo" to NSData +// for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -233,22 +239,22 @@ class SQLiteStatementConversionTests : GRDBTestCase { try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: ["foo".dataUsingEncoding(NSUTF8StringEncoding)]) // Check SQLite conversions from Blob storage: for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Bool?), false) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int32?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int64?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Double?), 0.0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as String?), "foo") // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT textAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as NSData?), "foo".dataUsingEncoding(NSUTF8StringEncoding)) @@ -343,11 +349,12 @@ class SQLiteStatementConversionTests : GRDBTestCase { XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0) } for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion - } - for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) + XCTAssertEqual((row.value(atIndex: 0) as String?), "0.0") // incompatible with DatabaseValue conversion } + // NSData extraction: precondition failed: could not convert 0.0 to NSData +// for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -387,11 +394,12 @@ class SQLiteStatementConversionTests : GRDBTestCase { XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0) } for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion - } - for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) + XCTAssertEqual((row.value(atIndex: 0) as String?), "0.0") // incompatible with DatabaseValue conversion } + // NSData extraction: precondition failed: could not convert 0.0 to NSData +// for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -431,11 +439,12 @@ class SQLiteStatementConversionTests : GRDBTestCase { XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0) } for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion - } - for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) + XCTAssertEqual((row.value(atIndex: 0) as String?), "0.0") // incompatible with DatabaseValue conversion } + // NSData extraction: precondition failed: could not convert 0.0 to NSData +// for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -475,11 +484,12 @@ class SQLiteStatementConversionTests : GRDBTestCase { XCTAssertEqual((row.value(atIndex: 0) as Double), Double(300000)) } for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion - } - for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) + XCTAssertEqual((row.value(atIndex: 0) as String?), "300000.0") // incompatible with DatabaseValue conversion } + // NSData extraction: precondition failed: could not convert 300000.0 to NSData +// for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -501,11 +511,12 @@ class SQLiteStatementConversionTests : GRDBTestCase { XCTAssertEqual((row.value(atIndex: 0) as Double), 1e20) } for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion - } - for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) + XCTAssertEqual((row.value(atIndex: 0) as String?), "1.0e+20") // incompatible with DatabaseValue conversion } + // NSData extraction: precondition failed: could not convert 1e+20 to NSData +// for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -545,11 +556,12 @@ class SQLiteStatementConversionTests : GRDBTestCase { XCTAssertEqual((row.value(atIndex: 0) as Double), Double(300000)) } for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion - } - for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) + XCTAssertEqual((row.value(atIndex: 0) as String?), "300000.0") // incompatible with DatabaseValue conversion } + // NSData extraction: precondition failed: could not convert 300000.0 to NSData +// for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -571,11 +583,12 @@ class SQLiteStatementConversionTests : GRDBTestCase { XCTAssertEqual((row.value(atIndex: 0) as Double), 1e20) } for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion - } - for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) + XCTAssertEqual((row.value(atIndex: 0) as String?), "1.0e+20") // incompatible with DatabaseValue conversion } + // NSData extraction: precondition failed: could not convert 1e+20 to NSData +// for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -585,19 +598,19 @@ class SQLiteStatementConversionTests : GRDBTestCase { try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: ["foo"]) // Check SQLite conversions from Text storage: for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Bool?), false) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int32?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int64?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Double?), 0.0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as String?)!, "foo") @@ -605,9 +618,10 @@ class SQLiteStatementConversionTests : GRDBTestCase { for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as String), "foo") } - for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) - } + // NSData extraction: precondition failed: could not convert "foo" to NSData +// for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -617,22 +631,22 @@ class SQLiteStatementConversionTests : GRDBTestCase { try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: ["foo".dataUsingEncoding(NSUTF8StringEncoding)]) // Check SQLite conversions from Blob storage: for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Bool?), false) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int32?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int64?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Double?), 0.0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as String?), "foo") // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT realAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as NSData?), "foo".dataUsingEncoding(NSUTF8StringEncoding)) @@ -687,11 +701,12 @@ class SQLiteStatementConversionTests : GRDBTestCase { XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0) } for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion - } - for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) + XCTAssertEqual((row.value(atIndex: 0) as String?), "0") // incompatible with DatabaseValue conversion } + // NSData extraction: precondition failed: could not convert 0 to NSData +// for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -731,11 +746,12 @@ class SQLiteStatementConversionTests : GRDBTestCase { XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0) } for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion - } - for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) + XCTAssertEqual((row.value(atIndex: 0) as String?), "0") // incompatible with DatabaseValue conversion } + // NSData extraction: precondition failed: could not convert 0 to NSData +// for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -775,11 +791,12 @@ class SQLiteStatementConversionTests : GRDBTestCase { XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0) } for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion - } - for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) + XCTAssertEqual((row.value(atIndex: 0) as String?), "0") // incompatible with DatabaseValue conversion } + // NSData extraction: precondition failed: could not convert 0 to NSData +// for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -819,11 +836,12 @@ class SQLiteStatementConversionTests : GRDBTestCase { XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0) } for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion - } - for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) + XCTAssertEqual((row.value(atIndex: 0) as String?), "0.0") // incompatible with DatabaseValue conversion } + // NSData extraction: precondition failed: could not convert 0.0 to NSData +// for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -833,19 +851,19 @@ class SQLiteStatementConversionTests : GRDBTestCase { try db.execute("INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: ["3.0e+5"]) // Check SQLite conversions from Text storage for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Bool?), true) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int?), 3) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int32?), 3) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int64?), 3) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Double?), 300000.0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as String?)!, "3.0e+5") @@ -853,9 +871,10 @@ class SQLiteStatementConversionTests : GRDBTestCase { for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as String), "3.0e+5") } - for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) - } + // NSData extraction: precondition failed: could not convert "3.0e+5" to NSData +// for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -865,22 +884,22 @@ class SQLiteStatementConversionTests : GRDBTestCase { try db.execute("INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: ["foo".dataUsingEncoding(NSUTF8StringEncoding)]) // Check SQLite conversions from Blob storage for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Bool?), false) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int32?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int64?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Double?), 0.0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as String?), "foo") // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as NSData?), "foo".dataUsingEncoding(NSUTF8StringEncoding)) @@ -949,11 +968,12 @@ class SQLiteStatementConversionTests : GRDBTestCase { XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0) } for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion - } - for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) + XCTAssertEqual((row.value(atIndex: 0) as String?), "0") // incompatible with DatabaseValue conversion } + // NSData extraction: precondition failed: could not convert 0 to NSData +// for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -993,11 +1013,12 @@ class SQLiteStatementConversionTests : GRDBTestCase { XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0) } for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion - } - for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) + XCTAssertEqual((row.value(atIndex: 0) as String?), "0") // incompatible with DatabaseValue conversion } + // NSData extraction: precondition failed: could not convert 0 to NSData +// for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -1037,11 +1058,12 @@ class SQLiteStatementConversionTests : GRDBTestCase { XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0) } for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion - } - for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) + XCTAssertEqual((row.value(atIndex: 0) as String?), "0") // incompatible with DatabaseValue conversion } + // NSData extraction: precondition failed: could not convert 0 to NSData +// for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -1081,11 +1103,12 @@ class SQLiteStatementConversionTests : GRDBTestCase { XCTAssertEqual((row.value(atIndex: 0) as Double), Double(300000)) } for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion - } - for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) + XCTAssertEqual((row.value(atIndex: 0) as String?), "300000") // incompatible with DatabaseValue conversion } + // NSData extraction: precondition failed: could not convert 300000 to NSData +// for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -1107,11 +1130,12 @@ class SQLiteStatementConversionTests : GRDBTestCase { XCTAssertEqual((row.value(atIndex: 0) as Double), 1e20) } for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion - } - for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) + XCTAssertEqual((row.value(atIndex: 0) as String?), "1.0e+20") // incompatible with DatabaseValue conversion } + // NSData extraction: precondition failed: could not convert 1e+20 to NSData +// for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -1151,11 +1175,12 @@ class SQLiteStatementConversionTests : GRDBTestCase { XCTAssertEqual((row.value(atIndex: 0) as Double), Double(300000)) } for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion - } - for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) + XCTAssertEqual((row.value(atIndex: 0) as String?), "300000") // incompatible with DatabaseValue conversion } + // NSData extraction: precondition failed: could not convert 300000 to NSData +// for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -1177,11 +1202,12 @@ class SQLiteStatementConversionTests : GRDBTestCase { XCTAssertEqual((row.value(atIndex: 0) as Double), 1e20) } for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion - } - for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) + XCTAssertEqual((row.value(atIndex: 0) as String?), "1.0e+20") // incompatible with DatabaseValue conversion } + // NSData extraction: precondition failed: could not convert 1e+20 to NSData +// for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -1191,19 +1217,19 @@ class SQLiteStatementConversionTests : GRDBTestCase { try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: ["foo"]) // Check SQLite conversions from Text storage: for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Bool?), false) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int32?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int64?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Double?), 0.0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as String?)!, "foo") @@ -1211,9 +1237,10 @@ class SQLiteStatementConversionTests : GRDBTestCase { for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as String), "foo") } - for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) - } + // NSData extraction: precondition failed: could not convert "foo" to NSData +// for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { +// XCTAssertTrue((row.value(atIndex: 0) as NSData?) == nil) +// } return .Rollback } @@ -1223,22 +1250,22 @@ class SQLiteStatementConversionTests : GRDBTestCase { try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: ["foo".dataUsingEncoding(NSUTF8StringEncoding)]) // Check SQLite conversions from Blob storage: for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Bool?), false) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int32?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Int64?), 0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as Double?), 0.0) // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { - XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with DatabaseValue conversion + XCTAssertEqual((row.value(atIndex: 0) as String?), "foo") // incompatible with DatabaseValue conversion } for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") { XCTAssertEqual((row.value(atIndex: 0) as NSData?), "foo".dataUsingEncoding(NSUTF8StringEncoding)) diff --git a/Tests/Public/FetchRequest/SQLSupportTests.swift b/Tests/Public/FetchRequest/SQLSupportTests.swift index cc4ec02b5..ae8022f4c 100644 --- a/Tests/Public/FetchRequest/SQLSupportTests.swift +++ b/Tests/Public/FetchRequest/SQLSupportTests.swift @@ -350,6 +350,28 @@ class SQLSupportTests: GRDBTestCase { XCTAssertEqual( sql(tableRequest.filter(Col.name == Col.name)), "SELECT * FROM \"readers\" WHERE (\"name\" = \"name\")") + + XCTAssertEqual( + sql(tableRequest.filter(Col.age == true)), + "SELECT * FROM \"readers\" WHERE \"age\"") + XCTAssertEqual( + sql(tableRequest.filter(true == Col.age)), + "SELECT * FROM \"readers\" WHERE \"age\"") + XCTAssertEqual( + sql(tableRequest.filter(Col.age == false)), + "SELECT * FROM \"readers\" WHERE (NOT \"age\")") + XCTAssertEqual( + sql(tableRequest.filter(false == Col.age)), + "SELECT * FROM \"readers\" WHERE (NOT \"age\")") + XCTAssertEqual( + sql(tableRequest.filter(true == true)), + "SELECT * FROM \"readers\" WHERE 1") + XCTAssertEqual( + sql(tableRequest.filter(false == false)), + "SELECT * FROM \"readers\" WHERE 1") + XCTAssertEqual( + sql(tableRequest.filter(true == false)), + "SELECT * FROM \"readers\" WHERE 0") } func testEqualWithCollation() { @@ -409,6 +431,28 @@ class SQLSupportTests: GRDBTestCase { XCTAssertEqual( sql(tableRequest.filter(Col.name != Col.name)), "SELECT * FROM \"readers\" WHERE (\"name\" <> \"name\")") + + XCTAssertEqual( + sql(tableRequest.filter(Col.age != true)), + "SELECT * FROM \"readers\" WHERE (NOT \"age\")") + XCTAssertEqual( + sql(tableRequest.filter(true != Col.age)), + "SELECT * FROM \"readers\" WHERE (NOT \"age\")") + XCTAssertEqual( + sql(tableRequest.filter(Col.age != false)), + "SELECT * FROM \"readers\" WHERE \"age\"") + XCTAssertEqual( + sql(tableRequest.filter(false != Col.age)), + "SELECT * FROM \"readers\" WHERE \"age\"") + XCTAssertEqual( + sql(tableRequest.filter(true != true)), + "SELECT * FROM \"readers\" WHERE 0") + XCTAssertEqual( + sql(tableRequest.filter(false != false)), + "SELECT * FROM \"readers\" WHERE 0") + XCTAssertEqual( + sql(tableRequest.filter(true != false)), + "SELECT * FROM \"readers\" WHERE 1") } func testNotEqualWithCollation() {