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