From 85895d01eba715872a2c25f1341381631e632b5f Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Tue, 8 Jul 2014 19:53:17 -0700 Subject: [PATCH] GetAccountIDByChar converted to StringFormat --- common/database.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/common/database.cpp b/common/database.cpp index 8c6396bca..1a30808d8 100644 --- a/common/database.cpp +++ b/common/database.cpp @@ -660,32 +660,27 @@ the name "name" or zero if no character with that name was found Zero will also be returned if there is a database error. */ uint32 Database::GetAccountIDByChar(const char* charname, uint32* oCharID) { - char *query = nullptr; + std::string query = StringFormat("SELECT account_id, id FROM character_ WHERE name='%s'", charname); - auto results = QueryDatabase(query, MakeAnyLenString(&query, "SELECT account_id, id FROM character_ WHERE name='%s'", charname)); + auto results = QueryDatabase(query); if (!results.Success()) { std::cerr << "Error in GetAccountIDByChar query '" << query << "' " << results.ErrorMessage() << std::endl; - safe_delete_array(query); return 0; } - safe_delete_array(query); + if (results.RowCount() != 1) + return 0; - if (results.RowCount() == 1) - { - auto row = results.begin(); + auto row = results.begin(); - uint32 accountId = atoi(row[0]); + uint32 accountId = atoi(row[0]); - if (oCharID) - *oCharID = atoi(row[1]); + if (oCharID) + *oCharID = atoi(row[1]); - return accountId; - } - - return 0; + return accountId; } // Retrieve account_id for a given char_id