UniDAC 的 RecordCount 属性注意事项

一直以来都是用UniDAC作为数据库查询组件,而一般的写法都是这样:

01UniQuery_sqlite.close;
02      UniQuery_sqlite.SQL.Clear;
03      UniQuery_sqlite.SQL.Add('SELECT * FROM TABLE');
04      try
05        UniQuery_sqlite.Open;
06      except
07        { TODO : 异常捕获 }
08      end;
09      //循环出所有记录
10      for i := 0 to UniQuery_sqlite.RecordCount - 1 do
11      begin
12         //....
13         UniQuery_sqlite.Next;
14      end;

今天突然发现一个问题,明明数据库里存在近百条记录,但只查出来了25条,仔细检查了代码,没有问题啊,于是又检查了UniDAC UniQuery的属性,发现有这样一个属性: FetchRows,而且默认值是25!肯定是这里的问题了,帮助里搜了一下这个属性,帮助解释如下:

2011-06-08_163522.jpg  大小: 154.69 K 浏览: 44 次
可见这个属性是为了性能考虑的,既然默认设置成25,肯定是最佳设置了,还是不改为何,于是寻求其他解决办法,网上又搜到了这样一个解释:

1If you set the QueryRecCount option to True, TUniTable executes SELECT COUNT() query automatically when you open the table, and assigns the correct value to the RecordCount property.

于是,我试着把QueryRecCount属性设置为true,问题解决了,showmessage了一下recordcount,不再是25了,已经是正确的行数了。为了找到权威的解释,又搜了一下帮助文档,解释如下:

2011-06-08_164040.jpg  大小: 174.86 K 浏览: 39 次
特别是这一句:Used for TCustomDADataSet to perform additional query to get the record count for this SELECT, so the RecordCount property reflects the actual number of records. 
原文地址:https://www.cnblogs.com/jxgxy/p/2516172.html