From dbfe33d55b4173f200c5b3cedc8c96f53819a21a Mon Sep 17 00:00:00 2001 From: Tanner Nelson Date: Wed, 19 Jul 2017 15:41:23 -0400 Subject: [PATCH] fix int 64 fetch --- Sources/SQLite/SQLite+Result.swift | 2 +- Tests/SQLiteTests/SQLite3Tests.swift | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Sources/SQLite/SQLite+Result.swift b/Sources/SQLite/SQLite+Result.swift index dbd74c8..2ab95fa 100644 --- a/Sources/SQLite/SQLite+Result.swift +++ b/Sources/SQLite/SQLite+Result.swift @@ -44,7 +44,7 @@ extension SQLite { data[column] = .string(value) case SQLITE_INTEGER: - let integer = Int(sqlite3_column_int(pointer, i)) + let integer = Int(sqlite3_column_int64(pointer, i)) data[column] = .number(.int(integer)) case SQLITE_FLOAT: // as in floating point, actually returns a double. diff --git a/Tests/SQLiteTests/SQLite3Tests.swift b/Tests/SQLiteTests/SQLite3Tests.swift index 0d2c35f..148e808 100644 --- a/Tests/SQLiteTests/SQLite3Tests.swift +++ b/Tests/SQLiteTests/SQLite3Tests.swift @@ -3,9 +3,6 @@ import XCTest import Node class SQLite3Tests: XCTestCase { - static let allTests = [("testTables", testTables), - ("testUnicode", testUnicode)] - var database:SQLite! override func setUp() { @@ -77,17 +74,24 @@ class SQLite3Tests: XCTestCase { } func testBigInts() throws { - let bar: UInt64 = 1 << 20 - let baz: UInt64 = 1 << 40 + let max = Int.max - _ = try database.execute("DROP TABLE IF EXISTS foo") - _ = try database.execute("CREATE TABLE foo (bar BIGINT, baz BIGINT)") - _ = try database.execute("INSERT INTO foo VALUES (\(bar), (\(baz)))") + _ = try! database.execute("DROP TABLE IF EXISTS foo") + _ = try! database.execute("CREATE TABLE foo (max INT)") + _ = try! database.execute("INSERT INTO foo VALUES (?)") { statement in + try! statement.bind(max) + + } - if let result = try database.execute("SELECT * FROM foo").first { - XCTAssertEqual(result.data["bar"], bar.makeNode(in: nil)) - XCTAssertEqual(result.data["baz"], baz.makeNode(in: nil)) + if let result = try! database.execute("SELECT * FROM foo").first { + XCTAssertEqual(result.data["max"], max.makeNode(in: nil)) } } + + static let allTests = [ + ("testTables", testTables), + ("testUnicode", testUnicode), + ("testBigInts", testBigInts), + ] }