Akonadi

query.cpp
1 /*
2  SPDX-FileCopyrightText: 2007 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "query.h"
8 
9 using namespace Akonadi::Server;
10 using namespace Akonadi::Server::Query;
11 
12 void 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 
22 void 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 
59 Case::Case(const Condition &when, const QString &then, const QString &elseBranch)
60 {
61  addCondition(when, then);
62  setElse(elseBranch);
63 }
64 
65 Case::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 
71 void Case::addCondition(const Condition &when, const QString &then)
72 {
73  mWhenThen.append(qMakePair(when, then));
74 }
75 
76 void 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 
83 void 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 
90 void Case::setElse(const QString &elseBranch)
91 {
92  mElse = elseBranch;
93 }
void addCondition(const Condition &condition)
Add a WHERE condition.
Definition: query.cpp:54
Building blocks for SQL queries.
Definition: query.h:25
bool isEmpty() const
Returns if there are sub conditions.
Definition: query.cpp:39
Condition::List subConditions() const
Returns the list of sub-conditions.
Definition: query.cpp:44
CompareOperator
Compare operators to be used in query conditions.
Definition: query.h:31
bool isEmpty() const const
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(LogicOperator op=And)
Create an empty condition.
Definition: query.cpp:33
void setSubQueryMode(LogicOperator op)
Set how sub-conditions should be combined, default is And.
Definition: query.cpp:49
bool isEmpty() const const
LogicOperator
Logic operations used to combine multiple query conditions.
Definition: query.h:48
Represents a WHERE condition tree.
Definition: query.h:64
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 Wed Sep 23 2020 23:17:31 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.