ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/runtime/IBSQLParser.pas
(Generate patch)

Comparing ibx/trunk/runtime/IBSQLParser.pas (file contents):
Revision 21 by tony, Thu Feb 26 10:33:34 2015 UTC vs.
Revision 139 by tony, Wed Jan 24 16:16:29 2018 UTC

# Line 27 | Line 27 | unit IBSQLParser;
27  
28   {$Mode Delphi}
29  
30 + {$codepage UTF8}
31 +
32   interface
33  
34   uses Classes, DB;
# Line 115 | Line 117 | type
117      FCTE: TCTEDef;
118      FNested: integer;
119      FDestroying: boolean;
120 +    FOwner: TSelectSQLParser;
121      procedure AddToSQL(const Word: string);
122      procedure CTEClear;
123      function GetCTE(Index: integer): PCTEDef;
# Line 134 | Line 137 | type
137      procedure SetGroupClause(const Value: string);
138      procedure SetFromClause(const Value: string);
139    protected
140 <    constructor Create(SQLText: TStrings; StartLine, StartIndex: integer); overload;
140 >    constructor Create(aOwner: TSelectSQLParser; SQLText: TStrings; StartLine, StartIndex: integer); overload;
141      procedure Changed;
142    public
143      constructor Create(aDataSet: TDataSet; SQLText: TStrings); overload;
# Line 175 | Line 178 | implementation
178   uses Sysutils, IBCustomDataSet;
179  
180   resourcestring
178  sNoEndToThis    = 'Unterminated string';
181    sBadBy          = 'Unexpected symbol "BY" in: %s';
182    sBadSymbol      = 'Unknown Symbol';
183    sIncomplete     = 'Incomplete Union';
# Line 288 | Line 290 | begin
290        if not (FState in [stInComment,stInCommentLine]) then
291        begin
292          AddToSQL(':');
293 <        SetState(stInParam);
293 >        if not (FState in [stInSingleQuotes,stInDoubleQuotes]) then
294 >          SetState(stInParam);
295        end;
296  
297      sqSemiColon:
# Line 447 | Line 450 | begin
450            FState := PopState;
451          stInDoubleQuotes,
452          stInSingleQuotes:
453 <          raise Exception.Create(sNoEndToThis);
453 >          Begin
454 >            FLiteral := FLiteral + #$0A;
455 >            Exit;
456 >          End;
457          end;
458          AddToSQL(' ');
459          Exit;
# Line 576 | Line 582 | begin
582          begin
583            if FIndex > length(Lines[I]) then
584              if I+1 < Lines.Count then
585 <              FUnion := TSelectSQLParser.Create(Lines,I+1,1)
585 >              FUnion := TSelectSQLParser.Create(self,Lines,I+1,1)
586              else
587                raise Exception.Create(sIncomplete)
588            else
589 <            FUnion := TSelectSQLParser.Create(Lines,I,FIndex);
589 >            FUnion := TSelectSQLParser.Create(self,Lines,I,FIndex);
590            Exit
591          end;
592        end;
# Line 662 | Line 668 | end;
668   constructor TSelectSQLParser.Create(aDataSet: TDataSet; SQLText: TStrings);
669   begin
670    FDataSet := aDataSet;
671 <  Create(SQLText,0,1)
671 >  Create(nil,SQLText,0,1)
672   end;
673  
674   constructor TSelectSQLParser.Create(aDataSet: TDataSet; const SQLText: string);
# Line 677 | Line 683 | begin
683    end
684   end;
685  
686 < constructor TSelectSQLParser.Create(SQLText: TStrings; StartLine,
687 <  StartIndex: integer);
686 > constructor TSelectSQLParser.Create(aOwner: TSelectSQLParser;
687 >  SQLText: TStrings; StartLine, StartIndex: integer);
688   begin
689    inherited Create;
690 +  FOwner := aOwner;
691    FParamList := TStringList.Create;
692    FCTEs := TList.Create;
693    FLastSymbol := sqNone;
# Line 693 | Line 700 | end;
700  
701   procedure TSelectSQLParser.Changed;
702   begin
703 +  if FOwner <> nil then
704 +    FOwner.Changed
705 +  else
706    if assigned(FOnSQLChanging) and not FDestroying then
707       OnSQLChanging(self)
708   end;
# Line 782 | Line 792 | begin
792      Inc(index)
793    end;
794  
795 <  if (Result = sqString)  and not (FState in [stInComment,stInCommentLine])then
795 >  if (Result = sqString)  and not (FState in [stInComment,stInCommentLine, stInSingleQuotes,stInDoubleQuotes])then
796      Result := Check4ReservedWord(FString);
797  
798    if (index > Length(Line)) then
799 <    if Result = sqNone then
799 >  begin
800 >    if  (Result = sqNone) then
801        Result := sqEOL
802      else
803      if (FLastSymbol = sqNone) and (Result <> sqEOL) then
804        FLastSymbol := sqEOL;
805 +  end;
806  
807   end;
808  
# Line 861 | Line 873 | end;
873  
874   procedure TSelectSQLParser.SetSelectClause(const Value: string);
875   begin
876 <  if Union <> nil then Union.SelectClause := Value;
877 <  FSelectClause := Value;
878 <  Changed
876 >  if FSelectClause <> Value then
877 >  begin
878 >    FSelectClause := Value;
879 >    Changed
880 >  end;
881   end;
882  
883   procedure TSelectSQLParser.SetFromClause(const Value: string);
884   begin
885 <  if Union <> nil then
886 <    Union.FromClause := Value
887 <  else
888 <  FFromClause := Value;
889 <  Changed
885 >  if FFromClause <> Value then
886 >  begin
887 >    FFromClause := Value;
888 >    Changed
889 >  end;
890   end;
891  
892   procedure TSelectSQLParser.SetGroupClause(const Value: string);
893   begin
894 <  if Union <> nil then
895 <    Union.GroupClause := Value
896 <  else
897 <  FGroupClause := Value;
898 <  Changed
894 >  if FGroupClause <> Value then
895 >  begin
896 >    FGroupClause := Value;
897 >    Changed
898 >  end;
899   end;
900  
901   procedure TSelectSQLParser.SetOrderByClause(const Value: string);
# Line 889 | Line 903 | begin
903    if Union <> nil then
904      Union.OrderByClause := Value
905    else
906 +  if FOrderByClause <> Value then
907 +  begin
908      FOrderByClause := Value;
909 <  Changed
909 >    Changed
910 >  end;
911   end;
912  
913   procedure TSelectSQLParser.DropUnion;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines