wherephrase removed [skip ci]
This commit is contained in:
parent
84e219f6b3
commit
a8feb39ab7
|
|
@ -26,6 +26,12 @@ NUT_BEGIN_NAMESPACE
|
|||
|
||||
#define LOG(s) qDebug() << __func__ << s;
|
||||
|
||||
PhraseData::PhraseData() :
|
||||
className(""), fieldName(""),
|
||||
type(Field), operatorCond(NotAssign),
|
||||
left(0), right(0), operand(QVariant::Invalid), isNot(false)
|
||||
{ }
|
||||
|
||||
PhraseData::PhraseData(const char *className, const char *fieldName) :
|
||||
className(className), fieldName(fieldName),
|
||||
type(Field), operatorCond(NotAssign),
|
||||
|
|
@ -384,22 +390,67 @@ ConditionalPhrase ConditionalPhrase::operator ==(const QVariant &other)
|
|||
return ConditionalPhrase(this, PhraseData::Equal, other);
|
||||
}
|
||||
|
||||
ConditionalPhrase ConditionalPhrase::operator ==(const AbstractFieldPhrase &other)
|
||||
{
|
||||
return ConditionalPhrase(this, PhraseData::Equal, other);
|
||||
//ConditionalPhrase ConditionalPhrase::operator ==(const AbstractFieldPhrase &other)
|
||||
//{
|
||||
// return ConditionalPhrase(this, PhraseData::Equal, other);
|
||||
//}
|
||||
|
||||
//ConditionalPhrase ConditionalPhrase::operator &&(const ConditionalPhrase &other)
|
||||
//{
|
||||
// return ConditionalPhrase(this, PhraseData::And,
|
||||
// const_cast<ConditionalPhrase&>(other));
|
||||
//}
|
||||
|
||||
//ConditionalPhrase ConditionalPhrase::operator ||(const ConditionalPhrase &other)
|
||||
//{
|
||||
// return ConditionalPhrase(this, PhraseData::Or,
|
||||
// const_cast<ConditionalPhrase&>(other));
|
||||
//}
|
||||
|
||||
#define DECLARE_CONDITIONALPHRASE_OPERATORS(op, cond) \
|
||||
ConditionalPhrase operator op(const ConditionalPhrase &l, const ConditionalPhrase &r) \
|
||||
{ \
|
||||
ConditionalPhrase p; \
|
||||
p.data = new PhraseData; \
|
||||
p.data->operatorCond = cond; \
|
||||
p.data->left = new PhraseData(l.data); \
|
||||
p.data->right = new PhraseData(r.data); \
|
||||
return p; \
|
||||
} \
|
||||
ConditionalPhrase operator op(const ConditionalPhrase &l, ConditionalPhrase &&r) \
|
||||
{ \
|
||||
ConditionalPhrase p; \
|
||||
p.data = new PhraseData; \
|
||||
p.data->operatorCond = cond; \
|
||||
p.data->left = new PhraseData(l.data); \
|
||||
p.data->right = r.data; \
|
||||
r.data = 0; \
|
||||
return p; \
|
||||
} \
|
||||
ConditionalPhrase operator op(ConditionalPhrase &&l, const ConditionalPhrase &r) \
|
||||
{ \
|
||||
ConditionalPhrase p; \
|
||||
p.data = new PhraseData; \
|
||||
p.data->operatorCond = cond; \
|
||||
p.data->left = l.data; \
|
||||
l.data = 0; \
|
||||
p.data->right = new PhraseData(r.data); \
|
||||
return p; \
|
||||
} \
|
||||
ConditionalPhrase operator op(ConditionalPhrase &&l, ConditionalPhrase &&r) \
|
||||
{ \
|
||||
ConditionalPhrase p; \
|
||||
p.data = new PhraseData; \
|
||||
p.data->operatorCond = cond; \
|
||||
p.data->left = l.data; \
|
||||
p.data->right = r.data; \
|
||||
l.data = r.data = 0; \
|
||||
return p; \
|
||||
}
|
||||
|
||||
ConditionalPhrase ConditionalPhrase::operator &&(const ConditionalPhrase &other)
|
||||
{
|
||||
return ConditionalPhrase(this, PhraseData::And,
|
||||
const_cast<ConditionalPhrase&>(other));
|
||||
}
|
||||
|
||||
ConditionalPhrase ConditionalPhrase::operator ||(const ConditionalPhrase &other)
|
||||
{
|
||||
return ConditionalPhrase(this, PhraseData::Or,
|
||||
const_cast<ConditionalPhrase&>(other));
|
||||
}
|
||||
DECLARE_CONDITIONALPHRASE_OPERATORS(==, PhraseData::Equal)
|
||||
DECLARE_CONDITIONALPHRASE_OPERATORS(||, PhraseData::Or)
|
||||
DECLARE_CONDITIONALPHRASE_OPERATORS(&&, PhraseData::And)
|
||||
|
||||
ConditionalPhrase ConditionalPhrase::operator !()
|
||||
{
|
||||
|
|
|
|||
19
src/phrase.h
19
src/phrase.h
|
|
@ -91,14 +91,15 @@ public:
|
|||
const char *fieldName;
|
||||
|
||||
Type type;
|
||||
Condition operatorCond;
|
||||
|
||||
const PhraseData *left;
|
||||
const PhraseData *right;
|
||||
|
||||
QVariant operand;
|
||||
Condition operatorCond;
|
||||
bool isNot;
|
||||
|
||||
PhraseData();
|
||||
PhraseData(const char *className, const char *fieldName);
|
||||
PhraseData(PhraseData *l, Condition o);
|
||||
PhraseData(PhraseData *l, Condition o, const PhraseData *r);
|
||||
|
|
@ -186,9 +187,9 @@ public:
|
|||
|
||||
ConditionalPhrase &operator =(const ConditionalPhrase &other);
|
||||
ConditionalPhrase operator ==(const QVariant &other);
|
||||
ConditionalPhrase operator ==(const AbstractFieldPhrase &other);
|
||||
ConditionalPhrase operator &&(const ConditionalPhrase &other);
|
||||
ConditionalPhrase operator ||(const ConditionalPhrase &other);
|
||||
// ConditionalPhrase operator ==(const AbstractFieldPhrase &other);
|
||||
// ConditionalPhrase operator &&(const ConditionalPhrase &other);
|
||||
// ConditionalPhrase operator ||(const ConditionalPhrase &other);
|
||||
ConditionalPhrase operator !();
|
||||
|
||||
SPECIALIZATION_NUMERIC_MEMBER(type, <, PhraseData::Less)
|
||||
|
|
@ -197,6 +198,16 @@ public:
|
|||
SPECIALIZATION_NUMERIC_MEMBER(type, >=, PhraseData::GreaterEqual)
|
||||
};
|
||||
|
||||
#define DECLARE_CONDITIONALPHRASE_OPERATORS(op) \
|
||||
ConditionalPhrase operator op(const ConditionalPhrase &l, const ConditionalPhrase &r); \
|
||||
ConditionalPhrase operator op(const ConditionalPhrase &l, ConditionalPhrase &&r); \
|
||||
ConditionalPhrase operator op(ConditionalPhrase &&l, const ConditionalPhrase &r); \
|
||||
ConditionalPhrase operator op(ConditionalPhrase &&l, ConditionalPhrase &&r);
|
||||
|
||||
DECLARE_CONDITIONALPHRASE_OPERATORS(==)
|
||||
DECLARE_CONDITIONALPHRASE_OPERATORS(&&)
|
||||
DECLARE_CONDITIONALPHRASE_OPERATORS(||)
|
||||
|
||||
class AbstractFieldPhrase
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -124,8 +124,8 @@ template <class T>
|
|||
Q_OUTOFLINE_TEMPLATE Query<T>::~Query()
|
||||
{
|
||||
Q_D(Query);
|
||||
qDebug() << "~Query";// << d->sql;
|
||||
delete d;
|
||||
qDebug() << "~Query";
|
||||
}
|
||||
|
||||
template <class T>
|
||||
|
|
|
|||
|
|
@ -1,234 +0,0 @@
|
|||
/**************************************************************************
|
||||
**
|
||||
** 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/>.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QDebug>
|
||||
|
||||
#include "phrase.h"
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
PhraseData::PhraseData(const char *className, const char *s)
|
||||
{
|
||||
Q_UNUSED(className)
|
||||
text = QString("[%1].%2").arg(className).arg(s);
|
||||
type = Field;
|
||||
operatorCond = NotAssign;
|
||||
}
|
||||
|
||||
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o) : left(l)
|
||||
{
|
||||
operatorCond = o;
|
||||
type = WithoutOperand;
|
||||
}
|
||||
|
||||
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o,
|
||||
const PhraseData *r)
|
||||
: left(l), right(r)
|
||||
{
|
||||
operatorCond = o;
|
||||
type = WithOther;
|
||||
}
|
||||
|
||||
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o, QVariant r)
|
||||
: left(l), operand(r)
|
||||
{
|
||||
operatorCond = o;
|
||||
type = WithVariant;
|
||||
}
|
||||
|
||||
PhraseData::~PhraseData()
|
||||
{
|
||||
if (type == WithOther) {
|
||||
delete left;
|
||||
delete right;
|
||||
}
|
||||
if (type == WithVariant) {
|
||||
if (left)
|
||||
delete left;
|
||||
}
|
||||
}
|
||||
|
||||
PhraseData *WherePhrase::data() const
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
WherePhrase::WherePhrase(const char *className, const char *s)
|
||||
{
|
||||
_data = new PhraseData(className, s);
|
||||
}
|
||||
|
||||
WherePhrase::WherePhrase(const WherePhrase &l)
|
||||
{
|
||||
_data = l._data;
|
||||
_dataPointer = QSharedPointer<PhraseData>(l._dataPointer);
|
||||
}
|
||||
|
||||
WherePhrase::WherePhrase(WherePhrase *l)
|
||||
{
|
||||
_data = l->_data;
|
||||
|
||||
l->_data = 0;
|
||||
l->_dataPointer.reset(0);
|
||||
}
|
||||
|
||||
WherePhrase::WherePhrase(WherePhrase *l, PhraseData::Condition o)
|
||||
{
|
||||
_data = new PhraseData(l->_data, o);
|
||||
l->_data = 0;
|
||||
l->_dataPointer.reset(0);
|
||||
}
|
||||
|
||||
WherePhrase::WherePhrase(WherePhrase *l, PhraseData::Condition o,
|
||||
WherePhrase *r)
|
||||
{
|
||||
_data = new PhraseData(l->_data, o, r->_data);
|
||||
l->_data = 0;
|
||||
r->_data = 0;
|
||||
|
||||
l->_dataPointer.reset(0);
|
||||
r->_dataPointer.reset(0);
|
||||
}
|
||||
|
||||
WherePhrase::WherePhrase(WherePhrase *l, PhraseData::Condition o, QVariant r)
|
||||
{
|
||||
_data = new PhraseData(l->_data, o, r);
|
||||
l->_data = 0;
|
||||
l->_dataPointer.reset(0);
|
||||
}
|
||||
|
||||
WherePhrase::~WherePhrase()
|
||||
{
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator==(const WherePhrase &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Equal, (WherePhrase *)&other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator!=(const WherePhrase &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::NotEqual, (WherePhrase *)&other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator<(const WherePhrase &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Less, (WherePhrase *)&other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator>(const WherePhrase &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Greater, (WherePhrase *)&other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator<=(const WherePhrase &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::LessEqual, (WherePhrase *)&other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator>=(const WherePhrase &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::GreaterEqual, (WherePhrase *)&other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator!()
|
||||
{
|
||||
if (_data->operatorCond < 20)
|
||||
_data->operatorCond
|
||||
= (PhraseData::Condition)((_data->operatorCond + 10) % 20);
|
||||
else
|
||||
qFatal("Operator ! can not aplied to non condition statements");
|
||||
|
||||
return this; // WherePhrase(this, PhraseData::Not);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator=(const WherePhrase &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Set, (WherePhrase *)&other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator+(const WherePhrase &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Add, (WherePhrase *)&other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator-(const WherePhrase &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Minus, (WherePhrase *)&other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator*(const WherePhrase &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Multiple, (WherePhrase *)&other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator/(const WherePhrase &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Divide, (WherePhrase *)&other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator&&(const WherePhrase &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::And, (WherePhrase *)&other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator||(const WherePhrase &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Or, (WherePhrase *)&other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator&(const WherePhrase &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Append, (WherePhrase *)&other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator==(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Equal, other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator!=(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::NotEqual, other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator<(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Less, other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator>(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Greater, other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator<=(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::LessEqual, other);
|
||||
}
|
||||
|
||||
WherePhrase WherePhrase::operator>=(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::GreaterEqual, other);
|
||||
}
|
||||
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
|
@ -1,515 +0,0 @@
|
|||
/**************************************************************************
|
||||
**
|
||||
** 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 WHEREPHRASE_H
|
||||
#define WHEREPHRASE_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#include <QVariant>
|
||||
#include <QDate>
|
||||
#include <QDateTime>
|
||||
#include <QTime>
|
||||
#include <QPoint>
|
||||
#include <QSharedPointer>
|
||||
#include "defines.h"
|
||||
#include "types/dbgeography.h"
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
#include <initializer_list>
|
||||
#endif
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
class SqlGeneratorBase;
|
||||
//class PhraseData
|
||||
//{
|
||||
//public:
|
||||
// enum Condition {
|
||||
// NotAssign = 0,
|
||||
// Equal,
|
||||
// Less,
|
||||
// LessEqual,
|
||||
// Null,
|
||||
// In,
|
||||
// Like,
|
||||
|
||||
// Not = 10,
|
||||
// NotEqual,
|
||||
// GreaterEqual,
|
||||
// Greater,
|
||||
// NotNull,
|
||||
// NotIn,
|
||||
// NotLike,
|
||||
|
||||
// And = 20,
|
||||
// Or,
|
||||
|
||||
// Append,
|
||||
// Set,
|
||||
|
||||
// Add,
|
||||
// Minus,
|
||||
// Multiple,
|
||||
// Divide,
|
||||
|
||||
// // special types
|
||||
// Distance
|
||||
// };
|
||||
|
||||
// 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();
|
||||
//};
|
||||
|
||||
class WherePhrase
|
||||
{
|
||||
protected:
|
||||
PhraseData *_data;
|
||||
QSharedPointer<PhraseData> _dataPointer;
|
||||
|
||||
public:
|
||||
WherePhrase(const char *className, const char *s);
|
||||
|
||||
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);
|
||||
|
||||
~WherePhrase();
|
||||
|
||||
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 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);
|
||||
|
||||
WherePhrase operator!();
|
||||
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);
|
||||
|
||||
PhraseData *data() const;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class FieldPhrase : public WherePhrase
|
||||
{
|
||||
public:
|
||||
FieldPhrase(const char *className, const char *s);
|
||||
|
||||
WherePhrase operator=(const FieldPhrase<T> &other);
|
||||
|
||||
WherePhrase operator=(const WherePhrase &other);
|
||||
WherePhrase operator=(const QVariant &other);
|
||||
WherePhrase operator+(const QVariant &other);
|
||||
WherePhrase operator!();
|
||||
|
||||
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);
|
||||
|
||||
WherePhrase isNull();
|
||||
WherePhrase in(QList<T> list);
|
||||
// WherePhrase in(QStringList list);
|
||||
WherePhrase like(QString pattern);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
Q_OUTOFLINE_TEMPLATE FieldPhrase<T>::FieldPhrase(const char *className,
|
||||
const char *s)
|
||||
: WherePhrase(className, s)
|
||||
{
|
||||
// qDebug() << "(" << this << ")" << "FieldPhrase ctor" << className <<
|
||||
// s;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Q_OUTOFLINE_TEMPLATE WherePhrase FieldPhrase<T>::
|
||||
operator=(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Set, other);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Q_OUTOFLINE_TEMPLATE WherePhrase
|
||||
FieldPhrase<T>::operator=(const FieldPhrase<T> &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Equal, &other);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Q_OUTOFLINE_TEMPLATE WherePhrase FieldPhrase<T>::
|
||||
operator=(const WherePhrase &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Set, &other);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Q_OUTOFLINE_TEMPLATE WherePhrase FieldPhrase<T>::
|
||||
operator+(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Add, other);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Q_OUTOFLINE_TEMPLATE WherePhrase FieldPhrase<T>::operator!()
|
||||
{
|
||||
if (_data->operatorCond < 20)
|
||||
_data->operatorCond
|
||||
= (PhraseData::Condition)((_data->operatorCond + 10) % 20);
|
||||
else
|
||||
qFatal("Operator ! can not aplied to non condition statements");
|
||||
|
||||
return this; // WherePhrase(this, PhraseData::Not);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Q_OUTOFLINE_TEMPLATE WherePhrase FieldPhrase<T>::
|
||||
operator==(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Equal, other);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Q_OUTOFLINE_TEMPLATE WherePhrase FieldPhrase<T>::
|
||||
operator!=(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::NotEqual, other);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Q_OUTOFLINE_TEMPLATE WherePhrase FieldPhrase<T>::
|
||||
operator<(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Less, other);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Q_OUTOFLINE_TEMPLATE WherePhrase FieldPhrase<T>::
|
||||
operator>(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Greater, other);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Q_OUTOFLINE_TEMPLATE WherePhrase FieldPhrase<T>::
|
||||
operator<=(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::LessEqual, other);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Q_OUTOFLINE_TEMPLATE WherePhrase FieldPhrase<T>::
|
||||
operator>=(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::GreaterEqual, other);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Q_OUTOFLINE_TEMPLATE WherePhrase FieldPhrase<T>::isNull()
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Null);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Q_OUTOFLINE_TEMPLATE WherePhrase FieldPhrase<T>::in(QList<T> list)
|
||||
{
|
||||
QVariantList vlist;
|
||||
foreach (T t, list)
|
||||
vlist.append(QVariant::fromValue(t));
|
||||
|
||||
return WherePhrase(this, PhraseData::In, vlist);
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// Q_OUTOFLINE_TEMPLATE WherePhrase FieldPhrase<T>::in(QStringList list)
|
||||
//{
|
||||
// return WherePhrase(this, PhraseData::In, list);
|
||||
//}
|
||||
|
||||
template <typename T>
|
||||
Q_OUTOFLINE_TEMPLATE WherePhrase FieldPhrase<T>::like(QString pattern)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Like, pattern);
|
||||
}
|
||||
|
||||
// Custom types
|
||||
template <>
|
||||
class FieldPhrase<DbGeography> : public WherePhrase
|
||||
{
|
||||
public:
|
||||
FieldPhrase(const char *className, const char *s)
|
||||
: WherePhrase(className, s)
|
||||
{
|
||||
}
|
||||
|
||||
WherePhrase distance(const DbGeography &geo)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Distance,
|
||||
QVariant::fromValue(geo));
|
||||
}
|
||||
};
|
||||
|
||||
// Custom types
|
||||
template <>
|
||||
class FieldPhrase<QPoint> : public WherePhrase
|
||||
{
|
||||
public:
|
||||
FieldPhrase(const char *className, const char *s)
|
||||
: WherePhrase(className, s)
|
||||
{
|
||||
}
|
||||
|
||||
WherePhrase distance(const QPoint &geo)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Distance,
|
||||
QVariant::fromValue(geo));
|
||||
}
|
||||
WherePhrase operator=(const QPoint &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Set, other);
|
||||
}
|
||||
};
|
||||
|
||||
// Custom types
|
||||
template <>
|
||||
class FieldPhrase<QPointF> : public WherePhrase
|
||||
{
|
||||
public:
|
||||
FieldPhrase(const char *className, const char *s)
|
||||
: WherePhrase(className, s)
|
||||
{
|
||||
}
|
||||
|
||||
WherePhrase distance(const QPointF &geo)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Distance,
|
||||
QVariant::fromValue(geo));
|
||||
}
|
||||
WherePhrase operator=(const QPointF &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Set, other);
|
||||
}
|
||||
};
|
||||
|
||||
// template<>
|
||||
// class FieldPhrase<QString>: public WherePhrase {
|
||||
// public:
|
||||
// FieldPhrase(const char *className, const char* s) : WherePhrase(className,
|
||||
// s){
|
||||
|
||||
// }
|
||||
|
||||
// WherePhrase like(QString pattern)
|
||||
// {
|
||||
// return WherePhrase(this, PhraseData::Like, pattern);
|
||||
// }
|
||||
//};
|
||||
|
||||
template <>
|
||||
class FieldPhrase<bool> : public WherePhrase
|
||||
{
|
||||
public:
|
||||
FieldPhrase(const char *className, const char *s)
|
||||
: WherePhrase(className, s)
|
||||
{
|
||||
}
|
||||
|
||||
WherePhrase operator==(const bool &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Equal, other ? 1 : 0);
|
||||
}
|
||||
|
||||
WherePhrase operator=(const bool &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Set, other ? 1 : 0);
|
||||
}
|
||||
|
||||
WherePhrase operator!()
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Equal, 0);
|
||||
}
|
||||
};
|
||||
|
||||
class NumericFieldPhrase : public WherePhrase
|
||||
{
|
||||
public:
|
||||
NumericFieldPhrase(const char *className, const char *s)
|
||||
: WherePhrase(className, s)
|
||||
{
|
||||
}
|
||||
|
||||
WherePhrase operator=(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Set, other);
|
||||
}
|
||||
|
||||
WherePhrase operator+(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Add, other);
|
||||
}
|
||||
|
||||
WherePhrase operator-(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Minus, other);
|
||||
}
|
||||
|
||||
WherePhrase operator++()
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Add, 1);
|
||||
}
|
||||
|
||||
WherePhrase operator--()
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Minus, 1);
|
||||
}
|
||||
|
||||
WherePhrase operator==(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Equal, other);
|
||||
}
|
||||
|
||||
WherePhrase operator!=(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::NotEqual, other);
|
||||
}
|
||||
|
||||
WherePhrase operator<(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Less, other);
|
||||
}
|
||||
|
||||
WherePhrase operator>(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Greater, other);
|
||||
}
|
||||
|
||||
WherePhrase operator<=(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::LessEqual, other);
|
||||
}
|
||||
|
||||
WherePhrase operator>=(const QVariant &other)
|
||||
{
|
||||
return WherePhrase(this, PhraseData::GreaterEqual, other);
|
||||
}
|
||||
|
||||
WherePhrase isNull()
|
||||
{
|
||||
return WherePhrase(this, PhraseData::Null);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
WherePhrase in(QList<T> list)
|
||||
{
|
||||
QVariantList vlist;
|
||||
foreach (T t, list)
|
||||
vlist.append(QVariant::fromValue(t));
|
||||
return WherePhrase(this, PhraseData::In, vlist);
|
||||
}
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
template<typename T>
|
||||
WherePhrase in(std::initializer_list<T> list)
|
||||
{
|
||||
return in(QList<T>(list));
|
||||
}
|
||||
#endif
|
||||
|
||||
WherePhrase in(int count, ...)
|
||||
{
|
||||
QVariantList vlist;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, count);
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
vlist.append(QVariant::fromValue(va_arg(ap, int)));
|
||||
|
||||
va_end(ap);
|
||||
|
||||
return WherePhrase(this, PhraseData::In, vlist);
|
||||
}
|
||||
};
|
||||
|
||||
#define SPECIALIZATION_NUMERIC(type) \
|
||||
template <> \
|
||||
class FieldPhrase<type> : public NumericFieldPhrase \
|
||||
{ \
|
||||
public: \
|
||||
FieldPhrase(const char *className, const char *s) \
|
||||
: NumericFieldPhrase(className, s) \
|
||||
{ \
|
||||
} \
|
||||
WherePhrase operator=(const WherePhrase &other) \
|
||||
{ \
|
||||
return WherePhrase(this, PhraseData::Set, (WherePhrase *)&other); \
|
||||
} \
|
||||
};
|
||||
|
||||
SPECIALIZATION_NUMERIC(qint8)
|
||||
SPECIALIZATION_NUMERIC(qint16)
|
||||
SPECIALIZATION_NUMERIC(qint32)
|
||||
SPECIALIZATION_NUMERIC(qint64)
|
||||
|
||||
SPECIALIZATION_NUMERIC(quint8)
|
||||
SPECIALIZATION_NUMERIC(quint16)
|
||||
SPECIALIZATION_NUMERIC(quint32)
|
||||
SPECIALIZATION_NUMERIC(quint64)
|
||||
|
||||
SPECIALIZATION_NUMERIC(qreal)
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
||||
#endif // PHRASE_H
|
||||
|
|
@ -27,7 +27,6 @@ private slots:
|
|||
void createUser();
|
||||
void createPost();
|
||||
void createPost2();
|
||||
void updatePostOnTheFly();
|
||||
void selectPublicts();
|
||||
void join();
|
||||
void selectPosts();
|
||||
|
|
@ -35,6 +34,7 @@ private slots:
|
|||
void selectFirst();
|
||||
void selectPostsWithoutTitle();
|
||||
void selectPostIds();
|
||||
void updatePostOnTheFly();
|
||||
void testDate();
|
||||
void selectWithInvalidRelation();
|
||||
void modifyPost();
|
||||
|
|
|
|||
Loading…
Reference in New Issue