QGIS API Documentation 3.43.0-Master (69d1901085b)
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
34class CORE_EXPORT QgsSQLStatement
35{
36 Q_DECLARE_TR_FUNCTIONS( QgsSQLStatement )
37 public:
38
42 QgsSQLStatement( const QString &statement );
43
44 QgsSQLStatement( const QgsSQLStatement &other );
45
46 QgsSQLStatement &operator=( const QgsSQLStatement &other );
47 virtual ~QgsSQLStatement();
50 bool hasParserError() const;
52 QString parserErrorString() const;
53
59 bool doBasicValidationChecks( QString &errorMsgOut SIP_OUT ) const;
60
61 class Node;
62
67 const QgsSQLStatement::Node *rootNode() const;
68
74 QString statement() const;
75
82 QString dump() const;
83
89 static QString quotedIdentifier( QString name );
90
97 static QString quotedIdentifierIfNeeded( const QString &name );
98
103 static QString stripQuotedIdentifier( QString text );
104
109 static QString stripMsQuotedIdentifier( QString text );
110
116 static QString quotedString( QString text );
117
127
133 {
134 // logical
137
138 // comparison
139 boEQ, // =
140 boNE, // <>
141 boLE, // <=
142 boGE, // >=
143 boLT, // <
144 boGT, // >
151
152 // math
160
161 // strings
163 };
164
180
182 static const char *BINARY_OPERATOR_TEXT[] SIP_SKIP;
183
185 static const char *UNARY_OPERATOR_TEXT[] SIP_SKIP;
186
188 static const char *JOIN_TYPE_TEXT[] SIP_SKIP;
189
191
192 class Visitor; // visitor interface is defined below
193
211
216 class CORE_EXPORT Node
217 {
218
219#ifdef SIP_RUN
221 switch ( sipCpp->nodeType() )
222 {
223 case QgsSQLStatement::ntUnaryOperator: sipType = sipType_QgsSQLStatement_NodeUnaryOperator; break;
224 case QgsSQLStatement::ntBinaryOperator: sipType = sipType_QgsSQLStatement_NodeBinaryOperator; break;
225 case QgsSQLStatement::ntInOperator: sipType = sipType_QgsSQLStatement_NodeInOperator; break;
226 case QgsSQLStatement::ntBetweenOperator: sipType = sipType_QgsSQLStatement_NodeBetweenOperator; break;
227 case QgsSQLStatement::ntFunction: sipType = sipType_QgsSQLStatement_NodeFunction; break;
228 case QgsSQLStatement::ntLiteral: sipType = sipType_QgsSQLStatement_NodeLiteral; break;
229 case QgsSQLStatement::ntColumnRef: sipType = sipType_QgsSQLStatement_NodeColumnRef; break;
230 case QgsSQLStatement::ntSelectedColumn: sipType = sipType_QgsSQLStatement_NodeSelectedColumn; break;
231 case QgsSQLStatement::ntSelect: sipType = sipType_QgsSQLStatement_NodeSelect; break;
232 case QgsSQLStatement::ntTableDef: sipType = sipType_QgsSQLStatement_NodeTableDef; break;
233 case QgsSQLStatement::ntJoin: sipType = sipType_QgsSQLStatement_NodeJoin; break;
234 case QgsSQLStatement::ntColumnSorted: sipType = sipType_QgsSQLStatement_NodeColumnSorted; break;
235 case QgsSQLStatement::ntCast: sipType = sipType_QgsSQLStatement_NodeCast; break;
236 default: sipType = 0; break;
237 }
238 SIP_END
239#endif
240
241 public:
242 virtual ~Node() = default;
243
250
256 virtual QString dump() const = 0;
257
267
283 virtual void accept( QgsSQLStatement::Visitor &v ) const = 0;
284 };
285
290 class CORE_EXPORT NodeList
291 {
292 public:
293
294 NodeList() = default;
295 virtual ~NodeList() { qDeleteAll( mList ); }
296
298 void append( QgsSQLStatement::Node *node SIP_TRANSFER ) { mList.append( node ); }
299
301 QList<QgsSQLStatement::Node *> list() { return mList; }
302
306 int count() const { return mList.count(); }
307
309 void accept( QgsSQLStatement::Visitor &v ) const;
310
313
315 virtual QString dump() const;
316
317 protected:
318 QList<Node *> mList;
319 };
320
325 class CORE_EXPORT NodeUnaryOperator : public QgsSQLStatement::Node
326 {
327 public:
329 NodeUnaryOperator( QgsSQLStatement::UnaryOperator op, QgsSQLStatement::Node *operand SIP_TRANSFER ) : mOp( op ), mOperand( operand ) {}
330
332 QgsSQLStatement::UnaryOperator op() const { return mOp; }
333
335 QgsSQLStatement::Node *operand() const { return mOperand.get(); }
336
337 QgsSQLStatement::NodeType nodeType() const override { return ntUnaryOperator; }
338 QString dump() const override;
339
340 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
341 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
342
343 private:
344
345 NodeUnaryOperator( const NodeUnaryOperator &other ) = delete;
346 NodeUnaryOperator &operator=( const NodeUnaryOperator &other ) = delete;
347
348#ifdef SIP_RUN
349 NodeUnaryOperator( const NodeUnaryOperator &other );
350#endif
351
352 protected:
354 std::unique_ptr<Node> mOperand;
355 };
356
361 class CORE_EXPORT NodeBinaryOperator : public QgsSQLStatement::Node
362 {
363 public:
366 : mOp( op )
367 , mOpLeft( opLeft )
368 , mOpRight( opRight )
369 {}
370
372 QgsSQLStatement::BinaryOperator op() const { return mOp; }
373
375 QgsSQLStatement::Node *opLeft() const { return mOpLeft.get(); }
376
378 QgsSQLStatement::Node *opRight() const { return mOpRight.get(); }
379
380 QgsSQLStatement::NodeType nodeType() const override { return ntBinaryOperator; }
381 QString dump() const override;
382
383 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
384 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
385
387 int precedence() const;
388
390 bool leftAssociative() const;
391
392 private:
393
394 NodeBinaryOperator( const NodeBinaryOperator &other ) = delete;
395 NodeBinaryOperator &operator=( const NodeBinaryOperator &other ) = delete;
396
397#ifdef SIP_RUN
399#endif
400
401 protected:
402
404 std::unique_ptr<Node> mOpLeft;
405 std::unique_ptr<Node> mOpRight;
406 };
407
412 class CORE_EXPORT NodeInOperator : public QgsSQLStatement::Node
413 {
414 public:
416 NodeInOperator( QgsSQLStatement::Node *node SIP_TRANSFER, QgsSQLStatement::NodeList *list SIP_TRANSFER, bool notin = false ) : mNode( node ), mList( list ), mNotIn( notin ) {}
417
419 QgsSQLStatement::Node *node() const { return mNode.get(); }
420
422 bool isNotIn() const { return mNotIn; }
423
425 QgsSQLStatement::NodeList *list() const { return mList.get(); }
426
427 QgsSQLStatement::NodeType nodeType() const override { return ntInOperator; }
428 QString dump() const override;
429
430 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
431 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
432
433 private:
434
435 NodeInOperator( const NodeInOperator &other ) = delete;
436 NodeInOperator &operator=( const NodeInOperator &other ) = delete;
437
438#ifdef SIP_RUN
439 NodeInOperator( const NodeInOperator &other );
440#endif
441
442 protected:
443 std::unique_ptr<Node> mNode;
444 std::unique_ptr<NodeList> mList;
445 bool mNotIn;
446 };
447
453 {
454 public:
457 : mNode( node ), mMinVal( minVal ), mMaxVal( maxVal ), mNotBetween( notBetween ) {}
458
460 QgsSQLStatement::Node *node() const { return mNode.get(); }
461
463 bool isNotBetween() const { return mNotBetween; }
464
466 QgsSQLStatement::Node *minVal() const { return mMinVal.get(); }
467
469 QgsSQLStatement::Node *maxVal() const { return mMaxVal.get(); }
470
471 QgsSQLStatement::NodeType nodeType() const override { return ntBetweenOperator; }
472 QString dump() const override;
473
474 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
475 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
476
477 private:
478
479 NodeBetweenOperator( const NodeBetweenOperator &other ) = delete;
480 NodeBetweenOperator &operator=( const NodeBetweenOperator &other ) = delete;
481
482#ifdef SIP_RUN
484#endif
485
486 protected:
487 std::unique_ptr<Node> mNode;
488 std::unique_ptr<Node> mMinVal;
489 std::unique_ptr<Node> mMaxVal;
491 };
492
497 class CORE_EXPORT NodeFunction : public QgsSQLStatement::Node
498 {
499 public:
501 NodeFunction( const QString &name, QgsSQLStatement::NodeList *args SIP_TRANSFER ) : mName( name ), mArgs( args ) {}
502
504 QString name() const { return mName; }
505
507 QgsSQLStatement::NodeList *args() const { return mArgs.get(); }
508
509 QgsSQLStatement::NodeType nodeType() const override { return ntFunction; }
510 QString dump() const override;
511
512 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
513 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
514
515 private:
516
517 NodeFunction( const NodeFunction &other ) = delete;
518 NodeFunction &operator=( const NodeFunction &other ) = delete;
519
520#ifdef SIP_RUN
521 NodeFunction( const NodeFunction &other );
522#endif
523
524 protected:
525 QString mName;
526 std::unique_ptr<NodeList> mArgs;
527
528 };
529
534 class CORE_EXPORT NodeLiteral : public QgsSQLStatement::Node
535 {
536 public:
538 NodeLiteral( const QVariant &value ) : mValue( value ) {}
539
541 inline QVariant value() const { return mValue; }
542
543 QgsSQLStatement::NodeType nodeType() const override { return ntLiteral; }
544 QString dump() const override;
545
546 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
547 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
548
549 protected:
550 QVariant mValue;
551 };
552
557 class CORE_EXPORT NodeColumnRef : public QgsSQLStatement::Node
558 {
559 public:
561 NodeColumnRef( const QString &name, bool star ) : mName( name ), mDistinct( false ), mStar( star ) {}
563 NodeColumnRef( const QString &tableName, const QString &name, bool star ) : mTableName( tableName ), mName( name ), mDistinct( false ), mStar( star ) {}
564
566 void setDistinct( bool distinct = true ) { mDistinct = distinct; }
567
569 QString tableName() const { return mTableName; }
570
572 QString name() const { return mName; }
573
575 bool star() const { return mStar; }
576
578 bool distinct() const { return mDistinct; }
579
580 QgsSQLStatement::NodeType nodeType() const override { return ntColumnRef; }
581 QString dump() const override;
582
583 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
584 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
586 QgsSQLStatement::NodeColumnRef *cloneThis() const SIP_FACTORY;
587
588 protected:
589 QString mTableName;
590 QString mName;
591 bool mDistinct;
592 bool mStar;
593 };
594
599 class CORE_EXPORT NodeSelectedColumn : public QgsSQLStatement::Node
600 {
601 public:
603 NodeSelectedColumn( QgsSQLStatement::Node *node SIP_TRANSFER ) : mColumnNode( node ) {}
604
606 void setAlias( const QString &alias ) { mAlias = alias; }
607
609 QgsSQLStatement::Node *column() const { return mColumnNode.get(); }
610
612 QString alias() const { return mAlias; }
613
614 QgsSQLStatement::NodeType nodeType() const override { return ntSelectedColumn; }
615 QString dump() const override;
616
617 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
618 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
621
622 private:
623
624 NodeSelectedColumn( const NodeSelectedColumn &other ) = delete;
625 NodeSelectedColumn &operator=( const NodeSelectedColumn &other ) = delete;
626
627#ifdef SIP_RUN
629#endif
630
631 protected:
632 std::unique_ptr<Node> mColumnNode;
633 QString mAlias;
634 };
635
640 class CORE_EXPORT NodeCast : public QgsSQLStatement::Node
641 {
642 public:
644 NodeCast( QgsSQLStatement::Node *node SIP_TRANSFER, const QString &type ) : mNode( node ), mType( type ) {}
645
647 QgsSQLStatement::Node *node() const { return mNode.get(); }
648
650 QString type() const { return mType; }
651
652 QgsSQLStatement::NodeType nodeType() const override { return ntCast; }
653 QString dump() const override;
654
655 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
656 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
657
658 private:
659
660 NodeCast( const NodeCast &other ) = delete;
661 NodeCast &operator=( const NodeCast &other ) = delete;
662
663#ifdef SIP_RUN
664 NodeCast( const NodeCast &other );
665#endif
666
667 protected:
668 std::unique_ptr<Node> mNode;
669 QString mType;
670 };
671
676 class CORE_EXPORT NodeTableDef : public QgsSQLStatement::Node
677 {
678 public:
680 NodeTableDef( const QString &name ) : mName( name ) {}
682 NodeTableDef( const QString &name, const QString &alias ) : mName( name ), mAlias( alias ) {}
683
688 NodeTableDef( const QString &schema, const QString &name, const QString &alias ) : mName( name ), mSchema( schema ), mAlias( alias ) {}
689
691 QString name() const { return mName; }
692
698 QString schema() const { return mSchema; }
699
701 QString alias() const { return mAlias; }
702
703 QgsSQLStatement::NodeType nodeType() const override { return ntTableDef; }
704 QString dump() const override;
705
706 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
707 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
709 QgsSQLStatement::NodeTableDef *cloneThis() const SIP_FACTORY;
710
711 protected:
712 QString mName;
713 QString mSchema;
714 QString mAlias;
715 };
716
721 class CORE_EXPORT NodeJoin : public QgsSQLStatement::Node
722 {
723 public:
725 NodeJoin( QgsSQLStatement::NodeTableDef *tabledef SIP_TRANSFER, QgsSQLStatement::Node *onExpr SIP_TRANSFER, QgsSQLStatement::JoinType type ) : mTableDef( tabledef ), mOnExpr( onExpr ), mType( type ) {}
727 NodeJoin( QgsSQLStatement::NodeTableDef *tabledef SIP_TRANSFER, const QList<QString> &usingColumns, QgsSQLStatement::JoinType type ) : mTableDef( tabledef ), mUsingColumns( usingColumns ), mType( type ) {}
728
730 QgsSQLStatement::NodeTableDef *tableDef() const { return mTableDef.get(); }
731
733 QgsSQLStatement::Node *onExpr() const { return mOnExpr.get(); }
734
736 QList<QString> usingColumns() const { return mUsingColumns; }
737
739 QgsSQLStatement::JoinType type() const { return mType; }
740
741 QgsSQLStatement::NodeType nodeType() const override { return ntJoin; }
742 QString dump() const override;
743
744 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
745 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
747 QgsSQLStatement::NodeJoin *cloneThis() const SIP_FACTORY;
748
749 private:
750
751 NodeJoin( const NodeJoin &other ) = delete;
752 NodeJoin &operator=( const NodeJoin &other ) = delete;
753
754#ifdef SIP_RUN
755 NodeJoin( const NodeJoin &other );
756#endif
757
758 protected:
759 std::unique_ptr<NodeTableDef> mTableDef;
760 std::unique_ptr<Node> mOnExpr;
761 QList<QString> mUsingColumns;
763 };
764
769 class CORE_EXPORT NodeColumnSorted : public QgsSQLStatement::Node
770 {
771 public:
773 NodeColumnSorted( QgsSQLStatement::NodeColumnRef *column SIP_TRANSFER, bool asc ) : mColumn( column ), mAsc( asc ) {}
774
776 QgsSQLStatement::NodeColumnRef *column() const { return mColumn.get(); }
777
779 bool ascending() const { return mAsc; }
780
781 QgsSQLStatement::NodeType nodeType() const override { return ntColumnSorted; }
782 QString dump() const override;
783
784 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
785 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
787 QgsSQLStatement::NodeColumnSorted *cloneThis() const SIP_FACTORY;
788
789 private:
790
791 NodeColumnSorted( const NodeColumnSorted &other ) = delete;
792 NodeColumnSorted &operator=( const NodeColumnSorted &other ) = delete;
793
794#ifdef SIP_RUN
795 NodeColumnSorted( const NodeColumnSorted &other );
796#endif
797
798 protected:
799 std::unique_ptr<NodeColumnRef> mColumn;
800 bool mAsc;
801 };
802
807 class CORE_EXPORT NodeSelect : public QgsSQLStatement::Node
808 {
809 public:
811 NodeSelect( const QList<QgsSQLStatement::NodeTableDef *> &tableList SIP_TRANSFER, const QList<QgsSQLStatement::NodeSelectedColumn *> &columns SIP_TRANSFER, bool distinct ) : mTableList( tableList ), mColumns( columns ), mDistinct( distinct ) {}
812 ~NodeSelect() override;
813
815 void setJoins( const QList<QgsSQLStatement::NodeJoin *> &joins SIP_TRANSFER ) { qDeleteAll( mJoins ); mJoins = joins; }
817 void appendJoin( QgsSQLStatement::NodeJoin *join SIP_TRANSFER ) { mJoins.append( join ); }
819 void setWhere( QgsSQLStatement::Node *where SIP_TRANSFER ) { mWhere.reset( where ); }
821 void setOrderBy( const QList<QgsSQLStatement::NodeColumnSorted *> &orderBy SIP_TRANSFER ) { qDeleteAll( mOrderBy ); mOrderBy = orderBy; }
822
824 QList<QgsSQLStatement::NodeTableDef *> tables() const { return mTableList; }
826 QList<QgsSQLStatement::NodeSelectedColumn *> columns() const { return mColumns; }
828 bool distinct() const { return mDistinct; }
830 QList<QgsSQLStatement::NodeJoin *> joins() const { return mJoins; }
832 QgsSQLStatement::Node *where() const { return mWhere.get(); }
834 QList<QgsSQLStatement::NodeColumnSorted *> orderBy() const { return mOrderBy; }
835
836 QgsSQLStatement::NodeType nodeType() const override { return ntSelect; }
837 QString dump() const override;
838
839 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
840 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
841
842 private:
843
844 NodeSelect( const NodeSelect &other ) = delete;
845 NodeSelect &operator=( const NodeSelect &other ) = delete;
846
847#ifdef SIP_RUN
848 NodeSelect( const NodeSelect &other );
849#endif
850
851 protected:
852 QList<NodeTableDef *> mTableList;
853 QList<NodeSelectedColumn *> mColumns;
855 QList<NodeJoin *> mJoins;
856 std::unique_ptr<Node> mWhere;
857 QList<NodeColumnSorted *> mOrderBy;
858 };
859
861
867 class CORE_EXPORT Visitor
868 {
869 public:
870 virtual ~Visitor() = default;
872 virtual void visit( const QgsSQLStatement::NodeUnaryOperator &n ) = 0;
874 virtual void visit( const QgsSQLStatement::NodeBinaryOperator &n ) = 0;
876 virtual void visit( const QgsSQLStatement::NodeInOperator &n ) = 0;
878 virtual void visit( const QgsSQLStatement::NodeBetweenOperator &n ) = 0;
880 virtual void visit( const QgsSQLStatement::NodeFunction &n ) = 0;
882 virtual void visit( const QgsSQLStatement::NodeLiteral &n ) = 0;
884 virtual void visit( const QgsSQLStatement::NodeColumnRef &n ) = 0;
886 virtual void visit( const QgsSQLStatement::NodeSelectedColumn &n ) = 0;
888 virtual void visit( const QgsSQLStatement::NodeTableDef &n ) = 0;
890 virtual void visit( const QgsSQLStatement::NodeSelect &n ) = 0;
892 virtual void visit( const QgsSQLStatement::NodeJoin &n ) = 0;
894 virtual void visit( const QgsSQLStatement::NodeColumnSorted &n ) = 0;
896 virtual void visit( const QgsSQLStatement::NodeCast &n ) = 0;
897 };
898
904 {
905 public:
906
907 RecursiveVisitor() = default;
908
909 void visit( const QgsSQLStatement::NodeUnaryOperator &n ) override { n.operand()->accept( *this ); }
910 void visit( const QgsSQLStatement::NodeBinaryOperator &n ) override { n.opLeft()->accept( *this ); n.opRight()->accept( *this ); }
911 void visit( const QgsSQLStatement::NodeInOperator &n ) override { n.node()->accept( *this ); n.list()->accept( *this ); }
912 void visit( const QgsSQLStatement::NodeBetweenOperator &n ) override { n.node()->accept( *this ); n.minVal()->accept( *this ); n.maxVal()->accept( *this ); }
913 void visit( const QgsSQLStatement::NodeFunction &n ) override { n.args()->accept( *this ); }
914 void visit( const QgsSQLStatement::NodeLiteral & ) override {}
915 void visit( const QgsSQLStatement::NodeColumnRef & ) override { }
916 void visit( const QgsSQLStatement::NodeSelectedColumn &n ) override { n.column()->accept( *this ); }
917 void visit( const QgsSQLStatement::NodeTableDef & ) override {}
918 void visit( const QgsSQLStatement::NodeSelect &n ) override;
919 void visit( const QgsSQLStatement::NodeJoin &n ) override;
920 void visit( const QgsSQLStatement::NodeColumnSorted &n ) override { n.column()->accept( *this ); }
921 void visit( const QgsSQLStatement::NodeCast &n ) override { n.node()->accept( *this ); }
922 };
923
925 void acceptVisitor( QgsSQLStatement::Visitor &v ) const;
926
927 protected:
928 std::unique_ptr<QgsSQLStatement::Node> mRootNode;
929 bool mAllowFragments = false;
930 QString mStatement;
932
941 QgsSQLStatement( const QString &statement, bool allowFragments );
942};
943
945
946
951class CORE_EXPORT QgsSQLStatementFragment : public QgsSQLStatement
952{
953 public:
954
958 QgsSQLStatementFragment( const QString &fragment );
959
960};
961
962
963#endif // QGSSQLSTATEMENT_H
Parses fragments of SQL statements, such as an expression or where clause.
An '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.
std::unique_ptr< Node > mNode
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.
std::unique_ptr< NodeColumnRef > mColumn
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.
std::unique_ptr< NodeList > mArgs
QgsSQLStatement::NodeList * args() const
Returns arguments.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QString name() const
Returns function name.
An 'x IN (y, z)' operator.
std::unique_ptr< NodeList > mList
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.
std::unique_ptr< Node > mNode
NodeInOperator(QgsSQLStatement::Node *node, QgsSQLStatement::NodeList *list, bool notin=false)
Constructor.
QgsSQLStatement::NodeList * list() const
Values list.
QList< QString > mUsingColumns
QgsSQLStatement::NodeTableDef * tableDef() const
Table definition.
std::unique_ptr< Node > mOnExpr
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.
std::unique_ptr< NodeTableDef > mTableDef
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.
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< NodeColumnSorted * > mOrderBy
QList< QgsSQLStatement::NodeSelectedColumn * > columns() const
Returns the list of columns.
bool distinct() const
Returns if the SELECT is DISTINCT.
QList< NodeSelectedColumn * > mColumns
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.
std::unique_ptr< Node > mWhere
QList< QgsSQLStatement::NodeJoin * > joins() const
Returns the list of joins.
QList< NodeTableDef * > mTableList
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.
std::unique_ptr< Node > mColumnNode
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 logical/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 for SQL statement nodes.
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.
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.
Parses SQL statements.
JoinType
list of join types
BinaryOperator
list of binary operators
std::unique_ptr< QgsSQLStatement::Node > mRootNode
UnaryOperator
list of unary operators
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#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:208
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)