Skip to content

Commit 942a560

Browse files
committed
Fix loading style for non-spatial tables in Postgres+SpatiaLite (fixes #19589)
OGR is not affected by the bug. Oracle and MS SQL are most likely affected, but I don't have them here to test. (cherry picked from commit bb0c629)
1 parent e410208 commit 942a560

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/providers/postgres/qgspostgresprovider.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -4228,18 +4228,28 @@ QGISEXTERN QString loadStyle( const QString& uri, QString& errCause )
42284228
dsUri.setDatabase( conn->currentDatabase() );
42294229
}
42304230

4231+
QString geomColumnExpr;
4232+
if ( dsUri.geometryColumn().isEmpty() )
4233+
{
4234+
geomColumnExpr = QString( "IS NULL" );
4235+
}
4236+
else
4237+
{
4238+
geomColumnExpr = QString( "=" ) + QgsPostgresConn::quotedValue( dsUri.geometryColumn() );
4239+
}
4240+
42314241
QString selectQmlQuery = QString( "SELECT styleQML"
42324242
" FROM layer_styles"
42334243
" WHERE f_table_catalog=%1"
42344244
" AND f_table_schema=%2"
42354245
" AND f_table_name=%3"
4236-
" AND f_geometry_column=%4"
4246+
" AND f_geometry_column %4"
42374247
" ORDER BY CASE WHEN useAsDefault THEN 1 ELSE 2 END"
42384248
",update_time DESC LIMIT 1" )
42394249
.arg( QgsPostgresConn::quotedValue( dsUri.database() ) )
42404250
.arg( QgsPostgresConn::quotedValue( dsUri.schema() ) )
42414251
.arg( QgsPostgresConn::quotedValue( dsUri.table() ) )
4242-
.arg( QgsPostgresConn::quotedValue( dsUri.geometryColumn() ) );
4252+
.arg( geomColumnExpr );
42434253

42444254
result = conn->PQexec( selectQmlQuery );
42454255

src/providers/spatialite/qgsspatialiteprovider.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -5456,18 +5456,28 @@ QGISEXTERN QString loadStyle( const QString& uri, QString& errCause )
54565456

54575457
sqlite3 *sqliteHandle = handle->handle();
54585458

5459+
QString geomColumnExpr;
5460+
if ( dsUri.geometryColumn().isEmpty() )
5461+
{
5462+
geomColumnExpr = QString( "IS NULL" );
5463+
}
5464+
else
5465+
{
5466+
geomColumnExpr = QString( "=" ) + QgsSpatiaLiteProvider::quotedValue( dsUri.geometryColumn() );
5467+
}
5468+
54595469
QString selectQmlQuery = QString( "SELECT styleQML"
54605470
" FROM layer_styles"
54615471
" WHERE f_table_catalog=%1"
54625472
" AND f_table_schema=%2"
54635473
" AND f_table_name=%3"
5464-
" AND f_geometry_column=%4"
5474+
" AND f_geometry_column %4"
54655475
" ORDER BY CASE WHEN useAsDefault THEN 1 ELSE 2 END"
54665476
",update_time DESC LIMIT 1" )
54675477
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.database() ) )
54685478
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.schema() ) )
54695479
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.table() ) )
5470-
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.geometryColumn() ) );
5480+
.arg( geomColumnExpr );
54715481

54725482
char **results;
54735483
int rows;

0 commit comments

Comments
 (0)