LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/sqlite - ogrsqlitesinglefeaturelayer.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 34 38 89.5 %
Date: 2024-04-29 12:21:24 Functions: 6 8 75.0 %

          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             :  * Permission is hereby granted, free of charge, to any person obtaining a
      11             :  * copy of this software and associated documentation files (the "Software"),
      12             :  * to deal in the Software without restriction, including without limitation
      13             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      14             :  * and/or sell copies of the Software, and to permit persons to whom the
      15             :  * Software is furnished to do so, subject to the following conditions:
      16             :  *
      17             :  * The above copyright notice and this permission notice shall be included
      18             :  * in all copies or substantial portions of the Software.
      19             :  *
      20             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      21             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      22             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      23             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      24             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      25             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      26             :  * DEALINGS IN THE SOFTWARE.
      27             :  ****************************************************************************/
      28             : 
      29             : #include "cpl_port.h"
      30             : #include "ogr_sqlite.h"
      31             : 
      32             : #include "cpl_conv.h"
      33             : #include "cpl_string.h"
      34             : #include "ogr_core.h"
      35             : #include "ogr_feature.h"
      36             : 
      37             : /************************************************************************/
      38             : /*                    OGRSQLiteSingleFeatureLayer()                     */
      39             : /************************************************************************/
      40             : 
      41         167 : OGRSQLiteSingleFeatureLayer::OGRSQLiteSingleFeatureLayer(
      42         167 :     const char *pszLayerName, int nValIn)
      43             :     : nVal(nValIn), pszVal(nullptr),
      44         167 :       poFeatureDefn(new OGRFeatureDefn("SELECT")), iNextShapeId(0)
      45             : {
      46         167 :     SetDescription(poFeatureDefn->GetName());
      47         167 :     poFeatureDefn->Reference();
      48         334 :     OGRFieldDefn oField(pszLayerName, OFTInteger);
      49         167 :     poFeatureDefn->AddFieldDefn(&oField);
      50         167 : }
      51             : 
      52             : /************************************************************************/
      53             : /*                    OGRSQLiteSingleFeatureLayer()                     */
      54             : /************************************************************************/
      55             : 
      56           3 : OGRSQLiteSingleFeatureLayer::OGRSQLiteSingleFeatureLayer(
      57           3 :     const char *pszLayerName, const char *pszValIn)
      58           6 :     : nVal(0), pszVal(CPLStrdup(pszValIn)),
      59           3 :       poFeatureDefn(new OGRFeatureDefn("SELECT")), iNextShapeId(0)
      60             : {
      61           3 :     poFeatureDefn->Reference();
      62           6 :     OGRFieldDefn oField(pszLayerName, OFTString);
      63           3 :     poFeatureDefn->AddFieldDefn(&oField);
      64           3 : }
      65             : 
      66             : /************************************************************************/
      67             : /*                   ~OGRSQLiteSingleFeatureLayer()                     */
      68             : /************************************************************************/
      69             : 
      70         338 : OGRSQLiteSingleFeatureLayer::~OGRSQLiteSingleFeatureLayer()
      71             : {
      72         169 :     if (poFeatureDefn != nullptr)
      73             :     {
      74         169 :         poFeatureDefn->Release();
      75         169 :         poFeatureDefn = nullptr;
      76             :     }
      77         169 :     CPLFree(pszVal);
      78         338 : }
      79             : 
      80             : /************************************************************************/
      81             : /*                            ResetReading()                            */
      82             : /************************************************************************/
      83             : 
      84           2 : void OGRSQLiteSingleFeatureLayer::ResetReading()
      85             : {
      86           2 :     iNextShapeId = 0;
      87           2 : }
      88             : 
      89             : /************************************************************************/
      90             : /*                           GetNextFeature()                           */
      91             : /************************************************************************/
      92             : 
      93          66 : OGRFeature *OGRSQLiteSingleFeatureLayer::GetNextFeature()
      94             : {
      95          66 :     if (iNextShapeId != 0)
      96           1 :         return nullptr;
      97             : 
      98          65 :     OGRFeature *poFeature = new OGRFeature(poFeatureDefn);
      99          65 :     if (pszVal)
     100           1 :         poFeature->SetField(0, pszVal);
     101             :     else
     102          64 :         poFeature->SetField(0, nVal);
     103          65 :     poFeature->SetFID(iNextShapeId++);
     104          65 :     return poFeature;
     105             : }
     106             : 
     107             : /************************************************************************/
     108             : /*                            GetLayerDefn()                            */
     109             : /************************************************************************/
     110             : 
     111           0 : OGRFeatureDefn *OGRSQLiteSingleFeatureLayer::GetLayerDefn()
     112             : {
     113           0 :     return poFeatureDefn;
     114             : }
     115             : 
     116             : /************************************************************************/
     117             : /*                           TestCapability()                           */
     118             : /************************************************************************/
     119             : 
     120           0 : int OGRSQLiteSingleFeatureLayer::TestCapability(const char *)
     121             : {
     122           0 :     return FALSE;
     123             : }

Generated by: LCOV version 1.14