Skip to content
Permalink
Browse files

[Spatialite] Remove t_table_catalog WHERE clause when searcing for la…

…yer styles in db

This sanity check is unnecessary and breaks styling if the sqlite file is moved or renamed.
The t_table_catalog column is kept for backwards compatibility.
  • Loading branch information
manisandro committed Aug 3, 2016
1 parent 6851c34 commit 756991b7dc642821725cc191beae8a75cf101399
Showing with 19 additions and 30 deletions.
  1. +19 −30 src/providers/spatialite/qgsspatialiteprovider.cpp
@@ -5330,7 +5330,7 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
") VALUES ("
"%1,%2,%3,%4,%5,%6,%7,%8,%9,%10%12"
")" )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.database() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( QString() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.schema() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.table() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.geometryColumn() ) )
@@ -5345,12 +5345,10 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS

QString checkQuery = QString( "SELECT styleName"
" FROM layer_styles"
" WHERE f_table_catalog=%1"
" AND f_table_schema=%2"
" AND f_table_name=%3"
" AND f_geometry_column=%4"
" AND styleName=%5" )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.database() ) )
" WHERE f_table_schema=%1"
" AND f_table_name=%2"
" AND f_geometry_column=%3"
" AND styleName=%4" )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.schema() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.table() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.geometryColumn() ) )
@@ -5384,17 +5382,15 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
",styleSLD=%3"
",description=%4"
",owner=%5"
" WHERE f_table_catalog=%6"
" AND f_table_schema=%7"
" AND f_table_name=%8"
" AND f_geometry_column=%9"
" AND styleName=%10" )
" WHERE f_table_schema=%6"
" AND f_table_name=%7"
" AND f_geometry_column=%8"
" AND styleName=%9" )
.arg( useAsDefault ? "1" : "0" )
.arg( QgsSpatiaLiteProvider::quotedValue( qmlStyle ) )
.arg( QgsSpatiaLiteProvider::quotedValue( sldStyle ) )
.arg( QgsSpatiaLiteProvider::quotedValue( styleDescription.isEmpty() ? QDateTime::currentDateTime().toString() : styleDescription ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.username() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.database() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.schema() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.table() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.geometryColumn() ) )
@@ -5405,11 +5401,9 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
{
QString removeDefaultSql = QString( "UPDATE layer_styles"
" SET useAsDefault=0"
" WHERE f_table_catalog=%1"
" AND f_table_schema=%2"
" AND f_table_name=%3"
" AND f_geometry_column=%4" )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.database() ) )
" WHERE f_table_schema=%1"
" AND f_table_name=%2"
" AND f_geometry_column=%3" )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.schema() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.table() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.geometryColumn() ) );
@@ -5460,13 +5454,11 @@ QGISEXTERN QString loadStyle( const QString& uri, QString& errCause )

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"
" WHERE f_table_schema=%1"
" AND f_table_name=%2"
" AND f_geometry_column=%3"
" 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() ) );
@@ -5543,11 +5535,9 @@ QGISEXTERN int listStyles( const QString &uri, QStringList &ids, QStringList &na
// get them
QString selectRelatedQuery = QString( "SELECT id,styleName,description"
" FROM layer_styles"
" WHERE f_table_catalog=%1"
" AND f_table_schema=%2"
" AND f_table_name=%3"
" AND f_geometry_column=%4" )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.database() ) )
" WHERE f_table_schema=%1"
" AND f_table_name=%2"
" AND f_geometry_column=%3" )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.schema() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.table() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.geometryColumn() ) );
@@ -5572,9 +5562,8 @@ QGISEXTERN int listStyles( const QString &uri, QStringList &ids, QStringList &na

QString selectOthersQuery = QString( "SELECT id,styleName,description"
" FROM layer_styles"
" WHERE NOT (f_table_catalog=%1 AND f_table_schema=%2 AND f_table_name=%3 AND f_geometry_column=%4)"
" WHERE NOT (f_table_schema=%1 AND f_table_name=%2 AND f_geometry_column=%3)"
" ORDER BY update_time DESC" )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.database() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.schema() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.table() ) )
.arg( QgsSpatiaLiteProvider::quotedValue( dsUri.geometryColumn() ) );

0 comments on commit 756991b

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