Issue
If a layer has both a PostGIS NATIVE_FILTER in PROCESSING and wfs_use_default_extent_for_getfeature set to false, the resulting SQL for a WFS filter request is missing an AND between the WHERE clauses.
Error response: "msWFSGetFeature(): WFS server error. FLTApplyFilterToLayer() failed
msPostGISLayerWhichShapes(): Query error. Error executing query. Check server logs"
Error log:
msPostGISLayerWhichShapes(): Error (ERROR: syntax error at or near "("
LINE 1: ...ROM public.example WHERE (("name"::text = 'test'))(num=1) LI...
^
) executing query: SELECT "id"::text,"name"::text,"num"::text,ST_AsBinary(("geom"),'NDR') as geom,"id"::text FROM public.example WHERE (("name"::text = 'test'))(num=1) LIMIT 11
msPostGISLayerWhichShapes(): Query error. Error executing query. Check server logs
msWFSGetFeature(): WFS server error. FLTApplyFilterToLayer() failed
Invalid SQL from above:
SELECT "id"::text,"name"::text,"num"::text,ST_AsBinary(("geom"),'NDR') as geom,"id"::text
FROM public.example
WHERE (("name"::text = 'test'))(num=1) LIMIT 11
Though the SQL is correctly generated when setting wfs_use_default_extent_for_getfeature=true (default):
SELECT "id"::text,"name"::text,"num"::text,ST_AsBinary(("geom"),'NDR') as geom,"id"::text
FROM public.example
WHERE ST_Intersects("geom", ST_GeomFromText('POLYGON((-20037508.3427892 -20037508.3427892,-20037508.3427892 20037508.3427892,20037508.3427892 20037508.3427892,20037508.3427892 -20037508.3427892,-20037508.3427892 -20037508.3427892))',3857))
AND (("name"::text = 'test')) AND (num='abc') LIMIT 11
This has been tested with Mapserver 8.6.2 (branch-8-6). It used to work with Mapserver 8.2.2.
Example Mapfile and requests
Mapfile
MAP
NAME example_map
STATUS ON
EXTENT -180 -90 180 90
PROJECTION
"init=epsg:4326"
END
WEB
METADATA
"wfs_enable_request" "*"
"wfs_onlineresource" "http://localhost/example?"
END
END
LAYER
NAME example
METADATA
"gml_featureid" "id"
"gml_include_items" "all"
"wfs_use_default_extent_for_getfeature" "false"
END
STATUS ON
TYPE POINT
CONNECTIONTYPE postgis
CONNECTION "dbname='devdb' host=postgis port=5432 user='xxxx' password='xxxx' sslmode=disable"
DATA "geom FROM public.example USING UNIQUE id USING SRID=3857"
PROCESSING "NATIVE_FILTER=num=1"
PROJECTION
"init=epsg:3857"
END
END
END
Example PostGIS table
CREATE TABLE public.example
(
id serial,
name character varying(32),
num integer,
geom geometry(Point,3857),
CONSTRAINT example_pkey PRIMARY KEY (id)
);
CREATE INDEX sidx_example_geom
ON public.example
USING gist
(geom);
INSERT INTO public.example (name, num, geom)
VALUES('test', '1', ST_GeomFromText('POINT(950758.0 6003950.0)', 3857));
Example WFS GetFeature requests:
- without filter:
http://localhost/example?SERVICE=WFS&VERSION=2.0.0&REQUEST=GetFeature&TYPENAME=example&MAXFEATURES=10
- with WFS filter:
http://localhost/example?SERVICE=WFS&VERSION=2.0.0&REQUEST=GetFeature&TYPENAME=example&MAXFEATURES=10&FILTER=<Filter><PropertyIsEqualTo><PropertyName>name</PropertyName><Literal>test</Literal></PropertyIsEqualTo></Filter>
Expected behaviour
The resulting SQL for a WFS filter request should always add an AND between the WHERE clauses for the WFS filter and the NATIVE_FILTER:
SELECT "id"::text,"name"::text,"num"::text,ST_AsBinary(("geom"),'NDR') as geom,"id"::text
FROM public.example
WHERE (("name"::text = 'test')) AND (num=1) LIMIT 11
Issue
If a layer has both a PostGIS
NATIVE_FILTERinPROCESSINGandwfs_use_default_extent_for_getfeatureset tofalse, the resulting SQL for a WFS filter request is missing anANDbetween the WHERE clauses.Error response: "msWFSGetFeature(): WFS server error. FLTApplyFilterToLayer() failed
msPostGISLayerWhichShapes(): Query error. Error executing query. Check server logs"
Error log:
Invalid SQL from above:
Though the SQL is correctly generated when setting
wfs_use_default_extent_for_getfeature=true(default):This has been tested with Mapserver 8.6.2 (
branch-8-6). It used to work with Mapserver 8.2.2.Example Mapfile and requests
Mapfile
MAP NAME example_map STATUS ON EXTENT -180 -90 180 90 PROJECTION "init=epsg:4326" END WEB METADATA "wfs_enable_request" "*" "wfs_onlineresource" "http://localhost/example?" END END LAYER NAME example METADATA "gml_featureid" "id" "gml_include_items" "all" "wfs_use_default_extent_for_getfeature" "false" END STATUS ON TYPE POINT CONNECTIONTYPE postgis CONNECTION "dbname='devdb' host=postgis port=5432 user='xxxx' password='xxxx' sslmode=disable" DATA "geom FROM public.example USING UNIQUE id USING SRID=3857" PROCESSING "NATIVE_FILTER=num=1" PROJECTION "init=epsg:3857" END END ENDExample PostGIS table
Example WFS GetFeature requests:
http://localhost/example?SERVICE=WFS&VERSION=2.0.0&REQUEST=GetFeature&TYPENAME=example&MAXFEATURES=10http://localhost/example?SERVICE=WFS&VERSION=2.0.0&REQUEST=GetFeature&TYPENAME=example&MAXFEATURES=10&FILTER=<Filter><PropertyIsEqualTo><PropertyName>name</PropertyName><Literal>test</Literal></PropertyIsEqualTo></Filter>Expected behaviour
The resulting SQL for a WFS filter request should always add an
ANDbetween the WHERE clauses for the WFS filter and theNATIVE_FILTER: