Nut/src/wherephrase.h

160 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>
QT_BEGIN_NAMESPACE
class SqlGeneratorBase;
struct PhraseData{
enum Condition
{
Equal = 0,
Less,
LessEqual,
Null,
In,
Like,
NotEqual = 10,
GreaterEqual,
Greater,
NotNull,
NotIn,
NotLike,
And = 20,
Or,
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();
QString operatorString() const;
QString escapeVariant() const;
QString command(SqlGeneratorBase *generator) const;
};
2016-05-24 14:47:37 +08:00
class WherePhrase{
protected:
2016-05-21 16:09:03 +08:00
PhraseData *data;
bool willDeleteData;
2016-05-24 14:47:37 +08:00
2016-05-20 21:13:49 +08:00
public:
2016-05-21 16:09:03 +08:00
QString text;
2016-05-24 14:47:37 +08:00
WherePhrase(const char *className, const char* s);
2016-05-21 16:09:03 +08:00
2016-05-24 14:47:37 +08:00
WherePhrase(PhraseData *l);
WherePhrase(PhraseData *l, PhraseData::Condition o);
WherePhrase(PhraseData *l, PhraseData::Condition o, PhraseData *r);
WherePhrase(PhraseData *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
QString command(SqlGeneratorBase *generator);
void deleteData(PhraseData *d);
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-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);
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-05-21 16:09:03 +08:00
QT_END_NAMESPACE
#endif // PHRASE_H