#2 Re: mORMot 1 » Is there any way to simulate an ORDER BY for a TDynArray? » 2017-05-31 17:35:08

I resolved passing this function to the Sort:

function OrderBy(const A, B): Integer;
   function SortDateTime(const A, B): Integer;
   begin
      if TDateTime(A) < TDateTime(B) then
         Result := -1
      else
         if TDateTime(A) > TDateTime(B) then
            Result := 1
         else
            Result := 0;
   end;
begin
   Result := SortDynArrayInteger(TRec(A).USER_ID, TRec(B).CUSER_ID);
   if Result = 0 then
   begin
      Result := SortDynArrayInteger(TRec(A).PRIORITY_ID, TRec(B).PRIORITY_ID);
      if Result = 0 then
         Result := SortDateTime(TRec(A).DATEINI, TRec(B).DATEINI);
   end;
end;

#3 Re: mORMot 1 » Is there any way to simulate an ORDER BY for a TDynArray? » 2017-05-30 21:08:18

For more than one column/field?
Like this: "ORDER BY NAME, PRIORITY, DATEINI ASC"

I was able to do only with one column

#4 mORMot 1 » Is there any way to simulate an ORDER BY for a TDynArray? » 2017-05-30 19:11:25

wendel
Replies: 6

I bring some records from the database with a specific sort order and I put it in a record type vector. I need to add more items to this vector by keeping the initial ordering, however the records that are added are left at the end of the vector.

I want to know if there is any way to reorder this vector in the same way as it does in SQL ORDER BY.

(Sorry for my English)

Board footer

Powered by FluxBB