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 class QueryBuilder;
19 
20 /**
21  Building blocks for SQL queries.
22  @see QueryBuilder
23 */
24 namespace Query
25 {
26 /**
27  Compare operators to be used in query conditions.
28 */
29 enum CompareOperator { Equals, NotEquals, Is, IsNot, Less, LessOrEqual, Greater, GreaterOrEqual, In, NotIn, Like };
30 
31 /**
32  Logic operations used to combine multiple query conditions.
33 */
34 enum LogicOperator { And, Or };
35 
36 /**
37  Sort orders.
38 */
39 enum SortOrder { Ascending, Descending };
40 
41 /**
42  Represents a WHERE condition tree.
43 */
44 class Condition
45 {
46  friend class Akonadi::Server::QueryBuilder;
47 
48 public:
49  /** A list of conditions. */
51 
52  /**
53  Create an empty condition.
54  @param op how to combine sub queries.
55  */
56  explicit Condition(LogicOperator op = And);
57 
58  /**
59  Add a WHERE condition which compares a column with a given value.
60  @param column The column that should be compared.
61  @param op The operator used for comparison
62  @param value The value @p column is compared to.
63  */
64  void addValueCondition(const QString &column, CompareOperator op, const QVariant &value);
65 
66  /**
67  Add a WHERE condition which compares a column with another column.
68  @param column The column that should be compared.
69  @param op The operator used for comparison.
70  @param column2 The column @p column is compared to.
71  */
72  void addColumnCondition(const QString &column, CompareOperator op, const QString &column2);
73 
74  /**
75  Add a WHERE condition. Use this method to build hierarchical conditions.
76  */
77  void addCondition(const Condition &condition);
78 
79  /**
80  Set how sub-conditions should be combined, default is And.
81  */
83 
84  /**
85  Returns if there are sub conditions.
86  */
87  bool isEmpty() const;
88 
89  /**
90  Returns the list of sub-conditions.
91  */
93 
94 private:
95  Condition::List mSubConditions;
96  QString mColumn;
97  QString mComparedColumn;
98  QVariant mComparedValue;
99  CompareOperator mCompareOp;
100  LogicOperator mCombineOp;
101 
102 }; // class Condition
103 
104 class Case
105 {
106  friend class Akonadi::Server::QueryBuilder;
107 
108 public:
109  Case(const Condition &when, const QString &then, const QString &elseBranch = QString());
110  Case(const QString &column, Query::CompareOperator op, const QVariant &value, const QString &when, const QString &elseBranch = QString());
111 
112  void addCondition(const Condition &when, const QString &then);
113  void addValueCondition(const QString &column, Query::CompareOperator op, const QVariant &value, const QString &then);
114  void addColumnCondition(const QString &column, Query::CompareOperator op, const QString &column2, const QString &then);
115 
116  void setElse(const QString &elseBranch);
117 
118 private:
120  QString mElse;
121 };
122 
123 } // namespace Query
124 } // namespace Server
125 } // namespace Akonadi
126 
127 Q_DECLARE_TYPEINFO(Akonadi::Server::Query::Condition, Q_MOVABLE_TYPE);
128 
129 #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:39
CompareOperator
Compare operators to be used in query conditions.
Definition: query.h:29
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:50
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:34
Represents a WHERE condition tree.
Definition: query.h:44
Helper class to construct arbitrary SQL queries.
Definition: querybuilder.h:31
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-2021 The KDE developers.
Generated on Wed Mar 3 2021 00:16:47 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.