diff --git a/src/core/expression/qgsexpressionnodeimpl.cpp b/src/core/expression/qgsexpressionnodeimpl.cpp index 09e3951833f..b05fa69761c 100644 --- a/src/core/expression/qgsexpressionnodeimpl.cpp +++ b/src/core/expression/qgsexpressionnodeimpl.cpp @@ -716,7 +716,7 @@ bool QgsExpressionNodeBinaryOperator::prepareNode( QgsExpression *parent, const if ( op->op() == boEQ ) { // If left is a column ref and right is a literal, collect - if ( dynamic_cast( op->opLeft() ) && dynamic_cast( op->opRight() ) ) + if ( ( dynamic_cast( op->opLeft() ) && dynamic_cast( op->opRight() ) ) ) { const QString fieldName = op->opLeft()->dump(); if ( !orValuesMap.contains( fieldName ) ) @@ -727,6 +727,17 @@ bool QgsExpressionNodeBinaryOperator::prepareNode( QgsExpression *parent, const orValuesMap[fieldName].append( op->opRight()->clone() ); return true; } + else if ( ( dynamic_cast( op->opRight() ) && dynamic_cast( op->opLeft() ) ) ) + { + const QString fieldName = op->opRight()->dump(); + if ( !orValuesMap.contains( fieldName ) ) + { + orFieldNames.append( fieldName ); + orValuesMap.insert( fieldName, QgsExpressionNode::NodeList() ); + } + orValuesMap[fieldName].append( op->opLeft()->clone() ); + return true; + } return false; } diff --git a/tests/src/core/testqgsexpression.cpp b/tests/src/core/testqgsexpression.cpp index c5805238931..41ba1b0e724 100644 --- a/tests/src/core/testqgsexpression.cpp +++ b/tests/src/core/testqgsexpression.cpp @@ -5600,6 +5600,7 @@ class TestQgsExpression: public QObject QTest::newRow( "simple3 mixed" ) << QStringLiteral( "field = 'value' OR field = 'value2' OR field2 = 'value3'" ) << QStringLiteral( "field IN ('value', 'value2') OR field2 = 'value3'" ); QTest::newRow( "simple3 mixed 2" ) << QStringLiteral( "field2 = 'value3' OR field = 'value1' OR field = 'value2'" ) << QStringLiteral( "field2 = 'value3' OR field IN ('value1', 'value2')" ); QTest::newRow( "simple3 mixed 3" ) << QStringLiteral( "field = 'value1' OR field2 = 'value3' OR field = 'value2'" ) << QStringLiteral( "field IN ('value1', 'value2') OR field2 = 'value3'" ); + QTest::newRow( "simple mixed order" ) << QStringLiteral( "field = 'value' OR 'value2' = field OR field = 'value3'" ) << QStringLiteral( "field IN ('value', 'value2', 'value3')" ); // test with IN QTest::newRow( "simple IN" ) << QStringLiteral( "field IN ('value', 'value2') OR field = 'value3'" ) << QStringLiteral( "field IN ('value', 'value2', 'value3')" );