QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 #define SIP_NO_FILE
20 
21 #include "qgis_core.h"
22 #include "qgsfields.h"
23 #include "qgsexpressionnodeimpl.h"
24 
25 class QgsExpression;
26 class QgsExpressionNode;
27 
40 class CORE_EXPORT QgsSqlExpressionCompiler
41 {
42  public:
43 
45  enum Result
46  {
47  None,
50  Fail
51  };
52 
56  enum Flag
57  {
58  CaseInsensitiveStringMatch = 1,
59  LikeIsCaseInsensitive = 1 << 1,
60  NoNullInBooleanLogic = 1 << 2,
61  NoUnaryMinus = 1 << 3,
62  IntegerDivisionResultsInInteger = 1 << 4,
63  };
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 
101  bool opIsStringComparison( QgsExpressionNodeBinaryOperator::BinaryOperator op );
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 
153  virtual QString castToReal( const QString &value ) const;
154 
170  virtual QString castToText( const QString &value ) const;
171 
177  virtual QString castToInt( const QString &value ) const;
178 
184  virtual Result replaceNodeByStaticCachedValueIfPossible( const QgsExpressionNode *node, QString &str );
185 
186  QString mResult;
188 
189  private:
190 
191  Flags mFlags;
192 
193  bool mIgnoreStaticNodes = false;
194 
195  bool nodeIsNullLiteral( const QgsExpressionNode *node ) const;
196 
197 };
198 
199 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsSqlExpressionCompiler::Flags )
200 
201 #endif // QGSSQLEXPRESSIONCOMPILER_H
qgsfields.h
QgsSqlExpressionCompiler::Flag
Flag
Enumeration of flags for how provider handles SQL clauses.
Definition: qgssqlexpressioncompiler.h:56
QgsSqlExpressionCompiler::mFields
QgsFields mFields
Definition: qgssqlexpressioncompiler.h:187
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:44
QgsSqlExpressionCompiler
Generic expression compiler for translation to provider specific SQL WHERE clauses.
Definition: qgssqlexpressioncompiler.h:40
QgsSqlExpressionCompiler::Partial
@ Partial
Expression was partially compiled, but provider will return extra records and results must be double-...
Definition: qgssqlexpressioncompiler.h:49
QgsSqlExpressionCompiler::Complete
@ Complete
Expression was successfully compiled and can be completely delegated to provider.
Definition: qgssqlexpressioncompiler.h:48
Q_DECLARE_OPERATORS_FOR_FLAGS
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
QgsExpressionNode
Abstract base class for all nodes that can appear in an expression.
Definition: qgsexpressionnode.h:34
qgsexpressionnodeimpl.h
str
#define str(x)
Definition: qgis.cpp:37
QgsSqlExpressionCompiler::mResult
QString mResult
Definition: qgssqlexpressioncompiler.h:186
QgsExpression
Class for parsing and evaluation of expressions (formerly called "search strings")....
Definition: qgsexpression.h:102
QgsSqlExpressionCompiler::Result
Result
Possible results from expression compilation.
Definition: qgssqlexpressioncompiler.h:45
QgsSqlExpressionCompiler::None
@ None
No expression.
Definition: qgssqlexpressioncompiler.h:47
QgsExpressionNodeBinaryOperator::BinaryOperator
BinaryOperator
list of binary operators
Definition: qgsexpressionnodeimpl.h:107