Skip to content

Commit bb517d7

Browse files
committed
fix: TMySQLQuery.TableName() returns wrong string, and introduce apphelpers.GetAppDir
Refs #2305
1 parent 06322de commit bb517d7

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

source/apphelpers.pas

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ TAppSettings = class(TObject)
356356
function FormatByteNumber( Bytes: String; Decimals: Byte = 1 ): String; Overload;
357357
function FormatTimeNumber(Seconds: Double; DisplaySeconds: Boolean; MilliSecondsPrecision: Integer=1): String;
358358
//function GetTempDir: String;
359+
function GetAppDir: String;
359360
procedure SaveUnicodeFile(Filename: String; Text: String; Encoding: TEncoding);
360361
procedure OpenTextFile(const Filename: String; out Stream: TFileStream; var Encoding: TEncoding);
361362
function DetectEncoding(Stream: TStream): TEncoding;
@@ -1303,6 +1304,11 @@ function FormatTimeNumber(Seconds: Double; DisplaySeconds: Boolean; MilliSeconds
13031304
end;}
13041305

13051306

1307+
function GetAppDir: String;
1308+
begin
1309+
Result := ExtractFilePath(Application.ExeName);
1310+
end;
1311+
13061312
{**
13071313
Save a textfile with unicode
13081314
}
@@ -2698,7 +2704,7 @@ procedure InitMoFile(LangCode: String);
26982704
// Initialize .mo file in the given language, so we can use that for translating via _()
26992705
if LangCode.IsEmpty then
27002706
LangCode := SysLanguage;
2701-
LocaleDir := AppendPathDelim(ExtractFilePath(Application.ExeName)) + AppendPathDelim('locale');
2707+
LocaleDir := GetAppDir + AppendPathDelim('locale');
27022708
AppLanguageMoBasePath := LocaleDir + GetApplicationName;
27032709
MOFileName := '';
27042710
if not LangCode.IsEmpty then begin
@@ -3662,7 +3668,7 @@ constructor TAppSettings.Create;
36623668
FReads := 0;
36633669
FWrites := 0;
36643670

3665-
PortableLockFile := ExtractFilePath(ParamStr(0)) + FPortableLockFileBase;
3671+
PortableLockFile := GetAppDir + FPortableLockFileBase;
36663672

36673673
// Use filename from command line. If not given, use file in directory of executable.
36683674
rx := TRegExpr.Create;
@@ -3675,7 +3681,7 @@ constructor TAppSettings.Create;
36753681
end;
36763682
// Default settings file, if not given per command line
36773683
if FSettingsFile = '' then
3678-
FSettingsFile := ExtractFilePath(ParamStr(0)) + 'portable_settings.txt';
3684+
FSettingsFile := GetAppDir + 'portable_settings.txt';
36793685
// Backwards compatibility: only settings file exists, create lock file in that case
36803686
if FileExists(FSettingsFile) and (not FileExists(PortableLockFile)) then begin
36813687
NewFileHandle := FileCreate(PortableLockFile);
@@ -3932,7 +3938,7 @@ constructor TAppSettings.Create;
39323938

39333939
// Default folder for snippets
39343940
if FPortableMode then
3935-
DefaultSnippetsDirectory := ExtractFilePath(ParamStr(0))
3941+
DefaultSnippetsDirectory := GetAppDir
39363942
else
39373943
DefaultSnippetsDirectory := DirnameUserDocuments;
39383944
DefaultSnippetsDirectory := DefaultSnippetsDirectory + 'Snippets' + DirectorySeparator;
@@ -4660,7 +4666,7 @@ function TAppSettings.DirnameBackups: String;
46604666
begin
46614667
// Create backup folder if it does not exist and return it
46624668
if PortableMode then begin
4663-
Result := ExtractFilePath(Application.ExeName) + 'Backups' + DirectorySeparator
4669+
Result := GetAppDir + 'Backups' + DirectorySeparator
46644670
end else begin
46654671
Result := DirnameUserAppData + 'Backups' + DirectorySeparator;
46664672
end;
@@ -4673,7 +4679,7 @@ function TAppSettings.DirnameBackups: String;
46734679
function TAppSettings.DirnameHighlighters: string;
46744680
begin
46754681
if PortableMode then begin
4676-
Result := ExtractFilePath(Application.ExeName) + 'Highlighters' + DirectorySeparator
4682+
Result := GetAppDir + 'Highlighters' + DirectorySeparator
46774683
end else begin
46784684
Result := DirnameUserAppData + 'Highlighters' + DirectorySeparator;
46794685
end;

source/connections.pas

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ procedure Tconnform.FormCreate(Sender: TObject);
334334
editLogFilePath.Hint := FilenameHint;
335335

336336
// Populate dropdown with supported SSH executables
337-
ExeFiles := FindAllFiles(ExtractFilePath(ParamStr(0)), '*.exe', False);
337+
ExeFiles := FindAllFiles(GetAppDir, '*.exe', False);
338338
for ExePath in ExeFiles do begin
339339
ExeFile := ExtractFileName(ExePath);
340340
if ExecRegExprI('([pk]link|putty)', ExeFile) then begin
@@ -1395,7 +1395,7 @@ procedure Tconnform.editUsernameRightButtonClick(Sender: TObject);
13951395
FPopupCiphers := TPopupMenu.Create(Self);
13961396
//FPopupCiphers.AutoHotkeys := maManual;
13971397
Params := CurrentParams;
1398-
LibraryPath := ExtractFilePath(ParamStr(0)) + Params.LibraryOrProvider;
1398+
LibraryPath := GetAppDir + Params.LibraryOrProvider;
13991399
// Throws EDbError on any failure:
14001400
Lib := TSQLiteLib.CreateWithMultipleCipherFunctions(LibraryPath, Params.DefaultLibrary);
14011401
for i:=1 to Lib.sqlite3mc_cipher_count() do begin
@@ -1758,7 +1758,7 @@ procedure Tconnform.PickFile(Sender: TObject);
17581758
FileNames.Assign(Selector.Files);
17591759
for i:=0 to FileNames.Count-1 do begin
17601760
// Remove path if it's the application directory
1761-
if ExtractFilePath(FileNames[i]) = ExtractFilePath(Application.ExeName) then
1761+
if ExtractFilePath(FileNames[i]) = GetAppDir then
17621762
FileNames[i] := ExtractFileName(FileNames[i]);
17631763
end;
17641764
Edit.Text := Implode(DELIM, FileNames);

source/dbconnection.pas

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,7 @@ function TConnectionParameters.GetLibraries: TStringList;
19401940
end;
19411941
end;
19421942
{$Else}
1943-
Dlls := FindAllFiles(ExtractFilePath(ParamStr(0)), '*.' + SharedSuffix, False);
1943+
Dlls := FindAllFiles(GetAppDir, '*.' + SharedSuffix, False);
19441944
for DllPath in Dlls do begin
19451945
DllFile := ExtractFileName(DllPath);
19461946
if rx.Exec(DllFile) then begin
@@ -2426,7 +2426,7 @@ procedure TMySQLConnection.SetActive( Value: Boolean );
24262426

24272427
{$IfDef WINDOWS}
24282428
// Point libmysql to the folder with client plugins
2429-
PluginDir := AnsiString(ExtractFilePath(ParamStr(0))+'plugins');
2429+
PluginDir := AnsiString(GetAppDir+'plugins');
24302430
SetOption(FLib.MYSQL_PLUGIN_DIR, PAnsiChar(PluginDir));
24312431
{$EndIf}
24322432

@@ -3270,7 +3270,7 @@ procedure TMySQLConnection.DoBeforeConnect;
32703270
LibraryPath: String;
32713271
begin
32723272
// Init libmysql before actually connecting.
3273-
LibraryPath := {$IFNDEF LINUX}ExtractFilePath(ParamStr(0)) + {$ENDIF} Parameters.LibraryOrProvider;
3273+
LibraryPath := {$IFNDEF LINUX}GetAppDir + {$ENDIF} Parameters.LibraryOrProvider;
32743274
Log(lcDebug, f_('Loading library file %s ...', [LibraryPath]));
32753275
// Throws EDbError on any failure:
32763276
FLib := TMySQLLib.Create(LibraryPath, Parameters.DefaultLibrary);
@@ -3285,7 +3285,7 @@ procedure TPgConnection.DoBeforeConnect;
32853285
msg: String;
32863286
begin
32873287
// Init lib before actually connecting.
3288-
LibraryPath := {$IFNDEF LINUX}ExtractFilePath(ParamStr(0)) + {$ENDIF} Parameters.LibraryOrProvider;
3288+
LibraryPath := {$IFNDEF LINUX}GetAppDir + {$ENDIF} Parameters.LibraryOrProvider;
32893289
Log(lcDebug, f_('Loading library file %s ...', [LibraryPath]));
32903290
try
32913291
FLib := TPostgreSQLLib.Create(LibraryPath, Parameters.DefaultLibrary);
@@ -3316,7 +3316,7 @@ procedure TSQLiteConnection.DoBeforeConnect;
33163316
LibraryPath: String;
33173317
begin
33183318
// Init lib before actually connecting.
3319-
LibraryPath := {$IFNDEF LINUX}ExtractFilePath(ParamStr(0)) + {$ENDIF} Parameters.LibraryOrProvider;
3319+
LibraryPath := {$IFNDEF LINUX}GetAppDir + {$ENDIF} Parameters.LibraryOrProvider;
33203320
Log(lcDebug, f_('Loading library file %s ...', [LibraryPath]));
33213321
// Throws EDbError on any failure:
33223322
if Parameters.NetType = ntSQLite then
@@ -9947,6 +9947,7 @@ function TMySQLQuery.TableName(Column: Integer): String;
99479947
Objects: TDBObjectList;
99489948
Obj: TDBObject;
99499949
begin
9950+
Result := '';
99509951
Field := FConnection.Lib.mysql_fetch_field_direct(FCurrentResults, Column);
99519952
FieldDb := FConnection.DecodeAPIString(Field.db);
99529953
FieldTable := FConnection.DecodeAPIString(Field.table);
@@ -11332,7 +11333,7 @@ constructor TSQLFunctionList.Create(AOwner: TDBConnection; SQLFunctionsFileOrder
1133211333

1133311334
TryFiles := Explode(',', SQLFunctionsFileOrder);
1133411335
for TryFile in TryFiles do begin
11335-
IniFilePath := ExtractFilePath(Application.ExeName) + 'functions-'+TryFile+'.ini';
11336+
IniFilePath := GetAppDir + 'functions-'+TryFile+'.ini';
1133611337
FOwner.Log(lcDebug, 'Trying '+IniFilePath);
1133711338
if FileExists(IniFilePath) then begin
1133811339
FOwner.Log(lcInfo, 'Reading function definitions from '+IniFilePath);

source/main.pas

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,7 +2332,7 @@ function TMainForm.InitTabsIniFile: TIniFile;
23322332
// Try to open tabs.ini for writing or reading
23332333
// Taking multiple application instances into account
23342334
if AppSettings.PortableMode then
2335-
TabsIniFilename := ExtractFilePath(Application.ExeName) + 'tabs.ini'
2335+
TabsIniFilename := GetAppDir + 'tabs.ini'
23362336
else
23372337
TabsIniFilename := AppSettings.DirnameUserAppData + 'tabs.ini';
23382338
{WaitingSince := GetTickCount64;
@@ -4653,7 +4653,7 @@ procedure TMainForm.actRunRoutinesExecute(Sender: TObject);
46534653

46544654
procedure TMainForm.actNewWindowExecute(Sender: TObject);
46554655
begin
4656-
ShellExec( ExtractFileName(paramstr(0)), ExtractFilePath(paramstr(0)) );
4656+
ShellExec( ExtractFileName(paramstr(0)), GetAppDir);
46574657
end;
46584658

46594659

@@ -5640,7 +5640,7 @@ procedure TMainForm.actAttachDatabaseExecute(Sender: TObject);
56405640
try
56415641
for i:=0 to NewFiles.Count-1 do begin
56425642
// Remove path if it's the application directory
5643-
if ExtractFilePath(NewFiles[i]) = ExtractFilePath(Application.ExeName) then
5643+
if ExtractFilePath(NewFiles[i]) = GetAppDir then
56445644
NewFiles[i] := ExtractFileName(NewFiles[i]);
56455645
if OldFiles.IndexOf(NewFiles[i]) = -1 then begin
56465646
OldFiles.Add(NewFiles[i]);

0 commit comments

Comments
 (0)