【问题标题】:Calculated fields are empty when using unidac in delphi 7在delphi 7中使用unidac时计算字段为空
【发布时间】:2015-04-28 20:25:47
【问题描述】:

我在 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 中执行时,相同的查询确实会返回正确填充的这些字段,所以我猜查询本身没有问题。

我希望其他人也遇到过同样的问题,并且可以为我指出解决此问题的方法。

【问题讨论】:

  • 我已经安装了 AnyDAC 的试用版,并且使用此组件不会出现问题。所有字段都正确显示。因此,要么我找到 uniDac 的修复程序,要么我需要获得一些资金来升级到 anyDac。

标签: delphi delphi-7 unidac


【解决方案1】:

此错误的解决方法是不使用持久字段。 当我不创建持久字段时,所有字段都被正确填充并且一切正常。 唯一的缺点是我必须在我的代码中使用 query1.FieldByName('FirstName').asString 而不是 query1FirstName.asString。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-30
    • 1970-01-01
    • 2013-07-24
    • 2018-06-20
    相关资源
    最近更新 更多