Skip to content
Permalink
Browse files

Merge pull request #5181 from manisandro/ogr_subsetstring

[OGR] Ensure subset string is set when reopening dataset
  • Loading branch information
manisandro committed Sep 12, 2017
2 parents 4115d06 + 95cd8d7 commit 9dcdefd68e55c8ec429b0fb2cfc652800366349d
Showing with 16 additions and 2 deletions.
  1. +7 −1 src/providers/ogr/qgsogrprovider.cpp
  2. +9 −1 tests/src/python/test_provider_ogr_sqlite.py
@@ -3623,7 +3623,13 @@ void QgsOgrProvider::open( OpenMode mode )
// check that the initial encoding setting is fit for this layer
setEncoding( encoding() );

mValid = setSubsetString( mSubsetString );
// Ensure subset is set (setSubsetString does nothing if the passed sql subset string is equal to mSubsetString, which is the case when reloading the dataset)
QString origSubsetString = mSubsetString;
mSubsetString = "";
// Block signals to avoid endless recusion reloadData -> emit dataChanged -> reloadData
blockSignals( true );
mValid = setSubsetString( origSubsetString );
blockSignals( false );
if ( mValid )
{
if ( mode == OpenModeInitial )
@@ -200,7 +200,10 @@ def testDefaultValues(self):
self.assertTrue(vl.dataProvider().defaultValue(6).secsTo(QDateTime.currentDateTime()) < 1)

def testSubsetStringFids(self):
""" tests that feature ids are stable even if a subset string is set """
"""
- tests that feature ids are stable even if a subset string is set
- tests that the subset string is correctly set on the ogr layer event when reloading the data source (issue #17122)
"""

tmpfile = os.path.join(self.basetestpath, 'subsetStringFids.sqlite')
ds = ogr.GetDriverByName('SQLite').CreateDataSource(tmpfile)
@@ -242,6 +245,7 @@ def testSubsetStringFids(self):

vl = QgsVectorLayer(tmpfile + "|subset=type=2", 'test', 'ogr')
self.assertTrue(vl.isValid())
self.assertTrue(vl.fields().at(0).name() == "orig_ogc_fid")

req = QgsFeatureRequest()
req.setFilterExpression("value=16")
@@ -250,6 +254,10 @@ def testSubsetStringFids(self):
self.assertTrue(it.nextFeature(f))
self.assertTrue(f.id() == 5)

# Check that subset string is correctly set on reload
vl.reload()
self.assertTrue(vl.fields().at(0).name() == "orig_ogc_fid")


if __name__ == '__main__':
unittest.main()

0 comments on commit 9dcdefd

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