1 /* 2 * This file is part of PowerDNS or dnsdist. 3 * Copyright -- PowerDNS.COM B.V. and its contributors 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of version 2 of the GNU General Public License as 7 * published by the Free Software Foundation. 8 * 9 * In addition, for the avoidance of any doubt, permission is granted to 10 * link this program with OpenSSL and to (re)distribute the binaries 11 * produced as the result of such linking. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21 */ 22 #pragma once 23 #include <mutex> 24 25 #include <mysql.h> 26 #include "pdns/backends/gsql/ssql.hh" 27 #include "pdns/utility.hh" 28 29 class SMySQL : public SSql 30 { 31 public: 32 SMySQL(string database, string host = "", uint16_t port = 0, 33 string msocket = "", string user = "", 34 string password = "", string group = "", 35 bool setIsolation = false, unsigned int timeout = 10, 36 bool threadCleanup = false, bool clientSSL = false); 37 38 ~SMySQL(); 39 40 SSqlException sPerrorException(const string& reason) override; 41 void setLog(bool state) override; 42 std::unique_ptr<SSqlStatement> prepare(const string& query, int nparams) override; 43 void execute(const string& query) override; 44 45 void startTransaction() override; 46 void commit() override; 47 void rollback() override; 48 bool isConnectionUsable() override; 49 50 private: 51 void connect(); 52 53 static bool s_dolog; 54 static std::mutex s_myinitlock; 55 56 MYSQL d_db; 57 std::string d_database; 58 std::string d_host; 59 std::string d_msocket; 60 std::string d_user; 61 std::string d_password; 62 std::string d_group; 63 unsigned int d_timeout; 64 uint16_t d_port; 65 bool d_setIsolation; 66 bool d_threadCleanup; 67 bool d_clientSSL; 68 }; 69