Use unique pointer instead of auto-pointer

This commit is contained in:
Esa Korhonen
2018-08-02 17:43:15 +03:00
parent c0bd5ca3a1
commit 0a81f78442
2 changed files with 8 additions and 9 deletions

View File

@ -92,18 +92,18 @@ int64_t MariaDBServer::relay_log_events()
GtidList::MISSING_DOMAIN_LHS_ADD) : 0;
}
std::auto_ptr<QueryResult> MariaDBServer::execute_query(const string& query, std::string* errmsg_out)
std::unique_ptr<QueryResult> MariaDBServer::execute_query(const string& query, std::string* errmsg_out)
{
auto conn = m_server_base->con;
std::auto_ptr<QueryResult> rval;
std::unique_ptr<QueryResult> rval;
MYSQL_RES *result = NULL;
if (mxs_mysql_query(conn, query.c_str()) == 0 && (result = mysql_store_result(conn)) != NULL)
{
rval = std::auto_ptr<QueryResult>(new QueryResult(result));
rval = std::unique_ptr<QueryResult>(new QueryResult(result));
}
else if (errmsg_out)
{
*errmsg_out = string("Query '") + query + "' failed: '" + mysql_error(conn) + "'.";
*errmsg_out = string_printf("Query '%s' failed: '%s'.", query.c_str(), mysql_error(conn));
}
return rval;
}

View File

@ -168,15 +168,14 @@ public:
int64_t relay_log_events();
/**
* Execute a query which returns data. The results are returned as an auto-pointer to a QueryResult
* object.
* Execute a query which returns data. The results are returned as a unique pointer to a QueryResult
* object. The column names of the results are assumed unique.
*
* @param query The query
* @param errmsg_out Where to store an error message if query fails. Can be null.
* @return Pointer to query results, or an empty auto-ptr on failure. Currently, the column names of the
* results are assumed unique.
* @return Pointer to query results, or an empty pointer on failure
*/
std::auto_ptr<QueryResult> execute_query(const std::string& query, std::string* errmsg_out = NULL);
std::unique_ptr<QueryResult> execute_query(const std::string& query, std::string* errmsg_out = NULL);
/**
* Update server slave connection information.