/src/gdal/ogr/ogrsf_frmts/sqlite/ogrsqlitesinglefeaturelayer.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | OGRSQLiteSingleFeatureLayer::OGRSQLiteSingleFeatureLayer( |
26 | | const char *pszLayerName, int nValIn) |
27 | 0 | : nVal(nValIn), pszVal(nullptr), |
28 | 0 | poFeatureDefn(new OGRFeatureDefn("SELECT")), iNextShapeId(0) |
29 | 0 | { |
30 | 0 | SetDescription(poFeatureDefn->GetName()); |
31 | 0 | poFeatureDefn->Reference(); |
32 | 0 | OGRFieldDefn oField(pszLayerName, OFTInteger); |
33 | 0 | poFeatureDefn->AddFieldDefn(&oField); |
34 | 0 | } |
35 | | |
36 | | /************************************************************************/ |
37 | | /* OGRSQLiteSingleFeatureLayer() */ |
38 | | /************************************************************************/ |
39 | | |
40 | | OGRSQLiteSingleFeatureLayer::OGRSQLiteSingleFeatureLayer( |
41 | | const char *pszLayerName, const char *pszValIn) |
42 | 0 | : nVal(0), pszVal(CPLStrdup(pszValIn)), |
43 | 0 | poFeatureDefn(new OGRFeatureDefn("SELECT")), iNextShapeId(0) |
44 | 0 | { |
45 | 0 | poFeatureDefn->Reference(); |
46 | 0 | OGRFieldDefn oField(pszLayerName, OFTString); |
47 | 0 | poFeatureDefn->AddFieldDefn(&oField); |
48 | 0 | } |
49 | | |
50 | | /************************************************************************/ |
51 | | /* ~OGRSQLiteSingleFeatureLayer() */ |
52 | | /************************************************************************/ |
53 | | |
54 | | OGRSQLiteSingleFeatureLayer::~OGRSQLiteSingleFeatureLayer() |
55 | 0 | { |
56 | 0 | if (poFeatureDefn != nullptr) |
57 | 0 | { |
58 | 0 | poFeatureDefn->Release(); |
59 | 0 | poFeatureDefn = nullptr; |
60 | 0 | } |
61 | 0 | CPLFree(pszVal); |
62 | 0 | } |
63 | | |
64 | | /************************************************************************/ |
65 | | /* ResetReading() */ |
66 | | /************************************************************************/ |
67 | | |
68 | | void OGRSQLiteSingleFeatureLayer::ResetReading() |
69 | 0 | { |
70 | 0 | iNextShapeId = 0; |
71 | 0 | } |
72 | | |
73 | | /************************************************************************/ |
74 | | /* GetNextFeature() */ |
75 | | /************************************************************************/ |
76 | | |
77 | | OGRFeature *OGRSQLiteSingleFeatureLayer::GetNextFeature() |
78 | 0 | { |
79 | 0 | if (iNextShapeId != 0) |
80 | 0 | return nullptr; |
81 | | |
82 | 0 | OGRFeature *poFeature = new OGRFeature(poFeatureDefn); |
83 | 0 | if (pszVal) |
84 | 0 | poFeature->SetField(0, pszVal); |
85 | 0 | else |
86 | 0 | poFeature->SetField(0, nVal); |
87 | 0 | poFeature->SetFID(iNextShapeId++); |
88 | 0 | return poFeature; |
89 | 0 | } |
90 | | |
91 | | /************************************************************************/ |
92 | | /* GetLayerDefn() */ |
93 | | /************************************************************************/ |
94 | | |
95 | | OGRFeatureDefn *OGRSQLiteSingleFeatureLayer::GetLayerDefn() |
96 | 0 | { |
97 | 0 | return poFeatureDefn; |
98 | 0 | } |
99 | | |
100 | | /************************************************************************/ |
101 | | /* TestCapability() */ |
102 | | /************************************************************************/ |
103 | | |
104 | | int OGRSQLiteSingleFeatureLayer::TestCapability(const char *) |
105 | 0 | { |
106 | 0 | return FALSE; |
107 | 0 | } |