Nut/src/wherephrase.h

162 lines
4.0 KiB
C
Raw Normal View History

2016-05-21 16:09:03 +08:00
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Nut is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#ifndef PHRASE_H
#define PHRASE_H
2016-05-20 21:13:49 +08:00
#include <QtCore/qglobal.h>
2016-05-21 16:09:03 +08:00
#include <QVariant>
#include <QDate>
#include <QDateTime>
#include <QTime>
2016-06-05 20:22:26 +08:00
#include <QSharedPointer>
2017-02-01 18:01:21 +08:00
#include "defines.h"
2016-05-21 16:09:03 +08:00
2017-02-01 18:01:21 +08:00
NUT_BEGIN_NAMESPACE
2016-05-21 16:09:03 +08:00
class SqlGeneratorBase;
2016-06-05 20:22:26 +08:00
class PhraseData{
public:
2016-05-21 16:09:03 +08:00
enum Condition
{
2016-06-05 20:22:26 +08:00
NotAssign = 0,
Equal,
2016-05-21 16:09:03 +08:00
Less,
LessEqual,
Null,
In,
Like,
2016-06-05 20:22:26 +08:00
Not = 10,
NotEqual,
2016-05-21 16:09:03 +08:00
GreaterEqual,
Greater,
NotNull,
NotIn,
NotLike,
And = 20,
Or,
2016-06-05 20:22:26 +08:00
2016-05-21 16:09:03 +08:00
Append,
Set,
Add,
Minus,
Multiple,
Divide
};
enum Type{
Field,
WithVariant,
WithOther,
WithoutOperand
};
Type type;
Condition operatorCond;
QString text;
const PhraseData *left;
const PhraseData *right;
QVariant operand;
PhraseData(const char *className, const char* s);
PhraseData(PhraseData *l, Condition o);
PhraseData(PhraseData *l, Condition o, const PhraseData *r);
PhraseData(PhraseData *l, Condition o, QVariant r);
~PhraseData();
};
2016-05-24 14:47:37 +08:00
class WherePhrase{
protected:
2016-06-05 20:22:26 +08:00
PhraseData *_data;
QSharedPointer<PhraseData> _dataPointer;
2016-05-24 14:47:37 +08:00
2016-05-20 21:13:49 +08:00
public:
2016-05-24 14:47:37 +08:00
WherePhrase(const char *className, const char* s);
2016-05-21 16:09:03 +08:00
2016-06-05 20:22:26 +08:00
WherePhrase(const WherePhrase &l);
WherePhrase(WherePhrase *l);
WherePhrase(WherePhrase *l, PhraseData::Condition o);
WherePhrase(WherePhrase *l, PhraseData::Condition o, WherePhrase *r);
WherePhrase(WherePhrase *l, PhraseData::Condition o, QVariant r);
2016-05-21 16:09:03 +08:00
2016-05-24 14:47:37 +08:00
~WherePhrase();
2016-05-21 16:09:03 +08:00
2016-05-24 14:47:37 +08:00
WherePhrase operator ==(const WherePhrase &other);
WherePhrase operator !=(const WherePhrase &other);
WherePhrase operator <(const WherePhrase &other);
WherePhrase operator >(const WherePhrase &other);
WherePhrase operator <=(const WherePhrase &other);
WherePhrase operator >=(const WherePhrase &other);
WherePhrase operator =(const WherePhrase &other);
WherePhrase operator +(const WherePhrase &other);
WherePhrase operator -(const WherePhrase &other);
WherePhrase operator *(const WherePhrase &other);
WherePhrase operator /(const WherePhrase &other);
2016-05-21 16:09:03 +08:00
2016-05-24 14:47:37 +08:00
WherePhrase operator &&(const WherePhrase &other);
WherePhrase operator ||(const WherePhrase &other);
2016-05-21 16:09:03 +08:00
2016-05-24 14:47:37 +08:00
WherePhrase operator &(const WherePhrase &other);
2016-05-21 16:09:03 +08:00
2016-05-24 14:47:37 +08:00
WherePhrase operator ==(const QVariant &other);
WherePhrase operator !=(const QVariant &other);
WherePhrase operator <(const QVariant &other);
WherePhrase operator >(const QVariant &other);
WherePhrase operator <=(const QVariant &other);
WherePhrase operator >=(const QVariant &other);
2016-05-21 16:09:03 +08:00
2016-06-05 20:22:26 +08:00
PhraseData *data() const;
2016-05-24 14:47:37 +08:00
};
class FieldPhrase: public WherePhrase{
public:
FieldPhrase(const char *className, const char* s);
2016-05-21 16:09:03 +08:00
2016-05-24 14:47:37 +08:00
WherePhrase operator =(const QVariant &other);
WherePhrase operator !();
2016-05-21 16:09:03 +08:00
2016-05-24 14:47:37 +08:00
WherePhrase isNull();
WherePhrase in(QVariantList list);
WherePhrase in(QStringList list);
WherePhrase like(QString pattern);
2016-05-20 21:13:49 +08:00
};
2016-06-05 20:22:26 +08:00
//TODO: make FieldPhrase template class
//template <typename T>
//class FieldPhrase: public WherePhrase{
//};
2017-02-01 18:01:21 +08:00
NUT_END_NAMESPACE
2016-05-21 16:09:03 +08:00
#endif // PHRASE_H