00001 /* 00002 00003 These classes defines a postgreSQL implementation 00004 to the open database interfaces 00005 00006 */ 00007 #ifndef OPENDBPG_H 00008 #define OPENDBPG_H 1 00009 00010 extern "C" 00011 { 00012 #include <libpq-fe.h> 00013 } 00014 #include "openDB.h" 00015 #include "pgTypeOids.h" 00016 00017 class postgresDB: public openDB 00018 { 00019 00020 protected: 00021 PGconn *conn; 00022 bool isTransactioning; 00023 virtual openCMD * createCommand(); 00024 virtual openRS * createRecordset(); 00025 00026 public: 00027 00028 postgresDB( string strConnection ); 00029 virtual ~postgresDB(); 00030 PGconn * getConnection( void ); 00031 virtual dbProvider getProvider( void ); 00032 inline bool transactioning( void ){ return isTransactioning; } 00033 inline void transactioning( bool in ){ isTransactioning=in; } 00034 00035 00036 }; 00037 00038 00039 /* 00040 This base class defines the interfaces to the command 00041 */ 00042 class postgresCMD: public openCMD 00043 { 00044 00045 protected: 00046 PGconn * conn; 00047 postgresDB &db; 00048 Oid oid; 00049 int iRows; 00050 PGresult *res; 00051 bool checkRes( ExecStatusType desired ); 00052 00053 00054 public: 00055 00056 postgresCMD( openDB & idb ); 00057 00058 virtual ~postgresCMD(); 00059 00060 // methods that must be defined by impl 00061 virtual bool execute( string ); 00062 virtual int resultId( void ){ return static_cast<int>(oid); }; 00063 virtual long long resultKey( const string & keyName, const string & tableName ); 00064 virtual bool beginTransaction(); 00065 virtual bool commit(); 00066 virtual bool rollback(); 00067 00068 }; 00069 00070 00071 /* 00072 This openRS base class defines the interfaces to the recordset 00073 */ 00074 class postgresRS: public openRS 00075 { 00076 protected: 00077 00078 PGconn *conn; 00079 postgresDB &db; 00080 static int iCursors; 00081 string strCursorName; 00082 PGresult *res; 00083 bool checkRes( ExecStatusType desired ); 00084 bool beginTransaction(); 00085 bool commit(); 00086 public: 00087 00088 postgresRS( openDB & idb ); 00089 00090 virtual ~ postgresRS(); 00091 00092 virtual bool open( string sql ); 00093 virtual bool close( void ); 00094 virtual bool next( int rows = 1 ); 00095 00096 virtual bool previous( int rows = 1 ); 00097 00098 }; 00099 00100 #endif
1.5.5