LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/pg - ogrpgdrivercore.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 57 57 100.0 %
Date: 2025-10-25 23:36:32 Functions: 5 5 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 "gdal_frmts.h"
      14             : #include "gdalplugindriverproxy.h"
      15             : 
      16             : #include "ogrsf_frmts.h"
      17             : 
      18             : #include "ogrpgdrivercore.h"
      19             : 
      20             : /************************************************************************/
      21             : /*                              Identify()                              */
      22             : /************************************************************************/
      23             : 
      24       54705 : int OGRPGDriverIdentify(GDALOpenInfo *poOpenInfo)
      25             : {
      26       54705 :     if (!STARTS_WITH_CI(poOpenInfo->pszFilename, "PGB:") &&
      27       54706 :         !STARTS_WITH_CI(poOpenInfo->pszFilename, "PG:") &&
      28       53848 :         !STARTS_WITH(poOpenInfo->pszFilename, "postgresql://"))
      29       53843 :         return FALSE;
      30         862 :     return TRUE;
      31             : }
      32             : 
      33             : /************************************************************************/
      34             : /*                OGRPGDriverSetCommonMetadata()                        */
      35             : /************************************************************************/
      36             : 
      37        1782 : void OGRPGDriverSetCommonMetadata(GDALDriver *poDriver)
      38             : {
      39        1782 :     poDriver->SetDescription(DRIVER_NAME);
      40             : 
      41        1782 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "PostgreSQL/PostGIS");
      42        1782 :     poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES");
      43        1782 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES");
      44        1782 :     poDriver->SetMetadataItem(GDAL_DCAP_DELETE_LAYER, "YES");
      45        1782 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATE_FIELD, "YES");
      46        1782 :     poDriver->SetMetadataItem(GDAL_DCAP_DELETE_FIELD, "YES");
      47        1782 :     poDriver->SetMetadataItem(GDAL_DCAP_CURVE_GEOMETRIES, "YES");
      48        1782 :     poDriver->SetMetadataItem(GDAL_DCAP_MEASURED_GEOMETRIES, "YES");
      49        1782 :     poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES");
      50        1782 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/pg.html");
      51        1782 :     poDriver->SetMetadataItem(GDAL_DMD_CONNECTION_PREFIX, "PG:");
      52        1782 :     poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS,
      53        1782 :                               "NATIVE OGRSQL SQLITE");
      54             : 
      55        1782 :     poDriver->SetMetadataItem(
      56             :         GDAL_DMD_OPENOPTIONLIST,
      57             :         "<OpenOptionList>"
      58             :         "  <Option name='DBNAME' type='string' description='Database name'/>"
      59             :         "  <Option name='PORT' type='int' description='Port'/>"
      60             :         "  <Option name='USER' type='string' description='User name'/>"
      61             :         "  <Option name='PASSWORD' type='string' description='Password'/>"
      62             :         "  <Option name='HOST' type='string' description='Server hostname'/>"
      63             :         "  <Option name='SERVICE' type='string' description='Service name'/>"
      64             :         "  <Option name='ACTIVE_SCHEMA' type='string' description='Active "
      65             :         "schema'/>"
      66             :         "  <Option name='SCHEMAS' type='string' description='Restricted sets "
      67             :         "of schemas to explore (comma separated)'/>"
      68             :         "  <Option name='TABLES' type='string' description='Restricted set of "
      69             :         "tables to list (comma separated)'/>"
      70             :         "  <Option name='LIST_ALL_TABLES' type='boolean' description='Whether "
      71             :         "all tables, including non-spatial ones, should be listed' "
      72             :         "default='NO'/>"
      73             :         "  <Option name='PRELUDE_STATEMENTS' type='string' description='SQL "
      74             :         "statement(s) to send on the PostgreSQL client connection before any "
      75             :         "other ones'/>"
      76             :         "  <Option name='CLOSING_STATEMENTS' type='string' description='SQL "
      77             :         "statements() to send on the PostgreSQL client connection after any "
      78             :         "other ones'/>"
      79             :         "  <Option name='SKIP_VIEWS' type='boolean' description='Whether "
      80             :         "views should be omitted from the list' "
      81             :         "default='NO'/>"
      82        1782 :         "</OpenOptionList>");
      83             : 
      84        1782 :     poDriver->SetMetadataItem(GDAL_DMD_CREATIONOPTIONLIST,
      85        1782 :                               "<CreationOptionList/>");
      86             : 
      87        1782 :     poDriver->SetMetadataItem(
      88             :         GDAL_DS_LAYER_CREATIONOPTIONLIST,
      89             :         "<LayerCreationOptionList>"
      90             :         "  <Option name='GEOM_TYPE' type='string-select' description='Format "
      91             :         "of geometry columns' default='geometry'>"
      92             :         "    <Value>geometry</Value>"
      93             :         "    <Value>geography</Value>"
      94             :         "    <Value>BYTEA</Value>"
      95             :         "    <Value>OID</Value>"
      96             :         "  </Option>"
      97             :         "  <Option name='OVERWRITE' type='boolean' description='Whether to "
      98             :         "overwrite an existing table with the layer name to be created' "
      99             :         "default='NO'/>"
     100             :         "  <Option name='LAUNDER' type='boolean' description='Whether layer "
     101             :         "and field names will be laundered' default='YES'/>"
     102             :         "  <Option name='LAUNDER_ASCII' type='boolean' description='Same as "
     103             :         "LAUNDER, but force generation of ASCII identifiers' default='NO'/>"
     104             :         "  <Option name='PRECISION' type='boolean' description='Whether fields "
     105             :         "created should keep the width and precision' default='YES'/>"
     106             :         "  <Option name='DIM' type='string' description='Set to 2 to force the "
     107             :         "geometries to be 2D, 3 to be 2.5D, XYM or XYZM'/>"
     108             :         "  <Option name='GEOMETRY_NAME' type='string' description='Name of "
     109             :         "geometry column. Defaults to wkb_geometry for GEOM_TYPE=geometry or "
     110             :         "the_geog for GEOM_TYPE=geography'/>"
     111             :         "  <Option name='SCHEMA' type='string' description='Name of schema "
     112             :         "into which to create the new table'/>"
     113             :         "  <Option name='SPATIAL_INDEX' type='string-select' description='Type "
     114             :         "of spatial index to create' default='GIST'>"
     115             :         "    <Value>NONE</Value>"
     116             :         "    <Value>GIST</Value>"
     117             :         "    <Value>SPGIST</Value>"
     118             :         "    <Value>BRIN</Value>"
     119             :         "  </Option>"
     120             :         "  <Option name='TEMPORARY' type='boolean' description='Whether to a "
     121             :         "temporary table instead of a permanent one' default='NO'/>"
     122             :         "  <Option name='UNLOGGED' type='boolean' description='Whether to "
     123             :         "create the table as a unlogged one' default='NO'/>"
     124             :         "  <Option name='NONE_AS_UNKNOWN' type='boolean' description='Whether "
     125             :         "to force non-spatial layers to be created as spatial tables' "
     126             :         "default='NO'/>"
     127             :         "  <Option name='FID' type='string' description='Name of the FID "
     128             :         "column to create' default='ogc_fid'/>"
     129             :         "  <Option name='FID64' type='boolean' description='Whether to create "
     130             :         "the FID column with BIGSERIAL type to handle 64bit wide ids' "
     131             :         "default='NO'/>"
     132             :         "  <Option name='EXTRACT_SCHEMA_FROM_LAYER_NAME' type='boolean' "
     133             :         "description='Whether a dot in a layer name should be considered as "
     134             :         "the separator for the schema and table name' default='YES'/>"
     135             :         "  <Option name='COLUMN_TYPES' type='string' description='A list of "
     136             :         "strings of format field_name=pg_field_type (separated by comma) to "
     137             :         "force the PG column type of fields to be created'/>"
     138             :         "  <Option name='DESCRIPTION' type='string' description='Description "
     139             :         "string to put in the pg_description system table'/>"
     140        1782 :         "</LayerCreationOptionList>");
     141             : 
     142        1782 :     poDriver->SetMetadataItem(GDAL_DMD_CREATIONFIELDDATATYPES,
     143             :                               "Integer Integer64 Real String Date DateTime "
     144             :                               "Time IntegerList Integer64List RealList "
     145        1782 :                               "StringList Binary");
     146        1782 :     poDriver->SetMetadataItem(GDAL_DMD_CREATIONFIELDDATASUBTYPES,
     147        1782 :                               "Boolean Int16 Float32");
     148        1782 :     poDriver->SetMetadataItem(GDAL_DMD_CREATION_FIELD_DEFN_FLAGS,
     149        1782 :                               "WidthPrecision Nullable Unique Default Comment");
     150             : 
     151        1782 :     poDriver->SetMetadataItem(
     152             :         GDAL_DMD_ALTER_FIELD_DEFN_FLAGS,
     153        1782 :         "Name Type WidthPrecision Nullable Default Unique Comment");
     154        1782 :     poDriver->SetMetadataItem(GDAL_DCAP_NOTNULL_FIELDS, "YES");
     155        1782 :     poDriver->SetMetadataItem(GDAL_DCAP_DEFAULT_FIELDS, "YES");
     156        1782 :     poDriver->SetMetadataItem(GDAL_DCAP_UNIQUE_FIELDS, "YES");
     157        1782 :     poDriver->SetMetadataItem(GDAL_DCAP_NOTNULL_GEOMFIELDS, "YES");
     158        1782 :     poDriver->SetMetadataItem(GDAL_DCAP_MULTIPLE_VECTOR_LAYERS, "YES");
     159        1782 :     poDriver->SetMetadataItem(GDAL_DCAP_RENAME_LAYERS, "YES");
     160             : 
     161        1782 :     poDriver->SetMetadataItem(GDAL_DMD_ALTER_GEOM_FIELD_DEFN_FLAGS,
     162        1782 :                               "Name Type Nullable SRS");
     163             :     // see https://www.postgresql.org/docs/current/ddl-system-columns.html
     164        1782 :     poDriver->SetMetadataItem(GDAL_DMD_ILLEGAL_FIELD_NAMES,
     165        1782 :                               "tableoid xmin cmin xmax cmax ctid");
     166             : 
     167        1782 :     poDriver->pfnIdentify = OGRPGDriverIdentify;
     168        1782 :     poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES");
     169        1782 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATE, "YES");
     170             : 
     171        1782 :     poDriver->SetMetadataItem(GDAL_DCAP_UPDATE, "YES");
     172        1782 :     poDriver->SetMetadataItem(GDAL_DMD_UPDATE_ITEMS, "LayerMetadata Features");
     173        1782 : }
     174             : 
     175             : /************************************************************************/
     176             : /*                   DeclareDeferredOGRPGPlugin()                       */
     177             : /************************************************************************/
     178             : 
     179             : #ifdef PLUGIN_FILENAME
     180        2038 : void DeclareDeferredOGRPGPlugin()
     181             : {
     182        2038 :     if (GDALGetDriverByName(DRIVER_NAME) != nullptr)
     183             :     {
     184         283 :         return;
     185             :     }
     186        1755 :     auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME);
     187             : #ifdef PLUGIN_INSTALLATION_MESSAGE
     188             :     poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE,
     189             :                               PLUGIN_INSTALLATION_MESSAGE);
     190             : #endif
     191        1755 :     OGRPGDriverSetCommonMetadata(poDriver);
     192        1755 :     GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver);
     193             : }
     194             : #endif

Generated by: LCOV version 1.14