Skip to content

Commit

Permalink
[OGR] Ensure orig_ogc_fid is never set as ignored field
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Sep 25, 2017
1 parent cf23d56 commit 15eaafd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/providers/ogr/qgsogrfeatureiterator.cpp
Expand Up @@ -176,6 +176,7 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource *source, bool
OGR_L_SetAttributeFilter( ogrLayer, nullptr );
}


//start with first feature
rewind();
}
Expand Down
6 changes: 5 additions & 1 deletion src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -1022,7 +1022,11 @@ void QgsOgrProviderUtils::setRelevantFields( OGRLayerH ogrLayer, int fieldCount,
if ( !fetchAttributes.contains( i ) )
{
// add to ignored fields
ignoredFields.append( OGR_Fld_GetNameRef( OGR_FD_GetFieldDefn( featDefn, firstAttrIsFid ? i - 1 : i ) ) );
const char *fieldName = OGR_Fld_GetNameRef( OGR_FD_GetFieldDefn( featDefn, firstAttrIsFid ? i - 1 : i ) );
if ( qstrcmp( fieldName, "orig_ogc_fid" ) != 0 )
{
ignoredFields.append( fieldName );
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions tests/src/python/test_provider_ogr_sqlite.py
Expand Up @@ -254,6 +254,18 @@ def testSubsetStringFids(self):
self.assertTrue(it.nextFeature(f))
self.assertTrue(f.id() == 5)

# Ensure that orig_ogc_fid is still retrieved even if attribute subset is passed
req = QgsFeatureRequest()
req.setSubsetOfAttributes([])
it = vl.getFeatures(req)
ids = []
while it.nextFeature(f):
ids.append(f.id())
self.assertTrue(len(ids) == 3)
self.assertTrue(3 in ids)
self.assertTrue(4 in ids)
self.assertTrue(5 in ids)

# Check that subset string is correctly set on reload
vl.reload()
self.assertTrue(vl.fields().at(vl.fields().count() - 1).name() == "orig_ogc_fid")
Expand Down

0 comments on commit 15eaafd

Please sign in to comment.