-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDataLankProtocol.pas
173 lines (138 loc) · 3.7 KB
/
DataLankProtocol.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
unit DataLankProtocol;
{
DataLankProtocol only serves as a guide to describe what the interface
to the TDataConnection and TQueryResult object should be.
Don't include it in a project (unless you need a quick-fix to determine
if a project has correct syntax.)
Don't override from TDataConnection or TQueryResult.
Create a DataLank.pas unit with code like this to patch through to an
implementation of your selection.
unit DataLink;
interface
uses SomeDBTools;
type
TDataConnection = TSomeDBConnection;
TQueryResult = TSomeDBCommand;
implementations
end.
See
https://github.com/stijnsanders/DataLank
for a list of implementations.
}
interface
type
TDataConnection=class(TObject)
public
constructor Create(const ConnectionInfo: WideString);
destructor Destroy override;
function Execute(const SQL: WideString;
const Values: array of Variant): integer;
function Insert(const TableName: WideString; const Values: array of Variant;
const PKFieldName: WideString=''): int64;
procedure Update(const TableName: WideString; const Values:array of Variant);
procedure BeginTrans;
procedure CommitTrans;
procedure RollbackTrans;
end;
TQueryResult=class(TObject)
private
FFirstLoad:boolean;
function GetValue(const Idx:Variant):Variant;
function IsEof:boolean;
public
constructor Create(Connection: TDataConnection; const SQL: WideString;
const Values: array of Variant);
destructor Destroy; override;
function Read:boolean;
property Fields[Idx:Variant]:Variant read GetValue; default;
property EOF: boolean read IsEof;
function GetInt(const Idx:Variant):integer;
function GetStr(const Idx:Variant):WideString;
function GetDate(const Idx:Variant):TDateTime;
function IsNull(const Idx:Variant):boolean;
end;
implementation
{ TDataConnection }
constructor TDataConnection.Create(const ConnectionInfo: WideString);
begin
inherited Create;
//create connection data
//open connection
end;
destructor TDataConnection.Destroy;
begin
//close connection
//free connection data
inherited;
end;
function TDataConnection.Insert(const TableName: WideString;
const Values: array of Variant): integer;
begin
//insert record
//catch primary key and/or auto-number
end;
function TDataConnection.Execute(const SQL: WideString;
const Values: array of Variant): integer;
begin
//prepare command and parameters
//execute SQL
end;
procedure TDataConnection.BeginTrans;
begin
Execute('BEGIN TRANSACTION',[]);
end;
procedure TDataConnection.CommitTrans;
begin
Execute('COMMIT TRANSACTION',[]);
end;
procedure TDataConnection.RollbackTrans;
begin
Execute('ROLLBACK TRANSACTION',[]);
end;
{ TQueryResult }
constructor TQueryResult.Create(Connection: TDataConnection;
const SQL: WideString; const Values: array of Variant);
begin
inherited Create;
//prepare command, set parameter values
//execute and prepare result set
FFirstRead:=true;
end;
destructor TQueryResult.Destroy;
begin
//clean-up result set data
inherited;
end;
function TQueryResult.GetValue(const Idx: Variant): Variant;
begin
//Result:=
end;
function TQueryResult.GetInt(const Idx: Variant): integer;
begin
//Result:=
end;
function TQueryResult.GetStr(const Idx: Variant): WideString;
begin
//Result:=
end;
function TQueryResult.GetDate(const Idx: Variant): TDateTime;
begin
//Result:=VarToDateTime(
end;
function TQueryResult.IsNull(const Idx: Variant): boolean;
begin
//Result:=VarIsNull(
end;
function TQueryResult.IsEof: boolean;
begin
//Result:=
end;
function TQueryResult.Read: boolean;
begin
if EOF then Result:=false else
begin
if FFirstRead then FFirstRead:=false else ;//Next;
Result:=not(EOF);
end;
end;
end.