Skip to content
Permalink
Browse files

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)
  • Loading branch information
wonder-sk committed Sep 28, 2018
1 parent e410208 commit 942a560b3191bea5a26189ca9065ad1c37a51b64
Showing with 24 additions and 4 deletions.
  1. +12 −2 src/providers/postgres/qgspostgresprovider.cpp
  2. +12 −2 src/providers/spatialite/qgsspatialiteprovider.cpp
@@ -4228,18 +4228,28 @@ QGISEXTERN QString loadStyle( const QString& uri, QString& errCause )
dsUri.setDatabase( conn->currentDatabase() );
}

QString geomColumnExpr;
if ( dsUri.geometryColumn().isEmpty() )
{
geomColumnExpr = QString( "IS NULL" );
}
else
{
geomColumnExpr = QString( "=" ) + QgsPostgresConn::quotedValue( dsUri.geometryColumn() );
}

QString selectQmlQuery = QString( "SELECT styleQML"
" FROM layer_styles"
" WHERE f_table_catalog=%1"
" AND f_table_schema=%2"
" AND f_table_name=%3"
" AND f_geometry_column=%4"
" AND f_geometry_column %4"
" ORDER BY CASE WHEN useAsDefault THEN 1 ELSE 2 END"
",update_time DESC LIMIT 1" )
.arg( QgsPostgresConn::quotedValue( dsUri.database() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.schema() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.table() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.geometryColumn() ) );
.arg( geomColumnExpr );

result = conn->PQexec( selectQmlQuery );

@@ -5456,18 +5456,28 @@ QGISEXTERN QString loadStyle( const QString& uri, QString& errCause )

sqlite3 *sqliteHandle = handle->handle();

QString geomColumnExpr;
if ( dsUri.geometryColumn().isEmpty() )
{
geomColumnExpr = QString( "IS NULL" );
}
else
{
geomColumnExpr = QString( "=" ) + QgsSpatiaLiteProvider::quotedValue( dsUri.geometryColumn() );
}

QString selectQmlQuery = QString( "SELECT styleQML"
" FROM layer_styles"
" WHERE f_table_catalog=%1"
" AND f_table_schema=%2"
" AND f_table_name=%3"
" AND f_geometry_column=%4"
" AND f_geometry_column %4"
" ORDER BY CASE WHEN useAsDefault THEN 1 ELSE 2 END"
",update_time DESC LIMIT 1" )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.database() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.schema() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.table() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.geometryColumn() ) );
.arg( geomColumnExpr );

char **results;
int rows;

0 comments on commit 942a560

Please sign in to comment.
You can’t perform that action at this time.