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

Generated by: LCOV version 1.14