[mapserver-commits] r8837 - trunk/mapserver
svn at osgeo.org
svn at osgeo.org
Thu Mar 26 15:35:57 EDT 2009
Author: dmorissette
Date: 2009-03-26 15:35:57 -0400 (Thu, 26 Mar 2009)
New Revision: 8837
Modified:
trunk/mapserver/mapquery.c
Log:
Properly reset filter/filteritem when queryByAttribute() fails (#2808)
Modified: trunk/mapserver/mapquery.c
===================================================================
--- trunk/mapserver/mapquery.c 2009-03-26 14:32:44 UTC (rev 8836)
+++ trunk/mapserver/mapquery.c 2009-03-26 19:35:57 UTC (rev 8837)
@@ -248,6 +248,25 @@
return _msQueryByIndex(map, qlayer, tileindex, shapeindex, 0);
}
+void msRestoreOldFilter(layerObj *lp, int old_filtertype, char *old_filteritem, char *old_filterstring)
+{
+ freeExpression(&(lp->filter));
+ if(lp->filteritem) {
+ free(lp->filteritem);
+ lp->filteritem = NULL;
+ lp->filteritemindex = -1;
+ }
+
+ /* restore any previously defined filter */
+ if(old_filterstring) {
+ lp->filter.type = old_filtertype;
+ lp->filter.string = old_filterstring;
+ if(old_filteritem) {
+ lp->filteritem = old_filteritem;
+ }
+ }
+}
+
int msQueryByAttributes(mapObj *map, int qlayer, char *qitem, char *qstring, int mode)
{
layerObj *lp;
@@ -310,11 +329,19 @@
/* open this layer */
status = msLayerOpen(lp);
- if(status != MS_SUCCESS) return(MS_FAILURE);
+ if(status != MS_SUCCESS) {
+ /* Manually reset the filter */
+ msRestoreOldFilter(lp,old_filtertype,old_filteritem,old_filterstring);
+ return(MS_FAILURE);
+ }
/* build item list (no annotation) */
status = msLayerWhichItems(lp, MS_TRUE, MS_FALSE, NULL);
- if(status != MS_SUCCESS) return(MS_FAILURE);
+ if(status != MS_SUCCESS) {
+ /* Manually reset the filter */
+ msRestoreOldFilter(lp,old_filtertype,old_filteritem,old_filterstring);
+ return(MS_FAILURE);
+ }
/* identify target shapes */
searchrect = map->extent;
@@ -327,10 +354,14 @@
status = msLayerWhichShapes(lp, searchrect);
if(status == MS_DONE) { /* no overlap */
+ /* Manually reset the filter */
+ msRestoreOldFilter(lp,old_filtertype,old_filteritem,old_filterstring);
msLayerClose(lp);
msSetError(MS_NOTFOUND, "No matching record(s) found, layer and area of interest do not overlap.", "msQueryByAttributes()");
return(MS_FAILURE);
} else if(status != MS_SUCCESS) {
+ /* Manually reset the filter */
+ msRestoreOldFilter(lp,old_filtertype,old_filteritem,old_filterstring);
msLayerClose(lp);
return(MS_FAILURE);
}
@@ -383,27 +414,15 @@
if (classgroup)
msFree(classgroup);
- if(status != MS_DONE) return(MS_FAILURE);
-
- /* the FILTER set was just temporary, clean up here */
- freeExpression(&(lp->filter));
- if(lp->filteritem) {
- free(lp->filteritem);
- lp->filteritem = NULL;
- lp->filteritemindex = -1;
+ if(status != MS_DONE){
+ /* Manually reset the filter */
+ msRestoreOldFilter(lp,old_filtertype,old_filteritem,old_filterstring);
+ return(MS_FAILURE);
}
-
- /* restore any previously defined filter */
- if(old_filterstring) {
- lp->filter.type = old_filtertype;
- lp->filter.string = strdup(old_filterstring);
- free(old_filterstring);
- if(old_filteritem) {
- lp->filteritem = strdup(old_filteritem);
- free(old_filteritem);
- }
- }
+ /* Manually reset the filter */
+ msRestoreOldFilter(lp,old_filtertype,old_filteritem,old_filterstring);
+
msLayerClose(lp);
/* was anything found? */
More information about the mapserver-commits
mailing list