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 100 : 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 100 : if (strcmp(pszName, "/dev/stdout") == 0) 26 0 : pszName = "/vsistdout/"; 27 : 28 100 : OGRPGDumpDataSource *poDS = new OGRPGDumpDataSource(pszName, papszOptions); 29 100 : if (!poDS->Log("SET standard_conforming_strings = ON")) 30 : { 31 1 : delete poDS; 32 1 : return nullptr; 33 : } 34 : 35 99 : return poDS; 36 : } 37 : 38 : /************************************************************************/ 39 : /* RegisterOGRPGDump() */ 40 : /************************************************************************/ 41 : 42 1595 : void RegisterOGRPGDump() 43 : 44 : { 45 1595 : if (GDALGetDriverByName("PGDUMP") != nullptr) 46 302 : return; 47 : 48 1293 : GDALDriver *poDriver = new GDALDriver(); 49 : 50 1293 : poDriver->SetDescription("PGDUMP"); 51 1293 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); 52 1293 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES"); 53 1293 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_FIELD, "YES"); 54 1293 : poDriver->SetMetadataItem(GDAL_DCAP_CURVE_GEOMETRIES, "YES"); 55 1293 : poDriver->SetMetadataItem(GDAL_DCAP_MEASURED_GEOMETRIES, "YES"); 56 1293 : poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES"); 57 1293 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "PostgreSQL SQL dump"); 58 1293 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/pgdump.html"); 59 1293 : poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "sql"); 60 : 61 1293 : 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 1293 : "</CreationOptionList>"); 75 : 76 1293 : 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='DROP_TABLE' type='string-select' description='Whether " 123 : "to explicitly destroy tables before recreating them' default='YES'>" 124 : " <Value>YES</Value>" 125 : " <Value>ON</Value>" 126 : " <Value>TRUE</Value>" 127 : " <Value>NO</Value>" 128 : " <Value>OFF</Value>" 129 : " <Value>FALSE</Value>" 130 : " <Value>IF_EXISTS</Value>" 131 : " </Option>" 132 : " <Option name='SRID' type='int' description='Forced SRID of the " 133 : "layer'/>" 134 : " <Option name='NONE_AS_UNKNOWN' type='boolean' description='Whether " 135 : "to force non-spatial layers to be created as spatial tables' " 136 : "default='NO'/>" 137 : " <Option name='FID' type='string' description='Name of the FID " 138 : "column to create. Set to empty to not create it.' default='ogc_fid'/>" 139 : " <Option name='FID64' type='boolean' description='Whether to create " 140 : "the FID column with BIGSERIAL type to handle 64bit wide ids' " 141 : "default='NO'/>" 142 : " <Option name='EXTRACT_SCHEMA_FROM_LAYER_NAME' type='boolean' " 143 : "description='Whether a dot in a layer name should be considered as " 144 : "the separator for the schema and table name' default='YES'/>" 145 : " <Option name='COLUMN_TYPES' type='string' description='A list of " 146 : "strings of format field_name=pg_field_type (separated by comma) to " 147 : "force the PG column type of fields to be created'/>" 148 : " <Option name='POSTGIS_VERSION' type='string' description='A string " 149 : "formatted as X.Y' default='2.2'/>" 150 : " <Option name='DESCRIPTION' type='string' description='Description " 151 : "string to put in the pg_description system table'/>" 152 1293 : "</LayerCreationOptionList>"); 153 : 154 1293 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONFIELDDATATYPES, 155 : "Integer Integer64 Real String Date DateTime " 156 : "Time IntegerList Integer64List RealList " 157 1293 : "StringList Binary"); 158 1293 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONFIELDDATASUBTYPES, 159 1293 : "Boolean Int16 Float32"); 160 1293 : poDriver->SetMetadataItem(GDAL_DMD_CREATION_FIELD_DEFN_FLAGS, 161 1293 : "WidthPrecision Nullable Unique Default Comment"); 162 : 163 1293 : poDriver->SetMetadataItem(GDAL_DCAP_NOTNULL_FIELDS, "YES"); 164 1293 : poDriver->SetMetadataItem(GDAL_DCAP_DEFAULT_FIELDS, "YES"); 165 1293 : poDriver->SetMetadataItem(GDAL_DCAP_UNIQUE_FIELDS, "YES"); 166 1293 : poDriver->SetMetadataItem(GDAL_DCAP_NOTNULL_GEOMFIELDS, "YES"); 167 : 168 1293 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 169 : 170 1293 : poDriver->pfnCreate = OGRPGDumpDriverCreate; 171 : 172 1293 : GetGDALDriverManager()->RegisterDriver(poDriver); 173 : }