Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include <limits>
00007 #include <string>
00008 #include <iostream>
00009 #include <sstream>
00010
00011 #include "OnlineDB/Oracle/interface/Oracle.h"
00012
00013 #include "FWCore/Utilities/interface/Exception.h"
00014 #include "CaloOnlineTools/HcalOnlineDb/interface/DBInterface.h"
00015
00016 DBInterface::DBInterface (const std::string& fDb, bool fVerbose)
00017 : mConnect (0),
00018 mVerbose (fVerbose)
00019 {
00020 mEnvironment = oracle::occi::Environment::createEnvironment (oracle::occi::Environment::OBJECT);
00021
00022 size_t ipass = fDb.find ('/');
00023 size_t ihost = fDb.find ('@');
00024
00025 if (ipass == std::string::npos || ihost == std::string::npos) {
00026 std::cerr << "DBInterface::DBInterface-> Error in connection std::string format: " << fDb
00027 << " Expect user/password@db" << std::endl;
00028 }
00029 else {
00030 std::string user (fDb, 0, ipass);
00031 std::string pass (fDb, ipass+1, ihost-ipass-1);
00032 std::string host (fDb, ihost+1);
00033
00034 try {
00035 mConnect = mEnvironment->createConnection(user, pass, host);
00036 mStatement = mConnect->createStatement ();
00037 }
00038 catch (oracle::occi::SQLException& sqlExcp) {
00039 std::cerr << "DBInterface::DBInterface exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl;
00040 }
00041 }
00042 }
00043
00044 DBInterface::~DBInterface () {
00045 delete mStatement;
00046 mEnvironment->terminateConnection (mConnect);
00047 oracle::occi::Environment::terminateEnvironment (mEnvironment);
00048 }
00049