Browse Source

fcl-db: parse order by upper

mattias 3 days ago
parent
commit
b938b43a49
2 changed files with 24 additions and 0 deletions
  1. 20 0
      packages/fcl-db/src/sql/fpsqlparser.pas
  2. 4 0
      packages/fcl-db/src/sql/fpsqltree.pp

+ 20 - 0
packages/fcl-db/src/sql/fpsqlparser.pas

@@ -582,6 +582,7 @@ Var
   O : TSQLOrderByElement;
   F : TSQLElement;
   BuildToken : string;
+  HasBracket, HasUpper: Boolean;
 
 begin
   // On entry we're on the ORDER token.
@@ -592,6 +593,17 @@ begin
   Expect(tsqlBy);
   Repeat
     GetNextToken;
+    HasUpper:=false;
+    HasBracket:=false;
+    if CurrentToken=tsqlUPPER then
+      begin
+      HasUpper:=true;
+      GetNextToken;
+      Expect(tsqlBraceOpen);
+      GetNextToken;
+      HasBracket:=true;
+      end;
+
     // Deal with table.column notation:
     Case CurrentToken of
       tsqlIdentifier :
@@ -614,10 +626,18 @@ begin
     else
       UnexpectedToken([tsqlIdentifier,tsqlIntegerNumber]);
     end;
+
+    if HasBracket then
+      begin
+      GetNextToken;
+      Expect(tsqlBraceClose);
+      end;
+
     try
       O:=TSQLOrderByElement(CreateElement(TSQLOrderByElement,APArent));
       AList.Add(O);
       O.Field:=F;
+      O.Upper:=HasUpper;
       F:=Nil;
     except
       FreeAndNil(F);

+ 4 - 0
packages/fcl-db/src/sql/fpsqltree.pp

@@ -766,12 +766,14 @@ Type
     FCollation: TSQLIdentifierName;
     FField: TSQLElement;
     FOrderBy: TSQLOrderDirection;
+    FUpper: boolean;
   Public
     Destructor Destroy; override;
     Function GetAsSQL(Options : TSQLFormatOptions; AIndent : Integer = 0): TSQLStringType; override;
     Property Field : TSQLElement Read FField Write FField;
     Property Collation : TSQLIdentifierName Read FCollation Write FCollation;
     Property OrderBy : TSQLOrderDirection Read FOrderBy write FOrderBy;
+    Property Upper: boolean Read FUpper Write FUpper;
   end;
 
   { TSQLSelectLimit }
@@ -3598,6 +3600,8 @@ Const
 begin
   If Assigned(FField) then
     Result:=FField.GetAsSQL(Options, AIndent);
+  if Upper then
+    Result:='UPPER('+Result+')';
   If (OrderBy=obDescending) or (sfoForceAscending in Options) then
     Result:=Result+' '+SQLKeyWord(Opcodes[OrderBy],Options);
   If (Collation<>Nil) then