QGIS API Documentation 4.1.0-Master (659fe69c07c)
Loading...
Searching...
No Matches
qgssqlstatement.h
Go to the documentation of this file.
1
2/***************************************************************************
3 qgssqlstatement.h
4 ---------------------
5 begin : April 2016
6 copyright : (C) 2011 by Martin Dobias
7 copyright : (C) 2016 by Even Rouault
8 email : even.rouault at spatialys.com
9 ***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSSQLSTATEMENT_H
19#define QGSSQLSTATEMENT_H
20
21#include <memory>
22
23#include "qgis_core.h"
24#include "qgis_sip.h"
25
26#include <QCoreApplication>
27#include <QList>
28#include <QMetaType>
29#include <QSet>
30#include <QString>
31#include <QStringList>
32#include <QVariant>
33
34using namespace Qt::StringLiterals;
35
37 * \ingroup core
38 * \brief Parses SQL statements.
39 */
40class CORE_EXPORT QgsSQLStatement
41{
42 Q_DECLARE_TR_FUNCTIONS( QgsSQLStatement )
43 public:
47 QgsSQLStatement( const QString &statement );
49 QgsSQLStatement( const QgsSQLStatement &other );
50
52 virtual ~QgsSQLStatement();
53
55 bool hasParserError() const;
57 QString parserErrorString() const;
58
59
64 bool doBasicValidationChecks( QString &errorMsgOut SIP_OUT ) const;
65
66 class Node;
67
72 const QgsSQLStatement::Node *rootNode() const;
73
79 QString statement() const;
80
87 QString dump() const;
88
94 static QString quotedIdentifier( QString name );
95
102 static QString quotedIdentifierIfNeeded( const QString &name );
103
108 static QString stripQuotedIdentifier( QString text );
109
114 static QString stripMsQuotedIdentifier( QString text );
115
121 static QString quotedString( QString text );
122
132
169
185
187 static const char *BINARY_OPERATOR_TEXT[] SIP_SKIP;
188
190 static const char *UNARY_OPERATOR_TEXT[] SIP_SKIP;
191
193 static const char *JOIN_TYPE_TEXT[] SIP_SKIP;
194
196
197 class Visitor; // visitor interface is defined below
198
216
221 class CORE_EXPORT Node
222 {
223#ifdef SIP_RUN
225 switch ( sipCpp->nodeType() )
226 {
228 sipType = sipType_QgsSQLStatement_NodeUnaryOperator;
229 break;
231 sipType = sipType_QgsSQLStatement_NodeBinaryOperator;
232 break;
234 sipType = sipType_QgsSQLStatement_NodeInOperator;
235 break;
237 sipType = sipType_QgsSQLStatement_NodeBetweenOperator;
238 break;
240 sipType = sipType_QgsSQLStatement_NodeFunction;
241 break;
243 sipType = sipType_QgsSQLStatement_NodeLiteral;
244 break;
246 sipType = sipType_QgsSQLStatement_NodeColumnRef;
247 break;
249 sipType = sipType_QgsSQLStatement_NodeSelectedColumn;
250 break;
252 sipType = sipType_QgsSQLStatement_NodeSelect;
253 break;
255 sipType = sipType_QgsSQLStatement_NodeTableDef;
256 break;
258 sipType = sipType_QgsSQLStatement_NodeJoin;
259 break;
261 sipType = sipType_QgsSQLStatement_NodeColumnSorted;
262 break;
264 sipType = sipType_QgsSQLStatement_NodeCast;
265 break;
266 default:
267 sipType = 0;
268 break;
269 }
270 SIP_END
271#endif
272
273 public:
274 virtual ~Node() = default;
275
282
288 virtual QString dump() const = 0;
289
299
315 virtual void accept( QgsSQLStatement::Visitor &v ) const = 0;
316 };
317
322 class CORE_EXPORT NodeList
323 {
324 public:
325 NodeList() = default;
326 virtual ~NodeList() { qDeleteAll( mList ); }
327
329 void append( QgsSQLStatement::Node *node SIP_TRANSFER ) { mList.append( node ); }
330
332 QList<QgsSQLStatement::Node *> list() { return mList; }
333
337 int count() const { return mList.count(); }
338
340 void accept( QgsSQLStatement::Visitor &v ) const;
341
344
346 virtual QString dump() const;
347
348 protected:
349 QList<Node *> mList;
350 };
351
356 class CORE_EXPORT NodeUnaryOperator : public QgsSQLStatement::Node
357 {
358 public:
364
365#ifdef SIP_RUN
366 SIP_PYOBJECT __repr__();
367 % MethodCode QString str = u"<QgsSQLStatement.NodeUnaryOperator: %1>"_s.arg( sipCpp->text() );
368 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
369 % End
370#endif
371
374 {
375 return mOp;
376 }
377
379 QgsSQLStatement::Node *operand() const { return mOperand.get(); }
380
382 QString dump() const override;
383
384 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
385 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
386
393 QString text() const;
394
395 private:
396 NodeUnaryOperator( const NodeUnaryOperator &other ) = delete;
397 NodeUnaryOperator &operator=( const NodeUnaryOperator &other ) = delete;
398
399#ifdef SIP_RUN
400 NodeUnaryOperator( const NodeUnaryOperator &other );
401#endif
402
403 protected:
405 std::unique_ptr<Node> mOperand;
406 };
407
412 class CORE_EXPORT NodeBinaryOperator : public QgsSQLStatement::Node
413 {
414 public:
421
422#ifdef SIP_RUN
423 SIP_PYOBJECT __repr__();
424 % MethodCode QString str = u"<QgsSQLStatement.NodeBinaryOperator: %1>"_s.arg( sipCpp->text() );
425 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
426 % End
427#endif
428
431 {
432 return mOp;
433 }
434
436 QgsSQLStatement::Node *opLeft() const { return mOpLeft.get(); }
437
439 QgsSQLStatement::Node *opRight() const { return mOpRight.get(); }
440
442 QString dump() const override;
443
444 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
445 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
446
448 int precedence() const;
449
451 bool leftAssociative() const;
452
459 QString text() const;
460
461 private:
462 NodeBinaryOperator( const NodeBinaryOperator &other ) = delete;
463 NodeBinaryOperator &operator=( const NodeBinaryOperator &other ) = delete;
464
465#ifdef SIP_RUN
467#endif
468
469 protected:
471 std::unique_ptr<Node> mOpLeft;
472 std::unique_ptr<Node> mOpRight;
473 };
474
479 class CORE_EXPORT NodeInOperator : public QgsSQLStatement::Node
480 {
481 public:
488
490 QgsSQLStatement::Node *node() const { return mNode.get(); }
491
493 bool isNotIn() const { return mNotIn; }
494
496 QgsSQLStatement::NodeList *list() const { return mList.get(); }
497
499 QString dump() const override;
500
501 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
502 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
503
504 private:
505 NodeInOperator( const NodeInOperator &other ) = delete;
506 NodeInOperator &operator=( const NodeInOperator &other ) = delete;
507
508#ifdef SIP_RUN
509 NodeInOperator( const NodeInOperator &other );
510#endif
511
512 protected:
513 std::unique_ptr<Node> mNode;
514 std::unique_ptr<NodeList> mList;
515 bool mNotIn;
516 };
517
523 {
524 public:
532
534 QgsSQLStatement::Node *node() const { return mNode.get(); }
535
537 bool isNotBetween() const { return mNotBetween; }
538
540 QgsSQLStatement::Node *minVal() const { return mMinVal.get(); }
541
543 QgsSQLStatement::Node *maxVal() const { return mMaxVal.get(); }
544
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 NodeBetweenOperator( const NodeBetweenOperator &other ) = delete;
553 NodeBetweenOperator &operator=( const NodeBetweenOperator &other ) = delete;
554
555#ifdef SIP_RUN
557#endif
558
559 protected:
560 std::unique_ptr<Node> mNode;
561 std::unique_ptr<Node> mMinVal;
562 std::unique_ptr<Node> mMaxVal;
564 };
565
570 class CORE_EXPORT NodeFunction : public QgsSQLStatement::Node
571 {
572 public:
575 : mName( name )
576 , mArgs( args )
577 {}
578
579
580#ifdef SIP_RUN
581 SIP_PYOBJECT __repr__();
582 % MethodCode QString function;
583 QString str = u"<QgsSQLStatement.NodeFunction: %1>"_s.arg( sipCpp->name() );
584 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
585 % End
586#endif
587
589 QString name() const
590 {
591 return mName;
592 }
593
595 QgsSQLStatement::NodeList *args() const { return mArgs.get(); }
596
597 QgsSQLStatement::NodeType nodeType() const override { return ntFunction; }
598 QString dump() const override;
599
600 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
601 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
602
603 private:
604 NodeFunction( const NodeFunction &other ) = delete;
605 NodeFunction &operator=( const NodeFunction &other ) = delete;
606
607#ifdef SIP_RUN
608 NodeFunction( const NodeFunction &other );
609#endif
610
611 protected:
612 QString mName;
613 std::unique_ptr<NodeList> mArgs;
614 };
615
620 class CORE_EXPORT NodeLiteral : public QgsSQLStatement::Node
621 {
622 public:
624 NodeLiteral( const QVariant &value )
625 : mValue( value )
626 {}
627
628#ifdef SIP_RUN
629 SIP_PYOBJECT __repr__();
630 % MethodCode QString str = u"<QgsSQLStatement.NodeLiteral: %1>"_s.arg( sipCpp->valueAsString() );
631 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
632 % End
633#endif
634
636 inline QVariant value() const
637 {
638 return mValue;
639 }
640
641 QgsSQLStatement::NodeType nodeType() const override { return ntLiteral; }
642 QString dump() const override;
643
644 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
645 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
646
651 QString valueAsString() const;
652
653
654 protected:
655 QVariant mValue;
656 };
657
662 class CORE_EXPORT NodeColumnRef : public QgsSQLStatement::Node
663 {
664 public:
666 NodeColumnRef( const QString &name, bool star )
667 : mName( name )
668 , mDistinct( false )
669 , mStar( star )
670 {}
671
672 NodeColumnRef( const QString &tableName, const QString &name, bool star )
674 , mName( name )
675 , mDistinct( false )
676 , mStar( star )
677 {}
678
679#ifdef SIP_RUN
680 SIP_PYOBJECT __repr__();
681 % MethodCode QString columnRef;
682 if ( sipCpp->star() )
683 {
684 columnRef = "*";
685 }
686 else
687 {
688 columnRef = sipCpp->name();
689 }
690 if ( !sipCpp->tableName().isEmpty() )
691 {
692 columnRef = u"\"%1.%2\""_s.arg( sipCpp->tableName(), columnRef );
693 }
694 if ( sipCpp->distinct() )
695 {
696 columnRef = u"DISTINCT %1"_s.arg( columnRef );
697 }
698 QString str = u"<QgsSQLStatement.NodeColumnRef: %1>"_s.arg( columnRef );
699 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
700 % End
701#endif
702
704 void setDistinct( bool distinct = true )
705 {
707 }
708
710 QString tableName() const { return mTableName; }
711
713 QString name() const { return mName; }
714
716 bool star() const { return mStar; }
717
719 bool distinct() const { return mDistinct; }
720
721 QgsSQLStatement::NodeType nodeType() const override { return ntColumnRef; }
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::NodeColumnRef *cloneThis() const SIP_FACTORY;
728
729 protected:
730 QString mTableName;
731 QString mName;
733 bool mStar;
734 };
735
740 class CORE_EXPORT NodeSelectedColumn : public QgsSQLStatement::Node
741 {
742 public:
747
749 void setAlias( const QString &alias ) { mAlias = alias; }
750
752 QgsSQLStatement::Node *column() const { return mColumnNode.get(); }
753
755 QString alias() const { return mAlias; }
756
758 QString dump() const override;
759
760 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
761 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
764
765 private:
766 NodeSelectedColumn( const NodeSelectedColumn &other ) = delete;
767 NodeSelectedColumn &operator=( const NodeSelectedColumn &other ) = delete;
768
769#ifdef SIP_RUN
771#endif
772
773 protected:
774 std::unique_ptr<Node> mColumnNode;
775 QString mAlias;
776 };
777
782 class CORE_EXPORT NodeCast : public QgsSQLStatement::Node
783 {
784 public:
787 : mNode( node )
788 , mType( type )
789 {}
790
791#ifdef SIP_RUN
792 SIP_PYOBJECT __repr__();
793 % MethodCode QString str = u"<QgsSQLStatement.NodeCast: AS %1>"_s.arg( sipCpp->type() );
794 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
795 % End
796#endif
797
800 {
801 return mNode.get();
802 }
803
805 QString type() const { return mType; }
806
807 QgsSQLStatement::NodeType nodeType() const override { return ntCast; }
808 QString dump() const override;
809
810 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
811 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
812
813 private:
814 NodeCast( const NodeCast &other ) = delete;
815 NodeCast &operator=( const NodeCast &other ) = delete;
816
817#ifdef SIP_RUN
818 NodeCast( const NodeCast &other );
819#endif
820
821 protected:
822 std::unique_ptr<Node> mNode;
823 QString mType;
824 };
825
830 class CORE_EXPORT NodeTableDef : public QgsSQLStatement::Node
831 {
832 public:
834 NodeTableDef( const QString &name )
835 : mName( name )
836 {}
837
838 NodeTableDef( const QString &name, const QString &alias )
839 : mName( name )
840 , mAlias( alias )
841 {}
842
847 NodeTableDef( const QString &schema, const QString &name, const QString &alias )
848 : mName( name )
849 , mSchema( schema )
850 , mAlias( alias )
851 {}
852
853#ifdef SIP_RUN
854 SIP_PYOBJECT __repr__();
855 % MethodCode QString table;
856 if ( !sipCpp->schema().isEmpty() )
857 {
858 table = u"%1.%2"_s.arg( sipCpp->schema(), sipCpp->name() );
859 }
860 else
861 {
862 table = sipCpp->name();
863 }
864 QString str = u"<QgsSQLStatement.NodeTableDef: %1>"_s.arg( table );
865 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
866 % End
867#endif
868
870 QString name() const
871 {
872 return mName;
873 }
874
880 QString schema() const { return mSchema; }
881
883 QString alias() const { return mAlias; }
884
885 QgsSQLStatement::NodeType nodeType() const override { return ntTableDef; }
886 QString dump() const override;
887
888 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
889 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
891 QgsSQLStatement::NodeTableDef *cloneThis() const SIP_FACTORY;
892
893 protected:
894 QString mName;
895 QString mSchema;
896 QString mAlias;
897 };
898
903 class CORE_EXPORT NodeJoin : public QgsSQLStatement::Node
904 {
905 public:
912
914 : mTableDef( tabledef )
916 , mType( type )
917 {}
918
921
923 QgsSQLStatement::Node *onExpr() const { return mOnExpr.get(); }
924
926 QList<QString> usingColumns() const { return mUsingColumns; }
927
930
931 QgsSQLStatement::NodeType nodeType() const override { return ntJoin; }
932 QString dump() const override;
933
934 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
935 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
937 QgsSQLStatement::NodeJoin *cloneThis() const SIP_FACTORY;
938
939 private:
940 NodeJoin( const NodeJoin &other ) = delete;
941 NodeJoin &operator=( const NodeJoin &other ) = delete;
942
943#ifdef SIP_RUN
944 NodeJoin( const NodeJoin &other );
945#endif
946
947 protected:
948 std::unique_ptr<NodeTableDef> mTableDef;
949 std::unique_ptr<Node> mOnExpr;
950 QList<QString> mUsingColumns;
952 };
953
958 class CORE_EXPORT NodeColumnSorted : public QgsSQLStatement::Node
959 {
960 public:
966
969
971 bool ascending() const { return mAsc; }
972
974 QString dump() const override;
975
976 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
977 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
979 QgsSQLStatement::NodeColumnSorted *cloneThis() const SIP_FACTORY;
980
981 private:
982 NodeColumnSorted( const NodeColumnSorted &other ) = delete;
983 NodeColumnSorted &operator=( const NodeColumnSorted &other ) = delete;
984
985#ifdef SIP_RUN
986 NodeColumnSorted( const NodeColumnSorted &other );
987#endif
988
989 protected:
990 std::unique_ptr<NodeColumnRef> mColumn;
991 bool mAsc;
992 };
993
998 class CORE_EXPORT NodeSelect : public QgsSQLStatement::Node
999 {
1000 public:
1002 NodeSelect( const QList<QgsSQLStatement::NodeTableDef *> &tableList SIP_TRANSFER, const QList<QgsSQLStatement::NodeSelectedColumn *> &columns SIP_TRANSFER, bool distinct )
1003 : mTableList( tableList )
1004 , mColumns( columns )
1005 , mDistinct( distinct )
1006 {}
1007 ~NodeSelect() override;
1008
1010 void setJoins( const QList<QgsSQLStatement::NodeJoin *> &joins SIP_TRANSFER )
1011 {
1012 qDeleteAll( mJoins );
1013 mJoins = joins;
1014 }
1015
1020 void setOrderBy( const QList<QgsSQLStatement::NodeColumnSorted *> &orderBy SIP_TRANSFER )
1021 {
1022 qDeleteAll( mOrderBy );
1023 mOrderBy = orderBy;
1024 }
1025
1027 QList<QgsSQLStatement::NodeTableDef *> tables() const { return mTableList; }
1029 QList<QgsSQLStatement::NodeSelectedColumn *> columns() const { return mColumns; }
1031 bool distinct() const { return mDistinct; }
1033 QList<QgsSQLStatement::NodeJoin *> joins() const { return mJoins; }
1035 QgsSQLStatement::Node *where() const { return mWhere.get(); }
1037 QList<QgsSQLStatement::NodeColumnSorted *> orderBy() const { return mOrderBy; }
1038
1039 QgsSQLStatement::NodeType nodeType() const override { return ntSelect; }
1040 QString dump() const override;
1041
1042 void accept( QgsSQLStatement::Visitor &v ) const override { v.visit( *this ); }
1043 QgsSQLStatement::Node *clone() const override SIP_FACTORY;
1044
1045 private:
1046 NodeSelect( const NodeSelect &other ) = delete;
1047 NodeSelect &operator=( const NodeSelect &other ) = delete;
1048
1049#ifdef SIP_RUN
1050 NodeSelect( const NodeSelect &other );
1051#endif
1052
1053 protected:
1054 QList<NodeTableDef *> mTableList;
1055 QList<NodeSelectedColumn *> mColumns;
1057 QList<NodeJoin *> mJoins;
1058 std::unique_ptr<Node> mWhere;
1059 QList<NodeColumnSorted *> mOrderBy;
1060 };
1061
1063
1069 class CORE_EXPORT Visitor
1070 {
1071 public:
1072 virtual ~Visitor() = default;
1074 virtual void visit( const QgsSQLStatement::NodeUnaryOperator &n ) = 0;
1076 virtual void visit( const QgsSQLStatement::NodeBinaryOperator &n ) = 0;
1078 virtual void visit( const QgsSQLStatement::NodeInOperator &n ) = 0;
1080 virtual void visit( const QgsSQLStatement::NodeBetweenOperator &n ) = 0;
1082 virtual void visit( const QgsSQLStatement::NodeFunction &n ) = 0;
1084 virtual void visit( const QgsSQLStatement::NodeLiteral &n ) = 0;
1086 virtual void visit( const QgsSQLStatement::NodeColumnRef &n ) = 0;
1088 virtual void visit( const QgsSQLStatement::NodeSelectedColumn &n ) = 0;
1090 virtual void visit( const QgsSQLStatement::NodeTableDef &n ) = 0;
1092 virtual void visit( const QgsSQLStatement::NodeSelect &n ) = 0;
1094 virtual void visit( const QgsSQLStatement::NodeJoin &n ) = 0;
1096 virtual void visit( const QgsSQLStatement::NodeColumnSorted &n ) = 0;
1098 virtual void visit( const QgsSQLStatement::NodeCast &n ) = 0;
1099 };
1100
1106 {
1107 public:
1108 RecursiveVisitor() = default;
1109
1110 void visit( const QgsSQLStatement::NodeUnaryOperator &n ) override { n.operand()->accept( *this ); }
1112 {
1113 n.opLeft()->accept( *this );
1114 n.opRight()->accept( *this );
1115 }
1116 void visit( const QgsSQLStatement::NodeInOperator &n ) override
1117 {
1118 n.node()->accept( *this );
1119 n.list()->accept( *this );
1120 }
1122 {
1123 n.node()->accept( *this );
1124 n.minVal()->accept( *this );
1125 n.maxVal()->accept( *this );
1126 }
1127 void visit( const QgsSQLStatement::NodeFunction &n ) override { n.args()->accept( *this ); }
1128 void visit( const QgsSQLStatement::NodeLiteral & ) override {}
1129 void visit( const QgsSQLStatement::NodeColumnRef & ) override {}
1130 void visit( const QgsSQLStatement::NodeSelectedColumn &n ) override { n.column()->accept( *this ); }
1131 void visit( const QgsSQLStatement::NodeTableDef & ) override {}
1132 void visit( const QgsSQLStatement::NodeSelect &n ) override;
1133 void visit( const QgsSQLStatement::NodeJoin &n ) override;
1134 void visit( const QgsSQLStatement::NodeColumnSorted &n ) override { n.column()->accept( *this ); }
1135 void visit( const QgsSQLStatement::NodeCast &n ) override { n.node()->accept( *this ); }
1136 };
1137
1139 void acceptVisitor( QgsSQLStatement::Visitor &v ) const;
1140
1141 protected:
1142 std::unique_ptr<QgsSQLStatement::Node> mRootNode;
1143 bool mAllowFragments = false;
1144 QString mStatement;
1146
1155 QgsSQLStatement( const QString &statement, bool allowFragments );
1156};
1157
1159
1160
1166{
1167 public:
1171 QgsSQLStatementFragment( const QString &fragment );
1172};
1173
1174
1175#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)