Skip to content

Commit b3a8d6f

Browse files
authoredSep 12, 2017
Merge pull request #5182 from manisandro/ogr_subsetsetring
[OGR] Ensure subset string is set when reopening dataset
2 parents b035704 + 54653e4 commit b3a8d6f

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
@@ -3574,7 +3574,13 @@ void QgsOgrProvider::open( OpenMode mode )
35743574
// check that the initial encoding setting is fit for this layer
35753575
setEncoding( encoding() );
35763576

3577-
mValid = setSubsetString( mSubsetString );
3577+
// 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)
3578+
QString origSubsetString = mSubsetString;
3579+
mSubsetString = "";
3580+
// Block signals to avoid endless recusion reloadData -> emit dataChanged -> reloadData
3581+
blockSignals( true );
3582+
mValid = setSubsetString( origSubsetString );
3583+
blockSignals( false );
35783584
if ( mValid )
35793585
{
35803586
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
@@ -130,7 +130,10 @@ def testFidSupport(self):
130130
self.assertEqual(got, [(12, 123)])
131131

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

135138
tmpfile = os.path.join(self.basetestpath, 'subsetStringFids.sqlite')
136139
ds = ogr.GetDriverByName('SQLite').CreateDataSource(tmpfile)
@@ -172,6 +175,7 @@ def testSubsetStringFids(self):
172175

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

176180
req = QgsFeatureRequest()
177181
req.setFilterExpression("value=16")
@@ -180,6 +184,10 @@ def testSubsetStringFids(self):
180184
self.assertTrue(it.nextFeature(f))
181185
self.assertTrue(f.id() == 5)
182186

187+
# Check that subset string is correctly set on reload
188+
vl.reload()
189+
self.assertTrue(vl.fields().at(0).name() == "orig_ogc_fid")
190+
183191

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

0 commit comments

Comments
 (0)
Please sign in to comment.