1 : /******************************************************************************
2 : * $Id: ogrsqlitesinglefeaturelayer.cpp 19205 2010-03-26 22:48:37Z 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 19205 2010-03-26 22:48:37Z rouault $");
35 :
36 : /************************************************************************/
37 : /* OGRSQLiteSingleFeatureLayer() */
38 : /************************************************************************/
39 :
40 : OGRSQLiteSingleFeatureLayer::OGRSQLiteSingleFeatureLayer(
41 : const char* pszLayerName,
42 37 : int nVal )
43 : {
44 37 : poFeatureDefn = new OGRFeatureDefn( "SELECT" );
45 37 : poFeatureDefn->Reference();
46 37 : OGRFieldDefn oField( pszLayerName, OFTInteger );
47 37 : poFeatureDefn->AddFieldDefn( &oField );
48 :
49 37 : iNextShapeId = 0;
50 37 : this->nVal = nVal;
51 37 : }
52 :
53 : /************************************************************************/
54 : /* ~OGRSQLiteSingleFeatureLayer() */
55 : /************************************************************************/
56 :
57 37 : OGRSQLiteSingleFeatureLayer::~OGRSQLiteSingleFeatureLayer()
58 : {
59 37 : if( poFeatureDefn != NULL )
60 : {
61 37 : poFeatureDefn->Release();
62 37 : poFeatureDefn = NULL;
63 : }
64 37 : }
65 :
66 : /************************************************************************/
67 : /* ResetReading() */
68 : /************************************************************************/
69 :
70 2 : void OGRSQLiteSingleFeatureLayer::ResetReading()
71 : {
72 2 : iNextShapeId = 0;
73 2 : }
74 :
75 : /************************************************************************/
76 : /* GetNextFeature() */
77 : /************************************************************************/
78 :
79 3 : OGRFeature * OGRSQLiteSingleFeatureLayer::GetNextFeature()
80 : {
81 3 : if (iNextShapeId != 0)
82 1 : return NULL;
83 :
84 2 : OGRFeature* poFeature = new OGRFeature(poFeatureDefn);
85 2 : poFeature->SetField(0, nVal);
86 2 : poFeature->SetFID(iNextShapeId ++);
87 2 : return poFeature;
88 : }
89 :
90 : /************************************************************************/
91 : /* GetLayerDefn() */
92 : /************************************************************************/
93 :
94 0 : OGRFeatureDefn * OGRSQLiteSingleFeatureLayer::GetLayerDefn()
95 : {
96 0 : return poFeatureDefn;
97 : }
98 :
99 : /************************************************************************/
100 : /* TestCapability() */
101 : /************************************************************************/
102 :
103 0 : int OGRSQLiteSingleFeatureLayer::TestCapability( const char * )
104 : {
105 0 : return FALSE;
106 : }
|