Skip to content
Permalink
Browse files
Fixes #44749 : list styles from database for layer with no geom
  • Loading branch information
troopa81 authored and nyalldawson committed Nov 1, 2021
1 parent 2fec04e commit 227d053aa193ed73841a529e52cb38c4e9761280
Showing with 19 additions and 2 deletions.
  1. +3 −2 src/providers/postgres/qgspostgresprovider.cpp
  2. +16 −0 tests/src/python/test_provider_postgres.py
@@ -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 ) );
@@ -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))')

0 comments on commit 227d053

Please sign in to comment.