QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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
35class CORE_EXPORT QgsSQLStatement
36{
37 Q_DECLARE_TR_FUNCTIONS( QgsSQLStatement )
38 public:
39
43 QgsSQLStatement( const QString &statement );
44
48 QgsSQLStatement( const QgsSQLStatement &other );
49
53 QgsSQLStatement &operator=( const QgsSQLStatement &other );
54 virtual ~QgsSQLStatement();
55
57 bool hasParserError() const;
59 QString parserErrorString() const;
60
66 bool doBasicValidationChecks( QString &errorMsgOut SIP_OUT ) const;
67
68 class Node;
69
74 const QgsSQLStatement::Node *rootNode() const;
75
81 QString statement() const;
82
89 QString dump() const;
90
95 static QString quotedIdentifier( QString name );
96
102 static QString quotedIdentifierIfNeeded( const QString &name );
103
108 static QString stripQuotedIdentifier( QString text );
109
114 static QString stripMsQuotedIdentifier( QString text );
115
120 static QString quotedString( QString text );
121
127 {
130 };
131
137 {
138 // logical
141
142 // comparison
143 boEQ, // =
144 boNE, // <>
145 boLE, // <=
146 boGE, // >=
147 boLT, // <
148 boGT, // >
155
156 // math
164
165 // strings
167 };
168
174 {
182 jtFull
183 };
184
186 static const char *BINARY_OPERATOR_TEXT[] SIP_SKIP;
187
189 static const char *UNARY_OPERATOR_TEXT[] SIP_SKIP;
190
192 static const char *JOIN_TYPE_TEXT[] SIP_SKIP;
193
195
196 class Visitor; // visitor interface is defined below
197
200 {
213 ntCast
214 };
215
220 class CORE_EXPORT Node
221 {
222
223#ifdef SIP_RUN
225 switch ( sipCpp->nodeType() )
226 {
227 case QgsSQLStatement::ntUnaryOperator: sipType = sipType_QgsSQLStatement_NodeUnaryOperator; break;
228 case QgsSQLStatement::ntBinaryOperator: sipType = sipType_QgsSQLStatement_NodeBinaryOperator; break;
229 case QgsSQLStatement::ntInOperator: sipType = sipType_QgsSQLStatement_NodeInOperator; break;
230 case QgsSQLStatement::ntBetweenOperator: sipType = sipType_QgsSQLStatement_NodeBetweenOperator; break;
231 case QgsSQLStatement::ntFunction: sipType = sipType_QgsSQLStatement_NodeFunction; break;
232 case QgsSQLStatement::ntLiteral: sipType = sipType_QgsSQLStatement_NodeLiteral; break;
233 case QgsSQLStatement::ntColumnRef: sipType = sipType_QgsSQLStatement_NodeColumnRef; break;
234 case QgsSQLStatement::ntSelectedColumn: sipType = sipType_QgsSQLStatement_NodeSelectedColumn; break;
235 case QgsSQLStatement::ntSelect: sipType = sipType_QgsSQLStatement_NodeSelect; break;
236 case QgsSQLStatement::ntTableDef: sipType = sipType_QgsSQLStatement_NodeTableDef; break;
237 case QgsSQLStatement::ntJoin: sipType = sipType_QgsSQLStatement_NodeJoin; break;
238 case QgsSQLStatement::ntColumnSorted: sipType = sipType_QgsSQLStatement_NodeColumnSorted; break;
239 case QgsSQLStatement::ntCast: sipType = sipType_QgsSQLStatement_NodeCast; break;
240 default: sipType = 0; break;
241 }
242 SIP_END
243#endif
244
245 public:
246 virtual ~Node() = default;
247
254
260 virtual QString dump() const = 0;
261
271
287 virtual void accept( QgsSQLStatement::Visitor &v ) const = 0;
288 };
289
294 class CORE_EXPORT NodeList
295 {
296 public:
298 NodeList() = default;
299 virtual ~NodeList() { qDeleteAll( mList ); }
300
302 void append( QgsSQLStatement::Node *node SIP_TRANSFER ) { mList.append( node ); }
303
305 QList<QgsSQLStatement::Node *> list() { return mList; }
306
310 int count() const { return mList.count(); }
311
313 void accept( QgsSQLStatement::Visitor &v ) const;
314
317
319 virtual QString dump() const;
320
321 protected:
322 QList<Node *> mList;
323 };
324
329 class CORE_EXPORT NodeUnaryOperator : public QgsSQLStatement::Node
330 {
331 public:
333 NodeUnaryOperator( QgsSQLStatement::UnaryOperator op, QgsSQLStatement::Node *operand SIP_TRANSFER ) : mOp( op ), mOperand( operand ) {}
334 ~NodeUnaryOperator() override { delete mOperand; }
335
337 QgsSQLStatement::UnaryOperator op() const { return mOp; }
338
340 QgsSQLStatement::Node *operand() const { return mOperand; }
341
342 QgsSQLStatement::NodeType nodeType() const override { return ntUnaryOperator; }
343 QString dump() const override;
344
345 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
346 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
347
348 protected:
350 Node *mOperand = nullptr;
351 };
352
357 class CORE_EXPORT NodeBinaryOperator : public QgsSQLStatement::Node
358 {
359 public:
362 : mOp( op )
363 , mOpLeft( opLeft )
364 , mOpRight( opRight )
365 {}
366 ~NodeBinaryOperator() override { delete mOpLeft; delete mOpRight; }
367
369 QgsSQLStatement::BinaryOperator op() const { return mOp; }
370
372 QgsSQLStatement::Node *opLeft() const { return mOpLeft; }
373
375 QgsSQLStatement::Node *opRight() const { return mOpRight; }
376
377 QgsSQLStatement::NodeType nodeType() const override { return ntBinaryOperator; }
378 QString dump() const override;
379
380 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
381 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
382
384 int precedence() const;
385
387 bool leftAssociative() const;
388
389 protected:
390
392 Node *mOpLeft = nullptr;
393 Node *mOpRight = nullptr;
394 };
395
400 class CORE_EXPORT NodeInOperator : public QgsSQLStatement::Node
401 {
402 public:
404 NodeInOperator( QgsSQLStatement::Node *node SIP_TRANSFER, QgsSQLStatement::NodeList *list SIP_TRANSFER, bool notin = false ) : mNode( node ), mList( list ), mNotIn( notin ) {}
405 ~NodeInOperator() override { delete mNode; delete mList; }
406
408 QgsSQLStatement::Node *node() const { return mNode; }
409
411 bool isNotIn() const { return mNotIn; }
412
414 QgsSQLStatement::NodeList *list() const { return mList; }
415
416 QgsSQLStatement::NodeType nodeType() const override { return ntInOperator; }
417 QString dump() const override;
418
419 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
420 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
421
422 protected:
423 Node *mNode = nullptr;
424 NodeList *mList = nullptr;
425 bool mNotIn;
426 };
427
432 class CORE_EXPORT NodeBetweenOperator : public QgsSQLStatement::Node
433 {
434 public:
437 : mNode( node ), mMinVal( minVal ), mMaxVal( maxVal ), mNotBetween( notBetween ) {}
438 ~NodeBetweenOperator() override { delete mNode; delete mMinVal; delete mMaxVal; }
439
441 QgsSQLStatement::Node *node() const { return mNode; }
442
444 bool isNotBetween() const { return mNotBetween; }
445
447 QgsSQLStatement::Node *minVal() const { return mMinVal; }
448
450 QgsSQLStatement::Node *maxVal() const { return mMaxVal; }
451
452 QgsSQLStatement::NodeType nodeType() const override { return ntBetweenOperator; }
453 QString dump() const override;
454
455 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
456 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
457
458 protected:
459 Node *mNode = nullptr;
460 Node *mMinVal = nullptr;
461 Node *mMaxVal = nullptr;
462 bool mNotBetween;
463 };
464
469 class CORE_EXPORT NodeFunction : public QgsSQLStatement::Node
470 {
471 public:
473 NodeFunction( const QString &name, QgsSQLStatement::NodeList *args SIP_TRANSFER ) : mName( name ), mArgs( args ) {}
474 ~NodeFunction() override { delete mArgs; }
475
477 QString name() const { return mName; }
478
480 QgsSQLStatement::NodeList *args() const { return mArgs; }
481
482 QgsSQLStatement::NodeType nodeType() const override { return ntFunction; }
483 QString dump() const override;
484
485 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
486 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
487
488 protected:
489 QString mName;
490 NodeList *mArgs = nullptr;
491
492 };
493
498 class CORE_EXPORT NodeLiteral : public QgsSQLStatement::Node
499 {
500 public:
502 NodeLiteral( const QVariant &value ) : mValue( value ) {}
503
505 inline QVariant value() const { return mValue; }
506
507 QgsSQLStatement::NodeType nodeType() const override { return ntLiteral; }
508 QString dump() const override;
509
510 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
511 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
512
513 protected:
514 QVariant mValue;
515 };
516
521 class CORE_EXPORT NodeColumnRef : public QgsSQLStatement::Node
522 {
523 public:
525 NodeColumnRef( const QString &name, bool star ) : mName( name ), mDistinct( false ), mStar( star ) {}
527 NodeColumnRef( const QString &tableName, const QString &name, bool star ) : mTableName( tableName ), mName( name ), mDistinct( false ), mStar( star ) {}
528
530 void setDistinct( bool distinct = true ) { mDistinct = distinct; }
531
533 QString tableName() const { return mTableName; }
534
536 QString name() const { return mName; }
537
539 bool star() const { return mStar; }
540
542 bool distinct() const { return mDistinct; }
543
544 QgsSQLStatement::NodeType nodeType() const override { return ntColumnRef; }
545 QString dump() const override;
546
547 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
548 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
550 QgsSQLStatement::NodeColumnRef *cloneThis() const SIP_FACTORY;
551
552 protected:
553 QString mTableName;
554 QString mName;
555 bool mDistinct;
556 bool mStar;
557 };
558
563 class CORE_EXPORT NodeSelectedColumn : public QgsSQLStatement::Node
564 {
565 public:
567 NodeSelectedColumn( QgsSQLStatement::Node *node SIP_TRANSFER ) : mColumnNode( node ) {}
568 ~NodeSelectedColumn() override { delete mColumnNode; }
569
571 void setAlias( const QString &alias ) { mAlias = alias; }
572
574 QgsSQLStatement::Node *column() const { return mColumnNode; }
575
577 QString alias() const { return mAlias; }
578
579 QgsSQLStatement::NodeType nodeType() const override { return ntSelectedColumn; }
580 QString dump() const override;
581
582 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
583 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
586
587 protected:
588 Node *mColumnNode = nullptr;
589 QString mAlias;
590 };
591
596 class CORE_EXPORT NodeCast : public QgsSQLStatement::Node
597 {
598 public:
600 NodeCast( QgsSQLStatement::Node *node SIP_TRANSFER, const QString &type ) : mNode( node ), mType( type ) {}
601 ~NodeCast() override { delete mNode; }
602
604 QgsSQLStatement::Node *node() const { return mNode; }
605
607 QString type() const { return mType; }
608
609 QgsSQLStatement::NodeType nodeType() const override { return ntCast; }
610 QString dump() const override;
611
612 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
613 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
614
615 protected:
616 Node *mNode = nullptr;
617 QString mType;
618 };
619
624 class CORE_EXPORT NodeTableDef : public QgsSQLStatement::Node
625 {
626 public:
628 NodeTableDef( const QString &name ) : mName( name ) {}
630 NodeTableDef( const QString &name, const QString &alias ) : mName( name ), mAlias( alias ) {}
631
636 NodeTableDef( const QString &schema, const QString &name, const QString &alias ) : mName( name ), mSchema( schema ), mAlias( alias ) {}
637
639 QString name() const { return mName; }
640
646 QString schema() const { return mSchema; }
647
649 QString alias() const { return mAlias; }
650
651 QgsSQLStatement::NodeType nodeType() const override { return ntTableDef; }
652 QString dump() const override;
653
654 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
655 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
657 QgsSQLStatement::NodeTableDef *cloneThis() const SIP_FACTORY;
658
659 protected:
660 QString mName;
661 QString mSchema;
662 QString mAlias;
663 };
664
669 class CORE_EXPORT NodeJoin : public QgsSQLStatement::Node
670 {
671 public:
673 NodeJoin( QgsSQLStatement::NodeTableDef *tabledef SIP_TRANSFER, QgsSQLStatement::Node *onExpr SIP_TRANSFER, QgsSQLStatement::JoinType type ) : mTableDef( tabledef ), mOnExpr( onExpr ), mType( type ) {}
675 NodeJoin( QgsSQLStatement::NodeTableDef *tabledef SIP_TRANSFER, const QList<QString> &usingColumns, QgsSQLStatement::JoinType type ) : mTableDef( tabledef ), mUsingColumns( usingColumns ), mType( type ) {}
676 ~NodeJoin() override { delete mTableDef; delete mOnExpr; }
677
679 QgsSQLStatement::NodeTableDef *tableDef() const { return mTableDef; }
680
682 QgsSQLStatement::Node *onExpr() const { return mOnExpr; }
683
685 QList<QString> usingColumns() const { return mUsingColumns; }
686
688 QgsSQLStatement::JoinType type() const { return mType; }
689
690 QgsSQLStatement::NodeType nodeType() const override { return ntJoin; }
691 QString dump() const override;
692
693 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
694 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
696 QgsSQLStatement::NodeJoin *cloneThis() const SIP_FACTORY;
697
698 protected:
699 NodeTableDef *mTableDef = nullptr;
700 Node *mOnExpr = nullptr;
701 QList<QString> mUsingColumns;
702 JoinType mType;
703 };
704
709 class CORE_EXPORT NodeColumnSorted : public QgsSQLStatement::Node
710 {
711 public:
713 NodeColumnSorted( QgsSQLStatement::NodeColumnRef *column SIP_TRANSFER, bool asc ) : mColumn( column ), mAsc( asc ) {}
714 ~NodeColumnSorted() override { delete mColumn; }
715
717 QgsSQLStatement::NodeColumnRef *column() const { return mColumn; }
718
720 bool ascending() const { return mAsc; }
721
722 QgsSQLStatement::NodeType nodeType() const override { return ntColumnSorted; }
723 QString dump() const override;
724
725 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
726 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
728 QgsSQLStatement::NodeColumnSorted *cloneThis() const SIP_FACTORY;
729
730 protected:
731 NodeColumnRef *mColumn = nullptr;
732 bool mAsc;
733 };
734
739 class CORE_EXPORT NodeSelect : public QgsSQLStatement::Node
740 {
741 public:
743 NodeSelect( const QList<QgsSQLStatement::NodeTableDef *> &tableList SIP_TRANSFER, const QList<QgsSQLStatement::NodeSelectedColumn *> &columns SIP_TRANSFER, bool distinct ) : mTableList( tableList ), mColumns( columns ), mDistinct( distinct ) {}
744 ~NodeSelect() override;
745
747 void setJoins( const QList<QgsSQLStatement::NodeJoin *> &joins SIP_TRANSFER ) { qDeleteAll( mJoins ); mJoins = joins; }
749 void appendJoin( QgsSQLStatement::NodeJoin *join SIP_TRANSFER ) { mJoins.append( join ); }
751 void setWhere( QgsSQLStatement::Node *where SIP_TRANSFER ) { delete mWhere; mWhere = where; }
753 void setOrderBy( const QList<QgsSQLStatement::NodeColumnSorted *> &orderBy SIP_TRANSFER ) { qDeleteAll( mOrderBy ); mOrderBy = orderBy; }
754
756 QList<QgsSQLStatement::NodeTableDef *> tables() const { return mTableList; }
758 QList<QgsSQLStatement::NodeSelectedColumn *> columns() const { return mColumns; }
760 bool distinct() const { return mDistinct; }
762 QList<QgsSQLStatement::NodeJoin *> joins() const { return mJoins; }
764 QgsSQLStatement::Node *where() const { return mWhere; }
766 QList<QgsSQLStatement::NodeColumnSorted *> orderBy() const { return mOrderBy; }
767
768 QgsSQLStatement::NodeType nodeType() const override { return ntSelect; }
769 QString dump() const override;
770
771 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
772 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
773
774 protected:
775 QList<NodeTableDef *> mTableList;
776 QList<NodeSelectedColumn *> mColumns;
777 bool mDistinct;
778 QList<NodeJoin *> mJoins;
779 Node *mWhere = nullptr;
780 QList<NodeColumnSorted *> mOrderBy;
781 };
782
784
790 class CORE_EXPORT Visitor
791 {
792 public:
793 virtual ~Visitor() = default;
795 virtual void visit( const QgsSQLStatement::NodeUnaryOperator &n ) = 0;
797 virtual void visit( const QgsSQLStatement::NodeBinaryOperator &n ) = 0;
799 virtual void visit( const QgsSQLStatement::NodeInOperator &n ) = 0;
801 virtual void visit( const QgsSQLStatement::NodeBetweenOperator &n ) = 0;
803 virtual void visit( const QgsSQLStatement::NodeFunction &n ) = 0;
805 virtual void visit( const QgsSQLStatement::NodeLiteral &n ) = 0;
807 virtual void visit( const QgsSQLStatement::NodeColumnRef &n ) = 0;
809 virtual void visit( const QgsSQLStatement::NodeSelectedColumn &n ) = 0;
811 virtual void visit( const QgsSQLStatement::NodeTableDef &n ) = 0;
813 virtual void visit( const QgsSQLStatement::NodeSelect &n ) = 0;
815 virtual void visit( const QgsSQLStatement::NodeJoin &n ) = 0;
817 virtual void visit( const QgsSQLStatement::NodeColumnSorted &n ) = 0;
819 virtual void visit( const QgsSQLStatement::NodeCast &n ) = 0;
820 };
821
827 {
828 public:
830 RecursiveVisitor() = default;
831
832 void visit( const QgsSQLStatement::NodeUnaryOperator &n ) override { n.operand()->accept( *this ); }
833 void visit( const QgsSQLStatement::NodeBinaryOperator &n ) override { n.opLeft()->accept( *this ); n.opRight()->accept( *this ); }
834 void visit( const QgsSQLStatement::NodeInOperator &n ) override { n.node()->accept( *this ); n.list()->accept( *this ); }
835 void visit( const QgsSQLStatement::NodeBetweenOperator &n ) override { n.node()->accept( *this ); n.minVal()->accept( *this ); n.maxVal()->accept( *this ); }
836 void visit( const QgsSQLStatement::NodeFunction &n ) override { n.args()->accept( *this ); }
837 void visit( const QgsSQLStatement::NodeLiteral & ) override {}
838 void visit( const QgsSQLStatement::NodeColumnRef & ) override { }
839 void visit( const QgsSQLStatement::NodeSelectedColumn &n ) override { n.column()->accept( *this ); }
840 void visit( const QgsSQLStatement::NodeTableDef & ) override {}
841 void visit( const QgsSQLStatement::NodeSelect &n ) override;
842 void visit( const QgsSQLStatement::NodeJoin &n ) override;
843 void visit( const QgsSQLStatement::NodeColumnSorted &n ) override { n.column()->accept( *this ); }
844 void visit( const QgsSQLStatement::NodeCast &n ) override { n.node()->accept( *this ); }
845 };
846
848 void acceptVisitor( QgsSQLStatement::Visitor &v ) const;
849
850 protected:
851 QgsSQLStatement::Node *mRootNode = nullptr;
852 bool mAllowFragments = false;
853 QString mStatement;
855
864 QgsSQLStatement( const QString &statement, bool allowFragments );
865};
866
868
869
874class CORE_EXPORT QgsSQLStatementFragment : public QgsSQLStatement
875{
876 public:
877
881 QgsSQLStatementFragment( const QString &fragment );
882
883};
884
885
886#endif // QGSSQLSTATEMENT_H
Class for parsing fragments of SQL statements, such as an expression or where clause.
'X BETWEEN y and z' operator
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QgsSQLStatement::Node * node() const
Variable at the left of BETWEEN.
QgsSQLStatement::Node * minVal() const
Minimum bound.
bool isNotBetween() const
Whether this is a NOT BETWEEN operator.
QgsSQLStatement::Node * maxVal() const
Maximum bound.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
NodeBetweenOperator(QgsSQLStatement::Node *node, QgsSQLStatement::Node *minVal, QgsSQLStatement::Node *maxVal, bool notBetween=false)
Constructor.
Binary logical/arithmetical operator (AND, OR, =, +, ...)
QgsSQLStatement::Node * opLeft() const
Left operand.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
NodeBinaryOperator(QgsSQLStatement::BinaryOperator op, QgsSQLStatement::Node *opLeft, QgsSQLStatement::Node *opRight)
Constructor.
QgsSQLStatement::BinaryOperator op() const
Operator.
QgsSQLStatement::Node * opRight() const
Right operand.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QgsSQLStatement::Node * node() const
Node that is referred to.
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.
NodeCast(QgsSQLStatement::Node *node, const QString &type)
Constructor.
QString type() const
Type.
Reference to a column.
QString name() const
The name of the column.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
NodeColumnRef(const QString &name, bool star)
Constructor with column name only.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
bool star() const
Whether this is the * column.
NodeColumnRef(const QString &tableName, const QString &name, bool star)
Constructor with table and column name.
QString tableName() const
The name of the table. May be empty.
void setDistinct(bool distinct=true)
Sets whether this is prefixed by DISTINCT.
bool distinct() const
Whether this is prefixed by DISTINCT.
bool ascending() const
Whether the column is sorted in ascending order.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QgsSQLStatement::NodeColumnRef * column() const
The name of the column.
NodeColumnSorted(QgsSQLStatement::NodeColumnRef *column, bool asc)
Constructor.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
Function with a name and arguments node.
NodeFunction(const QString &name, QgsSQLStatement::NodeList *args)
Constructor.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QgsSQLStatement::NodeList * args() const
Returns arguments.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QString name() const
Returns function name.
bool isNotIn() const
Whether this is a NOT IN operator.
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.
QgsSQLStatement::Node * node() const
Variable at the left of IN.
NodeInOperator(QgsSQLStatement::Node *node, QgsSQLStatement::NodeList *list, bool notin=false)
Constructor.
QgsSQLStatement::NodeList * list() const
Values list.
QgsSQLStatement::NodeTableDef * tableDef() const
Table definition.
QgsSQLStatement::Node * onExpr() const
On expression. Will be nullptr if usingColumns() is not empty.
NodeJoin(QgsSQLStatement::NodeTableDef *tabledef, QgsSQLStatement::Node *onExpr, QgsSQLStatement::JoinType type)
Constructor with table definition, ON expression.
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.
NodeJoin(QgsSQLStatement::NodeTableDef *tabledef, const QList< QString > &usingColumns, QgsSQLStatement::JoinType type)
Constructor with table definition and USING columns.
QList< QString > usingColumns() const
Columns referenced by USING.
QgsSQLStatement::JoinType type() const
Join type.
NodeList()=default
Constructor.
void accept(QgsSQLStatement::Visitor &v) const
Accept visitor.
QList< QgsSQLStatement::Node * > list()
Returns list.
int count() const
Returns the number of nodes in the list.
void append(QgsSQLStatement::Node *node)
Takes ownership of the provided node.
Literal value (integer, integer64, double, string)
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.
NodeLiteral(const QVariant &value)
Constructor.
QVariant value() const
The value of the literal.
NodeSelect(const QList< QgsSQLStatement::NodeTableDef * > &tableList, const QList< QgsSQLStatement::NodeSelectedColumn * > &columns, bool distinct)
Constructor.
QList< QgsSQLStatement::NodeColumnSorted * > orderBy() const
Returns the list of order by columns.
void setJoins(const QList< QgsSQLStatement::NodeJoin * > &joins)
Sets joins.
void setWhere(QgsSQLStatement::Node *where)
Sets where clause.
QList< QgsSQLStatement::NodeSelectedColumn * > columns() const
Returns the list of columns.
bool distinct() const
Returns if the SELECT is DISTINCT.
void appendJoin(QgsSQLStatement::NodeJoin *join)
Append a join.
void setOrderBy(const QList< QgsSQLStatement::NodeColumnSorted * > &orderBy)
Sets order by columns.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QList< QgsSQLStatement::NodeJoin * > joins() const
Returns the list of joins.
QgsSQLStatement::Node * where() const
Returns the where clause.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QList< QgsSQLStatement::NodeTableDef * > tables() const
Returns the list of tables.
NodeSelectedColumn(QgsSQLStatement::Node *node)
Constructor.
void setAlias(const QString &alias)
Sets alias name.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QgsSQLStatement::Node * column() const
Column that is referred to.
QString alias() const
Alias name.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QString name() const
Table name.
NodeTableDef(const QString &schema, const QString &name, const QString &alias)
Constructor with schema, table name and alias.
NodeTableDef(const QString &name)
Constructor with table name.
NodeTableDef(const QString &name, const QString &alias)
Constructor with table name and alias.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QString alias() const
Table alias.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QString schema() const
Returns the schema name.
Unary logicial/arithmetical operator ( NOT, - )
NodeUnaryOperator(QgsSQLStatement::UnaryOperator op, QgsSQLStatement::Node *operand)
Constructor.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QgsSQLStatement::UnaryOperator op() const
Operator.
QgsSQLStatement::Node * operand() const
Operand.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
Abstract node class.
virtual QgsSQLStatement::Node * clone() const =0
Generate a clone of this node.
virtual QString dump() const =0
Abstract virtual dump method.
virtual ~Node()=default
virtual QgsSQLStatement::NodeType nodeType() const =0
Abstract virtual that returns the type of this node.
virtual void accept(QgsSQLStatement::Visitor &v) const =0
Support the visitor pattern.
A visitor that recursively explores all children.
void visit(const QgsSQLStatement::NodeFunction &n) override
Visit NodeFunction.
void visit(const QgsSQLStatement::NodeSelectedColumn &n) override
Visit NodeSelectedColumn.
void visit(const QgsSQLStatement::NodeUnaryOperator &n) override
Visit NodeUnaryOperator.
void visit(const QgsSQLStatement::NodeLiteral &) override
Visit NodeLiteral.
RecursiveVisitor()=default
Constructor.
void visit(const QgsSQLStatement::NodeBetweenOperator &n) override
Visit NodeBetweenOperator.
void visit(const QgsSQLStatement::NodeBinaryOperator &n) override
Visit NodeBinaryOperator.
void visit(const QgsSQLStatement::NodeColumnRef &) override
Visit NodeColumnRef.
void visit(const QgsSQLStatement::NodeTableDef &) override
Visit NodeTableDef.
void visit(const QgsSQLStatement::NodeColumnSorted &n) override
Visit NodeColumnSorted.
void visit(const QgsSQLStatement::NodeInOperator &n) override
Visit NodeInOperator.
void visit(const QgsSQLStatement::NodeCast &n) override
Visit NodeCast.
Support for visitor pattern - algorithms dealing with the statement may be implemented without modify...
virtual void visit(const QgsSQLStatement::NodeBetweenOperator &n)=0
Visit NodeBetweenOperator.
virtual ~Visitor()=default
virtual void visit(const QgsSQLStatement::NodeFunction &n)=0
Visit NodeFunction.
virtual void visit(const QgsSQLStatement::NodeColumnRef &n)=0
Visit NodeColumnRef.
virtual void visit(const QgsSQLStatement::NodeBinaryOperator &n)=0
Visit NodeBinaryOperator.
virtual void visit(const QgsSQLStatement::NodeSelect &n)=0
Visit NodeSelect.
virtual void visit(const QgsSQLStatement::NodeCast &n)=0
Visit NodeCast.
virtual void visit(const QgsSQLStatement::NodeSelectedColumn &n)=0
Visit NodeSelectedColumn.
virtual void visit(const QgsSQLStatement::NodeJoin &n)=0
Visit NodeJoin.
virtual void visit(const QgsSQLStatement::NodeUnaryOperator &n)=0
Visit NodeUnaryOperator.
virtual void visit(const QgsSQLStatement::NodeInOperator &n)=0
Visit NodeInOperator.
virtual void visit(const QgsSQLStatement::NodeLiteral &n)=0
Visit NodeLiteral.
virtual void visit(const QgsSQLStatement::NodeColumnSorted &n)=0
Visit NodeColumnSorted.
virtual void visit(const QgsSQLStatement::NodeTableDef &n)=0
Visit NodeTableDef.
Class for parsing SQL statements.
JoinType
list of join types
BinaryOperator
list of binary operators
QString mParserErrorString
UnaryOperator
list of unary operators
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_END
Definition: qgis_sip.h:203
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)