我在 Delphi 7 项目中使用 unidac 组件连接到 SQLite 数据库。连接和查询工作正常,除了计算字段。
我的查询是这样的:
select c.CardID,
c.FirstName,
c.SurName,
c.Street,
c.City,
c.PostCode,
c.Points,
(select count(1) from FullCard f where f.CardID = c.CardID and f.Paid = 1) as PaidCards,
(select count(1) from FullCard f where f.CardID = c.CardID and f.Paid = 0) as OpenCards,
(select count(1) from FullCard f where f.CardID = c.CardID) as FullCards
from Card c
当我在 SQLiteStudio 中运行它时,这个查询返回一个正确的结果集,但是当我在 delphi 中运行它时,计算的字段都是空的。
对于 Delphi 7,unidac 版本是 5.0.1。
我有一个 UniConnection 组件和一个 UniQuery 组件。连接属性似乎是正确的,因为我可以从数据库连接和查询。
UniQuery 组件具有用上述查询填充的 SQL 属性,并且所有字段都是持久的。
当我执行 UniQuery1.Open 时,DBGrid 会填满所有记录,但 PaidCards、OpenCards 和 FullCards 字段都是空的。
在 SQLiteStudio 中执行时,相同的查询确实会返回正确填充的这些字段,所以我猜查询本身没有问题。
我希望其他人也遇到过同样的问题,并且可以为我指出这个问题的解决方案。