00001 #ifndef open_db_h 00002 #define open_db_h 00003 #include <string> 00004 #include "openFields.h" 00005 00006 00007 // forward class declarations 00008 class openCMD; 00009 class openRS; 00010 class openDB; 00011 00012 /* 00013 This emumeration is my best first guess at possible 00014 providers 00015 00016 */ 00017 enum dbProvider 00018 { 00019 PostGresQL, 00020 MySQL, 00021 ODBC, 00022 DB2, 00023 Informix, 00024 Sybase // should work for MSSQL 00025 }; 00026 00027 /* 00028 00029 The next 3 object factories perform the following: 00030 1) Create the requested underlying implementation. 00031 2) Hide the pointers and pass back references instead. 00032 3) Manage the lifetime of the underlying heap object instance. 00033 00034 */ 00035 00036 // database object factory 00037 class openDbFactory 00038 { 00039 private: 00040 openDB * pDB; 00041 public: 00042 openDbFactory( dbProvider dbImplementation, const char * strConnection ); 00043 ~openDbFactory(); 00044 openDB & db(); 00045 }; 00046 00047 // recordset object factory 00048 class openRsFactory 00049 { 00050 private: 00051 openRS * pRS; 00052 public: 00053 openRsFactory( openDB & rdb ); 00054 ~openRsFactory(); 00055 openRS & rs(); 00056 }; 00057 00058 // command object factory 00059 class openCmdFactory 00060 { 00061 private: 00062 openCMD * pCMD; 00063 public: 00064 openCmdFactory( openDB & rdb ); 00065 ~openCmdFactory(); 00066 openCMD & cmd(); 00067 }; 00068 00069 00070 /* 00071 This base class defines the interfaces to the database 00072 */ 00073 class openDB 00074 { 00075 protected: 00076 string m_strErrors; 00077 dbProvider m_provider; 00078 bool m_bGood; 00079 virtual openCMD * createCommand() = 0; 00080 virtual openRS * createRecordset() = 0; 00081 00082 public: 00083 00084 openDB( string strConnection ); 00085 virtual ~openDB(); 00086 00087 // pure virtual 00088 virtual dbProvider getProvider( void ) = 0; 00089 inline bool isGood( void ){ return m_bGood; } 00090 00091 string & errorString( void ){ return m_strErrors; } 00092 00093 friend class openRsFactory; 00094 friend class openCmdFactory; 00095 }; 00096 00097 /* 00098 This base class defines the interfaces to the command 00099 */ 00100 class openCMD 00101 { 00102 00103 protected: 00104 openDB & rdb; 00105 bool m_bTransactioning; 00106 public: 00107 00108 openCMD( openDB & idb ); 00109 00110 virtual ~openCMD(); 00111 00112 // pure virtual methods that must be defined by impl 00113 virtual bool execute( string ) = 0; 00114 virtual int resultId( void ) = 0; 00115 virtual long long resultKey( const string & keyName, const string & tableName ) = 0; 00116 virtual bool beginTransaction() = 0; 00117 virtual bool commit() = 0; 00118 virtual bool rollback() = 0; 00119 00120 // methods implemented here 00121 virtual string & getErrors( void ) { return rdb.errorString(); } 00122 00123 }; 00124 00125 00126 /* 00127 This openRS base class defines the interfaces to the recordset 00128 */ 00129 class openRS 00130 { 00131 00132 protected: 00133 00134 openDB & rdb; 00135 fieldVector ordinals; 00136 fieldMap associations; 00137 int m_iRecords; 00138 int m_iFields; 00139 bool m_bOpen; 00140 bool m_bTransactioning; 00141 00142 // pure virtual 00143 virtual bool beginTransaction()=0; 00144 virtual bool commit()=0; 00145 00146 public: 00147 openRS(openDB & idb ); 00148 virtual ~ openRS(); 00149 // pure virtual 00150 virtual bool open( string sql )=0; 00151 virtual bool next( int rows = 1 )=0; 00152 virtual bool previous( int rows = 1 )=0; 00153 virtual bool close( void )=0; 00154 00155 00156 basicField & getField( int ); 00157 basicField & getField( const char * ); 00158 bool hasField( const char * ); 00159 00160 inline int getFieldCount( void ){ return m_iFields;} 00161 inline int getRecordCount( void ){ return m_iRecords; } 00162 inline int isOpen( void ){ return m_bOpen; } 00163 virtual string & getErrors( void ) { return rdb.errorString(); } 00164 00165 }; 00166 00167 #endif
1.5.5