Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes #44749 : list styles from database for layer with no geom
  • Loading branch information
troopa81 authored and github-actions[bot] committed Sep 17, 2021
1 parent 2cabe53 commit 2d37988
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -5441,13 +5441,14 @@ int QgsPostgresProviderMetadata::listStyles( const QString &uri, QStringList &id
" WHERE f_table_catalog=%1"
" AND f_table_schema=%2"
" AND f_table_name=%3"
" AND f_geometry_column=%4"
" AND %4"
" AND (type=%5 OR type IS NULL)"
" ORDER BY useasdefault DESC, update_time DESC" )
.arg( QgsPostgresConn::quotedValue( dsUri.database() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.schema() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.table() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.geometryColumn() ) )
.arg( dsUri.geometryColumn().isEmpty() ? "f_geometry_column is NULL" :
QString( "f_geometry_column=%1" ).arg( QgsPostgresConn::quotedValue( dsUri.geometryColumn() ) ) )
.arg( wkbTypeString );

QgsPostgresResult result( conn->PQexec( selectRelatedQuery ) );
Expand Down
16 changes: 16 additions & 0 deletions tests/src/python/test_provider_postgres.py
Expand Up @@ -2189,6 +2189,22 @@ def testStyleDatabaseWithService(self):
ids = styles[1]
self.assertEqual(len(ids), 0)

# try with a layer which doesn't have geom
myvl = QgsVectorLayer(
myconn +
' sslmode=disable key=\'pk\' table="qgis_test"."bikes" sql=', 'test', 'postgres')
self.assertTrue(myvl.isValid())

myvl.saveStyleToDatabase('mystyle_wo_geom', '', False, '')
styles = myvl.listStylesInDatabase()
ids = styles[1]
self.assertEqual(len(ids), 1)

myvl.deleteStyleFromDatabase(ids[0])
styles = myvl.listStylesInDatabase()
ids = styles[1]
self.assertEqual(len(ids), 0)

def testCurveToMultipolygon(self):
self.execSQLCommand(
'CREATE TABLE IF NOT EXISTS multicurve(pk SERIAL NOT NULL PRIMARY KEY, geom public.geometry(MultiPolygon, 4326))')
Expand Down

0 comments on commit 2d37988

Please sign in to comment.