gpt4 book ai didi

c# - 关于 SQLite 整数和 int 数据类型的问题

转载 作者:行者123 更新时间:2023-11-30 13:25:03 25 4
gpt4 key购买 nike

我遇到了一个问题:在运行基于 SQLite 提供程序的 SubSonic.Examples.SimpleRepo 项目时,类型为“System.Int64”的对象无法转换为类型“System.Int32”。 p>

我喜欢表Categories的列CategoryID的数据类型是'integer',同时SQLite中的'integer'将返回为Int64,同时Class Category中CategoryID的数据类型为int,出现上述错误。

我查看了 SubSonic 的源代码:\SubSonic.Core\SQLGeneration\Schema\SQLiteSchema.cs 并找到以下代码:

else if (column.IsPrimaryKey && column.DataType == DbType.Int32
|| column.IsPrimaryKey && column.DataType == DbType.Int16
|| column.IsPrimaryKey && column.DataType == DbType.Int64
)
sb.Append(" integer ");

谁能告诉我这些代码的用途?如何解决数据类型转换错误?

最佳答案

有趣的是,大约一个小时前我刚刚阅读了关于此的 sqlite3 文档。所以你很幸运:)

See the doc yourself (滚动到底部的 64 位 ROWID 部分)。

摘录如下:

To minimize storage space, the 64-bit rowid is stored as a variablelength integer. Rowids between 0 and 127 use only a single byte.Rowids between 0 and 16383 use just 2 bytes. Up to 2097152 uses threebytes. And so forth. Negative rowids are allowed but they always usenine bytes of storage and so their use is discouraged. When rowids aregenerated automatically by SQLite, they will always be non-negative.

第三方编辑

令我惊讶的是,尽管 Id 列被创建为 int 列,但它也被映射到 long

CREATE TABLE "Example" (
"Id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"Foo" TEXT NULL,
"SomeDate" DATETIME NULL
)

解释也在64-bit ROWID section

Every row of a table has a unique rowid. If the table defines a columnwith the type "INTEGER PRIMARY KEY" then that column becomes an aliasfor the rowid. But with or without an INTEGER PRIMARY KEY column,every row still has a rowid.

In SQLite version 3.0, the rowid is a 64-bit signed integer.

关于c# - 关于 SQLite 整数和 int 数据类型的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1320293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com