mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
MatelTypeTests
This commit is contained in:
1 parent
b22a5ccac4
commit
d0cf6cdf8b
2 files changed
+777
-4
No files matched your search
@@ -0,0 +1,759 @@
|
||||
import XCTest
|
||||
import GRDB
|
||||
|
||||
class MetalTypeTests : GRDBTestCase {
|
||||
|
||||
// Datatypes In SQLite Version 3: https://www.sqlite.org/datatype3.html
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPersons") { db in
|
||||
try db.execute(
|
||||
"CREATE TABLE `values` (" +
|
||||
"integerAffinity INTEGER, " +
|
||||
"textAffinity TEXT, " +
|
||||
"noneAffinity BLOB, " +
|
||||
"realAffinity DOUBLE, " +
|
||||
"numericAffinity NUMERIC" +
|
||||
")")
|
||||
}
|
||||
|
||||
assertNoError {
|
||||
try migrator.migrate(dbQueue)
|
||||
}
|
||||
}
|
||||
|
||||
func testTextAffinity() {
|
||||
// https://www.sqlite.org/datatype3.html
|
||||
//
|
||||
// > A column with TEXT affinity stores all data using storage classes
|
||||
// > NULL, TEXT or BLOB. If numerical data is inserted into a column
|
||||
// > with TEXT affinity it is converted into text form before being
|
||||
// > stored.
|
||||
|
||||
assertNoError {
|
||||
|
||||
// Int is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0 as Int])
|
||||
for row in Row.fetch(db, "SELECT textAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Text storage:
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertEqual((row.value(atIndex: 0) as String?)!, "0")
|
||||
XCTAssertEqual((row.value(atIndex: 0) as String), "0")
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// Int64 is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0 as Int64])
|
||||
for row in Row.fetch(db, "SELECT textAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Text storage:
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertEqual((row.value(atIndex: 0) as String?)!, "0")
|
||||
XCTAssertEqual((row.value(atIndex: 0) as String), "0")
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// Int32 is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0 as Int32])
|
||||
for row in Row.fetch(db, "SELECT textAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Text storage:
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertEqual((row.value(atIndex: 0) as String?)!, "0")
|
||||
XCTAssertEqual((row.value(atIndex: 0) as String), "0")
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// Double is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0.0])
|
||||
for row in Row.fetch(db, "SELECT textAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Text storage:
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertEqual((row.value(atIndex: 0) as String?)!, "0.0")
|
||||
XCTAssertEqual((row.value(atIndex: 0) as String), "0.0")
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// "3.0e+5" is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: ["3.0e+5"])
|
||||
for row in Row.fetch(db, "SELECT textAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Text storage:
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertEqual((row.value(atIndex: 0) as String?)!, "3.0e+5")
|
||||
XCTAssertEqual((row.value(atIndex: 0) as String), "3.0e+5")
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// "foo" is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: ["foo"])
|
||||
for row in Row.fetch(db, "SELECT textAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Text storage:
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertEqual((row.value(atIndex: 0) as String?)!, "foo")
|
||||
XCTAssertEqual((row.value(atIndex: 0) as String), "foo")
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// Blob is turned to Blob
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (textAffinity) VALUES (?)", arguments: ["foo".dataUsingEncoding(NSUTF8StringEncoding)])
|
||||
for row in Row.fetch(db, "SELECT textAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Blob storage:
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Blob?), Blob(data: "foo".dataUsingEncoding(NSUTF8StringEncoding))!)
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testNumericAffinity() {
|
||||
// https://www.sqlite.org/datatype3.html
|
||||
//
|
||||
// > A column with NUMERIC affinity may contain values using all five
|
||||
// > storage classes. When text data is inserted into a NUMERIC column,
|
||||
// > the storage class of the text is converted to INTEGER or REAL (in
|
||||
// > order of preference) if such conversion is lossless and reversible.
|
||||
// > For conversions between TEXT and REAL storage classes, SQLite
|
||||
// > considers the conversion to be lossless and reversible if the first
|
||||
// > 15 significant decimal digits of the number are preserved. If the
|
||||
// > lossless conversion of TEXT to INTEGER or REAL is not possible then
|
||||
// > the value is stored using the TEXT storage class. No attempt is
|
||||
// > made to convert NULL or BLOB values.
|
||||
// >
|
||||
// > A string might look like a floating-point literal with a decimal
|
||||
// > point and/or exponent notation but as long as the value can be
|
||||
// > expressed as an integer, the NUMERIC affinity will convert it into
|
||||
// > an integer. Hence, the string '3.0e+5' is stored in a column with
|
||||
// > NUMERIC affinity as the integer 300000, not as the floating point
|
||||
// > value 300000.0.
|
||||
|
||||
testNumericAffinity("numericAffinity")
|
||||
}
|
||||
|
||||
func testIntegerAffinity() {
|
||||
// https://www.sqlite.org/datatype3.html
|
||||
//
|
||||
// > A column that uses INTEGER affinity behaves the same as a column
|
||||
// > with NUMERIC affinity. The difference between INTEGER and NUMERIC
|
||||
// > affinity is only evident in a CAST expression.
|
||||
|
||||
testNumericAffinity("integerAffinity")
|
||||
}
|
||||
|
||||
func testRealAffinity() {
|
||||
// https://www.sqlite.org/datatype3.html
|
||||
//
|
||||
// > A column with REAL affinity behaves like a column with NUMERIC
|
||||
// > affinity except that it forces integer values into floating point
|
||||
// > representation. (As an internal optimization, small floating point
|
||||
// > values with no fractional component and stored in columns with REAL
|
||||
// > affinity are written to disk as integers in order to take up less
|
||||
// > space and are automatically converted back into floating point as
|
||||
// > the value is read out. This optimization is completely invisible at
|
||||
// > the SQL level and can only be detected by examining the raw bits of
|
||||
// > the database file.)
|
||||
|
||||
assertNoError {
|
||||
|
||||
// Int is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [0 as Int])
|
||||
for row in Row.fetch(db, "SELECT realAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Real storage
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool?)!, false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool), false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int?)!, 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int), 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32?)!, Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32), Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64?)!, Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64), Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double?)!, 0.0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0)
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// Int64 is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [0 as Int64])
|
||||
for row in Row.fetch(db, "SELECT realAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Real storage
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool?)!, false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool), false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int?)!, 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int), 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32?)!, Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32), Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64?)!, Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64), Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double?)!, 0.0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0)
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// Int32 is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [0 as Int32])
|
||||
for row in Row.fetch(db, "SELECT realAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Real storage
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool?)!, false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool), false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int?)!, 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int), 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32?)!, Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32), Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64?)!, Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64), Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double?)!, 0.0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0)
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// 3.0e5 Double is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [3.0e5])
|
||||
for row in Row.fetch(db, "SELECT realAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Real storage
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool?)!, true)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool), true)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int?)!, 300000)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int), 300000)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32?)!, Int32(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32), Int32(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64?)!, Int64(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64), Int64(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double?)!, Double(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double), Double(300000))
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// 1.0e20 Double is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [1.0e20])
|
||||
for row in Row.fetch(db, "SELECT realAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Real storage (avoid Int, Int32 and Int64 since 1.0e20 does not fit)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool?)!, true)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool), true)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double?)!, 1e20)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double), 1e20)
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// "3.0e+5" is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: ["3.0e+5"])
|
||||
for row in Row.fetch(db, "SELECT realAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Real storage
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool?)!, true)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool), true)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int?)!, 300000)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int), 300000)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32?)!, Int32(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32), Int32(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64?)!, Int64(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64), Int64(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double?)!, Double(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double), Double(300000))
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// "1.0e+20" is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: ["1.0e+20"])
|
||||
for row in Row.fetch(db, "SELECT realAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Real storage: (avoid Int, Int32 and Int64 since 1.0e20 does not fit)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool?)!, true)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool), true)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double?)!, 1e20)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double), 1e20)
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// "foo" is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: ["foo"])
|
||||
for row in Row.fetch(db, "SELECT realAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Text storage:
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertEqual((row.value(atIndex: 0) as String?)!, "foo")
|
||||
XCTAssertEqual((row.value(atIndex: 0) as String), "foo")
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// Blob is turned to Blob
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (realAffinity) VALUES (?)", arguments: ["foo".dataUsingEncoding(NSUTF8StringEncoding)])
|
||||
for row in Row.fetch(db, "SELECT realAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Blob storage:
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Blob?), Blob(data: "foo".dataUsingEncoding(NSUTF8StringEncoding))!)
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testNoneAffinity() {
|
||||
// https://www.sqlite.org/datatype3.html
|
||||
//
|
||||
// > A column with affinity NONE does not prefer one storage class over
|
||||
// > another and no attempt is made to coerce data from one storage
|
||||
// > class into another.
|
||||
|
||||
assertNoError {
|
||||
|
||||
// Int is turned to Integer
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0 as Int])
|
||||
for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Integer storage
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool?)!, false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool), false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int?)!, 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int), 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32?)!, Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32), Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64?)!, Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64), Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double?)!, 0.0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0)
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// Int64 is turned to Integer
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0 as Int64])
|
||||
for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Integer storage
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool?)!, false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool), false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int?)!, 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int), 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32?)!, Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32), Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64?)!, Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64), Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double?)!, 0.0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0)
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// Int32 is turned to Integer
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0 as Int32])
|
||||
for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Integer storage
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool?)!, false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool), false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int?)!, 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int), 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32?)!, Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32), Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64?)!, Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64), Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double?)!, 0.0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0)
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// Double is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0.0])
|
||||
for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Real storage
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool?)!, false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool), false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int?)!, 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int), 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32?)!, Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32), Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64?)!, Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64), Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double?)!, 0.0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0)
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// "3.0e+5" is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: ["3.0e+5"])
|
||||
for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Text storage
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertEqual((row.value(atIndex: 0) as String?)!, "3.0e+5")
|
||||
XCTAssertEqual((row.value(atIndex: 0) as String), "3.0e+5")
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// Blob is turned to Blob
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: ["foo".dataUsingEncoding(NSUTF8StringEncoding)])
|
||||
for row in Row.fetch(db, "SELECT noneAffinity FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Blob storage
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Blob?), Blob(data: "foo".dataUsingEncoding(NSUTF8StringEncoding))!)
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testNumericAffinity(columnName: String) {
|
||||
// https://www.sqlite.org/datatype3.html
|
||||
//
|
||||
// > A column with NUMERIC affinity may contain values using all five
|
||||
// > storage classes. When text data is inserted into a NUMERIC column,
|
||||
// > the storage class of the text is converted to INTEGER or REAL (in
|
||||
// > order of preference) if such conversion is lossless and reversible.
|
||||
// > For conversions between TEXT and REAL storage classes, SQLite
|
||||
// > considers the conversion to be lossless and reversible if the first
|
||||
// > 15 significant decimal digits of the number are preserved. If the
|
||||
// > lossless conversion of TEXT to INTEGER or REAL is not possible then
|
||||
// > the value is stored using the TEXT storage class. No attempt is
|
||||
// > made to convert NULL or BLOB values.
|
||||
// >
|
||||
// > A string might look like a floating-point literal with a decimal
|
||||
// > point and/or exponent notation but as long as the value can be
|
||||
// > expressed as an integer, the NUMERIC affinity will convert it into
|
||||
// > an integer. Hence, the string '3.0e+5' is stored in a column with
|
||||
// > NUMERIC affinity as the integer 300000, not as the floating point
|
||||
// > value 300000.0.
|
||||
|
||||
assertNoError {
|
||||
|
||||
// Int is turned to Integer
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [0 as Int])
|
||||
for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Integer storage
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool?)!, false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool), false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int?)!, 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int), 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32?)!, Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32), Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64?)!, Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64), Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double?)!, 0.0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0)
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// Int64 is turned to Integer
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [0 as Int64])
|
||||
for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Integer storage
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool?)!, false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool), false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int?)!, 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int), 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32?)!, Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32), Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64?)!, Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64), Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double?)!, 0.0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0)
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// Int32 is turned to Integer
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [0 as Int32])
|
||||
for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Integer storage
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool?)!, false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool), false)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int?)!, 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int), 0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32?)!, Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32), Int32(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64?)!, Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64), Int64(0))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double?)!, 0.0)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double), 0.0)
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// 3.0e5 Double is turned to Integer
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [3.0e5])
|
||||
for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Integer storage
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool?)!, true)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool), true)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int?)!, 300000)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int), 300000)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32?)!, Int32(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32), Int32(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64?)!, Int64(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64), Int64(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double?)!, Double(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double), Double(300000))
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// 1.0e20 Double is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [1.0e20])
|
||||
for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Real storage (avoid Int, Int32 and Int64 since 1.0e20 does not fit)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool?)!, true)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool), true)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double?)!, 1e20)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double), 1e20)
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// "3.0e+5" is turned to Integer
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: ["3.0e+5"])
|
||||
for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Integer storage
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool?)!, true)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool), true)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int?)!, 300000)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int), 300000)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32?)!, Int32(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int32), Int32(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64?)!, Int64(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Int64), Int64(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double?)!, Double(300000))
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double), Double(300000))
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// "1.0e+20" is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: ["1.0e+20"])
|
||||
for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Real storage: (avoid Int, Int32 and Int64 since 1.0e20 does not fit)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool?)!, true)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Bool), true)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double?)!, 1e20)
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Double), 1e20)
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// "foo" is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: ["foo"])
|
||||
for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Text storage:
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertEqual((row.value(atIndex: 0) as String?)!, "foo")
|
||||
XCTAssertEqual((row.value(atIndex: 0) as String), "foo")
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Blob?) == nil) // incompatible with GRDB conversion
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
|
||||
// Blob is turned to Blob
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute("INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: ["foo".dataUsingEncoding(NSUTF8StringEncoding)])
|
||||
for row in Row.fetch(db, "SELECT \(columnName) FROM `values`") {
|
||||
|
||||
// Check SQLite conversions from Blob storage:
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Bool?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int32?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Int64?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as Double?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertFalse((row.value(atIndex: 0) as String?) == nil) // incompatible with GRDB conversion
|
||||
XCTAssertEqual((row.value(atIndex: 0) as Blob?), Blob(data: "foo".dataUsingEncoding(NSUTF8StringEncoding))!)
|
||||
}
|
||||
return .Rollback
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,8 +128,6 @@
|
||||
56AC8CCF1BA3F2AD009E4319 /* ConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AC8CCD1BA3F2AD009E4319 /* ConcurrencyTests.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
56BB86131BA9886D001F9168 /* FetchPerformanceTests.sqlite in Resources */ = {isa = PBXBuildFile; fileRef = 56BB86111BA9886D001F9168 /* FetchPerformanceTests.sqlite */; settings = {ASSET_TAGS = (); }; };
|
||||
56BB86141BA9886D001F9168 /* FetchPerformanceTests.sqlite in Resources */ = {isa = PBXBuildFile; fileRef = 56BB86111BA9886D001F9168 /* FetchPerformanceTests.sqlite */; settings = {ASSET_TAGS = (); }; };
|
||||
56BB86151BA9886D001F9168 /* FetchPerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BB86121BA9886D001F9168 /* FetchPerformanceTests.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
56BB86161BA9886D001F9168 /* FetchPerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BB86121BA9886D001F9168 /* FetchPerformanceTests.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
56BB86231BA988F2001F9168 /* FMDatabase.m in Sources */ = {isa = PBXBuildFile; fileRef = 56BB86191BA988F2001F9168 /* FMDatabase.m */; settings = {ASSET_TAGS = (); }; };
|
||||
56BB86241BA988F2001F9168 /* FMDatabase.m in Sources */ = {isa = PBXBuildFile; fileRef = 56BB86191BA988F2001F9168 /* FMDatabase.m */; settings = {ASSET_TAGS = (); }; };
|
||||
56BB86251BA988F2001F9168 /* FMDatabaseAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 56BB861B1BA988F2001F9168 /* FMDatabaseAdditions.m */; settings = {ASSET_TAGS = (); }; };
|
||||
@@ -148,6 +146,10 @@
|
||||
56E5D8181B4D435D00430942 /* GRDBTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623E0901B4AFACC00B20B7F /* GRDBTestCase.swift */; };
|
||||
56E5D82C1B4D437600430942 /* GRDB.h in Headers */ = {isa = PBXBuildFile; fileRef = DC3773F819C8CBB3004FCF85 /* GRDB.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
56E5D82D1B4D438800430942 /* GRDB-Bridging.h in Headers */ = {isa = PBXBuildFile; fileRef = DC2393C61ABE35F8003FF113 /* GRDB-Bridging.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
56EE573D1BB317B7007A6A95 /* MetalTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EE573C1BB317B7007A6A95 /* MetalTypeTests.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
56EE573E1BB317B7007A6A95 /* MetalTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EE573C1BB317B7007A6A95 /* MetalTypeTests.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
56EE573F1BB31DBA007A6A95 /* FetchPerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BB86121BA9886D001F9168 /* FetchPerformanceTests.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
56EE57401BB31DBA007A6A95 /* FetchPerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BB86121BA9886D001F9168 /* FetchPerformanceTests.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
56F0B98F1B6001C600A2F135 /* NSDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* NSDateComponentsTests.swift */; };
|
||||
56F0B9901B6001C600A2F135 /* NSDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* NSDateComponentsTests.swift */; };
|
||||
56F0B9911B6001C600A2F135 /* NSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* NSDateTests.swift */; };
|
||||
@@ -259,6 +261,7 @@
|
||||
56E5D7CA1B4D3FED00430942 /* GRDB.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = GRDB.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
56E5D7D31B4D3FEE00430942 /* GRDBTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
56E5D7F91B4D422D00430942 /* GRDBTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
56EE573C1BB317B7007A6A95 /* MetalTypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalTypeTests.swift; sourceTree = "<group>"; };
|
||||
56F0B98D1B6001C600A2F135 /* NSDateComponentsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSDateComponentsTests.swift; sourceTree = "<group>"; };
|
||||
56F0B98E1B6001C600A2F135 /* NSDateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSDateTests.swift; sourceTree = "<group>"; };
|
||||
DC2393C61ABE35F8003FF113 /* GRDB-Bridging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GRDB-Bridging.h"; sourceTree = "<group>"; };
|
||||
@@ -377,6 +380,7 @@
|
||||
56A238151B9C74A90082EB20 /* DatabaseError */,
|
||||
56A238171B9C74A90082EB20 /* DatabaseValue */,
|
||||
56A238191B9C74A90082EB20 /* DatabaseValueConvertible */,
|
||||
56EE573B1BB317B7007A6A95 /* MetalType */,
|
||||
56A2381D1B9C74A90082EB20 /* Row */,
|
||||
56A238201B9C74A90082EB20 /* Statement */,
|
||||
);
|
||||
@@ -576,6 +580,14 @@
|
||||
path = GRDBOSX;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
56EE573B1BB317B7007A6A95 /* MetalType */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
56EE573C1BB317B7007A6A95 /* MetalTypeTests.swift */,
|
||||
);
|
||||
path = MetalType;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
56F0B98C1B6001C600A2F135 /* Foundation */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@@ -887,11 +899,11 @@
|
||||
56A238641B9C74A90082EB20 /* RecordAwakeFromFetchTests.swift in Sources */,
|
||||
56A2385A1B9C74A90082EB20 /* PrimaryKeySingleTests.swift in Sources */,
|
||||
56A238661B9C74A90082EB20 /* RecordFetchTests.swift in Sources */,
|
||||
56EE573E1BB317B7007A6A95 /* MetalTypeTests.swift in Sources */,
|
||||
56A238481B9C74A90082EB20 /* FetchedRowTests.swift in Sources */,
|
||||
56BB862C1BA988F2001F9168 /* FMResultSet.m in Sources */,
|
||||
56A2386E1B9C74A90082EB20 /* RecordUpdateFromRowTests.swift in Sources */,
|
||||
56A238541B9C74A90082EB20 /* PrimaryKeyMultipleTests.swift in Sources */,
|
||||
56BB86161BA9886D001F9168 /* FetchPerformanceTests.swift in Sources */,
|
||||
56BB862A1BA988F2001F9168 /* FMDatabaseQueue.m in Sources */,
|
||||
56A238681B9C74A90082EB20 /* RecordInitializersTests.swift in Sources */,
|
||||
56A2385E1B9C74A90082EB20 /* RecordCopyTests.swift in Sources */,
|
||||
@@ -905,6 +917,7 @@
|
||||
56A2385C1B9C74A90082EB20 /* PrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */,
|
||||
56997A8F1B5390D4005EBEED /* DatabaseErrorFromStatementCreationTests.swift in Sources */,
|
||||
56A238401B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift in Sources */,
|
||||
56EE57401BB31DBA007A6A95 /* FetchPerformanceTests.swift in Sources */,
|
||||
56A2383C1B9C74A90082EB20 /* DatabaseErrorTests.swift in Sources */,
|
||||
56A238521B9C74A90082EB20 /* MinimalPrimaryKeySingleTests.swift in Sources */,
|
||||
56A238B71B9CA2590082EB20 /* DatabaseTimestampTests.swift in Sources */,
|
||||
@@ -934,12 +947,12 @@
|
||||
56A2384D1B9C74A90082EB20 /* DatabaseMigratorTests.swift in Sources */,
|
||||
56A238631B9C74A90082EB20 /* RecordAwakeFromFetchTests.swift in Sources */,
|
||||
56A238591B9C74A90082EB20 /* PrimaryKeySingleTests.swift in Sources */,
|
||||
56EE573D1BB317B7007A6A95 /* MetalTypeTests.swift in Sources */,
|
||||
56A238651B9C74A90082EB20 /* RecordFetchTests.swift in Sources */,
|
||||
56A238471B9C74A90082EB20 /* FetchedRowTests.swift in Sources */,
|
||||
56BB862B1BA988F2001F9168 /* FMResultSet.m in Sources */,
|
||||
56A2386D1B9C74A90082EB20 /* RecordUpdateFromRowTests.swift in Sources */,
|
||||
56A238531B9C74A90082EB20 /* PrimaryKeyMultipleTests.swift in Sources */,
|
||||
56BB86151BA9886D001F9168 /* FetchPerformanceTests.swift in Sources */,
|
||||
56BB86291BA988F2001F9168 /* FMDatabaseQueue.m in Sources */,
|
||||
56A238671B9C74A90082EB20 /* RecordInitializersTests.swift in Sources */,
|
||||
56A2385D1B9C74A90082EB20 /* RecordCopyTests.swift in Sources */,
|
||||
@@ -952,6 +965,7 @@
|
||||
56A2385B1B9C74A90082EB20 /* PrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */,
|
||||
56997A8E1B5390D4005EBEED /* DatabaseErrorFromStatementCreationTests.swift in Sources */,
|
||||
56A2383F1B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift in Sources */,
|
||||
56EE573F1BB31DBA007A6A95 /* FetchPerformanceTests.swift in Sources */,
|
||||
56A2383B1B9C74A90082EB20 /* DatabaseErrorTests.swift in Sources */,
|
||||
56A238511B9C74A90082EB20 /* MinimalPrimaryKeySingleTests.swift in Sources */,
|
||||
56A238B61B9CA2590082EB20 /* DatabaseTimestampTests.swift in Sources */,
|
||||
|
||||
Reference in new issue
Block a user