Skip to content
Permalink
Browse files

Issue #677: provide a new library combobox in MySQL mode, for selecti…

…ng any of the libmysql/mariadb.dll files from the application directory
  • Loading branch information...
ansgarbecker committed Jul 5, 2019
1 parent a9fd8be commit e804db8fcc2db928dff08555a1aa70af0afbb5fb
Showing with 67 additions and 33 deletions.
  1. +5 −1 out/locale/en/LC_MESSAGES/default.po
  2. +2 −1 source/apphelpers.pas
  3. +21 −4 source/connections.dfm
  4. +22 −1 source/connections.pas
  5. +17 −26 source/dbconnection.pas
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: HeidiSQL\n"
"POT-Creation-Date: 2012-11-05 21:40\n"
"PO-Revision-Date: 2019-06-12 20:31+0200\n"
"PO-Revision-Date: 2019-07-05 06:42+0200\n"
"Last-Translator: Ansgar Becker <anse@heidisql.com>\n"
"Language-Team: English (http://www.transifex.com/projects/p/heidisql/language/en/)\n"
"MIME-Version: 1.0\n"
@@ -4025,6 +4025,10 @@ msgstr "Trying to load library with full path: %s"
msgid "Library error in %s: Could not find procedure address for \"%s\""
msgstr "Library error in %s: Could not find procedure address for \"%s\""

#. DLL loading failed entirely
msgid "Library %s seems unusable. Please select a different one."
msgstr "Library %s seems unusable. Please select a different one."

#: dbconnection.pas:1392
msgid "Cannot find a usable %s. Please launch %s from the directory where you have installed it."
msgstr "Cannot find a usable %s. Please launch %s from the directory where you have installed it."
@@ -141,7 +141,7 @@ TQueryThread = class(TThread)
asWrapLongLines, asDisplayBLOBsAsText, asSingleQueries, asMemoEditorWidth, asMemoEditorHeight, asMemoEditorMaximized,
asMemoEditorWrap, asDelimiter, asSQLHelpWindowLeft, asSQLHelpWindowTop, asSQLHelpWindowWidth,
asSQLHelpWindowHeight, asSQLHelpPnlLeftWidth, asSQLHelpPnlRightTopHeight, asHost,
asUser, asPassword, asCleartextPluginEnabled, asWindowsAuth, asLoginPrompt, asPort,
asUser, asPassword, asCleartextPluginEnabled, asWindowsAuth, asLoginPrompt, asPort, asLibrary,
asPlinkExecutable, asSSHtunnelHost, asSSHtunnelHostPort, asSSHtunnelPort, asSSHtunnelUser,
asSSHtunnelPassword, asSSHtunnelTimeout, asSSHtunnelPrivateKey, asSSLActive, asSSLKey,
asSSLCert, asSSLCA, asSSLCipher, asNetType, asCompressed, asLocalTimeZone, asQueryTimeout, asKeepAlive,
@@ -3495,6 +3495,7 @@ constructor TAppSettings.Create;
InitSetting(asWindowsAuth, 'WindowsAuth', 0, False, '', True);
InitSetting(asLoginPrompt, 'LoginPrompt', 0, False, '', True);
InitSetting(asPort, 'Port', 0, False, '', True);
InitSetting(asLibrary, 'Library', 0, False, 'libmariadb.dll', True);
InitSetting(asPlinkExecutable, 'PlinkExecutable', 0, False, '');
InitSetting(asSSHtunnelHost, 'SSHtunnelHost', 0, False, '', True);
InitSetting(asSSHtunnelHostPort, 'SSHtunnelHostPort', 22, False, '', True);
@@ -273,11 +273,18 @@ object connform: Tconnform
end
object lblComment: TLabel
Left = 3
Top = 241
Top = 270
Width = 49
Height = 13
Caption = 'Comment:'
end
object lblLibrary: TLabel
Left = 3
Top = 243
Width = 37
Height = 13
Caption = 'Library:'
end
object chkCompressed: TCheckBox
Left = 120
Top = 190
@@ -377,12 +384,12 @@ object connform: Tconnform
end
object memoComment: TMemo
Left = 120
Top = 238
Top = 267
Width = 294
Height = 119
Height = 90
Anchors = [akLeft, akTop, akRight, akBottom]
ScrollBars = ssVertical
TabOrder = 10
TabOrder = 11
OnChange = Modification
end
object editDatabases: TButtonedEdit
@@ -399,6 +406,16 @@ object connform: Tconnform
OnChange = Modification
OnRightButtonClick = editDatabasesRightButtonClick
end
object comboLibrary: TComboBox
Left = 120
Top = 240
Width = 294
Height = 21
Style = csDropDownList
Anchors = [akLeft, akTop, akRight]
TabOrder = 10
OnChange = Modification
end
end
end
object tabSSHtunnel: TTabSheet
@@ -11,7 +11,7 @@ interface
uses
Windows, SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls,
VirtualTrees, Menus, Graphics, Generics.Collections, ActiveX, extra_controls, Messages,
dbconnection, gnugettext;
dbconnection, gnugettext, SynRegExpr, System.Types, System.IOUtils;

type
Tconnform = class(TFormWithSizeGrip)
@@ -121,6 +121,8 @@ Tconnform = class(TFormWithSizeGrip)
TimerButtonAnimation: TTimer;
lblBackgroundColor: TLabel;
ColorBoxBackgroundColor: TColorBox;
comboLibrary: TComboBox;
lblLibrary: TLabel;
procedure FormCreate(Sender: TObject);
procedure btnOpenClick(Sender: TObject);
procedure FormShow(Sender: TObject);
@@ -230,6 +232,9 @@ procedure Tconnform.FormCreate(Sender: TObject);
nt: TNetType;
Node: PVirtualNode;
Params: TConnectionParameters;
rx: TRegExpr;
Libs: TStringDynArray;
LibPath, LibFile: String;
begin
// Fix GUI stuff
TranslateComponent(Self);
@@ -265,6 +270,17 @@ procedure Tconnform.FormCreate(Sender: TObject);
end;
Params.Free;

// Detect existing MySQL libraries
rx := TRegExpr.Create;
rx.Expression := '^lib(mysql|mariadb).*\.dll$';
Libs := TDirectory.GetFiles(ExtractFilePath(ParamStr(0)), '*.dll');
for LibPath in Libs do begin
LibFile := ExtractFileName(LibPath);
if rx.Exec(LibFile) then begin
comboLibrary.Items.Add(LibFile);
end;
end;

// Init sessions tree
RefreshSessions(nil);

@@ -388,6 +404,7 @@ procedure Tconnform.btnSaveClick(Sender: TObject);
Sess.LocalTimeZone := chkLocalTimeZone.Checked;
Sess.FullTableStatus := chkFullTableStatus.Checked;
Sess.SessionColor := ColorBoxBackgroundColor.Selected;
Sess.LibraryFile := comboLibrary.Text;
Sess.AllDatabasesStr := editDatabases.Text;
Sess.Comment := memoComment.Text;
Sess.StartupScriptFilename := editStartupScript.Text;
@@ -582,6 +599,7 @@ function Tconnform.CurrentParams: TConnectionParameters;
else
Result.Port := 0;
Result.AllDatabasesStr := editDatabases.Text;
Result.LibraryFile := comboLibrary.Text;
Result.Comment := memoComment.Text;
Result.SSHHost := editSSHHost.Text;
Result.SSHPort := MakeInt(editSSHPort.Text);
@@ -848,6 +866,7 @@ procedure Tconnform.ListSessionsFocusChanged(Sender: TBaseVirtualTree;
chkFullTableStatus.Checked := Sess.FullTableStatus;
ColorBoxBackgroundColor.Selected := Sess.SessionColor;
editDatabases.Text := Sess.AllDatabasesStr;
comboLibrary.ItemIndex := comboLibrary.Items.IndexOf(Sess.LibraryFile);
memoComment.Text := Sess.Comment;
editStartupScript.Text := Sess.StartupScriptFilename;
editSSHPlinkExe.Text := Sess.SSHPlinkExe;
@@ -1108,6 +1127,7 @@ procedure Tconnform.Modification(Sender: TObject);
or (Sess.SessionColor <> ColorBoxBackgroundColor.Selected)
or (Sess.NetType <> TNetType(comboNetType.ItemIndex))
or (Sess.StartupScriptFilename <> editStartupScript.Text)
or (Sess.LibraryFile <> comboLibrary.Text)
or (Sess.AllDatabasesStr <> editDatabases.Text)
or (Sess.Comment <> memoComment.Text)
or (Sess.SSHHost <> editSSHHost.Text)
@@ -1187,6 +1207,7 @@ procedure Tconnform.ValidateControls;
lblPort.Enabled := False; // Named instance without port
editPort.Enabled := lblPort.Enabled;
updownPort.Enabled := lblPort.Enabled;
comboLibrary.Enabled := Params.NetTypeGroup in [ngMySQL];
if Params.NetTypeGroup = ngPgSQL then
lblDatabase.Caption := _('Database')+':'
else
@@ -213,7 +213,7 @@ TPlink = class(TObject)
TConnectionParameters = class(TObject)
strict private
FNetType: TNetType;
FHostname, FUsername, FPassword, FAllDatabases, FComment, FStartupScriptFilename,
FHostname, FUsername, FPassword, FAllDatabases, FLibraryFile, FComment, FStartupScriptFilename,
FSessionPath, FSSLPrivateKey, FSSLCertificate, FSSLCACertificate, FSSLCipher, FServerVersion,
FSSHHost, FSSHUser, FSSHPassword, FSSHPlinkExe, FSSHPrivateKey: String;
FPort, FSSHPort, FSSHLocalPort, FSSHTimeout, FCounter, FQueryTimeout, FKeepAlive: Integer;
@@ -263,6 +263,7 @@ TConnectionParameters = class(TObject)
property WindowsAuth: Boolean read FWindowsAuth write FWindowsAuth;
property CleartextPluginEnabled: Boolean read FCleartextPluginEnabled write FCleartextPluginEnabled;
property AllDatabasesStr: String read FAllDatabases write FAllDatabases;
property LibraryFile: String read FLibraryFile write FLibraryFile;
property Comment: String read FComment write FComment;
property StartupScriptFilename: String read FStartupScriptFilename write FStartupScriptFilename;
property QueryTimeout: Integer read FQueryTimeout write FQueryTimeout;
@@ -1088,6 +1089,7 @@ constructor TConnectionParameters.Create;
FPort := DefaultPort;
FCompressed := AppSettings.GetDefaultBool(asCompressed);
FAllDatabases := AppSettings.GetDefaultString(asDatabases);
FLibraryFile := AppSettings.GetDefaultString(asLibrary);
FComment := AppSettings.GetDefaultString(asComment);

FSSHHost := AppSettings.GetDefaultString(asSSHtunnelHost);
@@ -1154,6 +1156,7 @@ constructor TConnectionParameters.Create(SessionRegPath: String);
FPort := MakeInt(AppSettings.ReadString(asPort));
FCompressed := AppSettings.ReadBool(asCompressed);
FAllDatabases := AppSettings.ReadString(asDatabases);
FLibraryFile := AppSettings.ReadString(asLibrary);
FComment := AppSettings.ReadString(asComment);

FSSHHost := AppSettings.ReadString(asSSHtunnelHost);
@@ -1218,6 +1221,7 @@ procedure TConnectionParameters.SaveToRegistry;
AppSettings.WriteInt(asKeepAlive, FKeepAlive);
AppSettings.WriteBool(asFullTableStatus, FFullTableStatus);
AppSettings.WriteString(asDatabases, FAllDatabases);
AppSettings.WriteString(asLibrary, FLibraryFile);
AppSettings.WriteString(asComment, FComment);
AppSettings.WriteString(asStartupScriptFilename, FStartupScriptFilename);
AppSettings.WriteInt(asTreeBackground, FSessionColor);
@@ -2214,35 +2218,22 @@ procedure TDBConnection.DoBeforeConnect;
procedure TMySQLConnection.DoBeforeConnect;
var
msg,
TryLibraryPath: String;
TryLibraryPaths: TStringList;
LibraryPath: String;
begin
// Init libmysql before actually connecting.


// Try newer libmariadb version at first, and fall back to libmysql,
// then fall back to dlls somewhere else on the users harddisk
// Win XP needs libmysql.dll
TryLibraryPaths := TStringList.Create;
TryLibraryPaths.Add(ExtractFilePath(Application.ExeName) + 'libmariadb.dll');
TryLibraryPaths.Add(ExtractFilePath(Application.ExeName) + 'libmysql.dll');
TryLibraryPaths.Add('libmariadb.dll');
TryLibraryPaths.Add('libmysql.dll');

for TryLibraryPath in TryLibraryPaths do begin
Log(lcDebug, f_('Loading library file %s ...', [TryLibraryPath]));
try
FLib := TMySQLLib.Create(TryLibraryPath);
Log(lcDebug, FLib.DllFile + ' v' + DecodeApiString(FLib.mysql_get_client_info) + ' loaded.');
Break;
except
on E:Exception do
Log(lcDebug, E.Message);
end
LibraryPath := ExtractFilePath(ParamStr(0)) + Parameters.LibraryFile;
Log(lcDebug, f_('Loading library file %s ...', [LibraryPath]));
try
FLib := TMySQLLib.Create(LibraryPath);
Log(lcDebug, FLib.DllFile + ' v' + DecodeApiString(FLib.mysql_get_client_info) + ' loaded.');
except
on E:Exception do
Log(lcDebug, E.Message);
end;

if not Assigned(FLib) then begin
msg := f_('Cannot find a usable %s. Please launch %s from the directory where you have installed it.',
[ExtractFileName(TryLibraryPaths[0]), ExtractFileName(ParamStr(0))]
msg := f_('Library %s seems unusable. Please select a different one.',
[ExtractFileName(LibraryPath)]
);
if Windows.GetLastError <> 0 then
msg := msg + CRLF + CRLF + f_('Internal error %d:', [Windows.GetLastError]) + ' ' + SysErrorMessage(Windows.GetLastError);

0 comments on commit e804db8

Please sign in to comment.
You can’t perform that action at this time.