Skip to content

Commit bb0c629

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.
1 parent 5508ea0 commit bb0c629

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
@@ -4819,18 +4819,28 @@ QGISEXTERN QString loadStyle( const QString &uri, QString &errCause )
48194819
return QString();
48204820
}
48214821

4822+
QString geomColumnExpr;
4823+
if ( dsUri.geometryColumn().isEmpty() )
4824+
{
4825+
geomColumnExpr = QStringLiteral( "IS NULL" );
4826+
}
4827+
else
4828+
{
4829+
geomColumnExpr = QStringLiteral( "=" ) + QgsPostgresConn::quotedValue( dsUri.geometryColumn() );
4830+
}
4831+
48224832
QString selectQmlQuery = QString( "SELECT styleQML"
48234833
" FROM layer_styles"
48244834
" WHERE f_table_catalog=%1"
48254835
" AND f_table_schema=%2"
48264836
" AND f_table_name=%3"
4827-
" AND f_geometry_column=%4"
4837+
" AND f_geometry_column %4"
48284838
" ORDER BY CASE WHEN useAsDefault THEN 1 ELSE 2 END"
48294839
",update_time DESC LIMIT 1" )
48304840
.arg( QgsPostgresConn::quotedValue( dsUri.database() ) )
48314841
.arg( QgsPostgresConn::quotedValue( dsUri.schema() ) )
48324842
.arg( QgsPostgresConn::quotedValue( dsUri.table() ) )
4833-
.arg( QgsPostgresConn::quotedValue( dsUri.geometryColumn() ) );
4843+
.arg( geomColumnExpr );
48344844

48354845
QgsPostgresResult result( conn->PQexec( selectQmlQuery ) );
48364846

src/providers/spatialite/qgsspatialiteprovider.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -5814,16 +5814,26 @@ QGISEXTERN QString loadStyle( const QString &uri, QString &errCause )
58145814

58155815
sqlite3 *sqliteHandle = handle->handle();
58165816

5817+
QString geomColumnExpr;
5818+
if ( dsUri.geometryColumn().isEmpty() )
5819+
{
5820+
geomColumnExpr = QStringLiteral( "IS NULL" );
5821+
}
5822+
else
5823+
{
5824+
geomColumnExpr = QStringLiteral( "=" ) + QgsSpatiaLiteProvider::quotedValue( dsUri.geometryColumn() );
5825+
}
5826+
58175827
QString selectQmlQuery = QString( "SELECT styleQML"
58185828
" FROM layer_styles"
58195829
" WHERE f_table_schema %1"
58205830
" AND f_table_name=%2"
5821-
" AND f_geometry_column=%3"
5831+
" AND f_geometry_column %3"
58225832
" ORDER BY CASE WHEN useAsDefault THEN 1 ELSE 2 END"
58235833
",update_time DESC LIMIT 1" )
58245834
.arg( QgsSpatiaLiteProvider::tableSchemaCondition( dsUri ) )
58255835
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.table() ) )
5826-
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.geometryColumn() ) );
5836+
.arg( geomColumnExpr );
58275837

58285838
char **results = nullptr;
58295839
int rows;

0 commit comments

Comments
 (0)