Commit 62fd2020 authored by Francis Dupont's avatar Francis Dupont

[#1008] Addressed comments

parent c131e65e
...@@ -229,52 +229,65 @@ MySqlConnection::getVersion(const ParameterMap& parameters) { ...@@ -229,52 +229,65 @@ MySqlConnection::getVersion(const ParameterMap& parameters) {
"statement structure, reason: " << mysql_error(conn.mysql_)); "statement structure, reason: " << mysql_error(conn.mysql_));
} }
// Prepare the statement from SQL text. try {
const char* version_sql = "SELECT version, minor FROM schema_version";
int status = mysql_stmt_prepare(stmt, version_sql, strlen(version_sql));
if (status != 0) {
isc_throw(DbOperationError, "unable to prepare MySQL statement <"
<< version_sql << ">, reason: " << mysql_error(conn.mysql_));
}
// Execute the prepared statement. // Prepare the statement from SQL text.
if (mysql_stmt_execute(stmt) != 0) { const char* version_sql = "SELECT version, minor FROM schema_version";
isc_throw(DbOperationError, "cannot execute schema version query <" int status = mysql_stmt_prepare(stmt, version_sql, strlen(version_sql));
<< version_sql << ">, reason: " << mysql_errno(conn.mysql_)); if (status != 0) {
} isc_throw(DbOperationError, "unable to prepare MySQL statement <"
<< version_sql << ">, reason: "
<< mysql_error(conn.mysql_));
}
// Bind the output of the statement to the appropriate variables. // Execute the prepared statement.
MYSQL_BIND bind[2]; if (mysql_stmt_execute(stmt) != 0) {
memset(bind, 0, sizeof(bind)); isc_throw(DbOperationError, "cannot execute schema version query <"
<< version_sql << ">, reason: "
uint32_t major; << mysql_errno(conn.mysql_));
bind[0].buffer_type = MYSQL_TYPE_LONG; }
bind[0].is_unsigned = 1;
bind[0].buffer = &major;
bind[0].buffer_length = sizeof(major);
uint32_t minor;
bind[1].buffer_type = MYSQL_TYPE_LONG;
bind[1].is_unsigned = 1;
bind[1].buffer = &minor;
bind[1].buffer_length = sizeof(minor);
if (mysql_stmt_bind_result(stmt, bind)) {
isc_throw(DbOperationError, "unable to bind result set for <"
<< version_sql << ">, reason: " << mysql_errno(conn.mysql_));
}
// Fetch the data. // Bind the output of the statement to the appropriate variables.
if (mysql_stmt_fetch(stmt)) { MYSQL_BIND bind[2];
memset(bind, 0, sizeof(bind));
uint32_t major;
bind[0].buffer_type = MYSQL_TYPE_LONG;
bind[0].is_unsigned = 1;
bind[0].buffer = &major;
bind[0].buffer_length = sizeof(major);
uint32_t minor;
bind[1].buffer_type = MYSQL_TYPE_LONG;
bind[1].is_unsigned = 1;
bind[1].buffer = &minor;
bind[1].buffer_length = sizeof(minor);
if (mysql_stmt_bind_result(stmt, bind)) {
isc_throw(DbOperationError, "unable to bind result set for <"
<< version_sql << ">, reason: "
<< mysql_errno(conn.mysql_));
}
// Fetch the data.
if (mysql_stmt_fetch(stmt)) {
isc_throw(DbOperationError, "unable to bind result set for <"
<< version_sql << ">, reason: "
<< mysql_errno(conn.mysql_));
}
// Discard the statement and its resources
mysql_stmt_close(stmt); mysql_stmt_close(stmt);
isc_throw(DbOperationError, "unable to bind result set for <"
<< version_sql << ">, reason: " << mysql_errno(conn.mysql_));
}
// Discard the statement and its resources return (std::make_pair(major, minor));
mysql_stmt_close(stmt);
return (std::make_pair(major, minor)); } catch (const std::exception&) {
// Avoid a memory leak on error.
mysql_stmt_close(stmt);
// Send the exception to the caller.
throw;
}
} }
// Prepared statement setup. The textual form of an SQL statement is stored // Prepared statement setup. The textual form of an SQL statement is stored
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment