#ifndef DBISTATEMENT
#define DBISTATEMENT
//////////////////////////////////////////////////////////////////////////
//////////////////////////// ROOT API ////////////////////////////
//////////////////////////////////////////////////////////////////////////
/**
*
* $Id: IDbiStatement.hxx,v 1.1 2011/01/18 05:49:20 finch Exp $
*
* \class COMET::IDbiStatement
*
*
* \brief
* Concept A connected reusable statement with accompanying exception log.
* After deleting, the associated server connection is dropped if then idle.
*
* \brief
* Purpose To minimise connections and to simplify interfacing to different
* database backends (in the original MINOS implementation, for COMET only MySQL supported).
*
* Contact: A.Finch@lancaster.ac.uk
*
*
*/
#include
#include "TList.h"
#include "TString.h"
#include "TSQLStatement.h"
#include "IDbi.hxx"
#include "IDbiExceptionLog.hxx"
#include "IDbiConnection.hxx"
namespace COMET {
class IDbiException;
}
namespace COMET {
class IDbiStatement
{
public:
// Constructors and destructors.
IDbiStatement(IDbiConnection& conDb);
virtual ~IDbiStatement();
// State testing member functions
// Exception log handling.
/// Print accumulated exceptions at supplied Msg level,
/// add them to the Global Exception Log if level >= kWarning
/// and return true if there are any.
Bool_t PrintExceptions(Int_t level = 3) const;
const IDbiExceptionLog& GetExceptionLog() const { return fExceptionLog; }
// State changing member functions
// Database I/O
/// Give caller a TSQLStatement of results (Process() and StoreResult() already performed.).
TSQLStatement* ExecuteQuery(const TString& sql="");
/// Apply an update and return success/fail.
Bool_t ExecuteUpdate( const TString& sql="");
private:
void AppendExceptionLog(IDbiException* e) { if ( e ) fExceptionLog.AddEntry(*e); }
void AppendExceptionLog(TSQLStatement* s) { if ( s ) fExceptionLog.AddEntry(*s); }
void AppendExceptionLog(IDbiConnection& c) { fExceptionLog.AddLog(c.GetExceptionLog()); }
void ClearExceptionLog() { fExceptionLog.Clear(); }
TSQLStatement* CreateProcessedStatement(const TString& sql="");
// Data members
///Connection associated with this statement.
IDbiConnection& fConDb;
/// A log of reported exceptions.
/// Cleared by calling ExecuteQuery, ExecuteUpdate
IDbiExceptionLog fExceptionLog;
ClassDef(IDbiStatement,0) // Managed TSQL_Statement
};
};
#endif // DBISTATEMENT