Skip to content

Commit

Permalink
Merge pull request #35367 from m-kuhn/requested_type_does_not_take_pr…
Browse files Browse the repository at this point in the history
…ecedence

[postgres] Do not overwrite detected type with requested type
  • Loading branch information
m-kuhn committed Mar 26, 2020
2 parents 8b965e3 + 1924f57 commit 2dec5a0
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 @@ -3643,7 +3643,7 @@ bool QgsPostgresProvider::getGeometryDetails()
}
}

QString detectedType = mRequestedGeomType == QgsWkbTypes::Unknown ? QString() : QgsPostgresConn::postgisWkbTypeName( mRequestedGeomType );
QString detectedType;
QString detectedSrid = mRequestedSrid;
if ( !schemaName.isEmpty() )
{
Expand All @@ -3659,8 +3659,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_qgsproviderconnection_postgres.py
Expand Up @@ -69,6 +69,13 @@ def test_postgis_connections_from_uri(self):
rl = QgsRasterLayer(conn.tableUri('qgis_test', 'Raster1'), 'r1', 'postgresraster')
self.assertTrue(rl.isValid())

def test_postgis_geometry_filter(self):
"""Make sure the postgres provider only returns one matching geometry record and no polygons etc."""
vl = QgsVectorLayer(self.postgres_conn + ' 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])

def test_postgis_table_uri(self):
"""Create a connection from a layer uri and create a table URI"""

Expand Down

0 comments on commit 2dec5a0

Please sign in to comment.