[mapserver-commits] r10393 - branches/branch-5-4/mapserver
svn at osgeo.org
svn at osgeo.org
Sat Jul 24 11:27:20 EDT 2010
Author: tamas
Date: 2010-07-24 15:27:20 +0000 (Sat, 24 Jul 2010)
New Revision: 10393
Modified:
branches/branch-5-4/mapserver/HISTORY.TXT
branches/branch-5-4/mapserver/mapmssql2008.c
Log:
Backport the recent fixes in the MSSQL2008 driver (#3058, #3244)
Modified: branches/branch-5-4/mapserver/HISTORY.TXT
===================================================================
--- branches/branch-5-4/mapserver/HISTORY.TXT 2010-07-24 06:12:42 UTC (rev 10392)
+++ branches/branch-5-4/mapserver/HISTORY.TXT 2010-07-24 15:27:20 UTC (rev 10393)
@@ -13,6 +13,9 @@
Current Version:
----------------
+
+- Backport the recent fixes in the MSSQL2008 driver (#3058, #3244)
+
- Fix computation of shape bounds when the first line contains no points
(#3119)(fixes #3383)
Modified: branches/branch-5-4/mapserver/mapmssql2008.c
===================================================================
--- branches/branch-5-4/mapserver/mapmssql2008.c 2010-07-24 06:12:42 UTC (rev 10392)
+++ branches/branch-5-4/mapserver/mapmssql2008.c 2010-07-24 15:27:20 UTC (rev 10393)
@@ -97,6 +97,30 @@
layer->layerinfo = (void*) MSSQL2008layerinfo;
}
+void handleSQLError(layerObj *layer)
+{
+ SQLCHAR SqlState[6], Msg[SQL_MAX_MESSAGE_LENGTH];
+ SQLINTEGER NativeError;
+ SQLSMALLINT i, MsgLen;
+ SQLRETURN rc;
+ msMSSQL2008LayerInfo *layerinfo = getMSSQL2008LayerInfo(layer);
+
+ if (layerinfo == NULL)
+ return;
+
+ // Get the status records.
+ i = 1;
+ while ((rc = SQLGetDiagRec(SQL_HANDLE_STMT, layerinfo->conn->hstmt, i, SqlState, &NativeError,
+ Msg, sizeof(Msg), &MsgLen)) != SQL_NO_DATA)
+ {
+ if(layer->debug)
+ {
+ msDebug("SQLError: %s\n", Msg);
+ }
+ i++;
+ }
+}
+
/* remove white space */
/* dont send in empty strings or strings with just " " in them! */
static char* removeWhite(char *str)
@@ -176,7 +200,7 @@
if (conn->hstmt)
{
- SQLFreeHandle(SQL_HANDLE_DBC, conn->hstmt);
+ SQLFreeHandle(SQL_HANDLE_STMT, conn->hstmt);
}
if (conn->hdbc)
{
@@ -417,8 +441,6 @@
return MS_FAILURE;
}
- //setMSSQL2008LayerInfo(layer, layerinfo);
-
return MS_SUCCESS;
}
@@ -492,7 +514,7 @@
Plus 10 formatted doubles (15 digits of precision, a decimal point, a space/comma delimiter each = 17 chars each)
Plus SRID + comma - if SRID is a long...we'll be safe with 10 chars
*/
- char box3d[40 + 10 * 17 + 11];
+ char box3d[40 + 10 * 22 + 11];
char query_string_temp[10000]; /* Should be big enough */
int t;
@@ -568,14 +590,23 @@
columns_wanted = _strdup(buffer);
}
- sprintf(box3d, "Geometry::STGeomFromText('POLYGON((%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g))',%s)", /* %s.STSrid)", */
- rect.minx, rect.miny,
- rect.maxx, rect.miny,
- rect.maxx, rect.maxy,
- rect.minx, rect.maxy,
- rect.minx, rect.miny,
- layerinfo->user_srid
- );
+ if (rect.minx == rect.maxx || rect.miny == rect.maxy)
+ {
+ /* create point shape for rectangles with zero area */
+ sprintf(box3d, "Geometry::STGeomFromText('POINT(%.15g %.15g)',%s)", /* %s.STSrid)", */
+ rect.minx, rect.miny, layerinfo->user_srid);
+ }
+ else
+ {
+ sprintf(box3d, "Geometry::STGeomFromText('POLYGON((%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g))',%s)", /* %s.STSrid)", */
+ rect.minx, rect.miny,
+ rect.maxx, rect.miny,
+ rect.maxx, rect.maxy,
+ rect.minx, rect.maxy,
+ rect.minx, rect.miny,
+ layerinfo->user_srid
+ );
+ }
/* substitute token '!BOX!' in geom_table with the box3d - do an unlimited # of subs */
/* to not undo the work here, we need to make sure that data_source is malloc'd here */
@@ -1249,6 +1280,7 @@
/* Any error assume out of recordset bounds */
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO)
{
+ handleSQLError(layer);
return MS_DONE;
}
@@ -1263,29 +1295,41 @@
{
/* figure out how big the buffer needs to be */
rc = SQLGetData(layerinfo->conn->hstmt, t + 1, SQL_C_BINARY, dummyBuffer, 0, &needLen);
+ if (rc == SQL_ERROR)
+ handleSQLError(layer);
- /* 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);
+ if (rc == SQL_ERROR || rc == SQL_SUCCESS_WITH_INFO)
+ handleSQLError(layer);
- /* 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 */
{
/* Set up to request the size of the buffer needed */
rc = SQLGetData(layerinfo->conn->hstmt, layer->numitems + 1, SQL_C_BINARY, dummyBuffer, 0, &needLen);
+ if (rc == SQL_ERROR)
+ handleSQLError(layer);
/* allow space for coercion to geometry collection if needed*/
wkbTemp = (char*)malloc(needLen+9);
@@ -1301,6 +1345,8 @@
/* Grab the WKB */
rc = SQLGetData(layerinfo->conn->hstmt, layer->numitems + 1, SQL_C_BINARY, wkbBuffer, needLen, &retLen);
+ if (rc == SQL_ERROR || rc == SQL_SUCCESS_WITH_INFO)
+ handleSQLError(layer);
memcpy(&geomType, wkbBuffer + 1, 4);
@@ -1362,6 +1408,9 @@
/* Next get unique id for row - since the OID shouldn't be larger than a long we'll assume billions as a limit */
rc = SQLGetData(layerinfo->conn->hstmt, layer->numitems + 2, SQL_C_BINARY, oidBuffer, sizeof(oidBuffer) - 1, &retLen);
+ if (rc == SQL_ERROR || rc == SQL_SUCCESS_WITH_INFO)
+ handleSQLError(layer);
+
oidBuffer[retLen] = 0;
record_oid = strtol(oidBuffer, NULL, 10);
@@ -1436,7 +1485,7 @@
if(layer->numitems == 0)
{
- snprintf(buffer, sizeof(buffer), "%s.STAsBinary()", layerinfo->geom_column);
+ snprintf(buffer, sizeof(buffer), "%s.STAsBinary(), convert(varchar(20), %s)", layerinfo->geom_column, layerinfo->urid_name);
columns_wanted = _strdup(buffer);
}
else
@@ -1445,7 +1494,7 @@
snprintf(buffer + strlen(buffer), sizeof(buffer) - strlen(buffer), "convert(varchar(max), %s),", layer->items[t]);
}
- snprintf(buffer + strlen(buffer), sizeof(buffer) - strlen(buffer), "%s.STAsBinary()", layerinfo->geom_column);
+ snprintf(buffer + strlen(buffer), sizeof(buffer) - strlen(buffer), "%s.STAsBinary(), convert(varchar(20), %s)", layerinfo->geom_column, layerinfo->urid_name);
columns_wanted = _strdup(buffer);
}
@@ -1471,6 +1520,9 @@
return MS_FAILURE;
}
+ layerinfo->sql = query_str;
+ layerinfo->row_num = 0;
+
return msMSSQL2008LayerGetShapeRandom(layer, shape, &(layerinfo->row_num));
}
@@ -1858,7 +1910,7 @@
vtable->LayerWhichShapes = msMSSQL2008LayerWhichShapes;
vtable->LayerNextShape = msMSSQL2008LayerNextShape;
vtable->LayerGetShape = msMSSQL2008LayerGetShapeVT;
-
+
vtable->LayerClose = msMSSQL2008LayerClose;
vtable->LayerGetItems = msMSSQL2008LayerGetItems;
@@ -1891,7 +1943,7 @@
layer->vtable->LayerWhichShapes = msMSSQL2008LayerWhichShapes;
layer->vtable->LayerNextShape = msMSSQL2008LayerNextShape;
layer->vtable->LayerGetShape = msMSSQL2008LayerGetShapeVT;
-
+
layer->vtable->LayerClose = msMSSQL2008LayerClose;
layer->vtable->LayerGetItems = msMSSQL2008LayerGetItems;
More information about the mapserver-commits
mailing list