forked from academiadocodigo/SimpleORM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleQueryRestDW.pas
95 lines (79 loc) · 2.04 KB
/
SimpleQueryRestDW.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
unit SimpleQueryRestDW;
interface
uses
SimpleInterface, System.Classes, Data.DB, uDWConstsData, uRESTDWPoolerDB;
Type
TSimpleQueryRestDW<T : class, constructor> = class(TInterfacedObject, iSimpleQuery)
private
FConnection : TRESTDWDataBase;
FQuery : TRESTDWClientSQL;
public
constructor Create(aConnection : TRESTDWDataBase);
destructor Destroy; override;
class function New(aConnection : TRESTDWDataBase) : iSimpleQuery;
function SQL : TStrings;
function Params : TParams;
function ExecSQL : iSimpleQuery;
function DataSet : TDataSet;
function Open(aSQL : String) : iSimpleQuery; overload;
function Open : iSimpleQuery; overload;
end;
implementation
uses
System.SysUtils, SimpleRTTI;
{ TSimpleQuery<T> }
constructor TSimpleQueryRestDW<T>.Create(aConnection : TRESTDWDataBase);
var
aTable : String;
begin
FConnection := aConnection;
FQuery := TRESTDWClientSQL.Create(nil);
FQuery.DataBase := FConnection;
TSimpleRTTI<T>.New(nil).ClassName(aTable);
FQuery.AutoCommitData := False;
FQuery.AutoRefreshAfterCommit := True;
//FQuery.SetInBlockEvents(false);
FQuery.UpdateTableName := aTable;
end;
function TSimpleQueryRestDW<T>.DataSet: TDataSet;
begin
Result := FQuery;
end;
destructor TSimpleQueryRestDW<T>.Destroy;
begin
FreeAndNil(FQuery);
inherited;
end;
function TSimpleQueryRestDW<T>.ExecSQL: iSimpleQuery;
var
aErro : String;
begin
Result := Self;
FQuery.ExecSQL(aErro);
FQuery.ApplyUpdates(aErro);
end;
class function TSimpleQueryRestDW<T>.New(aConnection : TRESTDWDataBase): iSimpleQuery;
begin
Result := Self.Create(aConnection);
end;
function TSimpleQueryRestDW<T>.Open: iSimpleQuery;
begin
Result := Self;
FQuery.Close;
FQuery.Open;
end;
function TSimpleQueryRestDW<T>.Open(aSQL: String): iSimpleQuery;
begin
FQuery.Close;
Result := Self;
FQuery.Open(aSQL);
end;
function TSimpleQueryRestDW<T>.Params: TParams;
begin
Result := FQuery.Params;
end;
function TSimpleQueryRestDW<T>.SQL: TStrings;
begin
Result := FQuery.SQL;
end;
end.