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-11-21 22:18:42 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             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #include "ogr_mssqlspatial.h"
      14             : #include "cpl_conv.h"
      15             : #include "ogrmssqlspatialdrivercore.h"
      16             : 
      17             : /************************************************************************/
      18             : /*                                Open()                                */
      19             : /************************************************************************/
      20             : 
      21           1 : static GDALDataset *OGRMSSQLSpatialDriverOpen(GDALOpenInfo *poOpenInfo)
      22             : 
      23             : {
      24           1 :     const char *pszFilename = poOpenInfo->pszFilename;
      25           1 :     const bool bUpdate = (poOpenInfo->nOpenFlags & GDAL_OF_UPDATE) != 0;
      26             :     OGRMSSQLSpatialDataSource *poDS;
      27             : 
      28           1 :     if (!OGRMSSQLSPATIALDriverIdentify(poOpenInfo))
      29           0 :         return nullptr;
      30             : 
      31           1 :     poDS = new OGRMSSQLSpatialDataSource();
      32             : 
      33           1 :     if (!poDS->Open(pszFilename, bUpdate, TRUE))
      34             :     {
      35           1 :         delete poDS;
      36           1 :         return nullptr;
      37             :     }
      38             :     else
      39           0 :         return poDS;
      40             : }
      41             : 
      42             : /************************************************************************/
      43             : /*                          CreateDataSource()                          */
      44             : /************************************************************************/
      45             : 
      46           0 : static GDALDataset *OGRMSSQLSpatialDriverCreateDataSource(
      47             :     const char *pszName, CPL_UNUSED int nBands, CPL_UNUSED int nXSize,
      48             :     CPL_UNUSED int nYSize, CPL_UNUSED GDALDataType eDT,
      49             :     CPL_UNUSED char **papszOptions)
      50             : {
      51           0 :     if (!STARTS_WITH_CI(pszName, "MSSQL:"))
      52           0 :         return nullptr;
      53             : 
      54           0 :     OGRMSSQLSpatialDataSource *poDS = new OGRMSSQLSpatialDataSource();
      55           0 :     if (!poDS->Open(pszName, TRUE, TRUE))
      56             :     {
      57           0 :         delete poDS;
      58           0 :         CPLError(CE_Failure, CPLE_AppDefined,
      59             :                  "MSSQL Spatial driver doesn't currently support database "
      60             :                  "creation.\n"
      61             :                  "Please create database with the Microsoft SQL Server Client "
      62             :                  "Tools.");
      63           0 :         return nullptr;
      64             :     }
      65             : 
      66           0 :     return poDS;
      67             : }
      68             : 
      69             : /************************************************************************/
      70             : /*                           RegisterOGRMSSQLSpatial()                  */
      71             : /************************************************************************/
      72             : 
      73           9 : void RegisterOGRMSSQLSpatial()
      74             : 
      75             : {
      76           9 :     if (!GDAL_CHECK_VERSION("OGR/MSSQLSpatial driver"))
      77           0 :         return;
      78             : 
      79           9 :     if (GDALGetDriverByName(DRIVER_NAME) != nullptr)
      80           0 :         return;
      81             : 
      82           9 :     GDALDriver *poDriver = new GDALDriver();
      83           9 :     OGRMSSQLSPATIALDriverSetCommonMetadata(poDriver);
      84             : 
      85           9 :     poDriver->pfnOpen = OGRMSSQLSpatialDriverOpen;
      86           9 :     poDriver->pfnCreate = OGRMSSQLSpatialDriverCreateDataSource;
      87             : 
      88           9 :     GetGDALDriverManager()->RegisterDriver(poDriver);
      89             : }

Generated by: LCOV version 1.14