diff --git a/doc/devel/unit-tests.dox b/doc/devel/unit-tests.dox
index cf39648134..937502ed82 100644
--- a/doc/devel/unit-tests.dox
+++ b/doc/devel/unit-tests.dox
@@ -101,6 +101,11 @@ The following environment variable can affect the unit tests:
mysql> GRANT ALL ON keatest.* TO 'keatest'@'localhost';
mysql> GRANT SELECT ON keatest.* TO 'keatest_readonly'@'localhost';
mysql>@endverbatim\n
+ -# If you get You do not have the SUPER privilege and binary logging is
+ enabled error message, you need to add:
+ @verbatim
+ mysql> SET GLOBAL LOG_BIN_TRUST_FUNCTION_CREATORS = 1;
+ mysql>@endverbatim\n
-# Exit MySQL:
@verbatim
mysql> quit
diff --git a/src/lib/dhcpsrv/mysql_host_data_source.cc b/src/lib/dhcpsrv/mysql_host_data_source.cc
index d6c63585db..75e2d17e18 100644
--- a/src/lib/dhcpsrv/mysql_host_data_source.cc
+++ b/src/lib/dhcpsrv/mysql_host_data_source.cc
@@ -220,10 +220,14 @@ public:
/// data associated with one of the "bind" elements, the
/// corresponding element in the error array is set to MLM_TRUE.
static void setErrorIndicators(std::vector& bind,
- std::vector& error) {
+ std::vector& error) {
for (size_t i = 0; i < error.size(); ++i) {
error[i] = MLM_FALSE;
+#ifdef HAVE_MYSQL_MY_BOOL
bind[i].error = reinterpret_cast(&error[i]);
+#else
+ bind[i].error = reinterpret_cast(&error[i]);
+#endif
}
};
@@ -240,7 +244,7 @@ public:
/// the error.
/// @param names Array of column names, the same size as the error array.
/// @param count Size of each of the arrays.
- static std::string getColumnsInError(std::vector& error,
+ static std::string getColumnsInError(std::vector& error,
const std::vector& names) {
std::string result = "";
@@ -723,7 +727,7 @@ protected:
std::vector columns_;
/// Error array.
- std::vector error_;
+ std::vector error_;
/// Pointer to Host object holding information to be inserted into
/// Hosts table.
diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.cc b/src/lib/dhcpsrv/mysql_lease_mgr.cc
index a663e781af..ef41e92e04 100644
--- a/src/lib/dhcpsrv/mysql_lease_mgr.cc
+++ b/src/lib/dhcpsrv/mysql_lease_mgr.cc
@@ -336,7 +336,11 @@ public:
size_t count) {
for (size_t i = 0; i < count; ++i) {
error[i] = MLM_FALSE;
+#ifdef HAVE_MYSQL_MY_BOOL
bind[i].error = reinterpret_cast(&error[i]);
+#else
+ bind[i].error = &error[i];
+#endif
}
}
diff --git a/src/lib/mysql/mysql_connection.cc b/src/lib/mysql/mysql_connection.cc
index e51a61f13c..0e9f001d5b 100644
--- a/src/lib/mysql/mysql_connection.cc
+++ b/src/lib/mysql/mysql_connection.cc
@@ -23,6 +23,8 @@ using namespace std;
namespace isc {
namespace db {
+bool MySqlHolder::atexit_ = false;
+
/// @todo: Migrate this default value to src/bin/dhcpX/simple_parserX.cc
const int MYSQL_DEFAULT_CONNECTION_TIMEOUT = 5; // seconds
diff --git a/src/lib/mysql/mysql_connection.h b/src/lib/mysql/mysql_connection.h
index 82ce504cf1..183934ca59 100644
--- a/src/lib/mysql/mysql_connection.h
+++ b/src/lib/mysql/mysql_connection.h
@@ -92,10 +92,15 @@ public:
/// @brief Constructor
///
+ /// Push a call to mysql_library_end() at exit time.
/// Initialize MySql and store the associated context object.
///
/// @throw DbOpenError Unable to initialize MySql handle.
MySqlHolder() : mysql_(mysql_init(NULL)) {
+ if (!atexit_) {
+ atexit([]{ mysql_library_end(); });
+ atexit_ = true;
+ }
if (mysql_ == NULL) {
isc_throw(db::DbOpenError, "unable to initialize MySQL");
}
@@ -108,8 +113,7 @@ public:
if (mysql_ != NULL) {
mysql_close(mysql_);
}
- // The library itself shouldn't be needed anymore
- mysql_library_end();
+ // @note Moved the call to mysql_library_end() to atexit.
}
/// @brief Conversion Operator
@@ -121,7 +125,9 @@ public:
}
private:
- MYSQL* mysql_; ///< Initialization context
+ static bool atexit_; ///< Flag to call atexit once.
+
+ MYSQL* mysql_; ///< Initialization context
};
/// @brief Forward declaration to @ref MySqlConnection.
diff --git a/src/lib/mysql/mysql_constants.h b/src/lib/mysql/mysql_constants.h
index 64b052017c..a18c4e027c 100644
--- a/src/lib/mysql/mysql_constants.h
+++ b/src/lib/mysql/mysql_constants.h
@@ -17,6 +17,9 @@ namespace db {
//@{
#ifdef HAVE_MYSQL_MY_BOOL
+/// @brief my_bools type for vectors.
+typedef my_bool my_bools;
+
/// @brief MySQL false value.
const my_bool MLM_FALSE = 0;
@@ -24,9 +27,13 @@ const my_bool MLM_FALSE = 0;
const my_bool MLM_TRUE = 1;
#else
-/// @brief my_bool type for MySQL 8.x.
+/// @brief my_bool type in MySQL 8.x.
typedef bool my_bool;
+/// @brief my_bools type for vectors in MySQL 8.x.
+/// @note vector is specialized into a bitset.
+typedef char my_bools;
+
/// @brief MySQL false value.
const my_bool MLM_FALSE = false;