使用Delphi 10.2,SQLite和Teecharts.我的SQLite数据库有两个字段,创建时间:
CREATE TABLE HistoryRuntime ('DayTime' DateTime, Device1 INTEGER DEFAULT (0));
Run Code Online (Sandbox Code Playgroud)
我使用带有以下SQL 的TFDQuery调用来访问表qryGrpahRuntime:
SELECT DayTime AS TheDate, Sum(Device1) As DeviceTotal
FROM HistoryRuntime
WHERE (DayTime >= "2017-06-01") and (DayTime <= "2017-06-26")
Group by Date(DayTime)
Run Code Online (Sandbox Code Playgroud)
使用Delphi IDE中的Field Editor,我可以添加两个持久字段,TheDate即a as TDateTimeField和DeviceTotala TLargeIntField.
我在程序中运行此查询以创建我在设计时创建的TeeChart.只要查询返回一些记录,所有这些都有效.但是,如果请求的日期没有记录,我会收到一条EDatabaseError消息:
qryGrpahRuntime:字段'DeviceTotal'的类型不匹配,期望:LargeInt actual:Widestring
我已经在网上搜索了大量关于如何在空查询中防止此错误的解决方案,但是我找不到任何好运.据我所知,当没有返回数据时,SQLite默认为宽字符串字段.我已经尝试在查询中使用CAST,它似乎没有任何区别.
如果我删除持久字段,查询将在空返回集上打开而没有问题.但是,为了在IDE中使用TeeChart编辑器,我看来需要持久字段.
有没有办法让我可以使用持久字段,或者我将不得不丢弃持久字段,然后在运行时添加TeeChart系列?