Skip to content

Commit

Permalink
Fix loading style for non-spatial tables in Postgres+SpatiaLite (fixes
Browse files Browse the repository at this point in the history
…#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 Oct 11, 2018
1 parent e410208 commit 942a560
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -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 );

Expand Down
14 changes: 12 additions & 2 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 942a560

Please sign in to comment.