]> granicus.if.org Git - postgis/commitdiff
Fix mis-handling of the commandline operations modes (#401)
authorPaul Ramsey <pramsey@cleverelephant.ca>
Tue, 2 Feb 2010 00:15:14 +0000 (00:15 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Tue, 2 Feb 2010 00:15:14 +0000 (00:15 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@5185 b70326c6-7e19-0410-871a-916f4a2858ee

loader/shp2pgsql-cli.c
loader/shp2pgsql-core.c

index 5e87e356bb07029575073802c2f3ca79c84048b5..443376f8f9172208987fa9278187d1ba11a831e5 100644 (file)
@@ -76,16 +76,7 @@ main (int argc, char **argv)
                case 'd':
                case 'a':
                case 'p':
-                       if (config->opt == ' ')
-                       {
-                               config->opt = c;
-                       }
-                       else
-                       {
-                               /* Only one of these options can be chosen */
-                               usage();
-                               exit(0);
-                       }
+                       config->opt = c;
                        break;
 
                case 'D':
@@ -248,62 +239,68 @@ main (int argc, char **argv)
        printf("%s", header);
        free(header);
 
-       /* If in COPY mode, output the COPY statement */
-       if (state->config->dump_format)
+       /* If we are not in "prepare" mode, go ahead and write out the data. */
+       if( state->config->opt != 'p' )
        {
-               ret = ShpLoaderGetSQLCopyStatement(state, &header);
-               if (ret != SHPLOADEROK)
-               {
-                       fprintf(stderr, "%s\n", state->message);
 
-                       if (ret == SHPLOADERERR)
-                               exit(1);
-               }
+               /* If in COPY mode, output the COPY statement */
+               if (state->config->dump_format)
+               {
+                       ret = ShpLoaderGetSQLCopyStatement(state, &header);
+                       if (ret != SHPLOADEROK)
+                       {
+                               fprintf(stderr, "%s\n", state->message);
 
-               printf("%s", header);
-               free(header);
-       }
+                               if (ret == SHPLOADERERR)
+                                       exit(1);
+                       }
 
-       /* Main loop: iterate through all of the records and send them to stdout */
-       for (i = 0; i < ShpLoaderGetRecordCount(state); i++)
-       {
-               ret = ShpLoaderGenerateSQLRowStatement(state, i, &record);
+                       printf("%s", header);
+                       free(header);
+               }
 
-               switch (ret)
+               /* Main loop: iterate through all of the records and send them to stdout */
+               for (i = 0; i < ShpLoaderGetRecordCount(state); i++)
                {
-               case SHPLOADEROK:
-                       /* Simply display the geometry */
-                       printf("%s\n", record);
-                       free(record);
-                       break;
+                       ret = ShpLoaderGenerateSQLRowStatement(state, i, &record);
 
-               case SHPLOADERERR:
-                       /* Display the error message then stop */
-                       fprintf(stderr, "%s\n", state->message);
-                       exit(1);
-                       break;
+                       switch (ret)
+                       {
+                       case SHPLOADEROK:
+                               /* Simply display the geometry */
+                               printf("%s\n", record);
+                               free(record);
+                               break;
 
-               case SHPLOADERWARN:
-                       /* Display the warning, but continue */
-                       fprintf(stderr, "%s\n", state->message);
-                       printf("%s\n", record);
-                       free(record);
-                       break;
+                       case SHPLOADERERR:
+                               /* Display the error message then stop */
+                               fprintf(stderr, "%s\n", state->message);
+                               exit(1);
+                               break;
 
-               case SHPLOADERRECDELETED:
-                       /* Record is marked as deleted - ignore */
-                       break;
+                       case SHPLOADERWARN:
+                               /* Display the warning, but continue */
+                               fprintf(stderr, "%s\n", state->message);
+                               printf("%s\n", record);
+                               free(record);
+                               break;
 
-               case SHPLOADERRECISNULL:
-                       /* Record is NULL and should be ignored according to NULL policy */
-                       break;
+                       case SHPLOADERRECDELETED:
+                               /* Record is marked as deleted - ignore */
+                               break;
+
+                       case SHPLOADERRECISNULL:
+                               /* Record is NULL and should be ignored according to NULL policy */
+                               break;
+                       }
                }
-       }
 
-       /* If in COPY mode, terminate the COPY statement */
-       if (state->config->dump_format)
-               printf("\\.\n");
+               /* If in COPY mode, terminate the COPY statement */
+               if (state->config->dump_format)
+                       printf("\\.\n");
 
+       }
+       
        /* Print the footer to stdout */
        ret = ShpLoaderGetSQLFooter(state, &footer);
        if (ret != SHPLOADEROK)
index df7bef594be6457610a47a8df66eacb4e7dd629a..80d4e40d7a0877e404f48e113e4ffa08c6d59fce 100644 (file)
@@ -1782,7 +1782,7 @@ ShpLoaderGetSQLFooter(SHPLOADERSTATE *state, char **strfooter)
        sb = stringbuffer_create();
        stringbuffer_clear(sb);
 
-       /* Create gist index if specified */
+       /* Create gist index if specified and not in "prepare" mode */
        if (state->config->createindex)
        {
                if (state->config->schema)