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