Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: OpenGIS Simple Features Reference Implementation 4 : * Purpose: Implements OGRPGDumpDriver class. 5 : * Author: Even Rouault, <even dot rouault at spatialys.com> 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2010-2011, Even Rouault <even dot rouault at spatialys.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #include "ogr_pgdump.h" 14 : #include "cpl_conv.h" 15 : 16 : /************************************************************************/ 17 : /* OGRPGDumpDriverCreate() */ 18 : /************************************************************************/ 19 : 20 : static GDALDataset * 21 103 : OGRPGDumpDriverCreate(const char *pszName, CPL_UNUSED int nXSize, 22 : CPL_UNUSED int nYSize, CPL_UNUSED int nBands, 23 : CPL_UNUSED GDALDataType eDT, char **papszOptions) 24 : { 25 103 : if (strcmp(pszName, "/dev/stdout") == 0) 26 0 : pszName = "/vsistdout/"; 27 : 28 103 : OGRPGDumpDataSource *poDS = new OGRPGDumpDataSource(pszName, papszOptions); 29 103 : if (!poDS->Log("SET standard_conforming_strings = ON")) 30 : { 31 1 : delete poDS; 32 1 : return nullptr; 33 : } 34 : 35 102 : return poDS; 36 : } 37 : 38 : /************************************************************************/ 39 : /* RegisterOGRPGDump() */ 40 : /************************************************************************/ 41 : 42 1928 : void RegisterOGRPGDump() 43 : 44 : { 45 1928 : if (GDALGetDriverByName("PGDUMP") != nullptr) 46 282 : return; 47 : 48 1646 : GDALDriver *poDriver = new GDALDriver(); 49 : 50 1646 : poDriver->SetDescription("PGDUMP"); 51 1646 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); 52 1646 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES"); 53 1646 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_FIELD, "YES"); 54 1646 : poDriver->SetMetadataItem(GDAL_DCAP_CURVE_GEOMETRIES, "YES"); 55 1646 : poDriver->SetMetadataItem(GDAL_DCAP_MEASURED_GEOMETRIES, "YES"); 56 1646 : poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES"); 57 1646 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "PostgreSQL SQL dump"); 58 1646 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/pgdump.html"); 59 1646 : poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "sql"); 60 : 61 1646 : poDriver->SetMetadataItem( 62 : GDAL_DMD_CREATIONOPTIONLIST, 63 : "<CreationOptionList>" 64 : #ifdef _WIN32 65 : " <Option name='LINEFORMAT' type='string-select' " 66 : "description='end-of-line sequence' default='CRLF'>" 67 : #else 68 : " <Option name='LINEFORMAT' type='string-select' " 69 : "description='end-of-line sequence' default='LF'>" 70 : #endif 71 : " <Value>CRLF</Value>" 72 : " <Value>LF</Value>" 73 : " </Option>" 74 1646 : "</CreationOptionList>"); 75 : 76 1646 : poDriver->SetMetadataItem( 77 : GDAL_DS_LAYER_CREATIONOPTIONLIST, 78 : "<LayerCreationOptionList>" 79 : " <Option name='GEOM_TYPE' type='string-select' description='Format " 80 : "of geometry columns' default='geometry'>" 81 : " <Value>geometry</Value>" 82 : " <Value>geography</Value>" 83 : " </Option>" 84 : " <Option name='LAUNDER' type='boolean' description='Whether layer " 85 : "and field names will be laundered' default='YES'/>" 86 : " <Option name='LAUNDER_ASCII' type='boolean' description='Same as " 87 : "LAUNDER, but force generation of ASCII identifiers' default='NO'/>" 88 : " <Option name='PRECISION' type='boolean' description='Whether fields " 89 : "created should keep the width and precision' default='YES'/>" 90 : " <Option name='DIM' type='string' description='Set to 2 to force the " 91 : "geometries to be 2D, 3 to be 2.5D, XYM or XYZM'/>" 92 : " <Option name='GEOMETRY_NAME' type='string' description='Name of " 93 : "geometry column. Defaults to wkb_geometry for GEOM_TYPE=geometry or " 94 : "the_geog for GEOM_TYPE=geography'/>" 95 : " <Option name='SCHEMA' type='string' description='Name of schema " 96 : "into which to create the new table'/>" 97 : " <Option name='CREATE_SCHEMA' type='boolean' description='Whether to " 98 : "explicitly emit the CREATE SCHEMA statement to create the specified " 99 : "schema' default='YES'/>" 100 : " <Option name='SPATIAL_INDEX' type='string-select' description='Type " 101 : "of spatial index to create' default='GIST'>" 102 : " <Value>NONE</Value>" 103 : " <Value>GIST</Value>" 104 : " <Value>SPGIST</Value>" 105 : " <Value>BRIN</Value>" 106 : " </Option>" 107 : " <Option name='GEOM_COLUMN_POSITION' type='string-select' " 108 : "description='Whether geometry/geography columns should be created " 109 : "as soon they are created (IMMEDIATE) or after non-spatial columns' " 110 : "default='IMMEDIATE'>" 111 : " <Value>IMMEDIATE</Value>" 112 : " <Value>END</Value>" 113 : " </Option>" 114 : " <Option name='TEMPORARY' type='boolean' description='Whether to a " 115 : "temporary table instead of a permanent one' default='NO'/>" 116 : " <Option name='UNLOGGED' type='boolean' description='Whether to " 117 : "create the table as a unlogged one' default='NO'/>" 118 : " <Option name='WRITE_EWKT_GEOM' type='boolean' description='Whether " 119 : "to write EWKT geometries instead of HEX geometry' default='NO'/>" 120 : " <Option name='CREATE_TABLE' type='boolean' description='Whether to " 121 : "explicitly recreate the table if necessary' default='YES'/>" 122 : " <Option name='SKIP_CONFLICTS' type='boolean' description='Whether " 123 : "to ignore conflicts when inserting features' default='NO'/>" 124 : " <Option name='DROP_TABLE' type='string-select' description='Whether " 125 : "to explicitly destroy tables before recreating them' default='YES'>" 126 : " <Value>YES</Value>" 127 : " <Value>ON</Value>" 128 : " <Value>TRUE</Value>" 129 : " <Value>NO</Value>" 130 : " <Value>OFF</Value>" 131 : " <Value>FALSE</Value>" 132 : " <Value>IF_EXISTS</Value>" 133 : " </Option>" 134 : " <Option name='SRID' type='int' description='Forced SRID of the " 135 : "layer'/>" 136 : " <Option name='NONE_AS_UNKNOWN' type='boolean' description='Whether " 137 : "to force non-spatial layers to be created as spatial tables' " 138 : "default='NO'/>" 139 : " <Option name='FID' type='string' description='Name of the FID " 140 : "column to create. Set to empty to not create it.' default='ogc_fid'/>" 141 : " <Option name='FID64' type='boolean' description='Whether to create " 142 : "the FID column with BIGSERIAL type to handle 64bit wide ids' " 143 : "default='NO'/>" 144 : " <Option name='EXTRACT_SCHEMA_FROM_LAYER_NAME' type='boolean' " 145 : "description='Whether a dot in a layer name should be considered as " 146 : "the separator for the schema and table name' default='YES'/>" 147 : " <Option name='COLUMN_TYPES' type='string' description='A list of " 148 : "strings of format field_name=pg_field_type (separated by comma) to " 149 : "force the PG column type of fields to be created'/>" 150 : " <Option name='POSTGIS_VERSION' type='string' description='A string " 151 : "formatted as X.Y' default='2.2'/>" 152 : " <Option name='DESCRIPTION' type='string' description='Description " 153 : "string to put in the pg_description system table'/>" 154 1646 : "</LayerCreationOptionList>"); 155 : 156 1646 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONFIELDDATATYPES, 157 : "Integer Integer64 Real String Date DateTime " 158 : "Time IntegerList Integer64List RealList " 159 1646 : "StringList Binary"); 160 1646 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONFIELDDATASUBTYPES, 161 1646 : "Boolean Int16 Float32"); 162 1646 : poDriver->SetMetadataItem(GDAL_DMD_CREATION_FIELD_DEFN_FLAGS, 163 1646 : "WidthPrecision Nullable Unique Default Comment"); 164 : 165 1646 : poDriver->SetMetadataItem(GDAL_DCAP_NOTNULL_FIELDS, "YES"); 166 1646 : poDriver->SetMetadataItem(GDAL_DCAP_DEFAULT_FIELDS, "YES"); 167 1646 : poDriver->SetMetadataItem(GDAL_DCAP_UNIQUE_FIELDS, "YES"); 168 1646 : poDriver->SetMetadataItem(GDAL_DCAP_NOTNULL_GEOMFIELDS, "YES"); 169 : 170 1646 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 171 : 172 1646 : poDriver->pfnCreate = OGRPGDumpDriverCreate; 173 : 174 1646 : GetGDALDriverManager()->RegisterDriver(poDriver); 175 : }