QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
71  explicit QgsSqlExpressionCompiler( const QgsFields &fields, QgsSqlExpressionCompiler::Flags flags = Flags() );
72  virtual ~QgsSqlExpressionCompiler() = default;
73 
77  virtual Result compile( const QgsExpression *exp );
78 
82  virtual QString result();
83 
98  bool opIsStringComparison( QgsExpressionNodeBinaryOperator::BinaryOperator op );
99 
100  protected:
101 
108  virtual QString quotedIdentifier( const QString &identifier );
109 
117  virtual QString quotedValue( const QVariant &value, bool &ok );
118 
125  virtual Result compileNode( const QgsExpressionNode *node, QString &str );
126 
133  virtual QString sqlFunctionFromFunctionName( const QString &fnName ) const;
134 
142  virtual QStringList sqlArgumentsFromFunctionName( const QString &fnName, const QStringList &fnArgs ) const;
143 
150  virtual QString castToReal( const QString &value ) const;
151 
167  virtual QString castToText( const QString &value ) const;
168 
174  virtual QString castToInt( const QString &value ) const;
175 
176  QString mResult;
178 
179  private:
180 
181  Flags mFlags;
182 
183  bool nodeIsNullLiteral( const QgsExpressionNode *node ) const;
184 
185 };
186 
187 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsSqlExpressionCompiler::Flags )
188 
189 #endif // QGSSQLEXPRESSIONCOMPILER_H
Class for parsing and evaluation of expressions (formerly called "search strings").
Container of fields for a vector layer.
Definition: qgsfields.h:42
Flag
Enumeration of flags for how provider handles SQL clauses.
BinaryOperator
list of binary operators
Abstract base class for all nodes that can appear in an expression.
Generic expression compiler for translation to provider specific SQL WHERE clauses.
Result
Possible results from expression compilation.
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. ...