Skip to content

Commit

Permalink
OGR GPKG: fix potential SELECT ambiguity for 'id' column (fixes #5858)
Browse files Browse the repository at this point in the history
When using a GeoPackage table that has a 'id' column, in some circumstances,
MapServer composes internally a SELECT statement, but fails to prefix the
id column with the table name, which causes an ambiguity when joining with
the spatial index RTree table that has also a id column.
  • Loading branch information
rouault committed Sep 9, 2019
1 parent 0f31eda commit e3c6d47
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mapogr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ typedef struct ms_ogr_file_info_t {
char *pszRowId;
int bIsOKForSQLCompose;
bool bHasSpatialIndex; // used only for spatialite for now
char* pszTablePrefix; // prefix to qualify field names. used only for spatialite for now when a join is done for spatial filtering.
char* pszTablePrefix; // prefix to qualify field names. used only for spatialite & gpkg for now when a join is done for spatial filtering.

int bPaging;

Expand Down Expand Up @@ -1386,6 +1386,7 @@ msOGRFileOpen(layerObj *layer, const char *connection )
if( have_gpkg_spatialite )
{
psInfo->pszMainTableName = msStrdup( OGR_L_GetName(hLayer) );
psInfo->pszTablePrefix = msStrdup( psInfo->pszMainTableName );
psInfo->pszSpatialFilterTableName = msStrdup( OGR_L_GetName(hLayer) );
psInfo->pszSpatialFilterGeometryColumn = msStrdup( OGR_L_GetGeometryColumn(hLayer) );
psInfo->dialect = "GPKG";
Expand Down
Binary file added msautotest/wxs/data/test.gpkg
Binary file not shown.
34 changes: 34 additions & 0 deletions msautotest/wxs/expected/wfs_ogr_gpkg_issue_5858.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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=test&amp;OUTPUTFORMAT=XMLSCHEMA">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>2.000000,49.000000 2.000000,49.000000</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<gml:featureMember>
<ms:test fid="test.1">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>2.000000,49.000000 2.000000,49.000000</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<ms:msGeometry>
<gml:Point srsName="EPSG:4326">
<gml:coordinates>2.000000,49.000000</gml:coordinates>
</gml:Point>
</ms:msGeometry>
<ms:id>1</ms:id>
<ms:name>some place in France</ms:name>
</ms:test>
</gml:featureMember>
</wfs:FeatureCollection>

63 changes: 63 additions & 0 deletions msautotest/wxs/wfs_ogr_gpkg.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#
# Test OGR GeoPackage support
#
# REQUIRES: SUPPORTS=WFS INPUT=OGR
#
# RUN_PARMS: wfs_ogr_gpkg_issue_5858.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=test&BBOX=-180,-90,180,90&MAXFEATURES=1" > [RESULT]

MAP

NAME WFS_OGR_GPKG
STATUS ON
SIZE 400 300
EXTENT 6 30 21 50
UNITS METERS
IMAGECOLOR 255 255 255

#
# Start of web interface definition
#

WEB

IMAGEPATH "tmp/"
IMAGEURL "/ms_tmp/"

METADATA
"wfs_title" "Test simple wfs"
"wfs_onlineresource" "http://localhost/path/to/wfs_simple?"
"wfs_srs" "EPSG:4326"
"wfs_enable_request" "*"
END
END

PROJECTION
"+proj=latlong +datum=WGS84"
END

#
# Start of layer definitions
#

LAYER

NAME test
DATA test
CONNECTIONTYPE OGR
CONNECTION "./data/test.gpkg"
METADATA
"ows_title" "test"
"wfs_featureid" "id"
"gml_include_items" "all"
"gml_types" "auto"
END
TYPE POINT
STATUS ON
PROJECTION
"init=epsg:4326"
END

TEMPLATE "wfs_ogr_gpkg.map"
END # Layer

END # Map File

0 comments on commit e3c6d47

Please sign in to comment.