X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/90e389f6ec12e60a62c362296ffcf314feb5b03d..2574a28cbf000603bc31f61593dbf061ff56c1d5:/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 c358a4c5..6c6b9985 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp @@ -26,19 +26,21 @@ * */ +#include "postgresql_store.h" + +#include "stg/corp_conf.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__); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -92,9 +94,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__); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -121,13 +123,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 +160,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__); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -187,13 +189,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 +220,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 +243,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__); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -270,13 +272,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 +310,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__); +std::lock_guard lock(m_mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -337,13 +339,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());