Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages   Examples  

Cursor.h

00001 #ifndef __CURSOR_H_
00002 #define __CURSOR_H_
00003 
00004 #include "ocicpp.h"
00005 #include "OraError.h"
00006 #include "OraType.h"
00007 #include "OraString.h"
00008 #include "OraNumber.h"
00009 #include "OraDummy.h"
00010 #include "OraLob.h"
00011 #include "OraBFile.h"
00012 #include "OraDate.h"
00013 #include "OraRaw.h"
00014 #include "OraLabel.h"
00015 #include "OraRowID.h"
00016 #include "OraRefCur.h"
00017 #include "Lob.h"
00018 #include "BFile.h"
00019 #include "RowID.h"
00020 
00021 #define TEST_EXPLICIT_PREFETCH 1000
00022 
00023 
00024 // const std::string default_null_text="<NULL>";
00025 #define default_null_text "<NULL>"
00026 namespace OCICPP {
00027 
00028 using std::string;
00029 using std::map;
00030     
00031 class Cursor {
00032 private: /* OCI Defined handles */
00033     OCIEnv      *envhp;
00034     OCISvcCtx   *svchp;
00035     OCIStmt     *stmthp;
00036     OCIParam    *paramd;
00037     OCIError    *errhp;
00038     map<string,OCIBind *> binds; /* map of bindings */
00039 private: 
00040     /* All information is in row now */
00041     OraType     **row; /* Contains fetched row.Array of pointers to OraTypes derivative */
00042     sb4         nCols;
00043     ub2         stmtType; /* Statement type as described in table 4-1 OCI Reference */
00044     sword       status;
00045     string      nulltext; /* Text for null fields */
00046     
00047     unsigned    fetched; /* 0..prefetchRows */
00048     unsigned    prefetchRows; /* 1.. */
00049     unsigned    curRow;  /* 0..fetched */
00050     unsigned    fetched_all; /* rows fetched from the start */
00051         
00052     int         haveResultSet; 
00053     int         canFetch;
00054     int         Initialized;
00055     int         cursorType; /* REFCURSOR or NTABLE */
00056     map<string,int> cols_map; /* For get<Type>("colName") methods */
00057 public:
00058     Cursor();
00059     Cursor(OCIEnv *,OCISvcCtx *,OCIError *er,int prefetch,int Type=DEFAULT);
00060     void init(OCIEnv *,OCISvcCtx *,OCIError *er,int prefetch,int Type=DEFAULT);
00061     ~Cursor();
00062     void drop();
00063     void setPrefetch(unsigned nRows); 
00064 /* Once for request*/
00065     int prepare(const string &);
00066     void exec();
00067     void describe();
00068     void define();
00069     void hashHead(); 
00070     void execute(int prefetch=1); /* User's should use this func in most cases 
00071                        or they can do exec(),describe(),define()
00072                        by hand
00073                     */
00074     void bind(const string &par,char *buf,int buflen,short *isNull=0);
00075     void bind(const string &par,const string &val,short *isNull=0);
00076     void bind(const string &par,int &val,short *isNull=0);
00077     void bind(const string &par,double &val,short *isNull=0);
00078     void bind(const string &par,RowID &val,short *isNull=0);
00079     void bind(const string &par,Cursor &val,short *isNull=0);
00080     void bind(const string &par,Lob &val,short *isNull=0);
00081     
00082 /* fetch returns non zero value if theres another rows */
00083     bool fetch();
00084 /* get<Type> methods working with hardcoded cols numbers */ 
00085     void getStr(int col,string &,bool *isNull=0) const;
00086     void getInt(int col,int &val,bool *isNull=0,const int *null_value=0) const;
00087     void getDouble(int col,double &val,bool *isNull=0,const double *null_value=0) const;
00088     void getStrMon(int col,string &val) const;
00089     void getSec(int col,int &val) const;
00090     void getMin(int col,int &val) const;
00091     void getHour(int col,int &val) const;
00092     void getDay(int col,int &val) const;
00093     void getMonth(int col,int &val) const;
00094     void getYear(int col,int &val) const;
00095     void getCLOB(int col,Lob &) const;
00096     void getBLOB(int col,Lob &) const;
00097     void getFILE(int col,BFile &) const;
00098     void getRowID(int col,RowID &) const;
00099     void getCursor(int col,Cursor &) const;
00100         
00101         inline string getStr(int col,bool *isNull=0) const;
00102         inline int getInt(int col,bool *isNull=0,const int *null_value=0) const;
00103         inline double getDouble(int col,bool *isNull=0,const double *null_value=0) const;
00104         
00105 /* get<Type> same but working with attribute name */
00106     void getStr(const string &col,string &val,bool *isNull=0) const;
00107     void getInt(const string &col,int &val,bool *isNull=0,const int *null_value=0) const;
00108     void getDouble(const string &col,double &val,bool *isNull=0,const double *null_value=0) const;
00109     void getStrMon(const string &,string &) const;
00110     void getSec(const string &,int &) const;
00111     void getMin(const string &,int &) const;
00112     void getHour(const string &,int &) const;
00113     void getDay(const string &,int &) const;
00114     void getMonth(const string &,int &) const;
00115         
00116         inline int getDay(int col) const;
00117         inline int getMonth(int col) const;
00118         inline int getYear(int col) const;
00119         inline int getHour(int col) const;
00120         inline int getSec(int col) const;
00121         inline int getMin(int col) const;
00122         
00123         inline int getDay(const string &col) const;
00124         inline int getMonth(const string &col) const;
00125         inline int getYear(const string &col) const;
00126         inline int getHour(const string &col) const;
00127         inline int getSec(const string &col) const;
00128         inline int getMin(const string &col) const;
00129         
00130     
00131     
00132     void getYear(const string &,int &) const;
00133     void getCLOB(const string &col,Lob &lob) const;
00134     void getBLOB(const string &col,Lob &lob) const;
00135     void getFILE(const string &col,BFile &bfile) const;
00136     void getRowID(const string &col,RowID &rid) const;
00137     void getCursor(const string &col,Cursor &cur) const;
00138     
00139         inline string getStr(const string &col,bool *isNull=0) const;
00140         inline int getInt(const string &col,bool *isNull=0, const int *null_value=0) const;
00141         inline double getDouble(const string &col,bool *isNull=0, const double *null_value=0) const;
00142     
00143 /* Some functions to describe select-list */    
00144     int getNCols() const;
00145     void getColName(int col,string &) const; 
00146     int getColSize(int col) const;
00147     int getColSize(const string &) const;
00148     int getColType(int col) const;
00149     int getColType(const string &) const;
00150     void getColTypeName(int col,string &) const;
00151     void getColTypeName(const string &,string &) const;
00152     bool isNull(int col) const;
00153     bool isNull(const string &) const;
00154 /* Some supplementary functions */
00155     void setNullText(const string &);
00156 private:            
00157     void newCellByType(OraType **,OCIStmt *,int col);
00158 
00159 };
00160 
00161 } // namespace OCICPP
00162 #define GET_STR \
00163     std::string s;       \
00164     getStr(col, s, isNull); \
00165     return (s);
00166 inline std::string OCICPP::Cursor::getStr(int col,bool *isNull) const
00167 {
00168     GET_STR;
00169 }
00170 
00171 inline std::string OCICPP::Cursor::getStr(const std::string &col,bool *isNull) const
00172 {
00173     GET_STR;
00174 }
00175 #undef GET_STR
00176 
00177 #define GET_INT  \
00178     int n;          \
00179     getInt(col, n, isNull, null_value); \
00180     return (n);
00181 inline int OCICPP::Cursor::getInt(int col,bool *isNull, const int *null_value) const
00182 {
00183     GET_INT;
00184 }
00185 
00186 inline int OCICPP::Cursor::getInt(const std::string &col,bool *isNull, const int *null_value) const
00187 {
00188     GET_INT;
00189 }
00190 #undef GET_INT
00191 
00192 #define GET_DOUBLE  \
00193     double d;       \
00194     getDouble(col, d, isNull, null_value); \
00195     return (d);
00196 inline double OCICPP::Cursor::getDouble(int col,bool *isNull, const double *null_value) const
00197 {
00198     GET_DOUBLE;
00199 }
00200 
00201 inline double OCICPP::Cursor::getDouble(const std::string &col,bool *isNull, const double *null_value) const
00202 {
00203     GET_DOUBLE;
00204 }
00205 #undef GET_DOUBLE
00206 
00207 #define GET_DAY  \
00208     int d;       \
00209     getDay(col, d); \
00210     return (d);
00211 inline int OCICPP::Cursor::getDay(int col) const 
00212 {
00213     GET_DAY;
00214 }
00215 
00216 inline int OCICPP::Cursor::getDay(const string &col) const 
00217 {
00218     GET_DAY;
00219 }
00220 
00221 #define GET_MONTH  \
00222     int d;       \
00223     getMonth(col, d); \
00224     return (d);
00225 inline int OCICPP::Cursor::getMonth(int col) const 
00226 {
00227     GET_MONTH;
00228 }
00229 
00230 inline int OCICPP::Cursor::getMonth(const string &col) const 
00231 {
00232     GET_MONTH;
00233 }
00234 
00235 #define GET_YEAR  \
00236     int d;       \
00237     getYear(col, d); \
00238     return (d);
00239 inline int OCICPP::Cursor::getYear(int col) const 
00240 {
00241     GET_YEAR;
00242 }
00243 
00244 inline int OCICPP::Cursor::getYear(const string &col) const 
00245 {
00246     GET_YEAR;
00247 }
00248 
00249 #define GET_HOUR  \
00250     int d;       \
00251     getHour(col, d); \
00252     return (d);
00253 inline int OCICPP::Cursor::getHour(int col) const 
00254 {
00255     GET_HOUR;
00256 }
00257 
00258 inline int OCICPP::Cursor::getHour(const string &col) const 
00259 {
00260     GET_HOUR;
00261 }
00262 
00263 #define GET_SEC  \
00264     int d;       \
00265     getSec(col, d); \
00266     return (d);
00267 inline int OCICPP::Cursor::getSec(int col) const 
00268 {
00269     GET_SEC;
00270 }
00271 
00272 inline int OCICPP::Cursor::getSec(const string &col) const 
00273 {
00274     GET_SEC;
00275 }
00276 
00277 #define GET_MIN  \
00278     int d;       \
00279     getMin(col, d); \
00280     return (d);
00281 inline int OCICPP::Cursor::getMin(int col) const 
00282 {
00283     GET_MIN;
00284 }
00285 
00286 inline int OCICPP::Cursor::getMin(const string &col) const 
00287 {
00288     GET_MIN;
00289 }
00290 
00291 #endif

Generated at Tue Jun 12 10:37:29 2001 for OCI C++ Library by doxygen1.2.4-20010128 written by Dimitri van Heesch, © 1997-2001