Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[oracle] Ensure that all attributes required for order by are fetched
Fixes potentially broken iterator sorting with oracle provider when
a subset of attributes is fetched

(cherry-picked from d7fd14b)
  • Loading branch information
nyalldawson committed Apr 17, 2018
1 parent 649dc19 commit 89a84f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/providers/oracle/qgsoraclefeatureiterator.cpp
Expand Up @@ -74,6 +74,14 @@ QgsOracleFeatureIterator::QgsOracleFeatureIterator( QgsOracleFeatureSource *sour
}
}

// 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 ( !mAttributeList.contains( attrIndex ) )
mAttributeList << attrIndex;
}
}
else
mAttributeList = mSource->mFields.allAttributesList();
Expand Down
4 changes: 4 additions & 0 deletions tests/src/python/featuresourcetestbase.py
Expand Up @@ -320,6 +320,10 @@ def runOrderByTests(self):
values = [f['name'] for f in self.source.getFeatures(request)]
self.assertEqual(values, ['Pear', 'Orange', 'Honey', 'Apple', NULL])

request = QgsFeatureRequest().addOrderBy('num_char', False)
values = [f['pk'] for f in self.source.getFeatures(request)]
self.assertEqual(values, [5, 4, 3, 2, 1])

# Case sensitivity
request = QgsFeatureRequest().addOrderBy('name2')
values = [f['name2'] for f in self.source.getFeatures(request)]
Expand Down

0 comments on commit 89a84f0

Please sign in to comment.