mysql> GRANT ALL ON keatest.* TO 'keatest'@'localhost';
mysql> GRANT SELECT ON keatest.* TO 'keatest_readonly'@'localhost';
mysql>@endverbatim\n
+ -# If you get <i>You do not have the SUPER privilege and binary logging is
+ enabled</i> error message, you need to add:
+ @verbatim
+ mysql> SET GLOBAL LOG_BIN_TRUST_FUNCTION_CREATORS = 1;
+ mysql>@endverbatim\n
-# Exit MySQL:
@verbatim
mysql> quit
/// 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<MYSQL_BIND>& bind,
- std::vector<my_bool>& error) {
+ std::vector<my_bools>& error) {
for (size_t i = 0; i < error.size(); ++i) {
error[i] = MLM_FALSE;
+#ifdef HAVE_MYSQL_MY_BOOL
bind[i].error = reinterpret_cast<char*>(&error[i]);
+#else
+ bind[i].error = reinterpret_cast<bool*>(&error[i]);
+#endif
}
};
/// 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<my_bool>& error,
+ static std::string getColumnsInError(std::vector<my_bools>& error,
const std::vector<std::string>& names) {
std::string result = "";
std::vector<std::string> columns_;
/// Error array.
- std::vector<my_bool> error_;
+ std::vector<my_bools> error_;
/// Pointer to Host object holding information to be inserted into
/// Hosts table.
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<char*>(&error[i]);
+#else
+ bind[i].error = &error[i];
+#endif
}
}
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
/// @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");
}
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
}
private:
- MYSQL* mysql_; ///< Initialization context
+ static bool atexit_; ///< Flag to call atexit once.
+
+ MYSQL* mysql_; ///< Initialization context
};
/// @brief Forward declaration to @ref MySqlConnection.
//@{
#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;
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<my_bool> is specialized into a bitset.
+typedef char my_bools;
+
/// @brief MySQL false value.
const my_bool MLM_FALSE = false;