Skip to content

Commit ec0b6c9

Browse files
committed
Use QgsFields::fieldNameIndex when preparing column refs in expressions
Fixes handling of duplicate field names with different case in expressions (cherry-picked from 0a84fbd)
1 parent 20e9d64 commit ec0b6c9

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/core/qgsexpression.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -2720,17 +2720,17 @@ QVariant QgsExpression::NodeColumnRef::eval( QgsExpression* /*parent*/, const Qg
27202720

27212721
bool QgsExpression::NodeColumnRef::prepare( QgsExpression* parent, const QgsFields& fields )
27222722
{
2723-
for ( int i = 0; i < fields.count(); ++i )
2723+
mIndex = fields.fieldNameIndex( mName );
2724+
if ( mIndex >= 0 )
27242725
{
2725-
if ( QString::compare( fields[i].name(), mName, Qt::CaseInsensitive ) == 0 )
2726-
{
2727-
mIndex = i;
2728-
return true;
2729-
}
2726+
return true;
2727+
}
2728+
else
2729+
{
2730+
parent->mEvalErrorString = QObject::tr( "Column '%1' not found" ).arg( mName );
2731+
mIndex = -1;
2732+
return false;
27302733
}
2731-
parent->mEvalErrorString = QObject::tr( "Column '%1' not found" ).arg( mName );
2732-
mIndex = -1;
2733-
return false;
27342734
}
27352735

27362736
QString QgsExpression::NodeColumnRef::dump() const

0 commit comments

Comments
 (0)