QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 <memory>
21
22#include "qgis_core.h"
23#include "qgis_sip.h"
24
25#include <QCoreApplication>
26#include <QList>
27#include <QMetaType>
28#include <QSet>
29#include <QStringList>
30#include <QVariant>
31
36class CORE_EXPORT QgsSQLStatement
37{
38 Q_DECLARE_TR_FUNCTIONS( QgsSQLStatement )
39 public:
40
41 * Creates a new statement based on the provided string.
42 */
43 QgsSQLStatement( const QString &statement );
44
45 QgsSQLStatement( const QgsSQLStatement &other );
46
48 virtual ~QgsSQLStatement();
49
51 bool hasParserError() const;
53 QString parserErrorString() const;
54
58
60 bool doBasicValidationChecks( QString &errorMsgOut SIP_OUT ) const;
61
62 class Node;
63
68 const QgsSQLStatement::Node *rootNode() const;
69
75 QString statement() const;
76
83 QString dump() const;
84
90 static QString quotedIdentifier( QString name );
91
98 static QString quotedIdentifierIfNeeded( const QString &name );
99
104 static QString stripQuotedIdentifier( QString text );
105
110 static QString stripMsQuotedIdentifier( QString text );
111
117 static QString quotedString( QString text );
118
128
134 {
135 // logical
138
139 // comparison
140 boEQ, // =
141 boNE, // <>
142 boLE, // <=
143 boGE, // >=
144 boLT, // <
145 boGT, // >
152
153 // math
161
162 // strings
164 };
165
181
183 static const char *BINARY_OPERATOR_TEXT[] SIP_SKIP;
184
186 static const char *UNARY_OPERATOR_TEXT[] SIP_SKIP;
187
189 static const char *JOIN_TYPE_TEXT[] SIP_SKIP;
190
192
193 class Visitor; // visitor interface is defined below
194
212
217 class CORE_EXPORT Node
218 {
219#ifdef SIP_RUN
221 switch ( sipCpp->nodeType() )
222 {
224 sipType = sipType_QgsSQLStatement_NodeUnaryOperator;
225 break;
227 sipType = sipType_QgsSQLStatement_NodeBinaryOperator;
228 break;
230 sipType = sipType_QgsSQLStatement_NodeInOperator;
231 break;
233 sipType = sipType_QgsSQLStatement_NodeBetweenOperator;
234 break;
236 sipType = sipType_QgsSQLStatement_NodeFunction;
237 break;
239 sipType = sipType_QgsSQLStatement_NodeLiteral;
240 break;
242 sipType = sipType_QgsSQLStatement_NodeColumnRef;
243 break;
245 sipType = sipType_QgsSQLStatement_NodeSelectedColumn;
246 break;
248 sipType = sipType_QgsSQLStatement_NodeSelect;
249 break;
251 sipType = sipType_QgsSQLStatement_NodeTableDef;
252 break;
254 sipType = sipType_QgsSQLStatement_NodeJoin;
255 break;
257 sipType = sipType_QgsSQLStatement_NodeColumnSorted;
258 break;
260 sipType = sipType_QgsSQLStatement_NodeCast;
261 break;
262 default:
263 sipType = 0;
264 break;
265 }
266 SIP_END
267#endif
268
269 public:
270 virtual ~Node() = default;
271
278
284 virtual QString dump() const = 0;
285
295
311 virtual void accept( QgsSQLStatement::Visitor &v ) const = 0;
312 };
313
318 class CORE_EXPORT NodeList
319 {
320 public:
321 NodeList() = default;
322 virtual ~NodeList() { qDeleteAll( mList ); }
323
325 void append( QgsSQLStatement::Node *node SIP_TRANSFER ) { mList.append( node ); }
326
328 QList<QgsSQLStatement::Node *> list() { return mList; }
329
333 int count() const { return mList.count(); }
334
336 void accept( QgsSQLStatement::Visitor &v ) const;
337
340
342 virtual QString dump() const;
343
344 protected:
345 QList<Node *> mList;
346 };
347
352 class CORE_EXPORT NodeUnaryOperator : public QgsSQLStatement::Node
353 {
354 public:
360
363
365 QgsSQLStatement::Node *operand() const { return mOperand.get(); }
366
368 QString dump() const override;
369
370 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
371 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
372
373 private:
374 NodeUnaryOperator( const NodeUnaryOperator &other ) = delete;
375 NodeUnaryOperator &operator=( const NodeUnaryOperator &other ) = delete;
376
377#ifdef SIP_RUN
378 NodeUnaryOperator( const NodeUnaryOperator &other );
379#endif
380
381 protected:
383 std::unique_ptr<Node> mOperand;
384 };
385
390 class CORE_EXPORT NodeBinaryOperator : public QgsSQLStatement::Node
391 {
392 public:
399
402
404 QgsSQLStatement::Node *opLeft() const { return mOpLeft.get(); }
405
407 QgsSQLStatement::Node *opRight() const { return mOpRight.get(); }
408
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
416 int precedence() const;
417
419 bool leftAssociative() const;
420
421 private:
422 NodeBinaryOperator( const NodeBinaryOperator &other ) = delete;
423 NodeBinaryOperator &operator=( const NodeBinaryOperator &other ) = delete;
424
425#ifdef SIP_RUN
427#endif
428
429 protected:
431 std::unique_ptr<Node> mOpLeft;
432 std::unique_ptr<Node> mOpRight;
433 };
434
439 class CORE_EXPORT NodeInOperator : public QgsSQLStatement::Node
440 {
441 public:
448
450 QgsSQLStatement::Node *node() const { return mNode.get(); }
451
453 bool isNotIn() const { return mNotIn; }
454
456 QgsSQLStatement::NodeList *list() const { return mList.get(); }
457
459 QString dump() const override;
460
461 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
462 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
463
464 private:
465 NodeInOperator( const NodeInOperator &other ) = delete;
466 NodeInOperator &operator=( const NodeInOperator &other ) = delete;
467
468#ifdef SIP_RUN
469 NodeInOperator( const NodeInOperator &other );
470#endif
471
472 protected:
473 std::unique_ptr<Node> mNode;
474 std::unique_ptr<NodeList> mList;
475 bool mNotIn;
476 };
477
483 {
484 public:
492
494 QgsSQLStatement::Node *node() const { return mNode.get(); }
495
497 bool isNotBetween() const { return mNotBetween; }
498
500 QgsSQLStatement::Node *minVal() const { return mMinVal.get(); }
501
503 QgsSQLStatement::Node *maxVal() const { return mMaxVal.get(); }
504
506 QString dump() const override;
507
508 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
509 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
510
511 private:
512 NodeBetweenOperator( const NodeBetweenOperator &other ) = delete;
513 NodeBetweenOperator &operator=( const NodeBetweenOperator &other ) = delete;
514
515#ifdef SIP_RUN
517#endif
518
519 protected:
520 std::unique_ptr<Node> mNode;
521 std::unique_ptr<Node> mMinVal;
522 std::unique_ptr<Node> mMaxVal;
524 };
525
530 class CORE_EXPORT NodeFunction : public QgsSQLStatement::Node
531 {
532 public:
535 : mName( name )
536 , mArgs( args )
537 {}
538
540 QString name() const { return mName; }
541
543 QgsSQLStatement::NodeList *args() const { return mArgs.get(); }
544
545 QgsSQLStatement::NodeType nodeType() const override { return ntFunction; }
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 private:
552 NodeFunction( const NodeFunction &other ) = delete;
553 NodeFunction &operator=( const NodeFunction &other ) = delete;
554
555#ifdef SIP_RUN
556 NodeFunction( const NodeFunction &other );
557#endif
558
559 protected:
560 QString mName;
561 std::unique_ptr<NodeList> mArgs;
562 };
563
568 class CORE_EXPORT NodeLiteral : public QgsSQLStatement::Node
569 {
570 public:
572 NodeLiteral( const QVariant &value )
573 : mValue( value )
574 {}
575
577 inline QVariant value() const { return mValue; }
578
579 QgsSQLStatement::NodeType nodeType() const override { return ntLiteral; }
580 QString dump() const override;
581
582 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
583 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
584
585 protected:
586 QVariant mValue;
587 };
588
593 class CORE_EXPORT NodeColumnRef : public QgsSQLStatement::Node
594 {
595 public:
597 NodeColumnRef( const QString &name, bool star )
598 : mName( name )
599 , mDistinct( false )
600 , mStar( star )
601 {}
602
603 NodeColumnRef( const QString &tableName, const QString &name, bool star )
605 , mName( name )
606 , mDistinct( false )
607 , mStar( star )
608 {}
609
611 void setDistinct( bool distinct = true ) { mDistinct = distinct; }
612
614 QString tableName() const { return mTableName; }
615
617 QString name() const { return mName; }
618
620 bool star() const { return mStar; }
621
623 bool distinct() const { return mDistinct; }
624
625 QgsSQLStatement::NodeType nodeType() const override { return ntColumnRef; }
626 QString dump() const override;
627
628 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
629 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
631 QgsSQLStatement::NodeColumnRef *cloneThis() const SIP_FACTORY;
632
633 protected:
634 QString mTableName;
635 QString mName;
637 bool mStar;
638 };
639
644 class CORE_EXPORT NodeSelectedColumn : public QgsSQLStatement::Node
645 {
646 public:
651
653 void setAlias( const QString &alias ) { mAlias = alias; }
654
656 QgsSQLStatement::Node *column() const { return mColumnNode.get(); }
657
659 QString alias() const { return mAlias; }
660
662 QString dump() const override;
663
664 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
665 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
668
669 private:
670 NodeSelectedColumn( const NodeSelectedColumn &other ) = delete;
671 NodeSelectedColumn &operator=( const NodeSelectedColumn &other ) = delete;
672
673#ifdef SIP_RUN
675#endif
676
677 protected:
678 std::unique_ptr<Node> mColumnNode;
679 QString mAlias;
680 };
681
686 class CORE_EXPORT NodeCast : public QgsSQLStatement::Node
687 {
688 public:
691 : mNode( node )
692 , mType( type )
693 {}
694
696 QgsSQLStatement::Node *node() const { return mNode.get(); }
697
699 QString type() const { return mType; }
700
701 QgsSQLStatement::NodeType nodeType() const override { return ntCast; }
702 QString dump() const override;
703
704 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
705 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
706
707 private:
708 NodeCast( const NodeCast &other ) = delete;
709 NodeCast &operator=( const NodeCast &other ) = delete;
710
711#ifdef SIP_RUN
712 NodeCast( const NodeCast &other );
713#endif
714
715 protected:
716 std::unique_ptr<Node> mNode;
717 QString mType;
718 };
719
724 class CORE_EXPORT NodeTableDef : public QgsSQLStatement::Node
725 {
726 public:
728 NodeTableDef( const QString &name )
729 : mName( name )
730 {}
731
732 NodeTableDef( const QString &name, const QString &alias )
733 : mName( name )
734 , mAlias( alias )
735 {}
736
741 NodeTableDef( const QString &schema, const QString &name, const QString &alias )
742 : mName( name )
743 , mSchema( schema )
744 , mAlias( alias )
745 {}
746
748 QString name() const { return mName; }
749
755 QString schema() const { return mSchema; }
756
758 QString alias() const { return mAlias; }
759
760 QgsSQLStatement::NodeType nodeType() const override { return ntTableDef; }
761 QString dump() const override;
762
763 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
764 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
766 QgsSQLStatement::NodeTableDef *cloneThis() const SIP_FACTORY;
767
768 protected:
769 QString mName;
770 QString mSchema;
771 QString mAlias;
772 };
773
778 class CORE_EXPORT NodeJoin : public QgsSQLStatement::Node
779 {
780 public:
787
789 : mTableDef( tabledef )
791 , mType( type )
792 {}
793
796
798 QgsSQLStatement::Node *onExpr() const { return mOnExpr.get(); }
799
801 QList<QString> usingColumns() const { return mUsingColumns; }
802
805
806 QgsSQLStatement::NodeType nodeType() const override { return ntJoin; }
807 QString dump() const override;
808
809 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
810 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
812 QgsSQLStatement::NodeJoin *cloneThis() const SIP_FACTORY;
813
814 private:
815 NodeJoin( const NodeJoin &other ) = delete;
816 NodeJoin &operator=( const NodeJoin &other ) = delete;
817
818#ifdef SIP_RUN
819 NodeJoin( const NodeJoin &other );
820#endif
821
822 protected:
823 std::unique_ptr<NodeTableDef> mTableDef;
824 std::unique_ptr<Node> mOnExpr;
825 QList<QString> mUsingColumns;
827 };
828
833 class CORE_EXPORT NodeColumnSorted : public QgsSQLStatement::Node
834 {
835 public:
841
844
846 bool ascending() const { return mAsc; }
847
849 QString dump() const override;
850
851 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
852 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
854 QgsSQLStatement::NodeColumnSorted *cloneThis() const SIP_FACTORY;
855
856 private:
857 NodeColumnSorted( const NodeColumnSorted &other ) = delete;
858 NodeColumnSorted &operator=( const NodeColumnSorted &other ) = delete;
859
860#ifdef SIP_RUN
861 NodeColumnSorted( const NodeColumnSorted &other );
862#endif
863
864 protected:
865 std::unique_ptr<NodeColumnRef> mColumn;
866 bool mAsc;
867 };
868
873 class CORE_EXPORT NodeSelect : public QgsSQLStatement::Node
874 {
875 public:
877 NodeSelect( const QList<QgsSQLStatement::NodeTableDef *> &tableList SIP_TRANSFER, const QList<QgsSQLStatement::NodeSelectedColumn *> &columns SIP_TRANSFER, bool distinct )
878 : mTableList( tableList )
879 , mColumns( columns )
881 {}
882 ~NodeSelect() override;
883
885 void setJoins( const QList<QgsSQLStatement::NodeJoin *> &joins SIP_TRANSFER )
886 {
887 qDeleteAll( mJoins );
888 mJoins = joins;
889 }
890
891 void appendJoin( QgsSQLStatement::NodeJoin *join SIP_TRANSFER ) { mJoins.append( join ); }
895 void setOrderBy( const QList<QgsSQLStatement::NodeColumnSorted *> &orderBy SIP_TRANSFER )
896 {
897 qDeleteAll( mOrderBy );
899 }
900
902 QList<QgsSQLStatement::NodeTableDef *> tables() const { return mTableList; }
904 QList<QgsSQLStatement::NodeSelectedColumn *> columns() const { return mColumns; }
906 bool distinct() const { return mDistinct; }
908 QList<QgsSQLStatement::NodeJoin *> joins() const { return mJoins; }
910 QgsSQLStatement::Node *where() const { return mWhere.get(); }
912 QList<QgsSQLStatement::NodeColumnSorted *> orderBy() const { return mOrderBy; }
913
914 QgsSQLStatement::NodeType nodeType() const override { return ntSelect; }
915 QString dump() const override;
916
917 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
918 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
919
920 private:
921 NodeSelect( const NodeSelect &other ) = delete;
922 NodeSelect &operator=( const NodeSelect &other ) = delete;
923
924#ifdef SIP_RUN
925 NodeSelect( const NodeSelect &other );
926#endif
927
928 protected:
929 QList<NodeTableDef *> mTableList;
930 QList<NodeSelectedColumn *> mColumns;
932 QList<NodeJoin *> mJoins;
933 std::unique_ptr<Node> mWhere;
934 QList<NodeColumnSorted *> mOrderBy;
935 };
936
938
944 class CORE_EXPORT Visitor
945 {
946 public:
947 virtual ~Visitor() = default;
949 virtual void visit( const QgsSQLStatement::NodeUnaryOperator &n ) = 0;
951 virtual void visit( const QgsSQLStatement::NodeBinaryOperator &n ) = 0;
953 virtual void visit( const QgsSQLStatement::NodeInOperator &n ) = 0;
955 virtual void visit( const QgsSQLStatement::NodeBetweenOperator &n ) = 0;
957 virtual void visit( const QgsSQLStatement::NodeFunction &n ) = 0;
959 virtual void visit( const QgsSQLStatement::NodeLiteral &n ) = 0;
961 virtual void visit( const QgsSQLStatement::NodeColumnRef &n ) = 0;
963 virtual void visit( const QgsSQLStatement::NodeSelectedColumn &n ) = 0;
965 virtual void visit( const QgsSQLStatement::NodeTableDef &n ) = 0;
967 virtual void visit( const QgsSQLStatement::NodeSelect &n ) = 0;
969 virtual void visit( const QgsSQLStatement::NodeJoin &n ) = 0;
971 virtual void visit( const QgsSQLStatement::NodeColumnSorted &n ) = 0;
973 virtual void visit( const QgsSQLStatement::NodeCast &n ) = 0;
974 };
975
981 {
982 public:
983 RecursiveVisitor() = default;
984
985 void visit( const QgsSQLStatement::NodeUnaryOperator &n ) override { n.operand()->accept( *this ); }
987 {
988 n.opLeft()->accept( *this );
989 n.opRight()->accept( *this );
990 }
991 void visit( const QgsSQLStatement::NodeInOperator &n ) override
992 {
993 n.node()->accept( *this );
994 n.list()->accept( *this );
995 }
997 {
998 n.node()->accept( *this );
999 n.minVal()->accept( *this );
1000 n.maxVal()->accept( *this );
1001 }
1002 void visit( const QgsSQLStatement::NodeFunction &n ) override { n.args()->accept( *this ); }
1003 void visit( const QgsSQLStatement::NodeLiteral & ) override {}
1004 void visit( const QgsSQLStatement::NodeColumnRef & ) override {}
1005 void visit( const QgsSQLStatement::NodeSelectedColumn &n ) override { n.column()->accept( *this ); }
1006 void visit( const QgsSQLStatement::NodeTableDef & ) override {}
1007 void visit( const QgsSQLStatement::NodeSelect &n ) override;
1008 void visit( const QgsSQLStatement::NodeJoin &n ) override;
1009 void visit( const QgsSQLStatement::NodeColumnSorted &n ) override { n.column()->accept( *this ); }
1010 void visit( const QgsSQLStatement::NodeCast &n ) override { n.node()->accept( *this ); }
1011 };
1012
1014 void acceptVisitor( QgsSQLStatement::Visitor &v ) const;
1015
1016 protected:
1017 std::unique_ptr<QgsSQLStatement::Node> mRootNode;
1018 bool mAllowFragments = false;
1019 QString mStatement;
1021
1030 QgsSQLStatement( const QString &statement, bool allowFragments );
1031};
1032
1034
1035
1041{
1042 public:
1046 QgsSQLStatementFragment( const QString &fragment );
1047};
1048
1049
1050#endif // QGSSQLSTATEMENT_H
QgsSQLStatementFragment(const QString &fragment)
Constructor for QgsSQLStatementFragment of the specified fragment.
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.
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.
bool doBasicValidationChecks(QString &errorMsgOut) const
Performs basic validity checks.
JoinType
list of join types
BinaryOperator
list of binary operators
static QString stripQuotedIdentifier(QString text)
Remove double quotes from an identifier.
static QString quotedIdentifierIfNeeded(const QString &name)
Returns a quoted column reference (in double quotes) if needed, or otherwise the original string.
static QString quotedIdentifier(QString name)
Returns a quoted column reference (in double quotes).
QString parserErrorString() const
Returns parser error.
QgsSQLStatement & operator=(const QgsSQLStatement &other)
static QString stripMsQuotedIdentifier(QString text)
Remove double quotes from an Microsoft style identifier.
static QString quotedString(QString text)
Returns a quoted version of a string (in single quotes).
QString dump() const
Returns the statement string, constructed from the internal abstract syntax tree.
std::unique_ptr< QgsSQLStatement::Node > mRootNode
UnaryOperator
list of unary operators
bool hasParserError() const
Returns true if an error occurred when parsing the input statement.
const QgsSQLStatement::Node * rootNode() const
Returns the root node of the statement.
QString statement() const
Returns the original, unmodified statement string.
QgsSQLStatement(const QString &statement)
Creates a new statement based on the provided string.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:198
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_END
Definition qgis_sip.h:215
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)