00001 /* 00002 openMyDB.h 00003 ========== 00004 These classes define the MySQL implementation 00005 to the open database class interface. 00006 00007 Copyright 2002 - davidmc@w3sys.com 00008 W3 System Development and Hosting www.w3sys.com 00009 00010 */ 00011 00012 #ifndef OPEN_MYDB_H 00013 #define OPEN_MYDB_H 1 00014 00015 #include <mysql.h> 00016 #include "openDB.h" 00017 #include "openFields.h" 00018 #include "mySqlTypeMap.h" 00019 00020 /* 00021 MySQL Implementation Classes 00022 =========================== 00023 */ 00024 class mySqlDB: public openDB 00025 { 00026 protected: 00027 00028 string host; 00029 string uid; 00030 string pwd; 00031 string db; 00032 unsigned int port; 00033 string socket; 00034 const char * pchSocket; 00035 unsigned int flags; 00036 00037 // MYSQL pointer and struct 00038 MYSQL * connection, mysql; 00039 bool transactioning; 00040 00041 virtual bool parseConnection( string & strConnection ); 00042 virtual openCMD * createCommand(); 00043 virtual openRS * createRecordset(); 00044 00045 public: 00046 00047 mySqlDB( string strConnection ); 00048 virtual ~mySqlDB(); 00049 virtual dbProvider getProvider( void ); 00050 00051 bool error( int state = 0 ); 00052 00053 MYSQL * getConnection( void ) 00054 { 00055 return connection; 00056 } 00057 }; 00058 00059 00060 /* 00061 This base class defines the interfaces to the command 00062 ===================================================== 00063 */ 00064 class mySqlCMD: public openCMD 00065 { 00066 protected: 00067 mySqlDB * poDB; 00068 00069 // return from query 00070 int state; 00071 size_t rows; 00072 00073 public: 00074 00075 mySqlCMD( openDB & idb ); 00076 virtual ~mySqlCMD(); 00077 00078 // methods that must be defined by impl 00079 virtual bool execute( string ); 00080 virtual int resultId( void ); 00081 virtual long long resultKey( const string & keyName , const string & tableName ); 00082 virtual bool beginTransaction(); 00083 virtual bool commit(); 00084 virtual bool rollback(); 00085 }; 00086 00087 00088 const size_t maxColLen = 512; 00089 /* 00090 This openRS base class defines the interfaces to the recordset 00091 ============================================================== 00092 */ 00093 class mySqlRS : public openRS 00094 { 00095 00096 protected: 00097 mySqlDB * poDB; 00098 00099 // return from query 00100 int state; 00101 size_t rows; 00102 MYSQL_RES * result; 00103 00104 // for field type resolution 00105 my_col_infoVector colInfo; 00106 mysqlMap colMap; 00107 00108 // transaction management 00109 bool beginTransaction(); 00110 bool commit(); 00111 00112 public: 00113 mySqlRS( openDB & idb ); 00114 virtual ~mySqlRS(); 00115 00116 virtual bool open( string sql ); 00117 virtual bool close( void ); 00118 virtual bool next( int rows = 1 ); 00119 virtual bool previous( int rows = 1 ); 00120 virtual string & getErrors( void ); 00121 }; 00122 00123 #endif
1.5.5