Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPrintDB.cc File Reference

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

#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include "KM3NeTDBClient.h"
#include "JDB/JDB.hh"
#include "JDB/JSelector.hh"
#include "JDetector/JDetector.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

Example 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 21 of file JPrintDB.cc.

22 {
23  using namespace std;
24  using namespace KM3NETDB;
25 
26  string usr;
27  string pwd;
28  string cookie;
29  string query;
30  JSelector selector;
31  int width;
32  int debug;
33 
34  try {
35 
36  JParser<> zap("Example program to print data from data base.");
37 
38  zap['u'] = make_field(usr) = "";
39  zap['!'] = make_field(pwd) = "";
40  zap['C'] = make_field(cookie) = "";
41  zap['q'] = make_field(query) = "";
42  zap['@'] = make_field(selector) = JPARSER::initialised();
43  zap['W'] = make_field(width) = 16;
44  zap['d'] = make_field(debug) = 1;
45 
46  zap(argc, argv);
47  }
48  catch(const exception &error) {
49  FATAL(error.what() << endl);
50  }
51 
52  DEBUG("Selection:" << endl << selector << endl);
53 
54  try {
55 
56  if (usr != "" && pwd != "")
57  JDB::reset(usr, pwd);
58  else if (cookie != "")
59  JDB::reset(cookie);
60  else
61  FATAL("Must provide either username (with passwrod) or cookie." << endl);
62 
63  ResultSet& rs = JDB::get()->StreamDS(query.c_str(), selector);
64 
65  for (unsigned int i = 0; i != rs.FieldCount(); ++i) {
66  cout << ' ' << setw(width) << left << rs.FieldName(i);
67  }
68  cout << endl;
69 
70  while (rs.Next()) {
71  for (unsigned int i = 0; i != rs.FieldCount(); ++i) {
72  cout << ' ' << setw(width) << left << rs.GetString(i);
73  }
74  cout << endl;
75  }
76  }
77  catch(const exception& error) {
78  FATAL(error.what() << endl);
79  }
80 }
Utility class to parse command line options.
Definition: JParser.hh:1410
Auxiliary class for specifying selection of database data.
void reset(JCLBInput &data, size_t size)
Reset CLB buffers.
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:64
T get(const JHead &head)
Get object from header.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
int debug
debug level
Definition: JSirene.cc:59
#define FATAL(A)
Definition: JMessage.hh:65
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60