X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/90e389f6ec12e60a62c362296ffcf314feb5b03d..3d0666c75bc51feb1ef512578e65c06a92c71cc8:/projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp index 4260c3b4..42a19073 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp @@ -33,14 +33,15 @@ #include +#include "stg/common.h" #include "postgresql_store.h" #include "stg/locker.h" #include "stg/message.h" //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::AddMessage(STG_MSG * msg, const string & login) const +int POSTGRESQL_STORE::AddMessage(STG_MSG * msg, const std::string & login) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -84,13 +85,13 @@ if (EscapeString(etext)) return -1; } -std::stringstream query; +std::ostringstream query; query << "SELECT sp_add_message(" << "'" << elogin << "', " << "CAST(1 AS SMALLINT), " // Here need to be a version, but, it's uninitiated actually << "CAST(" << msg->header.type << " AS SMALLINT), " - << "CAST('" << Int2TS(msg->header.lastSendTime) << "' AS TIMESTAMP), " - << "CAST('" << Int2TS(msg->header.creationTime) << "' AS TIMESTAMP), " + << "CAST('" << formatTime(msg->header.lastSendTime) << "' AS TIMESTAMP), " + << "CAST('" << formatTime(msg->header.creationTime) << "' AS TIMESTAMP), " << msg->header.showTime << ", " << "CAST(" << msg->header.repeat << " AS SMALLINT), " << msg->header.repeatPeriod << ", " @@ -141,9 +142,9 @@ return 0; } //----------------------------------------------------------------------------- int POSTGRESQL_STORE::EditMessage(const STG_MSG & msg, - const string & login) const + const std::string & login) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -187,13 +188,13 @@ if (EscapeString(etext)) return -1; } -std::stringstream query; +std::ostringstream query; query << "UPDATE tb_messages SET " << "fk_user = (SELECT pk_user FROM tb_users WHERE name = '" << elogin << "'), " << "ver = " << msg.header.ver << ", " << "msg_type = " << msg.header.type << ", " - << "last_send_time = CAST('" << Int2TS(msg.header.lastSendTime) << "' AS TIMESTAMP), " - << "creation_time = CAST('" << Int2TS(msg.header.creationTime) << "' AS TIMESTAMP), " + << "last_send_time = CAST('" << formatTime(msg.header.lastSendTime) << "' AS TIMESTAMP), " + << "creation_time = CAST('" << formatTime(msg.header.creationTime) << "' AS TIMESTAMP), " << "show_time = " << msg.header.showTime << ", " << "repeat = " << msg.header.repeat << ", " << "repeat_period = " << msg.header.repeatPeriod << ", " @@ -227,9 +228,9 @@ return 0; //----------------------------------------------------------------------------- int POSTGRESQL_STORE::GetMessage(uint64_t id, STG_MSG * msg, - const string &) const + const std::string &) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -242,7 +243,6 @@ if (PQstatus(connection) != CONNECTION_OK) } } -string login; PGresult * result; if (StartTransaction()) @@ -251,7 +251,7 @@ if (StartTransaction()) return -1; } -std::stringstream query; +std::ostringstream query; query << "SELECT ver, msg_type, last_send_time, \ creation_time, show_time, repeat, \ repeat_period, msg_text \ @@ -286,17 +286,10 @@ if (tuples != 1) return -1; } -/*std::stringstream tuple; - -for (int i = 0; i < 8; ++i) - { - tuple << PQgetvalue(result, 0, i) << " "; - }*/ - str2x(PQgetvalue(result, 0, 0), msg->header.ver); str2x(PQgetvalue(result, 0, 1), msg->header.type); -msg->header.lastSendTime = TS2Int(PQgetvalue(result, 0, 2)); -msg->header.creationTime = TS2Int(PQgetvalue(result, 0, 3)); +msg->header.lastSendTime = static_cast(readTime(PQgetvalue(result, 0, 2))); +msg->header.creationTime = static_cast(readTime(PQgetvalue(result, 0, 3))); str2x(PQgetvalue(result, 0, 4), msg->header.showTime); str2x(PQgetvalue(result, 0, 5), msg->header.repeat); str2x(PQgetvalue(result, 0, 6), msg->header.repeatPeriod); @@ -304,15 +297,6 @@ msg->text = PQgetvalue(result, 0, 7); PQclear(result); -/*tuple >> msg->header.ver; -tuple >> msg->header.type; -tuple >> msg->header.lastSendTime; -tuple >> msg->header.creationTime; -tuple >> msg->header.showTime; -tuple >> msg->header.repeat; -tuple >> msg->header.repeatPeriod; -tuple >> msg->text;*/ - if (CommitTransaction()) { printfd(__FILE__, "POSTGRESQL_STORE::GetMessage(): 'Failed to commit transaction'\n"); @@ -322,9 +306,9 @@ if (CommitTransaction()) return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::DelMessage(uint64_t id, const string &) const +int POSTGRESQL_STORE::DelMessage(uint64_t id, const std::string &) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -345,7 +329,7 @@ if (StartTransaction()) return -1; } -std::stringstream query; +std::ostringstream query; query << "DELETE FROM tb_messages WHERE pk_message = " << id; result = PQexec(connection, query.str().c_str()); @@ -373,10 +357,10 @@ if (CommitTransaction()) return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::GetMessageHdrs(vector * hdrsList, - const string & login) const +int POSTGRESQL_STORE::GetMessageHdrs(std::vector * hdrsList, + const std::string & login) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -409,7 +393,7 @@ if (EscapeString(elogin)) return -1; } -std::stringstream query; +std::ostringstream query; query << "SELECT pk_message, ver, msg_type, \ last_send_time, creation_time, show_time, \ repeat, repeat_period \ @@ -441,8 +425,8 @@ for (int i = 0; i < tuples; ++i) tuple << PQgetvalue(result, i, 0) << " "; tuple << PQgetvalue(result, i, 1) << " "; tuple << PQgetvalue(result, i, 2) << " "; - header.lastSendTime = TS2Int(PQgetvalue(result, i, 3)); - header.creationTime = TS2Int(PQgetvalue(result, i, 4)); + header.lastSendTime = static_cast(readTime(PQgetvalue(result, i, 3))); + header.creationTime = static_cast(readTime(PQgetvalue(result, i, 4))); tuple << PQgetvalue(result, i, 5) << " "; tuple << PQgetvalue(result, i, 6) << " "; tuple << PQgetvalue(result, i, 7) << " ";