1 /****************************************************************************** 2 * $Id: ogr_idb.h 28375 2015-01-30 12:06:11Z rouault $ 3 * 4 * Project: OpenGIS Simple Features Reference Implementation 5 * Purpose: Implements OGRIDBTableLayer class, access to an existing table 6 * (based on ODBC and PG drivers). 7 * Author: Oleg Semykin, oleg.semykin@gmail.com 8 * 9 ****************************************************************************** 10 * Copyright (c) 2006, Oleg Semykin 11 * 12 * Permission is hereby granted, free of charge, to any person obtaining a 13 * copy of this software and associated documentation files (the "Software"), 14 * to deal in the Software without restriction, including without limitation 15 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 16 * and/or sell copies of the Software, and to permit persons to whom the 17 * Software is furnished to do so, subject to the following conditions: 18 * 19 * The above copyright notice and this permission notice shall be included 20 * in all copies or substantial portions of the Software. 21 * 22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28 * DEALINGS IN THE SOFTWARE. 29 ****************************************************************************/ 30 31 #ifndef _OGR_IDB_H_INCLUDED_ 32 #define _OGR_IDB_H_INCLUDED_ 33 34 #include "ogrsf_frmts.h" 35 #include "cpl_error.h" 36 #include <it.h> 37 38 /************************************************************************/ 39 /* OGRIDBLayer */ 40 /************************************************************************/ 41 42 class OGRIDBDataSource; 43 44 class OGRIDBLayer : public OGRLayer 45 { 46 protected: 47 OGRFeatureDefn *poFeatureDefn; 48 49 ITCursor *poCurr; 50 51 // Layer spatial reference system, and srid. 52 OGRSpatialReference *poSRS; 53 int nSRSId; 54 55 int iNextShapeId; 56 57 OGRIDBDataSource *poDS; 58 59 int bGeomColumnWKB; 60 char *pszGeomColumn; 61 char *pszFIDColumn; 62 63 CPLErr BuildFeatureDefn( const char *pszLayerName, 64 ITCursor *poCurr ); 65 GetQuery()66 virtual ITCursor * GetQuery() { return poCurr; } 67 68 public: 69 OGRIDBLayer(); 70 virtual ~OGRIDBLayer(); 71 72 virtual void ResetReading(); 73 virtual OGRFeature *GetNextRawFeature(); 74 virtual OGRFeature *GetNextFeature(); 75 76 virtual OGRFeature *GetFeature( GIntBig nFeatureId ); 77 GetLayerDefn()78 OGRFeatureDefn * GetLayerDefn() { return poFeatureDefn; } 79 80 virtual const char *GetFIDColumn(); 81 virtual const char *GetGeometryColumn(); 82 83 virtual OGRSpatialReference *GetSpatialRef(); 84 85 virtual int TestCapability( const char * ); 86 }; 87 88 /************************************************************************/ 89 /* OGRIDBTableLayer */ 90 /************************************************************************/ 91 92 class OGRIDBTableLayer : public OGRIDBLayer 93 { 94 int bUpdateAccess; 95 96 char *pszQuery; 97 98 int bHaveSpatialExtents; 99 100 void ClearQuery(); 101 OGRErr ResetQuery(); 102 103 virtual ITCursor * GetQuery(); 104 105 public: 106 OGRIDBTableLayer( OGRIDBDataSource * ); 107 ~OGRIDBTableLayer(); 108 109 CPLErr Initialize( const char *pszTableName, 110 const char *pszGeomCol, 111 int bUpdate 112 ); 113 114 virtual void ResetReading(); 115 virtual GIntBig GetFeatureCount( int ); 116 117 virtual OGRErr SetAttributeFilter( const char * ); 118 virtual OGRErr ISetFeature( OGRFeature *poFeature ); 119 virtual OGRErr ICreateFeature( OGRFeature *poFeature ); 120 121 #if 0 122 virtual OGRErr CreateField( OGRFieldDefn *poField, 123 int bApproxOK = TRUE ); 124 #endif 125 virtual OGRFeature *GetFeature( GIntBig nFeatureId ); 126 127 virtual OGRSpatialReference *GetSpatialRef(); 128 129 virtual int TestCapability( const char * ); 130 }; 131 132 /************************************************************************/ 133 /* OGRIDBSelectLayer */ 134 /************************************************************************/ 135 136 class OGRIDBSelectLayer : public OGRIDBLayer 137 { 138 char *pszBaseQuery; 139 140 void ClearQuery(); 141 OGRErr ResetQuery(); 142 143 virtual ITCursor * GetQuery(); 144 145 public: 146 OGRIDBSelectLayer( OGRIDBDataSource *, 147 ITCursor * ); 148 ~OGRIDBSelectLayer(); 149 150 virtual void ResetReading(); 151 virtual GIntBig GetFeatureCount( int ); 152 153 virtual OGRFeature *GetFeature( GIntBig nFeatureId ); 154 155 virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE); 156 157 virtual int TestCapability( const char * ); 158 }; 159 160 /************************************************************************/ 161 /* OGRIDBDataSource */ 162 /************************************************************************/ 163 164 class OGRIDBDataSource : public OGRDataSource 165 { 166 OGRIDBLayer **papoLayers; 167 int nLayers; 168 169 char *pszName; 170 171 int bDSUpdate; 172 ITConnection *poConn; 173 174 public: 175 OGRIDBDataSource(); 176 ~OGRIDBDataSource(); 177 178 int Open( const char *, int bUpdate, int bTestOpen ); 179 int OpenTable( const char *pszTableName, 180 const char *pszGeomCol, 181 int bUpdate ); 182 GetName()183 const char *GetName() { return pszName; } GetLayerCount()184 int GetLayerCount() { return nLayers; } 185 OGRLayer *GetLayer( int ); 186 187 int TestCapability( const char * ); 188 189 virtual OGRLayer * ExecuteSQL( const char *pszSQLCommand, 190 OGRGeometry *poSpatialFilter, 191 const char *pszDialect ); 192 virtual void ReleaseResultSet( OGRLayer * poLayer ); 193 194 // Internal use GetConnection()195 ITConnection * GetConnection() { return poConn; } 196 }; 197 198 /************************************************************************/ 199 /* OGRIDBDriver */ 200 /************************************************************************/ 201 202 class OGRIDBDriver : public OGRSFDriver 203 { 204 public: 205 ~OGRIDBDriver(); 206 const char * GetName(); 207 OGRDataSource * Open( const char *, int ); 208 209 OGRDataSource * CreateDataSource( const char *pszName, 210 char ** = NULL ); 211 212 int TestCapability( const char * ); 213 }; 214 215 ITCallbackResult 216 IDBErrorHandler( const ITErrorManager &err, void * userdata, long errorlevel ); 217 218 #endif /* ndef _OGR_idb_H_INCLUDED_ */ 219 220 221