Skip to content

Commit 6878578

Browse files
committed
fix: use default library of connection when the one from a stored session contains an invalid path/file
Refs #2501
1 parent 0aaa1f2 commit 6878578

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

source/apphelpers.pas

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,12 @@ TAppSettings = class(TObject)
360360
function FormatByteNumber( Bytes: String; Decimals: Byte = 1 ): String; Overload;
361361
function FormatTimeNumber(Seconds: Double; DisplaySeconds: Boolean; MilliSecondsPrecision: Integer=1): String;
362362
function GetTempDir: String;
363+
// Return directory of running executable, including a trailing path delimiter
363364
function GetAppDir: String;
365+
// Return directory with dlls or dylibs, or empty string for auto-detection
366+
function GetLibDir: String;
367+
// Return directory with MySQL plugin files. Empty on Linux inidicating auto-detection.
368+
function GetPluginDir: String;
364369
procedure SaveUnicodeFile(Filename: String; Text: String; Encoding: TEncoding);
365370
procedure OpenTextFile(const Filename: String; out Stream: TFileStream; var Encoding: TEncoding);
366371
function DetectEncoding(Stream: TStream): TEncoding;
@@ -1310,6 +1315,17 @@ function GetAppDir: String;
13101315
Result := ExtractFilePath(Application.ExeName);
13111316
end;
13121317

1318+
function GetLibDir: String;
1319+
begin
1320+
Result := GetAppDir;
1321+
end;
1322+
1323+
function GetPluginDir: String;
1324+
begin
1325+
Result := GetLibDir;
1326+
Result := Result + 'plugins' + PathDelim;
1327+
end;
1328+
13131329
{**
13141330
Save a textfile with unicode
13151331
}

source/dbconnection.pas

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,9 @@ constructor TConnectionParameters.Create(SessionRegPath: String);
14871487
FPort := MakeInt(AppSettings.ReadString(asPort));
14881488
FCompressed := AppSettings.ReadBool(asCompressed);
14891489
FAllDatabases := AppSettings.ReadString(asDatabases);
1490-
FLibraryOrProvider := AppSettings.ReadString(asLibrary, '', DefaultLibrary);
1490+
FLibraryOrProvider := AppSettings.ReadString(asLibrary);
1491+
if not FileExists(GetLibDir + FLibraryOrProvider) then
1492+
FLibraryOrProvider := DefaultLibrary; // Catches empty string and any non-existant file
14911493
FComment := AppSettings.ReadString(asComment);
14921494

14931495
// Auto-activate SSH for sessions created before asSSHtunnelActive was introduced
@@ -2049,7 +2051,7 @@ function TConnectionParameters.GetLibraries: TStringList;
20492051
end;
20502052
case NetTypeGroup of
20512053
ngMySQL, ngPgSQL, ngSQLite, ngInterbase: begin
2052-
Dlls := TDirectory.GetFiles(GetAppDir, '*.dll');
2054+
Dlls := TDirectory.GetFiles(GetLibDir, '*.dll');
20532055
for DllPath in Dlls do begin
20542056
DllFile := ExtractFileName(DllPath);
20552057
if rx.Exec(DllFile) then begin
@@ -2540,9 +2542,11 @@ procedure TMySQLConnection.SetActive( Value: Boolean );
25402542
if Parameters.WantSSL and (not FLib.IsLibMariadb) then
25412543
ClientFlags := ClientFlags or CLIENT_SSL;
25422544

2543-
// Point libmysql to the folder with client plugins
2544-
PluginDir := AnsiString(GetAppDir+'plugins');
2545-
SetOption(FLib.MYSQL_PLUGIN_DIR, PAnsiChar(PluginDir));
2545+
if not GetPluginDir.IsEmpty then begin
2546+
// Point libmysql to the folder with client plugins
2547+
PluginDir := AnsiString(GetPluginDir);
2548+
SetOption(FLib.MYSQL_PLUGIN_DIR, PAnsiChar(PluginDir));
2549+
end;
25462550

25472551
// Enable cleartext plugin
25482552
if Parameters.CleartextPluginEnabled then
@@ -3309,7 +3313,7 @@ procedure TMySQLConnection.DoBeforeConnect;
33093313
LibraryPath: String;
33103314
begin
33113315
// Init libmysql before actually connecting.
3312-
LibraryPath := GetAppDir + Parameters.LibraryOrProvider;
3316+
LibraryPath := GetLibDir + Parameters.LibraryOrProvider;
33133317
Log(lcDebug, f_('Loading library file %s ...', [LibraryPath]));
33143318
// Throws EDbError on any failure:
33153319
FLib := TMySQLLib.Create(LibraryPath, Parameters.DefaultLibrary);
@@ -3324,7 +3328,7 @@ procedure TPgConnection.DoBeforeConnect;
33243328
msg: String;
33253329
begin
33263330
// Init lib before actually connecting.
3327-
LibraryPath := GetAppDir + Parameters.LibraryOrProvider;
3331+
LibraryPath := GetLibDir + Parameters.LibraryOrProvider;
33283332
Log(lcDebug, f_('Loading library file %s ...', [LibraryPath]));
33293333
try
33303334
FLib := TPostgreSQLLib.Create(LibraryPath, Parameters.DefaultLibrary);
@@ -3355,7 +3359,7 @@ procedure TSQLiteConnection.DoBeforeConnect;
33553359
LibraryPath: String;
33563360
begin
33573361
// Init lib before actually connecting.
3358-
LibraryPath := GetAppDir + Parameters.LibraryOrProvider;
3362+
LibraryPath := GetLibDir + Parameters.LibraryOrProvider;
33593363
Log(lcDebug, f_('Loading library file %s ...', [LibraryPath]));
33603364
// Throws EDbError on any failure:
33613365
if Parameters.NetType = ntSQLite then

0 commit comments

Comments
 (0)