mirror of
https://git.osgeo.org/gitea/postgis/postgis
synced 2024-10-23 16:42:35 +00:00
Jeff Adams patch to add command line flag to not use a transaction. (#110)
git-svn-id: http://svn.osgeo.org/postgis/trunk@6909 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
parent
9b96a9869f
commit
2db8d4de0e
|
@ -23,7 +23,7 @@ usage()
|
|||
printf(_( "USAGE: shp2pgsql [<options>] <shapefile> [<schema>.]<table>\n"
|
||||
"OPTIONS:\n" ));
|
||||
printf(_( " -s <srid> Set the SRID field. Defaults to -1.\n"
|
||||
" (-d|a|c|p) These are mutually exclusive options:\n"
|
||||
" (-d|a|c|p) These are mutually exclusive options:\n"
|
||||
" -d Drops the table, then recreates it and populates\n"
|
||||
" it with current shape file data.\n"
|
||||
" -a Appends shape file into current table, must be\n"
|
||||
|
@ -34,6 +34,8 @@ usage()
|
|||
printf(_( " -g <geocolumn> Specify the name of the geometry/geography column\n"
|
||||
" (mostly useful in append mode).\n" ));
|
||||
printf(_( " -D Use postgresql dump format (defaults to SQL insert statments).\n" ));
|
||||
printf(_( " -e Execute each statement individually, do not use a transaction.\n"
|
||||
" Not compatible with -D.\n" ));
|
||||
printf(_( " -G Use geography type (requires lon/lat data).\n" ));
|
||||
printf(_( " -k Keep postgresql identifiers case.\n" ));
|
||||
printf(_( " -i Use int4 type for all integer dbf fields.\n" ));
|
||||
|
@ -44,11 +46,11 @@ usage()
|
|||
printf(_( " -N <policy> NULL geometries handling policy (insert*,skip,abort).\n" ));
|
||||
printf(_( " -n Only import DBF file.\n" ));
|
||||
printf(_( " -T <tablespace> Specify the tablespace for the new table.\n"
|
||||
" Note that indexes will still use the default tablespace unless the"
|
||||
" -X flag is also used."));
|
||||
" Note that indexes will still use the default tablespace unless the\n"
|
||||
" -X flag is also used.\n"));
|
||||
printf(_( " -X <tablespace> Specify the tablespace for the table's indexes.\n"
|
||||
" This applies to the primary key, and the spatial index if"
|
||||
" the -I flag is used." ));
|
||||
" This applies to the primary key, and the spatial index if\n"
|
||||
" the -I flag is used.\n" ));
|
||||
printf(_( " -? Display this help screen.\n" ));
|
||||
}
|
||||
|
||||
|
@ -79,7 +81,8 @@ main (int argc, char **argv)
|
|||
config = malloc(sizeof(SHPLOADERCONFIG));
|
||||
set_config_defaults(config);
|
||||
|
||||
while ((c = pgis_getopt(argc, argv, "kcdapGDs:Sg:iW:wIN:nT:X:")) != EOF)
|
||||
/* Keep the flag list alphabetic so it's easy to see what's left. */
|
||||
while ((c = pgis_getopt(argc, argv, "acdeg:iknps:wDGIN:ST:W:X:")) != EOF)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
|
@ -92,6 +95,11 @@ main (int argc, char **argv)
|
|||
|
||||
case 'D':
|
||||
config->dump_format = 1;
|
||||
if (!config->usetransaction)
|
||||
{
|
||||
fprintf(stderr, "Cannot use both -D and -e.\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'G':
|
||||
|
@ -169,6 +177,15 @@ main (int argc, char **argv)
|
|||
config->idxtablespace = pgis_optarg;
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
config->usetransaction = 0;
|
||||
if (config->dump_format)
|
||||
{
|
||||
fprintf(stderr, "Cannot use both -D and -e.\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
||||
case '?':
|
||||
usage();
|
||||
exit(0);
|
||||
|
|
|
@ -799,6 +799,7 @@ set_config_defaults(SHPLOADERCONFIG *config)
|
|||
config->hwgeom = 0;
|
||||
config->tablespace = NULL;
|
||||
config->idxtablespace = NULL;
|
||||
config->usetransaction = 1;
|
||||
}
|
||||
|
||||
/* Create a new shapefile state object */
|
||||
|
@ -1239,8 +1240,11 @@ ShpLoaderGetSQLHeader(SHPLOADERSTATE *state, char **strheader)
|
|||
}
|
||||
}
|
||||
|
||||
/* Start of transaction */
|
||||
stringbuffer_aprintf(sb, "BEGIN;\n");
|
||||
/* Start of transaction if we are using one */
|
||||
if (state->config->usetransaction)
|
||||
{
|
||||
stringbuffer_aprintf(sb, "BEGIN;\n");
|
||||
}
|
||||
|
||||
/* If not in 'append' mode create the spatial table */
|
||||
if (state->config->opt != 'a')
|
||||
|
@ -1811,8 +1815,11 @@ ShpLoaderGetSQLFooter(SHPLOADERSTATE *state, char **strfooter)
|
|||
stringbuffer_aprintf(sb, ";\n");
|
||||
}
|
||||
|
||||
/* End the transaction */
|
||||
stringbuffer_aprintf(sb, "COMMIT;\n");
|
||||
/* End the transaction if there is one. */
|
||||
if (state->config->usetransaction)
|
||||
{
|
||||
stringbuffer_aprintf(sb, "COMMIT;\n");
|
||||
}
|
||||
|
||||
/* Copy the string buffer into a new string, destroying the string buffer */
|
||||
ret = (char *)malloc(strlen((char *)stringbuffer_getstring(sb)) + 1);
|
||||
|
|
|
@ -138,6 +138,9 @@ typedef struct shp_loader_config
|
|||
/* 0 = new style (PostGIS 1.x) geometries, 1 = old style (PostGIS 0.9.x) geometries */
|
||||
int hwgeom;
|
||||
|
||||
/* whether to do a single transaction or run each statement on its own */
|
||||
int usetransaction;
|
||||
|
||||
} SHPLOADERCONFIG;
|
||||
|
||||
|
||||
|
|
|
@ -37,6 +37,10 @@ TESTS = \
|
|||
loader/Polygon \
|
||||
loader/PolygonM \
|
||||
loader/PolygonZ \
|
||||
loader/TSTPolygon \
|
||||
loader/TSIPolygon \
|
||||
loader/TSTIPolygon \
|
||||
loader/NoTransPoint \
|
||||
regress \
|
||||
regress_index \
|
||||
regress_index_nulls \
|
||||
|
|
3
regress/loader/NoTransPoint-wkb.expected
Normal file
3
regress/loader/NoTransPoint-wkb.expected
Normal file
|
@ -0,0 +1,3 @@
|
|||
POINT(0 1)
|
||||
POINT(9 -1)
|
||||
POINT(9 -1)
|
2
regress/loader/NoTransPoint-wkb.sql
Normal file
2
regress/loader/NoTransPoint-wkb.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
select ST_Asewkt(the_geom) from loadedshp;
|
||||
|
3
regress/loader/NoTransPoint-wkt.expected
Normal file
3
regress/loader/NoTransPoint-wkt.expected
Normal file
|
@ -0,0 +1,3 @@
|
|||
POINT(0 1)
|
||||
POINT(9 -1)
|
||||
POINT(9 -1)
|
2
regress/loader/NoTransPoint-wkt.sql
Normal file
2
regress/loader/NoTransPoint-wkt.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
select ST_Asewkt(the_geom) from loadedshp;
|
||||
|
BIN
regress/loader/NoTransPoint.dbf
Normal file
BIN
regress/loader/NoTransPoint.dbf
Normal file
Binary file not shown.
5
regress/loader/NoTransPoint.opts
Normal file
5
regress/loader/NoTransPoint.opts
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Ideally we'd use a shapefile with an invalid geometry, so you could see that the
|
||||
# "don't use a transaction" version successfully inserts every row except that one.
|
||||
# However as of this writing, we don't have such a shapefile, so this test just
|
||||
# shows that it doesn't break anything to use the flag.
|
||||
-e
|
BIN
regress/loader/NoTransPoint.shp
Normal file
BIN
regress/loader/NoTransPoint.shp
Normal file
Binary file not shown.
BIN
regress/loader/NoTransPoint.shx
Normal file
BIN
regress/loader/NoTransPoint.shx
Normal file
Binary file not shown.
Loading…
Reference in a new issue