Skip to content
Permalink
Browse files

Add boolean node literal to expressions

  • Loading branch information
m-kuhn committed Jul 20, 2015
1 parent 5be0ee7 commit 7573078e2edaf9ccbf4658bacbc239ab5c17c250
@@ -2803,6 +2803,7 @@ QString QgsExpression::NodeLiteral::dump() const
case QVariant::Int: return QString::number( mValue.toInt() );
case QVariant::Double: return QString::number( mValue.toDouble() );
case QVariant::String: return quotedString( mValue.toString() );
case QVariant::Bool: return mValue.toBool() ? "TRUE" : "FALSE";
default: return QObject::tr( "[unsupported type;%1; value:%2]" ).arg( mValue.typeName() ).arg( mValue.toString() );
}
}
@@ -115,6 +115,7 @@ column_ref_quoted "\""{col_str_char}*"\""
dig [0-9]
num_int {dig}+
num_float {dig}*(\.{dig}+([eE][-+]?{dig}+)?|[eE][-+]?{dig}+)
boolean "TRUE"|"FALSE"
str_char ('')|(\\.)|[^'\\]
string "'"{str_char}*"'"
@@ -188,6 +189,8 @@ string "'"{str_char}*"'"
return Unknown_CHARACTER;
}
{boolean} { yylval->boolVal = QString( yytext ).compare( "true", Qt::CaseInsensitive ) == 0; return BOOLEAN; }
{string} { TEXT_FILTER(stripText); return STRING; }
{special_col} { TEXT; return SPECIAL_COL; }
@@ -79,6 +79,7 @@ struct expression_parser_context
QgsExpression::NodeList* nodelist;
double numberFloat;
int numberInt;
bool boolVal;
QString* text;
QgsExpression::BinaryOperator b_op;
QgsExpression::UnaryOperator u_op;
@@ -101,6 +102,7 @@ struct expression_parser_context
// literals
%token <numberFloat> NUMBER_FLOAT
%token <numberInt> NUMBER_INT
%token <boolVal> BOOLEAN
%token NULLVALUE

// tokens for conditional expressions
@@ -254,6 +256,7 @@ expression:
// literals
| NUMBER_FLOAT { $$ = new QgsExpression::NodeLiteral( QVariant($1) ); }
| NUMBER_INT { $$ = new QgsExpression::NodeLiteral( QVariant($1) ); }
| BOOLEAN { $$ = new QgsExpression::NodeLiteral( QVariant($1) ); }
| STRING { $$ = new QgsExpression::NodeLiteral( QVariant(*$1) ); delete $1; }
| NULLVALUE { $$ = new QgsExpression::NodeLiteral( QVariant() ); }
;
@@ -435,7 +435,7 @@ bool QgsRuleBasedRendererV2::Rule::startRender( QgsRenderContext& context, const
if ( isElse() )
{
if ( !sf.length() )
filter = "1";
filter = "TRUE";
else
filter = sf;
}
@@ -907,6 +907,9 @@ QString QgsPostgresConn::quotedValue( QVariant value )
case QVariant::Double:
return value.toString();

case QVariant::Bool:
return value.toBool() ? "TRUE" : "FALSE";

default:
case QVariant::String:
QString v = value.toString();
@@ -190,6 +190,8 @@ class TestQgsExpression: public QObject
QTest::newRow( "literal double" ) << ".000001" << false << QVariant( 0.000001 );
QTest::newRow( "literal double" ) << "1.0e-6" << false << QVariant( 0.000001 );
QTest::newRow( "literal double" ) << "1e-6" << false << QVariant( 0.000001 );
QTest::newRow( "literal FALSE" ) << "FALSE" << false << QVariant( false );
QTest::newRow( "literal TRUE" ) << "TRUE" << false << QVariant( true );

// unary minus
QTest::newRow( "unary minus double" ) << "-1.3" << false << QVariant( -1.3 );
@@ -492,6 +494,9 @@ class TestQgsExpression: public QObject
case QVariant::Double:
QCOMPARE( res.toDouble(), result.toDouble() );
break;
case QVariant::Bool:
QCOMPARE( res.toBool(), result.toBool() );
break;
case QVariant::String:
QCOMPARE( res.toString(), result.toString() );
break;
@@ -51,6 +51,7 @@ def runGetFeatureTests(self, provider):
self.assert_query(provider, '"name" || \' \' || "cnt" = \'Orange 100\'', [1])
self.assert_query(provider, 'cnt = 10 ^ 2', [1])
self.assert_query(provider, '"name" ~ \'[OP]ra[gne]+\'', [1])
self.assert_query(provider, 'true', [1, 2, 3, 4, 5])


def testGetFeaturesUncompiled(self):

0 comments on commit 7573078

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