@@ -673,7 +673,7 @@ void QgsSpatiaLiteProvider::loadFieldsAbstractInterface( gaiaVectorLayerPtr lyr
673673 return ;
674674
675675 mAttributeFields .clear ();
676- mPrimaryKey .clear (); // cazzo cazzo cazzo
676+ mPrimaryKey .clear ();
677677 mPrimaryKeyAttrs .clear ();
678678 mDefaultValues .clear ();
679679
@@ -816,6 +816,13 @@ QString QgsSpatiaLiteProvider::spatialiteVersion()
816816 return mSpatialiteVersionInfo ;
817817}
818818
819+ QString QgsSpatiaLiteProvider::tableSchemaCondition ( const QgsDataSourceUri &dsUri )
820+ {
821+ return dsUri.schema ().isEmpty () ?
822+ QStringLiteral ( " IS NULL" ) :
823+ QStringLiteral ( " = %1" ).arg ( quotedValue ( dsUri.schema ( ) ) );
824+ }
825+
819826void QgsSpatiaLiteProvider::fetchConstraints ()
820827{
821828 char **results = nullptr ;
@@ -5662,11 +5669,11 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
56625669
56635670 QString checkQuery = QString ( " SELECT styleName"
56645671 " FROM layer_styles"
5665- " WHERE f_table_schema= %1"
5672+ " WHERE f_table_schema %1"
56665673 " AND f_table_name=%2"
56675674 " AND f_geometry_column=%3"
56685675 " AND styleName=%4" )
5669- .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri. schema () ) )
5676+ .arg ( QgsSpatiaLiteProvider::tableSchemaCondition ( dsUri ) )
56705677 .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.table () ) )
56715678 .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.geometryColumn () ) )
56725679 .arg ( QgsSpatiaLiteProvider::quotedValue ( styleName.isEmpty () ? dsUri.table () : styleName ) );
@@ -5699,7 +5706,7 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
56995706 " ,styleSLD=%3"
57005707 " ,description=%4"
57015708 " ,owner=%5"
5702- " WHERE f_table_schema= %6"
5709+ " WHERE f_table_schema %6"
57035710 " AND f_table_name=%7"
57045711 " AND f_geometry_column=%8"
57055712 " AND styleName=%9" )
@@ -5708,7 +5715,7 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
57085715 .arg ( QgsSpatiaLiteProvider::quotedValue ( sldStyle ) )
57095716 .arg ( QgsSpatiaLiteProvider::quotedValue ( styleDescription.isEmpty () ? QDateTime::currentDateTime ().toString () : styleDescription ) )
57105717 .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.username () ) )
5711- .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri. schema () ) )
5718+ .arg ( QgsSpatiaLiteProvider::tableSchemaCondition ( dsUri ) )
57125719 .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.table () ) )
57135720 .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.geometryColumn () ) )
57145721 .arg ( QgsSpatiaLiteProvider::quotedValue ( styleName.isEmpty () ? dsUri.table () : styleName ) );
@@ -5718,10 +5725,10 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
57185725 {
57195726 QString removeDefaultSql = QString ( " UPDATE layer_styles"
57205727 " SET useAsDefault=0"
5721- " WHERE f_table_schema= %1"
5728+ " WHERE f_table_schema %1"
57225729 " AND f_table_name=%2"
57235730 " AND f_geometry_column=%3" )
5724- .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri. schema () ) )
5731+ .arg ( QgsSpatiaLiteProvider::tableSchemaCondition ( dsUri ) )
57255732 .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.table () ) )
57265733 .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.geometryColumn () ) );
57275734 sql = QStringLiteral ( " BEGIN; %1; %2; COMMIT;" ).arg ( removeDefaultSql, sql );
@@ -5763,12 +5770,12 @@ QGISEXTERN QString loadStyle( const QString &uri, QString &errCause )
57635770
57645771 QString selectQmlQuery = QString ( " SELECT styleQML"
57655772 " FROM layer_styles"
5766- " WHERE f_table_schema= %1"
5773+ " WHERE f_table_schema %1"
57675774 " AND f_table_name=%2"
57685775 " AND f_geometry_column=%3"
57695776 " ORDER BY CASE WHEN useAsDefault THEN 1 ELSE 2 END"
57705777 " ,update_time DESC LIMIT 1" )
5771- .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri. schema () ) )
5778+ .arg ( QgsSpatiaLiteProvider::tableSchemaCondition ( dsUri ) )
57725779 .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.table () ) )
57735780 .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.geometryColumn () ) );
57745781
@@ -5842,13 +5849,13 @@ QGISEXTERN int listStyles( const QString &uri, QStringList &ids, QStringList &na
58425849 }
58435850
58445851 // get them
5845- QString selectRelatedQuery = QString ( " SELECT id,styleName,description"
5846- " FROM layer_styles"
5847- " WHERE f_table_schema= %1"
5848- " AND f_table_name=%2"
5849- " AND f_geometry_column=%3"
5850- " ORDER BY useasdefault DESC, update_time DESC" )
5851- .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri. schema () ) )
5852+ QString selectRelatedQuery = QStringLiteral ( " SELECT id,styleName,description"
5853+ " FROM layer_styles"
5854+ " WHERE f_table_schema %1"
5855+ " AND f_table_name=%2"
5856+ " AND f_geometry_column=%3"
5857+ " ORDER BY useasdefault DESC, update_time DESC" )
5858+ .arg ( QgsSpatiaLiteProvider::tableSchemaCondition ( dsUri ) )
58525859 .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.table () ) )
58535860 .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.geometryColumn () ) );
58545861
@@ -5870,11 +5877,11 @@ QGISEXTERN int listStyles( const QString &uri, QStringList &ids, QStringList &na
58705877 }
58715878 sqlite3_free_table ( results );
58725879
5873- QString selectOthersQuery = QString ( " SELECT id,styleName,description"
5874- " FROM layer_styles"
5875- " WHERE NOT (f_table_schema= %1 AND f_table_name=%2 AND f_geometry_column=%3)"
5876- " ORDER BY update_time DESC" )
5877- .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri. schema () ) )
5880+ QString selectOthersQuery = QStringLiteral ( " SELECT id,styleName,description"
5881+ " FROM layer_styles"
5882+ " WHERE NOT (f_table_schema %1 AND f_table_name=%2 AND f_geometry_column=%3)"
5883+ " ORDER BY update_time DESC" )
5884+ .arg ( QgsSpatiaLiteProvider::tableSchemaCondition ( dsUri ) )
58785885 .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.table () ) )
58795886 .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.geometryColumn () ) );
58805887
0 commit comments