Skip to content

Commit dd336bc

Browse files
committed
MSSQL driver: Get feature attributes as UTF8 strings (#5308)
1 parent 375a7ae commit dd336bc

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

mapmssql2008.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,11 @@ static int prepare_database(layerObj *layer, rectObj rect, char **query_string)
976976
char buffer[10000] = "";
977977

978978
for(t = 0; t < layer->numitems; t++) {
979+
#ifdef USE_ICONV
980+
snprintf(buffer + strlen(buffer), sizeof(buffer) - strlen(buffer), "convert(nvarchar(max), [%s]),", layer->items[t]);
981+
#else
979982
snprintf(buffer + strlen(buffer), sizeof(buffer) - strlen(buffer), "convert(varchar(max), [%s]),", layer->items[t]);
983+
#endif
980984
}
981985

982986
if (layerinfo->geometry_format == MSSQLGEOMETRY_NATIVE)
@@ -1699,7 +1703,7 @@ int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *recor
16991703

17001704
if (needLen > 0) {
17011705
/* allocate the buffer - this will be a null-terminated string so alloc for the null too */
1702-
valueBuffer = (char*) msSmallMalloc( needLen + 1 );
1706+
valueBuffer = (char*) msSmallMalloc( needLen + 2 );
17031707
if ( valueBuffer == NULL ) {
17041708
msSetError( MS_QUERYERR, "Could not allocate value buffer.", "msMSSQL2008LayerGetShapeRandom()" );
17051709
return MS_FAILURE;
@@ -1714,7 +1718,13 @@ int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *recor
17141718
valueBuffer[retLen] = 0; /* null terminate it */
17151719

17161720
/* Pop the value into the shape's value array */
1721+
#ifdef USE_ICONV
1722+
valueBuffer[retLen + 1] = 0;
1723+
shape->values[t] = msConvertWideStringToUTF8((wchar_t*)valueBuffer, "UCS-2LE");
1724+
msFree(valueBuffer);
1725+
#else
17171726
shape->values[t] = valueBuffer;
1727+
#endif
17181728
} else
17191729
/* Copy empty sting for NULL values */
17201730
shape->values[t] = msStrdup("");

0 commit comments

Comments
 (0)