QGIS API Documentation  3.14.0-Pi (9f7028fd23)
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
QgsSQLStatement Class Reference

#include <qgssqlstatement.h>

Classes

class  Node
 
class  NodeBetweenOperator
 
class  NodeBinaryOperator
 
class  NodeCast
 
class  NodeColumnRef
 
class  NodeColumnSorted
 
class  NodeFunction
 
class  NodeInOperator
 
class  NodeJoin
 
class  NodeList
 A list of nodes. More...
 
class  NodeLiteral
 
class  NodeSelect
 
class  NodeSelectedColumn
 
class  NodeTableDef
 
class  NodeUnaryOperator
 
class  RecursiveVisitor
 
class  Visitor
 

Public Types

enum  BinaryOperator {
  boOr, boAnd, boEQ, boNE,
  boLE, boGE, boLT, boGT,
  boLike, boNotLike, boILike, boNotILike,
  boIs, boIsNot, boPlus, boMinus,
  boMul, boDiv, boIntDiv, boMod,
  boPow, boConcat
}
 list of binary operators More...
 
enum  JoinType {
  jtDefault, jtLeft, jtLeftOuter, jtRight,
  jtRightOuter, jtCross, jtInner, jtFull
}
 list of join types More...
 
enum  NodeType {
  ntUnaryOperator, ntBinaryOperator, ntInOperator, ntBetweenOperator,
  ntFunction, ntLiteral, ntColumnRef, ntSelectedColumn,
  ntSelect, ntTableDef, ntJoin, ntColumnSorted,
  ntCast
}
 Node type. More...
 
enum  UnaryOperator { uoNot, uoMinus }
 list of unary operators More...
 

Public Member Functions

 QgsSQLStatement (const QgsSQLStatement &other)
 Create a copy of this statement. More...
 
 QgsSQLStatement (const QString &statement)
 Creates a new statement based on the provided string. More...
 
 ~QgsSQLStatement ()
 
void acceptVisitor (QgsSQLStatement::Visitor &v) const
 Entry function for the visitor pattern. More...
 
bool doBasicValidationChecks (QString &errorMsgOut) const
 Performs basic validity checks. More...
 
QString dump () const
 Returns the statement string, constructed from the internal abstract syntax tree. More...
 
bool hasParserError () const
 Returns true if an error occurred when parsing the input statement. More...
 
QgsSQLStatementoperator= (const QgsSQLStatement &other)
 Create a copy of this statement. More...
 
QString parserErrorString () const
 Returns parser error. More...
 
const QgsSQLStatement::NoderootNode () const
 Returns the root node of the statement. More...
 
QString statement () const
 Returns the original, unmodified statement string. More...
 

Static Public Member Functions

static QString quotedIdentifier (QString name)
 Returns a quoted column reference (in double quotes) More...
 
static QString quotedIdentifierIfNeeded (const QString &name)
 Returns a quoted column reference (in double quotes) if needed, or otherwise the original string. More...
 
static QString quotedString (QString text)
 Returns a quoted version of a string (in single quotes) More...
 
static QString stripQuotedIdentifier (QString text)
 Remove double quotes from an identifier. More...
 

Static Public Attributes

static const char * BINARY_OPERATOR_TEXT []
 
static const char * JOIN_TYPE_TEXT []
 
static const char * UNARY_OPERATOR_TEXT []
 

Protected Attributes

QString mParserErrorString
 
QgsSQLStatement::NodemRootNode = nullptr
 
QString mStatement
 

Detailed Description

Class for parsing SQL statements.

Since
QGIS 2.16

Definition at line 36 of file qgssqlstatement.h.

Member Enumeration Documentation

◆ BinaryOperator

list of binary operators

Note
if any change is made here, the definition of QgsSQLStatement::BinaryOperatorText[] must be adapted.
Enumerator
boOr 
boAnd 
boEQ 
boNE 
boLE 
boGE 
boLT 
boGT 
boLike 
boNotLike 
boILike 
boNotILike 
boIs 
boIsNot 
boPlus 
boMinus 
boMul 
boDiv 
boIntDiv 
boMod 
boPow 
boConcat 

Definition at line 145 of file qgssqlstatement.h.

◆ JoinType

list of join types

Note
if any change is made here, the definition of QgsSQLStatement::JoinTypeText[] must be adapted.
Enumerator
jtDefault 
jtLeft 
jtLeftOuter 
jtRight 
jtRightOuter 
jtCross 
jtInner 
jtFull 

Definition at line 182 of file qgssqlstatement.h.

◆ NodeType

Node type.

Enumerator
ntUnaryOperator 
ntBinaryOperator 
ntInOperator 
ntBetweenOperator 
ntFunction 
ntLiteral 
ntColumnRef 
ntSelectedColumn 
ntSelect 
ntTableDef 
ntJoin 
ntColumnSorted 
ntCast 

Definition at line 208 of file qgssqlstatement.h.

◆ UnaryOperator

list of unary operators

Note
if any change is made here, the definition of QgsSQLStatement::UnaryOperatorText[] must be adapted.
Enumerator
uoNot 
uoMinus 

Definition at line 135 of file qgssqlstatement.h.

Constructor & Destructor Documentation

◆ QgsSQLStatement() [1/2]

QgsSQLStatement::QgsSQLStatement ( const QString &  statement)

Creates a new statement based on the provided string.

Definition at line 118 of file qgssqlstatement.cpp.

◆ QgsSQLStatement() [2/2]

QgsSQLStatement::QgsSQLStatement ( const QgsSQLStatement other)

Create a copy of this statement.

Definition at line 124 of file qgssqlstatement.cpp.

◆ ~QgsSQLStatement()

QgsSQLStatement::~QgsSQLStatement ( )

Definition at line 142 of file qgssqlstatement.cpp.

Member Function Documentation

◆ acceptVisitor()

void QgsSQLStatement::acceptVisitor ( QgsSQLStatement::Visitor v) const

Entry function for the visitor pattern.

Definition at line 151 of file qgssqlstatement.cpp.

◆ doBasicValidationChecks()

bool QgsSQLStatement::doBasicValidationChecks ( QString &  errorMsgOut) const

Performs basic validity checks.

Basically checking that columns referencing a table, references a specified table. Returns true if the validation is successful

Definition at line 232 of file qgssqlstatement.cpp.

◆ dump()

QString QgsSQLStatement::dump ( ) const

Returns the statement string, constructed from the internal abstract syntax tree.

This does not contain any nice whitespace formatting or comments. In general it is preferable to use statement() instead.

Definition at line 61 of file qgssqlstatement.cpp.

◆ hasParserError()

bool QgsSQLStatement::hasParserError ( ) const

Returns true if an error occurred when parsing the input statement.

Definition at line 147 of file qgssqlstatement.cpp.

◆ operator=()

QgsSQLStatement & QgsSQLStatement::operator= ( const QgsSQLStatement other)

Create a copy of this statement.

Definition at line 130 of file qgssqlstatement.cpp.

◆ parserErrorString()

QString QgsSQLStatement::parserErrorString ( ) const

Returns parser error.

Definition at line 149 of file qgssqlstatement.cpp.

◆ quotedIdentifier()

QString QgsSQLStatement::quotedIdentifier ( QString  name)
static

Returns a quoted column reference (in double quotes)

See also
quotedString(), quotedIdentifierIfNeeded()

Definition at line 69 of file qgssqlstatement.cpp.

◆ quotedIdentifierIfNeeded()

QString QgsSQLStatement::quotedIdentifierIfNeeded ( const QString &  name)
static

Returns a quoted column reference (in double quotes) if needed, or otherwise the original string.

See also
quotedString(), quotedIdentifier()

Definition at line 74 of file qgssqlstatement.cpp.

◆ quotedString()

QString QgsSQLStatement::quotedString ( QString  text)
static

Returns a quoted version of a string (in single quotes)

See also
quotedIdentifier(), quotedIdentifierIfNeeded()

Definition at line 109 of file qgssqlstatement.cpp.

◆ rootNode()

const QgsSQLStatement::Node * QgsSQLStatement::rootNode ( ) const

Returns the root node of the statement.

The root node is nullptr if parsing has failed.

Definition at line 157 of file qgssqlstatement.cpp.

◆ statement()

QString QgsSQLStatement::statement ( ) const

Returns the original, unmodified statement string.

If there was none supplied because it was constructed by sole API calls, dump() will be used to create one instead.

Definition at line 53 of file qgssqlstatement.cpp.

◆ stripQuotedIdentifier()

QString QgsSQLStatement::stripQuotedIdentifier ( QString  text)
static

Remove double quotes from an identifier.

See also
quotedIdentifier()

Definition at line 96 of file qgssqlstatement.cpp.

Member Data Documentation

◆ BINARY_OPERATOR_TEXT

const char * QgsSQLStatement::BINARY_OPERATOR_TEXT
static
Initial value:
=
{
"OR", "AND",
"=", "<>", "<=", ">=", "<", ">", "LIKE", "NOT LIKE", "ILIKE", "NOT ILIKE", "IS", "IS NOT",
"+", "-", "*", "/", "//", "%", "^",
"||"
}
Note
not available in Python bindings

Definition at line 195 of file qgssqlstatement.h.

◆ JOIN_TYPE_TEXT

const char * QgsSQLStatement::JOIN_TYPE_TEXT
static
Initial value:
=
{
"", "LEFT", "LEFT OUTER", "RIGHT", "RIGHT OUTER", "CROSS", "INNER", "FULL"
}
Note
not available in Python bindings

Definition at line 201 of file qgssqlstatement.h.

◆ mParserErrorString

QString QgsSQLStatement::mParserErrorString
protected

Definition at line 848 of file qgssqlstatement.h.

◆ mRootNode

QgsSQLStatement::Node* QgsSQLStatement::mRootNode = nullptr
protected

Definition at line 846 of file qgssqlstatement.h.

◆ mStatement

QString QgsSQLStatement::mStatement
protected

Definition at line 847 of file qgssqlstatement.h.

◆ UNARY_OPERATOR_TEXT

const char * QgsSQLStatement::UNARY_OPERATOR_TEXT
static
Initial value:
=
{
"NOT", "-"
}
Note
not available in Python bindings

Definition at line 198 of file qgssqlstatement.h.


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