CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
DBInterface Class Reference

Gather data from DB. More...

#include <DBInterface.h>

Public Member Functions

 DBInterface (const std::string &fDb, bool fVerbose=false)
 
 ~DBInterface ()
 

Protected Member Functions

template<class T >
bool getObjectGeneric (T *fObject, const std::string &fTag)
 

Protected Attributes

oracle::occi::Connection * mConnect
 
oracle::occi::Environment * mEnvironment
 
oracle::occi::Statement * mStatement
 
bool mVerbose
 

Detailed Description

Gather data from DB.

Author
Gena Kukartsev

Definition at line 27 of file DBInterface.h.

Constructor & Destructor Documentation

DBInterface::DBInterface ( const std::string &  fDb,
bool  fVerbose = false 
)

Definition at line 16 of file DBInterface.cc.

References dtNoiseDBValidation_cfg::cerr, query::host, mConnect, mEnvironment, mStatement, AlCaHLTBitMon_QueryRunRegistry::string, and hcal_dqm_sourceclient-file_cfg::user.

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 }
bool mVerbose
Definition: DBInterface.h:38
oracle::occi::Statement * mStatement
Definition: DBInterface.h:36
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
string host
Definition: query.py:114
oracle::occi::Connection * mConnect
Definition: DBInterface.h:35
oracle::occi::Environment * mEnvironment
Definition: DBInterface.h:34
DBInterface::~DBInterface ( )

Definition at line 44 of file DBInterface.cc.

References mConnect, mEnvironment, and mStatement.

44  {
45  delete mStatement;
46  mEnvironment->terminateConnection (mConnect);
47  oracle::occi::Environment::terminateEnvironment (mEnvironment);
48 }
oracle::occi::Statement * mStatement
Definition: DBInterface.h:36
oracle::occi::Connection * mConnect
Definition: DBInterface.h:35
oracle::occi::Environment * mEnvironment
Definition: DBInterface.h:34

Member Function Documentation

template<class T >
bool DBInterface::getObjectGeneric ( T fObject,
const std::string &  fTag 
)
protected

Member Data Documentation

oracle::occi::Connection* DBInterface::mConnect
protected

Definition at line 35 of file DBInterface.h.

Referenced by DBInterface(), and ~DBInterface().

oracle::occi::Environment* DBInterface::mEnvironment
protected

Definition at line 34 of file DBInterface.h.

Referenced by DBInterface(), and ~DBInterface().

oracle::occi::Statement* DBInterface::mStatement
protected

Definition at line 36 of file DBInterface.h.

Referenced by DBInterface(), and ~DBInterface().

bool DBInterface::mVerbose
protected

Definition at line 38 of file DBInterface.h.