27 |
|
|
28 |
|
{$Mode Delphi} |
29 |
|
|
30 |
+ |
{$codepage UTF8} |
31 |
+ |
|
32 |
|
interface |
33 |
|
|
34 |
|
uses Classes, DB; |
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; |
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; |
291 |
|
if not (FState in [stInComment,stInCommentLine]) then |
292 |
|
begin |
293 |
|
AddToSQL(':'); |
294 |
< |
SetState(stInParam); |
294 |
> |
if not (FState in [stInSingleQuotes,stInDoubleQuotes]) then |
295 |
> |
SetState(stInParam); |
296 |
|
end; |
297 |
|
|
298 |
|
sqSemiColon: |
451 |
|
FState := PopState; |
452 |
|
stInDoubleQuotes, |
453 |
|
stInSingleQuotes: |
454 |
< |
raise Exception.Create(sNoEndToThis); |
454 |
> |
Begin |
455 |
> |
FLiteral := FLiteral + #$0A; |
456 |
> |
Exit; |
457 |
> |
End; |
458 |
|
end; |
459 |
|
AddToSQL(' '); |
460 |
|
Exit; |
583 |
|
begin |
584 |
|
if FIndex > length(Lines[I]) then |
585 |
|
if I+1 < Lines.Count then |
586 |
< |
FUnion := TSelectSQLParser.Create(Lines,I+1,1) |
586 |
> |
FUnion := TSelectSQLParser.Create(self,Lines,I+1,1) |
587 |
|
else |
588 |
|
raise Exception.Create(sIncomplete) |
589 |
|
else |
590 |
< |
FUnion := TSelectSQLParser.Create(Lines,I,FIndex); |
590 |
> |
FUnion := TSelectSQLParser.Create(self,Lines,I,FIndex); |
591 |
|
Exit |
592 |
|
end; |
593 |
|
end; |
669 |
|
constructor TSelectSQLParser.Create(aDataSet: TDataSet; SQLText: TStrings); |
670 |
|
begin |
671 |
|
FDataSet := aDataSet; |
672 |
< |
Create(SQLText,0,1) |
672 |
> |
Create(nil,SQLText,0,1) |
673 |
|
end; |
674 |
|
|
675 |
|
constructor TSelectSQLParser.Create(aDataSet: TDataSet; const SQLText: string); |
684 |
|
end |
685 |
|
end; |
686 |
|
|
687 |
< |
constructor TSelectSQLParser.Create(SQLText: TStrings; StartLine, |
688 |
< |
StartIndex: integer); |
687 |
> |
constructor TSelectSQLParser.Create(aOwner: TSelectSQLParser; |
688 |
> |
SQLText: TStrings; StartLine, StartIndex: integer); |
689 |
|
begin |
690 |
|
inherited Create; |
691 |
+ |
FOwner := aOwner; |
692 |
|
FParamList := TStringList.Create; |
693 |
|
FCTEs := TList.Create; |
694 |
|
FLastSymbol := sqNone; |
701 |
|
|
702 |
|
procedure TSelectSQLParser.Changed; |
703 |
|
begin |
704 |
+ |
if FOwner <> nil then |
705 |
+ |
FOwner.Changed |
706 |
+ |
else |
707 |
|
if assigned(FOnSQLChanging) and not FDestroying then |
708 |
|
OnSQLChanging(self) |
709 |
|
end; |
793 |
|
Inc(index) |
794 |
|
end; |
795 |
|
|
796 |
< |
if (Result = sqString) and not (FState in [stInComment,stInCommentLine])then |
796 |
> |
if (Result = sqString) and not (FState in [stInComment,stInCommentLine, stInSingleQuotes,stInDoubleQuotes])then |
797 |
|
Result := Check4ReservedWord(FString); |
798 |
|
|
799 |
|
if (index > Length(Line)) then |
800 |
< |
if Result = sqNone then |
800 |
> |
begin |
801 |
> |
if (Result = sqNone) then |
802 |
|
Result := sqEOL |
803 |
|
else |
804 |
|
if (FLastSymbol = sqNone) and (Result <> sqEOL) then |
805 |
|
FLastSymbol := sqEOL; |
806 |
+ |
end; |
807 |
|
|
808 |
|
end; |
809 |
|
|
874 |
|
|
875 |
|
procedure TSelectSQLParser.SetSelectClause(const Value: string); |
876 |
|
begin |
877 |
< |
if Union <> nil then Union.SelectClause := Value; |
878 |
< |
FSelectClause := Value; |
879 |
< |
Changed |
877 |
> |
if FSelectClause <> Value then |
878 |
> |
begin |
879 |
> |
FSelectClause := Value; |
880 |
> |
Changed |
881 |
> |
end; |
882 |
|
end; |
883 |
|
|
884 |
|
procedure TSelectSQLParser.SetFromClause(const Value: string); |
885 |
|
begin |
886 |
< |
if Union <> nil then |
887 |
< |
Union.FromClause := Value |
888 |
< |
else |
889 |
< |
FFromClause := Value; |
890 |
< |
Changed |
886 |
> |
if FFromClause <> Value then |
887 |
> |
begin |
888 |
> |
FFromClause := Value; |
889 |
> |
Changed |
890 |
> |
end; |
891 |
|
end; |
892 |
|
|
893 |
|
procedure TSelectSQLParser.SetGroupClause(const Value: string); |
894 |
|
begin |
895 |
< |
if Union <> nil then |
896 |
< |
Union.GroupClause := Value |
897 |
< |
else |
898 |
< |
FGroupClause := Value; |
899 |
< |
Changed |
895 |
> |
if FGroupClause <> Value then |
896 |
> |
begin |
897 |
> |
FGroupClause := Value; |
898 |
> |
Changed |
899 |
> |
end; |
900 |
|
end; |
901 |
|
|
902 |
|
procedure TSelectSQLParser.SetOrderByClause(const Value: string); |
904 |
|
if Union <> nil then |
905 |
|
Union.OrderByClause := Value |
906 |
|
else |
907 |
+ |
if FOrderByClause <> Value then |
908 |
+ |
begin |
909 |
|
FOrderByClause := Value; |
910 |
< |
Changed |
910 |
> |
Changed |
911 |
> |
end; |
912 |
|
end; |
913 |
|
|
914 |
|
procedure TSelectSQLParser.DropUnion; |