test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DBInterface.cc
Go to the documentation of this file.
1 
2 //
3 // Gena Kukartsev (Brown), Feb 1, 2008
4 // $Id:
5 //
6 #include <limits>
7 #include <string>
8 #include <iostream>
9 #include <sstream>
10 
12 
15 
16 DBInterface::DBInterface (const std::string& fDb, bool fVerbose)
17  : mConnect (0),
18  mVerbose (fVerbose)
19 {
20  mEnvironment = oracle::occi::Environment::createEnvironment (oracle::occi::Environment::OBJECT);
21  // decode connect string
22  size_t ipass = fDb.find ('/');
23  size_t ihost = fDb.find ('@');
24 
25  if (ipass == std::string::npos || ihost == std::string::npos) {
26  std::cerr << "DBInterface::DBInterface-> Error in connection std::string format: " << fDb
27  << " Expect user/password@db" << std::endl;
28  }
29  else {
30  std::string user (fDb, 0, ipass);
31  std::string pass (fDb, ipass+1, ihost-ipass-1);
32  std::string host (fDb, ihost+1);
33  // std::cout << "DBInterface::DBInterface-> Connecting " << user << '/' << pass << '@' << host << std::endl;
34  try {
35  mConnect = mEnvironment->createConnection(user, pass, host);
36  mStatement = mConnect->createStatement ();
37  }
38  catch (oracle::occi::SQLException& sqlExcp) {
39  std::cerr << "DBInterface::DBInterface exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl;
40  }
41  }
42 }
43 
45  delete mStatement;
46  mEnvironment->terminateConnection (mConnect);
47  oracle::occi::Environment::terminateEnvironment (mEnvironment);
48 }
49 
oracle::occi::Statement * mStatement
Definition: DBInterface.h:36
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
DBInterface(const std::string &fDb, bool fVerbose=false)
Definition: DBInterface.cc:16
string host
Definition: query.py:114
oracle::occi::Connection * mConnect
Definition: DBInterface.h:35
mVerbose(fConfig.getUntrackedParameter< bool >("verbose", false))
oracle::occi::Environment * mEnvironment
Definition: DBInterface.h:34