Skip to content

Commit d9b6f87

Browse files
committed
fix: non working MySQL command line launcher, for all platforms
Todo: - test on Linux and macOS - the Linux code should probe for additional terminal emulators like gnome-terminal, konsole, xterm, etc., when x-terminal-emulator is not available Refs #2363
1 parent e18b3db commit d9b6f87

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

source/main.pas

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface
1515
LazStringUtils, dbconnection, dbstructures, dbstructures.mysql, generic_types,
1616
apphelpers, extra_controls, createdatabase, SynEditMarkupBracket,
1717
searchreplace, ImgList, IniFiles, LazFileUtils, LazUTF8, tabletools,
18-
lazaruscompat, extfiledialog;
18+
lazaruscompat, extfiledialog, process;
1919

2020

2121
type
@@ -3782,8 +3782,9 @@ procedure TMainForm.actDropObjectsExecute(Sender: TObject);
37823782

37833783
procedure TMainForm.actLaunchCommandlineExecute(Sender: TObject);
37843784
var
3785-
path, p, log, cmd: String;
3785+
path, log, cmd: String;
37863786
Conn: TDBConnection;
3787+
P: TProcess;
37873788
begin
37883789
// Launch mysql.exe
37893790
Conn := ActiveConnection;
@@ -3796,20 +3797,36 @@ procedure TMainForm.actLaunchCommandlineExecute(Sender: TObject);
37963797
path := IncludeTrailingPathDelimiter(path);
37973798
if not FileExists(path+cmd, true) then begin
37983799
ErrorDialog(f_('You need to tell %s where your MySQL binaries reside, in %s > %s > %s.', [APPNAME, _('Tools'), _('Preferences'), _('General')])+
3799-
CRLF+CRLF+f_('Current setting is: "%s"', [path]));
3800+
LineEnding+LineEnding+f_('Current setting is: "%s"', [path]));
38003801
end else begin
3801-
p := '';
3802-
{$IFNDEF WINDOWS}
3803-
p := ' -e '+path+cmd;
3804-
path := '';
3805-
cmd := '$TERM';
3806-
{$ENDIF}
3807-
3808-
log := path + cmd + p + Conn.Parameters.GetExternalCliArguments(Conn, nbTrue);
3802+
log := cmd + Conn.Parameters.GetExternalCliArguments(Conn, nbTrue);
38093803
LogSQL(f_('Launching command line: %s', [log]), lcInfo);
38103804

3811-
p := p + Conn.Parameters.GetExternalCliArguments(Conn, nbFalse);
3812-
ShellExec(cmd, path, p);
3805+
P := TProcess.Create(nil);
3806+
try
3807+
{$IF defined(WINDOWS)}
3808+
P.Executable := path + cmd;
3809+
P.Parameters.Add(Conn.Parameters.GetExternalCliArguments(Conn, nbFalse));
3810+
P.Options := P.Options + [poNewConsole]; // Windows only, opens console
3811+
3812+
{$ElseIf defined(LINUX)}
3813+
P.Executable := 'x-terminal-emulator';
3814+
P.Parameters.Add('-e');
3815+
P.Parameters.Add(path + cmd + ' ' + Conn.Parameters.GetExternalCliArguments(Conn, nbFalse));
3816+
P.Options := P.Options + [poWaitOnExit];
3817+
3818+
{$ElseIf defined(DARWIN)}
3819+
P.Executable := '/usr/bin/open';
3820+
P.Parameters.Add('-a');
3821+
P.Parameters.Add('Terminal');
3822+
P.Parameters.Add(path + cmd + ' ' + Conn.Parameters.GetExternalCliArguments(Conn, nbFalse));
3823+
{$ENDIF}
3824+
3825+
P.Execute;
3826+
finally
3827+
P.Free;
3828+
end;
3829+
38133830
end;
38143831
end;
38153832
end;

0 commit comments

Comments
 (0)