Akonadi

queryhelper.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "queryhelper.h"
8 
9 #include "storage/querybuilder.h"
10 
11 #include <private/imapset_p.h>
12 
13 using namespace Akonadi;
14 using namespace Akonadi::Server;
15 
16 void QueryHelper::setToQuery(const ImapSet &set, const QString &column, QueryBuilder &qb)
17 {
18  Query::Condition cond(Query::Or);
19  Q_FOREACH (const ImapInterval &i, set.intervals()) {
20  if (i.hasDefinedBegin() && i.hasDefinedEnd()) {
21  if (i.size() == 1) {
22  cond.addValueCondition(column, Query::Equals, i.begin());
23  } else {
24  if (i.begin() != 1) { // 1 is our standard lower bound, so we don't have to check for it explicitly
25  Query::Condition subCond(Query::And);
26  subCond.addValueCondition(column, Query::GreaterOrEqual, i.begin());
27  subCond.addValueCondition(column, Query::LessOrEqual, i.end());
28  cond.addCondition(subCond);
29  } else {
30  cond.addValueCondition(column, Query::LessOrEqual, i.end());
31  }
32  }
33  } else if (i.hasDefinedBegin()) {
34  if (i.begin() != 1) { // 1 is our standard lower bound, so we don't have to check for it explicitly
35  cond.addValueCondition(column, Query::GreaterOrEqual, i.begin());
36  }
37  } else if (i.hasDefinedEnd()) {
38  cond.addValueCondition(column, Query::LessOrEqual, i.end());
39  }
40  }
41  if (!cond.isEmpty()) {
42  qb.addCondition(cond);
43  }
44 }
void addCondition(const Condition &condition)
Add a WHERE condition.
Definition: query.cpp:54
QString::iterator end()
bool isEmpty() const
Returns if there are sub conditions.
Definition: query.cpp:39
void setToQuery(const ImapSet &set, const QString &column, QueryBuilder &qb)
Add conditions to qb for the given uid set set applied to column.
Definition: queryhelper.cpp:16
Helper integration between Akonadi and Qt.
Represents a WHERE condition tree.
Definition: query.h:64
QString::iterator begin()
Helper class to construct arbitrary SQL queries.
Definition: querybuilder.h:32
void addCondition(const Query::Condition &condition, ConditionType type=WhereCondition)
Add a WHERE condition.
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 Aug 8 2020 23:14:46 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.