Skip to content

Commit 1c9ce4d

Browse files
committed
+ Unit DAC.MySQL.FireDAC para Delphi que suporta 3 dlls: libmysql.dll, libmariadb.dll e libmysqld.dll
* Ajustes em units DAC para usar uma nova função de buscar as libs * Firebird suporta detecção de fbclient.dll ou fbembed.dll
1 parent d44244f commit 1c9ce4d

5 files changed

Lines changed: 152 additions & 40 deletions

File tree

dac/delphi/DAC.Firebird.FireDAC.pas

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Maiores Informações
1+
// Maiores Informações
22
// https://github.com/OpenSourceCommunityBrasil/PascalLibs/wiki
33

44
unit DAC.Firebird.FireDAC;
@@ -15,6 +15,7 @@ TDAC = class
1515
FDriver: TFDPhysFBDriverLink;
1616
FConnection: TFDConnection;
1717
FQuery: TFDQuery;
18+
function GetDefaultLibDir: string;
1819
public
1920
constructor Create(aJSON: TJSONObject);
2021
destructor Destroy; override;
@@ -25,17 +26,10 @@ TDAC = class
2526
implementation
2627

2728
constructor TDAC.Create(aJSON: TJSONObject);
28-
var
29-
DefaultDir: string;
3029
begin
31-
if DirectoryExists(ExtractFileDir(ParamStr(0)) + '\lib\') then
32-
DefaultDir := ExtractFileDir(ParamStr(0)) + '\lib\'
33-
else
34-
DefaultDir := ExtractFileDir(ParamStr(0));
35-
3630
FDriver := TFDPhysFBDriverLink.Create(nil);
3731
FDriver.DriverID := 'FB';
38-
FDriver.VendorLib := DefaultDir + 'fbclient.dll';
32+
FDriver.VendorLib := GetDefaultLibDir;
3933

4034
FConnection := TFDConnection.Create(nil);
4135
try
@@ -74,6 +68,23 @@ function TDAC.getConnection: TFDConnection;
7468
Result := FConnection;
7569
end;
7670

71+
function TDAC.GetDefaultLibDir: string;
72+
var
73+
DefaultDir: string;
74+
begin
75+
Result := '';
76+
DefaultDir := ExtractFileDir(ParamStr(0));
77+
// Firebird depende de fbembed.dll ou fbclient.dll
78+
if FileExists(DefaultDir + 'fbclient.dll') then
79+
Result := DefaultDir + 'fbclient.dll'
80+
else if FileExists(DefaultDir + 'fbembed.dll') then
81+
Result := DefaultDir + 'fbembed.dll'
82+
else if FileExists(DefaultDir + '\lib\fbclient.dll') then
83+
Result := DefaultDir + '\lib\fbclient.dll'
84+
else if FileExists(DefaultDir + '\lib\fbembed.dll') then
85+
Result := DefaultDir + '\lib\fbembed.dll';
86+
end;
87+
7788
function TDAC.getQuery: TFDQuery;
7889
begin
7990
if not Assigned(FQuery) then

dac/delphi/DAC.MySQL.FireDAC.pas

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Maiores Informações
2+
// https://github.com/OpenSourceCommunityBrasil/PascalLibs/wiki
3+
4+
unit DAC.MySQL.FireDAC;
5+
6+
interface
7+
8+
uses
9+
JSON, SysUtils,
10+
FireDAC.Comp.Client, FireDAC.Phys.MySQL;
11+
12+
type
13+
TDAC = class
14+
private
15+
FDriver: TFDPhysMySQLDriverLink;
16+
FConnection: TFDConnection;
17+
FQuery: TFDQuery;
18+
function GetDefaultLibDir: string;
19+
public
20+
constructor Create(aJSON: TJSONObject);
21+
destructor Destroy; override;
22+
function getConnection: TFDConnection;
23+
function getQuery: TFDQuery;
24+
end;
25+
26+
implementation
27+
28+
constructor TDAC.Create(aJSON: TJSONObject);
29+
begin
30+
FDriver := TFDPhysMySQLDriverLink.Create(nil);
31+
FDriver.DriverID := 'MySQL';
32+
FDriver.VendorLib := GetDefaultLibDir;
33+
34+
FConnection := TFDConnection.Create(nil);
35+
try
36+
with FConnection do
37+
begin
38+
LoginPrompt := false;
39+
Params.Add('DriverID=FB');
40+
Params.Add('Server=' + aJSON.GetValue('dbserver').Value);
41+
Params.Add('User_Name=' + aJSON.GetValue('dbuser').Value);
42+
Params.Add('Password=' + aJSON.GetValue('dbpassword').Value);
43+
Params.Add('Port=' + aJSON.GetValue('dbport').Value);
44+
if aJSON.GetValue('banco') <> nil then
45+
Params.Add('Database=' + aJSON.GetValue('banco').Value);
46+
47+
FQuery := TFDQuery.Create(nil);
48+
FQuery.Connection := FConnection;
49+
FQuery.ResourceOptions.SilentMode := true;
50+
end;
51+
except
52+
// log
53+
end;
54+
end;
55+
56+
destructor TDAC.Destroy;
57+
begin
58+
if FDriver <> nil then
59+
FDriver.Free;
60+
if FQuery <> nil then
61+
FQuery.Free;
62+
if FConnection <> nil then
63+
FConnection.Free;
64+
inherited;
65+
end;
66+
67+
function TDAC.getConnection: TFDConnection;
68+
begin
69+
Result := FConnection;
70+
end;
71+
72+
function TDAC.GetDefaultLibDir: string;
73+
var
74+
DefaultDir: string;
75+
begin
76+
Result := '';
77+
DefaultDir := ExtractFileDir(ParamStr(0));
78+
// libmysql.dll, libmariadb or libmysqld.dll
79+
// procurando no diretório do exe primeiro, depois no diretório \lib\
80+
81+
if FileExists(DefaultDir + 'libmysql.dll') then
82+
Result := DefaultDir + 'libmysql.dll'
83+
else if FileExists(DefaultDir + 'libmariadb.dll') then
84+
Result := DefaultDir + 'libmariadb.dll'
85+
else if FileExists(DefaultDir + 'libmysqld.dll') then
86+
Result := DefaultDir + 'libmysqld.dll'
87+
else if FileExists(DefaultDir + '\lib\libmysql.dll') then
88+
Result := DefaultDir + '\lib\libmysql.dll'
89+
else if FileExists(DefaultDir + '\lib\libmariadb.dll') then
90+
Result := DefaultDir + '\lib\libmariadb.dll'
91+
else if FileExists(DefaultDir + '\lib\libmysqld.dll') then
92+
Result := DefaultDir + '\lib\libmysqld.dll'
93+
else
94+
raise Exception.Create('libmysql.dll, libmariadb.dll ou libmysqld.dll' +
95+
' precisam estar na raiz do executável ou na pasta \lib\');
96+
end;
97+
98+
function TDAC.getQuery: TFDQuery;
99+
begin
100+
if not Assigned(FQuery) then
101+
FQuery := TFDQuery.Create(nil);
102+
Result := FQuery;
103+
end;
104+
105+
end.

dac/delphi/DAC.Postgres.FireDAC.pas

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ TDAC = class
1515
FDriver: TFDPhysPgDriverLink;
1616
FConnection: TFDConnection;
1717
FQuery: TFDQuery;
18-
function GetDefaultDir(aFileName: string): string;
18+
function GetDefaultLibDir: string;
1919
public
2020
constructor Create(aJSON: TJSONObject);
2121
destructor Destroy; override;
@@ -34,7 +34,7 @@ constructor TDAC.Create(aJSON: TJSONObject);
3434
begin
3535
FDriver := TFDPhysPgDriverLink.Create(nil);
3636
FDriver.DriverID := 'PG';
37-
FDriver.VendorLib := GetDefaultDir('libpq.dll');
37+
FDriver.VendorLib := GetDefaultLibDir;
3838

3939
FConnection := TFDConnection.Create(nil);
4040
try
@@ -108,15 +108,16 @@ function TDAC.getDataBases: TFDQuery;
108108

109109
end;
110110

111-
function TDAC.GetDefaultDir(aFileName: string): string;
111+
function TDAC.GetDefaultLibDir: string;
112112
var
113113
DefaultDir: string;
114114
begin
115+
Result := '';
115116
DefaultDir := ExtractFileDir(ParamStr(0));
116-
if FileExists(DefaultDir + '\lib\' + aFileName) then
117-
Result := DefaultDir + '\lib\' + aFileName
118-
else
119-
Result := DefaultDir + aFileName;
117+
if FileExists(DefaultDir + '\lib\libpq.dll') then
118+
Result := DefaultDir + '\lib\libpq.dll'
119+
else if FileExists(DefaultDir + 'libpq.dll') then
120+
Result := DefaultDir + 'libpq.dll';
120121
end;
121122

122123
function TDAC.getQuery: TFDQuery;

dac/delphi/DAC.Postgres.Zeos.pas

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ TDAC = class
1818
FConnection: TZConnection;
1919
FQuery: TZQuery;
2020
FSchema: string;
21-
function GetDefaultDir(aFileName: string): string;
21+
function GetDefaultLibDir: string;
2222
public
2323
constructor Create(aJSON: TJSONObject);
2424
destructor Destroy; override;
@@ -48,7 +48,7 @@ constructor TDAC.Create(aJSON: TJSONObject);
4848
User := aJSON.GetValue('dbuser').Value;
4949
Password := aJSON.GetValue('dbpassword').Value;
5050
Protocol := 'postgresql';
51-
LibraryLocation := GetDefaultDir('libpq.dll');
51+
LibraryLocation := GetDefaultLibDir;
5252

5353
if aJSON.GetValue('banco') <> nil then
5454
Database := aJSON.GetValue('banco').Value;
@@ -108,15 +108,16 @@ function TDAC.getDataBases: TZQuery;
108108

109109
end;
110110

111-
function TDAC.GetDefaultDir(aFileName: string): string;
111+
function TDAC.GetDefaultLibDir(aFileName: string): string;
112112
var
113113
DefaultDir: string;
114114
begin
115+
Result := '';
115116
DefaultDir := ExtractFileDir(ParamStr(0));
116-
if FileExists(DefaultDir + '\lib\' + aFileName) then
117-
Result := DefaultDir + '\lib\' + aFileName
118-
else
119-
Result := DefaultDir + aFileName;
117+
if FileExists(DefaultDir + '\lib\libpq.dll') then
118+
Result := DefaultDir + '\lib\libpq.dll'
119+
else if FileExists(DefaultDir + 'libpq.dll') then
120+
Result := DefaultDir + 'libpq.dll';
120121
end;
121122

122123
function TDAC.getQuery: TQuery;

dac/lazarus/dac.postgres.zeos.pas

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ TDAC = class
1919
FConnection: TZConnection;
2020
FQuery: TZQuery;
2121
FSchema: string;
22-
function GetDefaultDir(aFileName: string): string;
22+
function GetDefaultLibDir: string;
2323
public
2424
constructor Create(aJSON: TJSONObject);
2525
destructor Destroy; override;
2626
function getConnection: TConnection;
2727
function getQuery: TQuery;
2828
function getConnectionStatus: string;
29-
function getDataBases: TZQuery;
30-
function getTables(aDataBaseName: string): TZQuery;
3129
end;
3230

3331
implementation
@@ -104,31 +102,27 @@ function TDAC.getConnectionStatus: string;
104102
end;
105103
end;
106104

107-
function TDAC.getDataBases: TZQuery;
108-
begin
109-
110-
end;
111-
112-
function TDAC.GetDefaultDir(aFileName: string): string;
105+
function TDAC.GetDefaultLibDir: string;
113106
var
114107
DefaultDir, temp: string;
115108
begin
109+
Result := '';
116110
DefaultDir := ExtractFileDir(ParamStr(0));
117-
temp := DefaultDir + '\lib\' + aFileName;
111+
112+
temp := DefaultDir + '\lib\libpq.dll';
118113
if FileExists(temp) then
119-
Result := DefaultDir + '\lib\' + aFileName
114+
Result := temp
120115
else
121-
Result := DefaultDir + '\' + aFileName;
116+
begin
117+
temp := DefaultDir + 'libpq.dll';
118+
if FileExists(temp) then
119+
Result := temp;
120+
end;
122121
end;
123122

124123
function TDAC.getQuery: TQuery;
125124
begin
126125
Result := FQuery;
127126
end;
128127

129-
function TDAC.getTables(aDataBaseName: string): TZQuery;
130-
begin
131-
132-
end;
133-
134128
end.

0 commit comments

Comments
 (0)