| 1 |
/****************************************************************************** |
| 2 |
* |
| 3 |
* Project: OpenGIS Simple Features Reference Implementation |
| 4 |
* Purpose: Implements OGRIDBTableLayer class, access to an existing table |
| 5 |
* (based on ODBC and PG drivers). |
| 6 |
* Author: Oleg Semykin, [email protected] |
| 7 |
* |
| 8 |
****************************************************************************** |
| 9 |
* Copyright (c) 2006, Oleg Semykin |
| 10 |
* |
| 11 |
* SPDX-License-Identifier: MIT |
| 12 |
****************************************************************************/ |
| 13 |
|
| 14 |
#ifndef OGR_IDB_H_INCLUDED_ |
| 15 |
#define OGR_IDB_H_INCLUDED_ |
| 16 |
|
| 17 |
#include "ogrsf_frmts.h" |
| 18 |
#include "cpl_error.h" |
| 19 |
#include "idb_headers.h" |
| 20 |
|
| 21 |
/************************************************************************/ |
| 22 |
/* OGRIDBLayer */ |
| 23 |
/************************************************************************/ |
| 24 |
|
| 25 |
class OGRIDBDataSource; |
| 26 |
|
| 27 |
class OGRIDBLayer CPL_NON_FINAL : public OGRLayer |
| 28 |
{ |
| 29 |
protected: |
| 30 |
OGRFeatureDefn *poFeatureDefn; |
| 31 |
|
| 32 |
ITCursor *m_poCurr; |
| 33 |
|
| 34 |
// Layer spatial reference system, and srid. |
| 35 |
mutable OGRSpatialReference *poSRS; |
| 36 |
mutable int nSRSId; |
| 37 |
|
| 38 |
int iNextShapeId; |
| 39 |
|
| 40 |
OGRIDBDataSource *poDS; |
| 41 |
|
| 42 |
int bGeomColumnWKB; |
| 43 |
char *pszGeomColumn; |
| 44 |
char *pszFIDColumn; |
| 45 |
|
| 46 |
CPLErr BuildFeatureDefn(const char *pszLayerName, ITCursor *poCurr); |
| 47 |
|
| 48 |
virtual ITCursor *GetQuery() |
| 49 |
{ |
| 50 |
return m_poCurr; |
| 51 |
} |
| 52 |
|
| 53 |
public: |
| 54 |
OGRIDBLayer(); |
| 55 |
~OGRIDBLayer() override; |
| 56 |
|
| 57 |
void ResetReading() override; |
| 58 |
virtual OGRFeature *GetNextRawFeature(); |
| 59 |
OGRFeature *GetNextFeature() override; |
| 60 |
|
| 61 |
OGRFeature *GetFeature(GIntBig nFeatureId) override; |
| 62 |
|
| 63 |
const OGRFeatureDefn *GetLayerDefn() const override |
| 64 |
{ |
| 65 |
return poFeatureDefn; |
| 66 |
} |
| 67 |
|
| 68 |
const char *GetFIDColumn() const override; |
| 69 |
const char *GetGeometryColumn() const override; |
| 70 |
|
| 71 |
const OGRSpatialReference *GetSpatialRef() const override; |
| 72 |
|
| 73 |
int TestCapability(const char *) const override; |
| 74 |
}; |
| 75 |
|
| 76 |
/************************************************************************/ |
| 77 |
/* OGRIDBTableLayer */ |
| 78 |
/************************************************************************/ |
| 79 |
|
| 80 |
class OGRIDBTableLayer final : public OGRIDBLayer |
| 81 |
{ |
| 82 |
int bUpdateAccess; |
| 83 |
|
| 84 |
char *pszQuery; |
| 85 |
|
| 86 |
int bHaveSpatialExtents; |
| 87 |
|
| 88 |
void ClearQuery(); |
| 89 |
OGRErr ResetQuery(); |
| 90 |
|
| 91 |
ITCursor *GetQuery() override; |
| 92 |
|
| 93 |
public: |
| 94 |
explicit OGRIDBTableLayer(OGRIDBDataSource *); |
| 95 |
~OGRIDBTableLayer() override; |
| 96 |
|
| 97 |
CPLErr Initialize(const char *pszTableName, const char *pszGeomCol, |
| 98 |
int bUpdate); |
| 99 |
|
| 100 |
void ResetReading() override; |
| 101 |
GIntBig GetFeatureCount(int) override; |
| 102 |
|
| 103 |
OGRErr SetAttributeFilter(const char *) override; |
| 104 |
OGRErr ISetFeature(OGRFeature *poFeature) override; |
| 105 |
OGRErr ICreateFeature(OGRFeature *poFeature) override; |
| 106 |
|
| 107 |
#if 0 |
| 108 |
virtual OGRErr CreateField( OGRFieldDefn *poField, |
| 109 |
int bApproxOK = TRUE ); |
| 110 |
#endif |
| 111 |
OGRFeature *GetFeature(GIntBig nFeatureId) override; |
| 112 |
|
| 113 |
const OGRSpatialReference *GetSpatialRef() const override; |
| 114 |
|
| 115 |
int TestCapability(const char *) const override; |
| 116 |
}; |
| 117 |
|
| 118 |
/************************************************************************/ |
| 119 |
/* OGRIDBSelectLayer */ |
| 120 |
/************************************************************************/ |
| 121 |
|
| 122 |
class OGRIDBSelectLayer final : public OGRIDBLayer |
| 123 |
{ |
| 124 |
char *pszBaseQuery; |
| 125 |
|
| 126 |
void ClearQuery(); |
| 127 |
OGRErr ResetQuery(); |
| 128 |
|
| 129 |
ITCursor *GetQuery() override; |
| 130 |
|
| 131 |
public: |
| 132 |
OGRIDBSelectLayer(OGRIDBDataSource *, ITCursor *); |
| 133 |
~OGRIDBSelectLayer() override; |
| 134 |
|
| 135 |
void ResetReading() override; |
| 136 |
GIntBig GetFeatureCount(int) override; |
| 137 |
|
| 138 |
OGRFeature *GetFeature(GIntBig nFeatureId) override; |
| 139 |
|
| 140 |
OGRErr IGetExtent(int iGeomField, OGREnvelope *psExtent, |
| 141 |
bool bForce) override; |
| 142 |
|
| 143 |
int TestCapability(const char *) const override; |
| 144 |
}; |
| 145 |
|
| 146 |
/************************************************************************/ |
| 147 |
/* OGRIDBDataSource */ |
| 148 |
/************************************************************************/ |
| 149 |
|
| 150 |
class OGRIDBDataSource final : public GDALDataset |
| 151 |
{ |
| 152 |
OGRIDBLayer **papoLayers; |
| 153 |
int nLayers; |
| 154 |
|
| 155 |
int bDSUpdate; |
| 156 |
ITConnection *poConn; |
| 157 |
|
| 158 |
public: |
| 159 |
OGRIDBDataSource(); |
| 160 |
~OGRIDBDataSource() override; |
| 161 |
|
| 162 |
int Open(const char *, int bUpdate, int bTestOpen); |
| 163 |
int OpenTable(const char *pszTableName, const char *pszGeomCol, |
| 164 |
int bUpdate); |
| 165 |
|
| 166 |
int GetLayerCount() const override |
| 167 |
{ |
| 168 |
return nLayers; |
| 169 |
} |
| 170 |
|
| 171 |
const OGRLayer *GetLayer(int) const override; |
| 172 |
|
| 173 |
int TestCapability(const char *) const override; |
| 174 |
|
| 175 |
OGRLayer *ExecuteSQL(const char *pszSQLCommand, |
| 176 |
OGRGeometry *poSpatialFilter, |
| 177 |
const char *pszDialect) override; |
| 178 |
void ReleaseResultSet(OGRLayer *poLayer) override; |
| 179 |
|
| 180 |
// Internal use |
| 181 |
ITConnection *GetConnection() |
| 182 |
{ |
| 183 |
return poConn; |
| 184 |
} |
| 185 |
}; |
| 186 |
|
| 187 |
ITCallbackResult IDBErrorHandler(const ITErrorManager &err, void *userdata, |
| 188 |
long errorlevel); |
| 189 |
|
| 190 |
#endif /* ndef _OGR_idb_H_INCLUDED_ */ |