return 0;
}
//-----------------------------------------------------------------------------
+ int MYSQL_STORE::MakeUpdates(MYSQL * sock)
+ {
+ if (schemaVersion < 1)
+ {
+ if (MysqlQuery("ALTER TABLE tariffs ADD period VARCHAR(32) NOT NULL DEFAULT 'month'", sock))
+ {
+ errorStr = "Couldn't update tariffs table to version 1. With error:\n";
+ errorStr += mysql_error(sock);
+ mysql_close(sock);
+ return -1;
+ }
+ if (MysqlQuery("UPDATE info SET version = 1", sock))
+ {
+ errorStr = "Couldn't update DB schema version to 1. With error:\n";
+ errorStr += mysql_error(sock);
+ mysql_close(sock);
+ return -1;
+ }
+ schemaVersion = 1;
+ WriteServLog("MYSQL_STORE: Updated DB schema to version %d", schemaVersion);
+ }
+ return 0;
+ }
//-----------------------------------------------------------------------------
-int MYSQL_STORE::GetAllParams(vector<string> * ParamList,
- const string & table, const string & name) const
+int MYSQL_STORE::GetAllParams(std::vector<std::string> * ParamList,
+ const std::string & table, const std::string & name) const
{
MYSQL_RES *res;
MYSQL_ROW row;
MYSQL_STORE(const MYSQL_STORE & rvalue);
MYSQL_STORE & operator=(const MYSQL_STORE & rvalue);
- virtual int WriteLogString(const string & str, const string & login) const;
- int GetAllParams(vector<string> * ParamList, const string & table, const string & name) const;
+ virtual int WriteLogString(const std::string & str, const std::string & login) const;
+ int GetAllParams(std::vector<std::string> * ParamList, const std::string & table, const std::string & name) const;
int CheckAllTables(MYSQL * sock);
- bool IsTablePresent(const string & str,MYSQL * sock);
- mutable string errorStr;
- int MysqlQuery(const char* sQuery,MYSQL * sock) const;
+ int MakeUpdates(MYSQL * sock);
+ bool IsTablePresent(const std::string & str,MYSQL * sock);
+ mutable std::string errorStr;
+ int MysqlQuery(const char* sQuery,MYSQL * sock) const;
int MysqlGetQuery(const char * Query,MYSQL * & sock) const;
int MysqlSetQuery(const char * Query) const;
MYSQL * MysqlConnect() const ;
- string version;
+ std::string version;
MYSQL_STORE_SETTINGS storeSettings;
MODULE_SETTINGS settings;
- STG_LOGGER & WriteServLog;
+ int schemaVersion;
+
+ PLUGIN_LOGGER logger;
};
//-----------------------------------------------------------------------------
return -1;
}
-std::stringstream tuple;
-tuple << PQgetvalue(result, 0, 0);
+ {
+ std::stringstream tuple;
+ tuple << PQgetvalue(result, 0, 0);
-PQclear(result);
+ PQclear(result);
-tuple >> id;
+ tuple >> id;
+ }
-query.str("");
-query << "UPDATE tb_tariffs SET \
- fee = " << td.tariffConf.fee << ", \
- free = " << td.tariffConf.free << ", \
- passive_cost = " << td.tariffConf.passiveCost << ", \
- traff_type = " << td.tariffConf.traffType;
+ {
+ std::ostringstream query;
+ query << "UPDATE tb_tariffs SET \
+ fee = " << td.tariffConf.fee << ", \
+ free = " << td.tariffConf.free << ", \
+ passive_cost = " << td.tariffConf.passiveCost << ", \
- traff_type = " << td.tariffConf.traffType << " \
- WHERE pk_tariff = " << id;
++ traff_type = " << td.tariffConf.traffType;
+
-if (version > 6)
- query << ", period = '" << TARIFF::PeriodToString(td.tariffConf.period) << "'";
++ if (version > 6)
++ query << ", period = '" << TARIFF::PeriodToString(td.tariffConf.period) << "'";
+
-query << " WHERE pk_tariff = " << id;
++ query << " WHERE pk_tariff = " << id;
-result = PQexec(connection, query.str().c_str());
+ result = PQexec(connection, query.str().c_str());
+ }
if (PQresultStatus(result) != PGRES_COMMAND_OK)
{
td->tariffConf.name = tariffName;
-std::stringstream query;
+std::ostringstream query;
query << "SELECT pk_tariff, \
fee, \
- free, \
- passive_cost, \
- traff_type \
- FROM tb_tariffs WHERE name = '" << ename << "'";
+ free, \
+ passive_cost, \
+ traff_type";
+
+ if (version > 6)
+ query << ", period";
+
+ query << " FROM tb_tariffs WHERE name = '" << ename << "'";
result = PQexec(connection, query.str().c_str());
return -1;
}
-std::stringstream tuple;
-tuple << PQgetvalue(result, 0, 0) << " ";
-tuple << PQgetvalue(result, 0, 1) << " ";
-tuple << PQgetvalue(result, 0, 2) << " ";
-tuple << PQgetvalue(result, 0, 3) << " ";
-tuple << PQgetvalue(result, 0, 4) << " ";
-
int id;
-tuple >> id;
-tuple >> td->tariffConf.fee;
-tuple >> td->tariffConf.free;
-tuple >> td->tariffConf.passiveCost;
-tuple >> td->tariffConf.traffType;
+
+ {
+ std::stringstream tuple;
+ tuple << PQgetvalue(result, 0, 0) << " ";
+ tuple << PQgetvalue(result, 0, 1) << " ";
+ tuple << PQgetvalue(result, 0, 2) << " ";
+ tuple << PQgetvalue(result, 0, 3) << " ";
+ tuple << PQgetvalue(result, 0, 4) << " ";
+
+ tuple >> id;
+ tuple >> td->tariffConf.fee;
+ tuple >> td->tariffConf.free;
+ tuple >> td->tariffConf.passiveCost;
+ tuple >> td->tariffConf.traffType;
+ }
+ if (version > 6)
+ td->tariffConf.period = TARIFF::StringToPeriod(PQgetvalue(result, 0, 5));
+
PQclear(result);
query.str("");