From d73449104a73a449183089cfe530ed6f2800501e Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Mon, 18 Aug 2014 17:00:37 -0700 Subject: [PATCH] GetMaxNPCSpellsEffectsID converted to QueryDatabase --- zone/MobAI.cpp | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/zone/MobAI.cpp b/zone/MobAI.cpp index b0a13b7a7..021d6f76b 100644 --- a/zone/MobAI.cpp +++ b/zone/MobAI.cpp @@ -2833,29 +2833,21 @@ DBnpcspellseffects_Struct* ZoneDatabase::GetNPCSpellsEffects(uint32 iDBSpellsEff } uint32 ZoneDatabase::GetMaxNPCSpellsEffectsID() { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - if (RunQuery(query, MakeAnyLenString(&query, "SELECT max(id) from npc_spells_effects"), errbuf, &result)) { - safe_delete_array(query); - if (mysql_num_rows(result) == 1) { - row = mysql_fetch_row(result); - uint32 ret = 0; - if (row[0]) - ret = atoi(row[0]); - mysql_free_result(result); - return ret; - } - mysql_free_result(result); - } - else { - std::cerr << "Error in GetMaxNPCSpellsEffectsID query '" << query << "' " << errbuf << std::endl; - safe_delete_array(query); + std::string query = "SELECT max(id) FROM npc_spells_effects"; + auto results = QueryDatabase(query); + if (!results.Success()) { + std::cerr << "Error in GetMaxNPCSpellsEffectsID query '" << query << "' " << results.ErrorMessage() << std::endl; return 0; } - return 0; + if (results.RowCount() != 1) + return 0; + + auto row = results.begin(); + if (!row[0]) + return 0; + + return atoi(row[0]); }