Jpp  17.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPrintDB.cc File Reference

Auxiliary program to print data from data base. More...

#include <iostream>
#include <iomanip>
#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"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to print data from data base.

Author
mdejong

Definition in file JPrintDB.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file JPrintDB.cc.

30 {
31  using namespace std;
32  using namespace JPP;
33 
34  JServer server;
35  string usr;
36  string pwd;
37  string cookie;
38  string query;
39  JSelector selection;
40  string api;
41  int width;
42  string csv;
43  string key;
44  int debug;
45 
46  try {
47 
48  JParser<> zap("Auxiliary program to print data from data base.");
49 
50  zap['s'] = make_field(server) = getServernames();
51  zap['u'] = make_field(usr) = "";
52  zap['!'] = make_field(pwd) = "";
53  zap['C'] = make_field(cookie) = "";
54  zap['q'] = make_field(query) = "";
55  zap['@'] = make_field(selection) = JPARSER::initialised();
56  zap['A'] = make_field(api) = streamds_t, apiv2_t, apiv2_help_t;
57  zap['W'] = make_field(width) = 16;
58  zap['c'] = make_field(csv) = " ";
59  zap['k'] = make_field(key) = "";
60  zap['d'] = make_field(debug) = 1;
61 
62  zap(argc, argv);
63  }
64  catch(const exception &error) {
65  FATAL(error.what() << endl);
66  }
67 
68  try {
69 
70  JDB::reset(usr, pwd, cookie);
71 
72  if (api == streamds_t) {
73 
74  ResultSet& rs = getResultSet(query, selection);
75 
76  for (unsigned int i = 0; i != rs.FieldCount(); ++i) {
77  cout << (i != 0 ? csv : "") << setw(width) << left << rs.FieldName(i) << flush;
78  }
79  cout << endl;
80 
81  while (rs.Next()) {
82  for (unsigned int i = 0; i != rs.FieldCount(); ++i) {
83  cout << (i != 0 ? csv : "") << setw(width) << left << rs.GetString(i) << flush;
84  }
85  cout << endl;
86  }
87 
88  rs.Close();
89  }
90 
91  if (api == apiv2_t) {
92 
93  JSON::JPrinter printer;
94 
95  json js;
96 
97  to_json(js, query.c_str(), selection);
98 
99  printer(cout, js, key);
100  }
101 
102  if (api == apiv2_help_t) {
103 
104  JSON::JPrinter printer;
105 
106  if (query == "") {
107  query = "all/h";
108  }
109 
110  json js;
111 
112  *(JDB::get()->APIv2Help(query.c_str())) >> js;
113 
114  printer(cout, js, key);
115  }
116  }
117  catch(const exception& error) {
118  FATAL(error.what() << endl);
119  }
120 
121  return 0;
122 }
Utility class to parse command line options.
Definition: JParser.hh:1517
T get(const JHead &header)
Get object from header.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
#define FATAL(A)
Definition: JMessage.hh:67
void reset(T &value)
Reset value.
nlohmann::json json
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:431
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition: JDB.hh:101
void to_json(json &js, const std::string &query)
Get result set.
Definition: JDB.hh:456
Auxiliary data structure to print (part of) JSon data.
Definition: JPrinter.hh:29
int debug
debug level