Skip to content

Commit

Permalink
Use QgsFields::fieldNameIndex when preparing column refs in expressions
Browse files Browse the repository at this point in the history
Fixes handling of duplicate field names with different case in
expressions

(cherry-picked from 0a84fbd)
  • Loading branch information
nyalldawson committed Feb 23, 2016
1 parent 20e9d64 commit ec0b6c9
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/core/qgsexpression.cpp
Expand Up @@ -2720,17 +2720,17 @@ QVariant QgsExpression::NodeColumnRef::eval( QgsExpression* /*parent*/, const Qg

bool QgsExpression::NodeColumnRef::prepare( QgsExpression* parent, const QgsFields& fields )
{
for ( int i = 0; i < fields.count(); ++i )
mIndex = fields.fieldNameIndex( mName );
if ( mIndex >= 0 )
{
if ( QString::compare( fields[i].name(), mName, Qt::CaseInsensitive ) == 0 )
{
mIndex = i;
return true;
}
return true;
}
else
{
parent->mEvalErrorString = QObject::tr( "Column '%1' not found" ).arg( mName );
mIndex = -1;
return false;
}
parent->mEvalErrorString = QObject::tr( "Column '%1' not found" ).arg( mName );
mIndex = -1;
return false;
}

QString QgsExpression::NodeColumnRef::dump() const
Expand Down

0 comments on commit ec0b6c9

Please sign in to comment.