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