Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# System.Data.SQLite将未签名的int字段错误地键入System.Int32_C#_Sqlite_Unsigned Integer - Fatal编程技术网

C# System.Data.SQLite将未签名的int字段错误地键入System.Int32

C# System.Data.SQLite将未签名的int字段错误地键入System.Int32,c#,sqlite,unsigned-integer,C#,Sqlite,Unsigned Integer,使用System.Data.SQLite,我正在创建一个包含无符号整数列的表: @"CREATE TABLE widgets (" + @"id unsigned integer(10) PRIMARY KEY, " + @"fkey unsigned integer(10), " + ... 然后插入值,如 INSERT INTO widgets (id, fkey, ...) VALUES (4294967295, 3456, ... 然而,在这个表的行和列上循环,我发现

使用
System.Data.SQLite
,我正在创建一个包含无符号整数列的表:

@"CREATE TABLE widgets (" +
    @"id unsigned integer(10) PRIMARY KEY, " +
    @"fkey unsigned integer(10), " + ...
然后插入值,如

INSERT INTO widgets (id, fkey, ...) VALUES (4294967295, 3456, ...
然而,在这个表的行和列上循环,我发现
行[“id”]
的类型是
System.Int32
(而不是
UInt32
),并且,毫不奇怪,4294967295被解释为-1。实际上,表中所有未签名的int字段(不仅主键id被错误地键入为
System.Int32

同时,SQLite类型规范指出,根据值的大小,整数存储在1、2、3、4、6或8字节中。4294967295=0xFFFFFFFF只适合四个字节。它似乎也和SQLite所谓的“动态类型”不一致。当我插入大于4294967295的正值时,类型保持为
System.Int32

它是一个bug还是一个特性

PS1:

我的表包含一行,列id=2^32-1=4294967295(或更大),我打印所有列的类型,并使用

public void PrintDataTypes(DataTable dt) {
    foreach (DataRow row in dt.Rows) {
        foreach (DataColumn col in dt.Columns)
            Console.WriteLine("name={0}, type={1}", 
                               col.ToString(),
                               row[col].GetType().ToString());
        return; // after 1st row is done
    }
}
我总是得到

name=id, type=System.Int32
name=fkey, type=System.Int32
...    

即使在SQL中指定了unsigned,在SqLite中也不会得到无符号整数列。是的,我个人认为这是一个明显的缺陷——它甚至在你的SQL中看到你的“未签名”规范时甚至不会发出警告。因此,您的列是64位有符号的,您可以存储的最大值实际上是63次方的2。

请参阅-据我所知,SQLite忽略了“unsigned”关键字和大小说明符。要确定您看到
Int32
的原因,您可能需要发布用于从表中读取的代码。谢谢!我在原始帖子中添加了PS1,以解释如何获取System.Int32,引用了您建议的参考:例如,INTEGER存储类包括6种不同长度的不同整数数据类型。这会在磁盘上产生影响。但是,一旦将整数值从磁盘读取到内存中进行处理,它们就会转换为最通用的数据类型(8字节有符号整数)。在SQLite中,所有整数都具有相同的类型,即有符号64位。(更小的存储只是一种优化)。使用
Int32
看起来像是数据库驱动程序中的一个bug。仍然缺少的是SQlite表如何变成DataTable。可能是适配器或表配置错误。如果它们是强类型的,选择查询是什么?