]> granicus.if.org Git - pdns/commitdiff
gmysql-client can now be used to select which 'group' we connect as to MySQL. Continu...
authorBert Hubert <bert.hubert@netherlabs.nl>
Sat, 6 Oct 2012 10:58:38 +0000 (10:58 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Sat, 6 Oct 2012 10:58:38 +0000 (10:58 +0000)
Please check!

git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2770 d19b8d6e-7fed-0310-83ef-9ca221ded41b

modules/gmysqlbackend/gmysqlbackend.cc
modules/gmysqlbackend/smysql.cc
modules/gmysqlbackend/smysql.hh

index 315e7a30b86cf09573ea435443adb2d86c10a171..c9cf59971326f4b9bb8c05a04a57264a5ab13d04 100644 (file)
@@ -26,7 +26,8 @@ gMySQLBackend::gMySQLBackend(const string &mode, const string &suffix)  : GSQLBa
                     getArgAsNum("port"),
                     getArg("socket"),
                     getArg("user"),
-                    getArg("password")));
+                    getArg("password"),
+                    getArg("group")));
     
   }
   
@@ -50,6 +51,7 @@ public:
     declare(suffix,"port","Database backend port to connect to","0");
     declare(suffix,"socket","Pdns backend socket to connect to","");
     declare(suffix,"password","Pdns backend password to connect with","");
+    declare(suffix,"group", "Pdns backend MySQL 'group' to connect as", "client");
     declare(suffix,"dnssec","Assume DNSSEC Schema is in place","no");
 
     declare(suffix,"basic-query","Basic query","select content,ttl,prio,type,domain_id,name from records where type='%s' and name='%s'");
index 42b6180cee4f7f60911e6a8c8ea0da7961924379..987adbf4b7d96fe6e1e2ff82a6e544e254c6555e 100644 (file)
@@ -14,15 +14,14 @@ bool SMySQL::s_dolog;
 pthread_mutex_t SMySQL::s_myinitlock = PTHREAD_MUTEX_INITIALIZER;
 
 SMySQL::SMySQL(const string &database, const string &host, uint16_t port, const string &msocket, const string &user, 
-               const string &password)
+               const string &password, const string &group)
 {
   {
     Lock l(&s_myinitlock);
     mysql_init(&d_db);
-    mysql_options(&d_db, MYSQL_READ_DEFAULT_GROUP, "client");
-  my_bool reconnect = 1;
 
   #if MYSQL_VERSION_ID >= 50013
+    my_bool reconnect = 1;
     mysql_options(&d_db, MYSQL_OPT_RECONNECT, &reconnect);
   #endif
 
@@ -31,12 +30,15 @@ SMySQL::SMySQL(const string &database, const string &host, uint16_t port, const
     mysql_options(&d_db, MYSQL_OPT_READ_TIMEOUT, &timeout);
     mysql_options(&d_db, MYSQL_OPT_WRITE_TIMEOUT, &timeout);
   #endif
+
+    mysql_options(&d_db, MYSQL_READ_DEFAULT_GROUP, &group);
     
-    if (!mysql_real_connect(&d_db, host.empty() ? 0 : host.c_str(), 
-                         user.empty() ? 0 : user.c_str(), 
-                         password.empty() ? 0 : password.c_str(),
-                         database.c_str(), port,
-                         msocket.empty() ? 0 : msocket.c_str(),
+    if (!mysql_real_connect(&d_db, host.empty() ? NULL : host.c_str(), 
+                         user.empty() ? NULL : user.c_str(), 
+                         password.empty() ? NULL : password.c_str(),
+                         database.empty() ? NULL : database.c_str(),
+                         port,
+                         msocket.empty() ? NULL : msocket.c_str(),
                          CLIENT_MULTI_RESULTS)) {
 
       throw sPerrorException("Unable to connect to database");
index edb36456bdf69c6039c7d1ca7a894b45cba5f6a5..4be990c123de0e412155b9e10e3669e76c6cf9c1 100644 (file)
@@ -12,8 +12,8 @@ class SMySQL : public SSql
 {
 public:
   SMySQL(const string &database, const string &host="", uint16_t port=0,
-         const string &msocket="",const string &user="", 
-         const string &password="");
+         const string &msocket="",const string &user="",
+         const string &password="", const string &group="");
 
   ~SMySQL();