ios Int64使用SQLite抛出“Number overflow”

a7qyws3x  于 12个月前  发布在  iOS
关注(0)|答案(4)|浏览(108)

我已经创建了一个SQLite数据库(在Windows中),其中包含一个Int64列。我把数据库复制到了我的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

你知道我为什么以及如何修复它吗?

sycxhyv7

sycxhyv71#

例外是由于无法转换为int的数字(即它将对较小的long值起作用)。不知何故,
在/Developer/MonoTouch/Source/mono/mcs/class/Mono.Data. Sqlite/Mono.Data.Sqlite_2.0/SQLite3.cs中的Mono.Data.Sqlite.Sqlite3.GetValue(Mono.Data.Sqlite.SqliteStatement stmt,Int32 index,Mono. Data.SqliteType typ)[0x0011e]:990
判断类型是System.Int32而不是System.Int64。这意味着堆栈中的某个东西正在做出错误的决定数据表结构被误读。
很遗憾我不知道你该如何解决这个问题。解决这个问题的最好方法是在http://bugzilla.xamarin.com上打开一个bug报告,并附上一个简单的测试用例和数据库,以显示问题。这将使我们能够看到问题的确切位置,并为您提供解决方案。

qc6wkl3g

qc6wkl3g2#

我在Microsoft Visual Studio中的SQLite中遇到了同样的问题。选择任何Int 64列都会导致溢出。我看起来像是System. Data. DataTable中的一个bug。出现错误的方法是dtTable.Load(aSQLDataReader);
我的工作是在查询中将所有Int 64列转换为TEXT。
而不是SELECT columName FROM tableName
SELECT CAST(columnName as TEXT) columName FROM tableName
然后,SQLite将值作为文本字段返回。

ymzxtsji

ymzxtsji3#

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

sshcrbum

sshcrbum4#

我也遇到了同样的问题,在进行了详尽的调试之后,我发现将数据库字段数据类型从“INT”更改为“INTEGER”解决了这个问题。
看起来客户端错误地使用了数据库数据类型来进行转换,即使对数据库来说也是一样的。

相关问题