44 lines
2.2 KiB
Diff
44 lines
2.2 KiB
Diff
From 30449e577f0cd432bd8c60787743fba54c1e51b9 Mon Sep 17 00:00:00 2001
|
|
From: Nyall Dawson <nyall.dawson@gmail.com>
|
|
Date: Thu, 3 Mar 2016 10:34:32 +1100
|
|
Subject: [PATCH] Fix fetching subset of attributes with mssql (fix #14402),
|
|
add test
|
|
|
|
---
|
|
src/providers/mssql/qgsmssqlfeatureiterator.cpp | 2 +-
|
|
tests/src/python/providertestbase.py | 11 +++++++++++
|
|
2 files changed, 12 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/src/providers/mssql/qgsmssqlfeatureiterator.cpp b/src/providers/mssql/qgsmssqlfeatureiterator.cpp
|
|
index 53214d4..560d344 100644
|
|
--- a/src/providers/mssql/qgsmssqlfeatureiterator.cpp
|
|
+++ b/src/providers/mssql/qgsmssqlfeatureiterator.cpp
|
|
@@ -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 );
|
|
diff --git a/tests/src/python/providertestbase.py b/tests/src/python/providertestbase.py
|
|
index 7b8707e..26e6d86 100644
|
|
--- a/tests/src/python/providertestbase.py
|
|
+++ b/tests/src/python/providertestbase.py
|
|
@@ -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))
|