00001 #ifndef DBITABLEMETADATA_H 00002 #define DBITABLEMETADATA_H 00003 00004 00005 ////////////////////////////////////////////////////////////////////////// 00006 //////////////////////////// ROOT API //////////////////////////// 00007 ////////////////////////////////////////////////////////////////////////// 00008 00009 /** 00010 * 00011 * $Id: TDbiTableMetaData.hxx,v 1.1 2011/01/18 05:49:20 finch Exp $ 00012 * 00013 * \class TDbiTableMetaData 00014 * 00015 * 00016 * \brief 00017 * <b>Concept</b> Table meta data i.e. data about the table itself 00018 * 00019 * \brief 00020 * <b>Purpose</b> To provide information on the names and types of columns 00021 * 00022 * 00023 * Contact: A.Finch@lancaster.ac.uk 00024 *to transient TDbiRowStream objects. 00025 * 00026 */ 00027 00028 #include <string> 00029 using std::string; 00030 #include <vector> 00031 00032 #include "TDbiFieldType.hxx" 00033 00034 00035 class TDbiTableMetaData 00036 { 00037 00038 friend class TDbiDBProxy; //See ctor program notes. 00039 00040 public: 00041 00042 // Constructors and destructors. 00043 TDbiTableMetaData(const string& tableName = "Unknown"); 00044 virtual ~TDbiTableMetaData(); 00045 00046 // State testing member functions 00047 00048 /// Return SQL string to create table. 00049 string Sql() const; 00050 00051 string TableName() const { return fTableName; } 00052 Bool_t HasEpoch() const {return this->NumCols() >=4 && this->ColName(4) == "EPOCH"; } 00053 UInt_t NumCols() const { return fNumCols;} 00054 00055 // Column attribute getters (columns number starts from 1 NOT zero) 00056 00057 const TDbiFieldType& ColFieldType(Int_t colNum) const { return GetAttributes(colNum).Type;} 00058 UInt_t ColFieldConcept(Int_t colNum) const { return GetAttributes(colNum).Concept;} 00059 Bool_t ColIsNullable(Int_t colNum) const { return GetAttributes(colNum).IsNullable;} 00060 Bool_t ColMustDelimit(Int_t colNum) const { return GetAttributes(colNum).MustDelimit;} 00061 string ColName(Int_t colNum) const { return GetAttributes(colNum).Name;} 00062 00063 // State changing member functions 00064 00065 /// Recreate from SQL used to create table. 00066 void SetFromSql(const string& sql); 00067 00068 protected: 00069 00070 void Clear(); 00071 00072 // Column attribute setters (columns number starts from 1 NOT zero) 00073 00074 void SetColIsNullable(Int_t colNum, Bool_t isNullable = true) { SetAttributes(colNum).IsNullable = isNullable;} 00075 void SetColName(const string& name, Int_t colNum) { SetAttributes(colNum).Name = name;} 00076 void SetColFieldType(const TDbiFieldType& type, Int_t colNum); 00077 00078 private: 00079 00080 /// Use to parse table creation SQL - move to UtilString? 00081 static string GetToken(const char*& strPtr); 00082 00083 /// Sanity check: limit number of columns. 00084 enum { MAXCOL = 1000}; 00085 00086 void ExpandTo(UInt_t colNum); 00087 00088 /// Column attributes 00089 struct ColumnAttributes { 00090 ColumnAttributes() { this->SetDefault(); } 00091 void SetDefault() { 00092 Name = "Unknown"; 00093 Concept = TDbi::kUnknown; 00094 MustDelimit = false; 00095 IsNullable = false; 00096 Type = TDbi::kUnknown; 00097 } 00098 string Name; 00099 Int_t Concept; 00100 Bool_t MustDelimit; 00101 Bool_t IsNullable; 00102 TDbiFieldType Type; 00103 }; 00104 00105 /// Dummy attributes (used when requesting invalid column) 00106 static ColumnAttributes fgDummy; 00107 00108 00109 /// Return a column attributes (will be dummy entry if requesting invalid column) 00110 const ColumnAttributes& GetAttributes(Int_t colNum) const; 00111 00112 /// Return a setable column attributes (will be dummy entry if requesting invalid column) 00113 ColumnAttributes& SetAttributes(Int_t colNum); 00114 00115 // Data members 00116 00117 /// Column attributes indexed by column (starting from 0) 00118 std::vector<ColumnAttributes> fColAttr; 00119 00120 /// Number of columns. 00121 UInt_t fNumCols; 00122 00123 /// Table name (either XXX or XXXVLD) 00124 string fTableName; 00125 00126 ClassDef(TDbiTableMetaData,0) //TableMetaData for database table 00127 00128 }; 00129 00130 00131 #endif // DBITABLEMETADATA_H 00132