}
MySqlConfigBackendImpl::~MySqlConfigBackendImpl() {
- // Free up the prepared statements, ignoring errors. (What would we do
- // about them? We're destroying this object and are not really concerned
- // with errors on a database connection that is about to go away.)
- for (int i = 0; i < conn_.handle().statements_.size(); ++i) {
- if (conn_.handle().statements_[i] != NULL) {
- (void) mysql_stmt_close(conn_.handle().statements_[i]);
- conn_.handle().statements_[i] = NULL;
- }
- }
}
MySqlBindingPtr
}
MySqlHostDataSourceImpl::~MySqlHostDataSourceImpl() {
- // Free up the prepared statements, ignoring errors. (What would we do
- // about them? We're destroying this object and are not really concerned
- // with errors on a database connection that is about to go away.)
- for (int i = 0; i < conn_.handle().statements_.size(); ++i) {
- if (conn_.handle().statements_[i] != NULL) {
- (void) mysql_stmt_close(conn_.handle().statements_[i]);
- conn_.handle().statements_[i] = NULL;
- }
- }
-
- // There is no need to close the database in this destructor: it is
- // closed in the destructor of the mysql_ member variable.
}
std::pair<uint32_t, uint32_t>
if (status != 0) {
mysql_stmt_close(stmt);
isc_throw(DbOperationError, "unable to prepare MySQL statement <"
- << version_sql << ">, reason: " << mysql_errno(conn_.handle()));
+ << version_sql << ">, reason: " << mysql_error(conn_.handle()));
}
// Execute the prepared statement.
if (mysql_stmt_execute(stmt) != 0) {
mysql_stmt_close(stmt);
isc_throw(DbOperationError, "cannot execute schema version query <"
- << version_sql << ">, reason: " << mysql_errno(conn_.handle()));
+ << version_sql << ">, reason: " << mysql_error(conn_.handle()));
}
// Bind the output of the statement to the appropriate variables.
if (mysql_stmt_bind_result(stmt, bind)) {
isc_throw(DbOperationError, "unable to bind result set for <"
- << version_sql << ">, reason: " << mysql_errno(conn_.handle()));
+ << version_sql << ">, reason: " << mysql_error(conn_.handle()));
}
// Fetch the data.
if (mysql_stmt_fetch(stmt)) {
mysql_stmt_close(stmt);
isc_throw(DbOperationError, "unable to bind result set for <"
- << version_sql << ">, reason: " << mysql_errno(conn_.handle()));
+ << version_sql << ">, reason: " << mysql_error(conn_.handle()));
}
// Discard the statement and its resources
return (std::make_pair(major, minor));
}
-
void
MySqlHostDataSourceImpl::addStatement(StatementIndex stindex,
std::vector<MYSQL_BIND>& bind) {
MYSQL_STMT *stmt = mysql_stmt_init(conn_.handle());
if (stmt == NULL) {
isc_throw(DbOperationError, "unable to allocate MySQL prepared "
- "statement structure, reason: " << mysql_error(conn_.handle()));
+ "statement structure, reason: " << mysql_error(conn_.handle()));
}
// Prepare the statement from SQL text.
const char* version_sql = "SELECT version, minor FROM schema_version";
int status = mysql_stmt_prepare(stmt, version_sql, strlen(version_sql));
if (status != 0) {
+ mysql_stmt_close(stmt);
isc_throw(DbOperationError, "unable to prepare MySQL statement <"
<< version_sql << ">, reason: " << mysql_error(conn_.handle()));
}
// Execute the prepared statement.
if (mysql_stmt_execute(stmt) != 0) {
+ mysql_stmt_close(stmt);
isc_throw(DbOperationError, "cannot execute schema version query <"
- << version_sql << ">, reason: " << mysql_errno(conn_.handle()));
+ << version_sql << ">, reason: " << mysql_error(conn_.handle()));
}
// Bind the output of the statement to the appropriate variables.
if (mysql_stmt_bind_result(stmt, bind)) {
isc_throw(DbOperationError, "unable to bind result set for <"
- << version_sql << ">, reason: " << mysql_errno(conn_.handle()));
+ << version_sql << ">, reason: " << mysql_error(conn_.handle()));
}
// Fetch the data.
if (mysql_stmt_fetch(stmt)) {
mysql_stmt_close(stmt);
isc_throw(DbOperationError, "unable to bind result set for <"
- << version_sql << ">, reason: " << mysql_errno(conn_.handle()));
+ << version_sql << ">, reason: " << mysql_error(conn_.handle()));
}
// Discard the statement and its resources
return (result);
}
-std::pair<uint32_t, uint32_t> PgSqlHostDataSourceImpl::getVersion() const {
+pair<uint32_t, uint32_t>
+PgSqlHostDataSourceImpl::getVersion() const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
DHCPSRV_PGSQL_HOST_DB_GET_VERSION);
+
const char* version_sql = "SELECT version, minor FROM schema_version;";
PgSqlResult r(PQexec(conn_.handle(), version_sql));
if(PQresultStatus(r) != PGRES_TUPLES_OK) {
<< version_sql << ">, reason: " << PQerrorMessage(conn_.handle()));
}
- uint32_t version;
- PgSqlExchange::getColumnValue(r, 0, 0, version);
+ uint32_t major;
+ PgSqlExchange::getColumnValue(r, 0, 0, major);
uint32_t minor;
PgSqlExchange::getColumnValue(r, 0, 1, minor);
- return (std::make_pair(version, minor));
+ return (make_pair(major, minor));
}
void
PgSqlResult r(PQexec(conn_.handle(), version_sql));
if(PQresultStatus(r) != PGRES_TUPLES_OK) {
isc_throw(DbOperationError, "unable to execute PostgreSQL statement <"
- << version_sql << ", reason: " << PQerrorMessage(conn_.handle()));
+ << version_sql << ">, reason: " << PQerrorMessage(conn_.handle()));
}
uint32_t major;