Diana Software
QDianaDb.cc
Go to the documentation of this file.
1 /*
2  *
3  * Author: MP 19/04/06
4  * $Id: QDianaDb.cc 511 2006-12-01 12:09:32Z didomiz $
5  *
6  * Class QDianaDb: interface to data base
7  *
8 */
9 
10 #include <stdexcept>
11 #include <iostream>
12 #include <sstream>
13 
14 #include "QDianaDb.hh"
15 #include "QError.hh"
16 
17 
19 
20 //______________________________________________________________________________
22  // singleton
23 
24  if ( !me ) {
25  std::string host;
26  std::string port;
27  std::string user;
28  std::string pwd;
29  std::string db;
30 
31  const char *p = getenv("DIANA_DB_HOST");
32  if (p)
33  host = p;
34  else
36  __LINE__, "Cannot find environment"
37  " variable DIANA_DB_HOST"));
38 
39  p = getenv("DIANA_DB_PORT");
40  if (p)
41  port = p;
42  else
44  __LINE__, "Cannot find environment"
45  " variable DIANA_DB_PORT"));
46 
47  p = getenv("DIANA_DB_USER");
48  if (p)
49  user = p;
50  else
52  __LINE__, "Cannot find environment"
53  " variable DIANA_DB_USER"));
54 
55  p = getenv("DIANA_DB_PWD");
56  if (p)
57  pwd = p;
58  else
60  __LINE__, "Cannot find environment"
61  " variable DIANA_DB_PWD"));
62 
63  p = getenv("DIANA_DB_NAME");
64  if (p)
65  db = p;
66  else
68  __LINE__, "Cannot find environment"
69  " variable DIANA_DB_NAME"));
70 
71  me = new QDianaDb(host,port,user,pwd,db);
72  }
73  return me;
74 }
75 
76 QDianaDb *QDianaDb::Get(const std::string& host, const std::string& port,
77  const std::string& user, const std::string& pwd,
78  const std::string& db)
79 {
80  if(!me) {
81 
82  me = new QDianaDb(host,port,user,pwd,db);
83 }
84  return me;
85 }
86 
87 
88 //______________________________________________________________________________
89 QDianaDb::QDianaDb(const std::string& host, const std::string& port,
90  const std::string& usr, const std::string& pwd,
91  const std::string& db) : QDb(host,port,usr,pwd,db) {
92  //
93  // private ctor
94  //
95 
96  Clear();
97 }
98 
99 //______________________________________________________________________________
101  //
102  // dtor
103  //
104  Clear();
105 }
106 
107 
108 //______________________________________________________________________________
110  if ( IsConnected() )
111  Disconnect();
112  if ( me )
113  delete me;
114  me = 0;
115 }
116 
117 //______________________________________________________________________________
119  //
120  // clear all tables
121  //
122 }
#define DianaThrow(obj)
Definition: QDianaDebug.hh:26
@ QERR_UNDEFINED_PARAMETER
Definition: QError.hh:52
base class for db interface
Definition: QDb.hh:28
bool Disconnect()
Definition: QDb.cc:151
bool IsConnected() const
Definition: QDb.cc:66
void Clear()
Definition: QDianaDb.cc:118
void Reset()
Definition: QDianaDb.cc:109
QDianaDb(const std::string &, const std::string &, const std::string &, const std::string &, const std::string &)
Definition: QDianaDb.cc:89
virtual ~QDianaDb()
Definition: QDianaDb.cc:100
static QDianaDb * Get()
Definition: QDianaDb.cc:21
static QDianaDb * me
Definition: QDianaDb.hh:32
error class with error type and description
Definition: QError.hh:115