#include #include #include "dbclient/KM3NeTDBClient.h" #include "JDB/JDB.hh" #include "JDB/JSelector.hh" #include "JSon/JSon.hh" #include "JSon/JPrinter.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { static const std::string streamds_t = "streamds"; static const std::string apiv2_t = "apiv2"; static const std::string apiv2_help_t = "apiv2/help"; } /** * \file * * Auxiliary program to print data from data base. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; JServer server; string usr; string pwd; string cookie; string query; JSelector selection; string api; int width; string csv; string key; int debug; try { JParser<> zap("Auxiliary program to print data from data base."); zap['s'] = make_field(server) = getServernames(); zap['u'] = make_field(usr) = ""; zap['!'] = make_field(pwd) = ""; zap['C'] = make_field(cookie) = ""; zap['q'] = make_field(query) = ""; zap['@'] = make_field(selection) = JPARSER::initialised(); zap['A'] = make_field(api) = streamds_t, apiv2_t, apiv2_help_t; zap['W'] = make_field(width) = 16; zap['c'] = make_field(csv) = " "; zap['k'] = make_field(key) = ""; zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } try { JDB::reset(usr, pwd, cookie); if (api == streamds_t) { ResultSet& rs = getResultSet(query, selection); for (unsigned int i = 0; i != rs.FieldCount(); ++i) { cout << (i != 0 ? csv : "") << setw(width) << left << rs.FieldName(i) << flush; } cout << endl; while (rs.Next()) { for (unsigned int i = 0; i != rs.FieldCount(); ++i) { cout << (i != 0 ? csv : "") << setw(width) << left << rs.GetString(i) << flush; } cout << endl; } rs.Close(); } if (api == apiv2_t) { JSON::JPrinter printer; json js; to_json(js, query.c_str(), selection); printer(cout, js, key); } if (api == apiv2_help_t) { JSON::JPrinter printer; if (query == "") { query = "all/h"; } json js; *(JDB::get()->APIv2Help(query.c_str())) >> js; printer(cout, js, key); } } catch(const exception& error) { FATAL(error.what() << endl); } return 0; }