]> git.stg.codes - stg.git/commitdiff
Added optional DB port parameter for MySQL store.
authorYurii Olenych <yolenych@gmail.com>
Tue, 25 Aug 2020 12:49:06 +0000 (15:49 +0300)
committerYurii Olenych <yolenych@gmail.com>
Tue, 25 Aug 2020 12:49:06 +0000 (15:49 +0300)
stargazer/plugins/store/mysql/mysql_store.cpp
stargazer/plugins/store/mysql/mysql_store.h

index 3ad79b3019e8c4279d196aacbc6482297840fbaf..c441a7081ae658d96f3b4428774bc925e583ebdb 100644 (file)
@@ -110,6 +110,7 @@ extern "C" STG::Store* GetStore()
 //-----------------------------------------------------------------------------
 MYSQL_STORE_SETTINGS::MYSQL_STORE_SETTINGS()
     : settings(NULL)
 //-----------------------------------------------------------------------------
 MYSQL_STORE_SETTINGS::MYSQL_STORE_SETTINGS()
     : settings(NULL)
+    , dbPort(0)
 {
 }
 //-----------------------------------------------------------------------------
 {
 }
 //-----------------------------------------------------------------------------
@@ -146,13 +147,25 @@ if (ParseParam(s.moduleParams, "server", dbHost) < 0 &&
     ParseParam(s.moduleParams, "dbhost", dbHost) < 0)
     return -1;
 
     ParseParam(s.moduleParams, "dbhost", dbHost) < 0)
     return -1;
 
+// not required
+std::string dbPortAsString;
+if (ParseParam(s.moduleParams, "port", dbPortAsString) == 0 ||
+    ParseParam(s.moduleParams, "dbport", dbPortAsString) == 0)
+{
+    if (GetInt<unsigned int>(dbPortAsString, &dbPort, 0) != 0)
+    {
+        errorStr = "Can't parse db port from string: \"" + dbPortAsString + "\"\n";
+        return -1;
+    }
+}
+
 return 0;
 }
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 MYSQL_STORE::MYSQL_STORE()
 return 0;
 }
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 MYSQL_STORE::MYSQL_STORE()
-    : version("mysql_store v.0.67"),
+    : version("mysql_store v.0.68"),
       schemaVersion(0),
       logger(STG::PluginLogger::get("store_mysql"))
 {
       schemaVersion(0),
       logger(STG::PluginLogger::get("store_mysql"))
 {
@@ -195,7 +208,7 @@ else
     MYSQL * sock;
     if (!(sock = mysql_real_connect(&mysql,storeSettings.GetDBHost().c_str(),
             storeSettings.GetDBUser().c_str(),storeSettings.GetDBPassword().c_str(),
     MYSQL * sock;
     if (!(sock = mysql_real_connect(&mysql,storeSettings.GetDBHost().c_str(),
             storeSettings.GetDBUser().c_str(),storeSettings.GetDBPassword().c_str(),
-            0,0,NULL,0)))
+            0,storeSettings.GetDBPort(),NULL,0)))
         {
             errorStr = "Couldn't connect to mysql engine! With error:\n";
             errorStr += mysql_error(&mysql);
         {
             errorStr = "Couldn't connect to mysql engine! With error:\n";
             errorStr += mysql_error(&mysql);
@@ -2136,7 +2149,7 @@ MYSQL *  MYSQL_STORE::MysqlConnect() const {
     }
     if (!(sock = mysql_real_connect(sock,storeSettings.GetDBHost().c_str(),
             storeSettings.GetDBUser().c_str(),storeSettings.GetDBPassword().c_str(),
     }
     if (!(sock = mysql_real_connect(sock,storeSettings.GetDBHost().c_str(),
             storeSettings.GetDBUser().c_str(),storeSettings.GetDBPassword().c_str(),
-            0,0,NULL,0)))
+            0,storeSettings.GetDBPort(),NULL,0)))
         {
             errorStr = "Couldn't connect to mysql engine! With error:\n";
             errorStr += mysql_error(sock);
         {
             errorStr = "Couldn't connect to mysql engine! With error:\n";
             errorStr += mysql_error(sock);
index 6d09c476682e227ca7c5b3a5cc295f5650457108..61a13203be29483e5ac9d9b4e878a9e1d095006d 100644 (file)
@@ -24,6 +24,7 @@ public:
     const std::string & GetDBPassword() const { return dbPass; }
     const std::string & GetDBHost() const { return dbHost; }
     const std::string & GetDBName() const { return dbName; }
     const std::string & GetDBPassword() const { return dbPass; }
     const std::string & GetDBHost() const { return dbHost; }
     const std::string & GetDBName() const { return dbName; }
+    unsigned int GetDBPort() const { return dbPort; }
 
 private:
     MYSQL_STORE_SETTINGS(const MYSQL_STORE_SETTINGS & rvalue);
 
 private:
     MYSQL_STORE_SETTINGS(const MYSQL_STORE_SETTINGS & rvalue);
@@ -40,6 +41,7 @@ private:
     std::string  dbPass;
     std::string  dbName;
     std::string  dbHost;
     std::string  dbPass;
     std::string  dbName;
     std::string  dbHost;
+    unsigned int dbPort;
 };
 //-----------------------------------------------------------------------------
 class MYSQL_STORE: public STG::Store
 };
 //-----------------------------------------------------------------------------
 class MYSQL_STORE: public STG::Store