QGIS API Documentation 3.99.0-Master (c22de0620c0)
Loading...
Searching...
No Matches
qgssqlexpressioncompiler.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssqlexpressioncompiler.h
3 --------------------------
4 begin : November 2015
5 copyright : (C) 2015 Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSSQLEXPRESSIONCOMPILER_H
17#define QGSSQLEXPRESSIONCOMPILER_H
18
19
20#include "qgis_core.h"
22#include "qgsfields.h"
23
24#define SIP_NO_FILE
25
26class QgsExpression;
28
39
40class CORE_EXPORT QgsSqlExpressionCompiler
41{
42 public:
43
52
64 Q_DECLARE_FLAGS( Flags, Flag )
65
66
74 explicit QgsSqlExpressionCompiler( const QgsFields &fields, QgsSqlExpressionCompiler::Flags flags = Flags(), bool ignoreStaticNodes = false );
75 virtual ~QgsSqlExpressionCompiler() = default;
76
80 virtual Result compile( const QgsExpression *exp );
81
85 virtual QString result();
86
102
103 protected:
104
111 virtual QString quotedIdentifier( const QString &identifier );
112
120 virtual QString quotedValue( const QVariant &value, bool &ok );
121
128 virtual Result compileNode( const QgsExpressionNode *node, QString &str );
129
136 virtual QString sqlFunctionFromFunctionName( const QString &fnName ) const;
137
145 virtual QStringList sqlArgumentsFromFunctionName( const QString &fnName, const QStringList &fnArgs ) const;
146
152 virtual QString castToReal( const QString &value ) const;
153
169 virtual QString castToText( const QString &value ) const;
170
175 virtual QString castToInt( const QString &value ) const;
176
182 virtual Result replaceNodeByStaticCachedValueIfPossible( const QgsExpressionNode *node, QString &str );
183
184 QString mResult;
186
187 private:
188
189 Flags mFlags;
190
191 bool mIgnoreStaticNodes = false;
192
193 bool nodeIsNullLiteral( const QgsExpressionNode *node ) const;
194
195};
196
198
199#endif // QGSSQLEXPRESSIONCOMPILER_H
Abstract base class for all nodes that can appear in an expression.
Handles parsing and evaluation of expressions (formerly called "search strings").
Container of fields for a vector layer.
Definition qgsfields.h:46
virtual Result compileNode(const QgsExpressionNode *node, QString &str)
Compiles an expression node and returns the result of the compilation.
virtual Result compile(const QgsExpression *exp)
Compiles an expression and returns the result of the compilation.
Result
Possible results from expression compilation.
@ Fail
Provider cannot handle expression.
@ Complete
Expression was successfully compiled and can be completely delegated to provider.
@ Partial
Expression was partially compiled, but provider will return extra records and results must be double-...
virtual QStringList sqlArgumentsFromFunctionName(const QString &fnName, const QStringList &fnArgs) const
Returns the Arguments for SQL function for the expression function.
virtual Result replaceNodeByStaticCachedValueIfPossible(const QgsExpressionNode *node, QString &str)
Tries to replace a node by its static cached value where possible.
virtual ~QgsSqlExpressionCompiler()=default
virtual QString result()
Returns the compiled expression string for use by the provider.
virtual QString quotedValue(const QVariant &value, bool &ok)
Returns a quoted attribute value, in the format expected by the provider.
virtual QString castToText(const QString &value) const
Casts a value to a text result.
virtual QString castToInt(const QString &value) const
Casts a value to a integer result.
virtual QString quotedIdentifier(const QString &identifier)
Returns a quoted column identifier, in the format expected by the provider.
virtual QString sqlFunctionFromFunctionName(const QString &fnName) const
Returns the SQL function for the expression function.
QgsSqlExpressionCompiler(const QgsFields &fields, QgsSqlExpressionCompiler::Flags flags=Flags(), bool ignoreStaticNodes=false)
Constructor for expression compiler.
virtual QString castToReal(const QString &value) const
Casts a value to a real result.
bool opIsStringComparison(QgsExpressionNodeBinaryOperator::BinaryOperator op)
Returns true if op is one of.
Flag
Enumeration of flags for how provider handles SQL clauses.
@ LikeIsCaseInsensitive
Provider treats LIKE as case-insensitive.
@ NoUnaryMinus
Provider does not unary minus, e.g., " -( 100 * 2 ) = ...".
@ CaseInsensitiveStringMatch
Provider performs case-insensitive string matching for all strings.
@ NoNullInBooleanLogic
Provider does not support using NULL with boolean logic, e.g., "(...) OR NULL".
@ IntegerDivisionResultsInInteger
Dividing int by int results in int on provider. Subclass must implement the castToReal() function to ...
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)