#include #include #include #include "dbclient/KM3NeTDBClient.h" #include "JDB/JDB.hh" #include "JDB/JSelector.hh" #include "JSon/JSon.hh" #include "JSon/JPrinter.hh" #include "Jeep/JVersion.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { static const std::string help_t = "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, "API, possible values X.Y.Z[/help] ('apiv2') or \"\" ('streamds')") = ""; 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 == "") { 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(); } else { JVersion version; istringstream is(api); if (is >> version) { json js; JSON::JPrinter printer; string buffer; if (is.peek() == EOF) *(JDB::get()->APIv2Select(version.toString().c_str(), query.c_str(), selection)) >> js; else if (is.get() == '/' && is >> buffer && buffer == help_t) *(JDB::get()->APIv2Help(version.toString().c_str(), (query != "" ? query.c_str() : "all/h"))) >> js; else FATAL("Error reading API version <" << api << ">." << endl); printer(cout, js, key); } else { FATAL("Error reading API version <" << api << ">." << endl); } } } catch(const exception& error) { FATAL(error.what() << endl); } return 0; }