LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/mssqlspatial - ogrmssqlspatialdriver.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 16 29 55.2 %
Date: 2024-05-04 12:52:34 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  MSSQL Spatial driver
       4             :  * Purpose:  Definition of classes for OGR MSSQL Spatial driver.
       5             :  * Author:   Tamas Szekeres, szekerest at gmail.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2010, Tamas Szekeres
       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_mssqlspatial.h"
      30             : #include "cpl_conv.h"
      31             : #include "ogrmssqlspatialdrivercore.h"
      32             : 
      33             : /************************************************************************/
      34             : /*                                Open()                                */
      35             : /************************************************************************/
      36             : 
      37           1 : static GDALDataset *OGRMSSQLSpatialDriverOpen(GDALOpenInfo *poOpenInfo)
      38             : 
      39             : {
      40           1 :     const char *pszFilename = poOpenInfo->pszFilename;
      41           1 :     const bool bUpdate = (poOpenInfo->nOpenFlags & GDAL_OF_UPDATE) != 0;
      42             :     OGRMSSQLSpatialDataSource *poDS;
      43             : 
      44           1 :     if (!OGRMSSQLSPATIALDriverIdentify(poOpenInfo))
      45           0 :         return nullptr;
      46             : 
      47           1 :     poDS = new OGRMSSQLSpatialDataSource();
      48             : 
      49           1 :     if (!poDS->Open(pszFilename, bUpdate, TRUE))
      50             :     {
      51           1 :         delete poDS;
      52           1 :         return nullptr;
      53             :     }
      54             :     else
      55           0 :         return poDS;
      56             : }
      57             : 
      58             : /************************************************************************/
      59             : /*                          CreateDataSource()                          */
      60             : /************************************************************************/
      61             : 
      62           0 : static GDALDataset *OGRMSSQLSpatialDriverCreateDataSource(
      63             :     const char *pszName, CPL_UNUSED int nBands, CPL_UNUSED int nXSize,
      64             :     CPL_UNUSED int nYSize, CPL_UNUSED GDALDataType eDT,
      65             :     CPL_UNUSED char **papszOptions)
      66             : {
      67           0 :     if (!STARTS_WITH_CI(pszName, "MSSQL:"))
      68           0 :         return nullptr;
      69             : 
      70           0 :     OGRMSSQLSpatialDataSource *poDS = new OGRMSSQLSpatialDataSource();
      71           0 :     if (!poDS->Open(pszName, TRUE, TRUE))
      72             :     {
      73           0 :         delete poDS;
      74           0 :         CPLError(CE_Failure, CPLE_AppDefined,
      75             :                  "MSSQL Spatial driver doesn't currently support database "
      76             :                  "creation.\n"
      77             :                  "Please create database with the Microsoft SQL Server Client "
      78             :                  "Tools.");
      79           0 :         return nullptr;
      80             :     }
      81             : 
      82           0 :     return poDS;
      83             : }
      84             : 
      85             : /************************************************************************/
      86             : /*                           RegisterOGRMSSQLSpatial()                  */
      87             : /************************************************************************/
      88             : 
      89           7 : void RegisterOGRMSSQLSpatial()
      90             : 
      91             : {
      92           7 :     if (!GDAL_CHECK_VERSION("OGR/MSSQLSpatial driver"))
      93           0 :         return;
      94             : 
      95           7 :     if (GDALGetDriverByName(DRIVER_NAME) != nullptr)
      96           0 :         return;
      97             : 
      98           7 :     GDALDriver *poDriver = new GDALDriver();
      99           7 :     OGRMSSQLSPATIALDriverSetCommonMetadata(poDriver);
     100             : 
     101           7 :     poDriver->pfnOpen = OGRMSSQLSpatialDriverOpen;
     102           7 :     poDriver->pfnCreate = OGRMSSQLSpatialDriverCreateDataSource;
     103             : 
     104           7 :     GetGDALDriverManager()->RegisterDriver(poDriver);
     105             : }

Generated by: LCOV version 1.14