HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
harpoGetRunList.cxx
Go to the documentation of this file.
1 //
2 // Demo code for harpo database manipulation
3 //
4 
5 #include "HarpoDB.h"
6 #include "TSQLServer.h"
7 #include "TSQLResult.h"
8 #include "TSQLRow.h"
9 #include "TString.h"
10 #include <iostream>
11 #include <stdlib.h>
12 #include <unistd.h>
13 
14 
15 int main(int argc, char **argv)
16 {
17  // std::cout << "Connecting to server" << std::endl;
18  TString dbUrl = TString("mysql://llrharpo.in2p3.fr/harpo");
19  TString dbuser = TString("reader");
20  TString dbpw = TString("ro");
21  TSQLServer *db = TSQLServer::Connect(dbUrl.Data(),dbuser.Data(), dbpw.Data());
22  if ( db == NULL )
23  return false; // server not opened
24 
25  TSQLRow *mrow;
26  TSQLResult *res;
27 
28  TString sql;
29  TString cut;// = TString("Beam LIKE 'NSBeam'");
30 
31  if(argc>1) cut = TString(argv[1]);
32  else cut = TString("1");
33 
34  sql += "SELECT t0.run FROM `runconfig` t0 left join `NSBeam` t1 on t0.run = t1.run WHERE ";
35  sql += cut;
36  sql +=";";
37  // std::cout << "SQL : " << sql << std::endl;
38 
39  // // query database and print results
40  // //if ( db->SelectDataBase("harpo") != 0 ) return rec_found;
41  res = db->Query(sql.Data());
42 
43  int nfields = res->GetFieldCount();
44  if(nfields != 1) return 0;
45  int nrows = res->GetRowCount();
46 
47 
48  for(Int_t row = 0; row<nrows; row++){
49  mrow = res->Next();
50  std::cout << mrow->GetField(0) << " ";
51  }
52  std::cout << std::endl;
53 
54  // std::cout << "NROWS : " << nrows << std::endl;
55  return 0;
56 
57 }
int main(int argc, char **argv)
unsigned int res
Definition: Pmm2Status.h:428