Ignore:
Timestamp:
07/31/18 13:48:35 (6 years ago)
Author:
tbretz
Message:
Possibility to add the IGNORE keyword to the INSERT query.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/root2sql.cc

    r19102 r19103  
    6262        ("engine",         var<string>("InnoDB"),     "Database engine to be used when a new table is created")
    6363        ("duplicate",      var<string>(""),           "Specifies an assignment_list for an 'ON DUPLICATE KEY UPDATE' expression")
     64        ("ignore-errors",  po_switch(),               "Adds the IGNORE keyword to the INSERT query (turns errors into warnings, ignores rows with errors)")
    6465        ;
    6566
     
    159160        "end.\n"
    160161        "\n"
     162        "Another possibility is to add the IGNORE keyword to the INSERT query by "
     163        "--ignore-errors, which essentially ignores all errors and turns them into "
     164        "warnings which are printed after the query succeeded.\n"
     165        "\n"
    161166        "Using a higher verbosity level (-v), an overview of the written columns or all "
    162167        "processed leaves is printed depending on the verbosity level. The output looks "
     
    301306    const string duplicate       = conf.Get<string>("duplicate");
    302307
     308    const bool ignore_errors     = conf.Get<bool>("ignore-errors");
     309
    303310    const bool print_branches    = conf.Get<bool>("print-branches");
    304311    const bool print_leaves      = conf.Get<bool>("print-leaves");
     
    452459    // Checking for database connection
    453460
     461    Database connection(uri);
     462
    454463    try
    455464    {
    456465        if (!force)
    457             Database(uri).connected();
     466            connection.connected();
    458467    }
    459468    catch (const exception &e)
     
    485494            // => Simple result
    486495            if (!dry_run)
    487                 Database(uri).query("DROP TABLE `"+table+"`").execute();
     496                connection.query("DROP TABLE `"+table+"`").execute();
    488497            if (verbose>0)
    489498                cout << "Table `" << table << "` dropped." << endl;
     
    500509    {
    501510        if (create && !dry_run)
    502             Database(uri).query(query).execute();
     511            connection.query(query).execute();
    503512    }
    504513    catch (const exception &e)
     
    521530
    522531    //query = update ? "UPDATE" : "INSERT";
    523     query = "INSERT `"+table+"`\n"
     532    query = "INSERT ";
     533    if (ignore_errors)
     534        query += "IGNORE ";
     535    query += "`"+table+"`\n"
    524536        "(\n";
    525537
     
    589601        if (!noinsert && !dry_run)
    590602            // => Simple result
    591             Database(uri).query(query).execute();
     603            connection.query(query).execute();
    592604        else
    593605            cout << "Insert query skipped!" << endl;
     
    608620        cout << count << " row(s) inserted.\n\n";
    609621        cout << "Total execution time: " << Time().UnixTime()-start.UnixTime() << "s\n" << endl;
    610 /*
     622
    611623        try
    612624        {
     
    622634
    623635                cout << roww["Level"] << '[' << roww["Code"] << "]: ";
    624                 cout << roww["Message"] << '\n' << endl;
     636                cout << roww["Message"] << '\n';
    625637            }
     638            cout << endl;
    626639
    627640        }
     
    630643            cerr << "\nSHOW WARNINGS\n\n";
    631644            cerr << "SQL query failed:\n" << e.what() << endl;
    632             return 6;
    633         }*/
    634     }
    635 
     645            return 7;
     646        }
     647    }
    636648
    637649    return 0;
Note: See TracChangeset for help on using the changeset viewer.