@@ -471,10 +471,7 @@ QVariant QgsMssqlProvider::minimumValue( int index )
471
471
QString sql = QString ( " select min([%1]) from " )
472
472
.arg ( fld.name () );
473
473
474
- if ( !mSchemaName .isEmpty () )
475
- sql += " [" + mSchemaName + " ]." ;
476
-
477
- sql += " [" + mTableName + " ]" ;
474
+ sql += QString (" [%1].[%2]" ).arg ( mSchemaName , mTableName );
478
475
479
476
if ( !mSqlWhereClause .isEmpty () )
480
477
{
@@ -506,10 +503,7 @@ QVariant QgsMssqlProvider::maximumValue( int index )
506
503
QString sql = QString ( " select max([%1]) from " )
507
504
.arg ( fld.name () );
508
505
509
- if ( !mSchemaName .isEmpty () )
510
- sql += " [" + mSchemaName + " ]." ;
511
-
512
- sql += " [" + mTableName + " ]" ;
506
+ sql += QString (" [%1].[%2]" ).arg ( mSchemaName , mTableName );
513
507
514
508
if ( !mSqlWhereClause .isEmpty () )
515
509
{
@@ -550,10 +544,7 @@ void QgsMssqlProvider::uniqueValues( int index, QList<QVariant> &uniqueValues, i
550
544
sql += QString ( " [%1] from " )
551
545
.arg ( fld.name () );
552
546
553
- if ( !mSchemaName .isEmpty () )
554
- sql += " [" + mSchemaName + " ]." ;
555
-
556
- sql += " [" + mTableName + " ]" ;
547
+ sql += QString (" [%1].[%2]" ).arg ( mSchemaName , mTableName );
557
548
558
549
if ( !mSqlWhereClause .isEmpty () )
559
550
{
@@ -631,10 +622,7 @@ void QgsMssqlProvider::UpdateStatistics( bool estimate )
631
622
}
632
623
}
633
624
634
- if ( mSchemaName .isEmpty () )
635
- statement += QString ( " from [%1]" ).arg ( mTableName );
636
- else
637
- statement += QString ( " from [%1].[%2]" ).arg ( mSchemaName , mTableName );
625
+ statement += QString ( " from [%1].[%2]" ).arg ( mSchemaName , mTableName );
638
626
639
627
if ( !mSqlWhereClause .isEmpty () )
640
628
{
@@ -752,10 +740,7 @@ bool QgsMssqlProvider::addFeatures( QgsFeatureList & flist )
752
740
{
753
741
QString statement;
754
742
QString values;
755
- if ( mSchemaName .isEmpty () )
756
- statement = QString ( " INSERT INTO [%1].[%2] (" ).arg ( QString ( " dbo" ), mTableName );
757
- else
758
- statement = QString ( " INSERT INTO [%1].[%2] (" ).arg ( mSchemaName , mTableName );
743
+ statement = QString ( " INSERT INTO [%1].[%2] (" ).arg ( mSchemaName , mTableName );
759
744
760
745
bool first = true ;
761
746
QSqlQuery query = QSqlQuery ( mDatabase );
@@ -906,10 +891,7 @@ bool QgsMssqlProvider::addFeatures( QgsFeatureList & flist )
906
891
}
907
892
908
893
909
- if ( mSchemaName .isEmpty () )
910
- statement = QString ( " SELECT IDENT_CURRENT('dbo.%1')" ).arg ( mTableName );
911
- else
912
- statement = QString ( " SELECT IDENT_CURRENT('%1.%2')" ).arg ( mSchemaName , mTableName );
894
+ statement = QString ( " SELECT IDENT_CURRENT('%1.%2')" ).arg ( mSchemaName , mTableName );
913
895
914
896
if ( !query.exec ( statement ) )
915
897
{
@@ -949,12 +931,8 @@ bool QgsMssqlProvider::addAttributes( const QList<QgsField> &attributes )
949
931
950
932
if ( statement.isEmpty () )
951
933
{
952
- if ( mSchemaName .isEmpty () )
953
- statement = QString ( " ALTER TABLE [%1].[%2] ADD " ).arg (
954
- QString ( " dbo" ), mTableName );
955
- else
956
- statement = QString ( " ALTER TABLE [%1].[%2] ADD " ).arg (
957
- mSchemaName , mTableName );
934
+ statement = QString ( " ALTER TABLE [%1].[%2] ADD " ).arg (
935
+ mSchemaName , mTableName );
958
936
}
959
937
else
960
938
statement += " ," ;
@@ -982,10 +960,7 @@ bool QgsMssqlProvider::deleteAttributes( const QgsAttributeIds &attributes )
982
960
{
983
961
if ( statement.isEmpty () )
984
962
{
985
- if ( mSchemaName .isEmpty () )
986
- statement = QString ( " ALTER TABLE [%1].[%2] DROP COLUMN " ).arg ( QString ( " dbo" ), mTableName );
987
- else
988
- statement = QString ( " ALTER TABLE [%1].[%2] DROP COLUMN " ).arg ( mSchemaName , mTableName );
963
+ statement = QString ( " ALTER TABLE [%1].[%2] DROP COLUMN " ).arg ( mSchemaName , mTableName );
989
964
}
990
965
else
991
966
statement += " ," ;
@@ -1026,10 +1001,7 @@ bool QgsMssqlProvider::changeAttributeValues( const QgsChangedAttributesMap & at
1026
1001
continue ;
1027
1002
1028
1003
QString statement;
1029
- if ( mSchemaName .isEmpty () )
1030
- statement = QString ( " UPDATE [%1].[%2] SET " ).arg ( QString ( " dbo" ), mTableName );
1031
- else
1032
- statement = QString ( " UPDATE [%1].[%2] SET " ).arg ( mSchemaName , mTableName );
1004
+ statement = QString ( " UPDATE [%1].[%2] SET " ).arg ( mSchemaName , mTableName );
1033
1005
1034
1006
bool first = true ;
1035
1007
QSqlQuery query = QSqlQuery ( mDatabase );
@@ -1136,10 +1108,7 @@ bool QgsMssqlProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
1136
1108
continue ;
1137
1109
1138
1110
QString statement;
1139
- if ( mSchemaName .isEmpty () )
1140
- statement = QString ( " UPDATE [%1].[%2] SET " ).arg ( QString ( " dbo" ), mTableName );
1141
- else
1142
- statement = QString ( " UPDATE [%1].[%2] SET " ).arg ( mSchemaName , mTableName );
1111
+ statement = QString ( " UPDATE [%1].[%2] SET " ).arg ( mSchemaName , mTableName );
1143
1112
1144
1113
QSqlQuery query = QSqlQuery ( mDatabase );
1145
1114
query.setForwardOnly ( true );
@@ -1213,12 +1182,8 @@ bool QgsMssqlProvider::deleteFeatures( const QgsFeatureIds & id )
1213
1182
QSqlQuery query = QSqlQuery ( mDatabase );
1214
1183
query.setForwardOnly ( true );
1215
1184
QString statement;
1216
- if ( mSchemaName .isEmpty () )
1217
- statement = QString ( " DELETE FROM [%1].[%2] WHERE [%3] IN (%4)" ).arg ( QString ( " dbo" ),
1218
- mTableName , mFidColName , featureIds );
1219
- else
1220
- statement = QString ( " DELETE FROM [%1].[%2] WHERE [%3] IN (%4)" ).arg ( mSchemaName ,
1221
- mTableName , mFidColName , featureIds );
1185
+ statement = QString ( " DELETE FROM [%1].[%2] WHERE [%3] IN (%4)" ).arg ( mSchemaName ,
1186
+ mTableName , mFidColName , featureIds );
1222
1187
1223
1188
if ( !query.exec ( statement ) )
1224
1189
{
@@ -1248,12 +1213,8 @@ bool QgsMssqlProvider::createSpatialIndex()
1248
1213
QSqlQuery query = QSqlQuery ( mDatabase );
1249
1214
query.setForwardOnly ( true );
1250
1215
QString statement;
1251
- if ( mSchemaName .isEmpty () )
1252
- statement = QString ( " CREATE SPATIAL INDEX [qgs_%1_sidx] ON [%2].[%3] ( [%4] )" ).arg (
1253
- mGeometryColName , QString ( " dbo" ), mTableName , mGeometryColName );
1254
- else
1255
- statement = QString ( " CREATE SPATIAL INDEX [qgs_%1_sidx] ON [%2].[%3] ( [%4] )" ).arg (
1256
- mGeometryColName , mSchemaName , mTableName , mGeometryColName );
1216
+ statement = QString ( " CREATE SPATIAL INDEX [qgs_%1_sidx] ON [%2].[%3] ( [%4] )" ).arg (
1217
+ mGeometryColName , mSchemaName , mTableName , mGeometryColName );
1257
1218
1258
1219
if ( mGeometryColType == " geometry" )
1259
1220
{
@@ -1288,12 +1249,8 @@ bool QgsMssqlProvider::createAttributeIndex( int field )
1288
1249
return false ;
1289
1250
}
1290
1251
1291
- if ( mSchemaName .isEmpty () )
1292
- statement = QString ( " CREATE NONCLUSTERED INDEX [qgs_%1_idx] ON [%2].[%3] ( [%4] )" ).arg (
1293
- mGeometryColName , QString ( " dbo" ), mTableName , mAttributeFields [field].name () );
1294
- else
1295
- statement = QString ( " CREATE NONCLUSTERED INDEX [qgs_%1_idx] ON [%2].[%3] ( [%4] )" ).arg (
1296
- mGeometryColName , mSchemaName , mTableName , mAttributeFields [field].name () );
1252
+ statement = QString ( " CREATE NONCLUSTERED INDEX [qgs_%1_idx] ON [%2].[%3] ( [%4] )" ).arg (
1253
+ mGeometryColName , mSchemaName , mTableName , mAttributeFields [field].name () );
1297
1254
1298
1255
if ( !query.exec ( statement ) )
1299
1256
{
@@ -1346,10 +1303,7 @@ bool QgsMssqlProvider::setSubsetString( QString theSQL, bool )
1346
1303
1347
1304
QString sql = QString ( " select count(*) from " );
1348
1305
1349
- if ( !mSchemaName .isEmpty () )
1350
- sql += " [" + mSchemaName + " ]." ;
1351
-
1352
- sql += " [" + mTableName + " ]" ;
1306
+ sql += QString (" [%1].[%2]" ).arg ( mSchemaName , mTableName );
1353
1307
1354
1308
if ( !mSqlWhereClause .isEmpty () )
1355
1309
{
0 commit comments