////////////////////////////////////////////////////////////////////////// //////////////////////////// ROOT API //////////////////////////// ////////////////////////////////////////////////////////////////////////// #include #include #include #include #include "TString.h" #include "IDbiStatement.hxx" #include "IDbiTableMetaData.hxx" #include #include using std::endl; #include "UtilString.hxx" ClassImp(COMET::IDbiStatement) // Definition of static data members // ********************************* // Definition of all member functions (static or otherwise) // ******************************************************* // // - ordered: ctors, dtor, operators then in alphabetical order. //..................................................................... COMET::IDbiStatement::IDbiStatement(COMET::IDbiConnection& conDb) : fConDb(conDb) { // // // Purpose: Constructor // // Arguments: None. // // Return: // // conDb in The connection associated with the statement. // COMETTrace( "Creating COMET::IDbiStatement" << " "); fConDb.ConnectStatement(); } //..................................................................... COMET::IDbiStatement::~IDbiStatement() { // // // Purpose: Destructor COMETTrace( "Destroying COMET::IDbiStatement" << " "); fConDb.DisConnectStatement(); } //..................................................................... TSQLStatement* COMET::IDbiStatement::CreateProcessedStatement(const TString& sql /* ="" */) { // Attempt to create a processed statement (caller must delete). Return 0 if failure. TSQLStatement* stmt = fConDb.CreatePreparedStatement(sql.Data()); if ( ! stmt ) { this->AppendExceptionLog(fConDb); return 0; } if ( stmt->Process() ) return stmt; this->AppendExceptionLog(stmt); delete stmt; stmt = 0; return 0; } //..................................................................... TSQLStatement* COMET::IDbiStatement::ExecuteQuery( const TString& sql) { // // // Purpose: Execute SQL. // Return: TSQLStatement with Process() and StoreResult() already performed. this->ClearExceptionLog(); COMETInfo( "SQL:" << fConDb.GetDbName() << ":" << sql << " "); TSQLStatement* stmt = this->CreateProcessedStatement(sql); if ( ! stmt ) return 0; if ( ! stmt->StoreResult() ) { this->AppendExceptionLog(stmt); delete stmt; stmt = 0; } // Final sanity check: If there is a statement then the exception log should still // be clear otherwise it should not be. if ( stmt ) { if ( ! fExceptionLog.IsEmpty() ) { delete stmt; stmt = 0; } } else if ( fExceptionLog.IsEmpty() ) { ostringstream oss; oss << "Unknown failure (no execption but no TSQLStatement either executing " << sql; fExceptionLog.AddEntry(oss.str().c_str()); } return stmt; } //..................................................................... Bool_t COMET::IDbiStatement::ExecuteUpdate( const TString& sql) { // // // Purpose: Translate SQL if required and Execute. // // Return true if all updates successful. this->ClearExceptionLog(); COMETInfo( "SQL:" << fConDb.GetDbName() << ":" << sql << " "); bool ok = fConDb.GetServer()->Exec(sql.Data()); if ( ! ok ) { fConDb.RecordException(); this->AppendExceptionLog(fConDb); return false; } return fExceptionLog.IsEmpty(); } //..................................................................... Bool_t COMET::IDbiStatement::PrintExceptions(Int_t level) const { // Purpose: Print accumulated exceptions at supplied Msg level, // add them to the Global Exception Log if level >= kWarning // and return true if there are any. const COMET::IDbiExceptionLog& el(this->GetExceptionLog()); if ( el.IsEmpty() ) return false; if(level <= ICOMETLog::GetLogLevel()) ICOMETLog::GetLogStream ()<= COMET::ICOMETLog::WarnLevel ) COMET::IDbiExceptionLog::GetGELog().AddLog(el); return true; }