Skip to content

Commit 9dcdefd

Browse files
authoredSep 12, 2017
Merge pull request #5181 from manisandro/ogr_subsetstring
[OGR] Ensure subset string is set when reopening dataset
2 parents 4115d06 + 95cd8d7 commit 9dcdefd

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed
 

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3623,7 +3623,13 @@ void QgsOgrProvider::open( OpenMode mode )
36233623
// check that the initial encoding setting is fit for this layer
36243624
setEncoding( encoding() );
36253625

3626-
mValid = setSubsetString( mSubsetString );
3626+
// 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)
3627+
QString origSubsetString = mSubsetString;
3628+
mSubsetString = "";
3629+
// Block signals to avoid endless recusion reloadData -> emit dataChanged -> reloadData
3630+
blockSignals( true );
3631+
mValid = setSubsetString( origSubsetString );
3632+
blockSignals( false );
36273633
if ( mValid )
36283634
{
36293635
if ( mode == OpenModeInitial )

‎tests/src/python/test_provider_ogr_sqlite.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ def testDefaultValues(self):
200200
self.assertTrue(vl.dataProvider().defaultValue(6).secsTo(QDateTime.currentDateTime()) < 1)
201201

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

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

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

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

257+
# Check that subset string is correctly set on reload
258+
vl.reload()
259+
self.assertTrue(vl.fields().at(0).name() == "orig_ogc_fid")
260+
253261

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

0 commit comments

Comments
 (0)
Please sign in to comment.