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 56411 : int OGRPGDriverIdentify(GDALOpenInfo *poOpenInfo) 25 : { 26 56411 : if (!STARTS_WITH_CI(poOpenInfo->pszFilename, "PGB:") && 27 56411 : !STARTS_WITH_CI(poOpenInfo->pszFilename, "PG:") && 28 55521 : !STARTS_WITH(poOpenInfo->pszFilename, "postgresql://")) 29 55517 : return FALSE; 30 894 : return TRUE; 31 : } 32 : 33 : /************************************************************************/ 34 : /* OGRPGDriverSetCommonMetadata() */ 35 : /************************************************************************/ 36 : 37 1803 : void OGRPGDriverSetCommonMetadata(GDALDriver *poDriver) 38 : { 39 1803 : poDriver->SetDescription(DRIVER_NAME); 40 : 41 1803 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "PostgreSQL/PostGIS"); 42 1803 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); 43 1803 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES"); 44 1803 : poDriver->SetMetadataItem(GDAL_DCAP_DELETE_LAYER, "YES"); 45 1803 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_FIELD, "YES"); 46 1803 : poDriver->SetMetadataItem(GDAL_DCAP_DELETE_FIELD, "YES"); 47 1803 : poDriver->SetMetadataItem(GDAL_DCAP_CURVE_GEOMETRIES, "YES"); 48 1803 : poDriver->SetMetadataItem(GDAL_DCAP_MEASURED_GEOMETRIES, "YES"); 49 1803 : poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES"); 50 1803 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/pg.html"); 51 1803 : poDriver->SetMetadataItem(GDAL_DMD_CONNECTION_PREFIX, "PG:"); 52 1803 : poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, 53 1803 : "NATIVE OGRSQL SQLITE"); 54 : 55 1803 : 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 : " <Option name='SPATIAL_FILTER_INTERSECTION' type='string-select' " 83 : "description='Whether geometry intersection of spatial filter is " 84 : "evaluated locally or on the server' default='LOCAL'>" 85 : " <Value>LOCAL</Value>" 86 : " <Value>DATABASE</Value>" 87 : " </Option>" 88 1803 : "</OpenOptionList>"); 89 : 90 1803 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONOPTIONLIST, 91 1803 : "<CreationOptionList/>"); 92 : 93 1803 : poDriver->SetMetadataItem( 94 : GDAL_DS_LAYER_CREATIONOPTIONLIST, 95 : "<LayerCreationOptionList>" 96 : " <Option name='GEOM_TYPE' type='string-select' description='Format " 97 : "of geometry columns' default='geometry'>" 98 : " <Value>geometry</Value>" 99 : " <Value>geography</Value>" 100 : " <Value>BYTEA</Value>" 101 : " <Value>OID</Value>" 102 : " </Option>" 103 : " <Option name='OVERWRITE' type='boolean' description='Whether to " 104 : "overwrite an existing table with the layer name to be created' " 105 : "default='NO'/>" 106 : " <Option name='LAUNDER' type='boolean' description='Whether layer " 107 : "and field names will be laundered' default='YES'/>" 108 : " <Option name='LAUNDER_ASCII' type='boolean' description='Same as " 109 : "LAUNDER, but force generation of ASCII identifiers' default='NO'/>" 110 : " <Option name='PRECISION' type='boolean' description='Whether fields " 111 : "created should keep the width and precision' default='YES'/>" 112 : " <Option name='DIM' type='string' description='Set to 2 to force the " 113 : "geometries to be 2D, 3 to be 2.5D, XYM or XYZM'/>" 114 : " <Option name='GEOMETRY_NAME' type='string' description='Name of " 115 : "geometry column. Defaults to wkb_geometry for GEOM_TYPE=geometry or " 116 : "the_geog for GEOM_TYPE=geography'/>" 117 : " <Option name='SCHEMA' type='string' description='Name of schema " 118 : "into which to create the new table'/>" 119 : " <Option name='SPATIAL_INDEX' type='string-select' description='Type " 120 : "of spatial index to create' default='GIST'>" 121 : " <Value>NONE</Value>" 122 : " <Value>GIST</Value>" 123 : " <Value>SPGIST</Value>" 124 : " <Value>BRIN</Value>" 125 : " </Option>" 126 : " <Option name='TEMPORARY' type='boolean' description='Whether to a " 127 : "temporary table instead of a permanent one' default='NO'/>" 128 : " <Option name='UNLOGGED' type='boolean' description='Whether to " 129 : "create the table as a unlogged one' default='NO'/>" 130 : " <Option name='NONE_AS_UNKNOWN' type='boolean' description='Whether " 131 : "to force non-spatial layers to be created as spatial tables' " 132 : "default='NO'/>" 133 : " <Option name='FID' type='string' description='Name of the FID " 134 : "column to create' default='ogc_fid'/>" 135 : " <Option name='FID64' type='boolean' description='Whether to create " 136 : "the FID column with BIGSERIAL type to handle 64bit wide ids' " 137 : "default='NO'/>" 138 : " <Option name='EXTRACT_SCHEMA_FROM_LAYER_NAME' type='boolean' " 139 : "description='Whether a dot in a layer name should be considered as " 140 : "the separator for the schema and table name' default='YES'/>" 141 : " <Option name='COLUMN_TYPES' type='string' description='A list of " 142 : "strings of format field_name=pg_field_type (separated by comma) to " 143 : "force the PG column type of fields to be created'/>" 144 : " <Option name='DESCRIPTION' type='string' description='Description " 145 : "string to put in the pg_description system table'/>" 146 1803 : "</LayerCreationOptionList>"); 147 : 148 1803 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONFIELDDATATYPES, 149 : "Integer Integer64 Real String Date DateTime " 150 : "Time IntegerList Integer64List RealList " 151 1803 : "StringList Binary"); 152 1803 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONFIELDDATASUBTYPES, 153 1803 : "Boolean Int16 Float32"); 154 1803 : poDriver->SetMetadataItem(GDAL_DMD_CREATION_FIELD_DEFN_FLAGS, 155 1803 : "WidthPrecision Nullable Unique Default Comment"); 156 : 157 1803 : poDriver->SetMetadataItem( 158 : GDAL_DMD_ALTER_FIELD_DEFN_FLAGS, 159 1803 : "Name Type WidthPrecision Nullable Default Unique Comment"); 160 1803 : poDriver->SetMetadataItem(GDAL_DCAP_NOTNULL_FIELDS, "YES"); 161 1803 : poDriver->SetMetadataItem(GDAL_DCAP_DEFAULT_FIELDS, "YES"); 162 1803 : poDriver->SetMetadataItem(GDAL_DCAP_UNIQUE_FIELDS, "YES"); 163 1803 : poDriver->SetMetadataItem(GDAL_DCAP_NOTNULL_GEOMFIELDS, "YES"); 164 1803 : poDriver->SetMetadataItem(GDAL_DCAP_MULTIPLE_VECTOR_LAYERS, "YES"); 165 1803 : poDriver->SetMetadataItem(GDAL_DCAP_RENAME_LAYERS, "YES"); 166 : 167 1803 : poDriver->SetMetadataItem(GDAL_DMD_ALTER_GEOM_FIELD_DEFN_FLAGS, 168 1803 : "Name Type Nullable SRS"); 169 : // see https://www.postgresql.org/docs/current/ddl-system-columns.html 170 1803 : poDriver->SetMetadataItem(GDAL_DMD_ILLEGAL_FIELD_NAMES, 171 1803 : "tableoid xmin cmin xmax cmax ctid"); 172 : 173 1803 : poDriver->pfnIdentify = OGRPGDriverIdentify; 174 1803 : poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); 175 1803 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE, "YES"); 176 : 177 1803 : poDriver->SetMetadataItem(GDAL_DCAP_UPDATE, "YES"); 178 1803 : poDriver->SetMetadataItem(GDAL_DMD_UPDATE_ITEMS, "LayerMetadata Features"); 179 1803 : } 180 : 181 : /************************************************************************/ 182 : /* DeclareDeferredOGRPGPlugin() */ 183 : /************************************************************************/ 184 : 185 : #ifdef PLUGIN_FILENAME 186 2059 : void DeclareDeferredOGRPGPlugin() 187 : { 188 2059 : if (GDALGetDriverByName(DRIVER_NAME) != nullptr) 189 : { 190 283 : return; 191 : } 192 1776 : auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); 193 : #ifdef PLUGIN_INSTALLATION_MESSAGE 194 : poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, 195 : PLUGIN_INSTALLATION_MESSAGE); 196 : #endif 197 1776 : OGRPGDriverSetCommonMetadata(poDriver); 198 1776 : GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); 199 : } 200 : #endif