TDbiStatement.hxx

Go to the documentation of this file.
00001 #ifndef DBISTATEMENT
00002 #define DBISTATEMENT
00003 
00004 
00005 //////////////////////////////////////////////////////////////////////////
00006 ////////////////////////////     ROOT API     ////////////////////////////
00007 //////////////////////////////////////////////////////////////////////////
00008 
00009 /**
00010  *
00011  * $Id: TDbiStatement.hxx,v 1.1 2011/01/18 05:49:20 finch Exp $
00012  *
00013  * \class TDbiStatement
00014  *
00015  *
00016  * \brief
00017  * <b>Concept</b> A connected reusable statement with accompanying exception log.
00018  *  After deleting, the associated server connection is dropped if then idle.
00019  *
00020  * \brief
00021  * <b>Purpose</b>  To minimise connections and to simplify interfacing to different
00022  * database backends (in the original MINOS implementation, for SK_DBI_ only MySQL supported).
00023  *
00024  * Contact: A.Finch@lancaster.ac.uk
00025  *
00026  *
00027  */
00028 
00029 #include <list>
00030 
00031 #include "TList.h"
00032 #include "TString.h"
00033 #include "TSQLStatement.h"
00034 
00035 #include "TDbi.hxx"
00036 #include "TDbiExceptionLog.hxx"
00037 #include "TDbiConnection.hxx"
00038 
00039 class TDbiException;
00040 
00041 class TDbiStatement
00042 {
00043 
00044 public:
00045 
00046 // Constructors and destructors.
00047            TDbiStatement(TDbiConnection& conDb);
00048   virtual ~TDbiStatement();
00049 
00050 // State testing member functions
00051 
00052 // Exception log handling.
00053 
00054 /// Print accumulated exceptions at supplied Msg level,
00055 /// add them to the Global Exception Log if level >= kWarning
00056 /// and return true if there are any.
00057   Bool_t PrintExceptions(Int_t level = 3) const;
00058 
00059   const TDbiExceptionLog& GetExceptionLog() const { return fExceptionLog; }
00060 
00061 // State changing member functions
00062 
00063 // Database I/O
00064 
00065 /// Give caller a TSQLStatement of results (Process() and StoreResult() already performed.).
00066   TSQLStatement* ExecuteQuery(const TString& sql="");
00067 
00068 /// Apply an update and return success/fail.
00069   Bool_t ExecuteUpdate( const TString& sql="");
00070 
00071 private:
00072 
00073   void AppendExceptionLog(TDbiException* e)  { if ( e ) fExceptionLog.AddEntry(*e); }
00074   void AppendExceptionLog(TSQLStatement* s) { if ( s ) fExceptionLog.AddEntry(*s); }
00075   void AppendExceptionLog(TDbiConnection& c) {          fExceptionLog.AddLog(c.GetExceptionLog()); }
00076   void ClearExceptionLog()                  { fExceptionLog.Clear(); }
00077 
00078   TSQLStatement* CreateProcessedStatement(const TString& sql="");
00079 
00080 // Data members
00081 
00082 ///Connection associated with this statement.
00083   TDbiConnection& fConDb;
00084 
00085 /// A log of reported exceptions.
00086 /// Cleared by calling ExecuteQuery, ExecuteUpdate
00087   TDbiExceptionLog fExceptionLog;
00088 
00089  ClassDef(TDbiStatement,0)     // Managed TSQL_Statement
00090 
00091 };
00092 
00093 
00094 
00095 #endif // DBISTATEMENT
00096 
00097 

Generated on 11 Aug 2013 for SKDatabase by  doxygen 1.6.1