QGIS API Documentation  3.2.0-Bonn (bc43194)
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 "qgis.h"
23 #include <QMetaType>
24 #include <QStringList>
25 #include <QVariant>
26 #include <QList>
27 #include <QSet>
28 
29 #include "qgis_core.h"
30 
37 class CORE_EXPORT QgsSQLStatement
38 {
39  Q_DECLARE_TR_FUNCTIONS( QgsSQLStatement )
40  public:
41 
45  QgsSQLStatement( const QString &statement );
46 
50  QgsSQLStatement( const QgsSQLStatement &other );
51 
55  QgsSQLStatement &operator=( const QgsSQLStatement &other );
56  ~QgsSQLStatement();
57 
59  bool hasParserError() const;
61  QString parserErrorString() const;
62 
67  bool doBasicValidationChecks( QString &errorMsgOut SIP_OUT ) const;
68 
69  class Node;
70 
72  const QgsSQLStatement::Node *rootNode() const;
73 
79  QString statement() const;
80 
87  QString dump() const;
88 
93  static QString quotedIdentifier( QString name );
94 
100  static QString quotedIdentifierIfNeeded( const QString &name );
101 
106  static QString stripQuotedIdentifier( QString text );
107 
112  static QString quotedString( QString text );
113 
119  {
122  };
123 
129  {
130  // logical
133 
134  // comparison
135  boEQ, // =
136  boNE, // <>
137  boLE, // <=
138  boGE, // >=
139  boLT, // <
140  boGT, // >
147 
148  // math
156 
157  // strings
159  };
160 
165  enum JoinType
166  {
174  jtFull
175  };
176 
178  static const char *BINARY_OPERATOR_TEXT[] SIP_SKIP;
179 
181  static const char *UNARY_OPERATOR_TEXT[] SIP_SKIP;
182 
184  static const char *JOIN_TYPE_TEXT[] SIP_SKIP;
185 
187 
188  class Visitor; // visitor interface is defined below
189 
191  enum NodeType
192  {
205  ntCast
206  };
207 
211  class CORE_EXPORT Node
212  {
213 
214 #ifdef SIP_RUN
216  switch ( sipCpp->nodeType() )
217  {
218  case QgsSQLStatement::ntUnaryOperator: sipType = sipType_QgsSQLStatement_NodeUnaryOperator; break;
219  case QgsSQLStatement::ntBinaryOperator: sipType = sipType_QgsSQLStatement_NodeBinaryOperator; break;
220  case QgsSQLStatement::ntInOperator: sipType = sipType_QgsSQLStatement_NodeInOperator; break;
221  case QgsSQLStatement::ntBetweenOperator: sipType = sipType_QgsSQLStatement_NodeBetweenOperator; break;
222  case QgsSQLStatement::ntFunction: sipType = sipType_QgsSQLStatement_NodeFunction; break;
223  case QgsSQLStatement::ntLiteral: sipType = sipType_QgsSQLStatement_NodeLiteral; break;
224  case QgsSQLStatement::ntColumnRef: sipType = sipType_QgsSQLStatement_NodeColumnRef; break;
225  case QgsSQLStatement::ntSelectedColumn: sipType = sipType_QgsSQLStatement_NodeSelectedColumn; break;
226  case QgsSQLStatement::ntSelect: sipType = sipType_QgsSQLStatement_NodeSelect; break;
227  case QgsSQLStatement::ntTableDef: sipType = sipType_QgsSQLStatement_NodeTableDef; break;
228  case QgsSQLStatement::ntJoin: sipType = sipType_QgsSQLStatement_NodeJoin; break;
229  case QgsSQLStatement::ntColumnSorted: sipType = sipType_QgsSQLStatement_NodeColumnSorted; break;
230  case QgsSQLStatement::ntCast: sipType = sipType_QgsSQLStatement_NodeCast; break;
231  default: sipType = 0; break;
232  }
233  SIP_END
234 #endif
235 
236  public:
237  virtual ~Node() = default;
238 
244  virtual QgsSQLStatement::NodeType nodeType() const = 0;
245 
251  virtual QString dump() const = 0;
252 
261  virtual QgsSQLStatement::Node *clone() const = 0 SIP_FACTORY;
262 
278  virtual void accept( QgsSQLStatement::Visitor &v ) const = 0;
279  };
280 
285  class CORE_EXPORT NodeList
286  {
287  public:
289  NodeList() = default;
290  virtual ~NodeList() { qDeleteAll( mList ); }
291 
293  void append( QgsSQLStatement::Node *node SIP_TRANSFER ) { mList.append( node ); }
294 
296  QList<QgsSQLStatement::Node *> list() { return mList; }
297 
301  int count() const { return mList.count(); }
302 
304  void accept( QgsSQLStatement::Visitor &v ) const;
305 
307  QgsSQLStatement::NodeList *clone() const SIP_FACTORY;
308 
310  virtual QString dump() const;
311 
312  protected:
313  QList<Node *> mList;
314  };
315 
319  class CORE_EXPORT NodeUnaryOperator : public QgsSQLStatement::Node
320  {
321  public:
323  NodeUnaryOperator( QgsSQLStatement::UnaryOperator op, QgsSQLStatement::Node *operand SIP_TRANSFER ) : mOp( op ), mOperand( operand ) {}
324  ~NodeUnaryOperator() override { delete mOperand; }
325 
327  QgsSQLStatement::UnaryOperator op() const { return mOp; }
328 
330  QgsSQLStatement::Node *operand() const { return mOperand; }
331 
333  QString dump() const override;
334 
335  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
336  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
337 
338  protected:
340  Node *mOperand = nullptr;
341  };
342 
346  class CORE_EXPORT NodeBinaryOperator : public QgsSQLStatement::Node
347  {
348  public:
351  : mOp( op )
352  , mOpLeft( opLeft )
353  , mOpRight( opRight )
354  {}
355  ~NodeBinaryOperator() override { delete mOpLeft; delete mOpRight; }
356 
358  QgsSQLStatement::BinaryOperator op() const { return mOp; }
359 
361  QgsSQLStatement::Node *opLeft() const { return mOpLeft; }
362 
364  QgsSQLStatement::Node *opRight() const { return mOpRight; }
365 
367  QString dump() const override;
368 
369  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
370  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
371 
373  int precedence() const;
374 
376  bool leftAssociative() const;
377 
378  protected:
379 
381  Node *mOpLeft = nullptr;
382  Node *mOpRight = nullptr;
383  };
384 
388  class CORE_EXPORT NodeInOperator : public QgsSQLStatement::Node
389  {
390  public:
392  NodeInOperator( QgsSQLStatement::Node *node SIP_TRANSFER, QgsSQLStatement::NodeList *list SIP_TRANSFER, bool notin = false ) : mNode( node ), mList( list ), mNotIn( notin ) {}
393  ~NodeInOperator() override { delete mNode; delete mList; }
394 
396  QgsSQLStatement::Node *node() const { return mNode; }
397 
399  bool isNotIn() const { return mNotIn; }
400 
402  QgsSQLStatement::NodeList *list() const { return mList; }
403 
404  QgsSQLStatement::NodeType nodeType() const override { return ntInOperator; }
405  QString dump() const override;
406 
407  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
408  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
409 
410  protected:
411  Node *mNode = nullptr;
412  NodeList *mList = nullptr;
413  bool mNotIn;
414  };
415 
419  class CORE_EXPORT NodeBetweenOperator : public QgsSQLStatement::Node
420  {
421  public:
423  NodeBetweenOperator( QgsSQLStatement::Node *node SIP_TRANSFER, QgsSQLStatement::Node *minVal SIP_TRANSFER, QgsSQLStatement::Node *maxVal SIP_TRANSFER, bool notBetween = false )
424  : mNode( node ), mMinVal( minVal ), mMaxVal( maxVal ), mNotBetween( notBetween ) {}
425  ~NodeBetweenOperator() override { delete mNode; delete mMinVal; delete mMaxVal; }
426 
428  QgsSQLStatement::Node *node() const { return mNode; }
429 
431  bool isNotBetween() const { return mNotBetween; }
432 
434  QgsSQLStatement::Node *minVal() const { return mMinVal; }
435 
437  QgsSQLStatement::Node *maxVal() const { return mMaxVal; }
438 
440  QString dump() const override;
441 
442  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
443  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
444 
445  protected:
446  Node *mNode = nullptr;
447  Node *mMinVal = nullptr;
448  Node *mMaxVal = nullptr;
450  };
451 
455  class CORE_EXPORT NodeFunction : public QgsSQLStatement::Node
456  {
457  public:
459  NodeFunction( const QString &name, QgsSQLStatement::NodeList *args SIP_TRANSFER ) : mName( name ), mArgs( args ) {}
460  ~NodeFunction() override { delete mArgs; }
461 
463  QString name() const { return mName; }
464 
466  QgsSQLStatement::NodeList *args() const { return mArgs; }
467 
468  QgsSQLStatement::NodeType nodeType() const override { return ntFunction; }
469  QString dump() const override;
470 
471  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
472  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
473 
474  protected:
475  QString mName;
476  NodeList *mArgs = nullptr;
477 
478  };
479 
483  class CORE_EXPORT NodeLiteral : public QgsSQLStatement::Node
484  {
485  public:
487  NodeLiteral( const QVariant &value ) : mValue( value ) {}
488 
490  inline QVariant value() const { return mValue; }
491 
492  QgsSQLStatement::NodeType nodeType() const override { return ntLiteral; }
493  QString dump() const override;
494 
495  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
496  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
497 
498  protected:
499  QVariant mValue;
500  };
501 
505  class CORE_EXPORT NodeColumnRef : public QgsSQLStatement::Node
506  {
507  public:
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 ) {}
512 
514  void setDistinct( bool distinct = true ) { mDistinct = distinct; }
515 
517  QString tableName() const { return mTableName; }
518 
520  QString name() const { return mName; }
521 
523  bool star() const { return mStar; }
524 
526  bool distinct() const { return mDistinct; }
527 
528  QgsSQLStatement::NodeType nodeType() const override { return ntColumnRef; }
529  QString dump() const override;
530 
531  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
532  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
534  QgsSQLStatement::NodeColumnRef *cloneThis() const SIP_FACTORY;
535 
536  protected:
537  QString mTableName;
538  QString mName;
539  bool mDistinct;
540  bool mStar;
541  };
542 
546  class CORE_EXPORT NodeSelectedColumn : public QgsSQLStatement::Node
547  {
548  public:
550  NodeSelectedColumn( QgsSQLStatement::Node *node SIP_TRANSFER ) : mColumnNode( node ) {}
551  ~NodeSelectedColumn() override { delete mColumnNode; }
552 
554  void setAlias( const QString &alias ) { mAlias = alias; }
555 
557  QgsSQLStatement::Node *column() const { return mColumnNode; }
558 
560  QString alias() const { return mAlias; }
561 
563  QString dump() const override;
564 
565  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
566  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
569 
570  protected:
571  Node *mColumnNode = nullptr;
572  QString mAlias;
573  };
574 
578  class CORE_EXPORT NodeCast : public QgsSQLStatement::Node
579  {
580  public:
582  NodeCast( QgsSQLStatement::Node *node SIP_TRANSFER, const QString &type ) : mNode( node ), mType( type ) {}
583  ~NodeCast() override { delete mNode; }
584 
586  QgsSQLStatement::Node *node() const { return mNode; }
587 
589  QString type() const { return mType; }
590 
591  QgsSQLStatement::NodeType nodeType() const override { return ntCast; }
592  QString dump() const override;
593 
594  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
595  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
596 
597  protected:
598  Node *mNode = nullptr;
599  QString mType;
600  };
601 
605  class CORE_EXPORT NodeTableDef : public QgsSQLStatement::Node
606  {
607  public:
609  NodeTableDef( const QString &name ) : mName( name ) {}
611  NodeTableDef( const QString &name, const QString &alias ) : mName( name ), mAlias( alias ) {}
612 
614  QString name() const { return mName; }
615 
617  QString alias() const { return mAlias; }
618 
619  QgsSQLStatement::NodeType nodeType() const override { return ntTableDef; }
620  QString dump() const override;
621 
622  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
623  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
625  QgsSQLStatement::NodeTableDef *cloneThis() const SIP_FACTORY;
626 
627  protected:
628  QString mName;
629  QString mAlias;
630  };
631 
635  class CORE_EXPORT NodeJoin : public QgsSQLStatement::Node
636  {
637  public:
639  NodeJoin( QgsSQLStatement::NodeTableDef *tabledef SIP_TRANSFER, QgsSQLStatement::Node *onExpr SIP_TRANSFER, QgsSQLStatement::JoinType type ) : mTableDef( tabledef ), mOnExpr( onExpr ), mType( type ) {}
641  NodeJoin( QgsSQLStatement::NodeTableDef *tabledef SIP_TRANSFER, const QList<QString> &usingColumns, QgsSQLStatement::JoinType type ) : mTableDef( tabledef ), mUsingColumns( usingColumns ), mType( type ) {}
642  ~NodeJoin() override { delete mTableDef; delete mOnExpr; }
643 
645  QgsSQLStatement::NodeTableDef *tableDef() const { return mTableDef; }
646 
648  QgsSQLStatement::Node *onExpr() const { return mOnExpr; }
649 
651  QList<QString> usingColumns() const { return mUsingColumns; }
652 
654  QgsSQLStatement::JoinType type() const { return mType; }
655 
656  QgsSQLStatement::NodeType nodeType() const override { return ntJoin; }
657  QString dump() const override;
658 
659  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
660  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
662  QgsSQLStatement::NodeJoin *cloneThis() const SIP_FACTORY;
663 
664  protected:
665  NodeTableDef *mTableDef = nullptr;
666  Node *mOnExpr = nullptr;
667  QList<QString> mUsingColumns;
669  };
670 
674  class CORE_EXPORT NodeColumnSorted : public QgsSQLStatement::Node
675  {
676  public:
678  NodeColumnSorted( QgsSQLStatement::NodeColumnRef *column SIP_TRANSFER, bool asc ) : mColumn( column ), mAsc( asc ) {}
679  ~NodeColumnSorted() override { delete mColumn; }
680 
682  QgsSQLStatement::NodeColumnRef *column() const { return mColumn; }
683 
685  bool ascending() const { return mAsc; }
686 
687  QgsSQLStatement::NodeType nodeType() const override { return ntColumnSorted; }
688  QString dump() const override;
689 
690  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
691  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
694 
695  protected:
696  NodeColumnRef *mColumn = nullptr;
697  bool mAsc;
698  };
699 
703  class CORE_EXPORT NodeSelect : public QgsSQLStatement::Node
704  {
705  public:
707  NodeSelect( const QList<QgsSQLStatement::NodeTableDef *> &tableList SIP_TRANSFER, const QList<QgsSQLStatement::NodeSelectedColumn *> &columns SIP_TRANSFER, bool distinct ) : mTableList( tableList ), mColumns( columns ), mDistinct( distinct ) {}
708  ~NodeSelect() override;
709 
711  void setJoins( const QList<QgsSQLStatement::NodeJoin *> &joins SIP_TRANSFER ) { qDeleteAll( mJoins ); mJoins = joins; }
713  void appendJoin( QgsSQLStatement::NodeJoin *join SIP_TRANSFER ) { mJoins.append( join ); }
715  void setWhere( QgsSQLStatement::Node *where SIP_TRANSFER ) { delete mWhere; mWhere = where; }
717  void setOrderBy( const QList<QgsSQLStatement::NodeColumnSorted *> &orderBy SIP_TRANSFER ) { qDeleteAll( mOrderBy ); mOrderBy = orderBy; }
718 
720  QList<QgsSQLStatement::NodeTableDef *> tables() const { return mTableList; }
722  QList<QgsSQLStatement::NodeSelectedColumn *> columns() const { return mColumns; }
724  bool distinct() const { return mDistinct; }
726  QList<QgsSQLStatement::NodeJoin *> joins() const { return mJoins; }
728  QgsSQLStatement::Node *where() const { return mWhere; }
730  QList<QgsSQLStatement::NodeColumnSorted *> orderBy() const { return mOrderBy; }
731 
732  QgsSQLStatement::NodeType nodeType() const override { return ntSelect; }
733  QString dump() const override;
734 
735  void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
736  QgsSQLStatement::Node *clone() const override SIP_FACTORY;
737 
738  protected:
739  QList<NodeTableDef *> mTableList;
740  QList<NodeSelectedColumn *> mColumns;
741  bool mDistinct;
742  QList<NodeJoin *> mJoins;
743  Node *mWhere = nullptr;
744  QList<NodeColumnSorted *> mOrderBy;
745  };
746 
748 
753  class CORE_EXPORT Visitor
754  {
755  public:
756  virtual ~Visitor() = default;
758  virtual void visit( const QgsSQLStatement::NodeUnaryOperator &n ) = 0;
760  virtual void visit( const QgsSQLStatement::NodeBinaryOperator &n ) = 0;
762  virtual void visit( const QgsSQLStatement::NodeInOperator &n ) = 0;
764  virtual void visit( const QgsSQLStatement::NodeBetweenOperator &n ) = 0;
766  virtual void visit( const QgsSQLStatement::NodeFunction &n ) = 0;
768  virtual void visit( const QgsSQLStatement::NodeLiteral &n ) = 0;
770  virtual void visit( const QgsSQLStatement::NodeColumnRef &n ) = 0;
772  virtual void visit( const QgsSQLStatement::NodeSelectedColumn &n ) = 0;
774  virtual void visit( const QgsSQLStatement::NodeTableDef &n ) = 0;
776  virtual void visit( const QgsSQLStatement::NodeSelect &n ) = 0;
778  virtual void visit( const QgsSQLStatement::NodeJoin &n ) = 0;
780  virtual void visit( const QgsSQLStatement::NodeColumnSorted &n ) = 0;
782  virtual void visit( const QgsSQLStatement::NodeCast &n ) = 0;
783  };
784 
788  class CORE_EXPORT RecursiveVisitor: public QgsSQLStatement::Visitor
789  {
790  public:
792  RecursiveVisitor() = default;
793 
794  void visit( const QgsSQLStatement::NodeUnaryOperator &n ) override { n.operand()->accept( *this ); }
795  void visit( const QgsSQLStatement::NodeBinaryOperator &n ) override { n.opLeft()->accept( *this ); n.opRight()->accept( *this ); }
796  void visit( const QgsSQLStatement::NodeInOperator &n ) override { n.node()->accept( *this ); n.list()->accept( *this ); }
797  void visit( const QgsSQLStatement::NodeBetweenOperator &n ) override { n.node()->accept( *this ); n.minVal()->accept( *this ); n.maxVal()->accept( *this ); }
798  void visit( const QgsSQLStatement::NodeFunction &n ) override { n.args()->accept( *this ); }
799  void visit( const QgsSQLStatement::NodeLiteral & ) override {}
800  void visit( const QgsSQLStatement::NodeColumnRef & ) override { }
801  void visit( const QgsSQLStatement::NodeSelectedColumn &n ) override { n.column()->accept( *this ); }
802  void visit( const QgsSQLStatement::NodeTableDef & ) override {}
803  void visit( const QgsSQLStatement::NodeSelect &n ) override;
804  void visit( const QgsSQLStatement::NodeJoin &n ) override;
805  void visit( const QgsSQLStatement::NodeColumnSorted &n ) override { n.column()->accept( *this ); }
806  void visit( const QgsSQLStatement::NodeCast &n ) override { n.node()->accept( *this ); }
807  };
808 
810  void acceptVisitor( QgsSQLStatement::Visitor &v ) const;
811 
812  protected:
813  QgsSQLStatement::Node *mRootNode = nullptr;
814  QString mStatement;
816 };
817 
819 
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
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.