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(
'\'' );
103 result =
"( NOT " + right +
')';
118 result =
"( - (" + right +
"))";
134 bool partialCompilation =
false;
135 bool failOnPartialNode =
false;
143 partialCompilation =
true;
146 op = QStringLiteral(
"=" );
150 op = QStringLiteral(
">=" );
154 op = QStringLiteral(
">" );
158 op = QStringLiteral(
"<=" );
162 op = QStringLiteral(
"<" );
166 op = QStringLiteral(
"IS" );
170 op = QStringLiteral(
"IS NOT" );
175 op = QStringLiteral(
"LIKE" );
181 op = QStringLiteral(
"LIKE" );
183 op = QStringLiteral(
"ILIKE" );
187 op = QStringLiteral(
"NOT LIKE" );
195 op = QStringLiteral(
"NOT LIKE" );
197 op = QStringLiteral(
"NOT ILIKE" );
203 if ( nodeIsNullLiteral( n->
opLeft() ) || nodeIsNullLiteral( n->
opRight() ) )
207 op = QStringLiteral(
"OR" );
213 if ( nodeIsNullLiteral( n->
opLeft() ) || nodeIsNullLiteral( n->
opRight() ) )
217 op = QStringLiteral(
"AND" );
222 op = QStringLiteral(
"<>" );
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(
"~" );
280 if ( right.isEmpty() )
287 result =
'(' + left +
' ' + op +
' ' + right +
')';
291 if ( result.isEmpty() )
362 result = QStringLiteral(
"%1 %2IN (%3)" ).arg( nd, n->
isNotIn() ? QStringLiteral(
"NOT " ) : QString(), list.join(
',' ) );
398 result = QStringLiteral(
"%1(%2)" ).arg( nd, args.join(
',' ) );
421 return QStringList( fnArgs );
441 bool QgsSqlExpressionCompiler::nodeIsNullLiteral(
const QgsExpressionNode *node )
const 447 return nLit->
value().isNull();
Class for parsing and evaluation of expressions (formerly called "search strings").
QgsExpressionNode::NodeList * args() const
Returns a list of arguments specified for the function.
virtual QString castToText(const QString &value) const
Casts a value to a text result.
Provider treats LIKE as case-insensitive.
QgsExpressionNode * opRight() const
Returns the node to the right of the operator.
virtual Result compile(const QgsExpression *exp)
Compiles an expression and returns the result of the compilation.
Container of fields for a vector layer.
QgsExpressionNode::NodeList * list() const
Returns the list of nodes to search for matching values within.
Provider cannot handle expression.
QgsExpressionNode * opLeft() const
Returns the node to the left of the operator.
QString name() const
The name of the column.
Provider does not support using NULL with boolean logic, e.g., "(...) OR NULL".
QgsSqlExpressionCompiler(const QgsFields &fields, QgsSqlExpressionCompiler::Flags flags=Flags())
Constructor for expression compiler.
Provider does not unary minus, e.g., " -( 100 * 2 ) = ...".
int indexFromName(const QString &fieldName) const
Gets the field index from the field name.
virtual QString quotedValue(const QVariant &value, bool &ok)
Returns a quoted attribute value, in the format expected by the provider.
virtual QStringList sqlArgumentsFromFunctionName(const QString &fnName, const QStringList &fnArgs) const
Returns the Arguments for SQL function for the expression function.
BinaryOperator
list of binary operators
An expression node for value IN or NOT IN clauses.
An expression node which takes it value from a feature's field.
bool opIsStringComparison(QgsExpressionNodeBinaryOperator::BinaryOperator op)
Returns true if op is one of.
Abstract base class for all nodes that can appear in an expression.
An expression node for expression functions.
static const QList< QgsExpressionFunction * > & Functions()
QString name() const
The name of the function.
virtual QString sqlFunctionFromFunctionName(const QString &fnName) const
Returns the SQL function for the expression function.
A abstract base class for defining QgsExpression functions.
QList< QgsExpressionNode * > list()
Gets a list of all the nodes.
QgsExpressionNodeUnaryOperator::UnaryOperator op() const
Returns the unary operator.
virtual QString castToInt(const QString &value) const
Casts a value to a integer result.
Result
Possible results from expression compilation.
An expression node for literal values.
Expression was partially compiled, but provider will return extra records and results must be double-...
Expression was successfully compiled and can be completely delegated to provider. ...
const QgsExpressionNode * rootNode() const
Returns root node of the expression. Root node is null is parsing has failed.
virtual QString castToReal(const QString &value) const
Casts a value to a real result.
A unary node is either negative as in boolean (not) or as in numbers (minus).
Provider performs case-insensitive string matching for all strings.
A binary expression operator, which operates on two values.
virtual QString quotedIdentifier(const QString &identifier)
Returns a quoted column identifier, in the format expected by the provider.
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.
QgsExpressionNode * node() const
Returns the expression node.
bool isNotIn() const
Returns true if this node is a "NOT IN" operator, or false if the node is a normal "IN" operator...
virtual QgsExpressionNode::NodeType nodeType() const =0
Gets the type of this node.
QgsExpressionNode * operand() const
Returns the node the operator will operate upon.
QgsExpressionNodeBinaryOperator::BinaryOperator op() const
Returns the binary operator.
QVariant value() const
The value of the literal.
int fnIndex() const
Returns the index of the node's function.
Dividing int by int results in int on provider. Subclass must implement the castToReal() function to ...