QGIS API Documentation  3.0.2-Girona (307d082)
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 
24 class QgsExpression;
25 class QgsExpressionNode;
26 
39 class CORE_EXPORT QgsSqlExpressionCompiler
40 {
41  public:
42 
44  enum Result
45  {
46  None,
49  Fail
50  };
51 
55  enum Flag
56  {
57  CaseInsensitiveStringMatch = 1,
58  LikeIsCaseInsensitive = 1 << 1,
59  NoNullInBooleanLogic = 1 << 2,
60  NoUnaryMinus = 1 << 3,
61  IntegerDivisionResultsInInteger = 1 << 4,
62  };
63  Q_DECLARE_FLAGS( Flags, Flag )
64 
65 
70  explicit QgsSqlExpressionCompiler( const QgsFields &fields, QgsSqlExpressionCompiler::Flags flags = Flags() );
71  virtual ~QgsSqlExpressionCompiler() = default;
72 
76  virtual Result compile( const QgsExpression *exp );
77 
81  virtual QString result();
82 
83  protected:
84 
91  virtual QString quotedIdentifier( const QString &identifier );
92 
100  virtual QString quotedValue( const QVariant &value, bool &ok );
101 
108  virtual Result compileNode( const QgsExpressionNode *node, QString &str );
109 
116  virtual QString sqlFunctionFromFunctionName( const QString &fnName ) const;
117 
125  virtual QStringList sqlArgumentsFromFunctionName( const QString &fnName, const QStringList &fnArgs ) const;
126 
133  virtual QString castToReal( const QString &value ) const;
134 
140  virtual QString castToInt( const QString &value ) const;
141 
142  QString mResult;
144 
145  private:
146 
147  Flags mFlags;
148 
149  bool nodeIsNullLiteral( const QgsExpressionNode *node ) const;
150 
151 };
152 
153 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsSqlExpressionCompiler::Flags )
154 
155 #endif // QGSSQLEXPRESSIONCOMPILER_H
Container of fields for a vector layer.
Definition: qgsfields.h:42
Flag
Enumeration of flags for how provider handles SQL clauses.
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. ...