From b7bcd13cbd9ffb25fedcf572cf16ba126a320489 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Mon, 18 Aug 2014 14:02:16 -0700 Subject: [PATCH 1/4] GetSpellColumns converted to QueryDatabase --- client_files/import/main.cpp | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/client_files/import/main.cpp b/client_files/import/main.cpp index 0bbbaa3fd..93a07e7c2 100644 --- a/client_files/import/main.cpp +++ b/client_files/import/main.cpp @@ -31,7 +31,7 @@ void ImportBaseData(SharedDatabase *db); int main(int argc, char **argv) { RegisterExecutablePlatform(ExePlatformClientImport); set_exception_handler(); - + LogFile->write(EQEMuLog::Status, "Client Files Import Utility"); if(!EQEmuConfig::LoadConfig()) { LogFile->write(EQEMuLog::Error, "Unable to load configuration file."); @@ -55,26 +55,20 @@ int main(int argc, char **argv) { ImportSpells(&database); ImportSkillCaps(&database); ImportBaseData(&database); - + return 0; } int GetSpellColumns(SharedDatabase *db) { - char errbuf[MYSQL_ERRMSG_SIZE]; - const char *query = "DESCRIBE spells_new"; - MYSQL_RES *result; - MYSQL_ROW row; - int res = 0; - if(db->RunQuery(query, (uint32)strlen(query), errbuf, &result)) { - while(row = mysql_fetch_row(result)) { - ++res; - } - mysql_free_result(result); - } else { - LogFile->write(EQEMuLog::Error, "Error in GetSpellColumns query '%s' %s", query, errbuf); - } - return res; + const std::string query = "DESCRIBE spells_new"; + auto results = db->QueryDatabase(query); + if(!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error in GetSpellColumns query '%s' %s", query.c_str(), results.ErrorMessage().c_str()); + return 0; + } + + return results.RowCount(); } void ImportSpells(SharedDatabase *db) { @@ -104,7 +98,7 @@ void ImportSpells(SharedDatabase *db) { auto split = SplitString(escaped, '^'); int line_columns = (int)split.size(); std::string sql; - + if(line_columns >= columns) { sql = "INSERT INTO spells_new VALUES("; for(int i = 0; i < columns; ++i) { @@ -170,12 +164,12 @@ void ImportSkillCaps(SharedDatabase *db) { char buffer[2048]; while(fgets(buffer, 2048, f)) { auto split = SplitString(buffer, '^'); - + if(split.size() < 4) { continue; } - + int class_id, skill_id, level, cap; class_id = atoi(split[0].c_str()); skill_id = atoi(split[1].c_str()); From 503a2c0d04149413fab18fb04fad06b93ed7d383 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Mon, 18 Aug 2014 14:03:53 -0700 Subject: [PATCH 2/4] ImportSpells converted to QueryDatabase --- client_files/import/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client_files/import/main.cpp b/client_files/import/main.cpp index 93a07e7c2..3547b4062 100644 --- a/client_files/import/main.cpp +++ b/client_files/import/main.cpp @@ -79,8 +79,8 @@ void ImportSpells(SharedDatabase *db) { return; } - std::string delete_sql = "DELETE FROM spells_new"; - db->RunQuery(delete_sql.c_str(), (uint32)delete_sql.length()); + std::string query = "DELETE FROM spells_new"; + db->QueryDatabase(query); int columns = GetSpellColumns(db); int spells_imported = 0; @@ -97,8 +97,8 @@ void ImportSpells(SharedDatabase *db) { std::string escaped = ::EscapeString(buffer); auto split = SplitString(escaped, '^'); int line_columns = (int)split.size(); - std::string sql; + std::string sql; if(line_columns >= columns) { sql = "INSERT INTO spells_new VALUES("; for(int i = 0; i < columns; ++i) { @@ -134,7 +134,7 @@ void ImportSpells(SharedDatabase *db) { sql += ");"; } - db->RunQuery(sql.c_str(), (uint32)sql.length()); + db->QueryDatabase(sql); spells_imported++; if(spells_imported % 1000 == 0) { From ad987c55315def4235daab04a09022010df35c1b Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Mon, 18 Aug 2014 14:05:06 -0700 Subject: [PATCH 3/4] ImportSkillCaps converted to QueryDatabase --- client_files/import/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client_files/import/main.cpp b/client_files/import/main.cpp index 3547b4062..5f786ee00 100644 --- a/client_files/import/main.cpp +++ b/client_files/import/main.cpp @@ -159,7 +159,7 @@ void ImportSkillCaps(SharedDatabase *db) { } std::string delete_sql = "DELETE FROM skill_caps"; - db->RunQuery(delete_sql.c_str(), (uint32)delete_sql.length()); + db->QueryDatabase(delete_sql); char buffer[2048]; while(fgets(buffer, 2048, f)) { @@ -179,7 +179,7 @@ void ImportSkillCaps(SharedDatabase *db) { std::string sql = StringFormat("INSERT INTO skill_caps(class, skillID, level, cap) VALUES(%d, %d, %d, %d)", class_id, skill_id, level, cap); - db->RunQuery(sql.c_str(), (uint32)sql.length()); + db->QueryDatabase(sql); } fclose(f); From 230296e777098f249d5822970b8b3e19d2dc3417 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Mon, 18 Aug 2014 14:05:59 -0700 Subject: [PATCH 4/4] ImportBaseData converted to QueryDatabase --- client_files/import/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client_files/import/main.cpp b/client_files/import/main.cpp index 5f786ee00..321e3a17b 100644 --- a/client_files/import/main.cpp +++ b/client_files/import/main.cpp @@ -195,7 +195,7 @@ void ImportBaseData(SharedDatabase *db) { } std::string delete_sql = "DELETE FROM base_data"; - db->RunQuery(delete_sql.c_str(), (uint32)delete_sql.length()); + db->QueryDatabase(delete_sql); char buffer[2048]; while(fgets(buffer, 2048, f)) { @@ -224,7 +224,7 @@ void ImportBaseData(SharedDatabase *db) { "mana_fac, end_fac) VALUES(%d, %d, %f, %f, %f, %f, %f, %f, %f, %f)", level, class_id, hp, mana, end, unk1, unk2, hp_fac, mana_fac, end_fac); - db->RunQuery(sql.c_str(), (uint32)sql.length()); + db->QueryDatabase(sql); } fclose(f);