Skip to content
Permalink
Browse files

[mssql] Fix incorrect feature sort order when combined with subset

of attributes request

Fixes a failing provider conformance test
  • Loading branch information
nyalldawson committed Oct 4, 2018
1 parent f377958 commit 7ac86d2fbf4892e8bb1308f074baebdff0b4058f
Showing with 20 additions and 8 deletions.
  1. +20 −8 src/providers/mssql/qgsmssqlfeatureiterator.cpp
@@ -81,16 +81,28 @@ void QgsMssqlFeatureIterator::BuildStatement( const QgsFeatureRequest &request )
bool subsetOfAttributes = mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes;
QgsAttributeList attrs = subsetOfAttributes ? mRequest.subsetOfAttributes() : mSource->mFields.allAttributesList();

// ensure that all attributes required for expression filter are being fetched
if ( subsetOfAttributes && request.filterType() == QgsFeatureRequest::FilterExpression )
if ( subsetOfAttributes )
{
//ensure that all fields required for filter expressions are prepared
QSet<int> attributeIndexes = request.filterExpression()->referencedAttributeIndexes( mSource->mFields );
attributeIndexes += attrs.toSet();
attrs = attributeIndexes.toList();
// ensure that all attributes required for expression filter are being fetched
if ( request.filterType() == QgsFeatureRequest::FilterExpression )
{
//ensure that all fields required for filter expressions are prepared
QSet<int> attributeIndexes = request.filterExpression()->referencedAttributeIndexes( mSource->mFields );
attributeIndexes += attrs.toSet();
attrs = attributeIndexes.toList();
}

// ensure that all attributes required for order by are fetched
const QSet< QString > orderByAttributes = mRequest.orderBy().usedAttributes();
for ( const QString &attr : orderByAttributes )
{
int attrIndex = mSource->mFields.lookupField( attr );
if ( !attrs.contains( attrIndex ) )
attrs << attrIndex;
}
}

Q_FOREACH ( int i, attrs )
for ( int i : qgis::as_const( attrs ) )
{
QString fieldname = mSource->mFields.at( i ).name();
if ( mSource->mFidColName == fieldname )
@@ -269,7 +281,7 @@ void QgsMssqlFeatureIterator::BuildStatement( const QgsFeatureRequest &request )
mOrderByClause = QStringLiteral( " ORDER BY %1" ).arg( orderByParts.join( QStringLiteral( "," ) ) );
}

QgsDebugMsg( mStatement );
QgsDebugMsg( mStatement + " " + mOrderByClause );
#if 0
if ( fieldCount == 0 )
{

0 comments on commit 7ac86d2

Please sign in to comment.
You can’t perform that action at this time.