Main Page   Class Hierarchy   File List  

openDB.h

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

Generated on Tue Jan 20 09:06:56 2004 for OpenTools by doxygen1.2.18