Skip to content
Permalink
Browse files

Fix #37338

  • Loading branch information
jgrocha committed Jun 24, 2020
1 parent 0888856 commit 5c3dff6f6bb1377434371ccbe6f3eb076d97ae73
Showing with 39 additions and 18 deletions.
  1. +39 −18 src/providers/postgres/qgspostgresprovider.cpp
@@ -5082,7 +5082,7 @@ bool QgsPostgresProviderMetadata::saveStyle( const QString &uri, const QString &
" AND f_table_schema=%2"
" AND f_table_name=%3"
" AND f_geometry_column=%4"
" AND type=%5"
" AND (type=%5 OR type IS NULL)"
" AND styleName=%6" )
.arg( QgsPostgresConn::quotedValue( dsUri.database() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.schema() ) )
@@ -5110,12 +5110,13 @@ bool QgsPostgresProviderMetadata::saveStyle( const QString &uri, const QString &
",styleSLD=XMLPARSE(DOCUMENT %13)"
",description=%4"
",owner=%5"
",type=%2"
" WHERE f_table_catalog=%6"
" AND f_table_schema=%7"
" AND f_table_name=%8"
" AND f_geometry_column=%9"
" AND styleName=%10"
" AND type=%2" )
" AND (type=%2 OR type IS NULL)" )
.arg( useAsDefault ? "true" : "false" )
.arg( wkbTypeString )
.arg( QgsPostgresConn::quotedValue( styleDescription.isEmpty() ? QDateTime::currentDateTime().toString() : styleDescription ) )
@@ -5138,7 +5139,7 @@ bool QgsPostgresProviderMetadata::saveStyle( const QString &uri, const QString &
" AND f_table_schema=%2"
" AND f_table_name=%3"
" AND f_geometry_column=%4"
" AND type=%5" )
" AND (type=%5 OR type IS NULL)" )
.arg( QgsPostgresConn::quotedValue( dsUri.database() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.schema() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.table() ) )
@@ -5163,6 +5164,7 @@ bool QgsPostgresProviderMetadata::saveStyle( const QString &uri, const QString &
QString QgsPostgresProviderMetadata::loadStyle( const QString &uri, QString &errCause )
{
QgsDataSourceUri dsUri( uri );
QString selectQmlQuery;

QgsPostgresConn *conn = QgsPostgresConn::connectDb( dsUri.connectionInfo( false ), false );
if ( !conn )
@@ -5194,20 +5196,39 @@ QString QgsPostgresProviderMetadata::loadStyle( const QString &uri, QString &err

QString wkbTypeString = QgsPostgresConn::quotedValue( QgsWkbTypes::geometryDisplayString( QgsWkbTypes::geometryType( dsUri.wkbType() ) ) );

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 type=%5"
" 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( geomColumnExpr )
.arg( wkbTypeString );
// support layer_styles without type column < 3.14
if ( !columnExists( *conn, QStringLiteral( "layer_styles" ), QStringLiteral( "type" ) ) )
{
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"
" 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( geomColumnExpr );
}
else
{
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 (type=%5 OR type IS NULL)"
" 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( geomColumnExpr )
.arg( wkbTypeString );
}

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

@@ -5242,7 +5263,7 @@ int QgsPostgresProviderMetadata::listStyles( const QString &uri, QStringList &id
" AND f_table_schema=%2"
" AND f_table_name=%3"
" AND f_geometry_column=%4"
" AND type=%5"
" AND (type=%5 OR type IS NULL)"
" ORDER BY useasdefault DESC, update_time DESC" )
.arg( QgsPostgresConn::quotedValue( dsUri.database() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.schema() ) )

0 comments on commit 5c3dff6

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