Permalink
Browse files

[OGR] Potential fix for SELECT ... FROM a Spatialite view (probably fix

  • Loading branch information...
rouault committed Jul 30, 2016
1 parent 91c7b85 commit 375a7aea204eb1eb40327a53592a9e1f9b057ead
View
@@ -1729,6 +1729,7 @@ static int msOGRFileWhichShapes(layerObj *layer, rectObj rect, msOGRFileInfo *ps
bIsOKForSQLCompose = (hFeature != NULL);
if( hFeature )
{
+ select = msStrdup(psInfo->pszLayerDef);
msFree(pszSpatialFilterTableName);
pszSpatialFilterTableName = msStrdup( OGR_F_GetFieldAsString( hFeature, 0 ) );
pszRowId = msStrdup( OGR_F_GetFieldAsString( hFeature, 1 ) );
@@ -1797,7 +1798,7 @@ static int msOGRFileWhichShapes(layerObj *layer, rectObj rect, msOGRFileInfo *ps
// side evaluation by unsetting it.
if( !bIsOKForSQLCompose && dialect != NULL && layer->filter.native_string )
{
- msDebug("msOGRFileWhichShapes(): unsetting native_string\n");
+ msDebug("msOGRFileWhichShapes(): unsetting native_string. Falling back to MapServer only evaluation\n");
msFree( layer->filter.native_string );
layer->filter.native_string = NULL;
dialect = NULL;
@@ -0,0 +1,38 @@
+Content-Type: text/xml; charset=UTF-8
+
+<?xml version='1.0' encoding="UTF-8" ?>
+<wfs:FeatureCollection
+ xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
+ xmlns:wfs="http://www.opengis.net/wfs"
+ xmlns:gml="http://www.opengis.net/gml"
+ xmlns:ogc="http://www.opengis.net/ogc"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd
+ http://mapserver.gis.umn.edu/mapserver http://localhost/path/to/wfs_simple?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=towns_select&amp;OUTPUTFORMAT=XMLSCHEMA">
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:32632">
+ <gml:coordinates>643513.360000,4896928.190000 643513.360000,4896928.190000</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+<!-- WARNING: FeatureId item 'ID' not found in typename 'towns_select'. -->
+ <gml:featureMember>
+ <ms:towns_select>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:32632">
+ <gml:coordinates>643513.360000,4896928.190000 643513.360000,4896928.190000</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <ms:msGeometry>
+ <gml:Point srsName="EPSG:32632">
+ <gml:coordinates>643513.360000,4896928.190000</gml:coordinates>
+ </gml:Point>
+ </ms:msGeometry>
+ <ms:name>Fanano</ms:name>
+ <ms:peoples>2910</ms:peoples>
+ <ms:localcounc>1</ms:localcounc>
+ <ms:county>0</ms:county>
+ <ms:region>0</ms:region>
+ </ms:towns_select>
+ </gml:featureMember>
+</wfs:FeatureCollection>
+
@@ -0,0 +1,38 @@
+Content-Type: text/xml; charset=UTF-8
+
+<?xml version='1.0' encoding="UTF-8" ?>
+<wfs:FeatureCollection
+ xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
+ xmlns:wfs="http://www.opengis.net/wfs"
+ xmlns:gml="http://www.opengis.net/gml"
+ xmlns:ogc="http://www.opengis.net/ogc"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd
+ http://mapserver.gis.umn.edu/mapserver http://localhost/path/to/wfs_simple?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=myview_select&amp;OUTPUTFORMAT=XMLSCHEMA">
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:32632">
+ <gml:coordinates>643513.360000,4896928.190000 643513.360000,4896928.190000</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+<!-- WARNING: FeatureId item 'ID' not found in typename 'myview_select'. -->
+ <gml:featureMember>
+ <ms:myview_select>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:32632">
+ <gml:coordinates>643513.360000,4896928.190000 643513.360000,4896928.190000</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <ms:msGeometry>
+ <gml:Point srsName="EPSG:32632">
+ <gml:coordinates>643513.360000,4896928.190000</gml:coordinates>
+ </gml:Point>
+ </ms:msGeometry>
+ <ms:name>Fanano</ms:name>
+ <ms:peoples>2910</ms:peoples>
+ <ms:localcounc>1</ms:localcounc>
+ <ms:county>0</ms:county>
+ <ms:region>0</ms:region>
+ </ms:myview_select>
+ </gml:featureMember>
+</wfs:FeatureCollection>
+
@@ -0,0 +1,38 @@
+Content-Type: text/xml; charset=UTF-8
+
+<?xml version='1.0' encoding="UTF-8" ?>
+<wfs:FeatureCollection
+ xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
+ xmlns:wfs="http://www.opengis.net/wfs"
+ xmlns:gml="http://www.opengis.net/gml"
+ xmlns:ogc="http://www.opengis.net/ogc"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd
+ http://mapserver.gis.umn.edu/mapserver http://localhost/path/to/wfs_simple?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=select_too_complex_for_optim&amp;OUTPUTFORMAT=XMLSCHEMA">
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:32632">
+ <gml:coordinates>643513.360000,4896928.190000 643513.360000,4896928.190000</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+<!-- WARNING: FeatureId item 'ID' not found in typename 'select_too_complex_for_optim'. -->
+ <gml:featureMember>
+ <ms:select_too_complex_for_optim>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:32632">
+ <gml:coordinates>643513.360000,4896928.190000 643513.360000,4896928.190000</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <ms:msGeometry>
+ <gml:Point srsName="EPSG:32632">
+ <gml:coordinates>643513.360000,4896928.190000</gml:coordinates>
+ </gml:Point>
+ </ms:msGeometry>
+ <ms:name>Fanano</ms:name>
+ <ms:peoples>2910</ms:peoples>
+ <ms:localcounc>1</ms:localcounc>
+ <ms:county>0</ms:county>
+ <ms:region>0</ms:region>
+ </ms:select_too_complex_for_optim>
+ </gml:featureMember>
+</wfs:FeatureCollection>
+
@@ -64,6 +64,16 @@
#
# Same as wfs_ogr_native_sql_02 on a view
# RUN_PARMS: wfs_ogr_native_sql_33.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=myview&OUTPUTFORMAT=GML2&FILTER=<Filter><AND><BBOX><PropertyName>Geometry</PropertyName><Box srsName='EPSG:32632'><coordinates>643159,4877386 696879,4898059</coordinates></Box></BBOX><PropertyIsEqualTo><PropertyName>name</PropertyName><Literal>Fanano</Literal></PropertyIsEqualTo></AND></Filter>" > [RESULT]
+#
+# Same as wfs_ogr_native_sql_02 on a "SELECT ... FROM " a table
+# RUN_PARMS: wfs_ogr_native_sql_34.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=towns_select&OUTPUTFORMAT=GML2&FILTER=<Filter><AND><BBOX><PropertyName>Geometry</PropertyName><Box srsName='EPSG:32632'><coordinates>643159,4877386 696879,4898059</coordinates></Box></BBOX><PropertyIsEqualTo><PropertyName>name</PropertyName><Literal>Fanano</Literal></PropertyIsEqualTo></AND></Filter>" > [RESULT]
+#
+# Same as wfs_ogr_native_sql_02 on a "SELECT ... FROM " a_view
+# RUN_PARMS: wfs_ogr_native_sql_35.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=myview_select&OUTPUTFORMAT=GML2&FILTER=<Filter><AND><BBOX><PropertyName>Geometry</PropertyName><Box srsName='EPSG:32632'><coordinates>643159,4877386 696879,4898059</coordinates></Box></BBOX><PropertyIsEqualTo><PropertyName>name</PropertyName><Literal>Fanano</Literal></PropertyIsEqualTo></AND></Filter>" > [RESULT]
+#
+# Same as wfs_ogr_native_sql_02 on a SELECT too complex to be edited, so falling back to client side evaluation
+# RUN_PARMS: wfs_ogr_native_sql_36.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=select_too_complex_for_optim&OUTPUTFORMAT=GML2&FILTER=<Filter><AND><BBOX><PropertyName>Geometry</PropertyName><Box srsName='EPSG:32632'><coordinates>643159,4877386 696879,4898059</coordinates></Box></BBOX><PropertyIsEqualTo><PropertyName>name</PropertyName><Literal>Fanano</Literal></PropertyIsEqualTo></AND></Filter>" > [RESULT]
+#
MAP
@@ -121,6 +131,28 @@ LAYER
TEMPLATE "wfs_ogr_native_sql.map"
END # Layer
+LAYER
+ NAME towns_select
+ DATA "SELECT * FROM towns"
+ CONNECTIONTYPE OGR
+ CONNECTION "./data/db.sqlite"
+ PROCESSING "NATIVE_SQL=YES"
+ METADATA
+ "ows_title" "towns_select"
+ "wfs_featureid" "ID"
+ "gml_include_items" "all"
+ "gml_types" "auto"
+ "wfs_getfeature_formatlist" "ogrgml"
+ END
+ TYPE POINT
+ STATUS ON
+ PROJECTION
+ "init=epsg:32632"
+ END
+
+ TEMPLATE "wfs_ogr_native_sql.map"
+END # Layer
+
LAYER
NAME myview
DATA myview
@@ -143,4 +175,48 @@ LAYER
TEMPLATE "wfs_ogr_native_sql.map"
END # Layer
+LAYER
+ NAME myview_select
+ DATA "SELECT * FROM myview"
+ CONNECTIONTYPE OGR
+ CONNECTION "./data/db.sqlite"
+ PROCESSING "NATIVE_SQL=YES"
+ METADATA
+ "ows_title" "myview_select"
+ "wfs_featureid" "ID"
+ "gml_include_items" "all"
+ "gml_types" "auto"
+ "wfs_getfeature_formatlist" "ogrgml"
+ END
+ TYPE POINT
+ STATUS ON
+ PROJECTION
+ "init=epsg:32632"
+ END
+
+ TEMPLATE "wfs_ogr_native_sql.map"
+END # Layer
+
+LAYER
+ NAME select_too_complex_for_optim
+ DATA "SELECT * FROM towns WHERE 1"
+ CONNECTIONTYPE OGR
+ CONNECTION "./data/db.sqlite"
+ PROCESSING "NATIVE_SQL=YES"
+ METADATA
+ "ows_title" "select_too_complex_for_optim"
+ "wfs_featureid" "ID"
+ "gml_include_items" "all"
+ "gml_types" "auto"
+ "wfs_getfeature_formatlist" "ogrgml"
+ END
+ TYPE POINT
+ STATUS ON
+ PROJECTION
+ "init=epsg:32632"
+ END
+
+ TEMPLATE "wfs_ogr_native_sql.map"
+END # Layer
+
END # Map File

0 comments on commit 375a7ae

Please sign in to comment.