Ignore:
Timestamp:
07/31/18 12:07:31 (6 years ago)
Author:
tbretz
Message:
Allow an 'ON DUPLICATE KEY UPDATE' clause
File:
1 edited

Legend:

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

    r19089 r19101  
    6161        ("max",            var<int64_t>(int64_t(0)),  "Maximum number of events to process (0: all), mainly for test purpose")
    6262        ("engine",         var<string>("InnoDB"),     "Database engine to be used when a new table is created")
     63        ("duplicate",      var<string>(""),           "Specifies an assignment_list for an 'ON DUPLICATE KEY UPDATE' expression")
    6364        ;
    6465
     
    114115        "\n"
    115116        "Sometimes it might also be convenient to skip a leaf. This can be done with "
    116         "the --ignore resource. If the given regular expresion yield a match, the "
    117         "leaf will be ignored. Note that the regular expression work on the raw-name "
     117        "the --ignore resource. If the given regular expresion yields a match, the "
     118        "leaf will be ignored. Note that the regular expression works on the raw-name "
    118119        "of the leaf not the readily mapped SQL column names. Example:\n"
    119120        "   --ignore=ThetaSq\\..*\n"
     
    144145        "\n"
    145146        "All columns are created as NOT NULL as default and the table is created as "
    146         "MyISAM (default).\n"
     147        "InnoDB (default).\n"
     148        "\n"
     149        "Usually, the INSERT query would fail if the PRIMARY key exists already. "
     150        "This can be avoided using the 'ON DUPLICATE KEY' directive. With the "
     151        "--duplicate,you can specify what should be updated in case of a duplicate key. "
     152        "For detaily, see the MySQL manual.\n"
    147153        "\n"
    148154        "For debugging purpose, or to just create or drop a table, the final insert "
     
    291297
    292298    const string engine          = conf.Get<string>("engine");
     299    const string duplicate       = conf.Get<string>("duplicate");
    293300
    294301    const bool print_branches    = conf.Get<bool>("print-branches");
     
    550557                query += " /* "+c->column+" -> "+c->branch+" */";
    551558        }
    552         query += "\n)";  // ON DUPLICATE KEY UPDATE\n";
     559        query += "\n)";
    553560
    554561        count ++;
    555562    }
     563
     564    if (!duplicate.empty())
     565        query += "\nON DUPLICATE KEY UPDATE\n   " + duplicate;
    556566
    557567    if (verbose>0)
     
    596606        cout << count << " row(s) inserted.\n\n";
    597607        cout << "Total execution time: " << Time().UnixTime()-start.UnixTime() << "s\n" << endl;
    598     }
     608/*
     609        try
     610        {
     611            const auto resw =
     612                connection.query("SHOW WARNINGS").store();
     613
     614            if (resw.num_rows()>0)
     615                cout << "\nWARNINGS:\n\n";
     616
     617            for (size_t i=0; i<resw.num_rows(); i++)
     618            {
     619                const mysqlpp::Row &roww = resw[i];
     620
     621                cout << roww["Level"] << '[' << roww["Code"] << "]: ";
     622                cout << roww["Message"] << '\n' << endl;
     623            }
     624
     625        }
     626        catch (const exception &e)
     627        {
     628            cerr << "\nSHOW WARNINGS\n\n";
     629            cerr << "SQL query failed:\n" << e.what() << endl;
     630            return 6;
     631        }*/
     632    }
     633
    599634
    600635    return 0;
Note: See TracChangeset for help on using the changeset viewer.