#ifndef DBIRESULTSET_H #define DBIRESULTSET_H ////////////////////////////////////////////////////////////////////////// //////////////////////////// ROOT API //////////////////////////// ////////////////////////////////////////////////////////////////////////// /** * * * \class COMET::IDbiInRowStream * * * \brief * Concept Input stream with type checking. * * \brief * Purpose This is an interface to TSQLResultSet. Its primary * purpose is to provide an >> operator with built-type checking to * simplify the writing of IDbiTableRow subclasses. * * Contact: A.Finch@lancaster.ac.uk * * */ #include #include "TString.h" #include "IDbi.hxx" #include "IDbiRowStream.hxx" namespace COMET { class IDbiString; class IDbiStatement; class IDbiTableMetaData; class IDbiTableProxy; } class TSQLStatement; namespace COMET { class IVldTimeStamp; }; namespace COMET { class IDbiInRowStream : public IDbiRowStream { public: // Constructors and destructors. ///\verbatim /// /// Purpose: Default constructor /// /// Arguments: /// stmtDb in COMET::IDbiStatement to be used for query. May be zero. /// sql in The query to be applied to the statement. /// metaData in Meta data for query. /// tableProxy in Source COMET::IDbiTableProxy. /// dbNo in Cascade no. of source. /// /// Return: n/a /// /// Contact: N. West /// /// Specification:- /// ============= /// /// o Create ResultSet for query. ///\endverbatim IDbiInRowStream(IDbiStatement* stmtDb, const IDbiString& sql, const IDbiTableMetaData* metaData, const IDbiTableProxy* tableProxy, UInt_t dbNo, const string& fillOpts = ""); virtual ~IDbiInRowStream(); // State testing member functions Bool_t CurColExists() const; string CurColString() const; string CurColValue() const { LoadCurValue(); return fValString;} UInt_t CurRowNum() const { return fCurRow;} UInt_t GetDbNo() const { return fDbNo; } string GetFillOpts() const { return fFillOpts;} const IDbiTableProxy* GetTableProxy() const { return fTableProxy; } /// IsBeforeFirst not needed for ROOT API, but leave a dummy /// for now so as not to disturb IDbiInRowStream API. Bool_t IsBeforeFirst() const { return false; }; Bool_t IsExhausted() const { return fExhausted; } void RowAsCsv(string& row) const; // State changing member functions COMET::IDbiInRowStream& operator>>(Bool_t& dest); COMET::IDbiInRowStream& operator>>(Char_t& dest); COMET::IDbiInRowStream& operator>>(Short_t& dest); COMET::IDbiInRowStream& operator>>(UShort_t& dest); COMET::IDbiInRowStream& operator>>(Int_t& dest); COMET::IDbiInRowStream& operator>>(UInt_t& dest); COMET::IDbiInRowStream& operator>>(Long_t& dest); COMET::IDbiInRowStream& operator>>(ULong_t& dest); COMET::IDbiInRowStream& operator>>(Float_t& dest); COMET::IDbiInRowStream& operator>>(Double_t& dest); COMET::IDbiInRowStream& operator>>(string& dest); COMET::IDbiInRowStream& operator>>(COMET::IVldTimeStamp& dest); Bool_t FetchRow(); private: string& AsString(IDbi::DataTypes type); Bool_t LoadCurValue() const; TString GetStringFromTSQL(Int_t col) const; // Data members /// Current row in query (0...) Int_t fCurRow; /// Cascade no. of source UInt_t fDbNo; /// Owned IDbiStatement. May be 0. /// It's only use is to create a TSQLStatement in the ctor but it is not /// destroyed until the dtor to prevent a premature attempt to close the /// connection. IDbiStatement* fStatement; /// Pointer to owned statement, may be 0. TSQLStatement* fTSQLStatement; /// True is result set missing or exhausted. Bool_t fExhausted; /// IDbiTableProxy that produced this set. const IDbiTableProxy* fTableProxy; /// Buffer for assembling value mutable string fValString; /// Optional fill options. string fFillOpts; ClassDef(IDbiInRowStream,0) //ResultSet from Query to database table }; }; #endif // DBIRESULTSET_H