Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPrintDB.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 
4 #include "dbclient/KM3NeTDBClient.h"
5 
6 #include "JDB/JDB.hh"
7 #include "JDB/JSelector.hh"
8 
9 #include "Jeep/JParser.hh"
10 #include "Jeep/JMessage.hh"
11 
12 
13 /**
14  * \file
15  *
16  * Auxiliary program to print data from data base.
17  * \author mdejong
18  */
19 int main(int argc, char **argv)
20 {
21  using namespace std;
22  using namespace JPP;
23 
24  string usr;
25  string pwd;
26  string cookie;
27  string query;
28  JSelector selection;
29  int width;
30  int debug;
31 
32  try {
33 
34  JParser<> zap("Auxiliary program to print data from data base.");
35 
36  zap['u'] = make_field(usr) = "";
37  zap['!'] = make_field(pwd) = "";
38  zap['C'] = make_field(cookie) = "";
39  zap['q'] = make_field(query) = "";
40  zap['@'] = make_field(selection) = JPARSER::initialised();
41  zap['W'] = make_field(width) = 16;
42  zap['d'] = make_field(debug) = 1;
43 
44  zap(argc, argv);
45  }
46  catch(const exception &error) {
47  FATAL(error.what() << endl);
48  }
49 
50  DEBUG("Selection:" << endl << selection << endl);
51 
52  try {
53 
54  JDB::reset(usr, pwd, cookie);
55 
56  ResultSet& rs = getResultSet(query, selection);
57 
58  for (unsigned int i = 0; i != rs.FieldCount(); ++i) {
59  cout << ' ' << setw(width) << left << rs.FieldName(i) << flush;
60  }
61  cout << endl;
62 
63  while (rs.Next()) {
64  for (unsigned int i = 0; i != rs.FieldCount(); ++i) {
65  cout << ' ' << setw(width) << left << rs.GetString(i) << flush;
66  }
67 
68  cout << endl;
69  }
70  }
71  catch(const exception& error) {
72  FATAL(error.what() << endl);
73  }
74 
75  return 0;
76 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
void reset(T &value)
Reset value.
Utility class to parse command line options.
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:269
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62