QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
24 , mIgnoreStaticNodes( ignoreStaticNodes )
43 if ( op == QgsExpressionNodeBinaryOperator::BinaryOperator::boILike ||
44 op == QgsExpressionNodeBinaryOperator::BinaryOperator::boLike ||
45 op == QgsExpressionNodeBinaryOperator::BinaryOperator::boNotILike ||
46 op == QgsExpressionNodeBinaryOperator::BinaryOperator::boNotLike ||
47 op == QgsExpressionNodeBinaryOperator::BinaryOperator::boRegexp )
55 QString quoted = identifier;
56 quoted.replace(
'"', QLatin1String(
"\"\"" ) );
57 quoted = quoted.prepend(
'\"' ).append(
'\"' );
66 return QStringLiteral(
"NULL" );
68 switch ( value.type() )
71 case QVariant::LongLong:
72 case QVariant::Double:
73 return value.toString();
76 return value.toBool() ? QStringLiteral(
"TRUE" ) : QStringLiteral(
"FALSE" );
79 case QVariant::String:
80 QString v = value.toString();
81 v.replace(
'\'', QLatin1String(
"''" ) );
82 if ( v.contains(
'\\' ) )
83 return v.replace(
'\\', QLatin1String(
"\\\\" ) ).prepend(
"E'" ).append(
'\'' );
85 return v.prepend(
'\'' ).append(
'\'' );
92 if ( staticRes !=
Fail )
107 result =
"( NOT " + right +
')';
122 result =
"( - (" + right +
"))";
138 bool partialCompilation =
false;
139 bool failOnPartialNode =
false;
147 partialCompilation =
true;
150 op = QStringLiteral(
"=" );
154 op = QStringLiteral(
">=" );
158 op = QStringLiteral(
">" );
162 op = QStringLiteral(
"<=" );
166 op = QStringLiteral(
"<" );
170 op = QStringLiteral(
"IS" );
174 op = QStringLiteral(
"IS NOT" );
179 op = QStringLiteral(
"LIKE" );
185 op = QStringLiteral(
"LIKE" );
187 op = QStringLiteral(
"ILIKE" );
191 op = QStringLiteral(
"NOT LIKE" );
199 op = QStringLiteral(
"NOT LIKE" );
201 op = QStringLiteral(
"NOT ILIKE" );
207 if ( nodeIsNullLiteral( n->
opLeft() ) || nodeIsNullLiteral( n->
opRight() ) )
211 op = QStringLiteral(
"OR" );
217 if ( nodeIsNullLiteral( n->
opLeft() ) || nodeIsNullLiteral( n->
opRight() ) )
221 op = QStringLiteral(
"AND" );
226 op = QStringLiteral(
"<>" );
230 op = QStringLiteral(
"*" );
234 op = QStringLiteral(
"+" );
238 op = QStringLiteral(
"-" );
242 op = QStringLiteral(
"/" );
246 op = QStringLiteral(
"%" );
250 op = QStringLiteral(
"||" );
254 op = QStringLiteral(
"/" );
258 op = QStringLiteral(
"^" );
262 op = QStringLiteral(
"~" );
284 if ( right.isEmpty() )
291 result =
'(' + left +
' ' + op +
' ' + right +
')';
343 res.append( n->
negate() ? QStringLiteral(
" NOT BETWEEN %1" ).arg( s ) : QStringLiteral(
" BETWEEN %1" ).arg( s ) );
358 res.append( QStringLiteral(
" AND %1" ).arg( s ) );
360 return betweenResult;
388 if ( fieldIndex == -1 )
403 const auto constList = n->
list()->
list();
423 result = QStringLiteral(
"%1 %2IN (%3)" ).arg( nd, n->
isNotIn() ? QStringLiteral(
"NOT " ) : QString(), list.join(
',' ) );
441 const auto constList = n->
args()->
list();
460 result = !nd.isEmpty() ? QStringLiteral(
"%1(%2)" ).arg( nd, args.join(
',' ) ) : args.join(
',' );
483 return QStringList( fnArgs );
505 if ( mIgnoreStaticNodes )
527 bool QgsSqlExpressionCompiler::nodeIsNullLiteral(
const QgsExpressionNode *node )
const
533 return nLit->
value().isNull();
QgsExpressionNodeBinaryOperator::BinaryOperator op() const
Returns the binary operator.
@ LikeIsCaseInsensitive
Provider treats LIKE as case-insensitive.
An expression node for literal values.
virtual Result replaceNodeByStaticCachedValueIfPossible(const QgsExpressionNode *node, QString &str)
Tries to replace a node by its static cached value where possible.
A binary expression operator, which operates on two values.
@ ntBetweenOperator
Between operator.
QgsExpressionNode * node() const
Returns the expression node.
virtual Result compileNode(const QgsExpressionNode *node, QString &str)
Compiles an expression node and returns the result of the compilation.
virtual QString result()
Returns the compiled expression string for use by the provider.
const QgsExpressionNode * rootNode() const
Returns the root node of the expression.
An expression node which takes it value from a feature's field.
QVariant value() const
The value of the literal.
int fnIndex() const
Returns the index of the node's function.
Container of fields for a vector layer.
virtual QString castToInt(const QString &value) const
Casts a value to a integer result.
A unary node is either negative as in boolean (not) or as in numbers (minus).
QgsExpressionNode * lowerBound() const
Returns the lower bound expression node of the range.
bool opIsStringComparison(QgsExpressionNodeBinaryOperator::BinaryOperator op)
Returns true if op is one of.
@ Partial
Expression was partially compiled, but provider will return extra records and results must be double-...
@ Complete
Expression was successfully compiled and can be completely delegated to provider.
@ CaseInsensitiveStringMatch
Provider performs case-insensitive string matching for all strings.
virtual QString castToText(const QString &value) const
Casts a value to a text result.
QgsExpressionNodeUnaryOperator::UnaryOperator op() const
Returns the unary operator.
virtual QString quotedValue(const QVariant &value, bool &ok)
Returns a quoted attribute value, in the format expected by the provider.
An expression node for value IN or NOT IN clauses.
virtual QString sqlFunctionFromFunctionName(const QString &fnName) const
Returns the SQL function for the expression function.
QgsExpressionNode * higherBound() const
Returns the higher bound expression node of the range.
QgsExpressionNode::NodeList * args() const
Returns a list of arguments specified for the function.
@ IntegerDivisionResultsInInteger
Dividing int by int results in int on provider. Subclass must implement the castToReal() function to ...
SQL-like BETWEEN and NOT BETWEEN predicates.
QgsExpressionNode * operand() const
Returns the node the operator will operate upon.
QgsExpressionNode * node() const
Returns the expression node.
@ Fail
Provider cannot handle expression.
An expression node for expression functions.
static const QList< QgsExpressionFunction * > & Functions()
QList< QgsExpressionNode * > list()
Gets a list of all the nodes.
Abstract base class for all nodes that can appear in an expression.
bool negate() const
Returns true if the predicate is an exclusion test (NOT BETWEEN).
bool isNotIn() const
Returns true if this node is a "NOT IN" operator, or false if the node is a normal "IN" operator.
QString name() const
The name of the column.
A abstract base class for defining QgsExpression functions.
QgsExpressionNode * opLeft() const
Returns the node to the left of the operator.
QString name() const
The name of the function.
QgsSqlExpressionCompiler(const QgsFields &fields, QgsSqlExpressionCompiler::Flags flags=Flags(), bool ignoreStaticNodes=false)
Constructor for expression compiler.
@ NoNullInBooleanLogic
Provider does not support using NULL with boolean logic, e.g., "(...) OR NULL".
bool hasCachedStaticValue() const
Returns true if the node can be replaced by a static cached value.
virtual QString castToReal(const QString &value) const
Casts a value to a real result.
virtual Result compile(const QgsExpression *exp)
Compiles an expression and returns the result of the compilation.
QgsExpressionNode::NodeList * list() const
Returns the list of nodes to search for matching values within.
@ NoUnaryMinus
Provider does not unary minus, e.g., " -( 100 * 2 ) = ...".
QgsExpressionNode * opRight() const
Returns the node to the right of the operator.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Class for parsing and evaluation of expressions (formerly called "search strings")....
Result
Possible results from expression compilation.
@ ntIndexOperator
Index operator.
virtual QStringList sqlArgumentsFromFunctionName(const QString &fnName, const QStringList &fnArgs) const
Returns the Arguments for SQL function for the expression function.
virtual QgsExpressionNode::NodeType nodeType() const =0
Gets the type of this node.
BinaryOperator
list of binary operators
virtual QString quotedIdentifier(const QString &identifier)
Returns a quoted column identifier, in the format expected by the provider.
QVariant cachedStaticValue() const
Returns the node's static cached value.