BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
ElogStatus.cxx
Go to the documentation of this file.
1
// ----------------------------------------------------------------------
2
// ElogStatus cxx file
3
// Generated 13-04-2026
4
// ----------------------------------------------------------------------
5
6
#include "
ElogStatus.h
"
7
8
#include "
TSQLServer.h
"
9
#include "
TSQLStatement.h
"
10
11
#include <iostream>
12
using namespace
std
;
13
14
/* GENERATED CLASS MEMBERS (SHOULD NOT BE CHANGED MANUALLY) */
15
// ----- Constructor with database connection -----------------------
16
ElogStatus::ElogStatus
(
ElogConnection
* db_connect,
int
status_id,
TString
status_text)
17
{
18
connectionDB
= db_connect;
19
20
i_status_id
= status_id;
21
str_status_text
= status_text;
22
}
23
24
// ----- Destructor -------------------------------------------------
25
ElogStatus::~ElogStatus
()
26
{
27
if
(
connectionDB
)
28
delete
connectionDB
;
29
}
30
31
// ----- Creating new status in the database ---------------------------
32
ElogStatus
*
ElogStatus::CreateStatus
(
TString
status_text)
33
{
34
ElogConnection
* connDb =
ElogConnection::Open
();
35
if
(connDb ==
nullptr
)
36
return
nullptr
;
37
38
TSQLServer
* db_server = connDb->
GetSQLServer
();
39
40
TString
sql =
TString::Format
(
"insert into status_(status_text) "
41
"values ($1)"
);
42
TSQLStatement
* stmt = db_server->
Statement
(sql);
43
44
stmt->
NextIteration
();
45
stmt->
SetString
(0, status_text);
46
47
// inserting new status to the Database
48
if
(!stmt->
Process
()) {
49
cout <<
"ERROR: inserting new status to the Database has been failed"
<< endl;
50
delete
stmt;
51
delete
connDb;
52
return
nullptr
;
53
}
54
55
delete
stmt;
56
57
// getting last inserted ID
58
int
status_id;
59
TSQLStatement
* stmt_last = db_server->
Statement
(
"SELECT currval(pg_get_serial_sequence('status_','status_id'))"
);
60
61
// process getting last id
62
if
(stmt_last->
Process
()) {
63
// store result of statement in buffer
64
stmt_last->
StoreResult
();
65
66
// if there is no last id then exit with error
67
if
(!stmt_last->
NextResultRow
()) {
68
cout <<
"ERROR: no last ID in DB!"
<< endl;
69
delete
stmt_last;
70
return
nullptr
;
71
}
else
{
72
status_id = stmt_last->
GetInt
(0);
73
delete
stmt_last;
74
}
75
}
else
{
76
cout <<
"ERROR: getting last ID has been failed!"
<< endl;
77
delete
stmt_last;
78
return
nullptr
;
79
}
80
81
int
tmp_status_id;
82
tmp_status_id = status_id;
83
TString
tmp_status_text;
84
tmp_status_text = status_text;
85
86
return
new
ElogStatus
(connDb, tmp_status_id, tmp_status_text);
87
}
88
89
// ----- Get status from the database ---------------------------
90
ElogStatus
*
ElogStatus::GetStatus
(
int
status_id)
91
{
92
ElogConnection
* connDb =
ElogConnection::Open
();
93
if
(connDb ==
nullptr
)
94
return
nullptr
;
95
96
TSQLServer
* db_server = connDb->
GetSQLServer
();
97
98
TString
sql =
TString::Format
(
"select status_id, status_text "
99
"from status_ "
100
"where status_id = %d"
,
101
status_id);
102
TSQLStatement
* stmt = db_server->
Statement
(sql);
103
104
// get status from the database
105
if
(!stmt->
Process
()) {
106
cout <<
"ERROR: getting status from the database has been failed"
<< endl;
107
108
delete
stmt;
109
delete
connDb;
110
return
nullptr
;
111
}
112
113
// store result of statement in buffer
114
stmt->
StoreResult
();
115
116
// extract row
117
if
(!stmt->
NextResultRow
()) {
118
cout <<
"ERROR: status was not found in the database"
<< endl;
119
120
delete
stmt;
121
delete
connDb;
122
return
nullptr
;
123
}
124
125
int
tmp_status_id;
126
tmp_status_id = stmt->
GetInt
(0);
127
TString
tmp_status_text;
128
tmp_status_text = stmt->
GetString
(1);
129
130
delete
stmt;
131
132
return
new
ElogStatus
(connDb, tmp_status_id, tmp_status_text);
133
}
134
135
// ----- Get status from the database by unique key --------------
136
ElogStatus
*
ElogStatus::GetStatus
(
TString
status_text)
137
{
138
ElogConnection
* connDb =
ElogConnection::Open
();
139
if
(connDb ==
nullptr
)
140
return
nullptr
;
141
142
TSQLServer
* db_server = connDb->
GetSQLServer
();
143
144
TString
sql =
TString::Format
(
"select status_id, status_text "
145
"from status_ "
146
"where lower(status_text) = lower('%s')"
,
147
status_text.
Data
());
148
TSQLStatement
* stmt = db_server->
Statement
(sql);
149
150
// get status from the database
151
if
(!stmt->
Process
()) {
152
cout <<
"ERROR: getting status from the database has been failed"
<< endl;
153
154
delete
stmt;
155
delete
connDb;
156
return
nullptr
;
157
}
158
159
// store result of statement in buffer
160
stmt->
StoreResult
();
161
162
// extract row
163
if
(!stmt->
NextResultRow
()) {
164
cout <<
"ERROR: status was not found in the database"
<< endl;
165
166
delete
stmt;
167
delete
connDb;
168
return
nullptr
;
169
}
170
171
int
tmp_status_id;
172
tmp_status_id = stmt->
GetInt
(0);
173
TString
tmp_status_text;
174
tmp_status_text = stmt->
GetString
(1);
175
176
delete
stmt;
177
178
return
new
ElogStatus
(connDb, tmp_status_id, tmp_status_text);
179
}
180
181
// ----- Check status exists in the database ---------------------------
182
int
ElogStatus::CheckStatusExists
(
int
status_id)
183
{
184
ElogConnection
* connDb =
ElogConnection::Open
();
185
if
(connDb ==
nullptr
)
186
return
-1;
187
188
TSQLServer
* db_server = connDb->
GetSQLServer
();
189
190
TString
sql =
TString::Format
(
"select 1 "
191
"from status_ "
192
"where status_id = %d"
,
193
status_id);
194
TSQLStatement
* stmt = db_server->
Statement
(sql);
195
196
// get status from the database
197
if
(!stmt->
Process
()) {
198
cout <<
"ERROR: getting status from the database has been failed"
<< endl;
199
200
delete
stmt;
201
delete
connDb;
202
return
-2;
203
}
204
205
// store result of statement in buffer
206
stmt->
StoreResult
();
207
208
// extract row
209
if
(!stmt->
NextResultRow
()) {
210
delete
stmt;
211
delete
connDb;
212
return
0;
213
}
214
215
delete
stmt;
216
delete
connDb;
217
218
return
1;
219
}
220
221
// ----- Check status exists in the database by unique key --------------
222
int
ElogStatus::CheckStatusExists
(
TString
status_text)
223
{
224
ElogConnection
* connDb =
ElogConnection::Open
();
225
if
(connDb ==
nullptr
)
226
return
-1;
227
228
TSQLServer
* db_server = connDb->
GetSQLServer
();
229
230
TString
sql =
TString::Format
(
"select 1 "
231
"from status_ "
232
"where lower(status_text) = lower('%s')"
,
233
status_text.
Data
());
234
TSQLStatement
* stmt = db_server->
Statement
(sql);
235
236
// get status from the database
237
if
(!stmt->
Process
()) {
238
cout <<
"ERROR: getting status from the database has been failed"
<< endl;
239
240
delete
stmt;
241
delete
connDb;
242
return
-2;
243
}
244
245
// store result of statement in buffer
246
stmt->
StoreResult
();
247
248
// extract row
249
if
(!stmt->
NextResultRow
()) {
250
delete
stmt;
251
delete
connDb;
252
return
0;
253
}
254
255
delete
stmt;
256
delete
connDb;
257
258
return
1;
259
}
260
261
// ----- Delete status from the database ---------------------------
262
int
ElogStatus::DeleteStatus
(
int
status_id)
263
{
264
ElogConnection
* connDb =
ElogConnection::Open
();
265
if
(connDb ==
nullptr
)
266
return
-1;
267
268
TSQLServer
* db_server = connDb->
GetSQLServer
();
269
270
TString
sql =
TString::Format
(
"delete from status_ "
271
"where status_id = $1"
);
272
TSQLStatement
* stmt = db_server->
Statement
(sql);
273
274
stmt->
NextIteration
();
275
stmt->
SetInt
(0, status_id);
276
277
// delete status from the dataBase
278
if
(!stmt->
Process
()) {
279
cout <<
"ERROR: deleting status from the dataBase has been failed"
<< endl;
280
281
delete
stmt;
282
delete
connDb;
283
return
-2;
284
}
285
286
delete
stmt;
287
delete
connDb;
288
return
0;
289
}
290
291
// ----- Delete status from the database by unique key --------------
292
int
ElogStatus::DeleteStatus
(
TString
status_text)
293
{
294
ElogConnection
* connDb =
ElogConnection::Open
();
295
if
(connDb ==
nullptr
)
296
return
-1;
297
298
TSQLServer
* db_server = connDb->
GetSQLServer
();
299
300
TString
sql =
TString::Format
(
"delete from status_ "
301
"where lower(status_text) = lower($1)"
);
302
TSQLStatement
* stmt = db_server->
Statement
(sql);
303
304
stmt->
NextIteration
();
305
stmt->
SetString
(0, status_text);
306
307
// delete status from the dataBase
308
if
(!stmt->
Process
()) {
309
cout <<
"ERROR: deleting status from the DataBase has been failed"
<< endl;
310
311
delete
stmt;
312
delete
connDb;
313
return
-2;
314
}
315
316
delete
stmt;
317
delete
connDb;
318
return
0;
319
}
320
321
// ----- Print all 'statuss' ---------------------------------
322
int
ElogStatus::PrintAll
()
323
{
324
ElogConnection
* connDb =
ElogConnection::Open
();
325
if
(connDb ==
nullptr
)
326
return
-1;
327
328
TSQLServer
* db_server = connDb->
GetSQLServer
();
329
330
TString
sql =
TString::Format
(
"select status_id, status_text "
331
"from status_"
);
332
TSQLStatement
* stmt = db_server->
Statement
(sql);
333
334
// get all 'statuss' from the database
335
if
(!stmt->
Process
()) {
336
cout <<
"ERROR: getting all 'statuss' from the dataBase has been failed"
<< endl;
337
338
delete
stmt;
339
delete
connDb;
340
return
-2;
341
}
342
343
// store result of statement in buffer
344
stmt->
StoreResult
();
345
346
// print rows
347
cout <<
"Table 'status_':"
<< endl;
348
while
(stmt->
NextResultRow
()) {
349
cout <<
"status_id: "
;
350
cout << (stmt->
GetInt
(0));
351
cout <<
", status_text: "
;
352
cout << (stmt->
GetString
(1));
353
cout <<
"."
<< endl;
354
}
355
356
delete
stmt;
357
delete
connDb;
358
359
return
0;
360
}
361
362
// Setters functions
363
int
ElogStatus::SetStatusText
(
TString
status_text)
364
{
365
if
(!
connectionDB
) {
366
cout <<
"CRITICAL ERROR: Connection object is null"
<< endl;
367
return
-1;
368
}
369
370
TSQLServer
* db_server =
connectionDB
->GetSQLServer();
371
372
TString
sql =
TString::Format
(
"update status_ "
373
"set status_text = $1 "
374
"where status_id = $2"
);
375
TSQLStatement
* stmt = db_server->
Statement
(sql);
376
377
stmt->
NextIteration
();
378
stmt->
SetString
(0, status_text);
379
stmt->
SetInt
(1,
i_status_id
);
380
381
// write new value to the database
382
if
(!stmt->
Process
()) {
383
cout <<
"ERROR: updating information about status has been failed"
<< endl;
384
385
delete
stmt;
386
return
-2;
387
}
388
389
str_status_text
= status_text;
390
391
delete
stmt;
392
return
0;
393
}
394
395
// ----- Print current status ---------------------------------------
396
void
ElogStatus::Print
()
397
{
398
cout <<
"Table 'status_'"
;
399
cout <<
". status_id: "
<<
i_status_id
<<
". status_text: "
<<
str_status_text
<< endl;
400
401
return
;
402
}
403
/* END OF GENERATED CLASS PART (SHOULD NOT BE CHANGED MANUALLY) */
ElogStatus.h
TSQLServer.h
TSQLStatement.h
ElogConnection
Definition
ElogConnection.h:27
ElogConnection::Open
static ElogConnection * Open()
Definition
ElogConnection.cxx:55
ElogConnection::GetSQLServer
TSQLServer * GetSQLServer()
Definition
ElogConnection.h:43
ElogStatus::CheckStatusExists
static int CheckStatusExists(int status_id)
check status exists in the database: 1- true, 0 - false, <0 - database operation error
Definition
ElogStatus.cxx:182
ElogStatus::connectionDB
ElogConnection * connectionDB
connection to the database
Definition
ElogStatus.h:23
ElogStatus::i_status_id
int i_status_id
status id
Definition
ElogStatus.h:26
ElogStatus::str_status_text
TString str_status_text
status text
Definition
ElogStatus.h:28
ElogStatus::~ElogStatus
virtual ~ElogStatus()
Definition
ElogStatus.cxx:25
ElogStatus::Print
void Print()
print information about current status
Definition
ElogStatus.cxx:396
ElogStatus::DeleteStatus
static int DeleteStatus(int status_id)
delete status from the database
Definition
ElogStatus.cxx:262
ElogStatus::PrintAll
static int PrintAll()
print all statuss
Definition
ElogStatus.cxx:322
ElogStatus::ElogStatus
ElogStatus(ElogConnection *db_connect, int status_id, TString status_text)
Definition
ElogStatus.cxx:16
ElogStatus::CreateStatus
static ElogStatus * CreateStatus(TString status_text)
add new status to the database
Definition
ElogStatus.cxx:32
ElogStatus::SetStatusText
int SetStatusText(TString status_text)
set status text of the current status
Definition
ElogStatus.cxx:363
ElogStatus::GetStatus
static ElogStatus * GetStatus(int status_id)
get status from the database
Definition
ElogStatus.cxx:90
TSQLServer
TSQLServer::Statement
virtual TSQLStatement * Statement(const char *, Int_t=100)
TSQLStatement
TSQLStatement::GetString
virtual const char * GetString(Int_t)
TSQLStatement::NextIteration
virtual Bool_t NextIteration()=0
TSQLStatement::NextResultRow
virtual Bool_t NextResultRow()=0
TSQLStatement::SetString
virtual Bool_t SetString(Int_t, const char *, Int_t=256)
TSQLStatement::GetInt
virtual Int_t GetInt(Int_t)
TSQLStatement::Process
virtual Bool_t Process()=0
TSQLStatement::SetInt
virtual Bool_t SetInt(Int_t, Int_t)
TSQLStatement::StoreResult
virtual Bool_t StoreResult()=0
TString
TString::Data
const char * Data() const
TString::Format
static TString Format(const char *fmt,...)
std
Definition
json.hpp:4446
database
elog_db
ElogStatus.cxx
Generated on
for BmnRoot by
1.17.0