/
qgssqlexpressioncompiler.h
102 lines (83 loc) · 3.88 KB
/
qgssqlexpressioncompiler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/***************************************************************************
qgssqlexpressioncompiler.h
--------------------------
begin : November 2015
copyright : (C) 2015 Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSSQLEXPRESSIONCOMPILER_H
#define QGSSQLEXPRESSIONCOMPILER_H
#include "qgsexpression.h"
#include "qgsfield.h"
/** \ingroup core
* \class QgsSqlExpressionCompiler
* \brief Generic expression compiler for translation to provider specific SQL WHERE clauses.
*
* This class is designed to be overriden by providers to take advantage of expression compilation,
* so that feature requests can take advantage of the provider's native filtering support.
* \note Added in version 2.14
* \note Not part of stable API, may change in future versions of QGIS
* \note Not available in Python bindings
*/
class CORE_EXPORT QgsSqlExpressionCompiler
{
public:
/** Possible results from expression compilation */
enum Result
{
None, /*!< No 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-checked using QGIS' expression engine*/
Fail /*!< Provider cannot handle expression */
};
/** Enumeration of flags for how provider handles SQL clauses
*/
enum Flag
{
CaseInsensitiveStringMatch = 0x01, //!< Provider performs case-insensitive string matching
};
Q_DECLARE_FLAGS( Flags, Flag )
/** Constructor for expression compiler.
* @param fields fields from provider
* @param flags flags which control how expression is compiled
*/
explicit QgsSqlExpressionCompiler( const QgsFields& fields, const Flags& flags = ( Flags )0 );
virtual ~QgsSqlExpressionCompiler();
/** Compiles an expression and returns the result of the compilation.
*/
virtual Result compile( const QgsExpression* exp );
/** Returns the compiled expression string for use by the provider.
*/
virtual QString result() { return mResult; }
protected:
/** Returns a quoted column identifier, in the format expected by the provider.
* Derived classes should override this if special handling of column identifiers
* is required.
* @see quotedValue()
*/
virtual QString quotedIdentifier( const QString& identifier );
/** Returns a quoted attribute value, in the format expected by the provider.
* Derived classes should override this if special handling of attribute values is required.
* @see quotedIdentifier()
*/
virtual QString quotedValue( const QVariant& value );
/** Compiles an expression node and returns the result of the compilation.
* @param node expression node to compile
* @param str string representing compiled node should be stored in this parameter
* @returns result of node compilation
*/
virtual Result compile( const QgsExpression::Node* node, QString& str );
QString mResult;
QgsFields mFields;
private:
Flags mFlags;
};
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsSqlExpressionCompiler::Flags )
#endif // QGSSQLEXPRESSIONCOMPILER_H