Skip to content
Permalink
Browse files
add optional type parameter to QgsExpression::createFieldEqualityExpr…
…ession
  • Loading branch information
3nids committed Nov 8, 2021
1 parent 00554ef commit 4b3c50d59ef765499ad801244a8657a29947bae9
Showing with 8 additions and 4 deletions.
  1. +2 −1 python/core/auto_generated/expression/qgsexpression.sip.in
  2. +4 −2 src/core/expression/qgsexpression.cpp
  3. +2 −1 src/core/expression/qgsexpression.h
@@ -673,13 +673,14 @@ length, and presents text representations of non numeric/text types (e.g., geome
.. versionadded:: 2.14
%End

static QString createFieldEqualityExpression( const QString &fieldName, const QVariant &value );
static QString createFieldEqualityExpression( const QString &fieldName, const QVariant &value, QVariant::Type fieldType = QVariant::Type::Invalid );
%Docstring
Create an expression allowing to evaluate if a field is equal to a
value. The value may be null.

:param fieldName: the name of the field
:param value: the value of the field
:param fieldType: the type of the field on the left side used to quote the value. If not given, the value type is used instead

:return: the expression to evaluate field equality

@@ -1112,14 +1112,16 @@ QString QgsExpression::formatPreviewString( const QVariant &value, const bool ht
}
}

QString QgsExpression::createFieldEqualityExpression( const QString &fieldName, const QVariant &value )
QString QgsExpression::createFieldEqualityExpression( const QString &fieldName, const QVariant &value, QVariant::Type fieldType )
{
QString expr;

if ( value.isNull() )
expr = QStringLiteral( "%1 IS NULL" ).arg( quotedColumnRef( fieldName ) );
else
else if ( fieldType == QVariant::Type::Invalid )
expr = QStringLiteral( "%1 = %2" ).arg( quotedColumnRef( fieldName ), quotedValue( value ) );
else
expr = QStringLiteral( "%1 = %2" ).arg( quotedColumnRef( fieldName ), quotedValue( value, fieldType ) );

return expr;
}
@@ -659,10 +659,11 @@ class CORE_EXPORT QgsExpression
* value. The value may be null.
* \param fieldName the name of the field
* \param value the value of the field
* \param fieldType the type of the field on the left side used to quote the value. If not given, the value type is used instead
* \returns the expression to evaluate field equality
* \since QGIS 3.0
*/
static QString createFieldEqualityExpression( const QString &fieldName, const QVariant &value );
static QString createFieldEqualityExpression( const QString &fieldName, const QVariant &value, QVariant::Type fieldType = QVariant::Type::Invalid );

/**
* Returns TRUE if the given \a expression is a simple "field=value" type expression.

0 comments on commit 4b3c50d

Please sign in to comment.