From c4db2be862a2a31361f7e0ff3a0a47e970ec2c48 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 22 May 2021 17:06:42 +0100 Subject: Wrap up mysql_query --- lib/input/mysqlConn.cpp | 10 +++++++++- lib/input/mysqlConn.h | 2 ++ 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 #include 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(!mysql_set_character_set(this, "utf8"), "Set character set"); } MySQLConn::~MySQLConn() { mysql_close(this); } + + void + MySQLConn::query(const char * const q) + { + verify(!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 #include #include -#include #include #include @@ -14,8 +13,8 @@ namespace MyGrate::Input { using MariaDB_Rpl_Ptr = std::unique_ptr; 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"); -- cgit v1.2.3