QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
QgsSqlExpressionCompiler Class Reference

Generic expression compiler for translation to provider specific SQL WHERE clauses. More...

#include <qgssqlexpressioncompiler.h>

Public Types

enum  Flag { CaseInsensitiveStringMatch = 0x01, LikeIsCaseInsensitive = 0x02, NoNullInBooleanLogic = 0x04, NoUnaryMinus = 0x08 }
 Enumeration of flags for how provider handles SQL clauses. More...
 
enum  Result { None, Complete, Partial, Fail }
 Possible results from expression compilation. More...
 

Public Member Functions

 QgsSqlExpressionCompiler (const QgsFields &fields, const Flags &flags=Flags())
 Constructor for expression compiler. More...
 
virtual ~QgsSqlExpressionCompiler ()
 
virtual Result compile (const QgsExpression *exp)
 Compiles an expression and returns the result of the compilation. More...
 
virtual QString result ()
 Returns the compiled expression string for use by the provider. More...
 

Protected Member Functions

virtual Result compileNode (const QgsExpression::Node *node, QString &str)
 Compiles an expression node and returns the result of the compilation. More...
 
virtual QString quotedIdentifier (const QString &identifier)
 Returns a quoted column identifier, in the format expected by the provider. More...
 
virtual QString quotedValue (const QVariant &value, bool &ok)
 Returns a quoted attribute value, in the format expected by the provider. More...
 

Protected Attributes

QgsFields mFields
 
QString mResult
 

Detailed Description

Generic expression compiler for translation to provider specific SQL WHERE clauses.

This class is designed to be overridden 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
Not part of stable API, may change in future versions of QGIS
Not available in Python bindings

Definition at line 33 of file qgssqlexpressioncompiler.h.

Member Enumeration Documentation

◆ Flag

Enumeration of flags for how provider handles SQL clauses.

Enumerator
CaseInsensitiveStringMatch 

Provider performs case-insensitive string matching for all strings.

LikeIsCaseInsensitive 

Provider treats LIKE as case-insensitive.

NoNullInBooleanLogic 

Provider does not support using NULL with boolean logic, eg "(...) OR NULL".

NoUnaryMinus 

Provider does not unary minus, eg " -( 100 * 2 ) = ...".

Definition at line 48 of file qgssqlexpressioncompiler.h.

◆ Result

Possible results from expression compilation.

Enumerator
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

Definition at line 38 of file qgssqlexpressioncompiler.h.

Constructor & Destructor Documentation

◆ QgsSqlExpressionCompiler()

QgsSqlExpressionCompiler::QgsSqlExpressionCompiler ( const QgsFields fields,
const Flags &  flags = Flags() 
)
explicit

Constructor for expression compiler.

Parameters
fieldsfields from provider
flagsflags which control how expression is compiled

Definition at line 18 of file qgssqlexpressioncompiler.cpp.

◆ ~QgsSqlExpressionCompiler()

QgsSqlExpressionCompiler::~QgsSqlExpressionCompiler ( )
virtual

Definition at line 25 of file qgssqlexpressioncompiler.cpp.

Member Function Documentation

◆ compile()

QgsSqlExpressionCompiler::Result QgsSqlExpressionCompiler::compile ( const QgsExpression exp)
virtual

Compiles an expression and returns the result of the compilation.

Definition at line 30 of file qgssqlexpressioncompiler.cpp.

◆ compileNode()

QgsSqlExpressionCompiler::Result QgsSqlExpressionCompiler::compileNode ( const QgsExpression::Node node,
QString str 
)
protectedvirtual

Compiles an expression node and returns the result of the compilation.

Parameters
nodeexpression node to compile
strstring representing compiled node should be stored in this parameter
Returns
result of node compilation

Definition at line 74 of file qgssqlexpressioncompiler.cpp.

◆ quotedIdentifier()

QString QgsSqlExpressionCompiler::quotedIdentifier ( const QString identifier)
protectedvirtual

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 also
quotedValue()

Definition at line 38 of file qgssqlexpressioncompiler.cpp.

◆ quotedValue()

QString QgsSqlExpressionCompiler::quotedValue ( const QVariant value,
bool &  ok 
)
protectedvirtual

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.

Parameters
valuevalue to quote
okwil be set to true if value can be compiled
See also
quotedIdentifier()

Definition at line 46 of file qgssqlexpressioncompiler.cpp.

◆ result()

virtual QString QgsSqlExpressionCompiler::result ( )
inlinevirtual

Returns the compiled expression string for use by the provider.

Definition at line 70 of file qgssqlexpressioncompiler.h.

Member Data Documentation

◆ mFields

QgsFields QgsSqlExpressionCompiler::mFields
protected

Definition at line 97 of file qgssqlexpressioncompiler.h.

◆ mResult

QString QgsSqlExpressionCompiler::mResult
protected

Definition at line 96 of file qgssqlexpressioncompiler.h.


The documentation for this class was generated from the following files: