Skip to content
Permalink
Browse files

QGIS expressions are not sensitive to the case of field names, so

mimic this same insensitivity when compiling expressions for providers

Avoids the expression compilation failing whenever a referenced
field in an expression does not exactly match the layer's field
name case.

(cherry picked from commit 52528c5)
  • Loading branch information
nyalldawson committed Mar 19, 2021
1 parent f892b3c commit 69e70d7ec0b74b6a785e466bc62c6afd5ef2a4f4
@@ -325,11 +325,14 @@ QgsSqlExpressionCompiler::Result QgsSqlExpressionCompiler::compileNode( const Qg
{
const QgsExpressionNodeColumnRef *n = static_cast<const QgsExpressionNodeColumnRef *>( node );

if ( mFields.indexFromName( n->name() ) == -1 )
// QGIS expressions don't care about case sensitive field naming, so we match case insensitively here to the
// layer's fields and then retrieve the actual case of the field name for use in the compilation
const int fieldIndex = mFields.lookupField( n->name() );
if ( fieldIndex == -1 )
// Not a provider field
return Fail;

result = quotedIdentifier( n->name() );
result = quotedIdentifier( mFields.at( fieldIndex ).name() );

return Complete;
}
@@ -168,6 +168,8 @@ def runGetFeatureTests(self, source):
self.assert_query(source, '"name" NOT ILIKE \'QGIS\'', [1, 2, 3, 4])
self.assert_query(source, '"name" NOT ILIKE \'pEAR\'', [1, 2, 4])
self.assert_query(source, 'name = \'Apple\'', [2])
# field names themselves are NOT case sensitive -- QGIS expressions don't care about this
self.assert_query(source, '\"NaMe\" = \'Apple\'', [2])
self.assert_query(source, 'name <> \'Apple\'', [1, 3, 4])
self.assert_query(source, 'name = \'apple\'', [])
self.assert_query(source, '"name" <> \'apple\'', [1, 2, 3, 4])
@@ -130,6 +130,7 @@ def partiallyCompiledFilters(self):
filters = set([
'name ILIKE \'QGIS\'',
'name = \'Apple\'',
'\"NaMe\" = \'Apple\'',
'name = \'apple\'',
'name LIKE \'Apple\'',
'name LIKE \'aPple\'',
@@ -227,6 +227,7 @@ def uncompiledFilters(self):
def partiallyCompiledFilters(self):
return set(['name = \'Apple\'',
'name = \'apple\'',
'\"NaMe\" = \'Apple\'',
'name LIKE \'Apple\'',
'name LIKE \'aPple\'',
'name LIKE \'Ap_le\'',

0 comments on commit 69e70d7

Please sign in to comment.