Skip to content
Permalink
Browse files

fix NULL support in expression evaluation

  • Loading branch information
jef-n committed Nov 3, 2011
1 parent 8e5aa03 commit 8da496e6d77c75b8c8c0fd3435845f133875ca09
Showing with 7 additions and 5 deletions.
  1. +6 −4 src/core/qgsexpression.cpp
  2. +1 −1 src/core/qgspallabeling.cpp
10 src/core/qgsexpression.cpp 100644 → 100755
@@ -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
@@ -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 )
@@ -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() );
}
}

@@ -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() );

0 comments on commit 8da496e

Please sign in to comment.
You can’t perform that action at this time.