9#include "TSQLStatement.h"
16ElogBeam::ElogBeam(
ElogConnection* db_connect, TString beam,
bool is_active)
18 connectionDB = db_connect;
21 b_is_active = is_active;
35 if (connDb ==
nullptr)
40 TString sql = TString::Format(
"insert into beam_(beam, is_active) "
42 TSQLStatement* stmt = db_server->Statement(sql);
44 stmt->NextIteration();
45 stmt->SetString(0, beam);
46 stmt->SetInt(1, is_active);
49 if (!stmt->Process()) {
50 cout <<
"ERROR: inserting new beam to the Database has been failed" << endl;
61 tmp_is_active = is_active;
63 return new ElogBeam(connDb, tmp_beam, tmp_is_active);
70 if (connDb ==
nullptr)
75 TString sql = TString::Format(
"select beam, is_active "
77 "where lower(beam) = lower('%s')",
79 TSQLStatement* stmt = db_server->Statement(sql);
82 if (!stmt->Process()) {
83 cout <<
"ERROR: getting beam from the database has been failed" << endl;
94 if (!stmt->NextResultRow()) {
95 cout <<
"ERROR: beam was not found in the database" << endl;
103 tmp_beam = stmt->GetString(0);
105 tmp_is_active = stmt->GetInt(1);
109 return new ElogBeam(connDb, tmp_beam, tmp_is_active);
116 if (connDb ==
nullptr)
121 TString sql = TString::Format(
"select 1 "
123 "where lower(beam) = lower('%s')",
125 TSQLStatement* stmt = db_server->Statement(sql);
128 if (!stmt->Process()) {
129 cout <<
"ERROR: getting beam from the database has been failed" << endl;
140 if (!stmt->NextResultRow()) {
156 if (connDb ==
nullptr)
161 TString sql = TString::Format(
"delete from beam_ "
162 "where lower(beam) = lower($1)");
163 TSQLStatement* stmt = db_server->Statement(sql);
165 stmt->NextIteration();
166 stmt->SetString(0, beam);
169 if (!stmt->Process()) {
170 cout <<
"ERROR: deleting beam from the dataBase has been failed" << endl;
186 if (connDb ==
nullptr)
191 TString sql = TString::Format(
"select beam, is_active "
193 TSQLStatement* stmt = db_server->Statement(sql);
196 if (!stmt->Process()) {
197 cout <<
"ERROR: getting all 'beams' from the dataBase has been failed" << endl;
208 cout <<
"Table 'beam_':" << endl;
209 while (stmt->NextResultRow()) {
211 cout << (stmt->GetString(0));
212 cout <<
", is_active: ";
213 cout << (stmt->GetInt(1));
227 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
233 TString sql = TString::Format(
"update beam_ "
236 TSQLStatement* stmt = db_server->Statement(sql);
238 stmt->NextIteration();
239 stmt->SetString(0, beam);
240 stmt->SetString(1, str_beam);
243 if (!stmt->Process()) {
244 cout <<
"ERROR: updating information about beam has been failed" << endl;
259 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
265 TString sql = TString::Format(
"update beam_ "
266 "set is_active = $1 "
268 TSQLStatement* stmt = db_server->Statement(sql);
270 stmt->NextIteration();
271 stmt->SetInt(0, is_active);
272 stmt->SetString(1, str_beam);
275 if (!stmt->Process()) {
276 cout <<
"ERROR: updating information about beam has been failed" << endl;
282 b_is_active = is_active;
291 cout <<
"Table 'beam_'";
292 cout <<
". beam: " << str_beam <<
". is_active: " << b_is_active << endl;
static int PrintAll()
print all beams
TString GetBeam()
get beam of the current beam
int SetBeam(TString beam)
set beam of the current beam
static ElogBeam * CreateBeam(TString beam, bool is_active)
add new beam to the database
static int CheckBeamExists(TString beam)
check beam exists in the database: 1- true, 0 - false, <0 - database operation error
static int DeleteBeam(TString beam)
delete beam from the database
void Print()
print information about current beam
int SetIsActive(bool is_active)
set is active of the current beam
static ElogConnection * Open()
TSQLServer * GetSQLServer()