17 #ifndef QGSSQLSTATEMENT_H 18 #define QGSSQLSTATEMENT_H 20 #include <QCoreApplication> 24 #include <QStringList> 29 #include "qgis_core.h" 59 bool hasParserError()
const;
61 QString parserErrorString()
const;
67 bool doBasicValidationChecks( QString &errorMsgOut
SIP_OUT )
const;
79 QString statement()
const;
93 static QString quotedIdentifier( QString name );
100 static QString quotedIdentifierIfNeeded(
const QString &name );
106 static QString stripQuotedIdentifier( QString text );
112 static QString quotedString( QString text );
178 static const char *BINARY_OPERATOR_TEXT[]
SIP_SKIP;
216 switch ( sipCpp->nodeType() )
231 default: sipType = 0;
break;
237 virtual ~
Node() =
default;
251 virtual QString dump()
const = 0;
296 QList<QgsSQLStatement::Node *>
list() {
return mList; }
301 int count()
const {
return mList.count(); }
310 virtual QString dump()
const;
333 QString
dump()
const override;
353 , mOpRight( opRight )
367 QString
dump()
const override;
373 int precedence()
const;
376 bool leftAssociative()
const;
405 QString
dump()
const override;
424 : mNode( node ), mMinVal( minVal ), mMaxVal( maxVal ), mNotBetween( notBetween ) {}
440 QString
dump()
const override;
463 QString
name()
const {
return mName; }
469 QString
dump()
const override;
490 inline QVariant
value()
const {
return mValue; }
493 QString
dump()
const override;
509 NodeColumnRef(
const QString &name,
bool star ) : mName( name ), mDistinct( false ), mStar( star ) {}
511 NodeColumnRef(
const QString &tableName,
const QString &name,
bool star ) : mTableName( tableName ), mName( name ), mDistinct( false ), mStar( star ) {}
514 void setDistinct(
bool distinct =
true ) { mDistinct = distinct; }
520 QString
name()
const {
return mName; }
523 bool star()
const {
return mStar; }
529 QString
dump()
const override;
554 void setAlias(
const QString &alias ) { mAlias = alias; }
560 QString
alias()
const {
return mAlias; }
563 QString
dump()
const override;
589 QString
type()
const {
return mType; }
592 QString
dump()
const override;
611 NodeTableDef(
const QString &name,
const QString &alias ) : mName( name ), mAlias( alias ) {}
614 QString
name()
const {
return mName; }
617 QString
alias()
const {
return mAlias; }
620 QString
dump()
const override;
642 ~NodeJoin()
override {
delete mTableDef;
delete mOnExpr; }
657 QString
dump()
const override;
688 QString
dump()
const override;
707 NodeSelect(
const QList<QgsSQLStatement::NodeTableDef *> &tableList
SIP_TRANSFER,
const QList<QgsSQLStatement::NodeSelectedColumn *> &columns SIP_TRANSFER,
bool distinct ) : mTableList( tableList ), mColumns( columns ), mDistinct( distinct ) {}
711 void setJoins(
const QList<QgsSQLStatement::NodeJoin *> &joins
SIP_TRANSFER ) { qDeleteAll( mJoins ); mJoins = joins; }
717 void setOrderBy(
const QList<QgsSQLStatement::NodeColumnSorted *> &orderBy
SIP_TRANSFER ) { qDeleteAll( mOrderBy ); mOrderBy = orderBy; }
720 QList<QgsSQLStatement::NodeTableDef *>
tables()
const {
return mTableList; }
722 QList<QgsSQLStatement::NodeSelectedColumn *>
columns()
const {
return mColumns; }
726 QList<QgsSQLStatement::NodeJoin *>
joins()
const {
return mJoins; }
730 QList<QgsSQLStatement::NodeColumnSorted *>
orderBy()
const {
return mOrderBy; }
733 QString
dump()
const override;
820 #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.