Skip to content

Commit c11e13a

Browse files
committed
Simplified msQueryByFilter() since FILTERs can *only* be MapServer expressions. (#5001)
1 parent b1c383b commit c11e13a

File tree

1 file changed

+15
-48
lines changed

1 file changed

+15
-48
lines changed

mapquery.c

+15-48
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,6 @@ int msQueryByFilter(mapObj *map)
669669
char *old_filteritem=NULL;
670670
expressionObj old_filter;
671671

672-
expressionObj merged_filter;
673-
674672
rectObj search_rect;
675673

676674
shapeObj shape;
@@ -745,24 +743,19 @@ int msQueryByFilter(mapObj *map)
745743
old_filteritem = lp->filteritem; /* cache the existing filter/filteritem */
746744
msInitExpression(&old_filter);
747745
msCopyExpression(&old_filter, &lp->filter);
748-
749-
lp->filteritem = map->query.filteritem; /* re-point lp->filteritem */
750-
// msCopyExpression(&lp->filter, &map->query.filter); /* apply new filter */
751-
746+
752747
if(msLayerSupportsCommonFilters(lp)) eval = MS_FALSE;
753748

754-
/*
755-
** Handle merging here for divers that can handle MapServer expressions. The function mergeFilters() creates
756-
** a MapServer logical expression and we want that right away. Other drivers are handled a bit later.
749+
/*
750+
** Set the lp->filter and lp->filteritem (may need to merge).
757751
*/
758-
if(msLayerSupportsCommonFilters(lp) && old_filter.string != NULL) {
759-
merged_filter = mergeFilters(&map->query.filter, map->query.filteritem, &old_filter, old_filteritem);
760-
if(!merged_filter.string) {
752+
lp->filteritem = map->query.filteritem; /* re-point lp->filteritem */
753+
if(old_filter.string != NULL) { /* need to merge filters to create one logical expression */
754+
lp->filter = mergeFilters(&map->query.filter, map->query.filteritem, &old_filter, old_filteritem);
755+
if(!lp->filter.string) {
761756
msSetError(MS_MISCERR, "Filter merge failed, able to process query.", "msQueryByFilter()");
762-
// something is wrong if we get here... **pointer being freed was not allocated**
763757
goto query_error;
764-
} else
765-
msCopyExpression(&lp->filter, &merged_filter);
758+
}
766759
} else {
767760
msCopyExpression(&lp->filter, &map->query.filter); /* apply new filter */
768761
}
@@ -773,32 +766,7 @@ int msQueryByFilter(mapObj *map)
773766

774767
if(eval == MS_TRUE) {
775768
status = msLayerTranslateFilter(lp, &lp->filter, lp->filteritem); /* sets lp->filter.native_string */
776-
if(status == MS_SUCCESS) {
777-
if(old_filter.string) { /* now we try to merge the old filter */
778-
status = msTokenizeExpression(&old_filter, lp->items, &(lp->numitems));
779-
if(status != MS_SUCCESS) goto query_error;
780-
status = msLayerTranslateFilter(lp, &old_filter, old_filteritem); /* sets old_filter.native_string */
781-
if(status == MS_SUCCESS) {
782-
lp->filter.native_string = msStringConcatenate(lp->filter.native_string, " AND ");
783-
lp->filter.native_string = msStringConcatenate(lp->filter.native_string, old_filter.native_string);
784-
} else {
785-
msSetError(MS_MISCERR, "Filter merge failed, able to process query.", "msQueryByFilter()");
786-
goto query_error;
787-
}
788-
}
789-
eval = MS_FALSE;
790-
} else {
791-
if(old_filter.string != NULL) {
792-
merged_filter = mergeFilters(&map->query.filter, map->query.filteritem, &old_filter, old_filteritem);
793-
if(!merged_filter.string) {
794-
msSetError(MS_MISCERR, "Filter merge failed, able to process query.", "msQueryByFilter()");
795-
goto query_error;
796-
} else
797-
msCopyExpression(&lp->filter, &merged_filter);
798-
} else {
799-
msCopyExpression(&lp->filter, &map->query.filter); /* apply new filter */
800-
}
801-
}
769+
if(status == MS_SUCCESS) eval = MS_FALSE; /* driver will apply the filter */
802770
}
803771

804772
search_rect = map->query.rect;
@@ -823,7 +791,6 @@ int msQueryByFilter(mapObj *map)
823791
if (lp->classgroup && lp->numclasses > 0)
824792
classgroup = msAllocateValidClassGroups(lp, &nclasses);
825793

826-
827794
if (lp->minfeaturesize > 0)
828795
minfeaturesize = Pix2LayerGeoref(map, lp, lp->minfeaturesize);
829796

@@ -891,7 +858,7 @@ int msQueryByFilter(mapObj *map)
891858

892859
if(classgroup) msFree(classgroup);
893860

894-
lp->filteritem = old_filteritem;
861+
lp->filteritem = old_filteritem; /* point back to original value */
895862
msCopyExpression(&lp->filter, &old_filter); /* restore old filter */
896863
msFreeExpression(&old_filter);
897864

@@ -910,11 +877,11 @@ int msQueryByFilter(mapObj *map)
910877
return MS_FAILURE;
911878

912879
query_error:
913-
//msFree(lp->filteritem);
914-
//lp->filteritem = old_filteritem;
915-
//msCopyExpression(&lp->filter, &old_filter); /* restore old filter */
916-
//msFreeExpression(&old_filter);
917-
//msLayerClose(lp);
880+
// msFree(lp->filteritem);
881+
// lp->filteritem = old_filteritem;
882+
// msCopyExpression(&lp->filter, &old_filter); /* restore old filter */
883+
// msFreeExpression(&old_filter);
884+
// msLayerClose(lp);
918885
return MS_FAILURE;
919886
}
920887

0 commit comments

Comments
 (0)