diff --git a/client_files/export/main.cpp b/client_files/export/main.cpp index d89976b88..aca5ddc56 100644 --- a/client_files/export/main.cpp +++ b/client_files/export/main.cpp @@ -32,7 +32,7 @@ void ExportBaseData(SharedDatabase *db); int main(int argc, char **argv) { RegisterExecutablePlatform(ExePlatformClientExport); set_exception_handler(); - + LogFile->write(EQEMuLog::Status, "Client Files Export Utility"); if(!EQEmuConfig::LoadConfig()) { LogFile->write(EQEMuLog::Error, "Unable to load configuration file."); @@ -52,11 +52,11 @@ int main(int argc, char **argv) { "database connection"); return 1; } - + ExportSpells(&database); ExportSkillCaps(&database); ExportBaseData(&database); - + return 0; } @@ -69,72 +69,67 @@ void ExportSpells(SharedDatabase *db) { return; } - char errbuf[MYSQL_ERRMSG_SIZE]; - const char *query = "SELECT * FROM spells_new ORDER BY id"; - MYSQL_RES *result; - MYSQL_ROW row; - if(db->RunQuery(query, strlen(query), errbuf, &result)) { - while(row = mysql_fetch_row(result)) { + const std::string query = "SELECT * FROM spells_new ORDER BY id"; + auto results = db->QueryDatabase(query); + + if(results.Success()) { + for (auto row = results.begin(); row != results.end(); ++row) { std::string line; - unsigned int fields = mysql_num_fields(result); + unsigned int fields = results.ColumnCount(); for(unsigned int i = 0; i < fields; ++i) { if(i != 0) { line.push_back('^'); } - + line += row[i]; } - + fprintf(f, "%s\n", line.c_str()); } - mysql_free_result(result); } else { - LogFile->write(EQEMuLog::Error, "Error in ExportSpells query '%s' %s", query, errbuf); + LogFile->write(EQEMuLog::Error, "Error in ExportSpells query '%s' %s", query.c_str(), results.ErrorMessage().c_str()); } - + fclose(f); } bool SkillUsable(SharedDatabase *db, int skill_id, int class_id) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = nullptr; - MYSQL_RES *result; - MYSQL_ROW row; - bool res = false; - if(db->RunQuery(query, MakeAnyLenString(&query, "SELECT max(cap) FROM skill_caps WHERE class=%d AND skillID=%d", - class_id, skill_id), errbuf, &result)) { - if(row = mysql_fetch_row(result)) { - if(row[0] && atoi(row[0]) > 0) { - res = true; - } - } - mysql_free_result(result); - } else { - LogFile->write(EQEMuLog::Error, "Error in skill_usable query '%s' %s", query, errbuf); - } - safe_delete_array(query); - return res; + bool res = false; + + std::string query = StringFormat("SELECT max(cap) FROM skill_caps WHERE class=%d AND skillID=%d", + class_id, skill_id); + auto results = db->QueryDatabase(query); + if(!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error in skill_usable query '%s' %s", query.c_str(), results.ErrorMessage().c_str()); + return false; + } + + if (results.RowCount() == 0) + return false; + + auto row = results.begin(); + if(row[0] && atoi(row[0]) > 0) + return true; + + return false; } int GetSkill(SharedDatabase *db, int skill_id, int class_id, int level) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = nullptr; - MYSQL_RES *result; - MYSQL_ROW row; - int res = 0; - if(db->RunQuery(query, MakeAnyLenString(&query, "SELECT cap FROM skill_caps WHERE class=%d AND skillID=%d AND level=%d", - class_id, skill_id, level), errbuf, &result)) { - if(row = mysql_fetch_row(result)) { - res = atoi(row[0]); - } - mysql_free_result(result); - } else { - LogFile->write(EQEMuLog::Error, "Error in get_skill query '%s' %s", query, errbuf); - } - safe_delete_array(query); - return res; + std::string query = StringFormat("SELECT cap FROM skill_caps WHERE class=%d AND skillID=%d AND level=%d", + class_id, skill_id, level); + auto results = db->QueryDatabase(query); + if (!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error in get_skill query '%s' %s", query.c_str(), results.ErrorMessage().c_str()); + return 0; + } + + if (results.RowCount() == 0) + return 0; + + auto row = results.begin(); + return atoi(row[0]); } void ExportSkillCaps(SharedDatabase *db) { @@ -175,27 +170,23 @@ void ExportBaseData(SharedDatabase *db) { return; } - char errbuf[MYSQL_ERRMSG_SIZE]; - const char *query = "SELECT * FROM base_data ORDER BY level, class"; - MYSQL_RES *result; - MYSQL_ROW row; - if(db->RunQuery(query, strlen(query), errbuf, &result)) { - while(row = mysql_fetch_row(result)) { + const std::string query = "SELECT * FROM base_data ORDER BY level, class"; + auto results = db->QueryDatabase(query); + if(results.Success()) { + for (auto row = results.begin();row != results.end();++row) { std::string line; - unsigned int fields = mysql_num_fields(result); - for(unsigned int i = 0; i < fields; ++i) { - if(i != 0) { + unsigned int fields = results.ColumnCount(); + for(unsigned int rowIndex = 0; rowIndex < fields; ++rowIndex) { + if(rowIndex != 0) line.push_back('^'); - } - line += row[i]; + line += row[rowIndex]; } fprintf(f, "%s\n", line.c_str()); } - mysql_free_result(result); } else { - LogFile->write(EQEMuLog::Error, "Error in ExportBaseData query '%s' %s", query, errbuf); + LogFile->write(EQEMuLog::Error, "Error in ExportBaseData query '%s' %s", query.c_str(), results.ErrorMessage().c_str()); } fclose(f);