You are not logged in.
Pages: 1
Hello,
I am new to mORMot and have built some code to learn it. But I cannot figure out how to retrieve data sorted when using CreateAndFillPrepare (from a table by using an TSQLRecord).
How can I change the code below to retrieve my data sorted?
In the code below TSQLPatientsis just an TSQLRecord with some properties.
patients := TSQLPatients.CreateAndFillPrepare(DatabaseClient, '');
cbListPatients.Clear();
try
while patients.FillOne do
begin
Inc(iTemp);
cbListPatients.AddItem(patients.name, Pointer(patients.id));
cbListPatients.Checked[iTemp]:= (patients.active='y');
end
finally
FreeAndNil(patients);
end;
I am curious to read the answer...!
Regards,
Maurijn
Offline
You have two possibilities, sorting either on the server side, either on the client side:
- You can specify an ORDER BY clause in the aSQLWhere parameter of the method, which will use the DB indexes (if any) on the server side;
- You can sort the internal TSQLTable instance containing the data on the client side, calling e.g. patients.FillTable.SortFields() method.
If there is a matching index in the DB for the field, I'd rather use ORDER BY on the server side.
But otherwise, client-side process is a good idea, since calling FillTable.SortFields() is very fast (see TUTF8QuickSort.QuickSort implementation) and will leave server CPU and memory resources free to process other requests.
Hope it helps.
Offline
It surely helped! Thanks a lot!
Regards,
Maurijn
Offline
Pages: 1