Akonadi

query.h
1/*
2 SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <QList>
10#include <QString>
11#include <QVariant>
12
13namespace Akonadi
14{
15namespace Server
16{
17class QueryBuilder;
18
19/**
20 Building blocks for SQL queries.
21 @see QueryBuilder
22*/
23namespace Query
24{
25/**
26 Compare operators to be used in query conditions.
27*/
29 Equals,
30 NotEquals,
31 Is,
32 IsNot,
33 Less,
34 LessOrEqual,
35 Greater,
36 GreaterOrEqual,
37 In,
38 NotIn,
39 Like,
40};
41
42/**
43 Logic operations used to combine multiple query conditions.
44*/
46 And,
47 Or,
48};
49
50/**
51 Sort orders.
52*/
54 Ascending,
55 Descending,
56};
57
58/**
59 Represents a WHERE condition tree.
60*/
62{
64
65public:
66 /** A list of conditions. */
68
69 /**
70 Create an empty condition.
71 @param op how to combine sub queries.
72 */
73 explicit Condition(LogicOperator op = And);
74
75 /**
76 Add a WHERE condition which compares a column with a given value.
77 @param column The column that should be compared.
78 @param op The operator used for comparison
79 @param value The value @p column is compared to.
80 */
81 void addValueCondition(const QString &column, CompareOperator op, const QVariant &value);
82 /**
83 * Add a WHERE condition which compares a column with a given value.
84 *
85 * This is an overload specially for passing a list of IDs, which is a fairly common case in Akonadi.
86 *
87 * @param column The column that should be compared.
88 * @param op The operator used for comparison.
89 * @param value The value @p column is compared to.
90 */
91 void addValueCondition(const QString &column, CompareOperator op, const QList<qint64> &value)
92 {
93 addValueCondition(column, op, QVariant::fromValue(value));
94 }
95
96 /**
97 Add a WHERE condition which compares a column with another column.
98 @param column The column that should be compared.
99 @param op The operator used for comparison.
100 @param column2 The column @p column is compared to.
101 */
102 void addColumnCondition(const QString &column, CompareOperator op, const QString &column2);
103
104 /**
105 Add a WHERE condition. Use this method to build hierarchical conditions.
106 */
107 void addCondition(const Condition &condition);
108
109 /**
110 Set how sub-conditions should be combined, default is And.
111 */
113
114 /**
115 Returns if there are sub conditions.
116 */
117 bool isEmpty() const;
118
119 /**
120 Returns the list of sub-conditions.
121 */
123
124private:
125 Condition::List mSubConditions;
126 QString mColumn;
127 QString mComparedColumn;
128 QVariant mComparedValue;
129 CompareOperator mCompareOp;
130 LogicOperator mCombineOp;
131
132}; // class Condition
133
134class Case
135{
137
138public:
139 Case(const Condition &when, const QString &then, const QString &elseBranch = QString());
140 Case(const QString &column, Query::CompareOperator op, const QVariant &value, const QString &when, const QString &elseBranch = QString());
141
142 void addCondition(const Condition &when, const QString &then);
143 void addValueCondition(const QString &column, Query::CompareOperator op, const QVariant &value, const QString &then);
144 void addColumnCondition(const QString &column, Query::CompareOperator op, const QString &column2, const QString &then);
145
146 void setElse(const QString &elseBranch);
147
148private:
150 QString mElse;
151};
152
153} // namespace Query
154} // namespace Server
155} // namespace Akonadi
156
157Q_DECLARE_TYPEINFO(Akonadi::Server::Query::Condition, Q_RELOCATABLE_TYPE);
Helper class to construct arbitrary SQL queries.
Represents a WHERE condition tree.
Definition query.h:62
void addValueCondition(const QString &column, CompareOperator op, const QList< qint64 > &value)
Add a WHERE condition which compares a column with a given value.
Definition query.h:91
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::List subConditions() const
Returns the list of sub-conditions.
Definition query.cpp:44
void setSubQueryMode(LogicOperator op)
Set how sub-conditions should be combined, default is And.
Definition query.cpp:49
Condition(LogicOperator op=And)
Create an empty condition.
Definition query.cpp:33
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
bool isEmpty() const
Returns if there are sub conditions.
Definition query.cpp:39
void addCondition(const Condition &condition)
Add a WHERE condition.
Definition query.cpp:54
CompareOperator
Compare operators to be used in query conditions.
Definition query.h:28
SortOrder
Sort orders.
Definition query.h:53
LogicOperator
Logic operations used to combine multiple query conditions.
Definition query.h:45
Helper integration between Akonadi and Qt.
QVariant fromValue(T &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 7 2024 11:56:45 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.