From 5ef05d1bb6b224714fb35b55545208343288ac20 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Thu, 3 Jul 2014 17:34:25 -0700 Subject: [PATCH] GetAccountName converted to QueryDatabase --- common/database.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/common/database.cpp b/common/database.cpp index 16c2bf89e..4cdc6f3c0 100644 --- a/common/database.cpp +++ b/common/database.cpp @@ -837,28 +837,29 @@ uint32 Database::GetAccountIDByName(const char* accname, int16* status, uint32* } void Database::GetAccountName(uint32 accountid, char* name, uint32* oLSAccountID) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; + char *query = nullptr; - if (RunQuery(query, MakeAnyLenString(&query, "SELECT name, lsaccount_id FROM account WHERE id='%i'", accountid), errbuf, &result)) { - safe_delete_array(query); - if (mysql_num_rows(result) == 1) { - row = mysql_fetch_row(result); + auto results = QueryDatabase(query, MakeAnyLenString(&query, "SELECT name, lsaccount_id FROM account WHERE id='%i'", accountid)); - strcpy(name, row[0]); - if (row[1] && oLSAccountID) { - *oLSAccountID = atoi(row[1]); - } - } - - mysql_free_result(result); - } - else { - safe_delete_array(query); + if (!results.Success()) + { std::cerr << "Error in GetAccountName query '" << query << "' " << errbuf << std::endl; + safe_delete_array(query); + return; } + + safe_delete_array(query); + + if (results.RowCount() != 1) + return; + + auto row = results.begin(); + + strcpy(name, row[0]); + if (row[1] && oLSAccountID) { + *oLSAccountID = atoi(row[1]); + } + } void Database::GetCharName(uint32 char_id, char* name) {