X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/641204dfbdb9fc870cdd2e7f9e3169a44693e7bf..0907aa4037b12b6b88ee24495d4577a064d4f8db:/projects/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp index 6fa3fd50..1387d418 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp @@ -26,19 +26,22 @@ * */ +#include "postgresql_store.h" + +#include "stg/corp_conf.h" +#include "stg/locker.h" +#include "stg/common.h" + #include #include #include #include -#include "postgresql_store.h" -#include "stg_locker.h" - //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::GetCorpsList(vector * corpsList) const +int POSTGRESQL_STORE::GetCorpsList(std::vector * corpsList) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -92,9 +95,9 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::SaveCorp(const CORP_CONF & cc) const +int POSTGRESQL_STORE::SaveCorp(const STG::CorpConf & cc) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -121,13 +124,13 @@ if (EscapeString(ename)) { printfd(__FILE__, "POSTGRESQL_STORE::SaveCorp(): 'Failed to escape name'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::SaveCorp(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::SaveCorp(): 'Failed to rollback transaction'\n"); + } return -1; } -std::stringstream query; +std::ostringstream query; query << "UPDATE tb_corporations SET " << "cash = " << cc.cash << "WHERE name = '" << ename << "'"; @@ -158,9 +161,9 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::RestoreCorp(CORP_CONF * cc, const string & name) const +int POSTGRESQL_STORE::RestoreCorp(STG::CorpConf * cc, const std::string & name) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -187,13 +190,13 @@ if (EscapeString(ename)) { printfd(__FILE__, "POSTGRESQL_STORE::RestoreCorp(): 'Failed to escape name'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::RestoreCorp(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::RestoreCorp(): 'Failed to rollback transaction'\n"); + } return -1; } -std::stringstream query; +std::ostringstream query; query << "SELECT cash FROM tb_corporations WHERE name = '" << ename << "'"; result = PQexec(connection, query.str().c_str()); @@ -218,9 +221,9 @@ if (tuples != 1) printfd(__FILE__, "POSTGRESQL_STORE::RestoreCorp(): 'Invalid number of tuples. Wanted 1, actulally %d'\n", tuples); PQclear(result); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::RestoreCorp(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::RestoreCorp(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -241,9 +244,9 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::AddCorp(const string & name) const +int POSTGRESQL_STORE::AddCorp(const std::string & name) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -270,13 +273,13 @@ if (EscapeString(ename)) { printfd(__FILE__, "POSTGRESQL_STORE::AddCorp(): 'Failed to escape name'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::AddCorp(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::AddCorp(): 'Failed to rollback transaction'\n"); + } return -1; } -std::stringstream query; +std::ostringstream query; query << "INSERT INTO tb_corporations \ (name, cash) \ VALUES \ @@ -308,9 +311,9 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::DelCorp(const string & name) const +int POSTGRESQL_STORE::DelCorp(const std::string & name) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -337,13 +340,13 @@ if (EscapeString(ename)) { printfd(__FILE__, "POSTGRESQL_STORE::DelCorp(): 'Failed to escape name'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::DelCorp(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::DelCorp(): 'Failed to rollback transaction'\n"); + } return -1; } -std::stringstream query; +std::ostringstream query; query << "DELETE FROM tb_corporations WHERE name = '" << ename << "'"; result = PQexec(connection, query.str().c_str());