View Issue Details

IDProjectCategoryView StatusLast Update
0012238FPCDatabasepublic2014-02-18 11:02
Reporterpomalo Assigned ToJoost van der Sluis  
Status feedbackResolutionopen 
Summary0012238: TSQLQuery.RecordCount returns wrong value when dataset is filtered
Descriptionsee attached sample
TagsNo tags attached.
Fixed in Revision
Attached Files


2008-09-26 15:12 (4,993 bytes)

Joost van der Sluis

2008-11-26 18:00

manager   ~0023580

Can you tell me some more? I can not run your example, offcourse. Because I do not have your database.

It is much easier if you can tell me what the problem is. Does it have something to do with filtering?

Do you know that recordcount only shows the amount of records in memory? So that you have to do a .movelast befor a recordcount to get the complete recordset in memory?


2008-11-26 22:33

reporter   ~0023589

when a dataset is filtered, recordcount return the number of record before filtering not the recordcount from the filtered dataset

Joost van der Sluis

2008-11-27 11:58

manager   ~0023601

Ok, thanks. That will be difficult to fix, though.

And I'm not sure if Delphi/other database-components can do this.

Felipe Monteiro de Carvalho

2010-07-21 11:01

developer   ~0039527

Please post a full compilable example with the database

Marco van de Voort

2012-03-17 15:20

manager   ~0057773

If sb interested see it, it would be very interesting to know if Delphi implements this.

If so, recordcount on a filtered dataset should trigger the filtering I guess.

Luiz Americo

2012-06-09 05:48

developer   ~0060388

I just hit the same problem as the reporter and i found that Delphi has the same behavior of sqldb. So seems not a bug.


Mike Thompson

2013-09-19 07:38

reporter   ~0070182

I've raised another issue that *may* be related (or then again, may not). However, over there, there is at least a test case that reproduces RecordCount not changing after a filter is applied.


2013-09-26 09:39

developer   ~0070340

I did test in Delphi XE (with TClientDataSet and TADODataSet) and it seems to me, that RecordCount CHANGES after activating Filter!
Can somebody else confirm it, as above mentioned links says, that in Delphi (lesser version?) RecordCount does not change after filtering ?

Reinier Olislagers

2013-12-17 11:40

developer   ~0071933

Last edited: 2013-12-17 11:42

View 3 revisions

If you can read Dutch: at least in 2009 (don't know what Delphi versions were used) the recordcount changes on TClientDataset:

I'd say that changing recordcount based on filter seems like a reasonable thing to do, especially as more recent Delphi versions do the same anyway.
(The delphigroups link Luiz posted apparently uses BDE, not clientdataset/any vaguely recent dataset, so I think we can discount that one)

Delphi XE5 dataset.recordcount documentations specifies it returns -1 as a fallback and descendents are free to implement their own versions.


2014-02-18 10:34


testRecordCount.dpr (2,243 bytes)


2014-02-18 10:40

developer   ~0073127

Last edited: 2014-02-18 11:02

View 2 revisions

I did again tests with TClientDataset in D7 and DXE and RecordCount reflects Filter (and also OnFilterRecord if used)
See attached testRecordCount.dpr

My observations:
- Calculated fields are not supported in filter expression
- User defined OnFilterRecord is not called on each usage of RecordCount (so I guess, that there must be some mechanism of caching "FilteredRecordCount" which is calculated once when filter is activatd and later only updated)
- When records are added/updated, RecordCount changes as records fit or fit not in filter criteria
- RecNo reflects Filter and is No. of record after filter is applied

Issue History

Date Modified Username Field Change
2008-09-26 15:12 pomalo New Issue
2008-09-26 15:12 pomalo File Added:
2008-09-26 15:12 pomalo Widgetset => Win32
2008-09-26 15:18 Vincent Snijders Project Packages => FPC
2008-09-26 15:33 Jonas Maebe Status new => assigned
2008-09-26 15:33 Jonas Maebe Assigned To => Joost van der Sluis
2008-11-26 18:00 Joost van der Sluis Note Added: 0023580
2008-11-26 18:00 Joost van der Sluis Status assigned => feedback
2008-11-26 22:33 pomalo Note Added: 0023589
2008-11-27 11:58 Joost van der Sluis Note Added: 0023601
2008-11-27 11:59 Joost van der Sluis Status feedback => acknowledged
2008-12-01 14:52 Joost van der Sluis FPCOldBugId => 0
2008-12-01 14:52 Joost van der Sluis Severity minor => feature
2008-12-01 14:52 Joost van der Sluis Product Version 0.9.25 (SVN) =>
2010-07-21 11:01 Felipe Monteiro de Carvalho Note Added: 0039527
2010-07-21 11:01 Felipe Monteiro de Carvalho Status acknowledged => feedback
2011-05-09 18:10 Joost van der Sluis Summary TSQLQuery.RecordCount return wrong value => TSQLQuery.RecordCount returns wrong value when dataset is filtered
2012-03-17 15:20 Marco van de Voort Note Added: 0057773
2012-06-09 05:48 Luiz Americo Note Added: 0060388
2013-09-19 07:38 Mike Thompson Note Added: 0070182
2013-09-26 09:39 LacaK Note Added: 0070340
2013-12-17 11:40 Reinier Olislagers Note Added: 0071933
2013-12-17 11:41 Reinier Olislagers Note Edited: 0071933 View Revisions
2013-12-17 11:42 Reinier Olislagers Note Edited: 0071933 View Revisions
2014-02-18 10:34 LacaK File Added: testRecordCount.dpr
2014-02-18 10:40 LacaK Note Added: 0073127
2014-02-18 11:02 LacaK Note Edited: 0073127 View Revisions