]> granicus.if.org Git - postgis/commitdiff
Fix construction of pgsql2shp's main retrieval query in ShpDumperOpenTable().
authorMark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
Fri, 3 Feb 2012 21:04:01 +0000 (21:04 +0000)
committerMark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
Fri, 3 Feb 2012 21:04:01 +0000 (21:04 +0000)
This fixes a regression which caused pgsql2shp to generate an incorrect SQL query
for tables without any geo columns.

git-svn-id: http://svn.osgeo.org/postgis/trunk@9020 b70326c6-7e19-0410-871a-916f4a2858ee

loader/pgsql2shp-core.c

index fde9c071ce3fbc557351186f1379b79a430ce34d..6a8166c74c24652d26c120941cec788accbb7bd4 100644 (file)
@@ -1902,20 +1902,25 @@ ShpDumperOpenTable(SHPDUMPERSTATE *state)
 
        for (i = 0; i < state->fieldcount; i++)
        {
+               /* Comma-separated column names */
+               if (i > 0)
+                       strcat(state->main_scan_query, ",");
+                       
                if (state->config->binary)
                        sprintf(buf, "\"%s\"::text", state->pgfieldnames[i]);
                else
                        sprintf(buf, "\"%s\"", state->pgfieldnames[i]);
 
                strcat(state->main_scan_query, buf);
-
-               /* Comma-separated column names */
-               strcat(state->main_scan_query, ",");
        }
 
        /* If we found a valid geometry/geography column then use it */
        if (state->geo_col_name)
        {
+               /* If this is the (only) column, no need for the initial comma */
+               if (state->fieldcount > 0)
+                       strcat(state->main_scan_query, ",");
+               
                if (state->big_endian)
                {
                        if (state->pgis_major_version > 0)