Skip to content

Commit 0a84fbd

Browse files
committedDec 10, 2015
Use QgsFields::fieldNameIndex when preparing column refs in expressions
1 parent 28cabbe commit 0a84fbd

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed
 

‎src/core/qgsexpression.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3626,17 +3626,17 @@ bool QgsExpression::NodeColumnRef::prepare( QgsExpression *parent, const QgsExpr
36263626

36273627
QgsFields fields = qvariant_cast<QgsFields>( context->variable( QgsExpressionContext::EXPR_FIELDS ) );
36283628

3629-
for ( int i = 0; i < fields.count(); ++i )
3629+
mIndex = fields.fieldNameIndex( mName );
3630+
if ( mIndex >= 0 )
36303631
{
3631-
if ( QString::compare( fields.at( i ).name(), mName, Qt::CaseInsensitive ) == 0 )
3632-
{
3633-
mIndex = i;
3634-
return true;
3635-
}
3632+
return true;
3633+
}
3634+
else
3635+
{
3636+
parent->mEvalErrorString = tr( "Column '%1' not found" ).arg( mName );
3637+
mIndex = -1;
3638+
return false;
36363639
}
3637-
parent->mEvalErrorString = tr( "Column '%1' not found" ).arg( mName );
3638-
mIndex = -1;
3639-
return false;
36403640
}
36413641

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

0 commit comments

Comments
 (0)
Please sign in to comment.