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

Generated by: LCOV version 1.14