Concept A connected reusable statement with accompanying exception log. After deleting, the associated server connection is dropped if then idle. More...
#include <TDbiStatement.hxx>
Public Member Functions | |
TDbiStatement (TDbiConnection &conDb) | |
virtual | ~TDbiStatement () |
Bool_t | PrintExceptions (Int_t level=3) const |
const TDbiExceptionLog & | GetExceptionLog () const |
TSQLStatement * | ExecuteQuery (const TString &sql="") |
Give caller a TSQLStatement of results (Process() and StoreResult() already performed.). | |
Bool_t | ExecuteUpdate (const TString &sql="") |
Apply an update and return success/fail. | |
Private Member Functions | |
void | AppendExceptionLog (TDbiException *e) |
void | AppendExceptionLog (TSQLStatement *s) |
void | AppendExceptionLog (TDbiConnection &c) |
void | ClearExceptionLog () |
TSQLStatement * | CreateProcessedStatement (const TString &sql="") |
Private Attributes | |
TDbiConnection & | fConDb |
Connection associated with this statement. | |
TDbiExceptionLog | fExceptionLog |
Concept A connected reusable statement with accompanying exception log. After deleting, the associated server connection is dropped if then idle.
Purpose To minimise connections and to simplify interfacing to different database backends (in the original MINOS implementation, for SK_DBI_ only MySQL supported). Contact: A.Finch@lancaster.ac.uk
Definition at line 41 of file TDbiStatement.hxx.
TDbiStatement::TDbiStatement | ( | TDbiConnection & | conDb | ) |
TDbiStatement::~TDbiStatement | ( | ) | [virtual] |
Definition at line 57 of file TDbiStatement.cxx.
References TDbiConnection::DisConnectStatement(), fConDb, and SK_DBI_Trace.
00057 { 00058 // 00059 // 00060 // Purpose: Destructor 00061 00062 SK_DBI_Trace( "Destroying TDbiStatement" << " "); 00063 00064 fConDb.DisConnectStatement(); 00065 }
void TDbiStatement::AppendExceptionLog | ( | TDbiConnection & | c | ) | [inline, private] |
Definition at line 75 of file TDbiStatement.hxx.
References TDbiExceptionLog::AddLog(), fExceptionLog, and TDbiConnection::GetExceptionLog().
00075 { fExceptionLog.AddLog(c.GetExceptionLog()); }
void TDbiStatement::AppendExceptionLog | ( | TSQLStatement * | s | ) | [inline, private] |
Definition at line 74 of file TDbiStatement.hxx.
References TDbiExceptionLog::AddEntry(), and fExceptionLog.
00074 { if ( s ) fExceptionLog.AddEntry(*s); }
void TDbiStatement::AppendExceptionLog | ( | TDbiException * | e | ) | [inline, private] |
Definition at line 73 of file TDbiStatement.hxx.
References TDbiExceptionLog::AddEntry(), and fExceptionLog.
Referenced by CreateProcessedStatement(), ExecuteQuery(), and ExecuteUpdate().
00073 { if ( e ) fExceptionLog.AddEntry(*e); }
void TDbiStatement::ClearExceptionLog | ( | ) | [inline, private] |
Definition at line 76 of file TDbiStatement.hxx.
References TDbiExceptionLog::Clear(), and fExceptionLog.
Referenced by ExecuteQuery(), and ExecuteUpdate().
00076 { fExceptionLog.Clear(); }
TSQLStatement * TDbiStatement::CreateProcessedStatement | ( | const TString & | sql = "" |
) | [private] |
Definition at line 69 of file TDbiStatement.cxx.
References AppendExceptionLog(), TDbiConnection::CreatePreparedStatement(), and fConDb.
Referenced by ExecuteQuery().
00069 { 00070 00071 // Attempt to create a processed statement (caller must delete). Return 0 if failure. 00072 00073 TSQLStatement* stmt = fConDb.CreatePreparedStatement(sql.Data()); 00074 if ( ! stmt ) { 00075 this->AppendExceptionLog(fConDb); 00076 return 0; 00077 } 00078 if ( stmt->Process() ) return stmt; 00079 this->AppendExceptionLog(stmt); 00080 delete stmt; 00081 stmt = 0; 00082 return 0; 00083 00084 }
TSQLStatement * TDbiStatement::ExecuteQuery | ( | const TString & | sql = "" |
) |
Give caller a TSQLStatement of results (Process() and StoreResult() already performed.).
Definition at line 89 of file TDbiStatement.cxx.
References TDbiExceptionLog::AddEntry(), AppendExceptionLog(), ClearExceptionLog(), CreateProcessedStatement(), fConDb, fExceptionLog, TDbiConnection::GetDbName(), TDbiExceptionLog::IsEmpty(), and SK_DBI_Info.
00089 { 00090 // 00091 // 00092 // Purpose: Execute SQL. 00093 // Return: TSQLStatement with Process() and StoreResult() already performed. 00094 00095 this->ClearExceptionLog(); 00096 00097 SK_DBI_Info( "SQL:" << fConDb.GetDbName() << ":" << sql << " "); 00098 TSQLStatement* stmt = this->CreateProcessedStatement(sql); 00099 if ( ! stmt ) return 0; 00100 if ( ! stmt->StoreResult() ) { 00101 this->AppendExceptionLog(stmt); 00102 delete stmt; 00103 stmt = 0; 00104 } 00105 00106 // Final sanity check: If there is a statement then the exception log should still 00107 // be clear otherwise it should not be. 00108 if ( stmt ) { 00109 if ( ! fExceptionLog.IsEmpty() ) { 00110 delete stmt; 00111 stmt = 0; 00112 } 00113 } 00114 else if ( fExceptionLog.IsEmpty() ) { 00115 ostringstream oss; 00116 oss << "Unknown failure (no execption but no TSQLStatement either executing " << sql; 00117 fExceptionLog.AddEntry(oss.str().c_str()); 00118 } 00119 return stmt; 00120 00121 }
Bool_t TDbiStatement::ExecuteUpdate | ( | const TString & | sql = "" |
) |
Apply an update and return success/fail.
Definition at line 125 of file TDbiStatement.cxx.
References AppendExceptionLog(), ClearExceptionLog(), fConDb, fExceptionLog, TDbiConnection::GetDbName(), TDbiConnection::GetServer(), TDbiExceptionLog::IsEmpty(), TDbiConnection::RecordException(), and SK_DBI_Info.
Referenced by TDbiCascader::Lock::SetLock().
00125 { 00126 // 00127 // 00128 // Purpose: Translate SQL if required and Execute. 00129 // 00130 // Return true if all updates successful. 00131 00132 00133 this->ClearExceptionLog(); 00134 00135 SK_DBI_Info( "SQL:" << fConDb.GetDbName() << ":" << sql << " "); 00136 bool ok = fConDb.GetServer()->Exec(sql.Data()); 00137 if ( ! ok ) { 00138 fConDb.RecordException(); 00139 this->AppendExceptionLog(fConDb); 00140 return false; 00141 } 00142 00143 return fExceptionLog.IsEmpty(); 00144 00145 }
const TDbiExceptionLog& TDbiStatement::GetExceptionLog | ( | ) | const [inline] |
Definition at line 59 of file TDbiStatement.hxx.
References fExceptionLog.
Referenced by PrintExceptions(), and TDbiCascader::Lock::SetLock().
00059 { return fExceptionLog; }
Bool_t TDbiStatement::PrintExceptions | ( | Int_t | level = 3 |
) | const |
Print accumulated exceptions at supplied Msg level, add them to the Global Exception Log if level >= kWarning and return true if there are any.
Definition at line 149 of file TDbiStatement.cxx.
References GetExceptionLog(), and TDbiExceptionLog::IsEmpty().
Referenced by TDbiCascader::CreateStatement(), and TDbiCascader::Lock::SetLock().
00149 { 00150 00151 // Purpose: Print accumulated exceptions at supplied Msg level, 00152 // add them to the Global Exception Log if level >= kWarning 00153 // and return true if there are any. 00154 00155 const TDbiExceptionLog& el(this->GetExceptionLog()); 00156 if ( el.IsEmpty() ) return false; 00157 00158 return true; 00159 00160 }
TDbiConnection& TDbiStatement::fConDb [private] |
Connection associated with this statement.
Definition at line 83 of file TDbiStatement.hxx.
Referenced by CreateProcessedStatement(), ExecuteQuery(), ExecuteUpdate(), and ~TDbiStatement().
TDbiExceptionLog TDbiStatement::fExceptionLog [private] |
A log of reported exceptions. Cleared by calling ExecuteQuery, ExecuteUpdate
Definition at line 87 of file TDbiStatement.hxx.
Referenced by AppendExceptionLog(), ClearExceptionLog(), ExecuteQuery(), ExecuteUpdate(), and GetExceptionLog().