Recent

Author Topic: SQLQuery.RecordCount property in detail dataset (master/detail relation)?  (Read 6392 times)

tatamata

  • Hero Member
  • *****
  • Posts: 787
    • ZMSQL - SQL enhanced in-memory database
If a SQLQuery dataset is a slave dataset in master/detail relation, does RecordCount property of SQLQuery return number of all records queried or just those that are filtered by master/detail filtering?
« Last Edit: February 11, 2016, 09:30:18 am by tatamata »

balazsszekely

  • Guest
Re: SQLQuery.RecordCount property in detail dataset (master/detail relation)?
« Reply #1 on: February 11, 2016, 10:23:08 am »
The second one, but you can easily test this.

rvk

  • Hero Member
  • *****
  • Posts: 6169
Re: SQLQuery.RecordCount property in detail dataset (master/detail relation)?
« Reply #2 on: February 11, 2016, 10:27:59 am »
Also note that SQLQuery.RecordCount is not reliable as a total count. Most databases only serve the first few records in the dataset. The Recordcount reflects that count. Only with a SQLQuery.Last and SQLQuery.First you are sure to get ALL detail records.

If RecordCount is an important number for you, you might be better off just getting it with a separate SQL. Like SELECT COUNT(*) FROM TABLE WHERE MASTER_ID=:master_id.

http://lazarus-ccr.sourceforge.net/docs/fcl/db/tdataset.recordcount.html
Quote
RecordCount is the number of records in the dataset. This number is not necessarily equal to the number of records returned by a query. For optimization purposes, a TDataset descendent may choose not to fetch all records from the database when the dataset is opened. If this is the case, then the RecordCount will only reflect the number of records that have actually been fetched at the current time, and therefor the value will change as more records are fetched from the database.

Only when Last has been called (and the dataset has been forced to fetch all records returned by the database), will the value of RecordCount be equal to the number of records returned by the query.

tatamata

  • Hero Member
  • *****
  • Posts: 787
    • ZMSQL - SQL enhanced in-memory database
Re: SQLQuery.RecordCount property in detail dataset (master/detail relation)?
« Reply #3 on: February 11, 2016, 11:21:52 am »
Thanks guys for calrification.
I will use it just to test whether there are any corresponding records in slave dataset. It seems RecordCount property is suitable for that, since I don't need to know actual number of records, just whether it is >0.
Thanks.

 

TinyPortal © 2005-2018