]> git.stg.codes - stg.git/commitdiff
Merge pull request #2 from bobr-kun/MySQL_custom_port stg-2.409
authorMaksym Mamontov <github.com@madf.info>
Mon, 1 Feb 2021 16:15:56 +0000 (18:15 +0200)
committerGitHub <noreply@github.com>
Mon, 1 Feb 2021 16:15:56 +0000 (18:15 +0200)
MySQL_custom_port

projects/stargazer/plugins/store/mysql/mysql_store.cpp
projects/stargazer/plugins/store/mysql/mysql_store.h

index cef72671b1c5e6b68b4b0d88c5e22b65d16d5ebd..48be4aa6b37ad952950c8b6f14d2d022e1d9918e 100644 (file)
@@ -113,6 +113,7 @@ return msc.GetPlugin();
 //-----------------------------------------------------------------------------
 MYSQL_STORE_SETTINGS::MYSQL_STORE_SETTINGS()
     : settings(NULL)
+    , dbPort(0)
 {
 }
 //-----------------------------------------------------------------------------
@@ -149,6 +150,17 @@ if (ParseParam(s.moduleParams, "server", dbHost) < 0 &&
     ParseParam(s.moduleParams, "dbhost", dbHost) < 0)
     return -1;
 
+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;
 }
 //-----------------------------------------------------------------------------
@@ -198,7 +210,7 @@ else
     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);
@@ -2139,7 +2151,7 @@ MYSQL *  MYSQL_STORE::MysqlConnect() const {
     }
     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);
index d7ed130eaa38f8cac3222e7ea6f5bb433044ce09..2bb4815e3ff56ac5df98c1fdc8eeecc45f5fe4f4 100644 (file)
@@ -31,6 +31,7 @@ public:
     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);
@@ -47,6 +48,7 @@ private:
     std::string  dbPass;
     std::string  dbName;
     std::string  dbHost;
+    unsigned int dbPort;
 };
 //-----------------------------------------------------------------------------
 class MYSQL_STORE: public STORE