Akonadi

tagqueryhelper.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Volker Krause <[email protected]>
3  SPDX-FileCopyrightText: 2015 Daniel Vr├ítil <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "tagqueryhelper.h"
9 
10 #include "commandcontext.h"
11 #include "handler.h"
12 #include "storage/querybuilder.h"
13 #include "storage/queryhelper.h"
14 
15 #include <private/imapset_p.h>
16 #include <private/scope_p.h>
17 
18 using namespace Akonadi;
19 using namespace Akonadi::Server;
20 
21 void TagQueryHelper::remoteIdToQuery(const QStringList &rids, const CommandContext &context, QueryBuilder &qb)
22 {
23  qb.addJoin(QueryBuilder::InnerJoin, TagRemoteIdResourceRelation::tableName(), Tag::idFullColumnName(), TagRemoteIdResourceRelation::tagIdFullColumnName());
24  qb.addValueCondition(TagRemoteIdResourceRelation::resourceIdFullColumnName(), Query::Equals, context.resource().id());
25 
26  if (rids.size() == 1) {
27  qb.addValueCondition(TagRemoteIdResourceRelation::remoteIdFullColumnName(), Query::Equals, rids.first());
28  } else {
29  qb.addValueCondition(TagRemoteIdResourceRelation::remoteIdFullColumnName(), Query::In, rids);
30  }
31 }
32 
33 void TagQueryHelper::gidToQuery(const QStringList &gids, const CommandContext &context, QueryBuilder &qb)
34 {
35  if (context.resource().isValid()) {
37  TagRemoteIdResourceRelation::tableName(),
38  Tag::idFullColumnName(),
39  TagRemoteIdResourceRelation::tagIdFullColumnName());
40  qb.addValueCondition(TagRemoteIdResourceRelation::resourceIdFullColumnName(), Query::Equals, context.resource().id());
41  }
42 
43  if (gids.size() == 1) {
44  qb.addValueCondition(Tag::gidFullColumnName(), Query::Equals, gids.first());
45  } else {
46  qb.addValueCondition(Tag::gidFullColumnName(), Query::In, gids);
47  }
48 }
49 
50 void TagQueryHelper::scopeToQuery(const Scope &scope, const CommandContext &context, QueryBuilder &qb)
51 {
52  if (scope.scope() == Scope::Uid) {
53  QueryHelper::setToQuery(scope.uidSet(), Tag::idFullColumnName(), qb);
54  return;
55  }
56 
57  if (scope.scope() == Scope::Gid) {
58  TagQueryHelper::gidToQuery(scope.gidSet(), context, qb);
59  return;
60  }
61 
62  if (scope.scope() == Scope::Rid) {
63  if (!context.resource().isValid()) {
64  throw HandlerException("Operations based on remote identifiers require a resource or collection context");
65  }
66 
67  if (scope.scope() == Scope::Rid) {
68  TagQueryHelper::remoteIdToQuery(scope.ridSet(), context, qb);
69  }
70  }
71 
72  throw HandlerException("HRID tag operations are not permitted");
73 }
T & first()
@ InnerJoin
NOTE: only supported for UPDATE and SELECT queries.
Definition: querybuilder.h:48
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
void addJoin(JoinType joinType, const QString &table, const Query::Condition &condition)
Join a table to the query.
int size() const const
void addValueCondition(const QString &column, Query::CompareOperator op, const QVariant &value, ConditionType type=WhereCondition)
Add a WHERE or HAVING condition which compares a column with a given value.
void remoteIdToQuery(const QStringList &rids, const CommandContext &context, QueryBuilder &qb)
Add conditions to qb for the given remote identifier rid.
void scopeToQuery(const Scope &scope, const CommandContext &context, QueryBuilder &qb)
Add conditions to qb for the given item operation scope scope.
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 Sat Jun 25 2022 06:00:33 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.