X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/641204dfbdb9fc870cdd2e7f9e3169a44693e7bf..80aca6d78d4ff5d514216fe96c44e2ee75c4e933:/projects/stargazer/plugins/store/postgresql/postgresql_store_services.cpp diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_services.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_services.cpp index 88b8049c..3d098161 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_services.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_services.cpp @@ -27,19 +27,22 @@ * */ +#include "postgresql_store.h" + +#include "stg/service_conf.h" +#include "stg/common.h" +#include "stg/locker.h" + #include #include #include #include -#include "postgresql_store.h" -#include "stg_locker.h" - //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::GetServicesList(vector * servicesList) const +int POSTGRESQL_STORE::GetServicesList(std::vector * servicesList) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -68,9 +71,9 @@ if (PQresultStatus(result) != PGRES_TUPLES_OK) PQclear(result); printfd(__FILE__, "POSTGRESQL_STORE::GetServicesList(): '%s'\n", strError.c_str()); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::GetServicesList(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::GetServicesList(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -93,9 +96,9 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::SaveService(const SERVICE_CONF & sc) const +int POSTGRESQL_STORE::SaveService(const STG::ServiceConf & sc) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -123,9 +126,9 @@ if (EscapeString(ename)) { printfd(__FILE__, "POSTGRESQL_STORE::SaveService(): 'Failed to escape name'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::SaveService(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::SaveService(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -133,13 +136,13 @@ if (EscapeString(ecomment)) { printfd(__FILE__, "POSTGRESQL_STORE::SaveService(): 'Failed to escape comment'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::SaveService(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::SaveService(): 'Failed to rollback transaction'\n"); + } return -1; } -std::stringstream query; +std::ostringstream query; query << "UPDATE tb_services SET " << "comment = '" << ecomment << "', " << "cost = " << sc.cost << ", " @@ -172,10 +175,10 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::RestoreService(SERVICE_CONF * sc, - const string & name) const +int POSTGRESQL_STORE::RestoreService(STG::ServiceConf * sc, + const std::string & name) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -202,13 +205,13 @@ if (EscapeString(ename)) { printfd(__FILE__, "POSTGRESQL_STORE::RestoreService(): 'Failed to escape name'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::RestoreService(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::RestoreService(): 'Failed to rollback transaction'\n"); + } return -1; } -std::stringstream query; +std::ostringstream query; query << "SELECT comment, cost, pay_day FROM tb_services WHERE name = '" << ename << "'"; result = PQexec(connection, query.str().c_str()); @@ -233,9 +236,9 @@ if (tuples != 1) printfd(__FILE__, "POSTGRESQL_STORE::RestoreService(): 'Invalid number of tuples. Wanted 1, actulally %d'\n", tuples); PQclear(result); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::RestoreService(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::RestoreService(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -260,9 +263,9 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::AddService(const string & name) const +int POSTGRESQL_STORE::AddService(const std::string & name) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -289,13 +292,13 @@ if (EscapeString(ename)) { printfd(__FILE__, "POSTGRESQL_STORE::AddService(): 'Failed to escape name'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::AddService(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::AddService(): 'Failed to rollback transaction'\n"); + } return -1; } -std::stringstream query; +std::ostringstream query; query << "INSERT INTO tb_services \ (name, comment, cost, pay_day) \ VALUES \ @@ -327,9 +330,9 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::DelService(const string & name) const +int POSTGRESQL_STORE::DelService(const std::string & name) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -356,13 +359,13 @@ if (EscapeString(ename)) { printfd(__FILE__, "POSTGRESQL_STORE::DelService(): 'Failed to escape name'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::DelService(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::DelService(): 'Failed to rollback transaction'\n"); + } return -1; } -std::stringstream query; +std::ostringstream query; query << "DELETE FROM tb_services WHERE name = '" << ename << "'"; result = PQexec(connection, query.str().c_str());