Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: OpenGIS Simple Features Reference Implementation 4 : * Purpose: Implements OGRSQLiteSingleFeatureLayer class. 5 : * Author: Even Rouault, <even dot rouault at spatialys.com> 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2010-2012, Even Rouault <even dot rouault at spatialys.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #include "cpl_port.h" 14 : #include "ogr_sqlite.h" 15 : 16 : #include "cpl_conv.h" 17 : #include "cpl_string.h" 18 : #include "ogr_core.h" 19 : #include "ogr_feature.h" 20 : 21 : /************************************************************************/ 22 : /* OGRSQLiteSingleFeatureLayer() */ 23 : /************************************************************************/ 24 : 25 170 : OGRSQLiteSingleFeatureLayer::OGRSQLiteSingleFeatureLayer( 26 170 : const char *pszLayerName, int nValIn) 27 : : nVal(nValIn), pszVal(nullptr), 28 170 : poFeatureDefn(new OGRFeatureDefn("SELECT")), iNextShapeId(0) 29 : { 30 170 : SetDescription(poFeatureDefn->GetName()); 31 170 : poFeatureDefn->Reference(); 32 340 : OGRFieldDefn oField(pszLayerName, OFTInteger); 33 170 : poFeatureDefn->AddFieldDefn(&oField); 34 170 : } 35 : 36 : /************************************************************************/ 37 : /* OGRSQLiteSingleFeatureLayer() */ 38 : /************************************************************************/ 39 : 40 3 : OGRSQLiteSingleFeatureLayer::OGRSQLiteSingleFeatureLayer( 41 3 : const char *pszLayerName, const char *pszValIn) 42 6 : : nVal(0), pszVal(CPLStrdup(pszValIn)), 43 3 : poFeatureDefn(new OGRFeatureDefn("SELECT")), iNextShapeId(0) 44 : { 45 3 : poFeatureDefn->Reference(); 46 6 : OGRFieldDefn oField(pszLayerName, OFTString); 47 3 : poFeatureDefn->AddFieldDefn(&oField); 48 3 : } 49 : 50 : /************************************************************************/ 51 : /* ~OGRSQLiteSingleFeatureLayer() */ 52 : /************************************************************************/ 53 : 54 346 : OGRSQLiteSingleFeatureLayer::~OGRSQLiteSingleFeatureLayer() 55 : { 56 173 : if (poFeatureDefn != nullptr) 57 : { 58 173 : poFeatureDefn->Release(); 59 173 : poFeatureDefn = nullptr; 60 : } 61 173 : CPLFree(pszVal); 62 346 : } 63 : 64 : /************************************************************************/ 65 : /* ResetReading() */ 66 : /************************************************************************/ 67 : 68 2 : void OGRSQLiteSingleFeatureLayer::ResetReading() 69 : { 70 2 : iNextShapeId = 0; 71 2 : } 72 : 73 : /************************************************************************/ 74 : /* GetNextFeature() */ 75 : /************************************************************************/ 76 : 77 69 : OGRFeature *OGRSQLiteSingleFeatureLayer::GetNextFeature() 78 : { 79 69 : if (iNextShapeId != 0) 80 1 : return nullptr; 81 : 82 68 : OGRFeature *poFeature = new OGRFeature(poFeatureDefn); 83 68 : if (pszVal) 84 1 : poFeature->SetField(0, pszVal); 85 : else 86 67 : poFeature->SetField(0, nVal); 87 68 : poFeature->SetFID(iNextShapeId++); 88 68 : return poFeature; 89 : } 90 : 91 : /************************************************************************/ 92 : /* GetLayerDefn() */ 93 : /************************************************************************/ 94 : 95 0 : OGRFeatureDefn *OGRSQLiteSingleFeatureLayer::GetLayerDefn() 96 : { 97 0 : return poFeatureDefn; 98 : } 99 : 100 : /************************************************************************/ 101 : /* TestCapability() */ 102 : /************************************************************************/ 103 : 104 0 : int OGRSQLiteSingleFeatureLayer::TestCapability(const char *) 105 : { 106 0 : return FALSE; 107 : }