cds.RecordCount 问题
cds.RecordCount 有问题吗?
我通常用它来确定查询中是否有任何记录。
但他在与一所大学交谈时表示,这样做会降低成绩!
我做了一些测试,没有发现什么重大问题。
那么 RecordCount 是否存在性能损失或任何其他问题?!
如果是这样,检查查询中是否有某些记录的最佳方法是什么?
谢谢
Is there a problem with cds.RecordCount ?
I usually use it to determine if I have any records in a query.
But talking with a college he told that there is a performance penalty to that!
I have made some test and nothing major came up.
So is there a performance penalty or any other problem with RecordCount?!
If so, what is the best way to check if there are some records in a query?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 TClientDataSet(正如您的“cds”似乎暗示的那样),并将
PacketRecords
设置为-1
(默认)或将FetchOnDemand
设置为False
没有区别,因为客户端数据集会立即接收所有数据并将其加载到内存中。对于其他数据集来说,差异是显而易见的,这些数据集在您前进光标时按需获取数据,使用
RecordCount
将首先获取所有数据。在这种情况下,如果您只想知道结果集是否为空,最好在打开后使用数据集的EOF
属性。If you're using TClientDataSet (as your 'cds' seems to imply) with
PacketRecords
set to-1
(default) orFetchOnDemand
set toFalse
there is no difference since the client dataset receives and loads all data into memory at once.The difference would be noticable with other datasets which fetch data on demand as you advance the cursor, using
RecordCount
would fetch all data first. In such cases it's better to use the dataset'sEOF
property after opening - if all you want to know is whether the result set was empty or not.最好的解决方案是执行
SELECT COUNT(*)
查询。如果您需要本地所有记录,则应将
FetchOnDemand
属性设置为False
,或者您可以在cds 之前调用
cds.Last
。记录计数。如果目的是检查数据集是否包含记录,还有一个 cds.IsEmpty 方法...
The best solution would be to execute a
SELECT COUNT(*)
query.If you need all records locally, you should set the
FetchOnDemand
property toFalse
or you can callcds.Last
right beforecds.RecordCount
.There is also a
cds.IsEmpty
method if the purpose is to check whether the dataset contains records...