SaveTimers converted to QueryDatabase

This commit is contained in:
Arthur Ice 2014-09-03 16:22:45 -07:00
parent 89f34246f0
commit 06d1bd632b

View File

@ -2844,30 +2844,28 @@ void Bot::LoadTimers() {
} }
void Bot::SaveTimers() { void Bot::SaveTimers() {
std::string errorMessage; bool hadError = false;
char* Query = 0;
char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE];
if(!database.RunQuery(Query, MakeAnyLenString(&Query, "DELETE FROM bottimers WHERE BotID = %u;", GetBotID()), TempErrorMessageBuffer)) { std::string query = StringFormat("DELETE FROM bottimers WHERE BotID = %u;", GetBotID());
errorMessage = std::string(TempErrorMessageBuffer); auto results = database.QueryDatabase(query);
safe_delete(Query); if(!results.Success())
Query = 0; hadError = true;
for(int timerIndex = 0; timerIndex < MaxTimer; timerIndex++) {
if(timers[timerIndex] <= Timer::GetCurrentTime())
continue;
query = StringFormat("REPLACE INTO bottimers (BotID, TimerID, Value) VALUES(%u, %u, %u);",
GetBotID(), timerIndex+1, timers[timerIndex]);
results = database.QueryDatabase(query);
if(!results.Success())
hadError = true;
} }
for(int i = 0; i < MaxTimer; i++) { if(hadError)
if(timers[i] > Timer::GetCurrentTime()) {
if(!database.RunQuery(Query, MakeAnyLenString(&Query, "REPLACE INTO bottimers (BotID, TimerID, Value) VALUES(%u, %u, %u);", GetBotID(), i+1, timers[i]), TempErrorMessageBuffer)) {
errorMessage = std::string(TempErrorMessageBuffer);
}
safe_delete(Query);
Query = 0;
}
}
if(!errorMessage.empty()) {
LogFile->write(EQEMuLog::Error, "Error in Bot::SaveTimers()"); LogFile->write(EQEMuLog::Error, "Error in Bot::SaveTimers()");
}
} }
bool Bot::Process() bool Bot::Process()