LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/filegdb - FGdbResultLayer.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 40 71 56.3 %
Date: 2024-05-06 18:28:20 Functions: 3 5 60.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  OpenGIS Simple Features Reference Implementation
       4             :  * Purpose:  Implements FileGDB OGR result layer.
       5             :  * Author:   Even Rouault, <even dot rouault at spatialys.com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 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 "ogr_fgdb.h"
      30             : #include "cpl_conv.h"
      31             : #include "cpl_string.h"
      32             : #include "FGdbUtils.h"
      33             : 
      34             : using std::string;
      35             : using std::wstring;
      36             : 
      37             : /************************************************************************/
      38             : /*                         FGdbResultLayer()                            */
      39             : /************************************************************************/
      40           2 : FGdbResultLayer::FGdbResultLayer(FGdbDataSource *pParentDataSource,
      41           2 :                                  const char *pszSQL, EnumRows *pEnumRows)
      42             : {
      43           2 :     m_pFeatureDefn = new OGRFeatureDefn("result");
      44           2 :     SetDescription(m_pFeatureDefn->GetName());
      45           2 :     m_pFeatureDefn->Reference();
      46           2 :     m_pEnumRows = pEnumRows;
      47           2 :     m_pDS = pParentDataSource;
      48           2 :     osSQL = pszSQL;
      49             : 
      50           2 :     m_suppressColumnMappingError = false;
      51             : 
      52           4 :     FieldInfo fieldInfo;
      53           2 :     m_pEnumRows->GetFieldInformation(fieldInfo);
      54             : 
      55             :     int fieldCount;
      56           2 :     fieldInfo.GetFieldCount(fieldCount);
      57           8 :     for (int i = 0; i < fieldCount; i++)
      58             :     {
      59             :         FieldType fieldType;
      60          12 :         string strFieldType;
      61          12 :         wstring fieldName;
      62           6 :         fieldInfo.GetFieldType(i, fieldType);
      63           6 :         fieldInfo.GetFieldName(i, fieldName);
      64             : 
      65           6 :         OGRFieldType eType = OFTString;
      66           6 :         int bSkip = FALSE;
      67             : 
      68           6 :         switch (fieldType)
      69             :         {
      70           0 :             case fieldTypeSmallInteger:
      71             :             case fieldTypeInteger:
      72           0 :                 eType = OFTInteger;
      73           0 :                 break;
      74             : 
      75           0 :             case fieldTypeSingle:
      76           0 :                 eType = OFTReal;
      77           0 :                 strFieldType = "esriFieldTypeSingle";
      78           0 :                 break;
      79             : 
      80           2 :             case fieldTypeDouble:
      81           2 :                 eType = OFTReal;
      82           2 :                 break;
      83             : 
      84           1 :             case fieldTypeString:
      85           1 :                 eType = OFTString;
      86           1 :                 break;
      87             : 
      88           0 :             case fieldTypeDate:
      89           0 :                 eType = OFTDateTime;
      90           0 :                 break;
      91             : 
      92           2 :             case fieldTypeOID:
      93           2 :                 bSkip = TRUE;
      94           2 :                 break;
      95             : 
      96           1 :             case fieldTypeGeometry:
      97           1 :                 bSkip = TRUE;
      98           1 :                 break;
      99             : 
     100           0 :             case fieldTypeBlob:
     101           0 :                 eType = OFTBinary;
     102           0 :                 break;
     103             : 
     104           0 :             case fieldTypeRaster:
     105           0 :                 bSkip = TRUE;
     106           0 :                 break;
     107             : 
     108           0 :             case fieldTypeGUID:
     109           0 :                 break;
     110             : 
     111           0 :             case fieldTypeGlobalID:
     112           0 :                 break;
     113             : 
     114           0 :             case fieldTypeXML:
     115           0 :                 break;
     116             : 
     117           0 :             default:
     118           0 :                 CPLAssert(false);
     119             :                 break;
     120             :         }
     121             : 
     122           6 :         if (!bSkip)
     123             :         {
     124           6 :             OGRFieldDefn oFieldDefn(WStringToString(fieldName).c_str(), eType);
     125             :             // cppcheck-suppress danglingTemporaryLifetime
     126           3 :             m_pFeatureDefn->AddFieldDefn(&oFieldDefn);
     127             : 
     128           3 :             m_vOGRFieldToESRIField.push_back(fieldName);
     129           3 :             m_vOGRFieldToESRIFieldType.push_back(strFieldType);
     130             :         }
     131             :     }
     132           2 : }
     133             : 
     134             : /************************************************************************/
     135             : /*                         ~FGdbResultLayer()                           */
     136             : /************************************************************************/
     137             : 
     138           4 : FGdbResultLayer::~FGdbResultLayer()
     139             : {
     140           4 : }
     141             : 
     142             : /************************************************************************/
     143             : /*                            ResetReading()                            */
     144             : /************************************************************************/
     145             : 
     146           0 : void FGdbResultLayer::ResetReading()
     147             : {
     148           0 :     m_pEnumRows->Close();
     149             :     long hr;
     150           0 :     if (FAILED(hr = m_pDS->GetGDB()->ExecuteSQL(StringToWString(osSQL), true,
     151             :                                                 *m_pEnumRows)))
     152             :     {
     153           0 :         GDBErr(hr, CPLSPrintf("Failed at executing '%s'", osSQL.c_str()));
     154             :     }
     155           0 : }
     156             : 
     157             : /************************************************************************/
     158             : /*                           TestCapability()                           */
     159             : /************************************************************************/
     160             : 
     161           0 : int FGdbResultLayer::TestCapability(const char *)
     162             : {
     163           0 :     return FALSE;
     164             : }

Generated by: LCOV version 1.14