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.
  • Loading branch information
nyalldawson committed Feb 11, 2021
1 parent 0e990e1 commit 52528c5dcd984097ee4f960268134588394a57e5
@@ -330,11 +330,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])
@@ -133,6 +133,7 @@ def partiallyCompiledFilters(self):
filters = set([
'name ILIKE \'QGIS\'',
'name = \'Apple\'',
'\"NaMe\" = \'Apple\'',
'name = \'apple\'',
'name LIKE \'Apple\'',
'name LIKE \'aPple\'',
@@ -229,6 +229,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 52528c5

Please sign in to comment.