Coverage Report

Created: 2025-12-31 08:30

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