I was looking for a skip and take selection in the TFDQuery. The properties I found are .FetchOptions.RecsSkip and .FetchOptions.RecsMax. I use Tokyo 10.2.3 and database Firebird 3
I make the query at runtime and I want to get the start record at 5 and get the 8 next records.
I to something like:
Result does not skip the fist 5 records
var
qryTest: TFDQuery;
begin
qryTest:= TFDQuery.Create(self);
qryTest.Connection := self.FDConnection;
qryTest.sql.Text:= ' select * from salutationdescriptions order by ID';
qryTest.Disconnect();
qryTest.FetchOptions.RecsSkip:= 5;
qryTest.FetchOptions.RecsMax:= 8;
qryTest.Open();
But this give as result the first 8 records. The 5 first records are not skipped.
Ok, I to the same but now I set TFQQuery at designtime (component on the form) and add the selection 'select * from salutationdescriptions order by ID' in the component.
Run the code:
This skip the fist 5 records
qryItem.Close;
qryItem.Disconnect();
qryItem.FetchOptions.RecsSkip:= 5;
qryItem.FetchOptions.RecsMax:= 8;
qryItem.Open();
The result I get is ok. This skip the first 5 records. When I add the qryItem.sql.text then it doesn't skip the first 5 records
This does not skip the fist 5 records
qryItem.Close;
qryItem.sql.Text:= ' select * from salutationdescriptions order by ID';
qryItem.Disconnect();
qryItem.FetchOptions.RecsSkip:= 5;
qryItem.FetchOptions.RecsMax:= 8;
qryItem.Open();
That doesn't skip the 5 first records.
Must I set something in the properties?
I want to use the RecsSkip and RecsMax at runtime. Any suggestions?
FOUND the problem
in the SQL.Text I must begin with 'Select ... no space between ' and select
Disconnect
first. Which doesn't seem to be your case though, or is that query object prepared when you change the fetch options in your real code? Oh, and in any case, tuples will be fetched in unpredictable order so long you won't sort them on the DBMS side (by usingORDER BY
clause). – Fayola