From df2afa4a3a76d30635c7ab435259d1659ffea6d0 Mon Sep 17 00:00:00 2001 From: alexs75 Date: Fri, 25 Mar 2016 08:19:10 +0000 Subject: [PATCH] RxFPC:TZeosDataSetSortEngine fix sorting on collimns with space in field's name git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4595 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/rx/trunk/exsortzeos.pas | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/components/rx/trunk/exsortzeos.pas b/components/rx/trunk/exsortzeos.pas index 1d29dad8f..9f9f31235 100644 --- a/components/rx/trunk/exsortzeos.pas +++ b/components/rx/trunk/exsortzeos.pas @@ -52,17 +52,21 @@ type implementation uses ZDbcIntfs, ZVariant; +function FixFieldName(S:string):string;inline; +begin + if Pos(' ', S)>0 then + S:='"'+S+'"'; + Result:=S; +end; + procedure TZeosDataSetSortEngine.Sort(FieldName: string; ADataSet: TDataSet; Asc: boolean; SortOptions: TRxSortEngineOptions); begin if not Assigned(ADataSet) then exit; - if Pos(' ', FieldName)>0 then - FieldName:='"'+FieldName+'"'; - if ADataSet is TZAbstractRODataset then begin - TZAbstractRODataset(ADataSet).SortedFields:=FieldName; + TZAbstractRODataset(ADataSet).SortedFields:=FixFieldName(FieldName); if Asc then TZAbstractRODataset(ADataSet).SortType:=stAscending else @@ -84,7 +88,7 @@ begin while C>0 do begin if S<>'' then S:=S+';'; - S:=S + Copy(ListField, 1, C-1); + S:=S + FixFieldName(Copy(ListField, 1, C-1)); Delete(ListField, 1, C); if (i<=High(Asc)) and (not Asc[i]) then @@ -96,7 +100,7 @@ begin if ListField<>'' then begin if S<>'' then S:=S+';'; - S:=S + ListField; + S:=S + FixFieldName(ListField); if (i<=High(Asc)) and (not Asc[i]) then S:=S + ' DESC'; end;