LoadBotGroup converted to QueryDatabase

This commit is contained in:
Arthur Ice 2014-09-03 17:52:06 -07:00
parent 96cf3d967f
commit 38d04931ba

View File

@ -4744,44 +4744,32 @@ void Bot::DeleteBotGroup(std::string botGroupName, std::string* errorMessage) {
} }
std::list<BotGroup> Bot::LoadBotGroup(std::string botGroupName, std::string* errorMessage) { std::list<BotGroup> Bot::LoadBotGroup(std::string botGroupName, std::string* errorMessage) {
std::list<BotGroup> Result; std::list<BotGroup> botGroup;
char ErrBuf[MYSQL_ERRMSG_SIZE];
char* Query = 0;
MYSQL_RES* DatasetResult;
MYSQL_ROW DataRow;
if(!botGroupName.empty()) { if(botGroupName.empty())
uint32 botGroupId = GetBotGroupIdByBotGroupName(botGroupName, errorMessage); return botGroup;
if(botGroupId > 0) { uint32 botGroupId = GetBotGroupIdByBotGroupName(botGroupName, errorMessage);
if(!database.RunQuery(Query, MakeAnyLenString(&Query, "select BotId from botgroupmembers where BotGroupId = %u", botGroupId), ErrBuf, &DatasetResult)) {
*errorMessage = std::string(ErrBuf);
}
else {
uint32 RowCount = mysql_num_rows(DatasetResult);
if(RowCount > 0) { if(botGroupId == 0)
for(int iCounter = 0; iCounter < RowCount; iCounter++) { return botGroup;
DataRow = mysql_fetch_row(DatasetResult);
if(DataRow) { std::string query = StringFormat("SELECT BotId FROM botgroupmembers WHERE BotGroupId = %u", botGroupId);
BotGroup tempBotGroup; auto results = database.QueryDatabase(query);
tempBotGroup.BotGroupID = botGroupId; if(!results.Success()) {
tempBotGroup.BotID = atoi(DataRow[0]); *errorMessage = std::string(results.ErrorMessage());
return botGroup;
}
Result.push_back(tempBotGroup); for(auto row = results.begin(); row != results.end(); ++row) {
} BotGroup tempBotGroup;
} tempBotGroup.BotGroupID = botGroupId;
} tempBotGroup.BotID = atoi(row[0]);
mysql_free_result(DatasetResult); botGroup.push_back(tempBotGroup);
} }
safe_delete_array(Query); return botGroup;
}
}
return Result;
} }
std::list<BotGroupList> Bot::GetBotGroupListByBotOwnerCharacterId(uint32 botOwnerCharacterId, std::string* errorMessage) { std::list<BotGroupList> Bot::GetBotGroupListByBotOwnerCharacterId(uint32 botOwnerCharacterId, std::string* errorMessage) {