LoadMercEquipment converted to QueryDatabase

This commit is contained in:
Arthur Ice 2014-08-20 22:00:00 -07:00
parent 2fd2cd4cec
commit 2028a5846c

View File

@ -1606,40 +1606,33 @@ bool ZoneDatabase::DeleteMerc(uint32 merc_id) {
}
void ZoneDatabase::LoadMercEquipment(Merc *merc) {
std::string errorMessage;
char* Query = 0;
char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE];
MYSQL_RES* DatasetResult;
MYSQL_ROW DataRow;
if(!database.RunQuery(Query, MakeAnyLenString(&Query, "SELECT item_id FROM merc_inventory WHERE merc_subtype_id = (SELECT merc_subtype_id FROM merc_subtypes WHERE class_id = '%u' AND tier_id = '%u') AND min_level <= %u AND max_level >= %u", merc->GetClass(), merc->GetTierID(), merc->GetLevel(), merc->GetLevel()), TempErrorMessageBuffer, &DatasetResult)) {
errorMessage = std::string(TempErrorMessageBuffer);
std::string query = StringFormat("SELECT item_id FROM merc_inventory "
"WHERE merc_subtype_id = ("
"SELECT merc_subtype_id FROM merc_subtypes "
"WHERE class_id = '%u' AND tier_id = '%u') "
"AND min_level <= %u AND max_level >= %u",
merc->GetClass(), merc->GetTierID(),
merc->GetLevel(), merc->GetLevel());
auto results = database.QueryDatabase(query);
if(!results.Success()) {
LogFile->write(EQEMuLog::Error, "Error Loading Merc Inventory: %s", results.ErrorMessage().c_str());
return;
}
else {
int itemCount = 0;
while(DataRow = mysql_fetch_row(DatasetResult)) {
int itemCount = 0;
for(auto row = results.begin(); row != results.end(); ++row) {
if (itemCount == EmuConstants::EQUIPMENT_SIZE)
break;
if(atoi(DataRow[0]) > 0) {
merc->AddItem(itemCount, atoi(DataRow[0]));
if(atoi(row[0]) == 0)
continue;
merc->AddItem(itemCount, atoi(row[0]));
itemCount++;
}
}
mysql_free_result(DatasetResult);
}
safe_delete_array(Query);
Query = 0;
if(!errorMessage.empty()) {
LogFile->write(EQEMuLog::Error, "Error Loading Merc Inventory: %s", errorMessage.c_str());
}
}
uint8 ZoneDatabase::GetGridType(uint32 grid, uint32 zoneid ) {
char *query = 0;
char errbuf[MYSQL_ERRMSG_SIZE];