Akonadi

query.h
1 /*
2  SPDX-FileCopyrightText: 2007 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef AKONADI_QUERY_H
8 #define AKONADI_QUERY_H
9 
10 #include <QString>
11 #include <QVariant>
12 #include <QVector>
13 
14 namespace Akonadi
15 {
16 namespace Server
17 {
18 
19 class QueryBuilder;
20 
25 namespace Query
26 {
27 
32  Equals,
33  NotEquals,
34  Is,
35  IsNot,
36  Less,
37  LessOrEqual,
38  Greater,
39  GreaterOrEqual,
40  In,
41  NotIn,
42  Like
43 };
44 
49  And,
50  Or
51 };
52 
56 enum SortOrder {
57  Ascending,
58  Descending
59 };
60 
64 class Condition
65 {
66  friend class Akonadi::Server::QueryBuilder;
67 public:
70 
75  explicit Condition(LogicOperator op = And);
76 
83  void addValueCondition(const QString &column, CompareOperator op, const QVariant &value);
84 
91  void addColumnCondition(const QString &column, CompareOperator op, const QString &column2);
92 
96  void addCondition(const Condition &condition);
97 
102 
106  bool isEmpty() const;
107 
112 
113 private:
114  Condition::List mSubConditions;
115  QString mColumn;
116  QString mComparedColumn;
117  QVariant mComparedValue;
118  CompareOperator mCompareOp;
119  LogicOperator mCombineOp;
120 
121 }; // class Condition
122 
123 class Case
124 {
125  friend class Akonadi::Server::QueryBuilder;
126 public:
127  Case(const Condition &when, const QString &then, const QString &elseBranch = QString());
128  Case(const QString &column, Query::CompareOperator op, const QVariant &value, const QString &when, const QString &elseBranch = QString());
129 
130  void addCondition(const Condition &when, const QString &then);
131  void addValueCondition(const QString &column, Query::CompareOperator op, const QVariant &value, const QString &then);
132  void addColumnCondition(const QString &column, Query::CompareOperator op, const QString &column2, const QString &then);
133 
134  void setElse(const QString &elseBranch);
135 
136 private:
138  QString mElse;
139 };
140 
141 } // namespace Query
142 } // namespace Server
143 } // namespace Akonadi
144 
145 Q_DECLARE_TYPEINFO(Akonadi::Server::Query::Condition, Q_MOVABLE_TYPE);
146 
147 #endif
void addCondition(const Condition &condition)
Add a WHERE condition.
Definition: query.cpp:54
bool isEmpty() const
Returns if there are sub conditions.
Definition: query.cpp:39
Condition::List subConditions() const
Returns the list of sub-conditions.
Definition: query.cpp:44
SortOrder
Sort orders.
Definition: query.h:56
CompareOperator
Compare operators to be used in query conditions.
Definition: query.h:31
void addColumnCondition(const QString &column, CompareOperator op, const QString &column2)
Add a WHERE condition which compares a column with another column.
Definition: query.cpp:22
Condition(LogicOperator op=And)
Create an empty condition.
Definition: query.cpp:33
QVector< Condition > List
A list of conditions.
Definition: query.h:69
void setSubQueryMode(LogicOperator op)
Set how sub-conditions should be combined, default is And.
Definition: query.cpp:49
Helper integration between Akonadi and Qt.
LogicOperator
Logic operations used to combine multiple query conditions.
Definition: query.h:48
Represents a WHERE condition tree.
Definition: query.h:64
Helper class to construct arbitrary SQL queries.
Definition: querybuilder.h:32
void addValueCondition(const QString &column, CompareOperator op, const QVariant &value)
Add a WHERE condition which compares a column with a given value.
Definition: query.cpp:12
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Nov 28 2020 23:17:16 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.