[mapserver-commits] r9660 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Sun Jan 3 11:54:22 EST 2010


Author: tamas
Date: 2010-01-03 11:54:22 -0500 (Sun, 03 Jan 2010)
New Revision: 9660

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapmssql2008.c
Log:
SQL Server 2008 plugin is not handling null field values correctly (#2893)

Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2010-01-03 16:53:22 UTC (rev 9659)
+++ trunk/mapserver/HISTORY.TXT	2010-01-03 16:54:22 UTC (rev 9660)
@@ -14,6 +14,8 @@
 Current Version (SVN trunk):
 ----------------------------
 
+- SQL Server 2008 plugin is not handling null field values correctly (#2893)
+
 - Hatch symbol not properly saved (#2905)
 
 - Expose symbolObj.inmapfile to the SWIG API, have already been exposed to PHP (#3233)

Modified: trunk/mapserver/mapmssql2008.c
===================================================================
--- trunk/mapserver/mapmssql2008.c	2010-01-03 16:53:22 UTC (rev 9659)
+++ trunk/mapserver/mapmssql2008.c	2010-01-03 16:54:22 UTC (rev 9660)
@@ -1264,22 +1264,28 @@
 				/* figure out how big the buffer needs to be */
                 rc = SQLGetData(layerinfo->conn->hstmt, t + 1, SQL_C_BINARY, dummyBuffer, 0, &needLen);
 
-				/* allocate the buffer - this will be a null-terminated string so alloc for the null too */
-				valueBuffer = (char*) malloc( needLen + 1 );
-				if ( valueBuffer == NULL )
-				{
-					msSetError( MS_QUERYERR, "Could not allocate value buffer.", "msMSSQL2008LayerGetShapeRandom()" );
-					return MS_FAILURE;
-				}
+                if (needLen > 0)
+                {
+				    /* allocate the buffer - this will be a null-terminated string so alloc for the null too */
+				    valueBuffer = (char*) malloc( needLen + 1 );
+				    if ( valueBuffer == NULL )
+				    {
+					    msSetError( MS_QUERYERR, "Could not allocate value buffer.", "msMSSQL2008LayerGetShapeRandom()" );
+					    return MS_FAILURE;
+				    }
 
-				/* Now grab the data */
-                rc = SQLGetData(layerinfo->conn->hstmt, t + 1, SQL_C_BINARY, valueBuffer, needLen, &retLen);
+				    /* Now grab the data */
+                    rc = SQLGetData(layerinfo->conn->hstmt, t + 1, SQL_C_BINARY, valueBuffer, needLen, &retLen);
 
-				/* Terminate the buffer */
-                valueBuffer[retLen] = 0; /* null terminate it */
+				    /* Terminate the buffer */
+                    valueBuffer[retLen] = 0; /* null terminate it */
 
-				/* Pop the value into the shape's value array */
-                shape->values[t] = valueBuffer;
+				    /* Pop the value into the shape's value array */
+                    shape->values[t] = valueBuffer;
+                }
+                else
+                    /* Copy empty sting for NULL values */
+                    shape->values[t] = strdup("");
             }
 
             /* Get shape geometry */



More information about the mapserver-commits mailing list