QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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
47 QgsSQLStatement( const QgsSQLStatement &other );
48
52 QgsSQLStatement &operator=( const QgsSQLStatement &other );
53 virtual ~QgsSQLStatement();
54
56 bool hasParserError() const;
58 QString parserErrorString() const;
59
65 bool doBasicValidationChecks( QString &errorMsgOut SIP_OUT ) const;
66
67 class Node;
68
73 const QgsSQLStatement::Node *rootNode() const;
74
80 QString statement() const;
81
88 QString dump() const;
89
94 static QString quotedIdentifier( QString name );
95
101 static QString quotedIdentifierIfNeeded( const QString &name );
102
107 static QString stripQuotedIdentifier( QString text );
108
113 static QString stripMsQuotedIdentifier( QString text );
114
119 static QString quotedString( QString text );
120
126 {
129 };
130
136 {
137 // logical
140
141 // comparison
142 boEQ, // =
143 boNE, // <>
144 boLE, // <=
145 boGE, // >=
146 boLT, // <
147 boGT, // >
154
155 // math
163
164 // strings
166 };
167
173 {
181 jtFull
182 };
183
185 static const char *BINARY_OPERATOR_TEXT[] SIP_SKIP;
186
188 static const char *UNARY_OPERATOR_TEXT[] SIP_SKIP;
189
191 static const char *JOIN_TYPE_TEXT[] SIP_SKIP;
192
194
195 class Visitor; // visitor interface is defined below
196
199 {
212 ntCast
213 };
214
219 class CORE_EXPORT Node
220 {
221
222#ifdef SIP_RUN
224 switch ( sipCpp->nodeType() )
225 {
226 case QgsSQLStatement::ntUnaryOperator: sipType = sipType_QgsSQLStatement_NodeUnaryOperator; break;
227 case QgsSQLStatement::ntBinaryOperator: sipType = sipType_QgsSQLStatement_NodeBinaryOperator; break;
228 case QgsSQLStatement::ntInOperator: sipType = sipType_QgsSQLStatement_NodeInOperator; break;
229 case QgsSQLStatement::ntBetweenOperator: sipType = sipType_QgsSQLStatement_NodeBetweenOperator; break;
230 case QgsSQLStatement::ntFunction: sipType = sipType_QgsSQLStatement_NodeFunction; break;
231 case QgsSQLStatement::ntLiteral: sipType = sipType_QgsSQLStatement_NodeLiteral; break;
232 case QgsSQLStatement::ntColumnRef: sipType = sipType_QgsSQLStatement_NodeColumnRef; break;
233 case QgsSQLStatement::ntSelectedColumn: sipType = sipType_QgsSQLStatement_NodeSelectedColumn; break;
234 case QgsSQLStatement::ntSelect: sipType = sipType_QgsSQLStatement_NodeSelect; break;
235 case QgsSQLStatement::ntTableDef: sipType = sipType_QgsSQLStatement_NodeTableDef; break;
236 case QgsSQLStatement::ntJoin: sipType = sipType_QgsSQLStatement_NodeJoin; break;
237 case QgsSQLStatement::ntColumnSorted: sipType = sipType_QgsSQLStatement_NodeColumnSorted; break;
238 case QgsSQLStatement::ntCast: sipType = sipType_QgsSQLStatement_NodeCast; break;
239 default: sipType = 0; break;
240 }
241 SIP_END
242#endif
243
244 public:
245 virtual ~Node() = default;
246
253
259 virtual QString dump() const = 0;
260
270
286 virtual void accept( QgsSQLStatement::Visitor &v ) const = 0;
287 };
288
293 class CORE_EXPORT NodeList
294 {
295 public:
297 NodeList() = default;
298 virtual ~NodeList() { qDeleteAll( mList ); }
299
301 void append( QgsSQLStatement::Node *node SIP_TRANSFER ) { mList.append( node ); }
302
304 QList<QgsSQLStatement::Node *> list() { return mList; }
305
309 int count() const { return mList.count(); }
310
312 void accept( QgsSQLStatement::Visitor &v ) const;
313
316
318 virtual QString dump() const;
319
320 protected:
321 QList<Node *> mList;
322 };
323
328 class CORE_EXPORT NodeUnaryOperator : public QgsSQLStatement::Node
329 {
330 public:
332 NodeUnaryOperator( QgsSQLStatement::UnaryOperator op, QgsSQLStatement::Node *operand SIP_TRANSFER ) : mOp( op ), mOperand( operand ) {}
333 ~NodeUnaryOperator() override { delete mOperand; }
334
336 QgsSQLStatement::UnaryOperator op() const { return mOp; }
337
339 QgsSQLStatement::Node *operand() const { return mOperand; }
340
341 QgsSQLStatement::NodeType nodeType() const override { return ntUnaryOperator; }
342 QString dump() const override;
343
344 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
345 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
346
347 protected:
349 Node *mOperand = nullptr;
350 };
351
356 class CORE_EXPORT NodeBinaryOperator : public QgsSQLStatement::Node
357 {
358 public:
361 : mOp( op )
362 , mOpLeft( opLeft )
363 , mOpRight( opRight )
364 {}
365 ~NodeBinaryOperator() override { delete mOpLeft; delete mOpRight; }
366
368 QgsSQLStatement::BinaryOperator op() const { return mOp; }
369
371 QgsSQLStatement::Node *opLeft() const { return mOpLeft; }
372
374 QgsSQLStatement::Node *opRight() const { return mOpRight; }
375
376 QgsSQLStatement::NodeType nodeType() const override { return ntBinaryOperator; }
377 QString dump() const override;
378
379 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
380 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
381
383 int precedence() const;
384
386 bool leftAssociative() const;
387
388 protected:
389
391 Node *mOpLeft = nullptr;
392 Node *mOpRight = nullptr;
393 };
394
399 class CORE_EXPORT NodeInOperator : public QgsSQLStatement::Node
400 {
401 public:
403 NodeInOperator( QgsSQLStatement::Node *node SIP_TRANSFER, QgsSQLStatement::NodeList *list SIP_TRANSFER, bool notin = false ) : mNode( node ), mList( list ), mNotIn( notin ) {}
404 ~NodeInOperator() override { delete mNode; delete mList; }
405
407 QgsSQLStatement::Node *node() const { return mNode; }
408
410 bool isNotIn() const { return mNotIn; }
411
413 QgsSQLStatement::NodeList *list() const { return mList; }
414
415 QgsSQLStatement::NodeType nodeType() const override { return ntInOperator; }
416 QString dump() const override;
417
418 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
419 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
420
421 protected:
422 Node *mNode = nullptr;
423 NodeList *mList = nullptr;
424 bool mNotIn;
425 };
426
431 class CORE_EXPORT NodeBetweenOperator : public QgsSQLStatement::Node
432 {
433 public:
436 : mNode( node ), mMinVal( minVal ), mMaxVal( maxVal ), mNotBetween( notBetween ) {}
437 ~NodeBetweenOperator() override { delete mNode; delete mMinVal; delete mMaxVal; }
438
440 QgsSQLStatement::Node *node() const { return mNode; }
441
443 bool isNotBetween() const { return mNotBetween; }
444
446 QgsSQLStatement::Node *minVal() const { return mMinVal; }
447
449 QgsSQLStatement::Node *maxVal() const { return mMaxVal; }
450
451 QgsSQLStatement::NodeType nodeType() const override { return ntBetweenOperator; }
452 QString dump() const override;
453
454 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
455 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
456
457 protected:
458 Node *mNode = nullptr;
459 Node *mMinVal = nullptr;
460 Node *mMaxVal = nullptr;
461 bool mNotBetween;
462 };
463
468 class CORE_EXPORT NodeFunction : public QgsSQLStatement::Node
469 {
470 public:
472 NodeFunction( const QString &name, QgsSQLStatement::NodeList *args SIP_TRANSFER ) : mName( name ), mArgs( args ) {}
473 ~NodeFunction() override { delete mArgs; }
474
476 QString name() const { return mName; }
477
479 QgsSQLStatement::NodeList *args() const { return mArgs; }
480
481 QgsSQLStatement::NodeType nodeType() const override { return ntFunction; }
482 QString dump() const override;
483
484 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
485 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
486
487 protected:
488 QString mName;
489 NodeList *mArgs = nullptr;
490
491 };
492
497 class CORE_EXPORT NodeLiteral : public QgsSQLStatement::Node
498 {
499 public:
501 NodeLiteral( const QVariant &value ) : mValue( value ) {}
502
504 inline QVariant value() const { return mValue; }
505
506 QgsSQLStatement::NodeType nodeType() const override { return ntLiteral; }
507 QString dump() const override;
508
509 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
510 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
511
512 protected:
513 QVariant mValue;
514 };
515
520 class CORE_EXPORT NodeColumnRef : public QgsSQLStatement::Node
521 {
522 public:
524 NodeColumnRef( const QString &name, bool star ) : mName( name ), mDistinct( false ), mStar( star ) {}
526 NodeColumnRef( const QString &tableName, const QString &name, bool star ) : mTableName( tableName ), mName( name ), mDistinct( false ), mStar( star ) {}
527
529 void setDistinct( bool distinct = true ) { mDistinct = distinct; }
530
532 QString tableName() const { return mTableName; }
533
535 QString name() const { return mName; }
536
538 bool star() const { return mStar; }
539
541 bool distinct() const { return mDistinct; }
542
543 QgsSQLStatement::NodeType nodeType() const override { return ntColumnRef; }
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;
549 QgsSQLStatement::NodeColumnRef *cloneThis() const SIP_FACTORY;
550
551 protected:
552 QString mTableName;
553 QString mName;
554 bool mDistinct;
555 bool mStar;
556 };
557
562 class CORE_EXPORT NodeSelectedColumn : public QgsSQLStatement::Node
563 {
564 public:
566 NodeSelectedColumn( QgsSQLStatement::Node *node SIP_TRANSFER ) : mColumnNode( node ) {}
567 ~NodeSelectedColumn() override { delete mColumnNode; }
568
570 void setAlias( const QString &alias ) { mAlias = alias; }
571
573 QgsSQLStatement::Node *column() const { return mColumnNode; }
574
576 QString alias() const { return mAlias; }
577
578 QgsSQLStatement::NodeType nodeType() const override { return ntSelectedColumn; }
579 QString dump() const override;
580
581 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
582 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
585
586 protected:
587 Node *mColumnNode = nullptr;
588 QString mAlias;
589 };
590
595 class CORE_EXPORT NodeCast : public QgsSQLStatement::Node
596 {
597 public:
599 NodeCast( QgsSQLStatement::Node *node SIP_TRANSFER, const QString &type ) : mNode( node ), mType( type ) {}
600 ~NodeCast() override { delete mNode; }
601
603 QgsSQLStatement::Node *node() const { return mNode; }
604
606 QString type() const { return mType; }
607
608 QgsSQLStatement::NodeType nodeType() const override { return ntCast; }
609 QString dump() const override;
610
611 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
612 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
613
614 protected:
615 Node *mNode = nullptr;
616 QString mType;
617 };
618
623 class CORE_EXPORT NodeTableDef : public QgsSQLStatement::Node
624 {
625 public:
627 NodeTableDef( const QString &name ) : mName( name ) {}
629 NodeTableDef( const QString &name, const QString &alias ) : mName( name ), mAlias( alias ) {}
630
635 NodeTableDef( const QString &schema, const QString &name, const QString &alias ) : mName( name ), mSchema( schema ), mAlias( alias ) {}
636
638 QString name() const { return mName; }
639
645 QString schema() const { return mSchema; }
646
648 QString alias() const { return mAlias; }
649
650 QgsSQLStatement::NodeType nodeType() const override { return ntTableDef; }
651 QString dump() const override;
652
653 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
654 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
656 QgsSQLStatement::NodeTableDef *cloneThis() const SIP_FACTORY;
657
658 protected:
659 QString mName;
660 QString mSchema;
661 QString mAlias;
662 };
663
668 class CORE_EXPORT NodeJoin : public QgsSQLStatement::Node
669 {
670 public:
672 NodeJoin( QgsSQLStatement::NodeTableDef *tabledef SIP_TRANSFER, QgsSQLStatement::Node *onExpr SIP_TRANSFER, QgsSQLStatement::JoinType type ) : mTableDef( tabledef ), mOnExpr( onExpr ), mType( type ) {}
674 NodeJoin( QgsSQLStatement::NodeTableDef *tabledef SIP_TRANSFER, const QList<QString> &usingColumns, QgsSQLStatement::JoinType type ) : mTableDef( tabledef ), mUsingColumns( usingColumns ), mType( type ) {}
675 ~NodeJoin() override { delete mTableDef; delete mOnExpr; }
676
678 QgsSQLStatement::NodeTableDef *tableDef() const { return mTableDef; }
679
681 QgsSQLStatement::Node *onExpr() const { return mOnExpr; }
682
684 QList<QString> usingColumns() const { return mUsingColumns; }
685
687 QgsSQLStatement::JoinType type() const { return mType; }
688
689 QgsSQLStatement::NodeType nodeType() const override { return ntJoin; }
690 QString dump() const override;
691
692 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
693 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
695 QgsSQLStatement::NodeJoin *cloneThis() const SIP_FACTORY;
696
697 protected:
698 NodeTableDef *mTableDef = nullptr;
699 Node *mOnExpr = nullptr;
700 QList<QString> mUsingColumns;
701 JoinType mType;
702 };
703
708 class CORE_EXPORT NodeColumnSorted : public QgsSQLStatement::Node
709 {
710 public:
712 NodeColumnSorted( QgsSQLStatement::NodeColumnRef *column SIP_TRANSFER, bool asc ) : mColumn( column ), mAsc( asc ) {}
713 ~NodeColumnSorted() override { delete mColumn; }
714
716 QgsSQLStatement::NodeColumnRef *column() const { return mColumn; }
717
719 bool ascending() const { return mAsc; }
720
721 QgsSQLStatement::NodeType nodeType() const override { return ntColumnSorted; }
722 QString dump() const override;
723
724 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
725 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
727 QgsSQLStatement::NodeColumnSorted *cloneThis() const SIP_FACTORY;
728
729 protected:
730 NodeColumnRef *mColumn = nullptr;
731 bool mAsc;
732 };
733
738 class CORE_EXPORT NodeSelect : public QgsSQLStatement::Node
739 {
740 public:
742 NodeSelect( const QList<QgsSQLStatement::NodeTableDef *> &tableList SIP_TRANSFER, const QList<QgsSQLStatement::NodeSelectedColumn *> &columns SIP_TRANSFER, bool distinct ) : mTableList( tableList ), mColumns( columns ), mDistinct( distinct ) {}
743 ~NodeSelect() override;
744
746 void setJoins( const QList<QgsSQLStatement::NodeJoin *> &joins SIP_TRANSFER ) { qDeleteAll( mJoins ); mJoins = joins; }
748 void appendJoin( QgsSQLStatement::NodeJoin *join SIP_TRANSFER ) { mJoins.append( join ); }
750 void setWhere( QgsSQLStatement::Node *where SIP_TRANSFER ) { delete mWhere; mWhere = where; }
752 void setOrderBy( const QList<QgsSQLStatement::NodeColumnSorted *> &orderBy SIP_TRANSFER ) { qDeleteAll( mOrderBy ); mOrderBy = orderBy; }
753
755 QList<QgsSQLStatement::NodeTableDef *> tables() const { return mTableList; }
757 QList<QgsSQLStatement::NodeSelectedColumn *> columns() const { return mColumns; }
759 bool distinct() const { return mDistinct; }
761 QList<QgsSQLStatement::NodeJoin *> joins() const { return mJoins; }
763 QgsSQLStatement::Node *where() const { return mWhere; }
765 QList<QgsSQLStatement::NodeColumnSorted *> orderBy() const { return mOrderBy; }
766
767 QgsSQLStatement::NodeType nodeType() const override { return ntSelect; }
768 QString dump() const override;
769
770 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
771 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
772
773 protected:
774 QList<NodeTableDef *> mTableList;
775 QList<NodeSelectedColumn *> mColumns;
776 bool mDistinct;
777 QList<NodeJoin *> mJoins;
778 Node *mWhere = nullptr;
779 QList<NodeColumnSorted *> mOrderBy;
780 };
781
783
789 class CORE_EXPORT Visitor
790 {
791 public:
792 virtual ~Visitor() = default;
794 virtual void visit( const QgsSQLStatement::NodeUnaryOperator &n ) = 0;
796 virtual void visit( const QgsSQLStatement::NodeBinaryOperator &n ) = 0;
798 virtual void visit( const QgsSQLStatement::NodeInOperator &n ) = 0;
800 virtual void visit( const QgsSQLStatement::NodeBetweenOperator &n ) = 0;
802 virtual void visit( const QgsSQLStatement::NodeFunction &n ) = 0;
804 virtual void visit( const QgsSQLStatement::NodeLiteral &n ) = 0;
806 virtual void visit( const QgsSQLStatement::NodeColumnRef &n ) = 0;
808 virtual void visit( const QgsSQLStatement::NodeSelectedColumn &n ) = 0;
810 virtual void visit( const QgsSQLStatement::NodeTableDef &n ) = 0;
812 virtual void visit( const QgsSQLStatement::NodeSelect &n ) = 0;
814 virtual void visit( const QgsSQLStatement::NodeJoin &n ) = 0;
816 virtual void visit( const QgsSQLStatement::NodeColumnSorted &n ) = 0;
818 virtual void visit( const QgsSQLStatement::NodeCast &n ) = 0;
819 };
820
826 {
827 public:
829 RecursiveVisitor() = default;
830
831 void visit( const QgsSQLStatement::NodeUnaryOperator &n ) override { n.operand()->accept( *this ); }
832 void visit( const QgsSQLStatement::NodeBinaryOperator &n ) override { n.opLeft()->accept( *this ); n.opRight()->accept( *this ); }
833 void visit( const QgsSQLStatement::NodeInOperator &n ) override { n.node()->accept( *this ); n.list()->accept( *this ); }
834 void visit( const QgsSQLStatement::NodeBetweenOperator &n ) override { n.node()->accept( *this ); n.minVal()->accept( *this ); n.maxVal()->accept( *this ); }
835 void visit( const QgsSQLStatement::NodeFunction &n ) override { n.args()->accept( *this ); }
836 void visit( const QgsSQLStatement::NodeLiteral & ) override {}
837 void visit( const QgsSQLStatement::NodeColumnRef & ) override { }
838 void visit( const QgsSQLStatement::NodeSelectedColumn &n ) override { n.column()->accept( *this ); }
839 void visit( const QgsSQLStatement::NodeTableDef & ) override {}
840 void visit( const QgsSQLStatement::NodeSelect &n ) override;
841 void visit( const QgsSQLStatement::NodeJoin &n ) override;
842 void visit( const QgsSQLStatement::NodeColumnSorted &n ) override { n.column()->accept( *this ); }
843 void visit( const QgsSQLStatement::NodeCast &n ) override { n.node()->accept( *this ); }
844 };
845
847 void acceptVisitor( QgsSQLStatement::Visitor &v ) const;
848
849 protected:
850 QgsSQLStatement::Node *mRootNode = nullptr;
851 bool mAllowFragments = false;
852 QString mStatement;
854
863 QgsSQLStatement( const QString &statement, bool allowFragments );
864};
865
867
868
873class CORE_EXPORT QgsSQLStatementFragment : public QgsSQLStatement
874{
875 public:
876
880 QgsSQLStatementFragment( const QString &fragment );
881
882};
883
884
885#endif // QGSSQLSTATEMENT_H
Class for parsing fragments of SQL statements, such as an expression or where clause.
'X BETWEEN y and z' operator
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QgsSQLStatement::Node * node() const
Variable at the left of BETWEEN.
QgsSQLStatement::Node * minVal() const
Minimum bound.
bool isNotBetween() const
Whether this is a NOT BETWEEN operator.
QgsSQLStatement::Node * maxVal() const
Maximum bound.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
NodeBetweenOperator(QgsSQLStatement::Node *node, QgsSQLStatement::Node *minVal, QgsSQLStatement::Node *maxVal, bool notBetween=false)
Constructor.
Binary logical/arithmetical operator (AND, OR, =, +, ...)
QgsSQLStatement::Node * opLeft() const
Left operand.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
NodeBinaryOperator(QgsSQLStatement::BinaryOperator op, QgsSQLStatement::Node *opLeft, QgsSQLStatement::Node *opRight)
Constructor.
QgsSQLStatement::BinaryOperator op() const
Operator.
QgsSQLStatement::Node * opRight() const
Right operand.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QgsSQLStatement::Node * node() const
Node that is referred to.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
NodeCast(QgsSQLStatement::Node *node, const QString &type)
Constructor.
QString type() const
Type.
Reference to a column.
QString name() const
The name of the column.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
NodeColumnRef(const QString &name, bool star)
Constructor with column name only.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
bool star() const
Whether this is the * column.
NodeColumnRef(const QString &tableName, const QString &name, bool star)
Constructor with table and column name.
QString tableName() const
The name of the table. May be empty.
void setDistinct(bool distinct=true)
Sets whether this is prefixed by DISTINCT.
bool distinct() const
Whether this is prefixed by DISTINCT.
bool ascending() const
Whether the column is sorted in ascending order.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QgsSQLStatement::NodeColumnRef * column() const
The name of the column.
NodeColumnSorted(QgsSQLStatement::NodeColumnRef *column, bool asc)
Constructor.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
Function with a name and arguments node.
NodeFunction(const QString &name, QgsSQLStatement::NodeList *args)
Constructor.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QgsSQLStatement::NodeList * args() const
Returns arguments.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QString name() const
Returns function name.
bool isNotIn() const
Whether this is a NOT IN operator.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QgsSQLStatement::Node * node() const
Variable at the left of IN.
NodeInOperator(QgsSQLStatement::Node *node, QgsSQLStatement::NodeList *list, bool notin=false)
Constructor.
QgsSQLStatement::NodeList * list() const
Values list.
QgsSQLStatement::NodeTableDef * tableDef() const
Table definition.
QgsSQLStatement::Node * onExpr() const
On expression. Will be nullptr if usingColumns() is not empty.
NodeJoin(QgsSQLStatement::NodeTableDef *tabledef, QgsSQLStatement::Node *onExpr, QgsSQLStatement::JoinType type)
Constructor with table definition, ON expression.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
NodeJoin(QgsSQLStatement::NodeTableDef *tabledef, const QList< QString > &usingColumns, QgsSQLStatement::JoinType type)
Constructor with table definition and USING columns.
QList< QString > usingColumns() const
Columns referenced by USING.
QgsSQLStatement::JoinType type() const
Join type.
NodeList()=default
Constructor.
void accept(QgsSQLStatement::Visitor &v) const
Accept visitor.
QList< QgsSQLStatement::Node * > list()
Returns list.
int count() const
Returns the number of nodes in the list.
void append(QgsSQLStatement::Node *node)
Takes ownership of the provided node.
Literal value (integer, integer64, double, string)
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
NodeLiteral(const QVariant &value)
Constructor.
QVariant value() const
The value of the literal.
NodeSelect(const QList< QgsSQLStatement::NodeTableDef * > &tableList, const QList< QgsSQLStatement::NodeSelectedColumn * > &columns, bool distinct)
Constructor.
QList< QgsSQLStatement::NodeColumnSorted * > orderBy() const
Returns the list of order by columns.
void setJoins(const QList< QgsSQLStatement::NodeJoin * > &joins)
Sets joins.
void setWhere(QgsSQLStatement::Node *where)
Sets where clause.
QList< QgsSQLStatement::NodeSelectedColumn * > columns() const
Returns the list of columns.
bool distinct() const
Returns if the SELECT is DISTINCT.
void appendJoin(QgsSQLStatement::NodeJoin *join)
Append a join.
void setOrderBy(const QList< QgsSQLStatement::NodeColumnSorted * > &orderBy)
Sets order by columns.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QList< QgsSQLStatement::NodeJoin * > joins() const
Returns the list of joins.
QgsSQLStatement::Node * where() const
Returns the where clause.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QList< QgsSQLStatement::NodeTableDef * > tables() const
Returns the list of tables.
NodeSelectedColumn(QgsSQLStatement::Node *node)
Constructor.
void setAlias(const QString &alias)
Sets alias name.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QgsSQLStatement::Node * column() const
Column that is referred to.
QString alias() const
Alias name.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QString name() const
Table name.
NodeTableDef(const QString &schema, const QString &name, const QString &alias)
Constructor with schema, table name and alias.
NodeTableDef(const QString &name)
Constructor with table name.
NodeTableDef(const QString &name, const QString &alias)
Constructor with table name and alias.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QString alias() const
Table alias.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
QString schema() const
Returns the schema name.
Unary logicial/arithmetical operator ( NOT, - )
NodeUnaryOperator(QgsSQLStatement::UnaryOperator op, QgsSQLStatement::Node *operand)
Constructor.
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
QgsSQLStatement::UnaryOperator op() const
Operator.
QgsSQLStatement::Node * operand() const
Operand.
QgsSQLStatement::NodeType nodeType() const override
Abstract virtual that returns the type of this node.
Abstract node class.
virtual QgsSQLStatement::Node * clone() const =0
Generate a clone of this node.
virtual QString dump() const =0
Abstract virtual dump method.
virtual ~Node()=default
virtual QgsSQLStatement::NodeType nodeType() const =0
Abstract virtual that returns the type of this node.
virtual void accept(QgsSQLStatement::Visitor &v) const =0
Support the visitor pattern.
A visitor that recursively explores all children.
void visit(const QgsSQLStatement::NodeFunction &n) override
Visit NodeFunction.
void visit(const QgsSQLStatement::NodeSelectedColumn &n) override
Visit NodeSelectedColumn.
void visit(const QgsSQLStatement::NodeUnaryOperator &n) override
Visit NodeUnaryOperator.
void visit(const QgsSQLStatement::NodeLiteral &) override
Visit NodeLiteral.
RecursiveVisitor()=default
Constructor.
void visit(const QgsSQLStatement::NodeBetweenOperator &n) override
Visit NodeBetweenOperator.
void visit(const QgsSQLStatement::NodeBinaryOperator &n) override
Visit NodeBinaryOperator.
void visit(const QgsSQLStatement::NodeColumnRef &) override
Visit NodeColumnRef.
void visit(const QgsSQLStatement::NodeTableDef &) override
Visit NodeTableDef.
void visit(const QgsSQLStatement::NodeColumnSorted &n) override
Visit NodeColumnSorted.
void visit(const QgsSQLStatement::NodeInOperator &n) override
Visit NodeInOperator.
void visit(const QgsSQLStatement::NodeCast &n) override
Visit NodeCast.
Support for visitor pattern - algorithms dealing with the statement may be implemented without modify...
virtual void visit(const QgsSQLStatement::NodeBetweenOperator &n)=0
Visit NodeBetweenOperator.
virtual ~Visitor()=default
virtual void visit(const QgsSQLStatement::NodeFunction &n)=0
Visit NodeFunction.
virtual void visit(const QgsSQLStatement::NodeColumnRef &n)=0
Visit NodeColumnRef.
virtual void visit(const QgsSQLStatement::NodeBinaryOperator &n)=0
Visit NodeBinaryOperator.
virtual void visit(const QgsSQLStatement::NodeSelect &n)=0
Visit NodeSelect.
virtual void visit(const QgsSQLStatement::NodeCast &n)=0
Visit NodeCast.
virtual void visit(const QgsSQLStatement::NodeSelectedColumn &n)=0
Visit NodeSelectedColumn.
virtual void visit(const QgsSQLStatement::NodeJoin &n)=0
Visit NodeJoin.
virtual void visit(const QgsSQLStatement::NodeUnaryOperator &n)=0
Visit NodeUnaryOperator.
virtual void visit(const QgsSQLStatement::NodeInOperator &n)=0
Visit NodeInOperator.
virtual void visit(const QgsSQLStatement::NodeLiteral &n)=0
Visit NodeLiteral.
virtual void visit(const QgsSQLStatement::NodeColumnSorted &n)=0
Visit NodeColumnSorted.
virtual void visit(const QgsSQLStatement::NodeTableDef &n)=0
Visit NodeTableDef.
Class for parsing SQL statements.
JoinType
list of join types
BinaryOperator
list of binary operators
QString mParserErrorString
UnaryOperator
list of unary operators
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h: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)