QGIS API Documentation 3.43.0-Master (80be09f213e)
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 <memory>
21
22#include <QCoreApplication>
23#include "qgis_sip.h"
24#include <QMetaType>
25#include <QStringList>
26#include <QVariant>
27#include <QList>
28#include <QSet>
29
30#include "qgis_core.h"
31
36class CORE_EXPORT QgsSQLStatement
37{
38 Q_DECLARE_TR_FUNCTIONS( QgsSQLStatement )
39 public:
40
44 QgsSQLStatement( const QString &statement );
45
46 QgsSQLStatement( const QgsSQLStatement &other );
47
48 QgsSQLStatement &operator=( const QgsSQLStatement &other );
49 virtual ~QgsSQLStatement();
50
52 bool hasParserError() const;
54 QString parserErrorString() const;
55
61 bool doBasicValidationChecks( QString &errorMsgOut SIP_OUT ) const;
62
63 class Node;
64
69 const QgsSQLStatement::Node *rootNode() const;
70
76 QString statement() const;
77
84 QString dump() const;
85
91 static QString quotedIdentifier( QString name );
92
99 static QString quotedIdentifierIfNeeded( const QString &name );
100
105 static QString stripQuotedIdentifier( QString text );
106
111 static QString stripMsQuotedIdentifier( QString text );
112
118 static QString quotedString( QString text );
119
129
135 {
136 // logical
139
140 // comparison
141 boEQ, // =
142 boNE, // <>
143 boLE, // <=
144 boGE, // >=
145 boLT, // <
146 boGT, // >
153
154 // math
162
163 // strings
165 };
166
182
184 static const char *BINARY_OPERATOR_TEXT[] SIP_SKIP;
185
187 static const char *UNARY_OPERATOR_TEXT[] SIP_SKIP;
188
190 static const char *JOIN_TYPE_TEXT[] SIP_SKIP;
191
193
194 class Visitor; // visitor interface is defined below
195
213
218 class CORE_EXPORT Node
219 {
220
221#ifdef SIP_RUN
223 switch ( sipCpp->nodeType() )
224 {
225 case QgsSQLStatement::ntUnaryOperator: sipType = sipType_QgsSQLStatement_NodeUnaryOperator; break;
226 case QgsSQLStatement::ntBinaryOperator: sipType = sipType_QgsSQLStatement_NodeBinaryOperator; break;
227 case QgsSQLStatement::ntInOperator: sipType = sipType_QgsSQLStatement_NodeInOperator; break;
228 case QgsSQLStatement::ntBetweenOperator: sipType = sipType_QgsSQLStatement_NodeBetweenOperator; break;
229 case QgsSQLStatement::ntFunction: sipType = sipType_QgsSQLStatement_NodeFunction; break;
230 case QgsSQLStatement::ntLiteral: sipType = sipType_QgsSQLStatement_NodeLiteral; break;
231 case QgsSQLStatement::ntColumnRef: sipType = sipType_QgsSQLStatement_NodeColumnRef; break;
232 case QgsSQLStatement::ntSelectedColumn: sipType = sipType_QgsSQLStatement_NodeSelectedColumn; break;
233 case QgsSQLStatement::ntSelect: sipType = sipType_QgsSQLStatement_NodeSelect; break;
234 case QgsSQLStatement::ntTableDef: sipType = sipType_QgsSQLStatement_NodeTableDef; break;
235 case QgsSQLStatement::ntJoin: sipType = sipType_QgsSQLStatement_NodeJoin; break;
236 case QgsSQLStatement::ntColumnSorted: sipType = sipType_QgsSQLStatement_NodeColumnSorted; break;
237 case QgsSQLStatement::ntCast: sipType = sipType_QgsSQLStatement_NodeCast; break;
238 default: sipType = 0; break;
239 }
240 SIP_END
241#endif
242
243 public:
244 virtual ~Node() = default;
245
252
258 virtual QString dump() const = 0;
259
269
285 virtual void accept( QgsSQLStatement::Visitor &v ) const = 0;
286 };
287
292 class CORE_EXPORT NodeList
293 {
294 public:
295
296 NodeList() = default;
297 virtual ~NodeList() { qDeleteAll( mList ); }
298
300 void append( QgsSQLStatement::Node *node SIP_TRANSFER ) { mList.append( node ); }
301
303 QList<QgsSQLStatement::Node *> list() { return mList; }
304
308 int count() const { return mList.count(); }
309
311 void accept( QgsSQLStatement::Visitor &v ) const;
312
315
317 virtual QString dump() const;
318
319 protected:
320 QList<Node *> mList;
321 };
322
327 class CORE_EXPORT NodeUnaryOperator : public QgsSQLStatement::Node
328 {
329 public:
331 NodeUnaryOperator( QgsSQLStatement::UnaryOperator op, QgsSQLStatement::Node *operand SIP_TRANSFER ) : mOp( op ), mOperand( operand ) {}
332
334 QgsSQLStatement::UnaryOperator op() const { return mOp; }
335
337 QgsSQLStatement::Node *operand() const { return mOperand.get(); }
338
339 QgsSQLStatement::NodeType nodeType() const override { return ntUnaryOperator; }
340 QString dump() const override;
341
342 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
343 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
344
345 private:
346
347 NodeUnaryOperator( const NodeUnaryOperator &other ) = delete;
348 NodeUnaryOperator &operator=( const NodeUnaryOperator &other ) = delete;
349
350#ifdef SIP_RUN
351 NodeUnaryOperator( const NodeUnaryOperator &other );
352#endif
353
354 protected:
356 std::unique_ptr<Node> mOperand;
357 };
358
363 class CORE_EXPORT NodeBinaryOperator : public QgsSQLStatement::Node
364 {
365 public:
368 : mOp( op )
369 , mOpLeft( opLeft )
370 , mOpRight( opRight )
371 {}
372
374 QgsSQLStatement::BinaryOperator op() const { return mOp; }
375
377 QgsSQLStatement::Node *opLeft() const { return mOpLeft.get(); }
378
380 QgsSQLStatement::Node *opRight() const { return mOpRight.get(); }
381
382 QgsSQLStatement::NodeType nodeType() const override { return ntBinaryOperator; }
383 QString dump() const override;
384
385 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
386 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
387
389 int precedence() const;
390
392 bool leftAssociative() const;
393
394 private:
395
396 NodeBinaryOperator( const NodeBinaryOperator &other ) = delete;
397 NodeBinaryOperator &operator=( const NodeBinaryOperator &other ) = delete;
398
399#ifdef SIP_RUN
401#endif
402
403 protected:
404
406 std::unique_ptr<Node> mOpLeft;
407 std::unique_ptr<Node> mOpRight;
408 };
409
414 class CORE_EXPORT NodeInOperator : public QgsSQLStatement::Node
415 {
416 public:
418 NodeInOperator( QgsSQLStatement::Node *node SIP_TRANSFER, QgsSQLStatement::NodeList *list SIP_TRANSFER, bool notin = false ) : mNode( node ), mList( list ), mNotIn( notin ) {}
419
421 QgsSQLStatement::Node *node() const { return mNode.get(); }
422
424 bool isNotIn() const { return mNotIn; }
425
427 QgsSQLStatement::NodeList *list() const { return mList.get(); }
428
429 QgsSQLStatement::NodeType nodeType() const override { return ntInOperator; }
430 QString dump() const override;
431
432 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
433 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
434
435 private:
436
437 NodeInOperator( const NodeInOperator &other ) = delete;
438 NodeInOperator &operator=( const NodeInOperator &other ) = delete;
439
440#ifdef SIP_RUN
441 NodeInOperator( const NodeInOperator &other );
442#endif
443
444 protected:
445 std::unique_ptr<Node> mNode;
446 std::unique_ptr<NodeList> mList;
447 bool mNotIn;
448 };
449
455 {
456 public:
459 : mNode( node ), mMinVal( minVal ), mMaxVal( maxVal ), mNotBetween( notBetween ) {}
460
462 QgsSQLStatement::Node *node() const { return mNode.get(); }
463
465 bool isNotBetween() const { return mNotBetween; }
466
468 QgsSQLStatement::Node *minVal() const { return mMinVal.get(); }
469
471 QgsSQLStatement::Node *maxVal() const { return mMaxVal.get(); }
472
473 QgsSQLStatement::NodeType nodeType() const override { return ntBetweenOperator; }
474 QString dump() const override;
475
476 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
477 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
478
479 private:
480
481 NodeBetweenOperator( const NodeBetweenOperator &other ) = delete;
482 NodeBetweenOperator &operator=( const NodeBetweenOperator &other ) = delete;
483
484#ifdef SIP_RUN
486#endif
487
488 protected:
489 std::unique_ptr<Node> mNode;
490 std::unique_ptr<Node> mMinVal;
491 std::unique_ptr<Node> mMaxVal;
493 };
494
499 class CORE_EXPORT NodeFunction : public QgsSQLStatement::Node
500 {
501 public:
503 NodeFunction( const QString &name, QgsSQLStatement::NodeList *args SIP_TRANSFER ) : mName( name ), mArgs( args ) {}
504
506 QString name() const { return mName; }
507
509 QgsSQLStatement::NodeList *args() const { return mArgs.get(); }
510
511 QgsSQLStatement::NodeType nodeType() const override { return ntFunction; }
512 QString dump() const override;
513
514 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
515 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
516
517 private:
518
519 NodeFunction( const NodeFunction &other ) = delete;
520 NodeFunction &operator=( const NodeFunction &other ) = delete;
521
522#ifdef SIP_RUN
523 NodeFunction( const NodeFunction &other );
524#endif
525
526 protected:
527 QString mName;
528 std::unique_ptr<NodeList> mArgs;
529
530 };
531
536 class CORE_EXPORT NodeLiteral : public QgsSQLStatement::Node
537 {
538 public:
540 NodeLiteral( const QVariant &value ) : mValue( value ) {}
541
543 inline QVariant value() const { return mValue; }
544
545 QgsSQLStatement::NodeType nodeType() const override { return ntLiteral; }
546 QString dump() const override;
547
548 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
549 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
550
551 protected:
552 QVariant mValue;
553 };
554
559 class CORE_EXPORT NodeColumnRef : public QgsSQLStatement::Node
560 {
561 public:
563 NodeColumnRef( const QString &name, bool star ) : mName( name ), mDistinct( false ), mStar( star ) {}
565 NodeColumnRef( const QString &tableName, const QString &name, bool star ) : mTableName( tableName ), mName( name ), mDistinct( false ), mStar( star ) {}
566
568 void setDistinct( bool distinct = true ) { mDistinct = distinct; }
569
571 QString tableName() const { return mTableName; }
572
574 QString name() const { return mName; }
575
577 bool star() const { return mStar; }
578
580 bool distinct() const { return mDistinct; }
581
582 QgsSQLStatement::NodeType nodeType() const override { return ntColumnRef; }
583 QString dump() const override;
584
585 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
586 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
588 QgsSQLStatement::NodeColumnRef *cloneThis() const SIP_FACTORY;
589
590 protected:
591 QString mTableName;
592 QString mName;
593 bool mDistinct;
594 bool mStar;
595 };
596
601 class CORE_EXPORT NodeSelectedColumn : public QgsSQLStatement::Node
602 {
603 public:
605 NodeSelectedColumn( QgsSQLStatement::Node *node SIP_TRANSFER ) : mColumnNode( node ) {}
606
608 void setAlias( const QString &alias ) { mAlias = alias; }
609
611 QgsSQLStatement::Node *column() const { return mColumnNode.get(); }
612
614 QString alias() const { return mAlias; }
615
616 QgsSQLStatement::NodeType nodeType() const override { return ntSelectedColumn; }
617 QString dump() const override;
618
619 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
620 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
623
624 private:
625
626 NodeSelectedColumn( const NodeSelectedColumn &other ) = delete;
627 NodeSelectedColumn &operator=( const NodeSelectedColumn &other ) = delete;
628
629#ifdef SIP_RUN
631#endif
632
633 protected:
634 std::unique_ptr<Node> mColumnNode;
635 QString mAlias;
636 };
637
642 class CORE_EXPORT NodeCast : public QgsSQLStatement::Node
643 {
644 public:
646 NodeCast( QgsSQLStatement::Node *node SIP_TRANSFER, const QString &type ) : mNode( node ), mType( type ) {}
647
649 QgsSQLStatement::Node *node() const { return mNode.get(); }
650
652 QString type() const { return mType; }
653
654 QgsSQLStatement::NodeType nodeType() const override { return ntCast; }
655 QString dump() const override;
656
657 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
658 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
659
660 private:
661
662 NodeCast( const NodeCast &other ) = delete;
663 NodeCast &operator=( const NodeCast &other ) = delete;
664
665#ifdef SIP_RUN
666 NodeCast( const NodeCast &other );
667#endif
668
669 protected:
670 std::unique_ptr<Node> mNode;
671 QString mType;
672 };
673
678 class CORE_EXPORT NodeTableDef : public QgsSQLStatement::Node
679 {
680 public:
682 NodeTableDef( const QString &name ) : mName( name ) {}
684 NodeTableDef( const QString &name, const QString &alias ) : mName( name ), mAlias( alias ) {}
685
690 NodeTableDef( const QString &schema, const QString &name, const QString &alias ) : mName( name ), mSchema( schema ), mAlias( alias ) {}
691
693 QString name() const { return mName; }
694
700 QString schema() const { return mSchema; }
701
703 QString alias() const { return mAlias; }
704
705 QgsSQLStatement::NodeType nodeType() const override { return ntTableDef; }
706 QString dump() const override;
707
708 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
709 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
711 QgsSQLStatement::NodeTableDef *cloneThis() const SIP_FACTORY;
712
713 protected:
714 QString mName;
715 QString mSchema;
716 QString mAlias;
717 };
718
723 class CORE_EXPORT NodeJoin : public QgsSQLStatement::Node
724 {
725 public:
727 NodeJoin( QgsSQLStatement::NodeTableDef *tabledef SIP_TRANSFER, QgsSQLStatement::Node *onExpr SIP_TRANSFER, QgsSQLStatement::JoinType type ) : mTableDef( tabledef ), mOnExpr( onExpr ), mType( type ) {}
729 NodeJoin( QgsSQLStatement::NodeTableDef *tabledef SIP_TRANSFER, const QList<QString> &usingColumns, QgsSQLStatement::JoinType type ) : mTableDef( tabledef ), mUsingColumns( usingColumns ), mType( type ) {}
730
732 QgsSQLStatement::NodeTableDef *tableDef() const { return mTableDef.get(); }
733
735 QgsSQLStatement::Node *onExpr() const { return mOnExpr.get(); }
736
738 QList<QString> usingColumns() const { return mUsingColumns; }
739
741 QgsSQLStatement::JoinType type() const { return mType; }
742
743 QgsSQLStatement::NodeType nodeType() const override { return ntJoin; }
744 QString dump() const override;
745
746 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
747 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
749 QgsSQLStatement::NodeJoin *cloneThis() const SIP_FACTORY;
750
751 private:
752
753 NodeJoin( const NodeJoin &other ) = delete;
754 NodeJoin &operator=( const NodeJoin &other ) = delete;
755
756#ifdef SIP_RUN
757 NodeJoin( const NodeJoin &other );
758#endif
759
760 protected:
761 std::unique_ptr<NodeTableDef> mTableDef;
762 std::unique_ptr<Node> mOnExpr;
763 QList<QString> mUsingColumns;
765 };
766
771 class CORE_EXPORT NodeColumnSorted : public QgsSQLStatement::Node
772 {
773 public:
775 NodeColumnSorted( QgsSQLStatement::NodeColumnRef *column SIP_TRANSFER, bool asc ) : mColumn( column ), mAsc( asc ) {}
776
778 QgsSQLStatement::NodeColumnRef *column() const { return mColumn.get(); }
779
781 bool ascending() const { return mAsc; }
782
783 QgsSQLStatement::NodeType nodeType() const override { return ntColumnSorted; }
784 QString dump() const override;
785
786 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
787 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
789 QgsSQLStatement::NodeColumnSorted *cloneThis() const SIP_FACTORY;
790
791 private:
792
793 NodeColumnSorted( const NodeColumnSorted &other ) = delete;
794 NodeColumnSorted &operator=( const NodeColumnSorted &other ) = delete;
795
796#ifdef SIP_RUN
797 NodeColumnSorted( const NodeColumnSorted &other );
798#endif
799
800 protected:
801 std::unique_ptr<NodeColumnRef> mColumn;
802 bool mAsc;
803 };
804
809 class CORE_EXPORT NodeSelect : public QgsSQLStatement::Node
810 {
811 public:
813 NodeSelect( const QList<QgsSQLStatement::NodeTableDef *> &tableList SIP_TRANSFER, const QList<QgsSQLStatement::NodeSelectedColumn *> &columns SIP_TRANSFER, bool distinct ) : mTableList( tableList ), mColumns( columns ), mDistinct( distinct ) {}
814 ~NodeSelect() override;
815
817 void setJoins( const QList<QgsSQLStatement::NodeJoin *> &joins SIP_TRANSFER ) { qDeleteAll( mJoins ); mJoins = joins; }
819 void appendJoin( QgsSQLStatement::NodeJoin *join SIP_TRANSFER ) { mJoins.append( join ); }
821 void setWhere( QgsSQLStatement::Node *where SIP_TRANSFER ) { mWhere.reset( where ); }
823 void setOrderBy( const QList<QgsSQLStatement::NodeColumnSorted *> &orderBy SIP_TRANSFER ) { qDeleteAll( mOrderBy ); mOrderBy = orderBy; }
824
826 QList<QgsSQLStatement::NodeTableDef *> tables() const { return mTableList; }
828 QList<QgsSQLStatement::NodeSelectedColumn *> columns() const { return mColumns; }
830 bool distinct() const { return mDistinct; }
832 QList<QgsSQLStatement::NodeJoin *> joins() const { return mJoins; }
834 QgsSQLStatement::Node *where() const { return mWhere.get(); }
836 QList<QgsSQLStatement::NodeColumnSorted *> orderBy() const { return mOrderBy; }
837
838 QgsSQLStatement::NodeType nodeType() const override { return ntSelect; }
839 QString dump() const override;
840
841 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
842 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
843
844 private:
845
846 NodeSelect( const NodeSelect &other ) = delete;
847 NodeSelect &operator=( const NodeSelect &other ) = delete;
848
849#ifdef SIP_RUN
850 NodeSelect( const NodeSelect &other );
851#endif
852
853 protected:
854 QList<NodeTableDef *> mTableList;
855 QList<NodeSelectedColumn *> mColumns;
857 QList<NodeJoin *> mJoins;
858 std::unique_ptr<Node> mWhere;
859 QList<NodeColumnSorted *> mOrderBy;
860 };
861
863
869 class CORE_EXPORT Visitor
870 {
871 public:
872 virtual ~Visitor() = default;
874 virtual void visit( const QgsSQLStatement::NodeUnaryOperator &n ) = 0;
876 virtual void visit( const QgsSQLStatement::NodeBinaryOperator &n ) = 0;
878 virtual void visit( const QgsSQLStatement::NodeInOperator &n ) = 0;
880 virtual void visit( const QgsSQLStatement::NodeBetweenOperator &n ) = 0;
882 virtual void visit( const QgsSQLStatement::NodeFunction &n ) = 0;
884 virtual void visit( const QgsSQLStatement::NodeLiteral &n ) = 0;
886 virtual void visit( const QgsSQLStatement::NodeColumnRef &n ) = 0;
888 virtual void visit( const QgsSQLStatement::NodeSelectedColumn &n ) = 0;
890 virtual void visit( const QgsSQLStatement::NodeTableDef &n ) = 0;
892 virtual void visit( const QgsSQLStatement::NodeSelect &n ) = 0;
894 virtual void visit( const QgsSQLStatement::NodeJoin &n ) = 0;
896 virtual void visit( const QgsSQLStatement::NodeColumnSorted &n ) = 0;
898 virtual void visit( const QgsSQLStatement::NodeCast &n ) = 0;
899 };
900
906 {
907 public:
908
909 RecursiveVisitor() = default;
910
911 void visit( const QgsSQLStatement::NodeUnaryOperator &n ) override { n.operand()->accept( *this ); }
912 void visit( const QgsSQLStatement::NodeBinaryOperator &n ) override { n.opLeft()->accept( *this ); n.opRight()->accept( *this ); }
913 void visit( const QgsSQLStatement::NodeInOperator &n ) override { n.node()->accept( *this ); n.list()->accept( *this ); }
914 void visit( const QgsSQLStatement::NodeBetweenOperator &n ) override { n.node()->accept( *this ); n.minVal()->accept( *this ); n.maxVal()->accept( *this ); }
915 void visit( const QgsSQLStatement::NodeFunction &n ) override { n.args()->accept( *this ); }
916 void visit( const QgsSQLStatement::NodeLiteral & ) override {}
917 void visit( const QgsSQLStatement::NodeColumnRef & ) override { }
918 void visit( const QgsSQLStatement::NodeSelectedColumn &n ) override { n.column()->accept( *this ); }
919 void visit( const QgsSQLStatement::NodeTableDef & ) override {}
920 void visit( const QgsSQLStatement::NodeSelect &n ) override;
921 void visit( const QgsSQLStatement::NodeJoin &n ) override;
922 void visit( const QgsSQLStatement::NodeColumnSorted &n ) override { n.column()->accept( *this ); }
923 void visit( const QgsSQLStatement::NodeCast &n ) override { n.node()->accept( *this ); }
924 };
925
927 void acceptVisitor( QgsSQLStatement::Visitor &v ) const;
928
929 protected:
930 std::unique_ptr<QgsSQLStatement::Node> mRootNode;
931 bool mAllowFragments = false;
932 QString mStatement;
934
943 QgsSQLStatement( const QString &statement, bool allowFragments );
944};
945
947
948
953class CORE_EXPORT QgsSQLStatementFragment : public QgsSQLStatement
954{
955 public:
956
960 QgsSQLStatementFragment( const QString &fragment );
961
962};
963
964
965#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)