Line data Source code
1 : /******************************************************************************
2 : * $Id$
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: Private definitions for Personal Geodatabase driver.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2005, Frank Warmerdam <warmerdam@pobox.com>
10 : * Copyright (c) 2009-2013, Even Rouault <even dot rouault at spatialys.com>
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_ODBC_H_INCLUDED
32 : #define OGR_ODBC_H_INCLUDED
33 :
34 : #include "ogrsf_frmts.h"
35 : #include "cpl_odbc.h"
36 : #include "cpl_error.h"
37 :
38 : #include <unordered_set>
39 :
40 : /************************************************************************/
41 : /* OGRPGeoLayer */
42 : /************************************************************************/
43 :
44 : class OGRPGeoDataSource;
45 :
46 : constexpr const char *pszRelationshipTypeUUID =
47 : "{B606A7E1-FA5B-439C-849C6E9C2481537B}";
48 :
49 : class OGRPGeoLayer CPL_NON_FINAL : public OGRLayer
50 : {
51 : protected:
52 : OGRFeatureDefn *poFeatureDefn;
53 :
54 : int m_nStatementFlags = 0;
55 :
56 : CPLODBCStatement *poStmt;
57 :
58 : // Layer spatial reference system, and srid.
59 : OGRSpatialReference *poSRS;
60 : int nSRSId;
61 :
62 : GIntBig iNextShapeId;
63 :
64 : OGRPGeoDataSource *poDS;
65 :
66 : char *pszGeomColumn;
67 : char *pszFIDColumn;
68 :
69 : int *panFieldOrdinals;
70 :
71 : bool m_bEOF = false;
72 :
73 : CPLErr BuildFeatureDefn(const char *pszLayerName, CPLODBCStatement *poStmt);
74 :
75 0 : virtual CPLODBCStatement *GetStatement()
76 : {
77 0 : return poStmt;
78 : }
79 :
80 : void LookupSRID(int);
81 :
82 : public:
83 : OGRPGeoLayer();
84 : virtual ~OGRPGeoLayer();
85 :
86 : virtual void ResetReading() override;
87 : virtual OGRFeature *GetNextRawFeature();
88 : virtual OGRFeature *GetNextFeature() override;
89 :
90 : virtual OGRFeature *GetFeature(GIntBig nFeatureId) override;
91 :
92 0 : OGRFeatureDefn *GetLayerDefn() override
93 : {
94 0 : return poFeatureDefn;
95 : }
96 :
97 : virtual int TestCapability(const char *) override;
98 :
99 : virtual const char *GetFIDColumn() override;
100 : virtual const char *GetGeometryColumn() override;
101 : };
102 :
103 : /************************************************************************/
104 : /* OGRPGeoTableLayer */
105 : /************************************************************************/
106 :
107 : class OGRPGeoTableLayer final : public OGRPGeoLayer
108 : {
109 : char *pszQuery;
110 :
111 : void ClearStatement();
112 : OGRErr ResetStatement();
113 :
114 : virtual CPLODBCStatement *GetStatement() override;
115 :
116 : OGREnvelope sExtent;
117 : std::string m_osDefinition;
118 : std::string m_osDocumentation;
119 :
120 : public:
121 : explicit OGRPGeoTableLayer(OGRPGeoDataSource *, int);
122 : virtual ~OGRPGeoTableLayer();
123 :
124 : CPLErr Initialize(const char *pszTableName, const char *pszGeomCol,
125 : int nShapeType, double dfExtentLeft, double dfExtentRight,
126 : double dfExtentBottom, double dfExtentTop, int nSRID,
127 : int bHasZ, int nHasM);
128 :
129 : virtual void ResetReading() override;
130 : virtual GIntBig GetFeatureCount(int) override;
131 :
132 : virtual OGRErr SetAttributeFilter(const char *) override;
133 : virtual OGRFeature *GetFeature(GIntBig nFeatureId) override;
134 :
135 : virtual int TestCapability(const char *) override;
136 :
137 : virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE) override;
138 :
139 0 : virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent,
140 : int bForce) override
141 : {
142 0 : return OGRLayer::GetExtent(iGeomField, psExtent, bForce);
143 : }
144 :
145 0 : const std::string &GetXMLDefinition()
146 : {
147 0 : return m_osDefinition;
148 : }
149 :
150 0 : const std::string &GetXMLDocumentation()
151 : {
152 0 : return m_osDocumentation;
153 : }
154 : };
155 :
156 : /************************************************************************/
157 : /* OGRPGeoSelectLayer */
158 : /************************************************************************/
159 :
160 : class OGRPGeoSelectLayer final : public OGRPGeoLayer
161 : {
162 : char *pszBaseStatement;
163 :
164 : void ClearStatement();
165 : OGRErr ResetStatement();
166 :
167 : virtual CPLODBCStatement *GetStatement() override;
168 :
169 : public:
170 : OGRPGeoSelectLayer(OGRPGeoDataSource *, CPLODBCStatement *);
171 : virtual ~OGRPGeoSelectLayer();
172 :
173 : virtual void ResetReading() override;
174 : virtual GIntBig GetFeatureCount(int) override;
175 :
176 : virtual OGRFeature *GetFeature(GIntBig nFeatureId) override;
177 :
178 : virtual int TestCapability(const char *) override;
179 : };
180 :
181 : /************************************************************************/
182 : /* OGRPGeoDataSource */
183 : /************************************************************************/
184 :
185 : class OGRPGeoDataSource final : public OGRDataSource
186 : {
187 : OGRPGeoLayer **papoLayers;
188 : int nLayers;
189 :
190 : char *pszName;
191 :
192 : mutable CPLODBCSession oSession;
193 :
194 : std::unordered_set<std::string> m_aosAllLCTableNames;
195 : bool m_bHasGdbItemsTable = false;
196 :
197 : std::vector<std::unique_ptr<OGRLayer>> m_apoInvisibleLayers;
198 :
199 : std::map<std::string, std::unique_ptr<GDALRelationship>>
200 : m_osMapRelationships{};
201 :
202 : #ifndef _WIN32
203 : mutable bool m_COUNT_STAR_state_known = false;
204 : mutable bool m_COUNT_STAR_working = false;
205 : #endif
206 :
207 : int m_nStatementFlags = 0;
208 :
209 : static bool IsPrivateLayerName(const CPLString &osName);
210 :
211 : public:
212 : OGRPGeoDataSource();
213 : virtual ~OGRPGeoDataSource();
214 :
215 : int Open(GDALOpenInfo *poOpenInfo);
216 : int OpenTable(const char *pszTableName, const char *pszGeomCol,
217 : int bUpdate);
218 :
219 0 : const char *GetName() override
220 : {
221 0 : return pszName;
222 : }
223 :
224 0 : int GetLayerCount() override
225 : {
226 0 : return nLayers;
227 : }
228 :
229 : OGRLayer *GetLayer(int) override;
230 : OGRLayer *GetLayerByName(const char *) override;
231 : bool IsLayerPrivate(int) const override;
232 :
233 : int TestCapability(const char *) override;
234 :
235 : virtual OGRLayer *ExecuteSQL(const char *pszSQLCommand,
236 : OGRGeometry *poSpatialFilter,
237 : const char *pszDialect) override;
238 : virtual void ReleaseResultSet(OGRLayer *poLayer) override;
239 :
240 : std::vector<std::string>
241 : GetRelationshipNames(CSLConstList papszOptions = nullptr) const override;
242 :
243 : const GDALRelationship *
244 : GetRelationship(const std::string &name) const override;
245 :
246 : // Internal use
247 0 : CPLODBCSession *GetSession()
248 : {
249 0 : return &oSession;
250 : }
251 :
252 : bool CountStarWorking() const;
253 :
254 0 : bool HasGdbItemsTable() const
255 : {
256 0 : return m_bHasGdbItemsTable;
257 : }
258 : };
259 :
260 : #endif /* ndef _OGR_PGeo_H_INCLUDED */
|