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 
16  string sid,
17  string user,
18  string pass,
19  int port )
20  noexcept(false)
21 {
22  stringstream ss;
23  try {
24  ss << "//" << host << ":" << port << "/" << sid;
25 
26  env = Environment::createEnvironment(Environment::OBJECT);
27  conn = env->createConnection(user, pass, ss.str());
28  stmt = conn->createStatement();
29  } catch (SQLException &e) {
30  cout<< ss.str() << endl;
31  throw(std::runtime_error(std::string("ERROR: Connection Failed: ") + getOraMessage(&e)));
32  }
33 
34  this->host = host;
35  this->sid = sid;
36  this->user = user;
37  this->pass = pass;
38  this->port = port;
39 }
40 
42  string user,
43  string pass )
44  noexcept(false)
45 {
46  try {
47  env = Environment::createEnvironment(Environment::OBJECT);
48  conn = env->createConnection(user, pass, sid);
49  stmt = conn->createStatement();
50  } catch (SQLException &e) {
51  throw(std::runtime_error(std::string("ERROR: Connection Failed: ") + getOraMessage(&e)));
52  }
53 
54  this->host = "";
55  this->sid = sid;
56  this->user = user;
57  this->pass = pass;
58  this->port = port;
59 }
60 
62  //Close database conection and terminate environment
63  try {
64  conn->terminateStatement(stmt);
65  env->terminateConnection(conn);
66  Environment::terminateEnvironment(env);
67  } catch (SQLException &e) {
68  throw(std::runtime_error(std::string("ERROR: Destructor Failed: ") + getOraMessage(&e)));
69  }
70 }
host
Definition: query.py:115
#define noexcept
port
Definition: query.py:116
EcalDBConnection(std::string host, std::string sid, std::string user, std::string pass, int port=1521) noexcept(false)
virtual ~EcalDBConnection() noexcept(false)