Skip to content
Permalink
Browse files

[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
  • Loading branch information
nyalldawson committed Apr 15, 2018
1 parent 66bd813 commit d7fd14b3403af9d2f8aa9faab0f4022a5c9315e1
Showing with 12 additions and 0 deletions.
  1. +8 −0 src/providers/oracle/qgsoraclefeatureiterator.cpp
  2. +4 −0 tests/src/python/featuresourcetestbase.py
@@ -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();
@@ -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)]

0 comments on commit d7fd14b

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