GetMaxNPCSpellsID converted to QueryDatabase

This commit is contained in:
Arthur Ice 2014-08-18 16:40:45 -07:00
parent 52344bfe24
commit 65cc3a4b0a

View File

@ -2746,30 +2746,23 @@ DBnpcspells_Struct* ZoneDatabase::GetNPCSpells(uint32 iDBSpellsID) {
} }
uint32 ZoneDatabase::GetMaxNPCSpellsID() { uint32 ZoneDatabase::GetMaxNPCSpellsID() {
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"), errbuf, &result)) { std::string query = "SELECT max(id) from npc_spells";
safe_delete_array(query); auto results = QueryDatabase(query);
if (mysql_num_rows(result) == 1) { if (!results.Success()) {
row = mysql_fetch_row(result); std::cerr << "Error in GetMaxNPCSpellsID query '" << query << "' " << results.ErrorMessage() << std::endl;
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 GetMaxNPCSpellsID query '" << query << "' " << errbuf << std::endl;
safe_delete_array(query);
return 0; return 0;
} }
return 0; if (results.RowCount() != 1)
return 0;
auto row = results.begin();
if (!row[0])
return 0;
return atoi(row[0]);
} }
DBnpcspellseffects_Struct* ZoneDatabase::GetNPCSpellsEffects(uint32 iDBSpellsEffectsID) { DBnpcspellseffects_Struct* ZoneDatabase::GetNPCSpellsEffects(uint32 iDBSpellsEffectsID) {