Recent

Author Topic: [SOLVED] Too many records in a TZquery. Problem with Record Count  (Read 2129 times)

donnie

  • Jr. Member
  • **
  • Posts: 72
Hi there,
I've got a TZQuery connected with a TDatasource which is connected to my TRXDBGrid(same as TDBGrid with many functions). My query brings from my database about 300.000 records and as they are enough when I open my query to bring the records to my DBGrid I have changed the FetchRow to 1000 in order not to wait too long. I have also added a button to my form with the title Total Count which brings me the number of Records in my DBgrid. In that button (SBRecordsCount) when I press it, the caption changes and shows the record count.
Code: Pascal  [Select][+][-]
  1. SBRecordsCount.Caption:= 'Total: ' + inttostr(MyQuery.RecordCount);
  2.  
With the above code the recordcount is 1000 which is the number of the fetched rows something which I expected. So I changed it to
Code: Pascal  [Select][+][-]
  1.    MyQuery.last;
  2.    MyQuery.first;
  3.    SBRecordsCount.Caption:= 'Total: ' + inttostr(MyQuery.RecordCount);
  4.  
The problem is that now that is too slow and sometimes it takes too much time to bring the number (more that 5 minutes) which is not logical. Is there any other way to load the record count somewhere else (memory) in order to take that number quicker?
Thank you, in advance.
« Last Edit: May 25, 2016, 10:43:12 am by dony »

balazsszekely

  • Guest
Re: Too many records in a TZquery. Problem with Record Count
« Reply #1 on: May 25, 2016, 10:16:34 am »
Quote
@dony
The problem is that now that is too slow and sometimes it takes too much time to bring the number
Add another TSQLQuery, with the following sql:
Code: Pascal  [Select][+][-]
  1. select count(id) as recordcount from TableName
Where id is the primary key. Any other field will do it, but preferably choose an indexed one.
Code: Pascal  [Select][+][-]
  1. SQLQuery1.Open;
  2. SBRecordsCount.Caption:= 'Total: ' + SQLQuery1.FieldByName('recordcount').AsString;
  3. SQLQuery1.Close
« Last Edit: May 25, 2016, 10:22:24 am by GetMem »

donnie

  • Jr. Member
  • **
  • Posts: 72
Re: Too many records in a TZquery. Problem with Record Count
« Reply #2 on: May 25, 2016, 10:40:58 am »
Excellent less than one second.
Thank you very much.

 

TinyPortal © 2005-2018