[mapserver-commits] r8238 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Thu Dec 11 01:12:27 EST 2008


Author: pramsey
Date: 2008-12-11 01:12:26 -0500 (Thu, 11 Dec 2008)
New Revision: 8238

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mappostgis.c
Log:
Fix trailing spaces in fixed varchar fields (#2817)



Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2008-12-11 03:48:52 UTC (rev 8237)
+++ trunk/mapserver/HISTORY.TXT	2008-12-11 06:12:26 UTC (rev 8238)
@@ -11,6 +11,9 @@
 
 Current Version (5.3-dev, SVN trunk):
 ------------------------------------
+
+- mappostgis.c: Fix trailing spaces in fixed varchar fields (#2817)
+
 - RFC48 implementation: GEOMTRANSFORM on styleObj (#2825)
 
 - mapwms.c: cleanup warnings with recent gcc versions (#2822)

Modified: trunk/mapserver/mappostgis.c
===================================================================
--- trunk/mapserver/mappostgis.c	2008-12-11 03:48:52 UTC (rev 8237)
+++ trunk/mapserver/mappostgis.c	2008-12-11 06:12:26 UTC (rev 8238)
@@ -1286,13 +1286,22 @@
         for ( t = 0; t < layer->numitems; t++) {
             int size = PQgetlength(layerinfo->pgresult, layerinfo->rownum, t);
             char *val = (char*)PQgetvalue(layerinfo->pgresult, layerinfo->rownum, t);
-            shape->values[t] = (char*) malloc(size + 1);
-            memcpy(shape->values[t], val, size);
-            shape->values[t][size] = '\0'; /* null terminate it */
+            int isnull = PQgetisnull(layerinfo->pgresult, layerinfo->rownum, t);
+            if ( isnull ) {
+                shape->values[t] = strdup("");
+            }
+            else {
+                shape->values[t] = (char*) malloc(size + 1);
+                memcpy(shape->values[t], val, size);
+                shape->values[t][size] = '\0'; /* null terminate it */
+                msStringTrimBlanks(shape->values[t]);
+            }
+            if( layer->debug > 4 ) {
+                msDebug("msPostGISReadShape: PQgetlength = %d\n", size);
+            }
             if( layer->debug > 1 ) {
-                msDebug("msPostGISReadShape: [%s] %s\n", layer->items[t], shape->values[t]);
+                msDebug("msPostGISReadShape: [%s] \"%s\"\n", layer->items[t], shape->values[t]);
             }
-
         }
         /* t is the geometry, t+1 is the uid */
         tmp = PQgetvalue(layerinfo->pgresult, layerinfo->rownum, t + 1);
@@ -1304,12 +1313,17 @@
         }
 
         shape->index = uid;
+
+        if( layer->debug > 2 ) {
+            msDebug("msPostGISReadShape: [index] %d\n",  shape->index);
+        }
+
         shape->numvalues = layer->numitems;
 
         find_bounds(shape);
     }
     
-    if( layer->debug > 1 ) {
+    if( layer->debug > 2 ) {
         char *tmp = msShapeToWKT(shape);
         msDebug("msPostGISReadShape: [shape] %s\n", tmp);
         free(tmp);
@@ -1525,16 +1539,16 @@
         free(layer->iteminfo);
     }
 
-    itemindexes = (int *) malloc(sizeof(int) * layer->numitems);
-    if (!itemindexes) {
+    layer->iteminfo = malloc(sizeof(int) * layer->numitems);
+    if (!layer->iteminfo) {
         msSetError(MS_MEMERR, "Out of memory.", "msPostGISLayerInitItemInfo()");
         return MS_FAILURE;
     }
-
+	
+    itemindexes = (int*)layer->iteminfo;
     for (i = 0; i < layer->numitems; i++) {
         itemindexes[i] = i; /* Last item is always the geometry. The rest are non-geometry. */
     }
-    layer->iteminfo = itemindexes;
 
     return MS_SUCCESS;
 #else



More information about the mapserver-commits mailing list