开发者

Problem with cds.RecordCount

开发者 https://www.devze.com 2023-02-22 13:50 出处:网络
Is there a problem with cds.RecordCount ? I usua开发者_开发问答lly use it to determine if I have any records in a query.

Is there a problem with cds.RecordCount ?

I usua开发者_开发问答lly 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


If you're using TClientDataSet (as your 'cds' seems to imply) with PacketRecords set to -1 (default) or FetchOnDemand set to False 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's EOF property after opening - if all you want to know is whether the result set was empty or not.


The best solution would be to execute a SELECT COUNT(*) query.

If you need all records locally, you should set the FetchOnDemand property to False or you can call cds.Last right before cds.RecordCount.

There is also a cds.IsEmpty method if the purpose is to check whether the dataset contains records...

0

精彩评论

暂无评论...
验证码 换一张
取 消