9#include "TSQLStatement.h"
16UniDetector::UniDetector(
UniConnection* db_connect, TString detector_name, TString* detector_desc)
18 connectionDB = db_connect;
20 str_detector_name = detector_name;
21 str_detector_desc = detector_desc;
29 if (str_detector_desc)
30 delete str_detector_desc;
37 if (connDb ==
nullptr)
42 TString sql = TString::Format(
"insert into detector_(detector_name, detector_desc) "
44 TSQLStatement* stmt = db_server->Statement(sql);
46 stmt->NextIteration();
47 stmt->SetString(0, detector_name);
48 if (detector_desc ==
nullptr)
51 stmt->SetString(1, *detector_desc);
54 if (!stmt->Process()) {
55 cout <<
"ERROR: inserting new detector to the Database has been failed" << endl;
63 TString tmp_detector_name;
64 tmp_detector_name = detector_name;
65 TString* tmp_detector_desc;
66 if (detector_desc ==
nullptr)
67 tmp_detector_desc =
nullptr;
69 tmp_detector_desc =
new TString(*detector_desc);
71 return new UniDetector(connDb, tmp_detector_name, tmp_detector_desc);
78 if (connDb ==
nullptr)
83 TString sql = TString::Format(
"select detector_name, detector_desc "
85 "where lower(detector_name) = lower('%s')",
86 detector_name.Data());
87 TSQLStatement* stmt = db_server->Statement(sql);
90 if (!stmt->Process()) {
91 cout <<
"ERROR: getting detector from the database has been failed" << endl;
102 if (!stmt->NextResultRow()) {
103 cout <<
"ERROR: detector was not found in the database" << endl;
110 TString tmp_detector_name;
111 tmp_detector_name = stmt->GetString(0);
112 TString* tmp_detector_desc;
114 tmp_detector_desc =
nullptr;
116 tmp_detector_desc =
new TString(stmt->GetString(1));
120 return new UniDetector(connDb, tmp_detector_name, tmp_detector_desc);
127 if (connDb ==
nullptr)
132 TString sql = TString::Format(
"select 1 "
134 "where lower(detector_name) = lower('%s')",
135 detector_name.Data());
136 TSQLStatement* stmt = db_server->Statement(sql);
139 if (!stmt->Process()) {
140 cout <<
"ERROR: getting detector from the database has been failed" << endl;
151 if (!stmt->NextResultRow()) {
167 if (connDb ==
nullptr)
172 TString sql = TString::Format(
"delete from detector_ "
173 "where lower(detector_name) = lower($1)");
174 TSQLStatement* stmt = db_server->Statement(sql);
176 stmt->NextIteration();
177 stmt->SetString(0, detector_name);
180 if (!stmt->Process()) {
181 cout <<
"ERROR: deleting detector from the dataBase has been failed" << endl;
197 if (connDb ==
nullptr)
202 TString sql = TString::Format(
"select detector_name, detector_desc "
204 TSQLStatement* stmt = db_server->Statement(sql);
207 if (!stmt->Process()) {
208 cout <<
"ERROR: getting all 'detectors' from the dataBase has been failed" << endl;
219 cout <<
"Table 'detector_':" << endl;
220 while (stmt->NextResultRow()) {
221 cout <<
"detector_name: ";
222 cout << (stmt->GetString(0));
223 cout <<
", detector_desc: ";
227 cout << stmt->GetString(1);
241 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
247 TString sql = TString::Format(
"update detector_ "
248 "set detector_name = $1 "
249 "where detector_name = $2");
250 TSQLStatement* stmt = db_server->Statement(sql);
252 stmt->NextIteration();
253 stmt->SetString(0, detector_name);
254 stmt->SetString(1, str_detector_name);
257 if (!stmt->Process()) {
258 cout <<
"ERROR: updating information about detector has been failed" << endl;
264 str_detector_name = detector_name;
273 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
279 TString sql = TString::Format(
"update detector_ "
280 "set detector_desc = $1 "
281 "where detector_name = $2");
282 TSQLStatement* stmt = db_server->Statement(sql);
284 stmt->NextIteration();
285 if (detector_desc ==
nullptr)
288 stmt->SetString(0, *detector_desc);
289 stmt->SetString(1, str_detector_name);
292 if (!stmt->Process()) {
293 cout <<
"ERROR: updating information about detector has been failed" << endl;
299 if (str_detector_desc)
300 delete str_detector_desc;
301 if (detector_desc ==
nullptr)
302 str_detector_desc =
nullptr;
304 str_detector_desc =
new TString(*detector_desc);
313 cout <<
"Table 'detector_'";
314 cout <<
". detector_name: " << str_detector_name
315 <<
". detector_desc: " << (str_detector_desc ==
nullptr ?
"nullptr" : *str_detector_desc) << endl;
static UniConnection * Open()
TSQLServer * GetSQLServer()
void Print()
print information about current detector
int SetDetectorName(TString detector_name)
set detector name of the current detector
static int CheckDetectorExists(TString detector_name)
check detector exists in the database: 1- true, 0 - false, <0 - database operation error
static int PrintAll()
print all detectors
static int DeleteDetector(TString detector_name)
delete detector from the database
static UniDetector * CreateDetector(TString detector_name, TString *detector_desc)
add new detector to the database
static UniDetector * GetDetector(TString detector_name)
get detector from the database
int SetDetectorDesc(TString *detector_desc)
set detector description of the current detector