-
Notifications
You must be signed in to change notification settings - Fork 0
/
pafTableUSERS_DB.pas
185 lines (159 loc) · 6.21 KB
/
pafTableUSERS_DB.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
174
175
176
177
178
179
180
181
182
183
184
185
unit pafTableUSERS_DB;
interface
uses
gVariables;
function fUSERS_DBGenID:integer;
procedure pUSERS_DBInsertData(varID:integer; varFULLNAME, varPASS:string);
function fUSERS_DBSelectFULLNAMEandID:TArray<Tusers_db>;
function fUSERS_DBGetPASSbyID(varID: integer):string;
implementation
uses
IBX.ib,
IBX.IBQuery,
pafOtherFunction,
System.SysUtils,
pafDatabase
;
const
ModuleName = 'pafTableUSERS_DB';
// ---USERS_DB---
//******************************************************************************
//USERS_DB // ãåíåðàöèÿ ID òàáëèöû USERS_DB
//******************************************************************************
function fUSERS_DBGenID:integer;
begin
result := fSQLGenID('select GEN_ID(GEN_USERS_DB_ID, 1) from RDB$DATABASE '); //âûçûâàåì çàïðîñ íà ãåíåðàöèþ è ïîëó÷åíèå ðåçóëüòàòà
end;
//******************************************************************************
//******************************************************************************
//******************************************************************************
//USERS_DB // Äîáàâëåíèå çàïèñè â òàáëèöó USER_DB
//******************************************************************************
procedure pUSERS_DBInsertData(varID:integer; varFULLNAME, varPASS:string);
var
varIBQuery: TIBQuery;
const
FunctionName = 'pInsert_USERS_DB';
begin
try
pCreateIBQuery(varIBQuery); //èíèöèàëèçèðóåì IBQuery
varIBQuery.Active := false;
varIBQuery.SQL.Clear;
varIBQuery.SQL.Add(
'insert into USERS_DB '
+ '('
+ 'ID, '
+ 'FULLNAME, '
+ 'PASS '
+ ') '
+ 'values ('
+ ':varID, '
+ ':varFULLNAME, '
+ ':varPASS '
+ ')'
);
if varID = 0 then varIBQuery.ParamByName('varID').IsNull else varIBQuery.ParamByName('varID').AsInteger:= varID;
if trim(varFULLNAME)='' then varIBQuery.ParamByName('varFULLNAME').IsNull else varIBQuery.ParamByName('varFULLNAME').asstring:=trim(varFULLNAME);
if trim(varPASS)='' then varIBQuery.ParamByName('varPASS').IsNull else varIBQuery.ParamByName('varPASS').asstring:=trim(varPASS);
varIBQuery.ExecSQL;
gIBTransaction.Commit;
FreeAndNil(varIBQuery);
except
on e:EIBInterBaseError do
begin //âûâîäèì èíôîðìàöèþ
pExceptionEIBInterBaseErrorSQL(e, ModuleName, FunctionName, varIBQuery.SQL.Text); //ãåíåðèðóåì îøèáêó è âûâîäèì äèàëîãîâîå îêíî
end;
end;
end;
//******************************************************************************
//******************************************************************************
//******************************************************************************
//USERS_DB // ïîëó÷àåì ID è FULLNAEM èç òàáëèöû USERS_DB
//******************************************************************************
function fUSERS_DBSelectFULLNAMEandID:TArray<Tusers_db>;
var
varIBQuery: TIBQuery;
i: integer;
r: Tusers_db;
const
FunctionName = 'fUSERS_DBSelectFULLNAMEandID';
begin
try
pCreateIBQuery(varIBQuery); //èíèöèàëèçèðóåì IBQuery
varIBQuery.Active := false;
varIBQuery.SQL.Clear;
varIBQuery.SQL.Add(
'select ID, FULLNAME '
+ 'from '
+ 'USERS_DB '
+ 'where '
+ 'DEL = 0 '
);
varIBQuery.Open;
except //âûçûâàåì èñêëþ÷åíèå ïðè îøèáêè â SQL çàïðîñå
on e:EIBInterBaseError do
begin //âûâîäèì èíôîðìàöèþ
pExceptionEIBInterBaseErrorSQL(e, ModuleName, FunctionName, varIBQuery.SQL.Text); //ãåíåðèðóåì îøèáêó è âûâîäèì äèàëîãîâîå îêíî
end;
end;
try
//ïîìåùàåì ðåçóëüòàò â ìàññèâ TArray //âîçìîæíî äëÿ óñêîðåíèÿ ðàáîòû òðåáóåòñÿ èñïîëüçâîàòü Tlist
Result := nil;
while not varIBQuery.Eof do
begin
r.ID := varIBQuery.FieldByName('ID').AsInteger;
r.FULLNAME := trim(varIBQuery.FieldByName('FULLNAME').AsString);
insert( r ,result, length(result));
varIBQuery.Next;
end;
except
on e:Exception do
begin
pException(e, ModuleName, FunctionName); //ãåíåðèðóåì îøèáêó è âûâîäèì äèàëîãîâîå îêíî
end;
end;
FreeAndNil(varIBQuery);
end;
//******************************************************************************
//******************************************************************************
//******************************************************************************
//USERS_DB // ïîëó÷àåì ïàðîëü ïî ID òàáëèöû USERS_DB
//******************************************************************************
function fUSERS_DBGetPASSbyID(varID: integer):string;
var
varIBQuery: TIBQuery;
const
FunctionName = 'fSelect_PASSWORDbyID_USERS_DB';
begin
try
pCreateIBQuery(varIBQuery); //èíèöèàëèçèðóåì IBQuery
varIBQuery.Active := false;
varIBQuery.SQL.Clear;
varIBQuery.SQL.Add(
'select PASS '
+ 'from '
+ 'USERS_DB '
+ 'where '
+ 'ID = :varID '
);
if varID = 0 then varIBQuery.ParamByName('varID').IsNull else varIBQuery.ParamByName('varID').AsInteger:= varID;
varIBQuery.Open;
except //âûçûâàåì èñêëþ÷åíèå ïðè îøèáêè â SQL çàïðîñå
on e:EIBInterBaseError do
begin //âûâîäèì èíôîðìàöèþ
pExceptionEIBInterBaseErrorSQL(e, ModuleName, FunctionName, varIBQuery.SQL.Text); //ãåíåðèðóåì îøèáêó è âûâîäèì äèàëîãîâîå îêíî
end;
end;
try
result := trim(varIBQuery.FieldByName('PASS').AsString); //ïîëó÷àåì ñòðîêó ñ ïàðîëåì
except
on e:Exception do
begin
pException(e, ModuleName, FunctionName); //ãåíåðèðóåì îøèáêó è âûâîäèì äèàëîãîâîå îêíî
end;
end;
FreeAndNil(varIBQuery);
end;
//******************************************************************************
//******************************************************************************
end.