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  const auto intervals = set.intervals();
20  for (const ImapInterval &i : intervals) {
21  if (i.hasDefinedBegin() && i.hasDefinedEnd()) {
22  if (i.size() == 1) {
23  cond.addValueCondition(column, Query::Equals, i.begin());
24  } else {
25  if (i.begin() != 1) { // 1 is our standard lower bound, so we don't have to check for it explicitly
26  Query::Condition subCond(Query::And);
27  subCond.addValueCondition(column, Query::GreaterOrEqual, i.begin());
28  subCond.addValueCondition(column, Query::LessOrEqual, i.end());
29  cond.addCondition(subCond);
30  } else {
31  cond.addValueCondition(column, Query::LessOrEqual, i.end());
32  }
33  }
34  } else if (i.hasDefinedBegin()) {
35  if (i.begin() != 1) { // 1 is our standard lower bound, so we don't have to check for it explicitly
36  cond.addValueCondition(column, Query::GreaterOrEqual, i.begin());
37  }
38  } else if (i.hasDefinedEnd()) {
39  cond.addValueCondition(column, Query::LessOrEqual, i.end());
40  }
41  }
42  if (!cond.isEmpty()) {
43  qb.addCondition(cond);
44  }
45 }
QString::iterator begin()
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
QString::iterator end()
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
void addCondition(const Condition &condition)
Add a WHERE condition.
Definition: query.cpp:54
Represents a WHERE condition tree.
Definition: query.h:61
void addCondition(const Query::Condition &condition, ConditionType type=WhereCondition)
Add a WHERE condition.
Helper class to construct arbitrary SQL queries.
Definition: querybuilder.h:31
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jun 30 2022 03:51:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.