Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

StDbSql.hh

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * 00003 * $Id: StDbSql.hh,v 1.10 2005/11/07 14:46:44 deph Exp $ 00004 * 00005 * Author: R. Jeff Porter 00006 *************************************************************************** 00007 * 00008 * Description: Implementation class of StDataBaseI in (My)SQL 00009 * 00010 *************************************************************************** 00011 * 00012 * $Log: StDbSql.hh,v $ 00013 * Revision 1.10 2005/11/07 14:46:44 deph 00014 * added protoype for function that accepts IN for non contiguous elementIDs 00015 * 00016 * Revision 1.9 2004/01/15 00:02:25 fisyak 00017 * Replace ostringstream => StString, add option for alpha 00018 * 00019 * Revision 1.8 2003/09/16 22:44:17 porter 00020 * got rid of all ostrstream objects; replaced with StString+string. 00021 * modified rules.make and added file stdb_streams.h for standalone compilation 00022 * 00023 * Revision 1.7 2003/04/11 22:47:36 porter 00024 * Added a fast multi-row write model specifically needed by the daqEventTag 00025 * writer. Speed increased from about 100Hz to ~3000Hz. It is only invoked if 00026 * the table is marked as Non-Indexed (daqTags & scalers). For non-indexed tables 00027 * which include binary stored data (we don't have any yet), the fast writer has 00028 * to invoke a slower buffer so that the rates are a bit slower (~500Hz at 50 rows/insert). 00029 * 00030 * Revision 1.6 2003/01/10 04:19:20 porter 00031 * added feature of getting timestamp list (but no data) for a table. 00032 * fixed 2 features sometimes used in online in query-by-whereclause. 00033 * removed a stray 'cout' in a routine that is rarely accessed 00034 * 00035 * Revision 1.5 2002/01/30 15:40:48 porter 00036 * changed limits on flavor tag & made defaults retrieving more readable 00037 * 00038 * Revision 1.4 2001/10/24 04:05:20 porter 00039 * added long long type to I/O and got rid of obsolete dataIndex table 00040 * 00041 * Revision 1.3 2001/04/25 17:19:53 perev 00042 * HPcorrs 00043 * 00044 * Revision 1.2 2001/03/30 18:48:26 porter 00045 * modified code to keep Insure from wigging-out on ostrstream functions. 00046 * moved some messaging into a StDbSql method. 00047 * 00048 * Revision 1.1 2001/01/22 18:37:59 porter 00049 * Update of code needed in next year running. This update has little 00050 * effect on the interface (only 1 method has been changed in the interface). 00051 * Code also preserves backwards compatibility so that old versions of 00052 * StDbLib can read new table structures. 00053 * -Important features: 00054 * a. more efficient low-level table structure (see StDbSql.cc) 00055 * b. more flexible indexing for new systems (see StDbElememtIndex.cc) 00056 * c. environment variable override KEYS for each database 00057 * d. StMessage support & clock-time logging diagnostics 00058 * -Cosmetic features 00059 * e. hid stl behind interfaces (see new *Impl.* files) to again allow rootcint access 00060 * f. removed codes that have been obsolete for awhile (e.g. db factories) 00061 * & renamed some classes for clarity (e.g. tableQuery became StDataBaseI 00062 * and mysqlAccessor became StDbSql) 00063 * 00064 * 00065 **************************************************************************/ 00066 #ifndef STDATABASE_HH 00067 #define STDATABASE_HH 00068 00069 #include "StDbTableDescriptor.h" 00070 #include "StDbManager.hh" 00071 #include "StDataBaseI.hh" 00072 #include "MysqlDb.h" 00073 #include "StDbBuffer.h" 00074 00075 #include <list> 00076 #ifdef ST_NO_TEMPLATE_DEF_ARGS 00077 typedef list<StDbTableDescriptor*,allocator<StDbTableDescriptor*> > DescList; 00078 #else 00079 #if !defined(ST_NO_NAMESPACES) 00080 using std::list; 00081 #endif 00082 00083 #ifdef HPUX 00084 #define freeze(i) str() 00085 #endif 00086 00087 typedef list<StDbTableDescriptor*> DescList; 00088 #endif 00089 00090 #define MAX_EID_INDECES 10 00091 00092 class StDbSql : public StDataBaseI { 00093 00094 protected: 00095 00096 StDbManager* mgr; 00097 00098 // A found descriptor list -> can be faster than asking DB if already found 00099 DescList mdescriptors; 00100 00101 char* mretString; // memory holder for internal string passing 00102 int mtableCatalog; // 0==hasn't checked, 1==doesn't have it, 2==has it 00103 char* mdefaultEndDateTime; 00104 unsigned int mdefaultEndTime; 00105 00106 // descriptor tracking methods 00107 StDbTableDescriptor* findDescriptor(int structID, int schemaID); 00108 StDbTableDescriptor* getDescriptor(int structID, int schemaID); 00109 void addDescriptor(StDbTableDescriptor* td); 00110 void deleteDescriptors(); 00111 void deleteDescriptor(int structID, int schemaID); 00112 00113 int prepareNode(StDbNode* node); 00114 int queryNode(StDbNode* node); 00115 bool readNodeInfo(StDbNode* node); 00116 bool readConfigNodeInfo(StDbConfigNode* node); 00117 bool readTableInfo(StDbTable* table); 00118 bool checkValue(const char* colName, const char* colValue); 00119 bool checkForNull(const char* src); 00120 00121 // use local 'mretString' for building and tracking common query entities 00122 char* insertNodeString(StDbNode* node); 00123 char* getFlavorQuery(const char* flavor); 00124 char* getProdTimeQuery(unsigned int prodTime); 00125 char* getElementList(int* elements, int num); 00126 char* getElementListIN(int* elements, int num); 00127 char* getColumnList(StDbTable* table,char* tableName=0, char* funcName=0); 00128 char* getEmptyString(); 00129 00130 bool hasInstance(StDbTable* table); 00131 void checkTableCatalog(); 00132 char* checkTablePrepForQuery(StDbTable* table, bool checkIndexed=false); 00133 00134 void deleteRows(const char* tableName, int* rowID, int nrows); 00135 void initEndTime(); 00136 00137 char* mRetString(StString& rs); 00138 int sendMess(const char* a, const char* b, StDbMessLevel m, 00139 int lineNum=0, const char* className=" ", 00140 const char* methName=" "); 00141 00142 /* new */ 00143 bool checkColumn(const char* tableName, const char* columnName); 00144 bool updateEndTime(StDbTable* table, const char* dataTable, unsigned int reqTime); 00145 void init(); 00146 00147 // specific meth for fast multi-row writes of non-indexed tables 00148 virtual int WriteDbNoIndex(StDbTable* table, unsigned int storeTime); 00149 00150 00151 public: 00152 00153 StDbSql(MysqlDb &db, StDbBuffer& buffer); 00154 StDbSql(MysqlDb &db, StDbBuffer& buffer, 00155 StDbType type, StDbDomain domain); 00156 StDbSql(MysqlDb &db, StDbBuffer& buffer, 00157 const char* typeName, const char* domainName); 00158 00159 virtual ~StDbSql(); 00160 00161 virtual void use(); 00162 virtual void close(); 00163 virtual void clear(); 00164 00165 virtual int QueryDb(StDbConfigNode* node); 00166 virtual int QueryDb(StDbNode* node); 00167 virtual int QueryDb(StDbTable* table, unsigned int reqTime); 00168 virtual int QueryDb(StDbTable* table, const char* whereClause); 00169 virtual unsigned int* QueryDbTimes(StDbTable* table, const char* whereClause,int opt=0); 00170 virtual int QueryDbFunction(StDbTable* table, const char* whereClause, char* funcName); 00171 virtual int QueryDescriptor(StDbTable* table); 00172 virtual int WriteDb(StDbTable* table, unsigned int storeTime); 00173 virtual int WriteDb(StDbConfigNode* node, int parentID, int& configID); 00174 00175 virtual int storeConfigNode(StDbConfigNode* node); 00176 virtual int storeTableNode(StDbTable* table); 00177 virtual bool insertNodeRelation(int configID, int parent, int child); 00178 virtual bool rollBack(StDbNode* node); 00179 virtual bool rollBack(StDbTable* table); 00180 00181 virtual unsigned int getUnixTime(const char* time) ; 00182 virtual char* getDateTime(unsigned int time) ; 00183 00184 virtual int* selectElements(const char* elementName, 00185 StDbElementIndex* inval, 00186 int& numElements); 00187 00188 char* getDataTable(StDbTable* table, unsigned int time); 00189 char** getDataTables(StDbTable* table,int& numTables); 00190 void setDbUtils(MysqlDb& db, StDbBuffer& buffer); 00191 void setDefaultReturnValues(StDbTable* table, unsigned int reqTime); 00192 void setDefaultBeginTime(StDbTable* table,unsigned int reqTime); 00193 void setDefaultEndTime(StDbTable* table ); 00194 char** getIndexNames( const char* elementName, int& numIndexes); 00195 00196 MysqlDb& Db; 00197 StDbBuffer& buff; 00198 00199 }; 00200 00201 inline char* StDbSql::mRetString(StString& rs){ 00202 if(mretString)delete [] mretString; 00203 string srs=rs.str(); 00204 mretString = new char[srs.length()+1]; 00205 strcpy(mretString,srs.c_str()); 00206 return mretString; 00207 } 00208 00209 inline int StDbSql::sendMess(const char* a, const char* b, StDbMessLevel m, int lineNum, const char* className, const char* methName){ 00210 if(m==dbMDebug && !(mgr->IsVerbose()))return 0; 00211 return mgr->printInfo(a,b,m,lineNum,className,methName); 00212 } 00213 00214 inline void StDbSql::init() { 00215 mretString = 0; 00216 mtableCatalog=0; 00217 mdefaultEndDateTime = 0; 00218 } 00219 00220 inline void StDbSql::use() { Db.setDefaultDb(mdbName); }; 00221 inline void StDbSql::close() { Db.Close(); }; 00222 inline void StDbSql::clear() { Db.Release(); buff.Raz(); }; 00223 00224 #endif 00225 00226 00227 00228 00229

Generated on Thu Aug 24 14:45:27 2006 for Doxygen by doxygen 1.3.7