Skip to content

Commit d2831e3

Browse files
committed
Load extents from geometry_columns. Fix #7883
1 parent 6a352b7 commit d2831e3

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/providers/mssql/qgsmssqlprovider.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,30 @@ void QgsMssqlProvider::UpdateStatistics( bool estimate )
574574
mNumberFeatures = 0;
575575
// get features to calculate the statistics
576576
QString statement;
577+
578+
QSqlQuery query = QSqlQuery( mDatabase );
579+
query.setForwardOnly( true );
580+
581+
// Get the extents from the geometry_columns table to speed up load times.
582+
statement = QString("SELECT min_x, min_y, max_x, max_y from geometry_columns where f_table_schema = '%1' and f_table_name = '%2'").arg( mSchemaName ).arg( mTableName );
583+
584+
if ( query.exec( statement ) )
585+
{
586+
if ( query.next() )
587+
{
588+
if (!query.value( 0 ).isNull() || !query.value( 1 ).isNull() ||
589+
!query.value( 2 ).isNull() || !query.value( 3 ).isNull())
590+
{
591+
mExtent.setXMinimum( query.value( 0 ).toDouble() );
592+
mExtent.setYMinimum( query.value( 1 ).toDouble() );
593+
mExtent.setXMaximum( query.value( 2 ).toDouble() );
594+
mExtent.setYMaximum( query.value( 3 ).toDouble() );
595+
return;
596+
}
597+
}
598+
}
599+
600+
// If we can't find the extents in the geometry_columns table just do what we normally do.
577601
bool readAll = false;
578602
if ( estimate )
579603
{
@@ -603,9 +627,6 @@ void QgsMssqlProvider::UpdateStatistics( bool estimate )
603627
statement += " where (" + mSqlWhereClause + ")";
604628
}
605629

606-
QSqlQuery query = QSqlQuery( mDatabase );
607-
query.setForwardOnly( true );
608-
609630
if ( !query.exec( statement ) )
610631
{
611632
QString msg = query.lastError().text();

0 commit comments

Comments
 (0)