17 #ifndef QGSSQLSTATEMENT_H 18 #define QGSSQLSTATEMENT_H 20 #include <QCoreApplication> 23 #include <QStringList> 28 #include "qgis_core.h" 58 bool hasParserError()
const;
60 QString parserErrorString()
const;
66 bool doBasicValidationChecks( QString &errorMsgOut
SIP_OUT )
const;
78 QString statement()
const;
92 static QString quotedIdentifier( QString name );
99 static QString quotedIdentifierIfNeeded(
const QString &name );
105 static QString stripQuotedIdentifier( QString text );
111 static QString quotedString( QString text );
177 static const char *BINARY_OPERATOR_TEXT[]
SIP_SKIP;
215 switch ( sipCpp->nodeType() )
230 default: sipType = 0;
break;
236 virtual ~
Node() =
default;
250 virtual QString dump()
const = 0;
295 QList<QgsSQLStatement::Node *>
list() {
return mList; }
300 int count()
const {
return mList.count(); }
309 virtual QString dump()
const;
332 QString
dump()
const override;
352 , mOpRight( opRight )
366 QString
dump()
const override;
372 int precedence()
const;
375 bool leftAssociative()
const;
404 QString
dump()
const override;
423 : mNode( node ), mMinVal( minVal ), mMaxVal( maxVal ), mNotBetween( notBetween ) {}
439 QString
dump()
const override;
462 QString
name()
const {
return mName; }
468 QString
dump()
const override;
489 inline QVariant
value()
const {
return mValue; }
492 QString
dump()
const override;
508 NodeColumnRef(
const QString &name,
bool star ) : mName( name ), mDistinct( false ), mStar( star ) {}
510 NodeColumnRef(
const QString &tableName,
const QString &name,
bool star ) : mTableName( tableName ), mName( name ), mDistinct( false ), mStar( star ) {}
513 void setDistinct(
bool distinct =
true ) { mDistinct = distinct; }
519 QString
name()
const {
return mName; }
522 bool star()
const {
return mStar; }
528 QString
dump()
const override;
553 void setAlias(
const QString &alias ) { mAlias = alias; }
559 QString
alias()
const {
return mAlias; }
562 QString
dump()
const override;
588 QString
type()
const {
return mType; }
591 QString
dump()
const override;
610 NodeTableDef(
const QString &name,
const QString &alias ) : mName( name ), mAlias( alias ) {}
613 QString
name()
const {
return mName; }
616 QString
alias()
const {
return mAlias; }
619 QString
dump()
const override;
641 ~NodeJoin()
override {
delete mTableDef;
delete mOnExpr; }
656 QString
dump()
const override;
687 QString
dump()
const override;
706 NodeSelect(
const QList<QgsSQLStatement::NodeTableDef *> &tableList
SIP_TRANSFER,
const QList<QgsSQLStatement::NodeSelectedColumn *> &columns SIP_TRANSFER,
bool distinct ) : mTableList( tableList ), mColumns( columns ), mDistinct( distinct ) {}
710 void setJoins(
const QList<QgsSQLStatement::NodeJoin *> &joins
SIP_TRANSFER ) { qDeleteAll( mJoins ); mJoins = joins; }
716 void setOrderBy(
const QList<QgsSQLStatement::NodeColumnSorted *> &orderBy
SIP_TRANSFER ) { qDeleteAll( mOrderBy ); mOrderBy = orderBy; }
719 QList<QgsSQLStatement::NodeTableDef *>
tables()
const {
return mTableList; }
721 QList<QgsSQLStatement::NodeSelectedColumn *>
columns()
const {
return mColumns; }
725 QList<QgsSQLStatement::NodeJoin *>
joins()
const {
return mJoins; }
729 QList<QgsSQLStatement::NodeColumnSorted *>
orderBy()
const {
return mOrderBy; }
732 QString
dump()
const override;
819 #endif // QGSSQLSTATEMENT_H bool ascending() const
Whether the column is sorted in ascending order.
QgsSQLStatement::NodeList * list() const
Values list.
NodeTableDef(const QString &name)
Constructor with table name.
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.
QgsSQLStatement::Node * onExpr() const
On expression. Will be nullptr if usingColumns() is not empty.
void appendJoin(QgsSQLStatement::NodeJoin *join)
Append a join.
Function with a name and arguments node.
JoinType
list of join types
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QList< NodeJoin * > mJoins
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QgsSQLStatement::NodeTableDef * tableDef() const
Table definition.
QString type() const
Type.
QgsSQLStatement::Node * operand() const
Operand.
QgsSQLStatement::Node * where() const
Returns the where clause.
QList< NodeColumnSorted * > mOrderBy
~NodeSelectedColumn() override
UnaryOperator
list of unary operators
NodeTableDef(const QString &name, const QString &alias)
Constructor with table name and alias.
NodeUnaryOperator(QgsSQLStatement::UnaryOperator op, QgsSQLStatement::Node *operand)
Constructor.
void visit(const QgsSQLStatement::NodeSelectedColumn &n) override
Visit NodeSelectedColumn.
NodeJoin(QgsSQLStatement::NodeTableDef *tabledef, const QList< QString > &usingColumns, QgsSQLStatement::JoinType type)
Constructor with table definition and USING columns.
NodeBetweenOperator(QgsSQLStatement::Node *node, QgsSQLStatement::Node *minVal, QgsSQLStatement::Node *maxVal, bool notBetween=false)
Constructor.
Binary logical/arithmetical operator (AND, OR, =, +, ...)
NodeSelect(const QList< QgsSQLStatement::NodeTableDef *> &tableList, const QList< QgsSQLStatement::NodeSelectedColumn *> &columns, bool distinct)
Constructor.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QList< QString > mUsingColumns
QList< QgsSQLStatement::NodeSelectedColumn * > columns() const
Returns the list of columns.
Q_DECLARE_METATYPE(QModelIndex)
NodeSelectedColumn(QgsSQLStatement::Node *node)
Constructor.
QString name() const
Returns function name.
NodeBinaryOperator(QgsSQLStatement::BinaryOperator op, QgsSQLStatement::Node *opLeft, QgsSQLStatement::Node *opRight)
Constructor.
bool distinct() const
Returns if the SELECT is DISTINCT.
QgsSQLStatement::Node * node() const
Variable at the left of BETWEEN.
QList< QString > usingColumns() const
Columns referenced by USING.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
void setWhere(QgsSQLStatement::Node *where)
Sets where clause.
NodeFunction(const QString &name, QgsSQLStatement::NodeList *args)
Constructor.
QgsSQLStatement::JoinType type() const
Join type.
QgsSQLStatement::Node * minVal() const
Minimum bound.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
A visitor that recursively explores all children.
virtual void visit(const QgsSQLStatement::NodeUnaryOperator &n)=0
Visit NodeUnaryOperator.
bool isNotIn() const
Whether this is a NOT IN operator.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
NodeCast(QgsSQLStatement::Node *node, const QString &type)
Constructor.
Class for parsing SQL statements.
QString name() const
Table name.
QString alias() const
Table alias.
virtual QString dump() const =0
Abstract virtual dump method.
void visit(const QgsSQLStatement::NodeBetweenOperator &n) override
Visit NodeBetweenOperator.
virtual QgsSQLStatement::Node * clone() const =0
Generate a clone of this node.
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.
NodeColumnSorted(QgsSQLStatement::NodeColumnRef *column, bool asc)
Constructor.
QgsSQLStatement::NodeList * args() const
Returns arguments.
void setOrderBy(const QList< QgsSQLStatement::NodeColumnSorted *> &orderBy)
Sets order by columns.
NodeInOperator(QgsSQLStatement::Node *node, QgsSQLStatement::NodeList *list, bool notin=false)
Constructor.
~NodeUnaryOperator() override
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
Literal value (integer, integer64, double, string)
QString name() const
The name of the column.
QList< QgsSQLStatement::NodeTableDef * > tables() const
Returns the list of tables.
void setAlias(const QString &alias)
Sets alias name.
Unary logicial/arithmetical operator ( NOT, - )
QgsSQLStatement::BinaryOperator op() const
Operator.
QList< NodeTableDef * > mTableList
BinaryOperator
list of binary operators
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QList< NodeSelectedColumn * > mColumns
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
bool distinct() const
Whether this is prefixed by DISTINCT.
QString alias() const
Alias name.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QgsSQLStatement::Node * maxVal() const
Maximum bound.
bool isNotBetween() const
Whether this is a NOT BETWEEN operator.
~NodeBetweenOperator() override
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QList< QgsSQLStatement::NodeColumnSorted * > orderBy() const
Returns the list of order by columns.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
'X BETWEEN y and z' operator
void visit(const QgsSQLStatement::NodeColumnSorted &n) override
Visit NodeColumnSorted.
void accept(QgsSQLStatement::Visitor &v) const
Accept visitor.
QVariant value() const
The value of the literal.
QList< QgsSQLStatement::NodeJoin * > joins() const
Returns the list of joins.
void visit(const QgsSQLStatement::NodeLiteral &) override
Visit NodeLiteral.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QgsSQLStatement::NodeColumnRef * column() const
The name of the column.
void setJoins(const QList< QgsSQLStatement::NodeJoin *> &joins)
Sets joins.
void acceptVisitor(QgsSQLStatement::Visitor &v) const
Entry function for the visitor pattern.
~NodeColumnSorted() override
NodeJoin(QgsSQLStatement::NodeTableDef *tabledef, QgsSQLStatement::Node *onExpr, QgsSQLStatement::JoinType type)
Constructor with table definition, ON expression.
void visit(const QgsSQLStatement::NodeInOperator &n) override
Visit NodeInOperator.
bool star() const
Whether this is the * column.
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.
virtual void accept(QgsSQLStatement::Visitor &v) const =0
Support the visitor pattern.
QList< QgsSQLStatement::Node * > list()
Returns list.
NodeColumnRef(const QString &tableName, const QString &name, bool star)
Constructor with table and column name.
QgsSQLStatement::Node * node() const
Node that is referred to.
void setDistinct(bool distinct=true)
Sets whether this is prefixed by DISTINCT.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
void visit(const QgsSQLStatement::NodeUnaryOperator &n) override
Visit NodeUnaryOperator.
void visit(const QgsSQLStatement::NodeColumnRef &) override
Visit NodeColumnRef.
Support for visitor pattern - algorithms dealing with the statement may be implemented without modify...
void visit(const QgsSQLStatement::NodeTableDef &) override
Visit NodeTableDef.
QString tableName() const
The name of the table. May be empty.
void append(QgsSQLStatement::Node *node)
Takes ownership of the provided node.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QgsSQLStatement::UnaryOperator op() const
Operator.
~NodeBinaryOperator() override
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
'x IN (y, z)' operator
~NodeInOperator() override
QgsSQLStatement::Node * node() const
Variable at the left of IN.
void visit(const QgsSQLStatement::NodeFunction &n) override
Visit NodeFunction.
QgsSQLStatement::Node * opLeft() const
Left operand.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QgsSQLStatement::Node * opRight() const
Right operand.
NodeColumnRef(const QString &name, bool star)
Constructor with column name only.
void visit(const QgsSQLStatement::NodeCast &n) override
Visit NodeCast.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
void visit(const QgsSQLStatement::NodeBinaryOperator &n) override
Visit NodeBinaryOperator.
NodeLiteral(const QVariant &value)
Constructor.
QgsSQLStatement::Node * column() const
Column that is referred to.
QString mParserErrorString
int count() const
Returns the number of nodes in the list.