GetBook converted to QueryDatabase

This commit is contained in:
Arthur Ice 2014-10-04 14:07:55 -07:00
parent 2a73a572d3
commit 0ef428d286

View File

@ -1015,35 +1015,28 @@ const Item_Struct* SharedDatabase::IterateItems(uint32* id) {
std::string SharedDatabase::GetBook(const char *txtfile) std::string SharedDatabase::GetBook(const char *txtfile)
{ {
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
MYSQL_RES *result;
MYSQL_ROW row;
char txtfile2[20]; char txtfile2[20];
std::string txtout; std::string txtout;
strcpy(txtfile2,txtfile); strcpy(txtfile2, txtfile);
if (!RunQuery(query, MakeAnyLenString(&query, "SELECT txtfile FROM books where name='%s'", txtfile2), errbuf, &result)) {
std::cerr << "Error in GetBook query '" << query << "' " << errbuf << std::endl; std::string query = StringFormat("SELECT txtfile FROM books WHERE name = '%s'", txtfile2);
if (query != 0) auto results = QueryDatabase(query);
safe_delete_array(query); if (!results.Success()) {
std::cerr << "Error in GetBook query '" << query << "' " << results.ErrorMessage() << std::endl;
txtout.assign(" ",1); txtout.assign(" ",1);
return txtout; return txtout;
} }
else {
safe_delete_array(query); if (results.RowCount() == 0) {
if (mysql_num_rows(result) == 0) { LogFile->write(EQEMuLog::Error, "No book to send, (%s)", txtfile);
mysql_free_result(result); txtout.assign(" ",1);
LogFile->write(EQEMuLog::Error, "No book to send, (%s)", txtfile); return txtout;
txtout.assign(" ",1); }
return txtout;
} auto row = results.begin();
else { txtout.assign(row[0],strlen(row[0]));
row = mysql_fetch_row(result);
txtout.assign(row[0],strlen(row[0])); return txtout;
mysql_free_result(result);
return txtout;
}
}
} }
void SharedDatabase::GetFactionListInfo(uint32 &list_count, uint32 &max_lists) { void SharedDatabase::GetFactionListInfo(uint32 &list_count, uint32 &max_lists) {