Int64使用SQLite抛出“数字溢出”

时间:2012-01-10 19:33:37

标签: ios sqlite mono xamarin.ios system.data

我创建了一个带有Int64列的SQLite数据库(在Windows中)。我将数据库复制到我的MonoTouch程序。

当我尝试读取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 

我知道为什么以及如何解决它?

3 个答案:

答案 0 :(得分:1)

异常是由于无法转换为int的数字(即它可以使用小long个值)。

的代码
  

在/ Developer / MonoTouch / Source / mono / mcs /中的Mono.Data.Sqlite.SQLite3.GetValue(Mono.Data.Sqlite.SqliteStatement stmt,Int32 index,Mono.Data.Sqlite.SQLiteType typ)[0x0011e] class / Mono.Data.Sqlite / Mono.Data.Sqlite_2.0 / SQLite3.cs:990

确定类型是System.Int32而不是System.Int64。这意味着,在堆栈中的某些内容正在做出错误的决定数据结构被误读。

可悲的是,我不确定你如何解决这个问题。解决此问题的最佳方法是在http://bugzilla.xamarin.com打开错误报告,并附上一个简单的测试用例,其中包含显示问题的数据库。这将使我们能够确定问题的确切位置并为您提供解决方案。

答案 1 :(得分:1)

我在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将值作为文本字段返回。

答案 2 :(得分:0)

您似乎正在从SQLLite读取Int64值并在序列化为mongodb时转换为Int32,这将导致超出范围并抛出错误。这里是为mongo筹集的JIRA的链接和可能的解决方法。 Mongodb Number overflow error