Akonadi

query.cpp
1/*
2 SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "query.h"
8
9using namespace Akonadi::Server;
10using namespace Akonadi::Server::Query;
11
12void Condition::addValueCondition(const QString &column, CompareOperator op, const QVariant &value)
13{
14 Q_ASSERT(!column.isEmpty());
15 Condition c;
16 c.mColumn = column;
17 c.mCompareOp = op;
18 c.mComparedValue = value;
19 mSubConditions << c;
20}
21
22void Condition::addColumnCondition(const QString &column, CompareOperator op, const QString &column2)
23{
24 Q_ASSERT(!column.isEmpty());
25 Q_ASSERT(!column2.isEmpty());
26 Condition c;
27 c.mColumn = column;
28 c.mComparedColumn = column2;
29 c.mCompareOp = op;
30 mSubConditions << c;
31}
32
34 : mCompareOp(Equals)
35 , mCombineOp(op)
36{
37}
38
40{
41 return mSubConditions.isEmpty();
42}
43
45{
46 return mSubConditions;
47}
48
50{
51 mCombineOp = op;
52}
53
55{
56 mSubConditions << condition;
57}
58
59Case::Case(const Condition &when, const QString &then, const QString &elseBranch)
60{
61 addCondition(when, then);
62 setElse(elseBranch);
63}
64
65Case::Case(const QString &column, CompareOperator op, const QVariant &value, const QString &when, const QString &elseBranch)
66{
67 addValueCondition(column, op, value, when);
68 setElse(elseBranch);
69}
70
71void Case::addCondition(const Condition &when, const QString &then)
72{
73 mWhenThen.append(qMakePair(when, then));
74}
75
76void Case::addValueCondition(const QString &column, CompareOperator op, const QVariant &value, const QString &then)
77{
78 Condition when;
79 when.addValueCondition(column, op, value);
80 addCondition(when, then);
81}
82
83void Case::addColumnCondition(const QString &column, CompareOperator op, const QString &column2, const QString &then)
84{
85 Condition when;
86 when.addColumnCondition(column, op, column2);
87 addCondition(when, then);
88}
89
90void Case::setElse(const QString &elseBranch)
91{
92 mElse = elseBranch;
93}
Represents a WHERE condition tree.
Definition query.h:62
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
Building blocks for SQL queries.
Definition query.h:24
CompareOperator
Compare operators to be used in query conditions.
Definition query.h:28
LogicOperator
Logic operations used to combine multiple query conditions.
Definition query.h:45
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:31:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.