[mapserver-commits] r9659 - branches/branch-5-6/mapserver

svn at osgeo.org svn at osgeo.org
Sun Jan 3 11:53:23 EST 2010


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

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

Modified: branches/branch-5-6/mapserver/HISTORY.TXT
===================================================================
--- branches/branch-5-6/mapserver/HISTORY.TXT	2010-01-03 14:30:09 UTC (rev 9658)
+++ branches/branch-5-6/mapserver/HISTORY.TXT	2010-01-03 16:53:22 UTC (rev 9659)
@@ -15,6 +15,8 @@
 Current Version (SVN branch-5-6):
 --------------------------------
 
+- 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: branches/branch-5-6/mapserver/mapmssql2008.c
===================================================================
--- branches/branch-5-6/mapserver/mapmssql2008.c	2010-01-03 14:30:09 UTC (rev 9658)
+++ branches/branch-5-6/mapserver/mapmssql2008.c	2010-01-03 16:53:22 UTC (rev 9659)
@@ -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