Skip to content
Permalink
Browse files
msMSSQL2008LayerGetExtent doesn't consider NATIVE_FILTER or translate…
…d filter (#6076)
  • Loading branch information
github-actions[bot] committed May 28, 2020
1 parent 9b93a70 commit 886398e175bcdd86cdd880fbfc761e4e0e0ea00a
Showing 1 changed file with 33 additions and 38 deletions.
@@ -1122,6 +1122,24 @@ static int getMSSQLMajorVersion(layerObj* layer)
return layerinfo->mssqlversion_major;
}

static int addFilter(layerObj *layer, char **query)
{
if (layer->filter.native_string) {
(*query) = msStringConcatenate(*query, " WHERE (");
(*query) = msStringConcatenate(*query, layer->filter.native_string);
(*query) = msStringConcatenate(*query, ")");
return MS_TRUE;
}
else if (msLayerGetProcessingKey(layer, "NATIVE_FILTER") != NULL) {
(*query) = msStringConcatenate(*query, " WHERE (");
(*query) = msStringConcatenate(*query, msLayerGetProcessingKey(layer, "NATIVE_FILTER"));
(*query) = msStringConcatenate(*query, ")");
return MS_TRUE;
}

return MS_FALSE;
}

/* Get the layer extent as specified in the mapfile or a largest area */
/* covering all features */
int msMSSQL2008LayerGetExtent(layerObj *layer, rectObj *extent)
@@ -1167,6 +1185,10 @@ int msMSSQL2008LayerGetExtent(layerObj *layer, rectObj *extent)
}
query = msStringConcatenate(query, ") AS extentcol FROM ");
query = msStringConcatenate(query, layerinfo->geom_table);

/* adding attribute filter */
addFilter(layer, &query);

query = msStringConcatenate(query, ") SELECT extentcol.STPointN(1).STX, extentcol.STPointN(1).STY, extentcol.STPointN(3).STX, extentcol.STPointN(3).STY FROM extent");
}
else {
@@ -1183,6 +1205,10 @@ int msMSSQL2008LayerGetExtent(layerObj *layer, rectObj *extent)
}
query = msStringConcatenate(query, ".STEnvelope() as envelope from ");
query = msStringConcatenate(query, layerinfo->geom_table);

/* adding attribute filter */
addFilter(layer, &query);

query = msStringConcatenate(query, "), CORNERS as (SELECT envelope.STPointN(1) as point from ENVELOPE UNION ALL select envelope.STPointN(3) from ENVELOPE) SELECT MIN(point.STX), MIN(point.STY), MAX(point.STX), MAX(point.STY) FROM CORNERS");
}

@@ -1204,7 +1230,7 @@ int msMSSQL2008LayerGetExtent(layerObj *layer, rectObj *extent)
}

rc = SQLGetData(layerinfo->conn->hstmt, 1, SQL_C_CHAR, result_data, sizeof(result_data), &retLen);
if (rc == SQL_ERROR) {
if (rc == SQL_ERROR || retLen < 0) {
msSetError(MS_QUERYERR, "Failed to get MinX value", "msMSSQL2008LayerGetExtent()");
return MS_FAILURE;
}
@@ -1214,7 +1240,7 @@ int msMSSQL2008LayerGetExtent(layerObj *layer, rectObj *extent)
extent->minx = atof(result_data);

rc = SQLGetData(layerinfo->conn->hstmt, 2, SQL_C_CHAR, result_data, sizeof(result_data), &retLen);
if (rc == SQL_ERROR) {
if (rc == SQL_ERROR || retLen < 0) {
msSetError(MS_QUERYERR, "Failed to get MinY value", "msMSSQL2008LayerGetExtent()");
return MS_FAILURE;
}
@@ -1224,7 +1250,7 @@ int msMSSQL2008LayerGetExtent(layerObj *layer, rectObj *extent)
extent->miny = atof(result_data);

rc = SQLGetData(layerinfo->conn->hstmt, 3, SQL_C_CHAR, result_data, sizeof(result_data), &retLen);
if (rc == SQL_ERROR) {
if (rc == SQL_ERROR || retLen < 0) {
msSetError(MS_QUERYERR, "Failed to get MaxX value", "msMSSQL2008LayerGetExtent()");
return MS_FAILURE;
}
@@ -1234,7 +1260,7 @@ int msMSSQL2008LayerGetExtent(layerObj *layer, rectObj *extent)
extent->maxx = atof(result_data);

rc = SQLGetData(layerinfo->conn->hstmt, 4, SQL_C_CHAR, result_data, sizeof(result_data), &retLen);
if (rc == SQL_ERROR) {
if (rc == SQL_ERROR || retLen < 0) {
msSetError(MS_QUERYERR, "Failed to get MaxY value", "msMSSQL2008LayerGetExtent()");
return MS_FAILURE;
}
@@ -1271,16 +1297,7 @@ int msMSSQL2008LayerGetNumFeatures(layerObj *layer)
query = msStringConcatenate(query, layerinfo->geom_table);

/* adding attribute filter */
if (layer->filter.native_string) {
query = msStringConcatenate(query, " WHERE (");
query = msStringConcatenate(query, layer->filter.native_string);
query = msStringConcatenate(query, ")");
}
else if (msLayerGetProcessingKey(layer, "NATIVE_FILTER") != NULL) {
query = msStringConcatenate(query, " WHERE (");
query = msStringConcatenate(query, msLayerGetProcessingKey(layer, "NATIVE_FILTER"));
query = msStringConcatenate(query, ")");
}
addFilter(layer, &query);

if (!executeSQL(layerinfo->conn, query)) {
msFree(query);
@@ -1508,18 +1525,7 @@ static int prepare_database(layerObj *layer, rectObj rect, char **query_string)
}

/* adding attribute filter */
if (layer->filter.native_string) {
query = msStringConcatenate(query, " WHERE (");
query = msStringConcatenate(query, layer->filter.native_string);
query = msStringConcatenate(query, ")");
hasFilter = MS_TRUE;
}
else if (msLayerGetProcessingKey(layer, "NATIVE_FILTER") != NULL) {
query = msStringConcatenate(query, " WHERE (");
query = msStringConcatenate(query, msLayerGetProcessingKey(layer, "NATIVE_FILTER"));
query = msStringConcatenate(query, ")");
hasFilter = MS_TRUE;
}
hasFilter = addFilter(layer, &query);

if( bIsValidRect ) {
/* adding spatial filter */
@@ -2583,18 +2589,7 @@ int msMSSQL2008LayerGetShapeCount(layerObj *layer, rectObj rect, projectionObj *
query = msStringConcatenate(query, layerinfo->geom_table);

/* adding attribute filter */
if (layer->filter.native_string) {
query = msStringConcatenate(query, " WHERE (");
query = msStringConcatenate(query, layer->filter.native_string);
query = msStringConcatenate(query, ")");
hasFilter = MS_TRUE;
}
else if (msLayerGetProcessingKey(layer, "NATIVE_FILTER") != NULL) {
query = msStringConcatenate(query, " WHERE (");
query = msStringConcatenate(query, msLayerGetProcessingKey(layer, "NATIVE_FILTER"));
query = msStringConcatenate(query, ")");
hasFilter = MS_TRUE;
}
hasFilter = addFilter(layer, &query);

if( bIsValidRect ) {
/* adding spatial filter */

0 comments on commit 886398e

Please sign in to comment.