Skip to content

Commit

Permalink
Fix fetching subset of attributes with mssql (fix #14402), add test
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 2, 2016
1 parent 527fe9d commit 30449e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/providers/mssql/qgsmssqlfeatureiterator.cpp
Expand Up @@ -284,7 +284,7 @@ bool QgsMssqlFeatureIterator::fetchFeature( QgsFeature& feature )
for ( int i = 0; i < mAttributesToFetch.count(); i++ )
{
QVariant v = mQuery->value( i );
const QgsField &fld = mSource->mFields.at( i );
const QgsField &fld = mSource->mFields.at( mAttributesToFetch.at( i ) );
if ( v.type() != fld.type() )
v = QgsVectorDataProvider::convertValue( fld.type(), v.toString() );
feature.setAttribute( mAttributesToFetch.at( i ), v );
Expand Down
11 changes: 11 additions & 0 deletions tests/src/python/providertestbase.py
Expand Up @@ -384,3 +384,14 @@ def testClosedIterators(self):

# Test rewinding closed iterator
self.assertFalse(f_it.rewind(), 'Rewinding closed iterator successful, should not be allowed')

def testGetFeaturesSubsetAttributes(self):
""" Test that expected results are returned when using subsets of attributes """

tests = {'pk': set([1, 2, 3, 4, 5]),
'cnt': set([-200, 300, 100, 200, 400]),
'name': set(['Pear', 'Orange', 'Apple', 'Honey', NULL]),
'name2': set(['NuLl', 'PEaR', 'oranGe', 'Apple', 'Honey'])}
for field, expected in tests.iteritems():
result = set([f[field] for f in self.provider.getFeatures(QgsFeatureRequest().setSubsetOfAttributes([field], self.provider.fields()))])
self.assertEqual(result, expected, 'Expected {}, got {}'.format(expected, result))

0 comments on commit 30449e5

Please sign in to comment.