CMS 3D CMS Logo

EcalDBConnection.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include <sstream>
4 #include <cstdlib>
5 #include <cstdlib>
6 #include <stdexcept>
8 
9 using namespace std;
10 using namespace oracle::occi;
11 
14 
15 EcalDBConnection::EcalDBConnection(string host, string sid, string user, string pass, int port) noexcept(false) {
16  stringstream ss;
17  try {
18  ss << "//" << host << ":" << port << "/" << sid;
19 
20  env = Environment::createEnvironment(Environment::OBJECT);
21  conn = env->createConnection(user, pass, ss.str());
22  stmt = conn->createStatement();
23  } catch (SQLException &e) {
24  cout << ss.str() << endl;
25  throw(std::runtime_error("ERROR: Connection Failed: " + e.getMessage()));
26  }
27 
28  this->host = host;
29  this->sid = sid;
30  this->user = user;
31  this->pass = pass;
32  this->port = port;
33 }
34 
35 EcalDBConnection::EcalDBConnection(string sid, string user, string pass) noexcept(false) {
36  try {
37  env = Environment::createEnvironment(Environment::OBJECT);
38  conn = env->createConnection(user, pass, sid);
39  stmt = conn->createStatement();
40  } catch (SQLException &e) {
41  throw(std::runtime_error("ERROR: Connection Failed: " + e.getMessage()));
42  }
43 
44  this->host = "";
45  this->sid = sid;
46  this->user = user;
47  this->pass = pass;
48 }
49 
51  //Close database conection and terminate environment
52  try {
53  conn->terminateStatement(stmt);
54  env->terminateConnection(conn);
55  Environment::terminateEnvironment(env);
56  } catch (SQLException &e) {
57  throw(std::runtime_error("ERROR: Destructor Failed: " + e.getMessage()));
58  }
59 }
string host
Definition: query.py:115
int port
Definition: query.py:116
EcalDBConnection(std::string host, std::string sid, std::string user, std::string pass, int port=1521) noexcept(false)
conn
Definition: getInfo.py:9
virtual ~EcalDBConnection() noexcept(false)