Skip to content

Commit

Permalink
[postgres] Do not overwrite detected type with requested type
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored and nyalldawson committed Mar 27, 2020
1 parent 89c49b2 commit 0c36152
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 @@ -3630,7 +3630,7 @@ bool QgsPostgresProvider::getGeometryDetails()
}
}

QString detectedType = mRequestedGeomType == QgsWkbTypes::Unknown ? QString() : QgsPostgresConn::postgisWkbTypeName( mRequestedGeomType );
QString detectedType;
QString detectedSrid = mRequestedSrid;
if ( !schemaName.isEmpty() )
{
Expand All @@ -3646,8 +3646,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 @@ -67,6 +67,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 0c36152

Please sign in to comment.