diff --git a/source/dbconnection.pas b/source/dbconnection.pas index 8e4b534e..58f970b9 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -323,7 +323,7 @@ type function DefaultPort: Integer; function DefaultUsername: String; function DefaultIgnoreDatabasePattern: String; - function GetExternalCliArguments: String; + function GetExternalCliArguments(Connection: TDBConnection; ReplacePassword: Boolean): String; published property IsFolder: Boolean read FIsFolder write FIsFolder; property NetType: TNetType read FNetType write FNetType; @@ -1723,6 +1723,54 @@ begin end; +function TConnectionParameters.GetExternalCliArguments(Connection: TDBConnection; ReplacePassword: Boolean): String; +var + Args: TStringList; +begin + // for mysql(dump) + Args := TStringList.Create; + Result := ''; + if WantSSL then + Args.Add('--ssl'); + if not SSLPrivateKey.IsEmpty then + Args.Add('--ssl-key="'+SSLPrivateKey+'"'); + if not SSLCertificate.IsEmpty then + Args.Add('--ssl-cert="'+SSLCertificate+'"'); + if not SSLCACertificate.IsEmpty then + Args.Add('--ssl-ca="'+SSLCACertificate+'"'); + + case NetType of + ntMySQL_NamedPipe: begin + Args.Add('--pipe'); + Args.Add('--socket="'+Hostname+'"'); + end; + ntMySQL_SSHtunnel: begin + Args.Add('--host="localhost"'); + Args.Add('--port='+IntToStr(SSHLocalPort)); + end; + else begin + Args.Add('--host="'+Hostname+'"'); + Args.Add('--port='+IntToStr(Port)); + end; + end; + + Args.Add('--user="'+Username+'"'); + if Password <> '' then begin + if ReplacePassword then + Args.Add('--password="***"') + else + Args.Add('--password="'+StringReplace(Password, '"', '\"', [rfReplaceAll])+'"'); + end; + if Compressed then + Args.Add('--compress'); + if Connection.Database <> '' then + Args.Add('--database="' + Connection.Database + '"'); + + Result := ' ' + Implode(' ', Args); + Args.Free; +end; + + function TConnectionParameters.GetLibraries: TStringList; var rx: TRegExpr; diff --git a/source/main.pas b/source/main.pas index 48e8098e..76fd98be 100644 --- a/source/main.pas +++ b/source/main.pas @@ -3828,7 +3828,6 @@ var path, p, log, cmd: String; sep: Char; Conn: TDBConnection; - PasswordStart, PasswordEnd: Integer; begin // Launch mysql.exe Conn := ActiveConnection; @@ -3856,43 +3855,10 @@ begin cmd := '$TERM'; end; - if Conn.Parameters.WantSSL then - p := p + ' --ssl'; - if not Conn.Parameters.SSLPrivateKey.IsEmpty then - p := p + ' --ssl-key="'+Conn.Parameters.SSLPrivateKey+'"'; - if not Conn.Parameters.SSLCertificate.IsEmpty then - p := p + ' --ssl-cert="'+Conn.Parameters.SSLCertificate+'"'; - if not Conn.Parameters.SSLCACertificate.IsEmpty then - p := p + ' --ssl-ca="'+Conn.Parameters.SSLCACertificate+'"'; - - case Conn.Parameters.NetType of - ntMySQL_NamedPipe: - p := p + ' --pipe --socket="'+Conn.Parameters.Hostname+'"'; - ntMySQL_SSHtunnel: - p := p + ' --host="localhost" --port='+IntToStr(Conn.Parameters.SSHLocalPort); - else - p := p + ' --host="'+Conn.Parameters.Hostname+'" --port='+IntToStr(Conn.Parameters.Port); - end; - - p := p + ' --user="'+Conn.Parameters.Username+'"'; - // Markers for removing password from log line - PasswordStart := -1; - PasswordEnd := -1; - if Conn.Parameters.Password <> '' then begin - PasswordStart := Length(path + cmd + p) +14; - p := p + ' --password="'+StringReplace(Conn.Parameters.Password, '"', '\"', [rfReplaceAll])+'"'; - PasswordEnd := Length(path + cmd + p); - end; - if Conn.Parameters.Compressed then - p := p + ' --compress'; - if ActiveDatabase <> '' then - p := p + ' --database="' + ActiveDatabase + '"'; - log := path + cmd + p; - if PasswordStart > -1 then begin - Delete(log, PasswordStart, PasswordEnd-PasswordStart); - Insert('********', log, PasswordStart); - end; + log := path + cmd + p + Conn.Parameters.GetExternalCliArguments(Conn, True); LogSQL(f_('Launching command line: %s', [log]), lcInfo); + + p := p + Conn.Parameters.GetExternalCliArguments(Conn, False); ShellExec(cmd, path, p); end; end;