简体   繁体   English

在delphi 7中使用unidac时,计算字段为空

[英]Calculated fields are empty when using unidac in delphi 7

I am using unidac components in a Delphi 7 project to connect to a SQLite database. 我在Delphi 7项目中使用unidac组件连接到SQLite数据库。 Connecting and quering works fine, except for calculated fields. 连接和查询工作正常,但计算字段除外。

My query is this : 我的查询是这样的:

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

This query returns a correct resultset when I run it in SQLiteStudio, but when I run it in delphi the Calculated fields are all empty. 当我在SQLiteStudio中运行该查询时,它返回正确的结果集,但是当我在delphi中运行它时,“计算所得”字段均为空。

The unidac version is 5.0.1 for Delphi 7. 对于Delphi 7,unidac版本为5.0.1。
I have a UniConnection component and a UniQuery component. 我有一个UniConnection组件和一个UniQuery组件。 The connection properties seem correct since I can connect and query from the database. 连接属性似乎正确,因为我可以连接数据库并从数据库中查询。
The UniQuery component has the SQL property filled with the above query, and all fields are made persistent. UniQuery组件具有使用上述查询填充的SQL属性,并且所有字段均保持不变。
When I do UniQuery1.Open a DBGrid fills up with all records, but the fields PaidCards, OpenCards and FullCards are all empty. 当我执行UniQuery1.Open时,DBGrid会填充所有记录,但是PaidCards,OpenCards和FullCards字段均为空。
The same query does returns these fields properly filled when executing it in SQLiteStudio so I guess there is nothing wrong with the query itself. 在SQLiteStudio中执行该查询时,该查询的确会正确填充这些字段,因此我认为查询本身没有错。

I am hoping someone else has encountered the same problem and can point me to a solution for this problem. 我希望其他人也遇到同样的问题,并可以为我提供解决该问题的方法。

The workaround for this bug is not using persistent fields. 此错误的解决方法是不使用持久字段。 When I don't create persistent fields than all fields are filled properly and everything works perfect. 当我不创建持久字段时,所有字段都会被正确填充,并且一切正常。 Only downfall is I have to use query1.FieldByName('FirstName').asString in stead of query1FirstName.asString in my code. 唯一的不足是我必须在代码中使用query1.FieldByName('FirstName')。asString代替query1FirstName.asString。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM