1 : /******************************************************************************
2 : * $Id: ogrsqlitesinglefeaturelayer.cpp 23736 2012-01-09 19:05:02Z rouault $
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: Implements OGRSQLiteSingleFeatureLayer class.
6 : * Author: Even Rouault, <even dot rouault at mines dash paris dot org>
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2010, Even Rouault
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 : #include "cpl_conv.h"
31 : #include "cpl_string.h"
32 : #include "ogr_sqlite.h"
33 :
34 : CPL_CVSID("$Id: ogrsqlitesinglefeaturelayer.cpp 23736 2012-01-09 19:05:02Z rouault $");
35 :
36 : /************************************************************************/
37 : /* OGRSQLiteSingleFeatureLayer() */
38 : /************************************************************************/
39 :
40 76 : OGRSQLiteSingleFeatureLayer::OGRSQLiteSingleFeatureLayer(
41 : const char* pszLayerName,
42 76 : int nVal )
43 : {
44 76 : poFeatureDefn = new OGRFeatureDefn( "SELECT" );
45 76 : poFeatureDefn->Reference();
46 76 : OGRFieldDefn oField( pszLayerName, OFTInteger );
47 76 : poFeatureDefn->AddFieldDefn( &oField );
48 :
49 76 : iNextShapeId = 0;
50 76 : this->nVal = nVal;
51 76 : pszVal = NULL;
52 76 : }
53 :
54 : /************************************************************************/
55 : /* OGRSQLiteSingleFeatureLayer() */
56 : /************************************************************************/
57 :
58 2 : OGRSQLiteSingleFeatureLayer::OGRSQLiteSingleFeatureLayer(
59 : const char* pszLayerName,
60 2 : const char *pszVal )
61 : {
62 2 : poFeatureDefn = new OGRFeatureDefn( "SELECT" );
63 2 : poFeatureDefn->Reference();
64 2 : OGRFieldDefn oField( pszLayerName, OFTString );
65 2 : poFeatureDefn->AddFieldDefn( &oField );
66 :
67 2 : iNextShapeId = 0;
68 2 : nVal = 0;
69 2 : this->pszVal = CPLStrdup(pszVal);
70 2 : }
71 :
72 : /************************************************************************/
73 : /* ~OGRSQLiteSingleFeatureLayer() */
74 : /************************************************************************/
75 :
76 78 : OGRSQLiteSingleFeatureLayer::~OGRSQLiteSingleFeatureLayer()
77 : {
78 78 : if( poFeatureDefn != NULL )
79 : {
80 78 : poFeatureDefn->Release();
81 78 : poFeatureDefn = NULL;
82 : }
83 78 : CPLFree(pszVal);
84 78 : }
85 :
86 : /************************************************************************/
87 : /* ResetReading() */
88 : /************************************************************************/
89 :
90 4 : void OGRSQLiteSingleFeatureLayer::ResetReading()
91 : {
92 4 : iNextShapeId = 0;
93 4 : }
94 :
95 : /************************************************************************/
96 : /* GetNextFeature() */
97 : /************************************************************************/
98 :
99 8 : OGRFeature * OGRSQLiteSingleFeatureLayer::GetNextFeature()
100 : {
101 8 : if (iNextShapeId != 0)
102 2 : return NULL;
103 :
104 6 : OGRFeature* poFeature = new OGRFeature(poFeatureDefn);
105 6 : if (pszVal)
106 2 : poFeature->SetField(0, pszVal);
107 : else
108 4 : poFeature->SetField(0, nVal);
109 6 : poFeature->SetFID(iNextShapeId ++);
110 6 : return poFeature;
111 : }
112 :
113 : /************************************************************************/
114 : /* GetLayerDefn() */
115 : /************************************************************************/
116 :
117 0 : OGRFeatureDefn * OGRSQLiteSingleFeatureLayer::GetLayerDefn()
118 : {
119 0 : return poFeatureDefn;
120 : }
121 :
122 : /************************************************************************/
123 : /* TestCapability() */
124 : /************************************************************************/
125 :
126 0 : int OGRSQLiteSingleFeatureLayer::TestCapability( const char * )
127 : {
128 0 : return FALSE;
129 : }
|