]> granicus.if.org Git - postgis/commitdiff
Jeff Adams patch to add command line flag to not use a transaction. (#110)
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 16 Mar 2011 17:16:47 +0000 (17:16 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 16 Mar 2011 17:16:47 +0000 (17:16 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@6909 b70326c6-7e19-0410-871a-916f4a2858ee

12 files changed:
loader/shp2pgsql-cli.c
loader/shp2pgsql-core.c
loader/shp2pgsql-core.h
regress/Makefile.in
regress/loader/NoTransPoint-wkb.expected [new file with mode: 0644]
regress/loader/NoTransPoint-wkb.sql [new file with mode: 0644]
regress/loader/NoTransPoint-wkt.expected [new file with mode: 0644]
regress/loader/NoTransPoint-wkt.sql [new file with mode: 0644]
regress/loader/NoTransPoint.dbf [new file with mode: 0644]
regress/loader/NoTransPoint.opts [new file with mode: 0644]
regress/loader/NoTransPoint.shp [new file with mode: 0644]
regress/loader/NoTransPoint.shx [new file with mode: 0644]

index a61078dc1ace44284b0c594b4329f8d4f0727abb..e98deada0bf7124dc0a8b0846762c88b1519c677 100644 (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);
index 957ef89ee83bade087f25c72e60680f0d014bc5f..0d627d09126d48c6d4574d74c3136e7c17000ab1 100644 (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);
index 8c93ebacc33fb84616cdf91e68ec09b33b17e5cb..060a1d9ef4505be18d0be7d725142414546af6f8 100644 (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;
 
 
index bea63e512653e41c0569031460e90e58911c7b63..a11e2249b215bbc9fc5286d046720c5578f212a2 100644 (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 \
diff --git a/regress/loader/NoTransPoint-wkb.expected b/regress/loader/NoTransPoint-wkb.expected
new file mode 100644 (file)
index 0000000..680e99b
--- /dev/null
@@ -0,0 +1,3 @@
+POINT(0 1)
+POINT(9 -1)
+POINT(9 -1)
diff --git a/regress/loader/NoTransPoint-wkb.sql b/regress/loader/NoTransPoint-wkb.sql
new file mode 100644 (file)
index 0000000..e680818
--- /dev/null
@@ -0,0 +1,2 @@
+select ST_Asewkt(the_geom) from loadedshp;
+
diff --git a/regress/loader/NoTransPoint-wkt.expected b/regress/loader/NoTransPoint-wkt.expected
new file mode 100644 (file)
index 0000000..680e99b
--- /dev/null
@@ -0,0 +1,3 @@
+POINT(0 1)
+POINT(9 -1)
+POINT(9 -1)
diff --git a/regress/loader/NoTransPoint-wkt.sql b/regress/loader/NoTransPoint-wkt.sql
new file mode 100644 (file)
index 0000000..e680818
--- /dev/null
@@ -0,0 +1,2 @@
+select ST_Asewkt(the_geom) from loadedshp;
+
diff --git a/regress/loader/NoTransPoint.dbf b/regress/loader/NoTransPoint.dbf
new file mode 100644 (file)
index 0000000..13b4aee
Binary files /dev/null and b/regress/loader/NoTransPoint.dbf differ
diff --git a/regress/loader/NoTransPoint.opts b/regress/loader/NoTransPoint.opts
new file mode 100644 (file)
index 0000000..bc95340
--- /dev/null
@@ -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
diff --git a/regress/loader/NoTransPoint.shp b/regress/loader/NoTransPoint.shp
new file mode 100644 (file)
index 0000000..51d38e7
Binary files /dev/null and b/regress/loader/NoTransPoint.shp differ
diff --git a/regress/loader/NoTransPoint.shx b/regress/loader/NoTransPoint.shx
new file mode 100644 (file)
index 0000000..7db02af
Binary files /dev/null and b/regress/loader/NoTransPoint.shx differ