QGIS API Documentation 3.39.0-Master (3aed037ce22)
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
88 static QString quotedIdentifier( QString name );
89
95 static QString quotedIdentifierIfNeeded( const QString &name );
96
101 static QString stripQuotedIdentifier( QString text );
102
107 static QString stripMsQuotedIdentifier( QString text );
108
113 static QString quotedString( QString text );
114
124
130 {
131 // logical
134
135 // comparison
136 boEQ, // =
137 boNE, // <>
138 boLE, // <=
139 boGE, // >=
140 boLT, // <
141 boGT, // >
148
149 // math
157
158 // strings
160 };
161
177
179 static const char *BINARY_OPERATOR_TEXT[] SIP_SKIP;
180
182 static const char *UNARY_OPERATOR_TEXT[] SIP_SKIP;
183
185 static const char *JOIN_TYPE_TEXT[] SIP_SKIP;
186
188
189 class Visitor; // visitor interface is defined below
190
208
213 class CORE_EXPORT Node
214 {
215
216#ifdef SIP_RUN
218 switch ( sipCpp->nodeType() )
219 {
220 case QgsSQLStatement::ntUnaryOperator: sipType = sipType_QgsSQLStatement_NodeUnaryOperator; break;
221 case QgsSQLStatement::ntBinaryOperator: sipType = sipType_QgsSQLStatement_NodeBinaryOperator; break;
222 case QgsSQLStatement::ntInOperator: sipType = sipType_QgsSQLStatement_NodeInOperator; break;
223 case QgsSQLStatement::ntBetweenOperator: sipType = sipType_QgsSQLStatement_NodeBetweenOperator; break;
224 case QgsSQLStatement::ntFunction: sipType = sipType_QgsSQLStatement_NodeFunction; break;
225 case QgsSQLStatement::ntLiteral: sipType = sipType_QgsSQLStatement_NodeLiteral; break;
226 case QgsSQLStatement::ntColumnRef: sipType = sipType_QgsSQLStatement_NodeColumnRef; break;
227 case QgsSQLStatement::ntSelectedColumn: sipType = sipType_QgsSQLStatement_NodeSelectedColumn; break;
228 case QgsSQLStatement::ntSelect: sipType = sipType_QgsSQLStatement_NodeSelect; break;
229 case QgsSQLStatement::ntTableDef: sipType = sipType_QgsSQLStatement_NodeTableDef; break;
230 case QgsSQLStatement::ntJoin: sipType = sipType_QgsSQLStatement_NodeJoin; break;
231 case QgsSQLStatement::ntColumnSorted: sipType = sipType_QgsSQLStatement_NodeColumnSorted; break;
232 case QgsSQLStatement::ntCast: sipType = sipType_QgsSQLStatement_NodeCast; break;
233 default: sipType = 0; break;
234 }
235 SIP_END
236#endif
237
238 public:
239 virtual ~Node() = default;
240
247
253 virtual QString dump() const = 0;
254
264
280 virtual void accept( QgsSQLStatement::Visitor &v ) const = 0;
281 };
282
287 class CORE_EXPORT NodeList
288 {
289 public:
290
291 NodeList() = default;
292 virtual ~NodeList() { qDeleteAll( mList ); }
293
295 void append( QgsSQLStatement::Node *node SIP_TRANSFER ) { mList.append( node ); }
296
298 QList<QgsSQLStatement::Node *> list() { return mList; }
299
303 int count() const { return mList.count(); }
304
306 void accept( QgsSQLStatement::Visitor &v ) const;
307
310
312 virtual QString dump() const;
313
314 protected:
315 QList<Node *> mList;
316 };
317
322 class CORE_EXPORT NodeUnaryOperator : public QgsSQLStatement::Node
323 {
324 public:
326 NodeUnaryOperator( QgsSQLStatement::UnaryOperator op, QgsSQLStatement::Node *operand SIP_TRANSFER ) : mOp( op ), mOperand( operand ) {}
327 ~NodeUnaryOperator() override { delete mOperand; }
328
330 QgsSQLStatement::UnaryOperator op() const { return mOp; }
331
333 QgsSQLStatement::Node *operand() const { return mOperand; }
334
335 QgsSQLStatement::NodeType nodeType() const override { return ntUnaryOperator; }
336 QString dump() const override;
337
338 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
339 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
340
341 protected:
343 Node *mOperand = nullptr;
344 };
345
350 class CORE_EXPORT NodeBinaryOperator : public QgsSQLStatement::Node
351 {
352 public:
355 : mOp( op )
356 , mOpLeft( opLeft )
357 , mOpRight( opRight )
358 {}
359 ~NodeBinaryOperator() override { delete mOpLeft; delete mOpRight; }
360
362 QgsSQLStatement::BinaryOperator op() const { return mOp; }
363
365 QgsSQLStatement::Node *opLeft() const { return mOpLeft; }
366
368 QgsSQLStatement::Node *opRight() const { return mOpRight; }
369
370 QgsSQLStatement::NodeType nodeType() const override { return ntBinaryOperator; }
371 QString dump() const override;
372
373 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
374 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
375
377 int precedence() const;
378
380 bool leftAssociative() const;
381
382 protected:
383
385 Node *mOpLeft = nullptr;
386 Node *mOpRight = nullptr;
387 };
388
393 class CORE_EXPORT NodeInOperator : public QgsSQLStatement::Node
394 {
395 public:
397 NodeInOperator( QgsSQLStatement::Node *node SIP_TRANSFER, QgsSQLStatement::NodeList *list SIP_TRANSFER, bool notin = false ) : mNode( node ), mList( list ), mNotIn( notin ) {}
398 ~NodeInOperator() override { delete mNode; delete mList; }
399
401 QgsSQLStatement::Node *node() const { return mNode; }
402
404 bool isNotIn() const { return mNotIn; }
405
407 QgsSQLStatement::NodeList *list() const { return mList; }
408
409 QgsSQLStatement::NodeType nodeType() const override { return ntInOperator; }
410 QString dump() const override;
411
412 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
413 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
414
415 protected:
416 Node *mNode = nullptr;
417 NodeList *mList = nullptr;
418 bool mNotIn;
419 };
420
425 class CORE_EXPORT NodeBetweenOperator : public QgsSQLStatement::Node
426 {
427 public:
430 : mNode( node ), mMinVal( minVal ), mMaxVal( maxVal ), mNotBetween( notBetween ) {}
431 ~NodeBetweenOperator() override { delete mNode; delete mMinVal; delete mMaxVal; }
432
434 QgsSQLStatement::Node *node() const { return mNode; }
435
437 bool isNotBetween() const { return mNotBetween; }
438
440 QgsSQLStatement::Node *minVal() const { return mMinVal; }
441
443 QgsSQLStatement::Node *maxVal() const { return mMaxVal; }
444
445 QgsSQLStatement::NodeType nodeType() const override { return ntBetweenOperator; }
446 QString dump() const override;
447
448 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
449 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
450
451 protected:
452 Node *mNode = nullptr;
453 Node *mMinVal = nullptr;
454 Node *mMaxVal = nullptr;
455 bool mNotBetween;
456 };
457
462 class CORE_EXPORT NodeFunction : public QgsSQLStatement::Node
463 {
464 public:
466 NodeFunction( const QString &name, QgsSQLStatement::NodeList *args SIP_TRANSFER ) : mName( name ), mArgs( args ) {}
467 ~NodeFunction() override { delete mArgs; }
468
470 QString name() const { return mName; }
471
473 QgsSQLStatement::NodeList *args() const { return mArgs; }
474
475 QgsSQLStatement::NodeType nodeType() const override { return ntFunction; }
476 QString dump() const override;
477
478 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
479 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
480
481 protected:
482 QString mName;
483 NodeList *mArgs = nullptr;
484
485 };
486
491 class CORE_EXPORT NodeLiteral : public QgsSQLStatement::Node
492 {
493 public:
495 NodeLiteral( const QVariant &value ) : mValue( value ) {}
496
498 inline QVariant value() const { return mValue; }
499
500 QgsSQLStatement::NodeType nodeType() const override { return ntLiteral; }
501 QString dump() const override;
502
503 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
504 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
505
506 protected:
507 QVariant mValue;
508 };
509
514 class CORE_EXPORT NodeColumnRef : public QgsSQLStatement::Node
515 {
516 public:
518 NodeColumnRef( const QString &name, bool star ) : mName( name ), mDistinct( false ), mStar( star ) {}
520 NodeColumnRef( const QString &tableName, const QString &name, bool star ) : mTableName( tableName ), mName( name ), mDistinct( false ), mStar( star ) {}
521
523 void setDistinct( bool distinct = true ) { mDistinct = distinct; }
524
526 QString tableName() const { return mTableName; }
527
529 QString name() const { return mName; }
530
532 bool star() const { return mStar; }
533
535 bool distinct() const { return mDistinct; }
536
537 QgsSQLStatement::NodeType nodeType() const override { return ntColumnRef; }
538 QString dump() const override;
539
540 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
541 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
543 QgsSQLStatement::NodeColumnRef *cloneThis() const SIP_FACTORY;
544
545 protected:
546 QString mTableName;
547 QString mName;
548 bool mDistinct;
549 bool mStar;
550 };
551
556 class CORE_EXPORT NodeSelectedColumn : public QgsSQLStatement::Node
557 {
558 public:
560 NodeSelectedColumn( QgsSQLStatement::Node *node SIP_TRANSFER ) : mColumnNode( node ) {}
561 ~NodeSelectedColumn() override { delete mColumnNode; }
562
564 void setAlias( const QString &alias ) { mAlias = alias; }
565
567 QgsSQLStatement::Node *column() const { return mColumnNode; }
568
570 QString alias() const { return mAlias; }
571
572 QgsSQLStatement::NodeType nodeType() const override { return ntSelectedColumn; }
573 QString dump() const override;
574
575 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
576 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
579
580 protected:
581 Node *mColumnNode = nullptr;
582 QString mAlias;
583 };
584
589 class CORE_EXPORT NodeCast : public QgsSQLStatement::Node
590 {
591 public:
593 NodeCast( QgsSQLStatement::Node *node SIP_TRANSFER, const QString &type ) : mNode( node ), mType( type ) {}
594 ~NodeCast() override { delete mNode; }
595
597 QgsSQLStatement::Node *node() const { return mNode; }
598
600 QString type() const { return mType; }
601
602 QgsSQLStatement::NodeType nodeType() const override { return ntCast; }
603 QString dump() const override;
604
605 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
606 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
607
608 protected:
609 Node *mNode = nullptr;
610 QString mType;
611 };
612
617 class CORE_EXPORT NodeTableDef : public QgsSQLStatement::Node
618 {
619 public:
621 NodeTableDef( const QString &name ) : mName( name ) {}
623 NodeTableDef( const QString &name, const QString &alias ) : mName( name ), mAlias( alias ) {}
624
629 NodeTableDef( const QString &schema, const QString &name, const QString &alias ) : mName( name ), mSchema( schema ), mAlias( alias ) {}
630
632 QString name() const { return mName; }
633
639 QString schema() const { return mSchema; }
640
642 QString alias() const { return mAlias; }
643
644 QgsSQLStatement::NodeType nodeType() const override { return ntTableDef; }
645 QString dump() const override;
646
647 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
648 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
650 QgsSQLStatement::NodeTableDef *cloneThis() const SIP_FACTORY;
651
652 protected:
653 QString mName;
654 QString mSchema;
655 QString mAlias;
656 };
657
662 class CORE_EXPORT NodeJoin : public QgsSQLStatement::Node
663 {
664 public:
666 NodeJoin( QgsSQLStatement::NodeTableDef *tabledef SIP_TRANSFER, QgsSQLStatement::Node *onExpr SIP_TRANSFER, QgsSQLStatement::JoinType type ) : mTableDef( tabledef ), mOnExpr( onExpr ), mType( type ) {}
668 NodeJoin( QgsSQLStatement::NodeTableDef *tabledef SIP_TRANSFER, const QList<QString> &usingColumns, QgsSQLStatement::JoinType type ) : mTableDef( tabledef ), mUsingColumns( usingColumns ), mType( type ) {}
669 ~NodeJoin() override { delete mTableDef; delete mOnExpr; }
670
672 QgsSQLStatement::NodeTableDef *tableDef() const { return mTableDef; }
673
675 QgsSQLStatement::Node *onExpr() const { return mOnExpr; }
676
678 QList<QString> usingColumns() const { return mUsingColumns; }
679
681 QgsSQLStatement::JoinType type() const { return mType; }
682
683 QgsSQLStatement::NodeType nodeType() const override { return ntJoin; }
684 QString dump() const override;
685
686 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
687 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
689 QgsSQLStatement::NodeJoin *cloneThis() const SIP_FACTORY;
690
691 protected:
692 NodeTableDef *mTableDef = nullptr;
693 Node *mOnExpr = nullptr;
694 QList<QString> mUsingColumns;
695 JoinType mType;
696 };
697
702 class CORE_EXPORT NodeColumnSorted : public QgsSQLStatement::Node
703 {
704 public:
706 NodeColumnSorted( QgsSQLStatement::NodeColumnRef *column SIP_TRANSFER, bool asc ) : mColumn( column ), mAsc( asc ) {}
707 ~NodeColumnSorted() override { delete mColumn; }
708
710 QgsSQLStatement::NodeColumnRef *column() const { return mColumn; }
711
713 bool ascending() const { return mAsc; }
714
715 QgsSQLStatement::NodeType nodeType() const override { return ntColumnSorted; }
716 QString dump() const override;
717
718 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
719 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
721 QgsSQLStatement::NodeColumnSorted *cloneThis() const SIP_FACTORY;
722
723 protected:
724 NodeColumnRef *mColumn = nullptr;
725 bool mAsc;
726 };
727
732 class CORE_EXPORT NodeSelect : public QgsSQLStatement::Node
733 {
734 public:
736 NodeSelect( const QList<QgsSQLStatement::NodeTableDef *> &tableList SIP_TRANSFER, const QList<QgsSQLStatement::NodeSelectedColumn *> &columns SIP_TRANSFER, bool distinct ) : mTableList( tableList ), mColumns( columns ), mDistinct( distinct ) {}
737 ~NodeSelect() override;
738
740 void setJoins( const QList<QgsSQLStatement::NodeJoin *> &joins SIP_TRANSFER ) { qDeleteAll( mJoins ); mJoins = joins; }
742 void appendJoin( QgsSQLStatement::NodeJoin *join SIP_TRANSFER ) { mJoins.append( join ); }
744 void setWhere( QgsSQLStatement::Node *where SIP_TRANSFER ) { delete mWhere; mWhere = where; }
746 void setOrderBy( const QList<QgsSQLStatement::NodeColumnSorted *> &orderBy SIP_TRANSFER ) { qDeleteAll( mOrderBy ); mOrderBy = orderBy; }
747
749 QList<QgsSQLStatement::NodeTableDef *> tables() const { return mTableList; }
751 QList<QgsSQLStatement::NodeSelectedColumn *> columns() const { return mColumns; }
753 bool distinct() const { return mDistinct; }
755 QList<QgsSQLStatement::NodeJoin *> joins() const { return mJoins; }
757 QgsSQLStatement::Node *where() const { return mWhere; }
759 QList<QgsSQLStatement::NodeColumnSorted *> orderBy() const { return mOrderBy; }
760
761 QgsSQLStatement::NodeType nodeType() const override { return ntSelect; }
762 QString dump() const override;
763
764 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
765 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
766
767 protected:
768 QList<NodeTableDef *> mTableList;
769 QList<NodeSelectedColumn *> mColumns;
770 bool mDistinct;
771 QList<NodeJoin *> mJoins;
772 Node *mWhere = nullptr;
773 QList<NodeColumnSorted *> mOrderBy;
774 };
775
777
783 class CORE_EXPORT Visitor
784 {
785 public:
786 virtual ~Visitor() = default;
788 virtual void visit( const QgsSQLStatement::NodeUnaryOperator &n ) = 0;
790 virtual void visit( const QgsSQLStatement::NodeBinaryOperator &n ) = 0;
792 virtual void visit( const QgsSQLStatement::NodeInOperator &n ) = 0;
794 virtual void visit( const QgsSQLStatement::NodeBetweenOperator &n ) = 0;
796 virtual void visit( const QgsSQLStatement::NodeFunction &n ) = 0;
798 virtual void visit( const QgsSQLStatement::NodeLiteral &n ) = 0;
800 virtual void visit( const QgsSQLStatement::NodeColumnRef &n ) = 0;
802 virtual void visit( const QgsSQLStatement::NodeSelectedColumn &n ) = 0;
804 virtual void visit( const QgsSQLStatement::NodeTableDef &n ) = 0;
806 virtual void visit( const QgsSQLStatement::NodeSelect &n ) = 0;
808 virtual void visit( const QgsSQLStatement::NodeJoin &n ) = 0;
810 virtual void visit( const QgsSQLStatement::NodeColumnSorted &n ) = 0;
812 virtual void visit( const QgsSQLStatement::NodeCast &n ) = 0;
813 };
814
820 {
821 public:
822
823 RecursiveVisitor() = default;
824
825 void visit( const QgsSQLStatement::NodeUnaryOperator &n ) override { n.operand()->accept( *this ); }
826 void visit( const QgsSQLStatement::NodeBinaryOperator &n ) override { n.opLeft()->accept( *this ); n.opRight()->accept( *this ); }
827 void visit( const QgsSQLStatement::NodeInOperator &n ) override { n.node()->accept( *this ); n.list()->accept( *this ); }
828 void visit( const QgsSQLStatement::NodeBetweenOperator &n ) override { n.node()->accept( *this ); n.minVal()->accept( *this ); n.maxVal()->accept( *this ); }
829 void visit( const QgsSQLStatement::NodeFunction &n ) override { n.args()->accept( *this ); }
830 void visit( const QgsSQLStatement::NodeLiteral & ) override {}
831 void visit( const QgsSQLStatement::NodeColumnRef & ) override { }
832 void visit( const QgsSQLStatement::NodeSelectedColumn &n ) override { n.column()->accept( *this ); }
833 void visit( const QgsSQLStatement::NodeTableDef & ) override {}
834 void visit( const QgsSQLStatement::NodeSelect &n ) override;
835 void visit( const QgsSQLStatement::NodeJoin &n ) override;
836 void visit( const QgsSQLStatement::NodeColumnSorted &n ) override { n.column()->accept( *this ); }
837 void visit( const QgsSQLStatement::NodeCast &n ) override { n.node()->accept( *this ); }
838 };
839
841 void acceptVisitor( QgsSQLStatement::Visitor &v ) const;
842
843 protected:
844 QgsSQLStatement::Node *mRootNode = nullptr;
845 bool mAllowFragments = false;
846 QString mStatement;
848
857 QgsSQLStatement( const QString &statement, bool allowFragments );
858};
859
861
862
867class CORE_EXPORT QgsSQLStatementFragment : public QgsSQLStatement
868{
869 public:
870
874 QgsSQLStatementFragment( const QString &fragment );
875
876};
877
878
879#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)