17#ifndef QGSSQLSTATEMENT_H
18#define QGSSQLSTATEMENT_H
20#include <QCoreApplication>
50 bool hasParserError()
const;
52 QString parserErrorString()
const;
59 bool doBasicValidationChecks( QString &errorMsgOut
SIP_OUT )
const;
74 QString statement()
const;
89 static QString quotedIdentifier( QString name );
97 static QString quotedIdentifierIfNeeded(
const QString &name );
103 static QString stripQuotedIdentifier( QString text );
109 static QString stripMsQuotedIdentifier( QString text );
116 static QString quotedString( QString text );
182 static const char *BINARY_OPERATOR_TEXT[]
SIP_SKIP;
185 static const char *UNARY_OPERATOR_TEXT[]
SIP_SKIP;
188 static const char *JOIN_TYPE_TEXT[]
SIP_SKIP;
221 switch ( sipCpp->nodeType() )
236 default: sipType = 0;
break;
256 virtual QString
dump()
const = 0;
301 QList<QgsSQLStatement::Node *>
list() {
return mList; }
306 int count()
const {
return mList.count(); }
315 virtual QString dump() const;
339 QString dump()
const override;
360 , mOpRight( opRight )
374 QString dump()
const override;
380 int precedence() const;
383 bool leftAssociative() const;
413 QString dump()
const override;
433 : mNode( node ), mMinVal( minVal ), mMaxVal( maxVal ), mNotBetween( notBetween ) {}
449 QString dump()
const override;
473 QString
name()
const {
return mName; }
479 QString dump()
const override;
501 inline QVariant
value()
const {
return mValue; }
504 QString dump()
const override;
521 NodeColumnRef(
const QString &name,
bool star ) : mName( name ), mDistinct( false ), mStar( star ) {}
523 NodeColumnRef(
const QString &tableName,
const QString &name,
bool star ) : mTableName( tableName ), mName( name ), mDistinct( false ), mStar( star ) {}
526 void setDistinct(
bool distinct =
true ) { mDistinct = distinct; }
532 QString
name()
const {
return mName; }
535 bool star()
const {
return mStar; }
541 QString dump()
const override;
567 void setAlias(
const QString &alias ) { mAlias = alias; }
573 QString
alias()
const {
return mAlias; }
576 QString dump()
const override;
603 QString
type()
const {
return mType; }
606 QString dump()
const override;
626 NodeTableDef(
const QString &name,
const QString &alias ) : mName( name ), mAlias( alias ) {}
632 NodeTableDef(
const QString &schema,
const QString &name,
const QString &alias ) : mName( name ), mSchema( schema ), mAlias( alias ) {}
635 QString
name()
const {
return mName; }
642 QString
schema()
const {
return mSchema; }
645 QString
alias()
const {
return mAlias; }
648 QString dump()
const override;
672 ~NodeJoin()
override {
delete mTableDef;
delete mOnExpr; }
687 QString dump()
const override;
697 QList<QString> mUsingColumns;
719 QString dump()
const override;
739 NodeSelect(
const QList<QgsSQLStatement::NodeTableDef *> &tableList
SIP_TRANSFER,
const QList<QgsSQLStatement::NodeSelectedColumn *> &columns
SIP_TRANSFER,
bool distinct ) : mTableList( tableList ), mColumns( columns ), mDistinct( distinct ) {}
743 void setJoins(
const QList<QgsSQLStatement::NodeJoin *> &joins
SIP_TRANSFER ) { qDeleteAll( mJoins ); mJoins = joins; }
749 void setOrderBy(
const QList<QgsSQLStatement::NodeColumnSorted *> &orderBy
SIP_TRANSFER ) { qDeleteAll( mOrderBy ); mOrderBy = orderBy; }
752 QList<QgsSQLStatement::NodeTableDef *>
tables()
const {
return mTableList; }
754 QList<QgsSQLStatement::NodeSelectedColumn *>
columns()
const {
return mColumns; }
758 QList<QgsSQLStatement::NodeJoin *>
joins()
const {
return mJoins; }
762 QList<QgsSQLStatement::NodeColumnSorted *>
orderBy()
const {
return mOrderBy; }
765 QString dump()
const override;
848 bool mAllowFragments =
false;
Class for parsing fragments of SQL statements, such as an expression or where clause.
'X BETWEEN y and z' operator
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QgsSQLStatement::Node * node() const
Variable at the left of BETWEEN.
QgsSQLStatement::Node * minVal() const
Minimum bound.
bool isNotBetween() const
Whether this is a NOT BETWEEN operator.
QgsSQLStatement::Node * maxVal() const
Maximum bound.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
~NodeBetweenOperator() override
NodeBetweenOperator(QgsSQLStatement::Node *node, QgsSQLStatement::Node *minVal, QgsSQLStatement::Node *maxVal, bool notBetween=false)
Constructor.
Binary logical/arithmetical operator (AND, OR, =, +, ...)
~NodeBinaryOperator() override
QgsSQLStatement::Node * opLeft() const
Left operand.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
NodeBinaryOperator(QgsSQLStatement::BinaryOperator op, QgsSQLStatement::Node *opLeft, QgsSQLStatement::Node *opRight)
Constructor.
QgsSQLStatement::BinaryOperator op() const
Operator.
QgsSQLStatement::Node * opRight() const
Right operand.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QgsSQLStatement::Node * node() const
Node that is referred to.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
NodeCast(QgsSQLStatement::Node *node, const QString &type)
Constructor.
QString type() const
Type.
QString name() const
The name of the column.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
NodeColumnRef(const QString &name, bool star)
Constructor with column name only.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
bool star() const
Whether this is the * column.
NodeColumnRef(const QString &tableName, const QString &name, bool star)
Constructor with table and column name.
QString tableName() const
The name of the table. May be empty.
void setDistinct(bool distinct=true)
Sets whether this is prefixed by DISTINCT.
bool distinct() const
Whether this is prefixed by DISTINCT.
bool ascending() const
Whether the column is sorted in ascending order.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QgsSQLStatement::NodeColumnRef * column() const
The name of the column.
~NodeColumnSorted() override
NodeColumnSorted(QgsSQLStatement::NodeColumnRef *column, bool asc)
Constructor.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
Function with a name and arguments node.
NodeFunction(const QString &name, QgsSQLStatement::NodeList *args)
Constructor.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QgsSQLStatement::NodeList * args() const
Returns arguments.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QString name() const
Returns function name.
bool isNotIn() const
Whether this is a NOT IN operator.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
~NodeInOperator() override
QgsSQLStatement::Node * node() const
Variable at the left of IN.
NodeInOperator(QgsSQLStatement::Node *node, QgsSQLStatement::NodeList *list, bool notin=false)
Constructor.
QgsSQLStatement::NodeList * list() const
Values list.
QgsSQLStatement::NodeTableDef * tableDef() const
Table definition.
QgsSQLStatement::Node * onExpr() const
On expression. Will be nullptr if usingColumns() is not empty.
NodeJoin(QgsSQLStatement::NodeTableDef *tabledef, QgsSQLStatement::Node *onExpr, QgsSQLStatement::JoinType type)
Constructor with table definition, ON expression.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
NodeJoin(QgsSQLStatement::NodeTableDef *tabledef, const QList< QString > &usingColumns, QgsSQLStatement::JoinType type)
Constructor with table definition and USING columns.
QList< QString > usingColumns() const
Columns referenced by USING.
QgsSQLStatement::JoinType type() const
Join type.
void accept(QgsSQLStatement::Visitor &v) const
Accept visitor.
QList< QgsSQLStatement::Node * > list()
Returns list.
int count() const
Returns the number of nodes in the list.
void append(QgsSQLStatement::Node *node)
Takes ownership of the provided node.
Literal value (integer, integer64, double, string)
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
NodeLiteral(const QVariant &value)
Constructor.
QVariant value() const
The value of the literal.
NodeSelect(const QList< QgsSQLStatement::NodeTableDef * > &tableList, const QList< QgsSQLStatement::NodeSelectedColumn * > &columns, bool distinct)
Constructor.
QList< QgsSQLStatement::NodeColumnSorted * > orderBy() const
Returns the list of order by columns.
void setJoins(const QList< QgsSQLStatement::NodeJoin * > &joins)
Sets joins.
void setWhere(QgsSQLStatement::Node *where)
Sets where clause.
QList< QgsSQLStatement::NodeSelectedColumn * > columns() const
Returns the list of columns.
bool distinct() const
Returns if the SELECT is DISTINCT.
void appendJoin(QgsSQLStatement::NodeJoin *join)
Append a join.
void setOrderBy(const QList< QgsSQLStatement::NodeColumnSorted * > &orderBy)
Sets order by columns.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QList< QgsSQLStatement::NodeJoin * > joins() const
Returns the list of joins.
QgsSQLStatement::Node * where() const
Returns the where clause.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QList< QgsSQLStatement::NodeTableDef * > tables() const
Returns the list of tables.
NodeSelectedColumn(QgsSQLStatement::Node *node)
Constructor.
void setAlias(const QString &alias)
Sets alias name.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
~NodeSelectedColumn() override
QgsSQLStatement::Node * column() const
Column that is referred to.
QString alias() const
Alias name.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QString name() const
Table name.
NodeTableDef(const QString &schema, const QString &name, const QString &alias)
Constructor with schema, table name and alias.
NodeTableDef(const QString &name)
Constructor with table name.
NodeTableDef(const QString &name, const QString &alias)
Constructor with table name and alias.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QString alias() const
Table alias.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QString schema() const
Returns the schema name.
Unary logicial/arithmetical operator ( NOT, - )
NodeUnaryOperator(QgsSQLStatement::UnaryOperator op, QgsSQLStatement::Node *operand)
Constructor.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QgsSQLStatement::UnaryOperator op() const
Operator.
QgsSQLStatement::Node * operand() const
Operand.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
~NodeUnaryOperator() override
virtual QgsSQLStatement::Node * clone() const =0
Generate a clone of this node.
virtual QString dump() const =0
Abstract virtual dump method.
virtual QgsSQLStatement::NodeType nodeType() const =0
Abstract virtual that returns the type of this node.
virtual void accept(QgsSQLStatement::Visitor &v) const =0
Support the visitor pattern.
A visitor that recursively explores all children.
void visit(const QgsSQLStatement::NodeFunction &n) override
Visit NodeFunction.
void visit(const QgsSQLStatement::NodeSelectedColumn &n) override
Visit NodeSelectedColumn.
void visit(const QgsSQLStatement::NodeUnaryOperator &n) override
Visit NodeUnaryOperator.
void visit(const QgsSQLStatement::NodeLiteral &) override
Visit NodeLiteral.
RecursiveVisitor()=default
void visit(const QgsSQLStatement::NodeBetweenOperator &n) override
Visit NodeBetweenOperator.
void visit(const QgsSQLStatement::NodeBinaryOperator &n) override
Visit NodeBinaryOperator.
void visit(const QgsSQLStatement::NodeColumnRef &) override
Visit NodeColumnRef.
void visit(const QgsSQLStatement::NodeTableDef &) override
Visit NodeTableDef.
void visit(const QgsSQLStatement::NodeColumnSorted &n) override
Visit NodeColumnSorted.
void visit(const QgsSQLStatement::NodeInOperator &n) override
Visit NodeInOperator.
void visit(const QgsSQLStatement::NodeCast &n) override
Visit NodeCast.
Support for visitor pattern - algorithms dealing with the statement may be implemented without modify...
virtual void visit(const QgsSQLStatement::NodeBetweenOperator &n)=0
Visit NodeBetweenOperator.
virtual ~Visitor()=default
virtual void visit(const QgsSQLStatement::NodeFunction &n)=0
Visit NodeFunction.
virtual void visit(const QgsSQLStatement::NodeColumnRef &n)=0
Visit NodeColumnRef.
virtual void visit(const QgsSQLStatement::NodeBinaryOperator &n)=0
Visit NodeBinaryOperator.
virtual void visit(const QgsSQLStatement::NodeSelect &n)=0
Visit NodeSelect.
virtual void visit(const QgsSQLStatement::NodeCast &n)=0
Visit NodeCast.
virtual void visit(const QgsSQLStatement::NodeSelectedColumn &n)=0
Visit NodeSelectedColumn.
virtual void visit(const QgsSQLStatement::NodeJoin &n)=0
Visit NodeJoin.
virtual void visit(const QgsSQLStatement::NodeUnaryOperator &n)=0
Visit NodeUnaryOperator.
virtual void visit(const QgsSQLStatement::NodeInOperator &n)=0
Visit NodeInOperator.
virtual void visit(const QgsSQLStatement::NodeLiteral &n)=0
Visit NodeLiteral.
virtual void visit(const QgsSQLStatement::NodeColumnSorted &n)=0
Visit NodeColumnSorted.
virtual void visit(const QgsSQLStatement::NodeTableDef &n)=0
Visit NodeTableDef.
Class for parsing SQL statements.
JoinType
list of join types
BinaryOperator
list of binary operators
QString mParserErrorString
UnaryOperator
list of unary operators
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)