Skip to content

Commit

Permalink
QgsOgrFeatureIterator(): remove (hopefully!) useless code in subset s…
Browse files Browse the repository at this point in the history
…tring case

Those lines where introduced per commit 5a9067e, but it is likely
that a following commit (391ec8a
potentially) make that useless.

I've added an extra test in addition to the one of 80e19b6
to test the case where the FID column is not selected
  • Loading branch information
rouault committed May 29, 2023
1 parent 06fde96 commit 2a318eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/core/providers/ogr/qgsogrfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource *source, bool
mOgrLayer = QgsOgrProviderUtils::setSubsetString( mOgrLayer, mConn->ds, mSource->mEncoding, mSource->mSubsetString );
// If the mSubsetString was a full SELECT ...., then mOgrLayer will be a OGR SQL layer != mOgrLayerOri

mFieldsWithoutFid.clear();
for ( int i = ( mFirstFieldIsFid ) ? 1 : 0; i < mSource->mFields.size(); i++ )
mFieldsWithoutFid.append( mSource->mFields.at( i ) );

if ( !mOgrLayer )
{
close();
Expand Down
10 changes: 10 additions & 0 deletions tests/src/python/test_provider_ogr_gpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,16 @@ def testSelectSubsetString(self):
got = [feat for feat in vl.getFeatures(QgsFeatureRequest(1))]
self.assertEqual(len(got), 1) # this is the current behavior, broken

# Test setSubsetString() with a SELECT ... statement not selecting
# the FID column
vl = QgsVectorLayer(f'{tmpfile}', 'test', 'ogr')
vl.setSubsetString("SELECT name FROM test_layer WHERE name = 'two'")
got = [feat for feat in vl.getFeatures()]
self.assertEqual(len(got), 1)

attributes = got[0].attributes()
self.assertEqual(attributes[0], 'two')

def testEditSubsetString(self):

tmpfile = os.path.join(self.basetestpath, 'testEditSubsetString.gpkg')
Expand Down

0 comments on commit 2a318eb

Please sign in to comment.