From 033c9e6325d7ec264f8fcf175f26596db53d37a1 Mon Sep 17 00:00:00 2001 From: Zhao Wang Date: Tue, 11 Aug 2015 16:53:30 -0700 Subject: [PATCH 1/2] Fix the issue that can not read Int64 Int64 can be saved to data base, but if the Int64 is bigger than Int32.Max, when read that number back from database, it is an unexpected value. --- SwiftData.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SwiftData.swift b/SwiftData.swift index c3e7ad2..abdc959 100644 --- a/SwiftData.swift +++ b/SwiftData.swift @@ -939,7 +939,7 @@ public struct SwiftData { if sqlite3_column_type(statement, index) == SQLITE_NULL { return nil } - return Int(sqlite3_column_int(statement, index)) + return Int(sqlite3_column_int64(statement, index)) case "CHARACTER(20)", "VARCHAR(255)", "VARYING CHARACTER(255)", "NCHAR(55)", "NATIVE CHARACTER", "NVARCHAR(100)", "TEXT", "CLOB": let text = UnsafePointer(sqlite3_column_text(statement, index)) return String.fromCString(text) @@ -1705,4 +1705,4 @@ extension SwiftData.SDError { } -public typealias SD = SwiftData \ No newline at end of file +public typealias SD = SwiftData From 1f9c03ad54a5a0d36784856f64c8740dd3901201 Mon Sep 17 00:00:00 2001 From: Zhao Wang Date: Wed, 12 Aug 2015 11:41:20 -0700 Subject: [PATCH 2/2] Make sure it can read Int64 for both 32/64 bits --- SwiftData.swift | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/SwiftData.swift b/SwiftData.swift index abdc959..061e8f1 100644 --- a/SwiftData.swift +++ b/SwiftData.swift @@ -939,7 +939,7 @@ public struct SwiftData { if sqlite3_column_type(statement, index) == SQLITE_NULL { return nil } - return Int(sqlite3_column_int64(statement, index)) + return NSNumber(longLong: sqlite3_column_int64(statement, index)) case "CHARACTER(20)", "VARCHAR(255)", "VARYING CHARACTER(255)", "NCHAR(55)", "NATIVE CHARACTER", "NVARCHAR(100)", "TEXT", "CLOB": let text = UnsafePointer(sqlite3_column_text(statement, index)) return String.fromCString(text) @@ -1141,7 +1141,22 @@ public struct SwiftData { :returns: An Optional Int corresponding to the apprioriate column value. Will be nil if: the column name does not exist, the value cannot be cast as a Int, or the value is NULL */ public func asInt() -> Int? { - return value as? Int + if let num = value as? NSNumber { + return num.longValue + } + return nil + } + + /** + Return the column value as an Int64 + + :returns: An Optional Int64 corresponding to the apprioriate column value. Will be nil if: the column name does not exist, the value cannot be cast as a Int64, or the value is NULL + */ + public func asInt64() -> Int64? { + if let num = value as? NSNumber { + return num.longLongValue + } + return nil } /**