BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
UniParameterType.cxx
Go to the documentation of this file.
1
// ----------------------------------------------------------------------
2
// UniParameterType cxx file
3
// Generated 05-06-2023
4
// ----------------------------------------------------------------------
5
6
#include "
UniParameterType.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
UniParameterType::UniParameterType
(
UniConnection
* db_connect,
int
type_id,
TString
type_name)
17
{
18
connectionDB
= db_connect;
19
20
i_type_id
= type_id;
21
str_type_name
= type_name;
22
}
23
24
// ----- Destructor -------------------------------------------------
25
UniParameterType::~UniParameterType
()
26
{
27
if
(
connectionDB
)
28
delete
connectionDB
;
29
}
30
31
// ----- Creating new parameter type in the database ---------------------------
32
UniParameterType
*
UniParameterType::CreateParameterType
(
TString
type_name)
33
{
34
UniConnection
* connDb =
UniConnection::Open
();
35
if
(connDb ==
nullptr
)
36
return
nullptr
;
37
38
TSQLServer
* db_server = connDb->
GetSQLServer
();
39
40
TString
sql =
TString::Format
(
"insert into parameter_type(type_name) "
41
"values ($1)"
);
42
TSQLStatement
* stmt = db_server->
Statement
(sql);
43
44
stmt->
NextIteration
();
45
stmt->
SetString
(0, type_name);
46
47
// inserting new parameter type to the Database
48
if
(!stmt->
Process
()) {
49
cout <<
"ERROR: inserting new parameter type 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
type_id;
59
TSQLStatement
* stmt_last =
60
db_server->
Statement
(
"SELECT currval(pg_get_serial_sequence('parameter_type','type_id'))"
);
61
62
// process getting last id
63
if
(stmt_last->
Process
()) {
64
// store result of statement in buffer
65
stmt_last->
StoreResult
();
66
67
// if there is no last id then exit with error
68
if
(!stmt_last->
NextResultRow
()) {
69
cout <<
"ERROR: no last ID in DB!"
<< endl;
70
delete
stmt_last;
71
return
nullptr
;
72
}
else
{
73
type_id = stmt_last->
GetInt
(0);
74
delete
stmt_last;
75
}
76
}
else
{
77
cout <<
"ERROR: getting last ID has been failed!"
<< endl;
78
delete
stmt_last;
79
return
nullptr
;
80
}
81
82
int
tmp_type_id;
83
tmp_type_id = type_id;
84
TString
tmp_type_name;
85
tmp_type_name = type_name;
86
87
return
new
UniParameterType
(connDb, tmp_type_id, tmp_type_name);
88
}
89
90
// ----- Get parameter type from the database ---------------------------
91
UniParameterType
*
UniParameterType::GetParameterType
(
int
type_id)
92
{
93
UniConnection
* connDb =
UniConnection::Open
();
94
if
(connDb ==
nullptr
)
95
return
nullptr
;
96
97
TSQLServer
* db_server = connDb->
GetSQLServer
();
98
99
TString
sql =
TString::Format
(
"select type_id, type_name "
100
"from parameter_type "
101
"where type_id = %d"
,
102
type_id);
103
TSQLStatement
* stmt = db_server->
Statement
(sql);
104
105
// get parameter type from the database
106
if
(!stmt->
Process
()) {
107
cout <<
"ERROR: getting parameter type from the database has been failed"
<< endl;
108
109
delete
stmt;
110
delete
connDb;
111
return
nullptr
;
112
}
113
114
// store result of statement in buffer
115
stmt->
StoreResult
();
116
117
// extract row
118
if
(!stmt->
NextResultRow
()) {
119
cout <<
"ERROR: parameter type was not found in the database"
<< endl;
120
121
delete
stmt;
122
delete
connDb;
123
return
nullptr
;
124
}
125
126
int
tmp_type_id;
127
tmp_type_id = stmt->
GetInt
(0);
128
TString
tmp_type_name;
129
tmp_type_name = stmt->
GetString
(1);
130
131
delete
stmt;
132
133
return
new
UniParameterType
(connDb, tmp_type_id, tmp_type_name);
134
}
135
136
// ----- Check parameter type exists in the database ---------------------------
137
int
UniParameterType::CheckParameterTypeExists
(
int
type_id)
138
{
139
UniConnection
* connDb =
UniConnection::Open
();
140
if
(connDb ==
nullptr
)
141
return
-1;
142
143
TSQLServer
* db_server = connDb->
GetSQLServer
();
144
145
TString
sql =
TString::Format
(
"select 1 "
146
"from parameter_type "
147
"where type_id = %d"
,
148
type_id);
149
TSQLStatement
* stmt = db_server->
Statement
(sql);
150
151
// get parameter type from the database
152
if
(!stmt->
Process
()) {
153
cout <<
"ERROR: getting parameter type from the database has been failed"
<< endl;
154
155
delete
stmt;
156
delete
connDb;
157
return
-2;
158
}
159
160
// store result of statement in buffer
161
stmt->
StoreResult
();
162
163
// extract row
164
if
(!stmt->
NextResultRow
()) {
165
delete
stmt;
166
delete
connDb;
167
return
0;
168
}
169
170
delete
stmt;
171
delete
connDb;
172
173
return
1;
174
}
175
176
// ----- Delete parameter type from the database ---------------------------
177
int
UniParameterType::DeleteParameterType
(
int
type_id)
178
{
179
UniConnection
* connDb =
UniConnection::Open
();
180
if
(connDb ==
nullptr
)
181
return
-1;
182
183
TSQLServer
* db_server = connDb->
GetSQLServer
();
184
185
TString
sql =
TString::Format
(
"delete from parameter_type "
186
"where type_id = $1"
);
187
TSQLStatement
* stmt = db_server->
Statement
(sql);
188
189
stmt->
NextIteration
();
190
stmt->
SetInt
(0, type_id);
191
192
// delete parameter type from the dataBase
193
if
(!stmt->
Process
()) {
194
cout <<
"ERROR: deleting parameter type from the dataBase has been failed"
<< endl;
195
196
delete
stmt;
197
delete
connDb;
198
return
-2;
199
}
200
201
delete
stmt;
202
delete
connDb;
203
return
0;
204
}
205
206
// ----- Print all 'parameter types' ---------------------------------
207
int
UniParameterType::PrintAll
()
208
{
209
UniConnection
* connDb =
UniConnection::Open
();
210
if
(connDb ==
nullptr
)
211
return
-1;
212
213
TSQLServer
* db_server = connDb->
GetSQLServer
();
214
215
TString
sql =
TString::Format
(
"select type_id, type_name "
216
"from parameter_type"
);
217
TSQLStatement
* stmt = db_server->
Statement
(sql);
218
219
// get all 'parameter types' from the database
220
if
(!stmt->
Process
()) {
221
cout <<
"ERROR: getting all 'parameter types' from the dataBase has been failed"
<< endl;
222
223
delete
stmt;
224
delete
connDb;
225
return
-2;
226
}
227
228
// store result of statement in buffer
229
stmt->
StoreResult
();
230
231
// print rows
232
cout <<
"Table 'parameter_type':"
<< endl;
233
while
(stmt->
NextResultRow
()) {
234
cout <<
"type_id: "
;
235
cout << (stmt->
GetInt
(0));
236
cout <<
", type_name: "
;
237
cout << (stmt->
GetString
(1));
238
cout <<
"."
<< endl;
239
}
240
241
delete
stmt;
242
delete
connDb;
243
244
return
0;
245
}
246
247
// Setters functions
248
int
UniParameterType::SetTypeName
(
TString
type_name)
249
{
250
if
(!
connectionDB
) {
251
cout <<
"CRITICAL ERROR: Connection object is null"
<< endl;
252
return
-1;
253
}
254
255
TSQLServer
* db_server =
connectionDB
->GetSQLServer();
256
257
TString
sql =
TString::Format
(
"update parameter_type "
258
"set type_name = $1 "
259
"where type_id = $2"
);
260
TSQLStatement
* stmt = db_server->
Statement
(sql);
261
262
stmt->
NextIteration
();
263
stmt->
SetString
(0, type_name);
264
stmt->
SetInt
(1,
i_type_id
);
265
266
// write new value to the database
267
if
(!stmt->
Process
()) {
268
cout <<
"ERROR: updating information about parameter type has been failed"
<< endl;
269
270
delete
stmt;
271
return
-2;
272
}
273
274
str_type_name
= type_name;
275
276
delete
stmt;
277
return
0;
278
}
279
280
// ----- Print current parameter type ---------------------------------------
281
void
UniParameterType::Print
()
282
{
283
cout <<
"Table 'parameter_type'"
;
284
cout <<
". type_id: "
<<
i_type_id
<<
". type_name: "
<<
str_type_name
<< endl;
285
286
return
;
287
}
288
/* END OF GENERATED CLASS PART (SHOULD NOT BE CHANGED MANUALLY) */
TSQLServer.h
TSQLStatement.h
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::Format
static TString Format(const char *fmt,...)
UniConnection
Definition
UniConnection.h:27
UniConnection::Open
static UniConnection * Open()
Definition
UniConnection.cxx:56
UniConnection::GetSQLServer
TSQLServer * GetSQLServer()
Definition
UniConnection.h:43
UniParameterType::connectionDB
UniConnection * connectionDB
connection to the database
Definition
UniParameterType.h:23
UniParameterType::GetParameterType
static UniParameterType * GetParameterType(int type_id)
get parameter type from the database
Definition
UniParameterType.cxx:91
UniParameterType::DeleteParameterType
static int DeleteParameterType(int type_id)
delete parameter type from the database
Definition
UniParameterType.cxx:177
UniParameterType::i_type_id
int i_type_id
type id
Definition
UniParameterType.h:26
UniParameterType::~UniParameterType
virtual ~UniParameterType()
Definition
UniParameterType.cxx:25
UniParameterType::str_type_name
TString str_type_name
type name
Definition
UniParameterType.h:28
UniParameterType::SetTypeName
int SetTypeName(TString type_name)
set type name of the current parameter type
Definition
UniParameterType.cxx:248
UniParameterType::CreateParameterType
static UniParameterType * CreateParameterType(TString type_name)
add new parameter type to the database
Definition
UniParameterType.cxx:32
UniParameterType::UniParameterType
UniParameterType(UniConnection *db_connect, int type_id, TString type_name)
Definition
UniParameterType.cxx:16
UniParameterType::PrintAll
static int PrintAll()
print all parameter types
Definition
UniParameterType.cxx:207
UniParameterType::Print
void Print()
print information about current parameter type
Definition
UniParameterType.cxx:281
UniParameterType::CheckParameterTypeExists
static int CheckParameterTypeExists(int type_id)
check parameter type exists in the database: 1- true, 0 - false, <0 - database operation error
Definition
UniParameterType.cxx:137
UniParameterType.h
std
Definition
json.hpp:4446
database
uni_db
UniParameterType.cxx
Generated on
for BmnRoot by
1.17.0