如何在Delphi中强制SQLite聚合字段为数字字段? [英] How in Delphi can I force an SQLite aggregate field to be a numeric field?

查看:45
本文介绍了如何在Delphi中强制SQLite聚合字段为数字字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在转换为MySQL编写的程序以使用SQLite.一些代码会自动适应我们从数据库中获取的字段类型.SQLite具有作为ftWideString呈现的SQL SUM(...)函数的有趣"属性(大概是为了处理可能的溢出).我们需要这些字段为整数或浮点型字段.我尝试了这一点,这似乎很明显地迫使SQL为您提供所需的类型:

We are converting a program written for MySQL to use SQLite. Some of the code adapts automatically to the type of fields we get back from the database. SQLite has the "interesting" property of present the SQL SUM(...) function as ftWideString (presumably to handle possible overflow). We need these fields to be integer or float fields. I tried this, which seems to obvious compel the SQL to give you the type you need:

SELECT cast(sum(units) as int) FROM dr02

但是类型仍然是ftWideString.

but the type is still ftWideString.

如何根据需要返回ftInteger或ftLargeInt或ftFloat?

How can I make it return an ftInteger or ftLargeInt, or ftFloat, as required?

推荐答案

尝试

SELECT sum(units)*1.0 FROM dr02

SELECT cast(sum(units) as real) FROM dr02

您尚未定义正在使用的库.您的问题与访问SQLite3的库高度相关.直接访问(通过 ZDBC/Zeos 7.2

You did not define which library you are using. Your question is highly linked to the library accessing SQLite3. A direct access (via ZDBC/Zeos 7.2 or SynSQLite3) would allow to get the value directly with the expected type.

这篇关于如何在Delphi中强制SQLite聚合字段为数字字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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