Skip to content

Commit 8da496e

Browse files
committedNov 3, 2011
fix NULL support in expression evaluation
1 parent 8e5aa03 commit 8da496e

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed
 

‎src/core/qgsexpression.cpp

100644100755
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ inline bool isDoubleSafe( const QVariant& v )
8787
return false;
8888
}
8989

90-
inline bool isNull( const QVariant& v ) { return v.type() == QVariant::Invalid; }
90+
inline bool isNull( const QVariant& v ) { return v.isNull(); }
9191

9292
///////////////////////////////////////////////
9393
// evaluation error macros
@@ -149,7 +149,7 @@ static int getIntValue( const QVariant& value, QgsExpression* parent )
149149
static TVL getTVLValue( const QVariant& value, QgsExpression* parent )
150150
{
151151
// we need to convert to TVL
152-
if ( value.type() == QVariant::Invalid )
152+
if ( value.isNull() )
153153
return Unknown;
154154

155155
if ( value.type() == QVariant::Int )
@@ -928,13 +928,15 @@ bool QgsExpression::NodeLiteral::prepare( QgsExpression* /*parent*/, const QgsFi
928928

929929
QString QgsExpression::NodeLiteral::dump() const
930930
{
931+
if ( mValue.isNull() )
932+
return "NULL";
933+
931934
switch ( mValue.type() )
932935
{
933-
case QVariant::Invalid: return "NULL";
934936
case QVariant::Int: return QString::number( mValue.toInt() );
935937
case QVariant::Double: return QString::number( mValue.toDouble() );
936938
case QVariant::String: return QString( "'%1'" ).arg( mValue.toString() );
937-
default: return "[unsupported value]";
939+
default: return QString( "[unsupported type;%1; value:%2]" ).arg( mValue.typeName() ).arg( mValue.toString() );
938940
}
939941
}
940942

‎src/core/qgspallabeling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
463463
QgsDebugMsg( "Expression parser error:" + exp->parserErrorString() );
464464
return;
465465
}
466-
QVariant result = exp->evaluate( &f, layer->dataProvider()->fields() );
466+
QVariant result = exp->evaluate( &f, layer->pendingFields() );
467467
if ( exp->hasEvalError() )
468468
{
469469
QgsDebugMsg( "Expression parser eval error:" + exp->evalErrorString() );

0 commit comments

Comments
 (0)
Please sign in to comment.