Akonadi

query.h
1 /*
2  Copyright (c) 2007 Volker Krause <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #ifndef AKONADI_QUERY_H
21 #define AKONADI_QUERY_H
22 
23 #include <QString>
24 #include <QVariant>
25 #include <QVector>
26 
27 namespace Akonadi
28 {
29 namespace Server
30 {
31 
32 class QueryBuilder;
33 
38 namespace Query
39 {
40 
45  Equals,
46  NotEquals,
47  Is,
48  IsNot,
49  Less,
50  LessOrEqual,
51  Greater,
52  GreaterOrEqual,
53  In,
54  NotIn,
55  Like
56 };
57 
62  And,
63  Or
64 };
65 
69 enum SortOrder {
70  Ascending,
71  Descending
72 };
73 
77 class Condition
78 {
79  friend class Akonadi::Server::QueryBuilder;
80 public:
83 
88  explicit Condition(LogicOperator op = And);
89 
96  void addValueCondition(const QString &column, CompareOperator op, const QVariant &value);
97 
104  void addColumnCondition(const QString &column, CompareOperator op, const QString &column2);
105 
109  void addCondition(const Condition &condition);
110 
115 
119  bool isEmpty() const;
120 
125 
126 private:
127  Condition::List mSubConditions;
128  QString mColumn;
129  QString mComparedColumn;
130  QVariant mComparedValue;
131  CompareOperator mCompareOp;
132  LogicOperator mCombineOp;
133 
134 }; // class Condition
135 
136 class Case
137 {
138  friend class Akonadi::Server::QueryBuilder;
139 public:
140  Case(const Condition &when, const QString &then, const QString &elseBranch = QString());
141  Case(const QString &column, Query::CompareOperator op, const QVariant &value, const QString &when, const QString &elseBranch = QString());
142 
143  void addCondition(const Condition &when, const QString &then);
144  void addValueCondition(const QString &column, Query::CompareOperator op, const QVariant &value, const QString &then);
145  void addColumnCondition(const QString &column, Query::CompareOperator op, const QString &column2, const QString &then);
146 
147  void setElse(const QString &elseBranch);
148 
149 private:
151  QString mElse;
152 };
153 
154 } // namespace Query
155 } // namespace Server
156 } // namespace Akonadi
157 
158 Q_DECLARE_TYPEINFO(Akonadi::Server::Query::Condition, Q_MOVABLE_TYPE);
159 
160 #endif
void addCondition(const Condition &condition)
Add a WHERE condition.
Definition: query.cpp:67
bool isEmpty() const
Returns if there are sub conditions.
Definition: query.cpp:52
Condition::List subConditions() const
Returns the list of sub-conditions.
Definition: query.cpp:57
SortOrder
Sort orders.
Definition: query.h:69
CompareOperator
Compare operators to be used in query conditions.
Definition: query.h:44
void addColumnCondition(const QString &column, CompareOperator op, const QString &column2)
Add a WHERE condition which compares a column with another column.
Definition: query.cpp:35
Condition(LogicOperator op=And)
Create an empty condition.
Definition: query.cpp:46
QVector< Condition > List
A list of conditions.
Definition: query.h:82
void setSubQueryMode(LogicOperator op)
Set how sub-conditions should be combined, default is And.
Definition: query.cpp:62
Helper integration between Akonadi and Qt.
LogicOperator
Logic operations used to combine multiple query conditions.
Definition: query.h:61
Represents a WHERE condition tree.
Definition: query.h:77
Helper class to construct arbitrary SQL queries.
Definition: querybuilder.h:45
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:25
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 23 2020 22:45:52 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.