Skip to content

Commit 8c3ed3d

Browse files
committed
fix warning
1 parent d37e03b commit 8c3ed3d

File tree

1 file changed

+39
-72
lines changed

1 file changed

+39
-72
lines changed

src/providers/mssql/qgsmssqlprovider.cpp

Lines changed: 39 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,11 @@ void QgsMssqlProvider::loadMetadata()
321321
QString msg = query.lastError().text();
322322
QgsDebugMsg( msg );
323323
}
324-
if ( query.isActive() )
324+
if ( query.isActive() && query.next() )
325325
{
326-
if ( query.next() )
327-
{
328-
mGeometryColName = query.value( 0 ).toString();
329-
mSRId = query.value( 2 ).toInt();
330-
mWkbType = getWkbType( query.value( 3 ).toString(), query.value( 1 ).toInt() );
331-
}
326+
mGeometryColName = query.value( 0 ).toString();
327+
mSRId = query.value( 2 ).toInt();
328+
mWkbType = getWkbType( query.value( 3 ).toString(), query.value( 1 ).toInt() );
332329
}
333330
}
334331

@@ -400,13 +397,10 @@ void QgsMssqlProvider::loadFields()
400397
QString msg = query.lastError().text();
401398
QgsDebugMsg( msg );
402399
}
403-
if ( query.isActive() )
400+
if ( query.isActive() && query.next() )
404401
{
405-
if ( query.next() )
406-
{
407-
mFidColName = query.value( 3 ).toString();
408-
return;
409-
}
402+
mFidColName = query.value( 3 ).toString();
403+
return;
410404
}
411405
foreach ( QString pk, pkCandidates )
412406
{
@@ -420,16 +414,10 @@ void QgsMssqlProvider::loadFields()
420414
QString msg = query.lastError().text();
421415
QgsDebugMsg( msg );
422416
}
423-
if ( query.isActive() )
417+
if ( query.isActive() && query.next() && query.value( 0 ).toInt() == query.value( 1 ).toInt() )
424418
{
425-
if ( query.next() )
426-
{
427-
if ( query.value( 0 ).toInt() == query.value( 1 ).toInt() )
428-
{
429-
mFidColName = pk;
430-
return;
431-
}
432-
}
419+
mFidColName = pk;
420+
return;
433421
}
434422
}
435423
}
@@ -476,10 +464,9 @@ QVariant QgsMssqlProvider::minimumValue( int index )
476464
QgsDebugMsg( msg );
477465
}
478466

479-
if ( query.isActive() )
467+
if ( query.isActive() && query.next() )
480468
{
481-
if ( query.next() )
482-
return query.value( 0 );
469+
return query.value( 0 );
483470
}
484471

485472
return QVariant( QString::null );
@@ -512,10 +499,9 @@ QVariant QgsMssqlProvider::maximumValue( int index )
512499
QgsDebugMsg( msg );
513500
}
514501

515-
if ( query.isActive() )
502+
if ( query.isActive() && query.next() )
516503
{
517-
if ( query.next() )
518-
return query.value( 0 );
504+
return query.value( 0 );
519505
}
520506

521507
return QVariant( QString::null );
@@ -582,23 +568,22 @@ void QgsMssqlProvider::UpdateStatistics( bool estimate )
582568
QString sql = "SELECT min(bounding_box_xmin), min(bounding_box_ymin), max(bounding_box_xmax), max(bounding_box_ymax)"
583569
" FROM sys.spatial_index_tessellations WHERE object_id = OBJECT_ID('[%1].[%2]')";
584570

585-
statement = QString (sql).arg( mSchemaName )
586-
.arg( mTableName );
571+
statement = QString( sql ).arg( mSchemaName ).arg( mTableName );
587572

588573
if ( query.exec( statement ) )
589574
{
590-
QgsDebugMsg("Found extents in spatial index");
575+
QgsDebugMsg( "Found extents in spatial index" );
591576
if ( query.next() )
592577
{
593-
mExtent.setXMinimum( query.value( 0 ).toDouble() );
594-
mExtent.setYMinimum( query.value( 1 ).toDouble() );
595-
mExtent.setXMaximum( query.value( 2 ).toDouble() );
596-
mExtent.setYMaximum( query.value( 3 ).toDouble() );
597-
return;
578+
mExtent.setXMinimum( query.value( 0 ).toDouble() );
579+
mExtent.setYMinimum( query.value( 1 ).toDouble() );
580+
mExtent.setXMaximum( query.value( 2 ).toDouble() );
581+
mExtent.setYMaximum( query.value( 3 ).toDouble() );
582+
return;
598583
}
599584
}
600585

601-
QgsDebugMsg(query.lastError().text());
586+
QgsDebugMsg( query.lastError().text() );
602587

603588
// If we can't find the extents in the spatial index table just do what we normally do.
604589
bool readAllGeography = false;
@@ -638,20 +623,17 @@ void QgsMssqlProvider::UpdateStatistics( bool estimate )
638623

639624
if ( !query.isActive() )
640625
{
641-
return;
626+
return;
642627
}
643628

644629
QgsGeometry geom;
645-
if ( !readAllGeography )
630+
if ( !readAllGeography && query.next() )
646631
{
647-
if ( query.next() )
648-
{
649-
mExtent.setXMinimum( query.value( 0 ).toDouble() );
650-
mExtent.setYMinimum( query.value( 1 ).toDouble() );
651-
mExtent.setXMaximum( query.value( 2 ).toDouble() );
652-
mExtent.setYMaximum( query.value( 3 ).toDouble() );
653-
return;
654-
}
632+
mExtent.setXMinimum( query.value( 0 ).toDouble() );
633+
mExtent.setYMinimum( query.value( 1 ).toDouble() );
634+
mExtent.setXMaximum( query.value( 2 ).toDouble() );
635+
mExtent.setYMaximum( query.value( 3 ).toDouble() );
636+
return;
655637
}
656638

657639
// We have to read all the geometry if readAllGeography is true.
@@ -714,15 +696,11 @@ long QgsMssqlProvider::featureCount() const
714696
" JOIN sys.partitions p ON t.object_id = p.object_id AND p.index_id IN (0,1)"
715697
" WHERE SCHEMA_NAME(t.schema_id) = '%1' AND OBJECT_NAME(t.OBJECT_ID) = '%2'";
716698

717-
QString statement = QString (sql).arg( mSchemaName )
718-
.arg( mTableName );
699+
QString statement = QString( sql ).arg( mSchemaName ).arg( mTableName );
719700

720-
if ( query.exec( statement ) )
701+
if ( query.exec( statement ) && query.next() )
721702
{
722-
if ( query.next() )
723-
{
724-
return query.value(0).toInt();
725-
}
703+
return query.value( 0 ).toInt();
726704
}
727705
else
728706
{
@@ -1311,23 +1289,15 @@ QgsCoordinateReferenceSystem QgsMssqlProvider::crs()
13111289
query.exec( QString( "select srtext from spatial_ref_sys where srid = %1" ).arg( QString::number( mSRId ) ) );
13121290
if ( query.isActive() )
13131291
{
1314-
if ( query.next() )
1315-
{
1316-
if ( mCrs.createFromWkt( query.value( 0 ).toString() ) )
1317-
return mCrs;
1318-
}
1292+
if ( query.next() && mCrs.createFromWkt( query.value( 0 ).toString() ) )
1293+
return mCrs;
1294+
13191295
query.finish();
13201296
}
13211297
query.clear();
13221298
query.exec( QString( "select well_known_text from sys.spatial_reference_systems where spatial_reference_id = %1" ).arg( QString::number( mSRId ) ) );
1323-
if ( query.isActive() )
1324-
{
1325-
if ( query.next() )
1326-
{
1327-
if ( mCrs.createFromWkt( query.value( 0 ).toString() ) )
1328-
return mCrs;
1329-
}
1330-
}
1299+
if ( query.isActive() && query.next() && mCrs.createFromWkt( query.value( 0 ).toString() ) )
1300+
return mCrs;
13311301
}
13321302
return mCrs;
13331303
}
@@ -1369,11 +1339,8 @@ bool QgsMssqlProvider::setSubsetString( QString theSQL, bool )
13691339
return false;
13701340
}
13711341

1372-
if ( query.isActive() )
1373-
{
1374-
if ( query.next() )
1375-
mNumberFeatures = query.value( 0 ).toInt();
1376-
}
1342+
if ( query.isActive() && query.next() )
1343+
mNumberFeatures = query.value( 0 ).toInt();
13771344

13781345
QgsDataSourceURI anUri = QgsDataSourceURI( dataSourceUri() );
13791346
anUri.setSql( mSqlWhereClause );

0 commit comments

Comments
 (0)