1 : /******************************************************************************
2 : * $Id: ogrpgeoselectlayer.cpp 20194 2010-08-06 18:28:05Z rouault $
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: Implements OGRPGeoSelectLayer class, layer access to the results
6 : * of a SELECT statement executed via ExecuteSQL().
7 : * Author: Frank Warmerdam, warmerdam@pobox.com
8 : *
9 : ******************************************************************************
10 : * Copyright (c) 2005, Frank Warmerdam
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 : #include "cpl_conv.h"
32 : #include "ogr_pgeo.h"
33 :
34 : CPL_CVSID("$Id: ogrpgeoselectlayer.cpp 20194 2010-08-06 18:28:05Z rouault $");
35 :
36 : /************************************************************************/
37 : /* OGRPGeoSelectLayer() */
38 : /************************************************************************/
39 :
40 0 : OGRPGeoSelectLayer::OGRPGeoSelectLayer( OGRPGeoDataSource *poDSIn,
41 0 : CPLODBCStatement * poStmtIn )
42 :
43 : {
44 0 : poDS = poDSIn;
45 :
46 0 : iNextShapeId = 0;
47 0 : nSRSId = -1;
48 0 : poFeatureDefn = NULL;
49 :
50 0 : poStmt = poStmtIn;
51 0 : pszBaseStatement = CPLStrdup( poStmtIn->GetCommand() );
52 :
53 0 : BuildFeatureDefn( "SELECT", poStmt );
54 0 : }
55 :
56 : /************************************************************************/
57 : /* ~OGRPGeoSelectLayer() */
58 : /************************************************************************/
59 :
60 0 : OGRPGeoSelectLayer::~OGRPGeoSelectLayer()
61 :
62 : {
63 0 : ClearStatement();
64 0 : CPLFree(pszBaseStatement);
65 0 : }
66 :
67 : /************************************************************************/
68 : /* ClearStatement() */
69 : /************************************************************************/
70 :
71 0 : void OGRPGeoSelectLayer::ClearStatement()
72 :
73 : {
74 0 : if( poStmt != NULL )
75 : {
76 0 : delete poStmt;
77 0 : poStmt = NULL;
78 : }
79 0 : }
80 :
81 : /************************************************************************/
82 : /* GetStatement() */
83 : /************************************************************************/
84 :
85 0 : CPLODBCStatement *OGRPGeoSelectLayer::GetStatement()
86 :
87 : {
88 0 : if( poStmt == NULL )
89 0 : ResetStatement();
90 :
91 0 : return poStmt;
92 : }
93 :
94 : /************************************************************************/
95 : /* ResetStatement() */
96 : /************************************************************************/
97 :
98 0 : OGRErr OGRPGeoSelectLayer::ResetStatement()
99 :
100 : {
101 0 : ClearStatement();
102 :
103 0 : iNextShapeId = 0;
104 :
105 0 : CPLDebug( "ODBC", "Recreating statement." );
106 0 : poStmt = new CPLODBCStatement( poDS->GetSession() );
107 0 : poStmt->Append( pszBaseStatement );
108 :
109 0 : if( poStmt->ExecuteSQL() )
110 0 : return OGRERR_NONE;
111 : else
112 : {
113 0 : delete poStmt;
114 0 : poStmt = NULL;
115 0 : return OGRERR_FAILURE;
116 : }
117 : }
118 :
119 : /************************************************************************/
120 : /* ResetReading() */
121 : /************************************************************************/
122 :
123 0 : void OGRPGeoSelectLayer::ResetReading()
124 :
125 : {
126 0 : if( iNextShapeId != 0 )
127 0 : ClearStatement();
128 :
129 0 : OGRPGeoLayer::ResetReading();
130 0 : }
131 :
132 : /************************************************************************/
133 : /* GetFeature() */
134 : /************************************************************************/
135 :
136 0 : OGRFeature *OGRPGeoSelectLayer::GetFeature( long nFeatureId )
137 :
138 : {
139 0 : return OGRPGeoLayer::GetFeature( nFeatureId );
140 : }
141 :
142 : /************************************************************************/
143 : /* TestCapability() */
144 : /************************************************************************/
145 :
146 0 : int OGRPGeoSelectLayer::TestCapability( const char * pszCap )
147 :
148 : {
149 0 : return OGRPGeoLayer::TestCapability( pszCap );
150 : }
151 :
152 : /************************************************************************/
153 : /* GetFeatureCount() */
154 : /* */
155 : /* If a spatial filter is in effect, we turn control over to */
156 : /* the generic counter. Otherwise we return the total count. */
157 : /* Eventually we should consider implementing a more efficient */
158 : /* way of counting features matching a spatial query. */
159 : /************************************************************************/
160 :
161 0 : int OGRPGeoSelectLayer::GetFeatureCount( int bForce )
162 :
163 : {
164 0 : return OGRPGeoLayer::GetFeatureCount( bForce );
165 : }
|