Skip to content

Commit 4dc3ddb

Browse files
committed
Alterado suporte para mysql e returning
1 parent 8c6d102 commit 4dc3ddb

File tree

6 files changed

+319
-429
lines changed

6 files changed

+319
-429
lines changed

GenericQuery.dproj

Lines changed: 274 additions & 425 deletions
Large diffs are not rendered by default.

GenericQuery.identcache

55 Bytes
Binary file not shown.

GenericQuery.res

0 Bytes
Binary file not shown.

src/core/Connection/GenericQuery.Model.Connection.pas

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ interface
2727
FireDAC.Comp.UI;
2828

2929
type
30-
TTypeConnection = (FireBird, SQLite, Ora);
30+
TTypeConnection = (FireBird, SQLite, Ora, MySQL);
3131

3232
var
3333
FConnList : TObjectList<TFDConnection>;
3434
FServer : String;
3535
FDatabase : String;
3636
FPassword : String;
3737
FUsername : String;
38+
FPort : String;
3839
FTypeConnection : TTypeConnection;
3940

4041
function Connected : Integer;
@@ -67,7 +68,8 @@ function Connected : Integer;
6768
raise Exception.Create('variable FServer must be informed!');
6869

6970
if FUsername = '' then FUsername := 'sysdba';
70-
if FPassword = '' then FPassword := 'masterkey';
71+
if FPassword = '' then FPassword := 'masterkey';
72+
if FPort = '' then FPort := '3050';
7173

7274
FConnList.Items[IndexConn].Params.DriverID := 'FB';
7375
FConnList.Items[IndexConn].Params.UserName := FUsername;
@@ -94,6 +96,27 @@ function Connected : Integer;
9496
FConnList.Items[IndexConn].Params.Database := FServer+'/'+FDatabase;
9597
FConnList.Items[IndexConn].Params.Add('CharacterSet=UTF8');
9698
end;
99+
100+
MySQL :
101+
begin
102+
if FServer = '' then
103+
raise Exception.Create('variable FServer must be informed!');
104+
105+
if FUsername = '' then
106+
raise Exception.Create('variable FUsername must be informed!');
107+
108+
if FPassword = '' then
109+
raise Exception.Create('variable FPassword must be informed!');
110+
111+
if FPort = '' then FPort := '3306';
112+
113+
FConnList.Items[IndexConn].Params.DriverID := 'MySQL';
114+
FConnList.Items[IndexConn].Params.UserName := FUserName;
115+
FConnList.Items[IndexConn].Params.Password := FPassword;
116+
FConnList.Items[IndexConn].Params.Add('Database='+FDatabase);
117+
FConnList.Items[IndexConn].Params.Add('Server='+FServer);
118+
FConnList.Items[IndexConn].Params.Add('Port='+FPort);
119+
end;
97120
end;
98121

99122
FConnList.Items[IndexConn].Connected;

src/core/GenericQuery/GenericQuery.pas

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ TGenericQuery = class(TInterfacedObject, iGenericQuery)
2929
function SQL(vSQL : String) : iGenericQuery;
3030
function Params(aValue : Variant) : iGenericQuery; overload;
3131
function Params(aParamName : String; aValue : Variant) : iGenericQuery; overload;
32-
function Execute : Boolean;
32+
function Execute : Boolean; overload;
33+
function Execute(var aValueReturn : Variant) : Boolean; overload;
3334
function OpenArray : TJSONArray;
3435
function OpenObject : TJSONObject;
3536
function RecordCount : Integer;
@@ -61,6 +62,22 @@ destructor TGenericQuery.Destroy;
6162
inherited;
6263
end;
6364

65+
function TGenericQuery.Execute(var aValueReturn: Variant): Boolean;
66+
begin
67+
if FSQL.Text = '' then
68+
raise Exception.Create('SQL não informado!');
69+
70+
try
71+
FQuery.Open;
72+
73+
aValueReturn := FQuery.Fields[0].Value;
74+
75+
Result := True;
76+
except
77+
Result := False;
78+
end;
79+
end;
80+
6481
function TGenericQuery.Execute: Boolean;
6582
begin
6683
if FSQL.Text = '' then

src/interfaces/Model.GenericQuery.Intf.pas

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ interface
88
type
99
iGenericQuery = interface
1010
['{D7C2F73C-5199-4890-A261-B2F2F16D35B9}']
11-
function Execute : Boolean;
11+
function Execute : Boolean; overload;
12+
function Execute(var aValueReturn : Variant) : Boolean; overload;
1213
function OpenArray : TJSONArray;
1314
function OpenObject : TJSONObject;
1415
function RecordCount : Integer;

0 commit comments

Comments
 (0)