Coverage Report

Created: 2025-08-11 09:23

/src/gdal/ogr/ogrsf_frmts/amigocloud/ogramigocloudresultlayer.cpp
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Project:  AmigoCloud Translator
4
 * Purpose:  Implements OGRAmigoCloudResultLayer class.
5
 * Author:   Victor Chernetsky, <victor at amigocloud dot com>
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2015, Victor Chernetsky, <victor at amigocloud dot com>
9
 *
10
 * SPDX-License-Identifier: MIT
11
 ****************************************************************************/
12
13
#include "ogr_amigocloud.h"
14
15
/************************************************************************/
16
/*                          OGRAmigoCloudResultLayer()                     */
17
/************************************************************************/
18
19
OGRAmigoCloudResultLayer::OGRAmigoCloudResultLayer(
20
    OGRAmigoCloudDataSource *poDSIn, const char *pszRawQueryIn)
21
108
    : OGRAmigoCloudLayer(poDSIn)
22
108
{
23
108
    osBaseSQL = pszRawQueryIn;
24
108
    SetDescription("result");
25
108
    poFirstFeature = nullptr;
26
108
}
27
28
/************************************************************************/
29
/*                       ~OGRAmigoCloudResultLayer()                       */
30
/************************************************************************/
31
32
OGRAmigoCloudResultLayer::~OGRAmigoCloudResultLayer()
33
34
108
{
35
108
    delete poFirstFeature;
36
108
}
37
38
/************************************************************************/
39
/*                          GetLayerDefnInternal()                      */
40
/************************************************************************/
41
42
OGRFeatureDefn *
43
OGRAmigoCloudResultLayer::GetLayerDefnInternal(json_object *poObjIn)
44
0
{
45
0
    if (poFeatureDefn != nullptr)
46
0
        return poFeatureDefn;
47
48
0
    EstablishLayerDefn("result", poObjIn);
49
50
0
    return poFeatureDefn;
51
0
}
52
53
/************************************************************************/
54
/*                           GetNextRawFeature()                        */
55
/************************************************************************/
56
57
OGRFeature *OGRAmigoCloudResultLayer::GetNextRawFeature()
58
108
{
59
108
    if (poFirstFeature)
60
0
    {
61
0
        OGRFeature *poRet = poFirstFeature;
62
0
        poFirstFeature = nullptr;
63
0
        return poRet;
64
0
    }
65
108
    else
66
108
        return OGRAmigoCloudLayer::GetNextRawFeature();
67
108
}
68
69
/************************************************************************/
70
/*                                IsOK()                                */
71
/************************************************************************/
72
73
int OGRAmigoCloudResultLayer::IsOK()
74
108
{
75
108
    CPLErrorReset();
76
108
    poFirstFeature = GetNextFeature();
77
108
    return CPLGetLastErrorType() == 0;
78
108
}
79
80
/************************************************************************/
81
/*                             GetSRS_SQL()                             */
82
/************************************************************************/
83
84
CPLString OGRAmigoCloudResultLayer::GetSRS_SQL(const char *pszGeomCol)
85
0
{
86
0
    CPLString osSQL;
87
0
    CPLString osLimitedSQL;
88
89
0
    size_t nPos = osBaseSQL.ifind(" LIMIT ");
90
0
    if (nPos != std::string::npos)
91
0
    {
92
0
        osLimitedSQL = osBaseSQL;
93
0
        size_t nSize = osLimitedSQL.size();
94
0
        for (size_t i = nPos + strlen(" LIMIT "); i < nSize; i++)
95
0
        {
96
0
            if (osLimitedSQL[i] == ' ' && osLimitedSQL[i - 1] == '0')
97
0
            {
98
0
                osLimitedSQL[i - 1] = '1';
99
0
                break;
100
0
            }
101
0
            osLimitedSQL[i] = '0';
102
0
        }
103
0
    }
104
0
    else
105
0
        osLimitedSQL.Printf("%s LIMIT 1", osBaseSQL.c_str());
106
107
    /* Assuming that the SRID of the first non-NULL geometry applies */
108
    /* to geometries of all rows. */
109
0
    osSQL.Printf("SELECT srid, srtext FROM spatial_ref_sys WHERE srid IN "
110
0
                 "(SELECT ST_SRID(%s) FROM (%s) ogr_subselect)",
111
0
                 OGRAMIGOCLOUDEscapeIdentifier(pszGeomCol).c_str(),
112
0
                 osLimitedSQL.c_str());
113
114
0
    return osSQL;
115
0
}