LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/odbc - ogrodbcdrivercore.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 33 36 91.7 %
Date: 2024-11-21 22:18:42 Functions: 7 7 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  OpenGIS Simple Features Reference Implementation
       4             :  * Purpose:  Implements OGRODBCDriver class.
       5             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2003, Frank Warmerdam <warmerdam@pobox.com>
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #include "ogrsf_frmts.h"
      14             : 
      15             : #include "ogrodbcdrivercore.h"
      16             : 
      17             : /************************************************************************/
      18             : /*                OGRODBCDriverIsSupportedMsAccessFileExtension()       */
      19             : /************************************************************************/
      20             : 
      21       46302 : bool OGRODBCDriverIsSupportedMsAccessFileExtension(const char *pszExtension)
      22             : {
      23             :     // these are all possible extensions for MS Access databases
      24       92602 :     return EQUAL(pszExtension, "MDB") || EQUAL(pszExtension, "ACCDB") ||
      25       92602 :            EQUAL(pszExtension, "STYLE");
      26             : }
      27             : 
      28             : /************************************************************************/
      29             : /*                    OGRODBCDriverIdentify()                           */
      30             : /************************************************************************/
      31             : 
      32       46305 : int OGRODBCDriverIdentify(GDALOpenInfo *poOpenInfo)
      33             : 
      34             : {
      35       46305 :     if (STARTS_WITH_CI(poOpenInfo->pszFilename, "PGEO:"))
      36             :     {
      37           0 :         return FALSE;
      38             :     }
      39             : 
      40       46305 :     if (STARTS_WITH_CI(poOpenInfo->pszFilename, "ODBC:"))
      41           0 :         return TRUE;
      42             : 
      43       46305 :     const char *psExtension(CPLGetExtension(poOpenInfo->pszFilename));
      44       46305 :     if (EQUAL(psExtension, "mdb"))
      45           5 :         return -1;  // Could potentially be a PGeo MDB database
      46             : 
      47       46300 :     if (OGRODBCDriverIsSupportedMsAccessFileExtension(psExtension))
      48           0 :         return TRUE;  // An Access database which isn't a .MDB file (we checked
      49             :                       // that above), so this is the only candidate driver
      50             : 
      51             :     // doesn't start with "ODBC:", and isn't an access database => not supported
      52       46300 :     return FALSE;
      53             : }
      54             : 
      55             : /************************************************************************/
      56             : /*                  OGRODBCDriverSetCommonMetadata()                    */
      57             : /************************************************************************/
      58             : 
      59        1302 : void OGRODBCDriverSetCommonMetadata(GDALDriver *poDriver)
      60             : {
      61        1302 :     poDriver->SetDescription(DRIVER_NAME);
      62        1302 :     poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES");
      63        1302 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME,
      64        1302 :                               "Open Database Connectivity (ODBC)");
      65        1302 :     poDriver->SetMetadataItem(GDAL_DMD_CONNECTION_PREFIX, "ODBC:");
      66        1302 :     poDriver->SetMetadataItem(GDAL_DMD_EXTENSIONS, "mdb accdb");
      67        1302 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/odbc.html");
      68        1302 :     poDriver->SetMetadataItem(GDAL_DCAP_MULTIPLE_VECTOR_LAYERS, "YES");
      69        1302 :     poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS,
      70        1302 :                               "NATIVE OGRSQL SQLITE");
      71             : 
      72        1302 :     poDriver->SetMetadataItem(
      73             :         GDAL_DMD_OPENOPTIONLIST,
      74             :         "<OpenOptionList>"
      75             :         "  <Option name='LIST_ALL_TABLES' type='string-select' scope='vector' "
      76             :         "description='Whether all tables, including system and internal tables "
      77             :         "(such as MSys* tables) should be listed' default='NO'>"
      78             :         "    <Value>YES</Value>"
      79             :         "    <Value>NO</Value>"
      80             :         "  </Option>"
      81        1302 :         "</OpenOptionList>");
      82             : 
      83        1302 :     poDriver->pfnIdentify = OGRODBCDriverIdentify;
      84        1302 :     poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES");
      85        1302 : }
      86             : 
      87             : /************************************************************************/
      88             : /*                   DeclareDeferredOGRODBCPlugin()                     */
      89             : /************************************************************************/
      90             : 
      91             : #ifdef PLUGIN_FILENAME
      92        1595 : void DeclareDeferredOGRODBCPlugin()
      93             : {
      94        1595 :     if (GDALGetDriverByName(DRIVER_NAME) != nullptr)
      95             :     {
      96         302 :         return;
      97             :     }
      98        1293 :     auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME);
      99             : #ifdef PLUGIN_INSTALLATION_MESSAGE
     100             :     poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE,
     101             :                               PLUGIN_INSTALLATION_MESSAGE);
     102             : #endif
     103        1293 :     OGRODBCDriverSetCommonMetadata(poDriver);
     104        1293 :     GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver);
     105             : }
     106             : #endif

Generated by: LCOV version 1.14