00001 #ifndef DBIRESULTSET_H 00002 #define DBIRESULTSET_H 00003 00004 00005 ////////////////////////////////////////////////////////////////////////// 00006 //////////////////////////// ROOT API //////////////////////////// 00007 ////////////////////////////////////////////////////////////////////////// 00008 00009 /** 00010 * 00011 * 00012 * \class TDbiInRowStream 00013 * 00014 * 00015 * \brief 00016 * <b>Concept</b> Input stream with type checking. 00017 * 00018 * \brief 00019 * <b>Purpose</b> This is an interface to TSQLResultSet. Its primary 00020 * purpose is to provide an >> operator with built-type checking to 00021 * simplify the writing of TDbiTableRow subclasses. 00022 * 00023 * Contact: A.Finch@lancaster.ac.uk 00024 * 00025 * 00026 */ 00027 00028 00029 #include <string> 00030 00031 #include "TString.h" 00032 00033 #include "TDbi.hxx" 00034 #include "TDbiRowStream.hxx" 00035 00036 00037 class TDbiString; 00038 class TDbiStatement; 00039 class TDbiTableMetaData; 00040 class TDbiTableProxy; 00041 00042 class TSQLStatement; 00043 class TVldTimeStamp; 00044 00045 class TDbiInRowStream : public TDbiRowStream 00046 { 00047 00048 public: 00049 00050 // Constructors and destructors. 00051 ///\verbatim 00052 /// 00053 /// Purpose: Default constructor 00054 /// 00055 /// Arguments: 00056 /// stmtDb in TDbiStatement to be used for query. May be zero. 00057 /// sql in The query to be applied to the statement. 00058 /// metaData in Meta data for query. 00059 /// tableProxy in Source TDbiTableProxy. 00060 /// dbNo in Cascade no. of source. 00061 /// 00062 /// Return: n/a 00063 /// 00064 /// Contact: N. West 00065 /// 00066 /// Specification:- 00067 /// ============= 00068 /// 00069 /// o Create ResultSet for query. 00070 ///\endverbatim 00071 TDbiInRowStream(TDbiStatement* stmtDb, 00072 const TDbiString& sql, 00073 const TDbiTableMetaData* metaData, 00074 const TDbiTableProxy* tableProxy, 00075 UInt_t dbNo, 00076 const string& fillOpts = ""); 00077 virtual ~TDbiInRowStream(); 00078 00079 // State testing member functions 00080 Bool_t CurColExists() const; 00081 string CurColString() const; 00082 string CurColValue() const { LoadCurValue(); return fValString;} 00083 UInt_t CurRowNum() const { return fCurRow;} 00084 UInt_t GetDbNo() const { return fDbNo; } 00085 string GetFillOpts() const { return fFillOpts;} 00086 const TDbiTableProxy* GetTableProxy() const { return fTableProxy; } 00087 /// IsBeforeFirst not needed for ROOT API, but leave a dummy 00088 /// for now so as not to disturb TDbiInRowStream API. 00089 Bool_t IsBeforeFirst() const { return false; }; 00090 Bool_t IsExhausted() const { return fExhausted; } 00091 void RowAsCsv(string& row) const; 00092 00093 // State changing member functions 00094 00095 TDbiInRowStream& operator>>(Bool_t& dest); 00096 TDbiInRowStream& operator>>(Char_t& dest); 00097 TDbiInRowStream& operator>>(Short_t& dest); 00098 TDbiInRowStream& operator>>(UShort_t& dest); 00099 TDbiInRowStream& operator>>(Int_t& dest); 00100 TDbiInRowStream& operator>>(UInt_t& dest); 00101 TDbiInRowStream& operator>>(Long_t& dest); 00102 TDbiInRowStream& operator>>(ULong_t& dest); 00103 TDbiInRowStream& operator>>(Float_t& dest); 00104 TDbiInRowStream& operator>>(Double_t& dest); 00105 TDbiInRowStream& operator>>(string& dest); 00106 TDbiInRowStream& operator>>(TVldTimeStamp& dest); 00107 00108 Bool_t FetchRow(); 00109 00110 private: 00111 00112 string& AsString(TDbi::DataTypes type); 00113 Bool_t LoadCurValue() const; 00114 TString GetStringFromTSQL(Int_t col) const; 00115 00116 // Data members 00117 00118 /// Current row in query (0...) 00119 Int_t fCurRow; 00120 00121 /// Cascade no. of source 00122 UInt_t fDbNo; 00123 00124 /// Owned TDbiStatement. May be 0. 00125 /// It's only use is to create a TSQLStatement in the ctor but it is not 00126 /// destroyed until the dtor to prevent a premature attempt to close the 00127 /// connection. 00128 TDbiStatement* fStatement; 00129 00130 /// Pointer to owned statement, may be 0. 00131 TSQLStatement* fTSQLStatement; 00132 00133 /// True is result set missing or exhausted. 00134 Bool_t fExhausted; 00135 00136 /// TDbiTableProxy that produced this set. 00137 const TDbiTableProxy* fTableProxy; 00138 00139 /// Buffer for assembling value 00140 mutable string fValString; 00141 00142 /// Optional fill options. 00143 string fFillOpts; 00144 00145 ClassDef(TDbiInRowStream,0) //ResultSet from Query to database table 00146 00147 }; 00148 00149 00150 00151 #endif // DBIRESULTSET_H 00152