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

Comparing ibx/trunk/runtime/nongui/ibxscript.pas (file contents):
Revision 227 by tony, Mon Apr 9 10:31:10 2018 UTC vs.
Revision 229 by tony, Tue Apr 10 13:32:36 2018 UTC

# Line 293 | Line 293 | type
293      FAutoDDL: boolean;
294      procedure DoCommit;
295      procedure DoReconnect;
296    procedure ExecSQL(stmt: string);
296      function GetOnProgressEvent: TOnProgressEvent;
297      function GetTransaction: TIBTransaction;
298      procedure SetDatabase(AValue: TIBDatabase);
# Line 305 | Line 304 | type
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;
# Line 561 | Line 561 | end;
561   procedure TCustomIBXScript.DoCommit;
562   begin
563    with GetTransaction do
564  begin
564      if InTransaction then Commit;
566    Active := true;
567  end;
565   end;
566  
567   procedure TCustomIBXScript.DoReconnect;
571 var LoginPrompt: boolean;
568   begin
569    with GetTransaction do
570      if InTransaction then Commit;
571 <  LoginPrompt := Database.LoginPrompt;
576 <  Database.LoginPrompt := false;
577 <  Database.Connected := false;
578 <  Database.Connected := true;
579 <  Database.LoginPrompt := LoginPrompt;
580 <  GetTransaction.Active := true;
571 >  Database.Reconnect;
572   end;
573  
574   procedure TCustomIBXScript.ExecSQL(stmt: string);
# Line 750 | Line 741 | end;
741  
742   function TCustomIBXScript.ProcessStatement(stmt: string): boolean;
743   var command: string;
753    ucStmt: string;
744  
745    function Toggle(aValue: string): boolean;
746    begin
# Line 771 | Line 761 | var command: string;
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
# Line 790 | Line 780 | var command: string;
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
# Line 805 | Line 796 | var command: string;
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
# Line 822 | Line 813 | var command: string;
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]);
833          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]);
845          ucStmt := AnsiUpperCase(stmt);
836          end;
837        end;
838      finally
# Line 860 | Line 850 | var  RegexObj: TRegExpr;
850       LoginPrompt: boolean;
851   begin
852    Result := false;
863  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
# Line 877 | Line 867 | begin
867        if assigned(FOnCreateDatabase) then
868          OnCreateDatabase(self,FileName);
869        stmt := 'CREATE DATABASE ''' + FileName + '''' + system.copy(stmt,RegexObj.MatchPos[3], RegexObj.MatchLen[3]);
880      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;
# Line 909 | Line 899 | begin
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;
# Line 918 | Line 908 | begin
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;
# Line 928 | Line 918 | begin
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;
# Line 937 | Line 927 | begin
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
# Line 952 | Line 942 | begin
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]);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines