Skip to content
Permalink
Browse files

Fix fetching subset of attributes with mssql (fix #14402), add test

(cherry-picked from 30449e5)
  • Loading branch information
nyalldawson committed Mar 3, 2016
1 parent 5a2ab97 commit 63d6f7b4f8afc43ff9cb36e82efab0850e9c8551
Showing with 12 additions and 1 deletion.
  1. +1 −1 src/providers/mssql/qgsmssqlfeatureiterator.cpp
  2. +11 −0 tests/src/python/providertestbase.py
@@ -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 );
@@ -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 63d6f7b

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