LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/odbc - ogrodbcselectlayer.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 0 46 0.0 %
Date: 2024-05-03 15:49:35 Functions: 0 11 0.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  OpenGIS Simple Features Reference Implementation
       4             :  * Purpose:  Implements OGRODBCSelectLayer class, layer access to the results
       5             :  *           of a SELECT statement executed via ExecuteSQL().
       6             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) 2004, Frank Warmerdam
      10             :  *
      11             :  * Permission is hereby granted, free of charge, to any person obtaining a
      12             :  * copy of this software and associated documentation files (the "Software"),
      13             :  * to deal in the Software without restriction, including without limitation
      14             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15             :  * and/or sell copies of the Software, and to permit persons to whom the
      16             :  * Software is furnished to do so, subject to the following conditions:
      17             :  *
      18             :  * The above copyright notice and this permission notice shall be included
      19             :  * in all copies or substantial portions of the Software.
      20             :  *
      21             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27             :  * DEALINGS IN THE SOFTWARE.
      28             :  ****************************************************************************/
      29             : 
      30             : #include "cpl_conv.h"
      31             : #include "ogr_odbc.h"
      32             : 
      33             : /************************************************************************/
      34             : /*                          OGRODBCSelectLayer()                         */
      35             : /************************************************************************/
      36             : 
      37           0 : OGRODBCSelectLayer::OGRODBCSelectLayer(OGRODBCDataSource *poDSIn,
      38           0 :                                        CPLODBCStatement *poStmtIn)
      39           0 :     : pszBaseStatement(CPLStrdup(poStmtIn->GetCommand()))
      40             : {
      41           0 :     poDS = poDSIn;
      42             : 
      43           0 :     iNextShapeId = 0;
      44           0 :     nSRSId = -1;
      45           0 :     poFeatureDefn = nullptr;
      46             : 
      47           0 :     poStmt = poStmtIn;
      48             : 
      49           0 :     BuildFeatureDefn("SELECT", poStmt);
      50           0 : }
      51             : 
      52             : /************************************************************************/
      53             : /*                          ~OGRODBCSelectLayer()                          */
      54             : /************************************************************************/
      55             : 
      56           0 : OGRODBCSelectLayer::~OGRODBCSelectLayer()
      57             : 
      58             : {
      59           0 :     ClearStatement();
      60           0 : }
      61             : 
      62             : /************************************************************************/
      63             : /*                           ClearStatement()                           */
      64             : /************************************************************************/
      65             : 
      66           0 : void OGRODBCSelectLayer::ClearStatement()
      67             : 
      68             : {
      69           0 :     if (poStmt != nullptr)
      70             :     {
      71           0 :         delete poStmt;
      72           0 :         poStmt = nullptr;
      73             :     }
      74           0 : }
      75             : 
      76             : /************************************************************************/
      77             : /*                            GetStatement()                            */
      78             : /************************************************************************/
      79             : 
      80           0 : CPLODBCStatement *OGRODBCSelectLayer::GetStatement()
      81             : 
      82             : {
      83           0 :     if (poStmt == nullptr)
      84           0 :         ResetStatement();
      85             : 
      86           0 :     return poStmt;
      87             : }
      88             : 
      89             : /************************************************************************/
      90             : /*                           ResetStatement()                           */
      91             : /************************************************************************/
      92             : 
      93           0 : OGRErr OGRODBCSelectLayer::ResetStatement()
      94             : 
      95             : {
      96           0 :     ClearStatement();
      97             : 
      98           0 :     iNextShapeId = 0;
      99             : 
     100           0 :     CPLDebug("OGR_ODBC", "Recreating statement.");
     101           0 :     poStmt = new CPLODBCStatement(poDS->GetSession());
     102           0 :     poStmt->Append(pszBaseStatement);
     103             : 
     104           0 :     if (poStmt->ExecuteSQL())
     105           0 :         return OGRERR_NONE;
     106             :     else
     107             :     {
     108           0 :         delete poStmt;
     109           0 :         poStmt = nullptr;
     110           0 :         return OGRERR_FAILURE;
     111             :     }
     112             : }
     113             : 
     114             : /************************************************************************/
     115             : /*                            ResetReading()                            */
     116             : /************************************************************************/
     117             : 
     118           0 : void OGRODBCSelectLayer::ResetReading()
     119             : 
     120             : {
     121           0 :     if (iNextShapeId != 0)
     122           0 :         ClearStatement();
     123             : 
     124           0 :     OGRODBCLayer::ResetReading();
     125           0 : }
     126             : 
     127             : /************************************************************************/
     128             : /*                             GetFeature()                             */
     129             : /************************************************************************/
     130             : 
     131           0 : OGRFeature *OGRODBCSelectLayer::GetFeature(GIntBig nFeatureId)
     132             : 
     133             : {
     134           0 :     return OGRODBCLayer::GetFeature(nFeatureId);
     135             : }
     136             : 
     137             : /************************************************************************/
     138             : /*                           TestCapability()                           */
     139             : /************************************************************************/
     140             : 
     141           0 : int OGRODBCSelectLayer::TestCapability(const char *pszCap)
     142             : 
     143             : {
     144           0 :     return OGRODBCLayer::TestCapability(pszCap);
     145             : }
     146             : 
     147             : /************************************************************************/
     148             : /*                             GetExtent()                              */
     149             : /*                                                                      */
     150             : /*      Since SELECT layers currently cannot ever have geometry, we     */
     151             : /*      can optimize the GetExtent() method!                            */
     152             : /************************************************************************/
     153             : 
     154           0 : OGRErr OGRODBCSelectLayer::GetExtent(OGREnvelope *, int)
     155             : 
     156             : {
     157           0 :     return OGRERR_FAILURE;
     158             : }
     159             : 
     160             : /************************************************************************/
     161             : /*                          GetFeatureCount()                           */
     162             : /*                                                                      */
     163             : /*      If a spatial filter is in effect, we turn control over to       */
     164             : /*      the generic counter.  Otherwise we return the total count.      */
     165             : /*      Eventually we should consider implementing a more efficient     */
     166             : /*      way of counting features matching a spatial query.              */
     167             : /************************************************************************/
     168             : 
     169           0 : GIntBig OGRODBCSelectLayer::GetFeatureCount(int bForce)
     170             : 
     171             : {
     172           0 :     return OGRODBCLayer::GetFeatureCount(bForce);
     173             : }

Generated by: LCOV version 1.14