From: Paul Ramsey Date: Tue, 2 Feb 2010 00:15:14 +0000 (+0000) Subject: Fix mis-handling of the commandline operations modes (#401) X-Git-Tag: 1.5.0~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=32142bcf98fcba274e9c6baddfe290aefc77fe7f;p=postgis Fix mis-handling of the commandline operations modes (#401) git-svn-id: http://svn.osgeo.org/postgis/trunk@5185 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/loader/shp2pgsql-cli.c b/loader/shp2pgsql-cli.c index 5e87e356b..443376f8f 100644 --- a/loader/shp2pgsql-cli.c +++ b/loader/shp2pgsql-cli.c @@ -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) diff --git a/loader/shp2pgsql-core.c b/loader/shp2pgsql-core.c index df7bef594..80d4e40d7 100644 --- a/loader/shp2pgsql-core.c +++ b/loader/shp2pgsql-core.c @@ -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)