mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
Code cleanup: outsource generation of mysql command line arguments into TConnectionParameters.GetExternalCliArguments
This commit is contained in:
@ -323,7 +323,7 @@ type
|
|||||||
function DefaultPort: Integer;
|
function DefaultPort: Integer;
|
||||||
function DefaultUsername: String;
|
function DefaultUsername: String;
|
||||||
function DefaultIgnoreDatabasePattern: String;
|
function DefaultIgnoreDatabasePattern: String;
|
||||||
function GetExternalCliArguments: String;
|
function GetExternalCliArguments(Connection: TDBConnection; ReplacePassword: Boolean): String;
|
||||||
published
|
published
|
||||||
property IsFolder: Boolean read FIsFolder write FIsFolder;
|
property IsFolder: Boolean read FIsFolder write FIsFolder;
|
||||||
property NetType: TNetType read FNetType write FNetType;
|
property NetType: TNetType read FNetType write FNetType;
|
||||||
@ -1723,6 +1723,54 @@ begin
|
|||||||
end;
|
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;
|
function TConnectionParameters.GetLibraries: TStringList;
|
||||||
var
|
var
|
||||||
rx: TRegExpr;
|
rx: TRegExpr;
|
||||||
|
@ -3828,7 +3828,6 @@ var
|
|||||||
path, p, log, cmd: String;
|
path, p, log, cmd: String;
|
||||||
sep: Char;
|
sep: Char;
|
||||||
Conn: TDBConnection;
|
Conn: TDBConnection;
|
||||||
PasswordStart, PasswordEnd: Integer;
|
|
||||||
begin
|
begin
|
||||||
// Launch mysql.exe
|
// Launch mysql.exe
|
||||||
Conn := ActiveConnection;
|
Conn := ActiveConnection;
|
||||||
@ -3856,43 +3855,10 @@ begin
|
|||||||
cmd := '$TERM';
|
cmd := '$TERM';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if Conn.Parameters.WantSSL then
|
log := path + cmd + p + Conn.Parameters.GetExternalCliArguments(Conn, True);
|
||||||
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;
|
|
||||||
LogSQL(f_('Launching command line: %s', [log]), lcInfo);
|
LogSQL(f_('Launching command line: %s', [log]), lcInfo);
|
||||||
|
|
||||||
|
p := p + Conn.Parameters.GetExternalCliArguments(Conn, False);
|
||||||
ShellExec(cmd, path, p);
|
ShellExec(cmd, path, p);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user