Skip to content

Commit

Permalink
fix NULL support in expression evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Nov 3, 2011
1 parent 8e5aa03 commit 8da496e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/core/qgsexpression.cpp 100644 → 100755
Expand Up @@ -87,7 +87,7 @@ inline bool isDoubleSafe( const QVariant& v )
return false;
}

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

///////////////////////////////////////////////
// evaluation error macros
Expand Down Expand Up @@ -149,7 +149,7 @@ static int getIntValue( const QVariant& value, QgsExpression* parent )
static TVL getTVLValue( const QVariant& value, QgsExpression* parent )
{
// we need to convert to TVL
if ( value.type() == QVariant::Invalid )
if ( value.isNull() )
return Unknown;

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

QString QgsExpression::NodeLiteral::dump() const
{
if ( mValue.isNull() )
return "NULL";

switch ( mValue.type() )
{
case QVariant::Invalid: return "NULL";
case QVariant::Int: return QString::number( mValue.toInt() );
case QVariant::Double: return QString::number( mValue.toDouble() );
case QVariant::String: return QString( "'%1'" ).arg( mValue.toString() );
default: return "[unsupported value]";
default: return QString( "[unsupported type;%1; value:%2]" ).arg( mValue.typeName() ).arg( mValue.toString() );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgspallabeling.cpp
Expand Up @@ -463,7 +463,7 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
QgsDebugMsg( "Expression parser error:" + exp->parserErrorString() );
return;
}
QVariant result = exp->evaluate( &f, layer->dataProvider()->fields() );
QVariant result = exp->evaluate( &f, layer->pendingFields() );
if ( exp->hasEvalError() )
{
QgsDebugMsg( "Expression parser eval error:" + exp->evalErrorString() );
Expand Down

0 comments on commit 8da496e

Please sign in to comment.