/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Calibration/rdbModel/rdbModel-00-01-01/rdbModel/Db/MysqlConnection.h

Go to the documentation of this file.
00001 // $Header: /bes/bes/BossCvs/Calibration/rdbModel/rdbModel/Db/MysqlConnection.h,v 1.3 2009/03/18 02:01:02 huangb Exp $
00002 #ifndef RDBMODEL_MYSQLCONNECTION_H
00003 #define RDBMODEL_MYSQLCONNECTION_H
00004 
00005 #include "rdbModel/Db/Connection.h"
00006 #include "rdbModel/Tables/Assertion.h"
00007 #include "rdbModel/Management/Visitor.h"
00008 #include <map>
00009 #include <iostream>
00010 
00011 typedef struct st_mysql MYSQL;
00012 typedef struct st_mysql_res MYSQL_RES;
00013 
00014 namespace rdbModel{
00015 
00016   class MysqlResults;
00017   class Datatype;
00032   class MysqlConnection : public virtual Connection, public Visitor {
00033   public:
00038     MysqlConnection(std::ostream* out=0, std::ostream* errOut=0);
00039     virtual ~MysqlConnection();
00040     virtual bool open(const std::string& host, const std::string& userid,
00041                       const std::string& password,
00042                       const std::string& dbName);
00043                       //                      ,unsigned int       port=0);
00044 
00047      virtual bool open(const std::string& parms);
00048 
00051     virtual bool close();
00052 
00054     virtual bool isConnected() {return m_connected;}
00055 
00056     std::ostream* getOut() const {return m_out;}
00057     std::ostream* getErrOut() const {return m_err;}
00066     virtual MATCH matchSchema(Rdb *rdb, bool matchDbName=true);
00067 
00080     virtual bool insertRow(const std::string& tableName, 
00081                            const StringVector& colNames, 
00082                            const StringVector& values,
00083                            int* auto_value=0,
00084                            const StringVector* nullCols = 0);
00085 
00089     virtual unsigned int update(const std::string& tableName, 
00090                                 const StringVector& colNames, 
00091                                 const StringVector& values,
00092                                 const Assertion* where=0,
00093                                 const StringVector* nullCols = 0);
00094 
00108     virtual ResultHandle* select(const std::string& tableName,
00109                                  const StringVector& getCols,
00110                                  const StringVector& orderCols,
00111                                  const Assertion* where=0,
00112                                  int   rowLimit=0,
00113                                  int   rowOffset=0);
00114 
00122     virtual ResultHandle* dbRequest(const std::string& request);
00123 
00124 
00130     virtual bool 
00131     compileAssertion(const Assertion* a, std::string& sqlString) const;
00132 
00137     virtual void disableModify(bool disable) {m_writeDisabled=disable;}
00138 
00139     // Needed to satisfy Visitor interface:
00140     virtual Visitor::VisitorState visitRdb(Rdb*);
00141     virtual Visitor::VisitorState visitTable(Table*);
00142     virtual Visitor::VisitorState visitColumn(Column*);
00143     virtual Visitor::VisitorState visitIndex(Index*);
00144     virtual Visitor::VisitorState visitAssertion(Assertion*);
00145 
00146     virtual VisitorState visitInsertNew(InsertNew*);
00147     virtual VisitorState visitSupersede(Supersede*);
00148     virtual VisitorState visitQuery(Query*);
00149     virtual VisitorState visitSet(Set*);
00150     virtual VisitorState visitInterRow(InterRow*);
00151       
00152 
00153 
00154 
00155   private:
00158     enum VISITOR {
00159       VISITORundefined,
00160       VISITORmatch
00161     };
00162 
00163     MYSQL* m_mysql;
00164     bool   m_connected;
00165 
00166     std::string m_dbName;
00167     std::ostream* m_out;
00168     std::ostream* m_err;
00169 
00170     // Following collection of data members is only of interest while 
00171     // visit is in progress.
00172 
00173     VISITOR m_visitorType;
00174     bool    m_matchDbName;
00175 
00177     MATCH   m_matchReturn;
00178 
00180     Rdb*   m_rdb;
00181 
00184     std::vector<Column* >  m_ourCols;
00185 
00187     MYSQL_RES* m_tempRes;
00188 
00190     std::map<std::string, unsigned int> m_colIx;
00191 
00192     std::string m_primColName;
00193 
00194     static bool   m_compileInit;
00195     bool          m_writeDisabled;
00196 
00197     static void compileInit();
00198     static bool compileComparison(Assertion::Operator* op, 
00199                                   std::string& sqlString);
00200     static bool compileOperator(Assertion::Operator* op, 
00201                                 std::string &sqlString);
00202 
00203     bool checkDType(Datatype* dtype, const std::string& sqlType);
00204 
00205    //huangb add to store the database information
00206     std::string m_host;
00207     std::string m_user;
00208     std::string m_password; 
00209 //    std::string m_dbName;
00210  };
00211 
00212 }  // end namespace rdbModel
00213 #endif

Generated on Tue Nov 29 22:57:56 2016 for BOSS_7.0.2 by  doxygen 1.4.7