Skip to content
Permalink
Browse files

Merge pull request #36648 from uclaros/backport-34368

Backport #34368 to 3.10
  • Loading branch information
elpaso committed May 22, 2020
2 parents e91e3d0 + 871def2 commit 1a1aa6222fc634b89a2275a4e323ef0925155d06
Showing with 25 additions and 1 deletion.
  1. +4 −1 src/core/providers/ogr/qgsogrprovider.cpp
  2. +21 −0 tests/src/python/test_provider_shapefile.py
@@ -4382,7 +4382,10 @@ OGRLayerH QgsOgrProviderUtils::setSubsetString( OGRLayerH layer, GDALDatasetH ds
}
else
{
OGR_L_SetAttributeFilter( layer, encoding->fromUnicode( subsetString ).constData() );
if ( OGR_L_SetAttributeFilter( layer, encoding->fromUnicode( subsetString ).constData() ) != OGRERR_NONE )
{
return nullptr;
}
subsetLayer = layer;
}

@@ -769,6 +769,27 @@ def _lessdigits(s):
self.assertEqual(_lessdigits(subSet_vl.extent().toString()), filtered_extent)
self.assertNotEqual(_lessdigits(subSet_vl.extent().toString()), unfiltered_extent)

def testMalformedSubsetStrings(self):
"""Test that invalid where clauses always return false"""

testPath = TEST_DATA_DIR + '/' + 'lines.shp'

vl = QgsVectorLayer(testPath, 'subset_test', 'ogr')
self.assertTrue(vl.isValid())
self.assertTrue(vl.setSubsetString(''))
self.assertTrue(vl.setSubsetString('"Name" = \'Arterial\''))
self.assertTrue(vl.setSubsetString('select * from lines where "Name" = \'Arterial\''))
self.assertFalse(vl.setSubsetString('this is invalid sql'))
self.assertFalse(vl.setSubsetString('select * from lines where "NonExistentField" = \'someValue\''))
self.assertFalse(vl.setSubsetString('select * from lines where "Name" = \'Arte...'))
self.assertFalse(vl.setSubsetString('select * from lines where "Name" in (\'Arterial\', \'Highway\' '))
self.assertFalse(vl.setSubsetString('select * from NonExistentTable'))
self.assertFalse(vl.setSubsetString('select NonExistentField from lines'))
self.assertFalse(vl.setSubsetString('"NonExistentField" = \'someValue\''))
self.assertFalse(vl.setSubsetString('"Name" = \'Arte...'))
self.assertFalse(vl.setSubsetString('"Name" in (\'Arterial\', \'Highway\' '))
self.assertTrue(vl.setSubsetString(''))

def testMultipatch(self):
"""Check that we can deal with multipatch shapefiles, returned natively by OGR as GeometryCollection of TIN"""

0 comments on commit 1a1aa62

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