QGIS API Documentation  3.6.0-Noosa (5873452)
qgssqlstatement.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgssqlstatement.h
3  ---------------------
4  begin : April 2016
5  copyright : (C) 2011 by Martin Dobias
6  copyright : (C) 2016 by Even Rouault
7  email : even.rouault at spatialys.com
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #ifndef QGSSQLSTATEMENT_H
18 #define QGSSQLSTATEMENT_H
19 
20 #include <QCoreApplication>
21 #include "qgis_sip.h"
22 #include <QMetaType>
23 #include <QStringList>
24 #include <QVariant>
25 #include <QList>
26 #include <QSet>
27 
28 #include "qgis_core.h"
29 
36 class CORE_EXPORT QgsSQLStatement
37 {
38  Q_DECLARE_TR_FUNCTIONS( QgsSQLStatement )
39  public:
40 
44  QgsSQLStatement( const QString &statement );
45 
49  QgsSQLStatement( const QgsSQLStatement &other );
50 
54  QgsSQLStatement &operator=( const QgsSQLStatement &other );
55  ~QgsSQLStatement();
56 
58  bool hasParserError() const;
60  QString parserErrorString() const;
61 
66  bool doBasicValidationChecks( QString &errorMsgOut SIP_OUT ) const;
67 
68  class Node;
69 
71  const QgsSQLStatement::Node *rootNode() const;
72 
78  QString statement() const;
79 
86  QString dump() const;
87 
92  static QString quotedIdentifier( QString name );
93 
99  static QString quotedIdentifierIfNeeded( const QString &name );
100 
105  static QString stripQuotedIdentifier( QString text );
106 
111  static QString quotedString( QString text );
112 
118  {
121  };
122 
128  {
129  // logical
132 
133  // comparison
134  boEQ, // =
135  boNE, // <>
136  boLE, // <=
137  boGE, // >=
138  boLT, // <
139  boGT, // >
146 
147  // math
155 
156  // strings
158  };
159 
164  enum JoinType
165  {
173  jtFull
174  };
175 
177  static const char *BINARY_OPERATOR_TEXT[] SIP_SKIP;
178 
180  static const char *UNARY_OPERATOR_TEXT[] SIP_SKIP;
181 
183  static const char *JOIN_TYPE_TEXT[] SIP_SKIP;
184 
186 
187  class Visitor; // visitor interface is defined below
188 
190  enum NodeType
191  {
204  ntCast
205  };
206 
210  class CORE_EXPORT Node
211  {
212 
213 #ifdef SIP_RUN
215  switch ( sipCpp->nodeType() )
216  {
217  case QgsSQLStatement::ntUnaryOperator: sipType = sipType_QgsSQLStatement_NodeUnaryOperator; break;
218  case QgsSQLStatement::ntBinaryOperator: sipType = sipType_QgsSQLStatement_NodeBinaryOperator; break;
219  case QgsSQLStatement::ntInOperator: sipType = sipType_QgsSQLStatement_NodeInOperator; break;
220  case QgsSQLStatement::ntBetweenOperator: sipType = sipType_QgsSQLStatement_NodeBetweenOperator; break;
221  case QgsSQLStatement::ntFunction: sipType = sipType_QgsSQLStatement_NodeFunction; break;
222  case QgsSQLStatement::ntLiteral: sipType = sipType_QgsSQLStatement_NodeLiteral; break;
223  case QgsSQLStatement::ntColumnRef: sipType = sipType_QgsSQLStatement_NodeColumnRef; break;
224  case QgsSQLStatement::ntSelectedColumn: sipType = sipType_QgsSQLStatement_NodeSelectedColumn; break;
225  case QgsSQLStatement::ntSelect: sipType = sipType_QgsSQLStatement_NodeSelect; break;
226  case QgsSQLStatement::ntTableDef: sipType = sipType_QgsSQLStatement_NodeTableDef; break;
227  case QgsSQLStatement::ntJoin: sipType = sipType_QgsSQLStatement_NodeJoin; break;
228  case QgsSQLStatement::ntColumnSorted: sipType = sipType_QgsSQLStatement_NodeColumnSorted; break;
229  case QgsSQLStatement::ntCast: sipType = sipType_QgsSQLStatement_NodeCast; break;
230  default: sipType = 0; break;
231  }
232  SIP_END
233 #endif
234 
235  public:
236  virtual ~Node() = default;
237 
243  virtual QgsSQLStatement::NodeType nodeType() const = 0;
244 
250  virtual QString dump() const = 0;
251 
260  virtual QgsSQLStatement::Node *clone() const = 0 SIP_FACTORY;
261 
277  virtual void accept( QgsSQLStatement::Visitor &v ) const = 0;
278  };
279 
284  class CORE_EXPORT NodeList
285  {
286  public:
288  NodeList() = default;
289  virtual ~NodeList() { qDeleteAll( mList ); }
290 
292  void append( QgsSQLStatement::Node *node SIP_TRANSFER ) { mList.append( node ); }
293 
295  QList<QgsSQLStatement::Node *> list() { return mList; }
296 
300  int count() const { return mList.count(); }
301 
303  void accept( QgsSQLStatement::Visitor &v ) const;
304 
306  QgsSQLStatement::NodeList *clone() const SIP_FACTORY;
307 
309  virtual QString dump() const;
310 
311  protected:
312  QList<Node *> mList;
313  };
314 
318  class CORE_EXPORT NodeUnaryOperator : public QgsSQLStatement::Node
319  {
320  public:
322  NodeUnaryOperator( QgsSQLStatement::UnaryOperator op, QgsSQLStatement::Node *operand SIP_TRANSFER ) : mOp( op ), mOperand( operand ) {}
323  ~NodeUnaryOperator() override { delete mOperand; }
324 
326  QgsSQLStatement::UnaryOperator op() const { return mOp; }
327 
329  QgsSQLStatement::Node *operand() const { return mOperand; }
330 
332  QString dump() const override;
333 
334  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
335  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
336 
337  protected:
339  Node *mOperand = nullptr;
340  };
341 
345  class CORE_EXPORT NodeBinaryOperator : public QgsSQLStatement::Node
346  {
347  public:
350  : mOp( op )
351  , mOpLeft( opLeft )
352  , mOpRight( opRight )
353  {}
354  ~NodeBinaryOperator() override { delete mOpLeft; delete mOpRight; }
355 
357  QgsSQLStatement::BinaryOperator op() const { return mOp; }
358 
360  QgsSQLStatement::Node *opLeft() const { return mOpLeft; }
361 
363  QgsSQLStatement::Node *opRight() const { return mOpRight; }
364 
366  QString dump() const override;
367 
368  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
369  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
370 
372  int precedence() const;
373 
375  bool leftAssociative() const;
376 
377  protected:
378 
380  Node *mOpLeft = nullptr;
381  Node *mOpRight = nullptr;
382  };
383 
387  class CORE_EXPORT NodeInOperator : public QgsSQLStatement::Node
388  {
389  public:
391  NodeInOperator( QgsSQLStatement::Node *node SIP_TRANSFER, QgsSQLStatement::NodeList *list SIP_TRANSFER, bool notin = false ) : mNode( node ), mList( list ), mNotIn( notin ) {}
392  ~NodeInOperator() override { delete mNode; delete mList; }
393 
395  QgsSQLStatement::Node *node() const { return mNode; }
396 
398  bool isNotIn() const { return mNotIn; }
399 
401  QgsSQLStatement::NodeList *list() const { return mList; }
402 
403  QgsSQLStatement::NodeType nodeType() const override { return ntInOperator; }
404  QString dump() const override;
405 
406  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
407  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
408 
409  protected:
410  Node *mNode = nullptr;
411  NodeList *mList = nullptr;
412  bool mNotIn;
413  };
414 
418  class CORE_EXPORT NodeBetweenOperator : public QgsSQLStatement::Node
419  {
420  public:
422  NodeBetweenOperator( QgsSQLStatement::Node *node SIP_TRANSFER, QgsSQLStatement::Node *minVal SIP_TRANSFER, QgsSQLStatement::Node *maxVal SIP_TRANSFER, bool notBetween = false )
423  : mNode( node ), mMinVal( minVal ), mMaxVal( maxVal ), mNotBetween( notBetween ) {}
424  ~NodeBetweenOperator() override { delete mNode; delete mMinVal; delete mMaxVal; }
425 
427  QgsSQLStatement::Node *node() const { return mNode; }
428 
430  bool isNotBetween() const { return mNotBetween; }
431 
433  QgsSQLStatement::Node *minVal() const { return mMinVal; }
434 
436  QgsSQLStatement::Node *maxVal() const { return mMaxVal; }
437 
439  QString dump() const override;
440 
441  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
442  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
443 
444  protected:
445  Node *mNode = nullptr;
446  Node *mMinVal = nullptr;
447  Node *mMaxVal = nullptr;
449  };
450 
454  class CORE_EXPORT NodeFunction : public QgsSQLStatement::Node
455  {
456  public:
458  NodeFunction( const QString &name, QgsSQLStatement::NodeList *args SIP_TRANSFER ) : mName( name ), mArgs( args ) {}
459  ~NodeFunction() override { delete mArgs; }
460 
462  QString name() const { return mName; }
463 
465  QgsSQLStatement::NodeList *args() const { return mArgs; }
466 
467  QgsSQLStatement::NodeType nodeType() const override { return ntFunction; }
468  QString dump() const override;
469 
470  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
471  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
472 
473  protected:
474  QString mName;
475  NodeList *mArgs = nullptr;
476 
477  };
478 
482  class CORE_EXPORT NodeLiteral : public QgsSQLStatement::Node
483  {
484  public:
486  NodeLiteral( const QVariant &value ) : mValue( value ) {}
487 
489  inline QVariant value() const { return mValue; }
490 
491  QgsSQLStatement::NodeType nodeType() const override { return ntLiteral; }
492  QString dump() const override;
493 
494  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
495  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
496 
497  protected:
498  QVariant mValue;
499  };
500 
504  class CORE_EXPORT NodeColumnRef : public QgsSQLStatement::Node
505  {
506  public:
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 ) {}
511 
513  void setDistinct( bool distinct = true ) { mDistinct = distinct; }
514 
516  QString tableName() const { return mTableName; }
517 
519  QString name() const { return mName; }
520 
522  bool star() const { return mStar; }
523 
525  bool distinct() const { return mDistinct; }
526 
527  QgsSQLStatement::NodeType nodeType() const override { return ntColumnRef; }
528  QString dump() const override;
529 
530  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
531  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
533  QgsSQLStatement::NodeColumnRef *cloneThis() const SIP_FACTORY;
534 
535  protected:
536  QString mTableName;
537  QString mName;
538  bool mDistinct;
539  bool mStar;
540  };
541 
545  class CORE_EXPORT NodeSelectedColumn : public QgsSQLStatement::Node
546  {
547  public:
549  NodeSelectedColumn( QgsSQLStatement::Node *node SIP_TRANSFER ) : mColumnNode( node ) {}
550  ~NodeSelectedColumn() override { delete mColumnNode; }
551 
553  void setAlias( const QString &alias ) { mAlias = alias; }
554 
556  QgsSQLStatement::Node *column() const { return mColumnNode; }
557 
559  QString alias() const { return mAlias; }
560 
562  QString dump() const override;
563 
564  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
565  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
568 
569  protected:
570  Node *mColumnNode = nullptr;
571  QString mAlias;
572  };
573 
577  class CORE_EXPORT NodeCast : public QgsSQLStatement::Node
578  {
579  public:
581  NodeCast( QgsSQLStatement::Node *node SIP_TRANSFER, const QString &type ) : mNode( node ), mType( type ) {}
582  ~NodeCast() override { delete mNode; }
583 
585  QgsSQLStatement::Node *node() const { return mNode; }
586 
588  QString type() const { return mType; }
589 
590  QgsSQLStatement::NodeType nodeType() const override { return ntCast; }
591  QString dump() const override;
592 
593  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
594  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
595 
596  protected:
597  Node *mNode = nullptr;
598  QString mType;
599  };
600 
604  class CORE_EXPORT NodeTableDef : public QgsSQLStatement::Node
605  {
606  public:
608  NodeTableDef( const QString &name ) : mName( name ) {}
610  NodeTableDef( const QString &name, const QString &alias ) : mName( name ), mAlias( alias ) {}
611 
613  QString name() const { return mName; }
614 
616  QString alias() const { return mAlias; }
617 
618  QgsSQLStatement::NodeType nodeType() const override { return ntTableDef; }
619  QString dump() const override;
620 
621  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
622  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
624  QgsSQLStatement::NodeTableDef *cloneThis() const SIP_FACTORY;
625 
626  protected:
627  QString mName;
628  QString mAlias;
629  };
630 
634  class CORE_EXPORT NodeJoin : public QgsSQLStatement::Node
635  {
636  public:
638  NodeJoin( QgsSQLStatement::NodeTableDef *tabledef SIP_TRANSFER, QgsSQLStatement::Node *onExpr SIP_TRANSFER, QgsSQLStatement::JoinType type ) : mTableDef( tabledef ), mOnExpr( onExpr ), mType( type ) {}
640  NodeJoin( QgsSQLStatement::NodeTableDef *tabledef SIP_TRANSFER, const QList<QString> &usingColumns, QgsSQLStatement::JoinType type ) : mTableDef( tabledef ), mUsingColumns( usingColumns ), mType( type ) {}
641  ~NodeJoin() override { delete mTableDef; delete mOnExpr; }
642 
644  QgsSQLStatement::NodeTableDef *tableDef() const { return mTableDef; }
645 
647  QgsSQLStatement::Node *onExpr() const { return mOnExpr; }
648 
650  QList<QString> usingColumns() const { return mUsingColumns; }
651 
653  QgsSQLStatement::JoinType type() const { return mType; }
654 
655  QgsSQLStatement::NodeType nodeType() const override { return ntJoin; }
656  QString dump() const override;
657 
658  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
659  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
661  QgsSQLStatement::NodeJoin *cloneThis() const SIP_FACTORY;
662 
663  protected:
664  NodeTableDef *mTableDef = nullptr;
665  Node *mOnExpr = nullptr;
666  QList<QString> mUsingColumns;
668  };
669 
673  class CORE_EXPORT NodeColumnSorted : public QgsSQLStatement::Node
674  {
675  public:
677  NodeColumnSorted( QgsSQLStatement::NodeColumnRef *column SIP_TRANSFER, bool asc ) : mColumn( column ), mAsc( asc ) {}
678  ~NodeColumnSorted() override { delete mColumn; }
679 
681  QgsSQLStatement::NodeColumnRef *column() const { return mColumn; }
682 
684  bool ascending() const { return mAsc; }
685 
686  QgsSQLStatement::NodeType nodeType() const override { return ntColumnSorted; }
687  QString dump() const override;
688 
689  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
690  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
693 
694  protected:
695  NodeColumnRef *mColumn = nullptr;
696  bool mAsc;
697  };
698 
702  class CORE_EXPORT NodeSelect : public QgsSQLStatement::Node
703  {
704  public:
706  NodeSelect( const QList<QgsSQLStatement::NodeTableDef *> &tableList SIP_TRANSFER, const QList<QgsSQLStatement::NodeSelectedColumn *> &columns SIP_TRANSFER, bool distinct ) : mTableList( tableList ), mColumns( columns ), mDistinct( distinct ) {}
707  ~NodeSelect() override;
708 
710  void setJoins( const QList<QgsSQLStatement::NodeJoin *> &joins SIP_TRANSFER ) { qDeleteAll( mJoins ); mJoins = joins; }
712  void appendJoin( QgsSQLStatement::NodeJoin *join SIP_TRANSFER ) { mJoins.append( join ); }
714  void setWhere( QgsSQLStatement::Node *where SIP_TRANSFER ) { delete mWhere; mWhere = where; }
716  void setOrderBy( const QList<QgsSQLStatement::NodeColumnSorted *> &orderBy SIP_TRANSFER ) { qDeleteAll( mOrderBy ); mOrderBy = orderBy; }
717 
719  QList<QgsSQLStatement::NodeTableDef *> tables() const { return mTableList; }
721  QList<QgsSQLStatement::NodeSelectedColumn *> columns() const { return mColumns; }
723  bool distinct() const { return mDistinct; }
725  QList<QgsSQLStatement::NodeJoin *> joins() const { return mJoins; }
727  QgsSQLStatement::Node *where() const { return mWhere; }
729  QList<QgsSQLStatement::NodeColumnSorted *> orderBy() const { return mOrderBy; }
730 
731  QgsSQLStatement::NodeType nodeType() const override { return ntSelect; }
732  QString dump() const override;
733 
734  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
735  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
736 
737  protected:
738  QList<NodeTableDef *> mTableList;
739  QList<NodeSelectedColumn *> mColumns;
740  bool mDistinct;
741  QList<NodeJoin *> mJoins;
742  Node *mWhere = nullptr;
743  QList<NodeColumnSorted *> mOrderBy;
744  };
745 
747 
752  class CORE_EXPORT Visitor
753  {
754  public:
755  virtual ~Visitor() = default;
757  virtual void visit( const QgsSQLStatement::NodeUnaryOperator &n ) = 0;
759  virtual void visit( const QgsSQLStatement::NodeBinaryOperator &n ) = 0;
761  virtual void visit( const QgsSQLStatement::NodeInOperator &n ) = 0;
763  virtual void visit( const QgsSQLStatement::NodeBetweenOperator &n ) = 0;
765  virtual void visit( const QgsSQLStatement::NodeFunction &n ) = 0;
767  virtual void visit( const QgsSQLStatement::NodeLiteral &n ) = 0;
769  virtual void visit( const QgsSQLStatement::NodeColumnRef &n ) = 0;
771  virtual void visit( const QgsSQLStatement::NodeSelectedColumn &n ) = 0;
773  virtual void visit( const QgsSQLStatement::NodeTableDef &n ) = 0;
775  virtual void visit( const QgsSQLStatement::NodeSelect &n ) = 0;
777  virtual void visit( const QgsSQLStatement::NodeJoin &n ) = 0;
779  virtual void visit( const QgsSQLStatement::NodeColumnSorted &n ) = 0;
781  virtual void visit( const QgsSQLStatement::NodeCast &n ) = 0;
782  };
783 
787  class CORE_EXPORT RecursiveVisitor: public QgsSQLStatement::Visitor
788  {
789  public:
791  RecursiveVisitor() = default;
792 
793  void visit( const QgsSQLStatement::NodeUnaryOperator &n ) override { n.operand()->accept( *this ); }
794  void visit( const QgsSQLStatement::NodeBinaryOperator &n ) override { n.opLeft()->accept( *this ); n.opRight()->accept( *this ); }
795  void visit( const QgsSQLStatement::NodeInOperator &n ) override { n.node()->accept( *this ); n.list()->accept( *this ); }
796  void visit( const QgsSQLStatement::NodeBetweenOperator &n ) override { n.node()->accept( *this ); n.minVal()->accept( *this ); n.maxVal()->accept( *this ); }
797  void visit( const QgsSQLStatement::NodeFunction &n ) override { n.args()->accept( *this ); }
798  void visit( const QgsSQLStatement::NodeLiteral & ) override {}
799  void visit( const QgsSQLStatement::NodeColumnRef & ) override { }
800  void visit( const QgsSQLStatement::NodeSelectedColumn &n ) override { n.column()->accept( *this ); }
801  void visit( const QgsSQLStatement::NodeTableDef & ) override {}
802  void visit( const QgsSQLStatement::NodeSelect &n ) override;
803  void visit( const QgsSQLStatement::NodeJoin &n ) override;
804  void visit( const QgsSQLStatement::NodeColumnSorted &n ) override { n.column()->accept( *this ); }
805  void visit( const QgsSQLStatement::NodeCast &n ) override { n.node()->accept( *this ); }
806  };
807 
809  void acceptVisitor( QgsSQLStatement::Visitor &v ) const;
810 
811  protected:
812  QgsSQLStatement::Node *mRootNode = nullptr;
813  QString mStatement;
815 };
816 
818 
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
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)
NodeType
Node type.
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.
Abstract node class.
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.
#define SIP_SKIP
Definition: qgis_sip.h:119
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.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
Literal value (integer, integer64, double, string)
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QString name() const
The name of the column.
QList< QgsSQLStatement::NodeTableDef * > tables() const
Returns the list of tables.
#define SIP_END
Definition: qgis_sip.h:182
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
#define SIP_FACTORY
Definition: qgis_sip.h:69
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.
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.
Reference to a column.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
&#39;X BETWEEN y and z&#39; 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.
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.
#define SIP_OUT
Definition: qgis_sip.h:51
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)
Definition: qgis_sip.h:165
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.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
&#39;x IN (y, z)&#39; operator
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.