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.
  • Loading branch information
wonder-sk committed Oct 1, 2018
1 parent 5508ea0 commit bb0c629
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 @@ -4819,18 +4819,28 @@ QGISEXTERN QString loadStyle( const QString &uri, QString &errCause )
return QString();
}

QString geomColumnExpr;
if ( dsUri.geometryColumn().isEmpty() )
{
geomColumnExpr = QStringLiteral( "IS NULL" );
}
else
{
geomColumnExpr = QStringLiteral( "=" ) + 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 );

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

Expand Down
14 changes: 12 additions & 2 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -5814,16 +5814,26 @@ QGISEXTERN QString loadStyle( const QString &uri, QString &errCause )

sqlite3 *sqliteHandle = handle->handle();

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

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

char **results = nullptr;
int rows;
Expand Down

0 comments on commit bb0c629

Please sign in to comment.