2012-01-10 161 views
1

我創建了一個SQLite數據庫(在windows中),其中有一個Int64列。我將數據庫複製到我的MonoTouch程序中。Int64使用SQLite拋出「數字溢出」

當我嘗試閱讀的MonoTouch(Mono.Data.Sqlite)列,它拋出一個「數字溢出」 ......

System.OverflowException: Number overflow. 
    at System.Convert.ToInt32 (Int64 value) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Convert.cs:1109 
    at System.Int64.System.IConvertible.ToInt32 (IFormatProvider provider) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Int64.cs:553 
    at System.Convert.ToType (System.Object value, System.Type conversionType, IFormatProvider provider, Boolean try_target_to_type) [0x00139] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Convert.cs:2596 
    at System.Convert.ChangeType (System.Object value, System.Type conversionType, IFormatProvider provider) [0x00017] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Convert.cs:2204 
    at Mono.Data.Sqlite.SQLite3.GetValue (Mono.Data.Sqlite.SqliteStatement stmt, Int32 index, Mono.Data.Sqlite.SQLiteType typ) [0x0011e] in /Developer/MonoTouch/Source/mono/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLite3.cs:990 
    at Mono.Data.Sqlite.SqliteDataReader.GetValue (Int32 i) [0x00033] in /Developer/MonoTouch/Source/mono/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteDataReader.cs:796 
    at Mono.Data.Sqlite.SqliteDataReader.get_Item (Int32 i) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteDataReader.cs:1023 
    at System.Data.Common.DbDataAdapter.FillFromReader (System.Data.DataTable table, IDataReader reader, Int32 start, Int32 length, System.Int32[] mapping, LoadOption loadOption) [0x0003e] in /Developer/MonoTouch/Source/mono/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs:365 
    at System.Data.DataTable.Load (IDataReader reader, LoadOption loadOption) [0x0002f] in /Developer/MonoTouch/Source/mono/mcs/class/System.Data/System.Data/DataTable.cs:2857 
    at System.Data.DataTable.Load (IDataReader reader) [0x00011] in /Developer/MonoTouch/Source/mono/mcs/class/System.Data/System.Data/DataTable.cs:2838 

任何想法,爲什麼我怎麼能解決這個問題?

回答

0

看來你正在讀取SQLLite的Int64值,並在序列化爲mongodb時轉換爲Int32,這將導致超出範圍和拋出錯誤。這裏是JIRA爲mongo提出的鏈接和可能的解決方法。 Mongodb Number overflow error

1

例外是由於一個不能轉換爲int的數字(即它可以與小的long值一起使用)。某種方式的代碼在

在Mono.Data.Sqlite.SQLite3.GetValue(Mono.Data.Sqlite.SqliteStatement語句,的Int32索引,Mono.Data.Sqlite.SQLiteType典型值)[0x0011e]在/開發人員/ MonoTouch的/Source/mono/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLite3.cs:990

決定類型是System.Int32而不是一個System.Int64。這意味着在堆棧之上的某個東西正在作出錯誤決定數據表結構被誤讀。

不幸的是我不知道如何解決這個問題。解決這個問題的最好方法是在http://bugzilla.xamarin.com上打開一個錯誤報告,並在數據庫中附上一個簡單的測試用例來說明問題。這將使我們能夠看到問題的具體位置,併爲您提供解決方案。

0

我在Microsoft Visual Studio的SQLite中遇到了同樣的問題。任何Int64列上的選擇都會導致溢出。我看起來像System.Data.DataTable中的錯誤。有錯誤的方法是dtTable.Load(aSQLDataReader);

我的工作是在查詢中將所有Int64列轉換爲TEXT。

而不是 SELECT columName FROM tableName

我做SELECT CAST(columnName as TEXT) columName FROM tableName

sqlite的,然後返回值作爲文本字段。