LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/odbc - ogrodbcdrivercore.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 31 34 91.2 %
Date: 2024-05-03 15:49:35 Functions: 4 4 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             :  * 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 "ogrsf_frmts.h"
      30             : 
      31             : #include "ogrodbcdrivercore.h"
      32             : 
      33             : /************************************************************************/
      34             : /*                OGRODBCDriverIsSupportedMsAccessFileExtension()       */
      35             : /************************************************************************/
      36             : 
      37       43221 : bool OGRODBCDriverIsSupportedMsAccessFileExtension(const char *pszExtension)
      38             : {
      39             :     // these are all possible extensions for MS Access databases
      40       86441 :     return EQUAL(pszExtension, "MDB") || EQUAL(pszExtension, "ACCDB") ||
      41       86441 :            EQUAL(pszExtension, "STYLE");
      42             : }
      43             : 
      44             : /************************************************************************/
      45             : /*                    OGRODBCDriverIdentify()                           */
      46             : /************************************************************************/
      47             : 
      48       43225 : int OGRODBCDriverIdentify(GDALOpenInfo *poOpenInfo)
      49             : 
      50             : {
      51       43225 :     if (STARTS_WITH_CI(poOpenInfo->pszFilename, "PGEO:"))
      52             :     {
      53           0 :         return FALSE;
      54             :     }
      55             : 
      56       43225 :     if (STARTS_WITH_CI(poOpenInfo->pszFilename, "ODBC:"))
      57           0 :         return TRUE;
      58             : 
      59       43225 :     const char *psExtension(CPLGetExtension(poOpenInfo->pszFilename));
      60       43225 :     if (EQUAL(psExtension, "mdb"))
      61           5 :         return -1;  // Could potentially be a PGeo MDB database
      62             : 
      63       43220 :     if (OGRODBCDriverIsSupportedMsAccessFileExtension(psExtension))
      64           0 :         return TRUE;  // An Access database which isn't a .MDB file (we checked
      65             :                       // that above), so this is the only candidate driver
      66             : 
      67             :     // doesn't start with "ODBC:", and isn't an access database => not supported
      68       43220 :     return FALSE;
      69             : }
      70             : 
      71             : /************************************************************************/
      72             : /*                  OGRODBCDriverSetCommonMetadata()                    */
      73             : /************************************************************************/
      74             : 
      75        1223 : void OGRODBCDriverSetCommonMetadata(GDALDriver *poDriver)
      76             : {
      77        1223 :     poDriver->SetDescription(DRIVER_NAME);
      78        1223 :     poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES");
      79        1223 :     poDriver->SetMetadataItem(GDAL_DMD_CONNECTION_PREFIX, "ODBC:");
      80        1223 :     poDriver->SetMetadataItem(GDAL_DMD_EXTENSIONS, "mdb accdb");
      81        1223 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/odbc.html");
      82        1223 :     poDriver->SetMetadataItem(GDAL_DCAP_MULTIPLE_VECTOR_LAYERS, "YES");
      83        1223 :     poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS,
      84        1223 :                               "NATIVE OGRSQL SQLITE");
      85             : 
      86        1223 :     poDriver->SetMetadataItem(
      87             :         GDAL_DMD_OPENOPTIONLIST,
      88             :         "<OpenOptionList>"
      89             :         "  <Option name='LIST_ALL_TABLES' type='string-select' scope='vector' "
      90             :         "description='Whether all tables, including system and internal tables "
      91             :         "(such as MSys* tables) should be listed' default='NO'>"
      92             :         "    <Value>YES</Value>"
      93             :         "    <Value>NO</Value>"
      94             :         "  </Option>"
      95        1223 :         "</OpenOptionList>");
      96             : 
      97        1223 :     poDriver->pfnIdentify = OGRODBCDriverIdentify;
      98        1223 :     poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES");
      99        1223 : }
     100             : 
     101             : /************************************************************************/
     102             : /*                   DeclareDeferredOGRODBCPlugin()                     */
     103             : /************************************************************************/
     104             : 
     105             : #ifdef PLUGIN_FILENAME
     106        1511 : void DeclareDeferredOGRODBCPlugin()
     107             : {
     108        1511 :     if (GDALGetDriverByName(DRIVER_NAME) != nullptr)
     109             :     {
     110         295 :         return;
     111             :     }
     112        1216 :     auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME);
     113             : #ifdef PLUGIN_INSTALLATION_MESSAGE
     114             :     poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE,
     115             :                               PLUGIN_INSTALLATION_MESSAGE);
     116             : #endif
     117        1216 :     OGRODBCDriverSetCommonMetadata(poDriver);
     118        1216 :     GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver);
     119             : }
     120             : #endif

Generated by: LCOV version 1.14