diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-05-22 17:06:42 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-05-22 17:06:42 +0100 |
commit | c4db2be862a2a31361f7e0ff3a0a47e970ec2c48 (patch) | |
tree | bcc40cdf2a3d936c4ac7490dd9bc15c4bc407abb /lib/input | |
parent | Pass linter checks (diff) | |
download | mygrate-c4db2be862a2a31361f7e0ff3a0a47e970ec2c48.tar.bz2 mygrate-c4db2be862a2a31361f7e0ff3a0a47e970ec2c48.tar.xz mygrate-c4db2be862a2a31361f7e0ff3a0a47e970ec2c48.zip |
Wrap up mysql_query
Diffstat (limited to 'lib/input')
-rw-r--r-- | lib/input/mysqlConn.cpp | 10 | ||||
-rw-r--r-- | lib/input/mysqlConn.h | 2 | ||||
-rw-r--r-- | lib/input/replStream.cpp | 5 |
3 files changed, 13 insertions, 4 deletions
diff --git a/lib/input/mysqlConn.cpp b/lib/input/mysqlConn.cpp index 6c00628..3a2c9f4 100644 --- a/lib/input/mysqlConn.cpp +++ b/lib/input/mysqlConn.cpp @@ -1,4 +1,6 @@ #include "mysqlConn.h" +#include "helpers.h" +#include <mysql.h> #include <stdexcept> namespace MyGrate::Input { @@ -11,11 +13,17 @@ namespace MyGrate::Input { mysql_close(this); throw std::runtime_error("ConnectionError"); } - mysql_query(this, "SET NAMES utf8"); + verify<std::runtime_error>(!mysql_set_character_set(this, "utf8"), "Set character set"); } MySQLConn::~MySQLConn() { mysql_close(this); } + + void + MySQLConn::query(const char * const q) + { + verify<std::runtime_error>(!mysql_query(this, q), q); + } } diff --git a/lib/input/mysqlConn.h b/lib/input/mysqlConn.h index fa3712c..2f57f33 100644 --- a/lib/input/mysqlConn.h +++ b/lib/input/mysqlConn.h @@ -8,6 +8,8 @@ namespace MyGrate::Input { public: MySQLConn(const char * const host, const char * const user, const char * const pass, unsigned short port); ~MySQLConn(); + + void query(const char * const); }; } diff --git a/lib/input/replStream.cpp b/lib/input/replStream.cpp index c894941..0de91b5 100644 --- a/lib/input/replStream.cpp +++ b/lib/input/replStream.cpp @@ -3,7 +3,6 @@ #include <eventHandlerBase.h> #include <eventHandlers.h> #include <memory> -#include <mysql.h> #include <stdexcept> #include <utility> @@ -14,8 +13,8 @@ namespace MyGrate::Input { using MariaDB_Rpl_Ptr = std::unique_ptr<MARIADB_RPL, decltype(&mariadb_rpl_close)>; auto rpl = MariaDB_Rpl_Ptr {mariadb_rpl_init(this), &mariadb_rpl_close}; - mysql_query(this, "SET @mariadb_slave_capability = 4"); - mysql_query(this, "SET @master_binlog_checksum = @@global.binlog_checksum"); + query("SET @mariadb_slave_capability = 4"); + query("SET @master_binlog_checksum = @@global.binlog_checksum"); mariadb_rpl_optionsv(rpl.get(), MARIADB_RPL_SERVER_ID, 12); mariadb_rpl_optionsv(rpl.get(), MARIADB_RPL_FILENAME, "mariadb-bin.000242"); |