Merge pull request #192 from addtheice/RunQueryToDatabaseQuery_EQW

Run query to database query eqw
This commit is contained in:
Alex 2014-08-20 21:03:44 -07:00
commit d5a5635a14

View File

@ -384,49 +384,41 @@ bool EQW::SetPublicNote(uint32 charid, const char *note) {
} }
int EQW::CountBugs() { int EQW::CountBugs() {
char errbuf[MYSQL_ERRMSG_SIZE]; std::string query = "SELECT count(*) FROM bugs where status = 0";
char* query = 0; auto results = database.QueryDatabase(query);
MYSQL_RES *result; if (!results.Success())
MYSQL_ROW row;
if(database.RunQuery(query, MakeAnyLenString(&query, "SELECT count(*) FROM bugs where status = 0"), errbuf, &result)) {
safe_delete_array(query);
if((row = mysql_fetch_row(result))) {
int count = atoi(row[0]);
mysql_free_result(result);
return count;
}
mysql_free_result(result);
}
safe_delete_array(query);
return 0; return 0;
if (results.RowCount() == 0)
return 0;
auto row = results.begin();
return atoi(row[0]);
} }
std::vector<std::string> EQW::ListBugs(uint32 offset) { std::vector<std::string> EQW::ListBugs(uint32 offset) {
std::vector<std::string> res; std::vector<std::string> res;
char errbuf[MYSQL_ERRMSG_SIZE]; std::string query = StringFormat("SELECT id FROM bugs WHERE status = 0 limit %d, 30", offset);
char* query = 0; auto results = database.QueryDatabase(query);
MYSQL_RES *result;
MYSQL_ROW row; if (!results.Success())
if(database.RunQuery(query, MakeAnyLenString(&query, "SELECT id FROM bugs WHERE status = 0 limit %d, 30", offset), errbuf, &result)) { return res;
safe_delete_array(query);
while((row = mysql_fetch_row(result))) { for (auto row = results.begin();row != results.end(); ++row)
res.push_back(row[0]); res.push_back(row[0]);
}
mysql_free_result(result);
}
safe_delete_array(query);
return res; return res;
} }
std::map<std::string,std::string> EQW::GetBugDetails(Const_char *id) { std::map<std::string,std::string> EQW::GetBugDetails(Const_char *id) {
std::map<std::string,std::string> res; std::map<std::string,std::string> res;
char errbuf[MYSQL_ERRMSG_SIZE]; std::string query = StringFormat("SELECT name, zone, x, y, z, target, bug FROM bugs WHERE id = %s", id);
char* query = 0; auto results = database.QueryDatabase(query);
MYSQL_RES *result;
MYSQL_ROW row; if (!results.Success())
if(database.RunQuery(query, MakeAnyLenString(&query, "select name, zone, x, y, z, target, bug from bugs where id = %s", id), errbuf, &result)) { return res;
safe_delete_array(query);
while((row = mysql_fetch_row(result))) { for(auto row = results.begin(); row != results.end(); ++row) {
res["name"] = row[0]; res["name"] = row[0];
res["zone"] = row[1]; res["zone"] = row[1];
res["x"] = row[2]; res["x"] = row[2];
@ -436,20 +428,13 @@ std::map<std::string,std::string> EQW::GetBugDetails(Const_char *id) {
res["bug"] = row[6]; res["bug"] = row[6];
res["id"] = id; res["id"] = id;
} }
mysql_free_result(result);
}
safe_delete_array(query);
return res; return res;
} }
void EQW::ResolveBug(const char *id) { void EQW::ResolveBug(const char *id) {
std::vector<std::string> res; std::vector<std::string> res;
char errbuf[MYSQL_ERRMSG_SIZE]; std::string query = StringFormat("UPDATE bugs SET status=1 WHERE id=%s", id);
char* query = 0; database.QueryDatabase(query);
if(database.RunQuery(query, MakeAnyLenString(&query, "UPDATE bugs SET status=1 WHERE id=%s", id), errbuf)) {
safe_delete_array(query);
}
safe_delete_array(query);
} }
void EQW::SendMessage(uint32 type, const char *msg) { void EQW::SendMessage(uint32 type, const char *msg) {