Skip to content

Commit 99137da

Browse files
committed
* Padronização de código DAC para Delphi.
- Remoção de funções vazias para Delphi. - Ajuste de mensagens de erro faltantes no Postgres para Delphi.
1 parent 28c64c9 commit 99137da

6 files changed

Lines changed: 68 additions & 80 deletions

File tree

dac/delphi/DAC.Firebird.FireDAC.pas

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ constructor TDAC.Create(aJSON: TJSONObject);
5858

5959
destructor TDAC.Destroy;
6060
begin
61-
if Assigned(FDriver) then FreeAndNil(FDriver);
62-
if Assigned(FQuery) then FreeAndNil(FQuery);
61+
if Assigned(FDriver) then FreeAndNil(FDriver);
62+
if Assigned(FQuery) then FreeAndNil(FQuery);
6363
if Assigned(FConnection) then FreeAndNil(FConnection);
6464
inherited;
6565
end;
@@ -76,14 +76,18 @@ function TDAC.GetDefaultLibDir: string;
7676
Result := '';
7777
DefaultDir := ExtractFileDir(ParamStr(0));
7878
// Firebird depende de fbembed.dll ou fbclient.dll
79-
if FileExists(DefaultDir + 'fbclient.dll') then
79+
80+
if FileExists(DefaultDir + '\lib\fbclient.dll') then
81+
Result := DefaultDir + '\lib\fbclient.dll'
82+
else if FileExists(DefaultDir + '\lib\fbembed.dll') then
83+
Result := DefaultDir + '\lib\fbembed.dll'
84+
else if FileExists(DefaultDir + 'fbclient.dll') then
8085
Result := DefaultDir + 'fbclient.dll'
8186
else if FileExists(DefaultDir + 'fbembed.dll') then
8287
Result := DefaultDir + 'fbembed.dll'
83-
else if FileExists(DefaultDir + '\lib\fbclient.dll') then
84-
Result := DefaultDir + '\lib\fbclient.dll'
85-
else if FileExists(DefaultDir + '\lib\fbembed.dll') then
86-
Result := DefaultDir + '\lib\fbembed.dll';
88+
else
89+
raise Exception.Create('fbclient.dll ou fbembed.dll' +
90+
' precisam estar na raiz do executável ou na pasta \lib\');
8791
end;
8892

8993
function TDAC.getQuery: TQuery;

dac/delphi/DAC.Firebird.Zeos.pas

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ constructor TDAC.Create(aJSON: TJSONObject);
4141
User := aJSON.GetValue('dbuser').Value;
4242
Password := aJSON.GetValue('dbpassword').Value;
4343
Protocol := 'firebird';
44-
LibraryLocation := GetDefaultLibDir;
45-
4644
if aJSON.GetValue('banco') <> nil then
4745
Database := aJSON.GetValue('banco').Value;
46+
LibraryLocation := GetDefaultLibDir;
4847
end;
4948
FQuery := TQuery.Create(nil);
5049
FQuery.Connection := FConnection;
@@ -55,7 +54,7 @@ constructor TDAC.Create(aJSON: TJSONObject);
5554

5655
destructor TDAC.Destroy;
5756
begin
58-
if Assigned(FQuery) then FreeAndNil(FQuery);
57+
if Assigned(FQuery) then FreeAndNil(FQuery);
5958
if Assigned(FConnection) then FreeAndNil(FConnection);
6059
inherited;
6160
end;
@@ -72,14 +71,18 @@ function TDAC.GetDefaultLibDir: string;
7271
Result := '';
7372
DefaultDir := ExtractFileDir(ParamStr(0));
7473
// Firebird depende de fbembed.dll ou fbclient.dll
75-
if FileExists(DefaultDir + 'fbclient.dll') then
74+
75+
if FileExists(DefaultDir + '\lib\fbclient.dll') then
76+
Result := DefaultDir + '\lib\fbclient.dll'
77+
else if FileExists(DefaultDir + '\lib\fbembed.dll') then
78+
Result := DefaultDir + '\lib\fbembed.dll'
79+
else if FileExists(DefaultDir + 'fbclient.dll') then
7680
Result := DefaultDir + 'fbclient.dll'
7781
else if FileExists(DefaultDir + 'fbembed.dll') then
7882
Result := DefaultDir + 'fbembed.dll'
79-
else if FileExists(DefaultDir + '\lib\fbclient.dll') then
80-
Result := DefaultDir + '\lib\fbclient.dll'
81-
else if FileExists(DefaultDir + '\lib\fbembed.dll') then
82-
Result := DefaultDir + '\lib\fbembed.dll';
83+
else
84+
raise Exception.Create('fbclient.dll ou fbembed.dll' +
85+
' precisam estar na raiz do executável ou na pasta \lib\');
8386
end;
8487

8588
function TDAC.getQuery: TQuery;

dac/delphi/DAC.MySQL.FireDAC.pas

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ constructor TDAC.Create(aJSON: TJSONObject);
5858

5959
destructor TDAC.Destroy;
6060
begin
61-
if Assigned(FDriver) then FreeAndNil(FDriver);
62-
if Assigned(FQuery) then FreeAndNil(FQuery);
61+
if Assigned(FDriver) then FreeAndNil(FDriver);
62+
if Assigned(FQuery) then FreeAndNil(FQuery);
6363
if Assigned(FConnection) then FreeAndNil(FConnection);
6464
inherited;
6565
end;
@@ -76,20 +76,19 @@ function TDAC.GetDefaultLibDir: string;
7676
Result := '';
7777
DefaultDir := ExtractFileDir(ParamStr(0));
7878
// libmysql.dll, libmariadb or libmysqld.dll
79-
// procurando no diretório do exe primeiro, depois no diretório \lib\
8079

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
80+
if FileExists(DefaultDir + '\lib\libmysql.dll') then
8881
Result := DefaultDir + '\lib\libmysql.dll'
8982
else if FileExists(DefaultDir + '\lib\libmariadb.dll') then
9083
Result := DefaultDir + '\lib\libmariadb.dll'
9184
else if FileExists(DefaultDir + '\lib\libmysqld.dll') then
9285
Result := DefaultDir + '\lib\libmysqld.dll'
86+
else if FileExists(DefaultDir + 'libmysql.dll') then
87+
Result := DefaultDir + 'libmysql.dll'
88+
else if FileExists(DefaultDir + 'libmariadb.dll') then
89+
Result := DefaultDir + 'libmariadb.dll'
90+
else if FileExists(DefaultDir + 'libmysqld.dll') then
91+
Result := DefaultDir + 'libmysqld.dll'
9392
else
9493
raise Exception.Create('libmysql.dll, libmariadb.dll ou libmysqld.dll' +
9594
' precisam estar na raiz do executável ou na pasta \lib\');

dac/delphi/DAC.MySQL.Zeos.pas

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ constructor TDAC.Create(aJSON: TJSONObject);
4343
User := aJSON.GetValue('dbuser').Value;
4444
Password := aJSON.GetValue('dbpassword').Value;
4545
Protocol := 'mysql';
46-
LibraryLocation := GetDefaultLibDir;
47-
4846
if aJSON.GetValue('banco') <> nil then
4947
Database := aJSON.GetValue('banco').Value;
48+
LibraryLocation := GetDefaultLibDir;
5049
end;
5150
FQuery := TQuery.Create(nil);
5251
FQuery.Connection := FConnection;
@@ -57,7 +56,7 @@ constructor TDAC.Create(aJSON: TJSONObject);
5756

5857
destructor TDAC.Destroy;
5958
begin
60-
if Assigned(FQuery) then FreeAndNil(FQuery);
59+
if Assigned(FQuery) then FreeAndNil(FQuery);
6160
if Assigned(FConnection) then FreeAndNil(FConnection);
6261
inherited;
6362
end;
@@ -74,20 +73,19 @@ function TDAC.GetDefaultLibDir: string;
7473
Result := '';
7574
DefaultDir := ExtractFileDir(ParamStr(0));
7675
// libmysql.dll, libmariadb or libmysqld.dll
77-
// procurando no diretório do exe primeiro, depois no diretório \lib\
7876

79-
if FileExists(DefaultDir + 'libmysql.dll') then
80-
Result := DefaultDir + 'libmysql.dll'
81-
else if FileExists(DefaultDir + 'libmariadb.dll') then
82-
Result := DefaultDir + 'libmariadb.dll'
83-
else if FileExists(DefaultDir + 'libmysqld.dll') then
84-
Result := DefaultDir + 'libmysqld.dll'
85-
else if FileExists(DefaultDir + '\lib\libmysql.dll') then
77+
if FileExists(DefaultDir + '\lib\libmysql.dll') then
8678
Result := DefaultDir + '\lib\libmysql.dll'
8779
else if FileExists(DefaultDir + '\lib\libmariadb.dll') then
8880
Result := DefaultDir + '\lib\libmariadb.dll'
8981
else if FileExists(DefaultDir + '\lib\libmysqld.dll') then
9082
Result := DefaultDir + '\lib\libmysqld.dll'
83+
else if FileExists(DefaultDir + 'libmysql.dll') then
84+
Result := DefaultDir + 'libmysql.dll'
85+
else if FileExists(DefaultDir + 'libmariadb.dll') then
86+
Result := DefaultDir + 'libmariadb.dll'
87+
else if FileExists(DefaultDir + 'libmysqld.dll') then
88+
Result := DefaultDir + 'libmysqld.dll'
9189
else
9290
raise Exception.Create('libmysql.dll, libmariadb.dll ou libmysqld.dll' +
9391
' precisam estar na raiz do executável ou na pasta \lib\');

dac/delphi/DAC.Postgres.FireDAC.pas

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ interface
1010
FireDAC.Comp.Client, FireDAC.Phys.PG;
1111

1212
type
13+
TConnection = TFDConnection;
14+
TQuery = TFDQuery;
15+
1316
TDAC = class
1417
private
1518
FDriver: TFDPhysPgDriverLink;
16-
FConnection: TFDConnection;
17-
FQuery: TFDQuery;
19+
FConnection: TConnection;
20+
FQuery: TQuery;
1821
function GetDefaultLibDir: string;
1922
public
2023
constructor Create(aJSON: TJSONObject);
2124
destructor Destroy; override;
22-
function getConnection: TFDConnection;
23-
function getQuery: TFDQuery;
25+
function getConnection: TConnection;
26+
function getQuery: TQuery;
2427
function getConnectionStatus: string;
25-
function getDataBases: TFDQuery;
26-
function getTables(aDataBaseName: string): TFDQuery;
2728
end;
2829

2930
implementation
@@ -36,7 +37,7 @@ constructor TDAC.Create(aJSON: TJSONObject);
3637
FDriver.DriverID := 'PG';
3738
FDriver.VendorLib := GetDefaultLibDir;
3839

39-
FConnection := TFDConnection.Create(nil);
40+
FConnection := TConnection.Create(nil);
4041
try
4142
with FConnection do
4243
begin
@@ -53,7 +54,7 @@ constructor TDAC.Create(aJSON: TJSONObject);
5354
if aJSON.GetValue('schema') <> nil then
5455
ExecSQL('SET search_path = ' + aJSON.GetValue('schema').Value);
5556

56-
FQuery := TFDQuery.Create(nil);
57+
FQuery := TQuery.Create(nil);
5758
FQuery.Connection := FConnection;
5859
FQuery.ResourceOptions.SilentMode := true;
5960
end;
@@ -64,13 +65,13 @@ constructor TDAC.Create(aJSON: TJSONObject);
6465

6566
destructor TDAC.Destroy;
6667
begin
67-
if Assigned(FDriver) then FreeAndNil(FDriver);
68-
if Assigned(FQuery) then FreeAndNil(FQuery);
68+
if Assigned(FDriver) then FreeAndNil(FDriver);
69+
if Assigned(FQuery) then FreeAndNil(FQuery);
6970
if Assigned(FConnection) then FreeAndNil(FConnection);
7071
inherited;
7172
end;
7273

73-
function TDAC.getConnection: TFDConnection;
74+
function TDAC.getConnection: TConnection;
7475
begin
7576
Result := FConnection;
7677
end;
@@ -100,11 +101,6 @@ function TDAC.getConnectionStatus: string;
100101
end;
101102
end;
102103

103-
function TDAC.getDataBases: TFDQuery;
104-
begin
105-
106-
end;
107-
108104
function TDAC.GetDefaultLibDir: string;
109105
var
110106
DefaultDir: string;
@@ -114,17 +110,15 @@ function TDAC.GetDefaultLibDir: string;
114110
if FileExists(DefaultDir + '\lib\libpq.dll') then
115111
Result := DefaultDir + '\lib\libpq.dll'
116112
else if FileExists(DefaultDir + 'libpq.dll') then
117-
Result := DefaultDir + 'libpq.dll';
113+
Result := DefaultDir + 'libpq.dll'
114+
else
115+
raise Exception.Create('libpq.dll' +
116+
' precisa estar na raiz do executável ou na pasta \lib\');
118117
end;
119118

120-
function TDAC.getQuery: TFDQuery;
119+
function TDAC.getQuery: TQuery;
121120
begin
122121
Result := FQuery;
123122
end;
124123

125-
function TDAC.getTables(aDataBaseName: string): TFDQuery;
126-
begin
127-
128-
end;
129-
130124
end.

dac/delphi/DAC.Postgres.Zeos.pas

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
interface
77

88
uses
9-
JSON, SysUtils, Classes,
9+
JSON, SysUtils,
1010
ZConnection, ZDataset;
1111

1212
type
@@ -25,8 +25,6 @@ TDAC = class
2525
function getConnection: TConnection;
2626
function getQuery: TQuery;
2727
function getConnectionStatus: string;
28-
function getDataBases: TQuery;
29-
function getTables(aDataBaseName: string): TQuery;
3028
end;
3129

3230
implementation
@@ -38,22 +36,21 @@ constructor TDAC.Create(aJSON: TJSONObject);
3836
FConnection := nil;
3937
FQuery := nil;
4038
FSchema := '';
41-
FConnection := TZConnection.Create(nil);
39+
FConnection := TConnection.Create(nil);
4240
try
4341
with FConnection do
4442
begin
45-
LoginPrompt := false;
43+
LoginPrompt := False;
4644
HostName := aJSON.GetValue('dbserver').Value;
4745
Port := aJSON.GetValue('dbport').Value.ToInteger;
4846
User := aJSON.GetValue('dbuser').Value;
4947
Password := aJSON.GetValue('dbpassword').Value;
5048
Protocol := 'postgresql';
51-
LibraryLocation := GetDefaultLibDir;
52-
5349
if aJSON.GetValue('banco') <> nil then
5450
Database := aJSON.GetValue('banco').Value;
51+
LibraryLocation := GetDefaultLibDir;
5552
end;
56-
FQuery := TZQuery.Create(nil);
53+
FQuery := TQuery.Create(nil);
5754
FQuery.Connection := FConnection;
5855

5956
if aJSON.GetValue('schema') <> nil then
@@ -65,7 +62,7 @@ constructor TDAC.Create(aJSON: TJSONObject);
6562

6663
destructor TDAC.Destroy;
6764
begin
68-
if Assigned(FQuery) then FreeAndNil(FQuery);
65+
if Assigned(FQuery) then FreeAndNil(FQuery);
6966
if Assigned(FConnection) then FreeAndNil(FConnection);
7067
inherited;
7168
end;
@@ -100,12 +97,7 @@ function TDAC.getConnectionStatus: string;
10097
end;
10198
end;
10299

103-
function TDAC.getDataBases: TZQuery;
104-
begin
105-
106-
end;
107-
108-
function TDAC.GetDefaultLibDir(aFileName: string): string;
100+
function TDAC.GetDefaultLibDir: string;
109101
var
110102
DefaultDir: string;
111103
begin
@@ -114,7 +106,10 @@ function TDAC.GetDefaultLibDir(aFileName: string): string;
114106
if FileExists(DefaultDir + '\lib\libpq.dll') then
115107
Result := DefaultDir + '\lib\libpq.dll'
116108
else if FileExists(DefaultDir + 'libpq.dll') then
117-
Result := DefaultDir + 'libpq.dll';
109+
Result := DefaultDir + 'libpq.dll'
110+
else
111+
raise Exception.Create('libpq.dll' +
112+
' precisa estar na raiz do executável ou na pasta \lib\');
118113
end;
119114

120115
function TDAC.getQuery: TQuery;
@@ -124,9 +119,4 @@ function TDAC.getQuery: TQuery;
124119
Result := FQuery;
125120
end;
126121

127-
function TDAC.getTables(aDataBaseName: string): TZQuery;
128-
begin
129-
130-
end;
131-
132122
end.

0 commit comments

Comments
 (0)