17 #ifndef QGSSQLSTATEMENT_H 18 #define QGSSQLSTATEMENT_H 20 #include <QCoreApplication> 22 #include <QStringList> 52 bool hasParserError()
const;
54 QString parserErrorString()
const;
59 bool doBasicValidationChecks(
QString& errorMsgOut )
const;
64 const Node* rootNode()
const;
162 static const char* BinaryOperatorText[];
165 static const char* UnaryOperatorText[];
168 static const char* JoinTypeText[];
204 virtual NodeType nodeType()
const = 0;
211 virtual QString dump()
const = 0;
221 virtual Node* clone()
const = 0;
238 virtual void accept(
Visitor& v )
const = 0;
258 int count()
const {
return mList.count(); }
324 int precedence()
const;
327 bool leftAssociative()
const;
372 NodeBetweenOperator(
Node* node,
Node* minVal,
Node* maxVal,
bool notBetween =
false ) : mNode( node ), mMinVal( minVal ), mMaxVal( maxVal ), mNotBetween( notBetween ) {}
456 NodeColumnRef(
const QString& tableName,
const QString& name,
bool star ) : mTableName( tableName ), mName( name ), mDistinct( false ), mStar( star ) {}
459 void setDistinct(
bool distinct =
true ) { mDistinct = distinct; }
468 bool star()
const {
return mStar; }
583 virtual ~NodeJoin() {
delete mTableDef;
delete mOnExpr; }
647 virtual ~NodeSelect() { qDeleteAll( mTableList ); qDeleteAll( mColumns ); qDeleteAll( mJoins );
delete mWhere; qDeleteAll( mOrderBy ); }
714 virtual void visit(
const NodeSelect& n ) = 0;
716 virtual void visit(
const NodeJoin& n ) = 0;
720 virtual void visit(
const NodeCast& n ) = 0;
757 #endif // QGSSQLSTATEMENT_H bool ascending() const
Whether the column is sorted in ascending order.
QList< NodeTableDef * > mTableList
virtual void accept(Visitor &v) const override
Support the visitor pattern.
Node * node() const
Node that is refered to.
NodeTableDef(const QString &name)
Constructor with table name.
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
JoinType type() const
Join type.
Function with a name and arguments node.
virtual void accept(Visitor &v) const override
Support the visitor pattern.
Node * onExpr() const
On expression.
JoinType
list of join types
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QList< NodeSelectedColumn * > mColumns
NodeColumnRef * column() const
The name of the column.
QString type() const
Type.
Node * operand() const
Operand.
virtual void accept(Visitor &v) const override
Support the visitor pattern.
QList< NodeJoin * > mJoins
Q_DECLARE_METATYPE(QgsMimeDataUtils::UriList)
void appendJoin(NodeJoin *join)
Append a join.
UnaryOperator
list of unary operators
Node * column() const
Column that is refered to.
NodeBetweenOperator(Node *node, Node *minVal, Node *maxVal, bool notBetween=false)
Constructor.
NodeTableDef(const QString &name, const QString &alias)
Constructor with table name and alias.
void visit(const QgsSQLStatement::NodeSelectedColumn &n) override
Visit NodeSelectedColumn.
NodeTableDef * tableDef() const
Table definition.
virtual ~NodeInOperator()
Node * node() const
Variable at the left of BETWEEN.
Binary logical/arithmetical operator (AND, OR, =, +, ...)
NodeBinaryOperator(BinaryOperator op, Node *opLeft, Node *opRight)
Constructor.
Node * opLeft() const
Left operand.
QList< QString > mUsingColumns
virtual void accept(Visitor &v) const override
Support the visitor pattern.
QString name() const
Return function name.
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
bool distinct() const
Return if the SELECT is DISTINCT.
QList< QString > usingColumns() const
Columns referenced by USING.
QgsSQLStatement::Node * mRootNode
NodeColumnSorted(NodeColumnRef *column, bool asc)
Constructor.
A visitor that recursively explores all children.
bool isNotIn() const
Whether this is a NOT IN operator.
virtual void accept(Visitor &v) const override
Support the visitor pattern.
Class for parsing SQL statements.
void accept(Visitor &v) const
Accept visitor.
Node * opRight() const
Right operand.
QString name() const
Table name.
void acceptVisitor(Visitor &v) const
Entry function for the visitor pattern.
QString alias() const
Table alias.
virtual QString dump() const =0
Abstract virtual dump method.
void visit(const QgsSQLStatement::NodeBetweenOperator &n) override
Visit NodeBetweenOperator.
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
NodeCast(Node *node, const QString &type)
Constructor.
NodeJoin(NodeTableDef *tabledef, QList< QString > usingColumns, JoinType type)
Constructor with table definition and USING columns.
void append(Node *node)
Takes ownership of the provided node.
virtual void accept(Visitor &v) const override
Support the visitor pattern.
QList< NodeColumnSorted * > mOrderBy
Literal value (integer, integer64, double, string)
Node * where() const
Return the where clause.
QString name() const
The name of the column.
Node * node() const
Variable at the left of IN.
void setAlias(const QString &alias)
Set alias name.
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
Unary logicial/arithmetical operator ( NOT, - )
BinaryOperator
list of binary operators
QList< Node * > list()
Return list.
virtual Node * clone() const =0
Generate a clone of this node.
virtual void accept(Visitor &v) const override
Support the visitor pattern.
bool distinct() const
Whether this is prefixed by DISTINCT.
QString alias() const
Alias name.
bool isNotBetween() const
Whether this is a NOT BETWEEN operator.
virtual void accept(Visitor &v) const =0
Support the visitor pattern.
BinaryOperator op() const
Operator.
NodeList * args() const
Return arguments.
'X BETWEEN y and z' operator
virtual void accept(Visitor &v) const override
Support the visitor pattern.
void visit(const QgsSQLStatement::NodeColumnSorted &n) override
Visit NodeColumnSorted.
void setOrderBy(QList< NodeColumnSorted *> orderBy)
Set order by columns.
void setJoins(QList< NodeJoin *> joins)
Set joins.
QVariant value() const
The value of the literal.
void visit(const QgsSQLStatement::NodeLiteral &) override
Visit NodeLiteral.
QList< NodeColumnSorted * > orderBy() const
Return the list of order by columns.
Node * minVal() const
Minimum bound.
virtual void visit(const NodeUnaryOperator &n)=0
Visit NodeUnaryOperator.
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
virtual ~NodeBetweenOperator()
void visit(const QgsSQLStatement::NodeInOperator &n) override
Visit NodeInOperator.
bool star() const
Whether this is the * column.
NodeColumnRef(const QString &tableName, const QString &name, bool star)
Constructor with table and column name.
QList< NodeTableDef * > tables() const
Return the list of tables.
virtual void accept(Visitor &v) const override
Support the visitor pattern.
void setDistinct(bool distinct=true)
Set whether this is prefixed by DISTINCT.
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
void visit(const QgsSQLStatement::NodeUnaryOperator &n) override
Visit NodeUnaryOperator.
void visit(const QgsSQLStatement::NodeColumnRef &) override
Visit NodeColumnRef.
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
virtual void accept(Visitor &v) const override
Support the visitor pattern.
void setWhere(Node *where)
Set where clause.
Support for visitor pattern - algorithms dealing with the statement may be implemented without modify...
void visit(const QgsSQLStatement::NodeTableDef &) override
Visit NodeTableDef.
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
NodeSelect(QList< NodeTableDef *> tableList, QList< NodeSelectedColumn *> columns, bool distinct)
Constructor.
QString tableName() const
The name of the table.
virtual void accept(Visitor &v) const override
Support the visitor pattern.
RecursiveVisitor()
Constructor.
NodeUnaryOperator(UnaryOperator op, Node *operand)
Constructor.
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
NodeFunction(QString name, NodeList *args)
Constructor.
NodeSelectedColumn(Node *node)
Constructor.
virtual void accept(Visitor &v) const override
Support the visitor pattern.
virtual ~NodeSelectedColumn()
UnaryOperator op() const
Operator.
Node * maxVal() const
Maximum bound.
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
virtual void accept(Visitor &v) const override
Support the visitor pattern.
'x IN (y, z)' operator
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
NodeJoin(NodeTableDef *tabledef, Node *onExpr, JoinType type)
Constructor with table definition, ON expression.
QList< NodeSelectedColumn * > columns() const
Return the list of columns.
void visit(const QgsSQLStatement::NodeFunction &n) override
Visit NodeFunction.
NodeColumnRef(const QString &name, bool star)
Constructor with colum name only.
NodeInOperator(Node *node, NodeList *list, bool notin=false)
Constructor.
void visit(const QgsSQLStatement::NodeCast &n) override
Visit NodeCast.
void visit(const QgsSQLStatement::NodeBinaryOperator &n) override
Visit NodeBinaryOperator.
NodeList * list() const
Values list.
NodeLiteral(const QVariant &value)
Constructor.
QString mParserErrorString
QList< NodeJoin * > joins() const
Return the list of joins.
int count() const
Returns the number of nodes in the list.