Skip to content

Commit

Permalink
Manual backport of master fix for PG mixed geometries
Browse files Browse the repository at this point in the history
Plus a new test case, fixes #35367 and #38565

The new test case needs forward port to master
  • Loading branch information
elpaso authored and nyalldawson committed Oct 23, 2020
1 parent 5266b7f commit b0bdb3f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -3658,7 +3658,7 @@ bool QgsPostgresProvider::getGeometryDetails()
}
}

QString detectedType = mRequestedGeomType == QgsWkbTypes::Unknown ? QString() : QgsPostgresConn::postgisWkbTypeName( mRequestedGeomType );
QString detectedType;
QString detectedSrid = mRequestedSrid;
if ( !schemaName.isEmpty() )
{
Expand All @@ -3674,8 +3674,7 @@ bool QgsPostgresProvider::getGeometryDetails()

if ( result.PQntuples() == 1 )
{
QString dt = result.PQgetvalue( 0, 0 );
if ( dt != "GEOMETRY" ) detectedType = dt;
detectedType = result.PQgetvalue( 0, 0 );

QString dim = result.PQgetvalue( 0, 2 );
if ( dim == QLatin1String( "3" ) && !detectedType.endsWith( 'M' ) )
Expand Down
7 changes: 7 additions & 0 deletions tests/src/python/test_provider_postgres.py
Expand Up @@ -1934,6 +1934,13 @@ def testAddFeature(self):
self.assertFalse(l.dataProvider().addFeatures([f1, f2]),
'Provider reported no AddFeatures capability, but returned true to addFeatures')

def test_postgis_geometry_filter(self):
"""Make sure the postgres provider only returns one matching geometry record and no polygons etc."""
vl = QgsVectorLayer(self.dbconn + ' srid=4326 type=POINT table="qgis_test"."geometries_table" (geom) sql=', 'test', 'postgres')

ids = [f.id() for f in vl.getFeatures()]
self.assertEqual(ids, [2])


if __name__ == '__main__':
unittest.main()

0 comments on commit b0bdb3f

Please sign in to comment.