1 : /******************************************************************************
2 : * $Id: ogr_odbc.h 17870 2009-10-22 04:47:29Z warmerdam $
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: Private definitions for OGR/ODBC driver.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2003, 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 : /* OGRODBCLayer */
39 : /************************************************************************/
40 :
41 : class OGRODBCDataSource;
42 :
43 : class OGRODBCLayer : 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 : OGRODBCDataSource *poDS;
57 :
58 : int bGeomColumnWKB;
59 : char *pszGeomColumn;
60 : char *pszFIDColumn;
61 :
62 : int *panFieldOrdinals;
63 :
64 : CPLErr BuildFeatureDefn( const char *pszLayerName,
65 : CPLODBCStatement *poStmt );
66 :
67 0 : virtual CPLODBCStatement * GetStatement() { return poStmt; }
68 :
69 : public:
70 : OGRODBCLayer();
71 : virtual ~OGRODBCLayer();
72 :
73 : virtual void ResetReading();
74 : virtual OGRFeature *GetNextRawFeature();
75 : virtual OGRFeature *GetNextFeature();
76 :
77 : virtual OGRFeature *GetFeature( long nFeatureId );
78 :
79 0 : OGRFeatureDefn * GetLayerDefn() { return poFeatureDefn; }
80 :
81 : virtual OGRSpatialReference *GetSpatialRef();
82 :
83 : virtual int TestCapability( const char * );
84 : };
85 :
86 : /************************************************************************/
87 : /* OGRODBCTableLayer */
88 : /************************************************************************/
89 :
90 : class OGRODBCTableLayer : public OGRODBCLayer
91 : {
92 : int bUpdateAccess;
93 :
94 : char *pszQuery;
95 :
96 : int bHaveSpatialExtents;
97 :
98 : void ClearStatement();
99 : OGRErr ResetStatement();
100 :
101 : virtual CPLODBCStatement * GetStatement();
102 :
103 : char *pszTableName;
104 : char *pszSchemaName;
105 :
106 : public:
107 : OGRODBCTableLayer( OGRODBCDataSource * );
108 : ~OGRODBCTableLayer();
109 :
110 : CPLErr Initialize( const char *pszTableName,
111 : const char *pszGeomCol );
112 :
113 : virtual void ResetReading();
114 : virtual int GetFeatureCount( int );
115 :
116 : virtual OGRErr SetAttributeFilter( const char * );
117 : #ifdef notdef
118 : virtual OGRErr SetFeature( OGRFeature *poFeature );
119 : virtual OGRErr CreateFeature( OGRFeature *poFeature );
120 :
121 : virtual OGRErr CreateField( OGRFieldDefn *poField,
122 : int bApproxOK = TRUE );
123 : #endif
124 : virtual OGRFeature *GetFeature( long nFeatureId );
125 :
126 : virtual OGRSpatialReference *GetSpatialRef();
127 :
128 : virtual int TestCapability( const char * );
129 :
130 : #ifdef notdef
131 : // follow methods are not base class overrides
132 : void SetLaunderFlag( int bFlag )
133 : { bLaunderColumnNames = bFlag; }
134 : void SetPrecisionFlag( int bFlag )
135 : { bPreservePrecision = bFlag; }
136 : #endif
137 : };
138 :
139 : /************************************************************************/
140 : /* OGRODBCSelectLayer */
141 : /************************************************************************/
142 :
143 : class OGRODBCSelectLayer : public OGRODBCLayer
144 : {
145 : char *pszBaseStatement;
146 :
147 : void ClearStatement();
148 : OGRErr ResetStatement();
149 :
150 : virtual CPLODBCStatement * GetStatement();
151 :
152 : public:
153 : OGRODBCSelectLayer( OGRODBCDataSource *,
154 : CPLODBCStatement * );
155 : ~OGRODBCSelectLayer();
156 :
157 : virtual void ResetReading();
158 : virtual int GetFeatureCount( int );
159 :
160 : virtual OGRFeature *GetFeature( long nFeatureId );
161 :
162 : virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE);
163 :
164 : virtual int TestCapability( const char * );
165 : };
166 :
167 : /************************************************************************/
168 : /* OGRODBCDataSource */
169 : /************************************************************************/
170 :
171 : class OGRODBCDataSource : public OGRDataSource
172 : {
173 : OGRODBCLayer **papoLayers;
174 : int nLayers;
175 :
176 : char *pszName;
177 :
178 : int bDSUpdate;
179 : CPLODBCSession oSession;
180 :
181 : // We maintain a list of known SRID to reduce the number of trips to
182 : // the database to get SRSes.
183 : int nKnownSRID;
184 : int *panSRID;
185 : OGRSpatialReference **papoSRS;
186 :
187 : public:
188 : OGRODBCDataSource();
189 : ~OGRODBCDataSource();
190 :
191 : int Open( const char *, int bUpdate, int bTestOpen );
192 : int OpenTable( const char *pszTableName,
193 : const char *pszGeomCol,
194 : int bUpdate );
195 :
196 0 : const char *GetName() { return pszName; }
197 0 : int GetLayerCount() { return nLayers; }
198 : OGRLayer *GetLayer( int );
199 :
200 : int TestCapability( const char * );
201 :
202 : virtual OGRLayer * ExecuteSQL( const char *pszSQLCommand,
203 : OGRGeometry *poSpatialFilter,
204 : const char *pszDialect );
205 : virtual void ReleaseResultSet( OGRLayer * poLayer );
206 :
207 : // Internal use
208 0 : CPLODBCSession *GetSession() { return &oSession; }
209 :
210 : };
211 :
212 : /************************************************************************/
213 : /* OGRODBCDriver */
214 : /************************************************************************/
215 :
216 : class OGRODBCDriver : public OGRSFDriver
217 80 : {
218 : public:
219 : ~OGRODBCDriver();
220 :
221 : const char *GetName();
222 : OGRDataSource *Open( const char *, int );
223 :
224 : virtual OGRDataSource *CreateDataSource( const char *pszName,
225 : char ** = NULL );
226 :
227 : int TestCapability( const char * );
228 : };
229 :
230 :
231 : #endif /* ndef _OGR_ODBC_H_INCLUDED */
232 :
233 :
|