9#include "TSQLStatement.h"
16UniParameterType::UniParameterType(
UniConnection* db_connect,
int type_id, TString type_name)
18 connectionDB = db_connect;
21 str_type_name = type_name;
35 if (connDb ==
nullptr)
40 TString sql = TString::Format(
"insert into parameter_type(type_name) "
42 TSQLStatement* stmt = db_server->Statement(sql);
44 stmt->NextIteration();
45 stmt->SetString(0, type_name);
48 if (!stmt->Process()) {
49 cout <<
"ERROR: inserting new parameter type to the Database has been failed" << endl;
59 TSQLStatement* stmt_last =
60 db_server->Statement(
"SELECT currval(pg_get_serial_sequence('parameter_type','type_id'))");
63 if (stmt_last->Process()) {
65 stmt_last->StoreResult();
68 if (!stmt_last->NextResultRow()) {
69 cout <<
"ERROR: no last ID in DB!" << endl;
73 type_id = stmt_last->GetInt(0);
77 cout <<
"ERROR: getting last ID has been failed!" << endl;
83 tmp_type_id = type_id;
84 TString tmp_type_name;
85 tmp_type_name = type_name;
94 if (connDb ==
nullptr)
99 TString sql = TString::Format(
"select type_id, type_name "
100 "from parameter_type "
101 "where type_id = %d",
103 TSQLStatement* stmt = db_server->Statement(sql);
106 if (!stmt->Process()) {
107 cout <<
"ERROR: getting parameter type from the database has been failed" << endl;
118 if (!stmt->NextResultRow()) {
119 cout <<
"ERROR: parameter type was not found in the database" << endl;
127 tmp_type_id = stmt->GetInt(0);
128 TString tmp_type_name;
129 tmp_type_name = stmt->GetString(1);
140 if (connDb ==
nullptr)
145 TString sql = TString::Format(
"select 1 "
146 "from parameter_type "
147 "where type_id = %d",
149 TSQLStatement* stmt = db_server->Statement(sql);
152 if (!stmt->Process()) {
153 cout <<
"ERROR: getting parameter type from the database has been failed" << endl;
164 if (!stmt->NextResultRow()) {
180 if (connDb ==
nullptr)
185 TString sql = TString::Format(
"delete from parameter_type "
186 "where type_id = $1");
187 TSQLStatement* stmt = db_server->Statement(sql);
189 stmt->NextIteration();
190 stmt->SetInt(0, type_id);
193 if (!stmt->Process()) {
194 cout <<
"ERROR: deleting parameter type from the dataBase has been failed" << endl;
210 if (connDb ==
nullptr)
215 TString sql = TString::Format(
"select type_id, type_name "
216 "from parameter_type");
217 TSQLStatement* stmt = db_server->Statement(sql);
220 if (!stmt->Process()) {
221 cout <<
"ERROR: getting all 'parameter types' from the dataBase has been failed" << endl;
232 cout <<
"Table 'parameter_type':" << endl;
233 while (stmt->NextResultRow()) {
235 cout << (stmt->GetInt(0));
236 cout <<
", type_name: ";
237 cout << (stmt->GetString(1));
251 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
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);
262 stmt->NextIteration();
263 stmt->SetString(0, type_name);
264 stmt->SetInt(1, i_type_id);
267 if (!stmt->Process()) {
268 cout <<
"ERROR: updating information about parameter type has been failed" << endl;
274 str_type_name = type_name;
283 cout <<
"Table 'parameter_type'";
284 cout <<
". type_id: " << i_type_id <<
". type_name: " << str_type_name << endl;
static UniConnection * Open()
TSQLServer * GetSQLServer()
static UniParameterType * GetParameterType(int type_id)
get parameter type from the database
static int DeleteParameterType(int type_id)
delete parameter type from the database
virtual ~UniParameterType()
int SetTypeName(TString type_name)
set type name of the current parameter type
static UniParameterType * CreateParameterType(TString type_name)
add new parameter type to the database
static int PrintAll()
print all parameter types
void Print()
print information about current parameter type
static int CheckParameterTypeExists(int type_id)
check parameter type exists in the database: 1- true, 0 - false, <0 - database operation error