QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
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 ~NodeUnaryOperator() override { delete mOperand; }
331
333 QgsSQLStatement::UnaryOperator op() const { return mOp; }
334
336 QgsSQLStatement::Node *operand() const { return mOperand; }
337
338 QgsSQLStatement::NodeType nodeType() const override { return ntUnaryOperator; }
339 QString dump() const override;
340
341 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
342 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
343
344 protected:
346 Node *mOperand = nullptr;
347 };
348
353 class CORE_EXPORT NodeBinaryOperator : public QgsSQLStatement::Node
354 {
355 public:
358 : mOp( op )
359 , mOpLeft( opLeft )
360 , mOpRight( opRight )
361 {}
362 ~NodeBinaryOperator() override { delete mOpLeft; delete mOpRight; }
363
365 QgsSQLStatement::BinaryOperator op() const { return mOp; }
366
368 QgsSQLStatement::Node *opLeft() const { return mOpLeft; }
369
371 QgsSQLStatement::Node *opRight() const { return mOpRight; }
372
373 QgsSQLStatement::NodeType nodeType() const override { return ntBinaryOperator; }
374 QString dump() const override;
375
376 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
377 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
378
380 int precedence() const;
381
383 bool leftAssociative() const;
384
385 protected:
386
388 Node *mOpLeft = nullptr;
389 Node *mOpRight = nullptr;
390 };
391
396 class CORE_EXPORT NodeInOperator : public QgsSQLStatement::Node
397 {
398 public:
400 NodeInOperator( QgsSQLStatement::Node *node SIP_TRANSFER, QgsSQLStatement::NodeList *list SIP_TRANSFER, bool notin = false ) : mNode( node ), mList( list ), mNotIn( notin ) {}
401 ~NodeInOperator() override { delete mNode; delete mList; }
402
404 QgsSQLStatement::Node *node() const { return mNode; }
405
407 bool isNotIn() const { return mNotIn; }
408
410 QgsSQLStatement::NodeList *list() const { return mList; }
411
412 QgsSQLStatement::NodeType nodeType() const override { return ntInOperator; }
413 QString dump() const override;
414
415 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
416 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
417
418 protected:
419 Node *mNode = nullptr;
420 NodeList *mList = nullptr;
421 bool mNotIn;
422 };
423
428 class CORE_EXPORT NodeBetweenOperator : public QgsSQLStatement::Node
429 {
430 public:
433 : mNode( node ), mMinVal( minVal ), mMaxVal( maxVal ), mNotBetween( notBetween ) {}
434 ~NodeBetweenOperator() override { delete mNode; delete mMinVal; delete mMaxVal; }
435
437 QgsSQLStatement::Node *node() const { return mNode; }
438
440 bool isNotBetween() const { return mNotBetween; }
441
443 QgsSQLStatement::Node *minVal() const { return mMinVal; }
444
446 QgsSQLStatement::Node *maxVal() const { return mMaxVal; }
447
448 QgsSQLStatement::NodeType nodeType() const override { return ntBetweenOperator; }
449 QString dump() const override;
450
451 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
452 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
453
454 protected:
455 Node *mNode = nullptr;
456 Node *mMinVal = nullptr;
457 Node *mMaxVal = nullptr;
458 bool mNotBetween;
459 };
460
465 class CORE_EXPORT NodeFunction : public QgsSQLStatement::Node
466 {
467 public:
469 NodeFunction( const QString &name, QgsSQLStatement::NodeList *args SIP_TRANSFER ) : mName( name ), mArgs( args ) {}
470 ~NodeFunction() override { delete mArgs; }
471
473 QString name() const { return mName; }
474
476 QgsSQLStatement::NodeList *args() const { return mArgs; }
477
478 QgsSQLStatement::NodeType nodeType() const override { return ntFunction; }
479 QString dump() const override;
480
481 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
482 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
483
484 protected:
485 QString mName;
486 NodeList *mArgs = nullptr;
487
488 };
489
494 class CORE_EXPORT NodeLiteral : public QgsSQLStatement::Node
495 {
496 public:
498 NodeLiteral( const QVariant &value ) : mValue( value ) {}
499
501 inline QVariant value() const { return mValue; }
502
503 QgsSQLStatement::NodeType nodeType() const override { return ntLiteral; }
504 QString dump() const override;
505
506 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
507 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
508
509 protected:
510 QVariant mValue;
511 };
512
517 class CORE_EXPORT NodeColumnRef : public QgsSQLStatement::Node
518 {
519 public:
521 NodeColumnRef( const QString &name, bool star ) : mName( name ), mDistinct( false ), mStar( star ) {}
523 NodeColumnRef( const QString &tableName, const QString &name, bool star ) : mTableName( tableName ), mName( name ), mDistinct( false ), mStar( star ) {}
524
526 void setDistinct( bool distinct = true ) { mDistinct = distinct; }
527
529 QString tableName() const { return mTableName; }
530
532 QString name() const { return mName; }
533
535 bool star() const { return mStar; }
536
538 bool distinct() const { return mDistinct; }
539
540 QgsSQLStatement::NodeType nodeType() const override { return ntColumnRef; }
541 QString dump() const override;
542
543 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
544 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
546 QgsSQLStatement::NodeColumnRef *cloneThis() const SIP_FACTORY;
547
548 protected:
549 QString mTableName;
550 QString mName;
551 bool mDistinct;
552 bool mStar;
553 };
554
559 class CORE_EXPORT NodeSelectedColumn : public QgsSQLStatement::Node
560 {
561 public:
563 NodeSelectedColumn( QgsSQLStatement::Node *node SIP_TRANSFER ) : mColumnNode( node ) {}
564 ~NodeSelectedColumn() override { delete mColumnNode; }
565
567 void setAlias( const QString &alias ) { mAlias = alias; }
568
570 QgsSQLStatement::Node *column() const { return mColumnNode; }
571
573 QString alias() const { return mAlias; }
574
575 QgsSQLStatement::NodeType nodeType() const override { return ntSelectedColumn; }
576 QString dump() const override;
577
578 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
579 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
582
583 protected:
584 Node *mColumnNode = nullptr;
585 QString mAlias;
586 };
587
592 class CORE_EXPORT NodeCast : public QgsSQLStatement::Node
593 {
594 public:
596 NodeCast( QgsSQLStatement::Node *node SIP_TRANSFER, const QString &type ) : mNode( node ), mType( type ) {}
597 ~NodeCast() override { delete mNode; }
598
600 QgsSQLStatement::Node *node() const { return mNode; }
601
603 QString type() const { return mType; }
604
605 QgsSQLStatement::NodeType nodeType() const override { return ntCast; }
606 QString dump() const override;
607
608 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
609 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
610
611 protected:
612 Node *mNode = nullptr;
613 QString mType;
614 };
615
620 class CORE_EXPORT NodeTableDef : public QgsSQLStatement::Node
621 {
622 public:
624 NodeTableDef( const QString &name ) : mName( name ) {}
626 NodeTableDef( const QString &name, const QString &alias ) : mName( name ), mAlias( alias ) {}
627
632 NodeTableDef( const QString &schema, const QString &name, const QString &alias ) : mName( name ), mSchema( schema ), mAlias( alias ) {}
633
635 QString name() const { return mName; }
636
642 QString schema() const { return mSchema; }
643
645 QString alias() const { return mAlias; }
646
647 QgsSQLStatement::NodeType nodeType() const override { return ntTableDef; }
648 QString dump() const override;
649
650 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
651 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
653 QgsSQLStatement::NodeTableDef *cloneThis() const SIP_FACTORY;
654
655 protected:
656 QString mName;
657 QString mSchema;
658 QString mAlias;
659 };
660
665 class CORE_EXPORT NodeJoin : public QgsSQLStatement::Node
666 {
667 public:
669 NodeJoin( QgsSQLStatement::NodeTableDef *tabledef SIP_TRANSFER, QgsSQLStatement::Node *onExpr SIP_TRANSFER, QgsSQLStatement::JoinType type ) : mTableDef( tabledef ), mOnExpr( onExpr ), mType( type ) {}
671 NodeJoin( QgsSQLStatement::NodeTableDef *tabledef SIP_TRANSFER, const QList<QString> &usingColumns, QgsSQLStatement::JoinType type ) : mTableDef( tabledef ), mUsingColumns( usingColumns ), mType( type ) {}
672 ~NodeJoin() override { delete mTableDef; delete mOnExpr; }
673
675 QgsSQLStatement::NodeTableDef *tableDef() const { return mTableDef; }
676
678 QgsSQLStatement::Node *onExpr() const { return mOnExpr; }
679
681 QList<QString> usingColumns() const { return mUsingColumns; }
682
684 QgsSQLStatement::JoinType type() const { return mType; }
685
686 QgsSQLStatement::NodeType nodeType() const override { return ntJoin; }
687 QString dump() const override;
688
689 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
690 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
692 QgsSQLStatement::NodeJoin *cloneThis() const SIP_FACTORY;
693
694 protected:
695 NodeTableDef *mTableDef = nullptr;
696 Node *mOnExpr = nullptr;
697 QList<QString> mUsingColumns;
698 JoinType mType;
699 };
700
705 class CORE_EXPORT NodeColumnSorted : public QgsSQLStatement::Node
706 {
707 public:
709 NodeColumnSorted( QgsSQLStatement::NodeColumnRef *column SIP_TRANSFER, bool asc ) : mColumn( column ), mAsc( asc ) {}
710 ~NodeColumnSorted() override { delete mColumn; }
711
713 QgsSQLStatement::NodeColumnRef *column() const { return mColumn; }
714
716 bool ascending() const { return mAsc; }
717
718 QgsSQLStatement::NodeType nodeType() const override { return ntColumnSorted; }
719 QString dump() const override;
720
721 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
722 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
724 QgsSQLStatement::NodeColumnSorted *cloneThis() const SIP_FACTORY;
725
726 protected:
727 NodeColumnRef *mColumn = nullptr;
728 bool mAsc;
729 };
730
735 class CORE_EXPORT NodeSelect : public QgsSQLStatement::Node
736 {
737 public:
739 NodeSelect( const QList<QgsSQLStatement::NodeTableDef *> &tableList SIP_TRANSFER, const QList<QgsSQLStatement::NodeSelectedColumn *> &columns SIP_TRANSFER, bool distinct ) : mTableList( tableList ), mColumns( columns ), mDistinct( distinct ) {}
740 ~NodeSelect() override;
741
743 void setJoins( const QList<QgsSQLStatement::NodeJoin *> &joins SIP_TRANSFER ) { qDeleteAll( mJoins ); mJoins = joins; }
745 void appendJoin( QgsSQLStatement::NodeJoin *join SIP_TRANSFER ) { mJoins.append( join ); }
747 void setWhere( QgsSQLStatement::Node *where SIP_TRANSFER ) { delete mWhere; mWhere = where; }
749 void setOrderBy( const QList<QgsSQLStatement::NodeColumnSorted *> &orderBy SIP_TRANSFER ) { qDeleteAll( mOrderBy ); mOrderBy = orderBy; }
750
752 QList<QgsSQLStatement::NodeTableDef *> tables() const { return mTableList; }
754 QList<QgsSQLStatement::NodeSelectedColumn *> columns() const { return mColumns; }
756 bool distinct() const { return mDistinct; }
758 QList<QgsSQLStatement::NodeJoin *> joins() const { return mJoins; }
760 QgsSQLStatement::Node *where() const { return mWhere; }
762 QList<QgsSQLStatement::NodeColumnSorted *> orderBy() const { return mOrderBy; }
763
764 QgsSQLStatement::NodeType nodeType() const override { return ntSelect; }
765 QString dump() const override;
766
767 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
768 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
769
770 protected:
771 QList<NodeTableDef *> mTableList;
772 QList<NodeSelectedColumn *> mColumns;
773 bool mDistinct;
774 QList<NodeJoin *> mJoins;
775 Node *mWhere = nullptr;
776 QList<NodeColumnSorted *> mOrderBy;
777 };
778
780
786 class CORE_EXPORT Visitor
787 {
788 public:
789 virtual ~Visitor() = default;
791 virtual void visit( const QgsSQLStatement::NodeUnaryOperator &n ) = 0;
793 virtual void visit( const QgsSQLStatement::NodeBinaryOperator &n ) = 0;
795 virtual void visit( const QgsSQLStatement::NodeInOperator &n ) = 0;
797 virtual void visit( const QgsSQLStatement::NodeBetweenOperator &n ) = 0;
799 virtual void visit( const QgsSQLStatement::NodeFunction &n ) = 0;
801 virtual void visit( const QgsSQLStatement::NodeLiteral &n ) = 0;
803 virtual void visit( const QgsSQLStatement::NodeColumnRef &n ) = 0;
805 virtual void visit( const QgsSQLStatement::NodeSelectedColumn &n ) = 0;
807 virtual void visit( const QgsSQLStatement::NodeTableDef &n ) = 0;
809 virtual void visit( const QgsSQLStatement::NodeSelect &n ) = 0;
811 virtual void visit( const QgsSQLStatement::NodeJoin &n ) = 0;
813 virtual void visit( const QgsSQLStatement::NodeColumnSorted &n ) = 0;
815 virtual void visit( const QgsSQLStatement::NodeCast &n ) = 0;
816 };
817
823 {
824 public:
825
826 RecursiveVisitor() = default;
827
828 void visit( const QgsSQLStatement::NodeUnaryOperator &n ) override { n.operand()->accept( *this ); }
829 void visit( const QgsSQLStatement::NodeBinaryOperator &n ) override { n.opLeft()->accept( *this ); n.opRight()->accept( *this ); }
830 void visit( const QgsSQLStatement::NodeInOperator &n ) override { n.node()->accept( *this ); n.list()->accept( *this ); }
831 void visit( const QgsSQLStatement::NodeBetweenOperator &n ) override { n.node()->accept( *this ); n.minVal()->accept( *this ); n.maxVal()->accept( *this ); }
832 void visit( const QgsSQLStatement::NodeFunction &n ) override { n.args()->accept( *this ); }
833 void visit( const QgsSQLStatement::NodeLiteral & ) override {}
834 void visit( const QgsSQLStatement::NodeColumnRef & ) override { }
835 void visit( const QgsSQLStatement::NodeSelectedColumn &n ) override { n.column()->accept( *this ); }
836 void visit( const QgsSQLStatement::NodeTableDef & ) override {}
837 void visit( const QgsSQLStatement::NodeSelect &n ) override;
838 void visit( const QgsSQLStatement::NodeJoin &n ) override;
839 void visit( const QgsSQLStatement::NodeColumnSorted &n ) override { n.column()->accept( *this ); }
840 void visit( const QgsSQLStatement::NodeCast &n ) override { n.node()->accept( *this ); }
841 };
842
844 void acceptVisitor( QgsSQLStatement::Visitor &v ) const;
845
846 protected:
847 QgsSQLStatement::Node *mRootNode = nullptr;
848 bool mAllowFragments = false;
849 QString mStatement;
851
860 QgsSQLStatement( const QString &statement, bool allowFragments );
861};
862
864
865
870class CORE_EXPORT QgsSQLStatementFragment : public QgsSQLStatement
871{
872 public:
873
877 QgsSQLStatementFragment( const QString &fragment );
878
879};
880
881
882#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.
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.
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.
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
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)