| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/drivers/Oracle/TeOCICursor.h
Go to the documentation of this file.

    00001 /************************************************************************************
    00002 TerraLib - a library for developing GIS applications.
    00003 Copyright © 2001-2007 INPE and Tecgraf/PUC-Rio.
    00004
    00005 This code is part of the TerraLib library.
    00006 This library is free software; you can redistribute it and/or
    00007 modify it under the terms of the GNU Lesser General Public
    00008 License as published by the Free Software Foundation; either
    00009 version 2.1 of the License, or (at your option) any later version.
    00010
    00011 You should have received a copy of the GNU Lesser General Public
    00012 License along with this library.
    00013
    00014 The authors reassure the license terms regarding the warranties.
    00015 They specifically disclaim any warranties, including, but not limited to,
    00016 the implied warranties of merchantability and fitness for a particular purpose.
    00017 The library provided hereunder is on an "as is" basis, and the authors have no
    00018 obligation to provide maintenance, support, updates, enhancements, or modifications.
    00019 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
    00020 indirect, special, incidental, or consequential damages arising out of the use
    00021 of this library and its documentation.
    00022 *************************************************************************************/
    00027 #ifndef OCICursor_H
    00028 #define OCICursor_H
    00029
    00030 #include <TeOCIConnect.h>
    00031 #include <vector>
    00032 #include <TeCoord2D.h>
    00033
    00034 #include "TeOracleDefines.h"
    00035
    00036 using namespace std;
    00037
    00038 #define TYPE_OWNER                                     "MDSYS"
    00039 #define SDO_ORDINATE_ARRAY      TYPE_OWNER".SDO_ORDINATE_ARRAY"
    00040 #define SDO_ELEM_INFO_ARRAY     TYPE_OWNER".SDO_ELEM_INFO_ARRAY"
    00041 #define SDO_GEOMETRY                        TYPE_OWNER".SDO_GEOMETRY"
    00042
    00044 #define MAX_ROWS                                       500
    00045
    00047 #define MAX_BLOB_LENGTH                                5000000 //5 MegaBytes (the max blob length is 4 Gigabytes)
    00048
    00050 struct TLORACLE_DLL sdo_point_type
    00051 {
    00052    OCINumber x;
    00053    OCINumber y;
    00054    OCINumber z;
    00055 };
    00056
    00057 typedef struct sdo_point_type sdo_point_type;
    00058
    00060 struct TLORACLE_DLL sdo_geometry
    00061 {
    00062    OCINumber       sdo_gtype;
    00063    OCINumber       sdo_srid;
    00064    sdo_point_type  sdo_point;
    00065    OCIArray        *sdo_elem_info;
    00066    OCIArray        *sdo_ordinates;
    00067 };
    00068
    00069 typedef struct sdo_geometry SDO_GEOMETRY_TYPE;
    00070
    00072 struct TLORACLE_DLL sdo_point_type_ind
    00073 {
    00074    OCIInd _atomic;
    00075    OCIInd x;
    00076    OCIInd y;
    00077    OCIInd z;
    00078 };
    00079
    00080 typedef struct sdo_point_type_ind sdo_point_type_ind;
    00081
    00083 struct TLORACLE_DLL SDO_GEOMETRY_ind
    00084 {
    00085    OCIInd                    _atomic;
    00086    OCIInd                    sdo_gtype;
    00087    OCIInd                    sdo_srid;
    00088    struct sdo_point_type_ind sdo_point;
    00089    OCIInd                    sdo_elem_info;
    00090    OCIInd                    sdo_ordinates;
    00091 };
    00092
    00093 typedef struct SDO_GEOMETRY_ind SDO_GEOMETRY_ind;
    00094
    00096 struct TLORACLE_DLL sb2ind
    00097 {
    00098            sb2                   sbind[MAX_ROWS];
    00099 };
    00100 typedef struct sb2ind indarray;
    00101
    00114 class TLORACLE_DLL TeOCICursor
    00115 {
    00116 protected:
    00117            TeOCIConnection*      connection_;
    00118            OCIStmt*                         stmthpToQuery_;
    00119            OCIDescribe*                     dschp_;
    00120            bool                                        isOpen_;
    00121            string                                      errorMessage_;
    00122
    00126            vector<void *>                              buffers_;
    00127            vector <indarray>                ind_;
    00128
    00129            SDO_GEOMETRY_TYPE*               global_geom_obj_[MAX_ROWS];
    00130            SDO_GEOMETRY_ind*                global_geom_ind_[MAX_ROWS];
    00131
    00132            vector<unsigned char*>           lobBuffer_;
    00133            bool                                                   hasBlob_;
    00134            unsigned long                               maxBuflen_;
    00135     int                                                           maxRows_;
    00136
    00137            vector<OCIDefine *>              defines_;
    00138            OCIArray*                                   ordinates_;
    00139
    00140
    00141            string                                                 fieldValue_;
    00142
    00146            short                                       row_Index_;
    00147            int                                                    row_Cur_;
    00148            int                                                    rows_Fetched_;
    00149            int                                                    rows_Mem_;
    00150            bool                                        last_Row_;
    00151
    00152
    00156            int                                                    numColls_;
    00157            vector<string>                   colName_;
    00158            vector<int>                                 colType_;
    00159            vector<int>                                 colSize_;
    00160            vector<int>                                 colScale_;
    00161            vector<string>                   colBlobName_;
    00162
    00163
    00164 public:
    00165
    00167            TeOCICursor(TeOCIConnection* conn, const unsigned long& maxBlobSize=0, const unsigned long& maxRowNum=0 );
    00168
    00170            ~TeOCICursor() { close(); }
    00171
    00173            bool open();
    00174
    00176            string     getErrorMessage() { return errorMessage_;}
    00177
    00179            bool isOpen()         { return isOpen_; }
    00180
    00182            TeOCIConnection*      conn()                { return connection_; }
    00183
    00185            int        currentRow() { return row_Cur_; }
    00186
    00188            void close();
    00189
    00191            void defineByPos(int pos, void* value, int size, void* indicator, int type);
    00192
    00194            bool                  execute();
    00195
    00197            bool                  fetch(int rows);
    00198
    00200            bool                  query(const string& query);
    00201
    00203            bool                  querySDO(const string& query);
    00204
    00206            bool                  moveFirst();
    00207
    00209            bool                  moveNext();
    00210
    00212            bool                  moveTo(int pos);
    00213
    00215            bool                  moveLast();
    00216
    00220
    00221            int                              colType (int colnumber);
    00223            string                colName (int colnumber);
    00225            int                              colSize (int colnumber);
    00227            int                              colScale (int colnumber);
    00229            int                              numCol(void);
    00231            void                  loadCollDescription ();
    00233            int                              numRows(void);
    00235
    00237            bool                  appendOrdinates(const double& val);
    00238
    00240            bool                  bindOrdinates();
    00241
    00243            bool                  prepare(const string& stmt);
    00244
    00246            int                              queryType();
    00247
    00249            bool                  allocateCursor(void);
    00250
    00252            char*                 getFieldValue(int i);
    00253
    00257
    00258            int                              getDimArraySize();
    00260            bool                  getDimElement(int i,int &elem);
    00262            int                              getNumberOrdinates(void);
    00264            bool                  getCoordinates(int i,TeCoord2D& coord);
    00266            bool                  getCoordinates(vector<TeCoord2D>& result);
    00268            int                              getGeometryType();
    00270            int                              getSpatialReferenceId();
    00272            bool                  getXYZcoord (double& x, double& y);
    00274
    00276            void                  freeResult(void);
    00277
    00281
    00282            bool                  readBlob(unsigned char* buffer, unsigned int& bufsize, unsigned int& blobCol);
    00284            bool                  readBlob(unsigned char* buffer, unsigned int& bufsize, const string& blobCol);
    00286            bool                  readBlob(double *buffer, unsigned int& bufsize);
    00288            bool                  readBlob(double **buffer);
    00290            unsigned int          getBlobSize(const string& blobCol);
    00292
    00293 protected:
    00295            bool                  checkError(sword status);
    00296 };
    00297
    00298 #endif
    00299
    00300

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines