为什么当我要求unsigned big int时,Delphi(Zeos)在SQLite中给我最广泛的字段? [英] Why is Delphi (Zeos) giving me widestring fields in SQLite when I ask for unsigned big int?

查看:379
本文介绍了为什么当我要求unsigned big int时,Delphi(Zeos)在SQLite中给我最广泛的字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SQLite 3中最新的Zeos。一旦我们完成了所有持久整数字段 TLargeInt

但是当我们使用列定义 unsigned big int (根据 https://www.sqlite.org/datatype3.html ),Delphi正在调用生成的字段一个 ftWidestring

解决方案

不,它没有还原到字符串,SQlite只将数据存储为提供。



作为文档状态


SQLite支持列上类型亲和性的概念。列的类型关联是存储在该列中的数据的推荐类型。这里的重要思想是推荐,不需要。任何列仍然可以存储任何类型的数据。只是一些列,给予选择,将更喜欢使用一个存储类超过另一个。列的首选存储类称为亲和性。


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



所以在你的情况下,如果你以 ftWideString 的形式检索数据,我猜这是因为你写的数据作为TEXT。例如,从MySQL创建SQLite3内容的工具或程序将此列写为TEXT。



关于数字,没有签名/无符号也不精确检查SQLite3。所以如果要存储unsigned big int值,只需使用INTEGER即Int64。



但是,在所有情况下,即使 SQLite3 API支持UNSIGNED 64位整数,这个 sqlite3_uint64 类型可能几乎不被Zeos / ZDBC API或Delphi支持(旧版本的Delphi不支持UInt64)。可以肯定的是,您应该更好地检索这样的值,如TEXT,然后在Delphi代码中手动将其转换为 UInt64



<您是否使用Zeos提供的 TDataSet 后代?



该组件绑定到 DB.Pas ,因此期望单列每列。这可能是您的代码混乱的根源(您根本没有显示,所以很难弄清楚发生了什么)。



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


I am using the latest Zeos with SQLite 3. It is generally going well, converting from MySQL, once we made all the persistent integer field TLargeInt.

But when we use a column definition unsigned big int (the only unsigned type allowed according to https://www.sqlite.org/datatype3.html), Delphi is calling the resulting field a ftWidestring.

解决方案

No, it does not "revert" to string, SQlite just stores the data as it is provided.

As 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".

If you supplied/bind a text value, it would store a text value. There is no conversion to the type supplied in the CREATE TABLE statement, as it may appear in other more strict RBMS, e.g. MySQL.

So in your case, if you retrieve the data as ftWideString, I guess this is because you wrote the data as TEXT. For instance, the tool or program creating the SQLite3 content from your MySQL is writing this column as TEXT.

About numbers, there is no "signed"/"unsigned", nor precision check in SQLite3. So if you want to store "unsigned big int" values, just use INTEGER, which are Int64.

But, in all cases, even if SQLite3 API does support UNSIGNED 64 bit integers, this sqlite3_uint64 type may hardly be supported by the Zeos/ZDBC API or by Delphi (older versions of Delphi do NOT support UInt64). To be sure, you should better retrieve such values as TEXT, then convert it as UInt64 manually in your Delphi code.

Update:

Are you using the TDataSet descendant provided by Zeos? This component is tied to DB.Pas, so expects a single per-column type. It may be the source of confusion of your code (which you did not show at all, so it is hard to figure out what's happening).

You should better use the lower level ZDBC interface, which allows to retrieve the column type for each row, and call the value getter method as you need.

这篇关于为什么当我要求unsigned big int时,Delphi(Zeos)在SQLite中给我最广泛的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆