@@ -673,7 +673,7 @@ void QgsSpatiaLiteProvider::loadFieldsAbstractInterface( gaiaVectorLayerPtr lyr
673
673
return ;
674
674
675
675
mAttributeFields .clear ();
676
- mPrimaryKey .clear (); // cazzo cazzo cazzo
676
+ mPrimaryKey .clear ();
677
677
mPrimaryKeyAttrs .clear ();
678
678
mDefaultValues .clear ();
679
679
@@ -816,6 +816,13 @@ QString QgsSpatiaLiteProvider::spatialiteVersion()
816
816
return mSpatialiteVersionInfo ;
817
817
}
818
818
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
+
819
826
void QgsSpatiaLiteProvider::fetchConstraints ()
820
827
{
821
828
char **results = nullptr ;
@@ -5662,11 +5669,11 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
5662
5669
5663
5670
QString checkQuery = QString ( " SELECT styleName"
5664
5671
" FROM layer_styles"
5665
- " WHERE f_table_schema= %1"
5672
+ " WHERE f_table_schema %1"
5666
5673
" AND f_table_name=%2"
5667
5674
" AND f_geometry_column=%3"
5668
5675
" AND styleName=%4" )
5669
- .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri. schema () ) )
5676
+ .arg ( QgsSpatiaLiteProvider::tableSchemaCondition ( dsUri ) )
5670
5677
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.table () ) )
5671
5678
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.geometryColumn () ) )
5672
5679
.arg ( QgsSpatiaLiteProvider::quotedValue ( styleName.isEmpty () ? dsUri.table () : styleName ) );
@@ -5699,7 +5706,7 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
5699
5706
" ,styleSLD=%3"
5700
5707
" ,description=%4"
5701
5708
" ,owner=%5"
5702
- " WHERE f_table_schema= %6"
5709
+ " WHERE f_table_schema %6"
5703
5710
" AND f_table_name=%7"
5704
5711
" AND f_geometry_column=%8"
5705
5712
" AND styleName=%9" )
@@ -5708,7 +5715,7 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
5708
5715
.arg ( QgsSpatiaLiteProvider::quotedValue ( sldStyle ) )
5709
5716
.arg ( QgsSpatiaLiteProvider::quotedValue ( styleDescription.isEmpty () ? QDateTime::currentDateTime ().toString () : styleDescription ) )
5710
5717
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.username () ) )
5711
- .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri. schema () ) )
5718
+ .arg ( QgsSpatiaLiteProvider::tableSchemaCondition ( dsUri ) )
5712
5719
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.table () ) )
5713
5720
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.geometryColumn () ) )
5714
5721
.arg ( QgsSpatiaLiteProvider::quotedValue ( styleName.isEmpty () ? dsUri.table () : styleName ) );
@@ -5718,10 +5725,10 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
5718
5725
{
5719
5726
QString removeDefaultSql = QString ( " UPDATE layer_styles"
5720
5727
" SET useAsDefault=0"
5721
- " WHERE f_table_schema= %1"
5728
+ " WHERE f_table_schema %1"
5722
5729
" AND f_table_name=%2"
5723
5730
" AND f_geometry_column=%3" )
5724
- .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri. schema () ) )
5731
+ .arg ( QgsSpatiaLiteProvider::tableSchemaCondition ( dsUri ) )
5725
5732
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.table () ) )
5726
5733
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.geometryColumn () ) );
5727
5734
sql = QStringLiteral ( " BEGIN; %1; %2; COMMIT;" ).arg ( removeDefaultSql, sql );
@@ -5763,12 +5770,12 @@ QGISEXTERN QString loadStyle( const QString &uri, QString &errCause )
5763
5770
5764
5771
QString selectQmlQuery = QString ( " SELECT styleQML"
5765
5772
" FROM layer_styles"
5766
- " WHERE f_table_schema= %1"
5773
+ " WHERE f_table_schema %1"
5767
5774
" AND f_table_name=%2"
5768
5775
" AND f_geometry_column=%3"
5769
5776
" ORDER BY CASE WHEN useAsDefault THEN 1 ELSE 2 END"
5770
5777
" ,update_time DESC LIMIT 1" )
5771
- .arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri. schema () ) )
5778
+ .arg ( QgsSpatiaLiteProvider::tableSchemaCondition ( dsUri ) )
5772
5779
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.table () ) )
5773
5780
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.geometryColumn () ) );
5774
5781
@@ -5842,13 +5849,13 @@ QGISEXTERN int listStyles( const QString &uri, QStringList &ids, QStringList &na
5842
5849
}
5843
5850
5844
5851
// 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 ) )
5852
5859
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.table () ) )
5853
5860
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.geometryColumn () ) );
5854
5861
@@ -5870,11 +5877,11 @@ QGISEXTERN int listStyles( const QString &uri, QStringList &ids, QStringList &na
5870
5877
}
5871
5878
sqlite3_free_table ( results );
5872
5879
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 ) )
5878
5885
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.table () ) )
5879
5886
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.geometryColumn () ) );
5880
5887
0 commit comments