LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/adbc - ogradbcdrivercore.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 41 42 97.6 %
Date: 2024-11-21 22:18:42 Functions: 11 11 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL
       4             :  * Purpose:  Arrow Database Connectivity driver
       5             :  * Author:   Even Rouault, <even dot rouault at spatialys.com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2024, Even Rouault <even dot rouault at spatialys.com>
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #include "ogrsf_frmts.h"
      14             : #include "ogradbcdrivercore.h"
      15             : #include "gdal_adbc.h"
      16             : 
      17             : /************************************************************************/
      18             : /*                             IsDuckDB()                               */
      19             : /************************************************************************/
      20             : 
      21       42755 : bool OGRADBCDriverIsDuckDB(const GDALOpenInfo *poOpenInfo)
      22             : {
      23       43377 :     return poOpenInfo->nHeaderBytes >= 20 &&
      24         622 :            memcmp(poOpenInfo->pabyHeader + 8, "DUCK\x40\0\0\0\0\0\0\0",
      25       42755 :                   4 + 8) == 0;
      26             : }
      27             : 
      28             : /************************************************************************/
      29             : /*                             IsSQLite3()                              */
      30             : /************************************************************************/
      31             : 
      32       42755 : bool OGRADBCDriverIsSQLite3(const GDALOpenInfo *poOpenInfo)
      33             : {
      34       42755 :     constexpr const char *SQLITE3_SIGNATURE = "SQLite format 3";
      35       43097 :     return poOpenInfo->nHeaderBytes >= 512 &&
      36         342 :            memcmp(poOpenInfo->pabyHeader, SQLITE3_SIGNATURE,
      37       42755 :                   strlen(SQLITE3_SIGNATURE)) == 0;
      38             : }
      39             : 
      40             : /************************************************************************/
      41             : /*                             IsParquet()                              */
      42             : /************************************************************************/
      43             : 
      44       42716 : bool OGRADBCDriverIsParquet(const GDALOpenInfo *poOpenInfo)
      45             : {
      46       42716 :     constexpr const char *PARQUET_SIGNATURE = "PAR1";
      47       42716 :     return poOpenInfo->nHeaderBytes >=
      48       43354 :                static_cast<int>(strlen(PARQUET_SIGNATURE)) &&
      49         638 :            memcmp(poOpenInfo->pabyHeader, PARQUET_SIGNATURE,
      50       42716 :                   strlen(PARQUET_SIGNATURE)) == 0;
      51             : }
      52             : 
      53             : /************************************************************************/
      54             : /*                    OGRADBCDriverIdentify()                           */
      55             : /************************************************************************/
      56             : 
      57       42755 : int OGRADBCDriverIdentify(GDALOpenInfo *poOpenInfo)
      58             : {
      59      128265 :     return STARTS_WITH(poOpenInfo->pszFilename, "ADBC:") ||
      60       85510 :            ((OGRADBCDriverIsDuckDB(poOpenInfo) ||
      61       85471 :              OGRADBCDriverIsSQLite3(poOpenInfo) ||
      62       42716 :              OGRADBCDriverIsParquet(poOpenInfo))
      63             : #ifndef OGR_ADBC_HAS_DRIVER_MANAGER
      64          39 :             && GDALGetAdbcLoadDriverOverride() != nullptr
      65             : #endif
      66           0 :             && !STARTS_WITH(poOpenInfo->pszFilename, "/vsi") &&
      67       42755 :             !EQUAL(CPLGetExtension(poOpenInfo->pszFilename), "mbtiles"));
      68             : }
      69             : 
      70             : /************************************************************************/
      71             : /*                  OGRADBCDriverSetCommonMetadata()                    */
      72             : /************************************************************************/
      73             : 
      74        1302 : void OGRADBCDriverSetCommonMetadata(GDALDriver *poDriver)
      75             : {
      76        1302 :     poDriver->SetDescription(DRIVER_NAME);
      77        1302 :     poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES");
      78        1302 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "Arrow Database Connectivity");
      79        1302 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/adbc.html");
      80             : 
      81        1302 :     poDriver->SetMetadataItem(GDAL_DMD_CONNECTION_PREFIX, "ADBC:");
      82             : 
      83        1302 :     poDriver->SetMetadataItem(
      84             :         GDAL_DMD_OPENOPTIONLIST,
      85             :         "<OpenOptionList>"
      86             :         "  <Option name='ADBC_DRIVER' type='string' description='ADBC driver "
      87             :         "name'/>"
      88             :         "  <Option name='SQL' type='string' "
      89             :         "description='SQL statement from which to build layer'/>"
      90             :         "  <Option name='ADBC_OPTION_*' type='string' "
      91             :         "description='Option to pass to AdbcDatabaseSetOption()'/>"
      92             :         "  <Option name='PRELUDE_STATEMENTS' type='string' description='SQL "
      93             :         "statement(s) to send on the database connection before any other "
      94             :         "ones'/>"
      95        1302 :         "</OpenOptionList>");
      96        1302 :     poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS,
      97        1302 :                               "NATIVE OGRSQL SQLITE");
      98             : #ifdef OGR_ADBC_HAS_DRIVER_MANAGER
      99             :     poDriver->SetMetadataItem("HAS_ADBC_DRIVER_MANAGER", "YES");
     100             : #endif
     101             : 
     102        1302 :     poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES");
     103        1302 :     poDriver->pfnIdentify = OGRADBCDriverIdentify;
     104        1302 : }
     105             : 
     106             : /************************************************************************/
     107             : /*                   DeclareDeferredOGRADBCPlugin()                     */
     108             : /************************************************************************/
     109             : 
     110             : #ifdef PLUGIN_FILENAME
     111        1595 : void DeclareDeferredOGRADBCPlugin()
     112             : {
     113        1595 :     if (GDALGetDriverByName(DRIVER_NAME) != nullptr)
     114             :     {
     115         302 :         return;
     116             :     }
     117        1293 :     auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME);
     118             : #ifdef PLUGIN_INSTALLATION_MESSAGE
     119             :     poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE,
     120             :                               PLUGIN_INSTALLATION_MESSAGE);
     121             : #endif
     122        1293 :     OGRADBCDriverSetCommonMetadata(poDriver);
     123        1293 :     GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver);
     124             : }
     125             : #endif

Generated by: LCOV version 1.14