00001 /* 00002 00003 openODBC.h 00004 ========== 00005 These classes define the ODBC implementation 00006 to the open database class interface. 00007 00008 */ 00009 #ifndef OPEN_OBDC_H 00010 #define OPEN_ODBC_H 1 00011 00012 #include <sqlext.h> 00013 #include "openDB.h" 00014 #include "openFields.h" 00015 #include "odbcTypeMaps.h" 00016 00017 /* ODBC Implementation Classes 00018 ===========================*/ 00019 class odbcDB: public openDB 00020 { 00021 protected: 00022 SQLHDBC hdbc; 00023 SQLHENV henv; 00024 SQLRETURN rc; 00025 string m_strErrors; 00026 string dsn; 00027 string uid; 00028 string pwd; 00029 bool transactioning; 00030 00031 virtual bool parseConnection( string & strConnection ); 00032 virtual openCMD * createCommand(); 00033 virtual openRS * createRecordset(); 00034 00035 public: 00036 odbcDB( string strConnection ); 00037 virtual ~odbcDB(); 00038 virtual dbProvider getProvider( void ); 00039 00040 // specific to the ODBC implementation 00041 SQLHDBC & getDbConnHandle(){ return hdbc; } 00042 SQLHENV & getEnvHandle(){ return henv; } 00043 bool error( SQLHSTMT hstmt ); 00044 string errorString( void ){ return m_strErrors; } 00045 }; 00046 00047 00048 /* 00049 This base class defines the interfaces to the command 00050 */ 00051 class odbcCMD: public openCMD 00052 { 00053 protected: 00054 odbcDB * poDB; 00055 SQLHSTMT hstmt; 00056 SQLRETURN rc; 00057 int id; 00058 00059 public: 00060 00061 odbcCMD( openDB & idb ); 00062 virtual ~odbcCMD(); 00063 00064 // methods that must be defined by impl 00065 virtual bool execute( string ); 00066 virtual int resultId( void ){ return static_cast<int>(id); }; 00067 00068 virtual bool beginTransaction(); 00069 virtual bool commit(); 00070 virtual bool rollback(); 00071 }; 00072 00073 00074 const size_t maxColLen = 512; 00075 /* 00076 This openRS base class defines the interfaces to the recordset 00077 */ 00078 class odbcRS : public openRS 00079 { 00080 00081 protected: 00082 odbcDB * poDB; 00083 SQLHSTMT hstmt; 00084 SQLRETURN rc; 00085 SWORD numCols; 00086 00087 string strCursorName; 00088 00089 // for SQLDescribe and SQLBind 00090 colInfoVector colInfo; 00091 odbcMap colMap; 00092 00093 // transaction management 00094 bool beginTransaction(); 00095 bool commit(); 00096 00097 public: 00098 odbcRS( openDB & idb ); 00099 virtual ~odbcRS(); 00100 00101 virtual bool open( string sql ); 00102 virtual bool close( void ); 00103 virtual bool next( int rows = 1 ); 00104 virtual bool previous( int rows = 1 ); 00105 00106 }; 00107 00108 #endif
1.5.5