Skip to content
Permalink
Browse files

Fix text encoding in request filter expression

  • Loading branch information
mhugo committed Feb 22, 2016
1 parent 83c57ef commit 3dea491deda17036f6da826077faf623f8c31e0f
@@ -94,7 +94,7 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource* source, bool
if ( result == QgsSqlExpressionCompiler::Complete || result == QgsSqlExpressionCompiler::Partial )
{
QString whereClause = compiler.result();
if ( OGR_L_SetAttributeFilter( ogrLayer, whereClause.toLocal8Bit().data() ) == OGRERR_NONE )
if ( OGR_L_SetAttributeFilter( ogrLayer, mSource->mEncoding->fromUnicode( whereClause ).constData() ) == OGRERR_NONE )
{
//if only partial success when compiling expression, we need to double-check results using QGIS' expressions
mExpressionCompiled = ( result == QgsSqlExpressionCompiler::Complete );
@@ -57,6 +57,22 @@ def test_FilterExpression(self):
myMessage = '\nExpected: {0} features\nGot: {1} features'.format(repr(expectedIds), repr(ids))
assert ids == expectedIds, myMessage

def test_FilterExpressionWithAccents(self):
myShpFile = os.path.join(TEST_DATA_DIR, 'france_parts.shp')
layer = QgsVectorLayer(myShpFile, 'poly', 'ogr')

layer.setProviderEncoding("ISO-8859-1")
ids = [feat.id() for feat in layer.getFeatures(QgsFeatureRequest().setFilterExpression(u"TYPE_1 = 'Région'"))]
expectedIds = [0, 1, 2, 3]
myMessage = '\nExpected: {0} features\nGot: {1} features'.format(repr(expectedIds), repr(ids))
assert ids == expectedIds, myMessage

layer.setProviderEncoding("UTF-8")
ids = [feat.id() for feat in layer.getFeatures(QgsFeatureRequest().setFilterExpression(u"TYPE_1 = 'Région'"))]
expectedIds = []
myMessage = '\nExpected: {0} features\nGot: {1} features'.format(repr(expectedIds), repr(ids))
assert ids == expectedIds, myMessage

def test_FilterFids(self):
# create point layer
myShpFile = os.path.join(TEST_DATA_DIR, 'points.shp')
BIN +0 Bytes (100%) tests/testdata/france_parts.dbf
Binary file not shown.

0 comments on commit 3dea491

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