1 : /******************************************************************************
2 : * $Id: ogr_pgeo.h 21550 2011-01-22 18:01:57Z rouault $
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 : *
11 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 : #ifndef _OGR_ODBC_H_INCLUDED
31 : #define _OGR_ODBC_H_INCLUDED
32 :
33 : #include "ogrsf_frmts.h"
34 : #include "cpl_odbc.h"
35 : #include "cpl_error.h"
36 :
37 : /************************************************************************/
38 : /* OGRPGeoLayer */
39 : /************************************************************************/
40 :
41 : class OGRPGeoDataSource;
42 :
43 : class OGRPGeoLayer : public OGRLayer
44 : {
45 : protected:
46 : OGRFeatureDefn *poFeatureDefn;
47 :
48 : CPLODBCStatement *poStmt;
49 :
50 : // Layer spatial reference system, and srid.
51 : OGRSpatialReference *poSRS;
52 : int nSRSId;
53 :
54 : int iNextShapeId;
55 :
56 : OGRPGeoDataSource *poDS;
57 :
58 : char *pszGeomColumn;
59 : char *pszFIDColumn;
60 :
61 : int *panFieldOrdinals;
62 :
63 : CPLErr BuildFeatureDefn( const char *pszLayerName,
64 : CPLODBCStatement *poStmt );
65 :
66 0 : virtual CPLODBCStatement * GetStatement() { return poStmt; }
67 :
68 : void LookupSRID( int );
69 :
70 : public:
71 : OGRPGeoLayer();
72 : virtual ~OGRPGeoLayer();
73 :
74 : virtual void ResetReading();
75 : virtual OGRFeature *GetNextRawFeature();
76 : virtual OGRFeature *GetNextFeature();
77 :
78 : virtual OGRFeature *GetFeature( long nFeatureId );
79 :
80 0 : OGRFeatureDefn * GetLayerDefn() { return poFeatureDefn; }
81 :
82 : virtual OGRSpatialReference *GetSpatialRef();
83 :
84 : virtual int TestCapability( const char * );
85 :
86 : virtual const char *GetFIDColumn();
87 : virtual const char *GetGeometryColumn();
88 : };
89 :
90 : /************************************************************************/
91 : /* OGRPGeoTableLayer */
92 : /************************************************************************/
93 :
94 : class OGRPGeoTableLayer : public OGRPGeoLayer
95 : {
96 : int bUpdateAccess;
97 :
98 : char *pszQuery;
99 :
100 : void ClearStatement();
101 : OGRErr ResetStatement();
102 :
103 : virtual CPLODBCStatement * GetStatement();
104 :
105 : OGREnvelope sExtent;
106 :
107 : public:
108 : OGRPGeoTableLayer( OGRPGeoDataSource * );
109 : ~OGRPGeoTableLayer();
110 :
111 : CPLErr Initialize( const char *pszTableName,
112 : const char *pszGeomCol,
113 : int nShapeType,
114 : double dfExtentLeft,
115 : double dfExtentRight,
116 : double dfExtentBottom,
117 : double dfExtentTop,
118 : int nSRID,
119 : int bHasZ );
120 :
121 : virtual void ResetReading();
122 : virtual int GetFeatureCount( int );
123 :
124 : virtual OGRErr SetAttributeFilter( const char * );
125 : virtual OGRFeature *GetFeature( long nFeatureId );
126 :
127 : virtual int TestCapability( const char * );
128 :
129 : virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE);
130 : };
131 :
132 : /************************************************************************/
133 : /* OGRPGeoSelectLayer */
134 : /************************************************************************/
135 :
136 : class OGRPGeoSelectLayer : public OGRPGeoLayer
137 : {
138 : char *pszBaseStatement;
139 :
140 : void ClearStatement();
141 : OGRErr ResetStatement();
142 :
143 : virtual CPLODBCStatement * GetStatement();
144 :
145 : public:
146 : OGRPGeoSelectLayer( OGRPGeoDataSource *,
147 : CPLODBCStatement * );
148 : ~OGRPGeoSelectLayer();
149 :
150 : virtual void ResetReading();
151 : virtual int GetFeatureCount( int );
152 :
153 : virtual OGRFeature *GetFeature( long nFeatureId );
154 :
155 : virtual int TestCapability( const char * );
156 : };
157 :
158 : /************************************************************************/
159 : /* OGRPGeoDataSource */
160 : /************************************************************************/
161 :
162 : class OGRPGeoDataSource : public OGRDataSource
163 : {
164 : OGRPGeoLayer **papoLayers;
165 : int nLayers;
166 :
167 : char *pszName;
168 :
169 : int bDSUpdate;
170 : CPLODBCSession oSession;
171 :
172 : public:
173 : OGRPGeoDataSource();
174 : ~OGRPGeoDataSource();
175 :
176 : int Open( const char *, int bUpdate, int bTestOpen );
177 : int OpenTable( const char *pszTableName,
178 : const char *pszGeomCol,
179 : int bUpdate );
180 :
181 0 : const char *GetName() { return pszName; }
182 0 : int GetLayerCount() { return nLayers; }
183 : OGRLayer *GetLayer( int );
184 :
185 : int TestCapability( const char * );
186 :
187 : virtual OGRLayer * ExecuteSQL( const char *pszSQLCommand,
188 : OGRGeometry *poSpatialFilter,
189 : const char *pszDialect );
190 : virtual void ReleaseResultSet( OGRLayer * poLayer );
191 :
192 : // Internal use
193 0 : CPLODBCSession *GetSession() { return &oSession; }
194 : };
195 :
196 : /************************************************************************/
197 : /* OGRPGeoDriver */
198 : /************************************************************************/
199 :
200 : class OGRPGeoDriver : public OGRSFDriver
201 178 : {
202 : CPLString osDriverFile;
203 :
204 : bool InstallMdbDriver();
205 : bool LibraryExists( const char* pszLibPath );
206 : bool FindDriverLib();
207 : CPLString FindDefaultLib(const char* pszLibName);
208 :
209 : public:
210 : ~OGRPGeoDriver();
211 :
212 : const char *GetName();
213 : OGRDataSource *Open( const char *, int );
214 :
215 : int TestCapability( const char * );
216 : };
217 :
218 : #endif /* ndef _OGR_PGeo_H_INCLUDED */
|