DeleteMerc converted to QueryDatabase

This commit is contained in:
Arthur Ice 2014-08-20 21:54:28 -07:00
parent 17b175daa4
commit 2fd2cd4cec

View File

@ -1582,41 +1582,27 @@ void ZoneDatabase::LoadMercBuffs(Merc *merc) {
} }
bool ZoneDatabase::DeleteMerc(uint32 merc_id) { bool ZoneDatabase::DeleteMerc(uint32 merc_id) {
std::string errorMessage;
bool Result = false;
int TempCounter = 0;
if(merc_id > 0) { if(merc_id == 0)
char* Query = 0; return false;
char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE];
// TODO: These queries need to be ran together as a transaction.. ie, if one or more fail then they all will fail to commit to the database. bool firstQueryWorked = false;
// TODO: These queries need to be ran together as a transaction.. ie,
if(!database.RunQuery(Query, MakeAnyLenString(&Query, "DELETE FROM merc_buffs WHERE MercID = '%u'", merc_id), TempErrorMessageBuffer)) { // if one or more fail then they all will fail to commit to the database.
errorMessage = std::string(TempErrorMessageBuffer); std::string query = StringFormat("DELETE FROM merc_buffs WHERE MercID = '%u'", merc_id);
} auto results = database.QueryDatabase(query);
if(!results.Success())
LogFile->write(EQEMuLog::Error, "Error Deleting Merc: %s", results.ErrorMessage().c_str());
else else
TempCounter++; firstQueryWorked = true;
safe_delete_array(Query); query = StringFormat("DELETE FROM mercs WHERE MercID = '%u'", merc_id);
if(!results.Success()) {
if(!database.RunQuery(Query, MakeAnyLenString(&Query, "DELETE FROM mercs WHERE MercID = '%u'", merc_id), TempErrorMessageBuffer)) { LogFile->write(EQEMuLog::Error, "Error Deleting Merc: %s", results.ErrorMessage().c_str());
errorMessage = std::string(TempErrorMessageBuffer); return false;
}
else
TempCounter++;
safe_delete_array(Query);
if(TempCounter == 2)
Result = true;
} }
if(!errorMessage.empty()) { return firstQueryWorked;
LogFile->write(EQEMuLog::Error, "Error Deleting Merc: %s", errorMessage.c_str());
}
return Result;
} }
void ZoneDatabase::LoadMercEquipment(Merc *merc) { void ZoneDatabase::LoadMercEquipment(Merc *merc) {