Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

dsOCI.h

Go to the documentation of this file.
00001 /* Oracle Call Interface shell library 
00002  *
00003  * $Id: dsOCI.h,v 1.9 2004/06/10 10:58:17 dsamersoff Exp $
00004  */
00005 
00006 #ifndef dsOCI_h
00007 #define dsOCI_h
00008 
00009 #ifdef HAVE_CONFIG_H
00010 # include <config.h>
00011 #endif
00012 
00013 #include <limits.h>
00014 #include <stdlib.h>
00015 
00016 #ifdef HAVE_UNISTD_H
00017 # include <unistd.h>
00018 #endif
00019 
00020 #ifdef Win32
00021 #include <wtypes.h>
00022 #endif
00023 
00024 #include <iostream>
00025 
00026 #include <oci.h>
00027 
00028 #include <dsSmartException.h>
00029 #include <dsSQLAccessor.h>
00030 
00031 DECLARE_EXCEPTION2(dsOCI, dsSQL);
00032 
00033 //#define PGOCI_VERBOSE
00034 
00035 #define MAX_COLUMN_NAME        256 
00036 #define COMMIT_ON_SUCCESS      1
00037 
00038 struct dsOCIParmDesc
00039 { 
00040     int type;                    // oratype of column
00041     int len;                     // column data size
00042     int pos;                     // column position 
00043     char name[MAX_COLUMN_NAME];  // column name
00044 };
00045 
00046 
00050 class dsOCI : public dsSQLAccessor
00051 {
00052 
00053     OCIEnv     *_envhp;  /* the environment handle */
00054     OCIServer  *_srvhp;  /* the server handle */
00055     OCIError   *_errhp;  /* the error handle */
00056     OCISession *_authp;  /* user session handle */
00057     OCISvcCtx  *_svchp;  /* the server context handle */
00058 
00059 public :
00060 
00061         dsOCI(const char *ORASID, const char *username = 0, const char *passwd = 0);
00062         virtual ~dsOCI();
00063 
00064        virtual void Connect(const char * ORASID, const char *username,const char *password, const int flags = OCI_DEFAULT);
00065        virtual void Cleanup();
00066        virtual void Execute(void *stmtp, int PrefetchRows = 0, int CommitOnSuccess = false );
00067 
00068        virtual OCIStmt *PrepareCall(const char *theQuery);
00069        virtual void ReleaseCall(OCIStmt *stmtp);
00070 
00071        int Fetch(OCIStmt   *stmtp, int nrows = 1);
00072 
00073        void Commit();
00074        void Rollback();
00075 
00076 
00077        /* Bind ref cursor SQLT_REF, return cursor statement handler for define and fetch */
00078        OCIBind   *BindCursor(OCIStmt *stmthp, char *ParamName, OCIStmt **cursor_stmthp);
00079 
00080        OCIBind   *BindParam(OCIStmt *stmthp, char *ParamName, ub2 ValueType, dvoid *valuep, ub4 ValueSize);
00081        OCIBind   *BindParam(OCIStmt *stmthp, char *ParamName, ub2 ValueType, dvoid *valuep, ub4 ValueSize, short *isNull);
00082 
00083        OCIDefine *DefineByPos(OCIStmt *stmthp, int pos, ub2 ValueType, dvoid *valuep, sb4 value_sz);
00084        OCIDefine *DefineByPos(OCIStmt *stmthp, int pos, ub2 ValueType, dvoid *valuep, sb4 value_sz, short *isNull);
00085 
00086        void Describe(OCIStmt *stmthp);
00087        
00088 
00089 protected:
00090       
00091       void HandleAlloc(int hdlType, dvoid ** hdlPtr);
00092       void HandleFree(int hdlType,  dvoid *hdlPtr);
00093 
00094       void AttrSet(ub4 attrType, dvoid *hdl, ub4 hdlType, dvoid * attrPtr, ub4 attrSize);
00095       void AttrSet(ub4 attrType, dvoid *hdl, ub4 hdlType, const char *attrPtr );
00096 
00097 
00098       void AttrGet(ub4 attrType, dvoid *hdl, ub4 hdlType, dvoid *attrPtr, ub4 *attrSize);
00099       int  AttrGet(ub4 attrType, dvoid *hdl, ub4 hdlType);
00100 
00101       sword check_error(int line, sword status);
00102 
00103 public:
00104 
00105 /* simplified input parameters bind */
00106     OCIBind   *BindParam(OCIStmt *stmthp, char *ParamName, int value)
00107     { int valuep = value;
00108       return BindParam(stmthp, ParamName, SQLT_INT, (dvoid *) &valuep, sizeof (valuep) );
00109     }
00110 
00111     OCIBind   *BindParam(OCIStmt *stmthp, char *ParamName, char *value, int size)
00112     { return BindParam(stmthp, ParamName, SQLT_STR, (dvoid *) value, size);
00113     }
00114 
00115 #ifndef Win32   
00116     template <class TValue> 
00117     OCIBind   *BindParam(OCIStmt *stmthp, char *ParamName, ub2 ValueType, TValue valuep, ub4 ValueSize)
00118     { return BindParam(stmthp, ParamName, ValueType, (dvoid *) valuep, ValueSize);
00119     }
00120 
00121 
00122     template <class TValue> 
00123     OCIDefine *DefineByPos(OCIStmt *stmthp, int pos, ub2 ValueType, TValue valuep, sb4 value_sz)
00124     {  return DefineByPos(stmthp, pos, ValueType, (dvoid *)valuep, value_sz);
00125     }
00126 
00127     template <class THdlVoid>  
00128     void HandleAlloc(int hdlType, THdlVoid hdlPtr)
00129     { HandleAlloc(hdlType, (dvoid **) hdlPtr);
00130     }
00131 
00132     template <class THdlVoid>
00133     void HandleFree(int hdlType,  THdlVoid hdlPtr)
00134     { HandleFree( hdlType, (dvoid *) hdlPtr);
00135     }
00136 
00137 
00138     template <class THdlVoid, class TAttrVoid> 
00139     void AttrSet(ub4 attrType, THdlVoid hdl, ub4 hdlType, TAttrVoid attrPtr, ub4 attrSize)
00140     { AttrSet(attrType, (dvoid *)hdl, hdlType, (dvoid *)attrPtr, attrSize);
00141     }
00142 
00143     template <class THdlVoid>
00144     void AttrSet(ub4 attrType, THdlVoid hdl, ub4 hdlType, const char *attrPtr )
00145     { AttrSet(attrType, (dvoid *) hdl, hdlType, attrPtr);
00146     }
00147 
00148     template <class THdlVoid, class TAttrVoid> 
00149     void AttrGet(ub4 attrType, THdlVoid hdl, ub4 hdlType, TAttrVoid attrPtr, ub4 *attrSize)
00150     { AttrGet(attrType, (dvoid *) hdl, hdlType, (dvoid *) attrPtr, attrSize);
00151     }
00152 
00153     template <class THdlVoid>                   
00154     int  AttrGet(ub4 attrType, THdlVoid hdl, ub4 hdlType)
00155     { return AttrGet(attrType, (dvoid *) hdl, hdlType);
00156     }
00157 
00158 #endif
00159 
00160 
00161 };
00162 
00163 #endif

Generated on Mon May 16 18:26:58 2005 for libdms4 by doxygen1.3-rc2