2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-05 00:15:17 +00:00

[2821] Move MySqlHolder to header, and use as member

Half-related change, if available, call mysql_library_end() at the end of the unit test run
This commit is contained in:
Jelte Jansen
2013-03-07 15:48:51 +01:00
parent 21dae0aa02
commit e58c2fd32c
3 changed files with 36 additions and 44 deletions

View File

@@ -26,6 +26,30 @@
namespace isc {
namespace dhcp {
/// Small RAII object for safer initialization, will close the database
/// connection upon destruction
class MySqlHolder {
public:
MySqlHolder() : mysql_(mysql_init(NULL)) {
if (mysql_ == NULL) {
isc_throw(DbOpenError, "unable to initialize MySQL");
}
}
~MySqlHolder() {
if (mysql_) {
mysql_close(mysql_);
}
}
operator MYSQL*() const {
return (mysql_);
}
private:
MYSQL* mysql_;
};
// Define the current database schema values
const uint32_t CURRENT_VERSION_VERSION = 1;
@@ -379,7 +403,7 @@ public:
/// @param cltt Reference to location where client last transmit time
/// is put.
static
void convertFromDatabaseTime(const MYSQL_TIME& expire,
void convertFromDatabaseTime(const MYSQL_TIME& expire,
uint32_t valid_lifetime, time_t& cltt);
///@}
@@ -616,7 +640,7 @@ private:
/// declare them as "mutable".)
boost::scoped_ptr<MySqlLease4Exchange> exchange4_; ///< Exchange object
boost::scoped_ptr<MySqlLease6Exchange> exchange6_; ///< Exchange object
MYSQL* mysql_; ///< MySQL context object
MySqlHolder mysql_;
std::vector<MYSQL_STMT*> statements_; ///< Prepared statements
std::vector<std::string> text_statements_; ///< Raw text of statements
};