Resolves SQL header output on suffix files (#5497)

* Resolves an issue where the wrong header was being printed to the SQL files that contain a suffix to them.
Thanks to @Atemo!
This commit is contained in:
Aleos
2020-10-28 12:45:52 -04:00
committed by GitHub
parent 8682a9e02e
commit 93eaf3207e
7 changed files with 23 additions and 4 deletions

View File

@@ -78,10 +78,11 @@ void prepareHeader(std::ofstream &file, const std::string& name) {
}
template<typename Func>
bool process( const std::string& type, uint32 version, const std::vector<std::string>& paths, const std::string& name, const std::string& to, const std::string& table, Func lambda ){
bool process( const std::string& type, uint32 version, const std::vector<std::string>& paths, const std::string& name, const std::string& to_table, const std::string& table, Func lambda ){
for( const std::string& path : paths ){
const std::string name_ext = name + ".yml";
const std::string from = path + name_ext;
const std::string to = "sql-files/" + to_table + ".sql";
if( fileExists( from ) ){
if( !askConfirmation( "Found the file \"%s\", which can be converted to sql.\nDo you want to convert it now? (Y/N)\n", from.c_str() ) ){
@@ -114,7 +115,7 @@ bool process( const std::string& type, uint32 version, const std::vector<std::st
return false;
}
prepareHeader(out, table);
prepareHeader(out, table.compare(to_table) == 0 ? table : to_table);
if( !lambda( path, name_ext, table ) ){
out.close();
@@ -146,14 +147,14 @@ int do_init( int argc, char** argv ){
};
for( const std::string& suffix : item_table_suffixes ){
if (!process("ITEM_DB", 1, { path_db_mode }, "item_db_" + suffix, "sql-files/" + item_table_name + "_" + suffix + ".sql", item_table_name, [](const std::string& path, const std::string& name_ext, const std::string& table) -> bool {
if (!process("ITEM_DB", 1, { path_db_mode }, "item_db_" + suffix, item_table_name + "_" + suffix, item_table_name, [](const std::string& path, const std::string& name_ext, const std::string& table) -> bool {
return item_db_yaml2sql(path + name_ext, table);
})) {
return 0;
}
}
if (!process("ITEM_DB", 1, { path_db_import }, "item_db", "sql-files/" + item_import_table_name + ".sql", item_import_table_name, [](const std::string& path, const std::string& name_ext, const std::string& table) -> bool {
if (!process("ITEM_DB", 1, { path_db_import }, "item_db", item_import_table_name, item_import_table_name, [](const std::string& path, const std::string& name_ext, const std::string& table) -> bool {
return item_db_yaml2sql(path + name_ext, table);
})) {
return 0;