mysql – 当我要求unsigned big int时,为什么Delphi(Zeos)在SQLite中给我带宽字符串?

我正在使用最新的zeossqlite 3.一旦我们创建了所有持久性整数字段TLargeInt,它通常很顺利,从MySQL转换.

但是当我们使用列定义unsigned big int(根据https://www.sqlite.org/datatype3.html允许的唯一无符号类型)时,Delphi将结果字段调用为ftWidestring.

解决方法:

不,它不会“恢复”为字符串,sqlite只是存储提供的数据.

the documentation states

sqlite supports the concept of “type affinity” on columns. The type affinity of a column is the recommended type for data stored in that column. The important idea here is that the type is recommended, not required. Any column can still store any type of data. It is just that some columns, given the choice, will prefer to use one storage class over another. The preferred storage class for a column is called its “affinity”.

如果提供/绑定文本值,它将存储文本值.没有转换为CREATE TABLE语句中提供的类型,因为它可能出现在其他更严格的RBMS中,例如MysqL的.

因此,在您的情况下,如果您将数据检索为ftWideString,我想这是因为您将数据写为TEXT.例如,从MysqL创建sqlite3内容的工具或程序将此列写为TEXT.

关于数字,没有“签名”/“无符号”,也没有sqlite3中的精确检查.因此,如果要存储“unsigned big int”值,只需使用INT64,即Int64.

但是,在所有情况下,即使是SQLite3 API does support UNSIGNED 64 bit integers,zeos / ZDBC API或Delphi(旧版本的Delphi不支持UInt64)也很难支持这种sqlite3_uint64类型.可以肯定的是,您应该更好地检索TEXT等值,然后在Delphi代码中手动将其转换为UInt64.

更新:

您使用的是zeos提供的TDataSet后代吗?此组件与DB.Pas绑定,因此需要单个每列类型.它可能是您的代码混淆的根源(您根本没有显示,因此很难弄清楚发生了什么).

您应该更好地使用较低级别的ZDBC接口,该接口允许检索每行的列类型,并根据需要调用值getter方法.

相关文章

SQLite架构简单,又有Json计算能力,有时会承担Json文件/RES...
使用Python操作内置数据库SQLite以及MySQL数据库。
破解微信数据库密码,用python导出微信聊天记录
(Unity)SQLite 是一个软件库,实现了自给自足的、无服务器...
安卓开发,利用SQLite实现登陆注册功能