Good day.
The point is this. I have 5000 entries in the table. To find out their number, I write:
IBTable1.Open; Edit1.Text:=inttostr(IBTable1.RecordCount); Instead of the expected 5000, I write 1 in food, because of what could it be?
Use the following methods:
IBTable1.Last; //сперва взять последнюю запись, а затем ваш код IBTable1.First; Edit1.Text:=inttostr(IBTable1.RecordCount); //другой вариант IBTable1.FetchAll; //он же в модификации procedure TfrmForm1.qAfterOpen(DataSet: TDataSet); begin if (DatSet is TIBCustomDataSet) then (DatSet as TIBCustomDataSet).FetchAll; end; //третий while not IBTable1.eof do //... If answering your question
what could that be?
It is necessary to understand the internal processes occurring when working with databases. The bottom line is that at the beginning of the variable RecordCount = 0, if the data in the table is, then the cursor becomes the record and naturally RecordCount becomes 1, with IBTable1.Last; moving the cursor on the table to the last record, respectively. RecordCount will be equal to the number of rows. FetchAll does a search of all records, which also leads to the correct (in your understanding) RecordCount.
although if you look at the code, it all comes down to
while not IBTable1.eof do begin inc(RecordCount); IBTable1.next; End; And this is done in order not to consume a lot of resources (memory and CPU), that is, the data is loaded into memory in batches, as needed.
Source: https://ru.stackoverflow.com/questions/43624/
All Articles