39 |
|
|
40 |
|
BlobLineLength = 40; |
41 |
|
|
42 |
+ |
DefaultTerminator = ';'; |
43 |
+ |
|
44 |
|
{Non-character symbols} |
45 |
|
sqNone = #0; |
46 |
|
sqEnd = #1; |
293 |
|
FAutoDDL: boolean; |
294 |
|
procedure DoCommit; |
295 |
|
procedure DoReconnect; |
294 |
– |
procedure ExecSQL(stmt: string); |
296 |
|
function GetOnProgressEvent: TOnProgressEvent; |
297 |
|
function GetTransaction: TIBTransaction; |
298 |
|
procedure SetDatabase(AValue: TIBDatabase); |
304 |
|
protected |
305 |
|
FSymbolStream: TSymbolStream; |
306 |
|
procedure Add2Log(const Msg: string; IsError: boolean=true); virtual; |
307 |
+ |
procedure ExecSQL(stmt: string); |
308 |
|
procedure EchoNextLine(Sender: TObject; Line: string); |
309 |
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override; |
310 |
|
function ProcessStatement(stmt: string): boolean; virtual; |
561 |
|
procedure TCustomIBXScript.DoCommit; |
562 |
|
begin |
563 |
|
with GetTransaction do |
562 |
– |
begin |
564 |
|
if InTransaction then Commit; |
564 |
– |
Active := true; |
565 |
– |
end; |
565 |
|
end; |
566 |
|
|
567 |
|
procedure TCustomIBXScript.DoReconnect; |
569 |
– |
var LoginPrompt: boolean; |
568 |
|
begin |
569 |
|
with GetTransaction do |
570 |
|
if InTransaction then Commit; |
571 |
< |
LoginPrompt := Database.LoginPrompt; |
574 |
< |
Database.LoginPrompt := false; |
575 |
< |
Database.Connected := false; |
576 |
< |
Database.Connected := true; |
577 |
< |
Database.LoginPrompt := LoginPrompt; |
578 |
< |
GetTransaction.Active := true; |
571 |
> |
Database.Reconnect; |
572 |
|
end; |
573 |
|
|
574 |
|
procedure TCustomIBXScript.ExecSQL(stmt: string); |
725 |
|
begin |
726 |
|
with GetTransaction do |
727 |
|
if InTransaction then Rollback; |
728 |
+ |
FSymbolStream.Terminator := DefaultTerminator; |
729 |
|
if assigned(OnErrorLog) then |
730 |
|
begin |
731 |
|
Add2Log(Format(sStatementError,[FSymbolStream.GetErrorPrefix, |
741 |
|
|
742 |
|
function TCustomIBXScript.ProcessStatement(stmt: string): boolean; |
743 |
|
var command: string; |
750 |
– |
ucStmt: string; |
744 |
|
|
745 |
|
function Toggle(aValue: string): boolean; |
746 |
|
begin |
761 |
|
try |
762 |
|
RegexObj.ModifierG := false; {turn off greedy matches} |
763 |
|
RegexObj.Expression := ' +USER +''(.+)'''; |
764 |
< |
if RegexObj.Exec(ucStmt) then |
764 |
> |
if RegexObj.Exec(stmt) then |
765 |
|
FDatabase.Params.Values['user_name'] := RegexObj.Match[1]; |
766 |
|
|
767 |
|
RegexObj.Expression := ' +PASSWORD +''(.+)'''; |
768 |
< |
if RegexObj.Exec(ucStmt) then |
768 |
> |
if RegexObj.Exec(stmt) then |
769 |
|
FDatabase.Params.Values['password'] := |
770 |
|
system.copy(stmt,RegexObj.MatchPos[1],RegexObj.MatchLen[1]); |
771 |
|
finally |
780 |
|
RegexObj := TRegExpr.Create; |
781 |
|
try |
782 |
|
RegexObj.ModifierG := false; {turn off greedy matches} |
783 |
+ |
RegexObj.ModifierI := true; {case insensitive} |
784 |
|
RegexObj.Expression := '^ *CONNECT +''(.*)'''; |
785 |
< |
if RegexObj.Exec(ucStmt) then |
785 |
> |
if RegexObj.Exec(stmt) then |
786 |
|
begin |
787 |
|
FDatabase.DatabaseName := system.copy(stmt,RegexObj.MatchPos[1],RegexObj.MatchLen[1]); |
788 |
|
end; |
789 |
|
|
790 |
|
RegexObj.Expression := ' +ROLE +''(.+)'''; |
791 |
< |
if RegexObj.Exec(ucStmt) then |
791 |
> |
if RegexObj.Exec(stmt) then |
792 |
|
FDatabase.Params.Values['sql_role_name'] := RegexObj.Match[1] |
793 |
|
else |
794 |
|
with FDatabase.Params do |
796 |
|
Delete(IndexOfName('sql_role_name')); |
797 |
|
|
798 |
|
RegexObj.Expression := ' +CACHE +([0-9]+)'; |
799 |
< |
if RegexObj.Exec(ucStmt) then |
799 |
> |
if RegexObj.Exec(stmt) then |
800 |
|
FDatabase.Params.Values['cache_manager'] := RegexObj.Match[1] |
801 |
|
else |
802 |
|
with FDatabase.Params do |
813 |
|
RegexObj := TRegExpr.Create; |
814 |
|
try |
815 |
|
RegexObj.ModifierG := false; {turn off greedy matches} |
816 |
+ |
RegexObj.ModifierI := true; {case insensitive} |
817 |
|
RegexObj.Expression := '^ *CREATE +(DATABASE|SCHEMA) +(''.*'') +USER +''(.+)'''; |
818 |
< |
if not RegexObj.Exec(ucStmt) and (FDatabase.Params.IndexOfName('user_name') <> -1) then |
818 |
> |
if not RegexObj.Exec(stmt) and (FDatabase.Params.IndexOfName('user_name') <> -1) then |
819 |
|
begin |
820 |
|
RegexObj.Expression := '^ *CREATE +(DATABASE|SCHEMA) +(''.*'')'; |
821 |
< |
if RegexObj.Exec(ucStmt) then |
821 |
> |
if RegexObj.Exec(stmt) then |
822 |
|
begin |
823 |
|
system.Insert(' USER ''' + FDatabase.Params.Values['user_name'] +'''',stmt, |
824 |
|
RegexObj.MatchPos[2] + RegexObj.MatchLen[2]); |
830 |
– |
ucStmt := AnsiUpperCase(stmt); |
825 |
|
end; |
826 |
|
end; |
827 |
|
|
828 |
|
RegexObj.Expression := '^ *CREATE +(DATABASE|SCHEMA) +''.*'' +USER +''.+'' PASSWORD +''(.+)'''; |
829 |
< |
if not RegexObj.Exec(ucStmt) and (FDatabase.Params.IndexOfName('password') <> -1) then |
829 |
> |
if not RegexObj.Exec(stmt) and (FDatabase.Params.IndexOfName('password') <> -1) then |
830 |
|
begin |
831 |
|
RegexObj.Expression := '^ *CREATE +(DATABASE|SCHEMA) +''.*'' +(USER +''.+'')'; |
832 |
< |
if RegexObj.Exec(ucStmt) then |
832 |
> |
if RegexObj.Exec(stmt) then |
833 |
|
begin |
834 |
|
system.Insert(' PASSWORD ''' + FDatabase.Params.Values['password'] +'''',stmt, |
835 |
|
RegexObj.MatchPos[2] + RegexObj.MatchLen[2]); |
842 |
– |
ucStmt := AnsiUpperCase(stmt); |
836 |
|
end; |
837 |
|
end; |
838 |
|
finally |
850 |
|
LoginPrompt: boolean; |
851 |
|
begin |
852 |
|
Result := false; |
860 |
– |
ucStmt := AnsiUpperCase(stmt); |
853 |
|
Terminator := FSymbolStream.Terminator; |
854 |
|
RegexObj := TRegExpr.Create; |
855 |
|
try |
856 |
|
{process create database} |
857 |
+ |
RegexObj.ModifierI := true; {case insensitive} |
858 |
|
RegexObj.Expression := '^ *CREATE +(DATABASE|SCHEMA) +''(.*)''(.*)(\' + Terminator + '|)'; |
859 |
< |
if RegexObj.Exec(ucStmt) then |
859 |
> |
if RegexObj.Exec(stmt) then |
860 |
|
begin |
861 |
|
if IgnoreCreateDatabase then |
862 |
|
begin |
867 |
|
if assigned(FOnCreateDatabase) then |
868 |
|
OnCreateDatabase(self,FileName); |
869 |
|
stmt := 'CREATE DATABASE ''' + FileName + '''' + system.copy(stmt,RegexObj.MatchPos[3], RegexObj.MatchLen[3]); |
877 |
– |
ucStmt := AnsiUpperCase(stmt); |
870 |
|
UpdateUserPassword; |
871 |
|
FDatabase.Connected := false; |
872 |
|
FDatabase.CreateDatabase(stmt); |
873 |
|
FDatabase.Connected := false; |
874 |
|
ExtractUserInfo; |
875 |
< |
DoReconnect; |
875 |
> |
FDatabase.Connected := true; |
876 |
|
Result := true; |
877 |
|
Exit; |
878 |
|
end; |
879 |
|
|
880 |
|
{process connect statement} |
881 |
|
RegexObj.Expression := '^ *CONNECT +.*(\' + Terminator + '|)'; |
882 |
< |
if RegexObj.Exec(ucStmt) then |
882 |
> |
if RegexObj.Exec(stmt) then |
883 |
|
begin |
884 |
|
ExtractConnectInfo; |
885 |
< |
DoReconnect; |
885 |
> |
FDatabase.Connected := false; |
886 |
> |
FDatabase.Connected := true; |
887 |
|
Result := true; |
888 |
|
Exit; |
889 |
|
end; |
890 |
|
|
891 |
|
{Process Drop Database} |
892 |
|
RegexObj.Expression := '^ *DROP +DATABASE *(\' + Terminator + '|)'; |
893 |
< |
if RegexObj.Exec(ucStmt) then |
893 |
> |
if RegexObj.Exec(stmt) then |
894 |
|
begin |
895 |
|
FDatabase.DropDatabase; |
896 |
|
Result := true; |
899 |
|
|
900 |
|
{process commit statement} |
901 |
|
RegexObj.Expression := '^ *COMMIT *(\' + Terminator + '|)'; |
902 |
< |
if RegexObj.Exec(ucStmt) then |
902 |
> |
if RegexObj.Exec(stmt) then |
903 |
|
begin |
904 |
|
DoCommit; |
905 |
|
Result := true; |
908 |
|
|
909 |
|
{process Reconnect statement} |
910 |
|
RegexObj.Expression := '^ *RECONNECT *(\' + Terminator + '|)'; |
911 |
< |
if RegexObj.Exec(ucStmt) then |
911 |
> |
if RegexObj.Exec(stmt) then |
912 |
|
begin |
913 |
|
DoReconnect; |
914 |
|
Result := true; |
918 |
|
|
919 |
|
{Process Set Term} |
920 |
|
RegexObj.Expression := '^ *SET +TERM +(.) *(\' + Terminator + '|)'; |
921 |
< |
if RegexObj.Exec(ucStmt) then |
921 |
> |
if RegexObj.Exec(stmt) then |
922 |
|
begin |
923 |
|
FSymbolStream.Terminator := RegexObj.Match[1][1]; |
924 |
|
Result := true; |
927 |
|
|
928 |
|
{process Set SQL Dialect} |
929 |
|
RegexObj.Expression := '^ *SET +SQL +DIALECT +([0-9]) *(\' + Terminator + '|)'; |
930 |
< |
if RegexObj.Exec(ucStmt) then |
930 |
> |
if RegexObj.Exec(stmt) then |
931 |
|
begin |
932 |
|
n := StrToInt(RegexObj.Match[1]); |
933 |
|
if Database.SQLDialect <> n then |
942 |
|
|
943 |
|
{Process Remaining Set statements} |
944 |
|
RegexObj.Expression := '^ *SET +([A-Z]+)( +[A-Z0-9]+|) *(\' + Terminator + '|)'; |
945 |
< |
if RegexObj.Exec(ucStmt) then |
945 |
> |
if RegexObj.Exec(stmt) then |
946 |
|
begin |
947 |
|
command := AnsiUpperCase(RegexObj.Match[1]); |
948 |
|
param := trim(RegexObj.Match[2]); |
1899 |
|
#0..#8,#10..#31,' ': |
1900 |
|
Result := ' '; |
1901 |
|
|
1902 |
< |
#9,';','"','''','/', |
1902 |
> |
#9,';','"','''','/','-', |
1903 |
|
'*','=','>','<',',': |
1904 |
|
Result := C; |
1905 |
|
else |
1926 |
|
constructor TSymbolStream.Create; |
1927 |
|
begin |
1928 |
|
inherited; |
1929 |
< |
FTerminator := ';'; |
1929 |
> |
FTerminator := DefaultTerminator; |
1930 |
|
NextStatement; |
1931 |
|
end; |
1932 |
|
|
2016 |
|
Result := sqCommentLine; |
2017 |
|
FIndex := 0; |
2018 |
|
FNextSymbol := sqNone |
2019 |
+ |
end; |
2020 |
+ |
|
2021 |
+ |
'-': |
2022 |
+ |
if FXMLMode > 0 then |
2023 |
+ |
break |
2024 |
+ |
else |
2025 |
+ |
if FNextSymbol = '-' then |
2026 |
+ |
begin |
2027 |
+ |
FString := '--' + system.copy(FLine,FIndex,length(FLine)- FIndex + 1) ; |
2028 |
+ |
Result := sqCommentLine; |
2029 |
+ |
FIndex := 0; |
2030 |
+ |
FNextSymbol := sqNone |
2031 |
|
end; |
2032 |
|
|
2033 |
|
'<': |