LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/pg - ogrpgdriver.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 19 25 76.0 %
Date: 2024-11-21 22:18:42 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  OpenGIS Simple Features Reference Implementation
       4             :  * Purpose:  Implements OGRPGDriver class.
       5             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2000, Frank Warmerdam
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #include "ogr_pg.h"
      14             : #include "cpl_conv.h"
      15             : 
      16             : #include "ogrpgdrivercore.h"
      17             : 
      18             : /************************************************************************/
      19             : /*                                Open()                                */
      20             : /************************************************************************/
      21             : 
      22         417 : static GDALDataset *OGRPGDriverOpen(GDALOpenInfo *poOpenInfo)
      23             : 
      24             : {
      25         417 :     if (!OGRPGDriverIdentify(poOpenInfo))
      26           0 :         return nullptr;
      27             : 
      28         417 :     OGRPGDataSource *poDS = new OGRPGDataSource();
      29             : 
      30         417 :     if (!poDS->Open(poOpenInfo->pszFilename, poOpenInfo->eAccess == GA_Update,
      31             :                     TRUE, poOpenInfo->papszOpenOptions))
      32             :     {
      33           5 :         delete poDS;
      34           5 :         return nullptr;
      35             :     }
      36             :     else
      37         412 :         return poDS;
      38             : }
      39             : 
      40             : /************************************************************************/
      41             : /*                          CreateDataSource()                          */
      42             : /************************************************************************/
      43             : 
      44             : static GDALDataset *
      45           2 : OGRPGDriverCreate(const char *pszName, CPL_UNUSED int nBands,
      46             :                   CPL_UNUSED int nXSize, CPL_UNUSED int nYSize,
      47             :                   CPL_UNUSED GDALDataType eDT, char **papszOptions)
      48             : 
      49             : {
      50           2 :     OGRPGDataSource *poDS = new OGRPGDataSource();
      51             : 
      52           2 :     if (!poDS->Open(pszName, TRUE, TRUE, papszOptions))
      53             :     {
      54           0 :         delete poDS;
      55           0 :         CPLError(
      56             :             CE_Failure, CPLE_AppDefined,
      57             :             "PostgreSQL driver doesn't currently support database creation.\n"
      58             :             "Please create database with the `createdb' command.");
      59           0 :         return nullptr;
      60             :     }
      61             : 
      62           2 :     return poDS;
      63             : }
      64             : 
      65             : /************************************************************************/
      66             : /*                           RegisterOGRPG()                            */
      67             : /************************************************************************/
      68             : 
      69          27 : void RegisterOGRPG()
      70             : 
      71             : {
      72          27 :     if (!GDAL_CHECK_VERSION("PG driver"))
      73           0 :         return;
      74             : 
      75          27 :     if (GDALGetDriverByName(DRIVER_NAME) != nullptr)
      76           0 :         return;
      77             : 
      78          27 :     GDALDriver *poDriver = new GDALDriver();
      79          27 :     OGRPGDriverSetCommonMetadata(poDriver);
      80          27 :     poDriver->pfnOpen = OGRPGDriverOpen;
      81          27 :     poDriver->pfnCreate = OGRPGDriverCreate;
      82             : 
      83          27 :     GetGDALDriverManager()->RegisterDriver(poDriver);
      84             : }

Generated by: LCOV version 1.14