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:
Paul Ramsey 2011-03-16 17:16:47 +00:00
parent 9b96a9869f
commit 2db8d4de0e
12 changed files with 56 additions and 10 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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;

View file

@ -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 \

View file

@ -0,0 +1,3 @@
POINT(0 1)
POINT(9 -1)
POINT(9 -1)

View file

@ -0,0 +1,2 @@
select ST_Asewkt(the_geom) from loadedshp;

View file

@ -0,0 +1,3 @@
POINT(0 1)
POINT(9 -1)
POINT(9 -1)

View file

@ -0,0 +1,2 @@
select ST_Asewkt(the_geom) from loadedshp;

Binary file not shown.

View 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

Binary file not shown.

Binary file not shown.