File indexing completed on 2025-01-05 04:47:00
0001 /* 0002 SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "query.h" 0008 0009 using namespace Akonadi::Server; 0010 using namespace Akonadi::Server::Query; 0011 0012 void Condition::addValueCondition(const QString &column, CompareOperator op, const QVariant &value) 0013 { 0014 Q_ASSERT(!column.isEmpty()); 0015 Condition c; 0016 c.mColumn = column; 0017 c.mCompareOp = op; 0018 c.mComparedValue = value; 0019 mSubConditions << c; 0020 } 0021 0022 void Condition::addColumnCondition(const QString &column, CompareOperator op, const QString &column2) 0023 { 0024 Q_ASSERT(!column.isEmpty()); 0025 Q_ASSERT(!column2.isEmpty()); 0026 Condition c; 0027 c.mColumn = column; 0028 c.mComparedColumn = column2; 0029 c.mCompareOp = op; 0030 mSubConditions << c; 0031 } 0032 0033 Query::Condition::Condition(LogicOperator op) 0034 : mCompareOp(Equals) 0035 , mCombineOp(op) 0036 { 0037 } 0038 0039 bool Query::Condition::isEmpty() const 0040 { 0041 return mSubConditions.isEmpty(); 0042 } 0043 0044 Condition::List Query::Condition::subConditions() const 0045 { 0046 return mSubConditions; 0047 } 0048 0049 void Query::Condition::setSubQueryMode(LogicOperator op) 0050 { 0051 mCombineOp = op; 0052 } 0053 0054 void Query::Condition::addCondition(const Condition &condition) 0055 { 0056 mSubConditions << condition; 0057 } 0058 0059 Case::Case(const Condition &when, const QString &then, const QString &elseBranch) 0060 { 0061 addCondition(when, then); 0062 setElse(elseBranch); 0063 } 0064 0065 Case::Case(const QString &column, CompareOperator op, const QVariant &value, const QString &when, const QString &elseBranch) 0066 { 0067 addValueCondition(column, op, value, when); 0068 setElse(elseBranch); 0069 } 0070 0071 void Case::addCondition(const Condition &when, const QString &then) 0072 { 0073 mWhenThen.append(qMakePair(when, then)); 0074 } 0075 0076 void Case::addValueCondition(const QString &column, CompareOperator op, const QVariant &value, const QString &then) 0077 { 0078 Condition when; 0079 when.addValueCondition(column, op, value); 0080 addCondition(when, then); 0081 } 0082 0083 void Case::addColumnCondition(const QString &column, CompareOperator op, const QString &column2, const QString &then) 0084 { 0085 Condition when; 0086 when.addColumnCondition(column, op, column2); 0087 addCondition(when, then); 0088 } 0089 0090 void Case::setElse(const QString &elseBranch) 0091 { 0092 mElse = elseBranch; 0093 }