test passed!
This commit is contained in:
parent
ace81b6fed
commit
56d8e3e6f7
|
|
@ -34,18 +34,18 @@ PhraseData::PhraseData(const char *className, const char *fieldName) :
|
||||||
|
|
||||||
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o)
|
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o)
|
||||||
: className(0), fieldName(0),
|
: className(0), fieldName(0),
|
||||||
type(WithoutOperand), operatorCond(o), left(l), right(0), isNot(false)
|
type(WithoutOperand), operatorCond(o), left(new PhraseData(l)), right(0), isNot(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o,
|
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o,
|
||||||
const PhraseData *r)
|
const PhraseData *r)
|
||||||
: className(0), fieldName(0),
|
: className(0), fieldName(0),
|
||||||
type(WithOther), operatorCond(o), left(l), right(r), isNot(false)
|
type(WithOther), operatorCond(o), left(new PhraseData(l)), right(new PhraseData(r)), isNot(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o, QVariant r)
|
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o, QVariant r)
|
||||||
: className(0), fieldName(0),
|
: className(0), fieldName(0),
|
||||||
type(WithVariant), operatorCond(o), left(l), operand(r), isNot(false)
|
type(WithVariant), operatorCond(o), left(new PhraseData(l)), operand(r), isNot(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
PhraseData::PhraseData(const PhraseData *other)
|
PhraseData::PhraseData(const PhraseData *other)
|
||||||
|
|
@ -57,6 +57,10 @@ PhraseData::PhraseData(const PhraseData *other)
|
||||||
className = other->className;
|
className = other->className;
|
||||||
fieldName = other->fieldName;
|
fieldName = other->fieldName;
|
||||||
type = other->type;
|
type = other->type;
|
||||||
|
isNot = other->isNot;
|
||||||
|
if (type != Field) {
|
||||||
|
qDebug() << "Bug";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PhraseData::toString() const
|
QString PhraseData::toString() const
|
||||||
|
|
@ -103,8 +107,9 @@ AbstractFieldPhrase::~AbstractFieldPhrase()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PhraseList AbstractFieldPhrase::operator |(const AbstractFieldPhrase &other) {
|
PhraseList AbstractFieldPhrase::operator |(const AbstractFieldPhrase &other)
|
||||||
return PhraseList(this, &other);
|
{
|
||||||
|
return PhraseList(this, other);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConditionalPhrase AbstractFieldPhrase::isNull()
|
ConditionalPhrase AbstractFieldPhrase::isNull()
|
||||||
|
|
@ -164,34 +169,38 @@ PhraseList::PhraseList() : isValid(false)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PhraseList::PhraseList(const AbstractFieldPhrase &other) : isValid(true)
|
PhraseList::PhraseList(const PhraseList &other)
|
||||||
{
|
{
|
||||||
data.append(other.data);
|
data = qMove(other.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
PhraseList::PhraseList(AbstractFieldPhrase *left, const AbstractFieldPhrase *right)
|
PhraseList::PhraseList(const AbstractFieldPhrase &other) : isValid(true)
|
||||||
|
{
|
||||||
|
data.append(new PhraseData(other.data));
|
||||||
|
}
|
||||||
|
|
||||||
|
PhraseList::PhraseList(const AbstractFieldPhrase *left, const AbstractFieldPhrase &right)
|
||||||
: isValid(true)
|
: isValid(true)
|
||||||
{
|
{
|
||||||
data.append(left->data);
|
data.append(new PhraseData(left->data));
|
||||||
data.append(right->data);
|
data.append(new PhraseData(right.data));
|
||||||
}
|
}
|
||||||
|
|
||||||
PhraseList::PhraseList(PhraseList *left, PhraseList *right) : isValid(true)
|
PhraseList::PhraseList(PhraseList *left, PhraseList *right) : isValid(true)
|
||||||
{
|
{
|
||||||
data = left->data;
|
data = qMove(left->data + right->data);
|
||||||
data.append(right->data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PhraseList::PhraseList(PhraseList *left, const AbstractFieldPhrase *right)
|
PhraseList::PhraseList(PhraseList *left, const AbstractFieldPhrase *right)
|
||||||
: isValid(true)
|
: isValid(true)
|
||||||
{
|
{
|
||||||
data = left->data;
|
data = left->data;
|
||||||
data.append(right->data);
|
data.append(new PhraseData(right->data));
|
||||||
}
|
}
|
||||||
|
|
||||||
PhraseList::~PhraseList()
|
PhraseList::~PhraseList()
|
||||||
{
|
{
|
||||||
data.clear();
|
// data.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
PhraseList PhraseList::operator |(const AbstractFieldPhrase &other) {
|
PhraseList PhraseList::operator |(const AbstractFieldPhrase &other) {
|
||||||
|
|
@ -247,23 +256,21 @@ AssignmentPhraseList AssignmentPhraseList::operator &(const AssignmentPhrase &ph
|
||||||
return AssignmentPhraseList(this, &ph);
|
return AssignmentPhraseList(this, &ph);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConditionalPhrase::ConditionalPhrase()
|
ConditionalPhrase::ConditionalPhrase() : data(0)
|
||||||
{
|
{ }
|
||||||
this->data = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConditionalPhrase::ConditionalPhrase(const ConditionalPhrase &other)
|
ConditionalPhrase::ConditionalPhrase(const ConditionalPhrase &other)
|
||||||
{
|
{
|
||||||
qDebug() << "************* ctor called:";
|
qDebug() << "************* ctor called:";
|
||||||
this->data = new PhraseData(other.data);
|
this->data = new PhraseData(other.data);
|
||||||
|
// const_cast<ConditionalPhrase&>(other).data = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __cplusplus >= 201103L
|
|
||||||
ConditionalPhrase::ConditionalPhrase(const ConditionalPhrase &&other)
|
ConditionalPhrase::ConditionalPhrase(const ConditionalPhrase &&other)
|
||||||
{
|
{
|
||||||
this->data = std::move(other.data);
|
qDebug() << "************* ctor called:";
|
||||||
|
this->data = qMove(other.data);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
ConditionalPhrase::ConditionalPhrase(const PhraseData *data)
|
ConditionalPhrase::ConditionalPhrase(const PhraseData *data)
|
||||||
{
|
{
|
||||||
|
|
@ -332,8 +339,8 @@ ConditionalPhrase::~ConditionalPhrase()
|
||||||
|
|
||||||
ConditionalPhrase ConditionalPhrase::operator =(const ConditionalPhrase &other)
|
ConditionalPhrase ConditionalPhrase::operator =(const ConditionalPhrase &other)
|
||||||
{
|
{
|
||||||
return ConditionalPhrase(other.data);
|
this->data = new PhraseData(other.data);
|
||||||
const_cast<ConditionalPhrase&>(other).data = 0;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConditionalPhrase ConditionalPhrase::operator ==(const QVariant &other)
|
ConditionalPhrase ConditionalPhrase::operator ==(const QVariant &other)
|
||||||
|
|
|
||||||
|
|
@ -142,8 +142,9 @@ public:
|
||||||
bool isValid;
|
bool isValid;
|
||||||
QList<const PhraseData*> data;
|
QList<const PhraseData*> data;
|
||||||
PhraseList();
|
PhraseList();
|
||||||
|
PhraseList(const PhraseList &other);
|
||||||
PhraseList(const AbstractFieldPhrase &other);
|
PhraseList(const AbstractFieldPhrase &other);
|
||||||
PhraseList(AbstractFieldPhrase *left, const AbstractFieldPhrase *right);
|
PhraseList(const AbstractFieldPhrase *left, const AbstractFieldPhrase &right);
|
||||||
PhraseList(PhraseList *left, PhraseList *right);
|
PhraseList(PhraseList *left, PhraseList *right);
|
||||||
PhraseList(PhraseList *left, const AbstractFieldPhrase *right);
|
PhraseList(PhraseList *left, const AbstractFieldPhrase *right);
|
||||||
virtual ~PhraseList();
|
virtual ~PhraseList();
|
||||||
|
|
@ -160,9 +161,7 @@ public:
|
||||||
QSharedPointer<PhraseData> rightDataPointer;
|
QSharedPointer<PhraseData> rightDataPointer;
|
||||||
ConditionalPhrase();
|
ConditionalPhrase();
|
||||||
ConditionalPhrase(const ConditionalPhrase &other);
|
ConditionalPhrase(const ConditionalPhrase &other);
|
||||||
#if __cplusplus >= 201103L
|
|
||||||
ConditionalPhrase(const ConditionalPhrase &&other);
|
ConditionalPhrase(const ConditionalPhrase &&other);
|
||||||
#endif
|
|
||||||
ConditionalPhrase(const PhraseData *data);
|
ConditionalPhrase(const PhraseData *data);
|
||||||
ConditionalPhrase(AbstractFieldPhrase *, PhraseData::Condition);
|
ConditionalPhrase(AbstractFieldPhrase *, PhraseData::Condition);
|
||||||
ConditionalPhrase(AbstractFieldPhrase *, PhraseData::Condition, const QVariant &v);
|
ConditionalPhrase(AbstractFieldPhrase *, PhraseData::Condition, const QVariant &v);
|
||||||
|
|
|
||||||
49
src/query.h
49
src/query.h
|
|
@ -139,7 +139,7 @@ Q_OUTOFLINE_TEMPLATE QList<T *> Query<T>::toList(int count)
|
||||||
d->sql = d->database->sqlGenertor()->selectCommand(
|
d->sql = d->database->sqlGenertor()->selectCommand(
|
||||||
d->tableName, d->fieldPhrase, d->wherePhrase, d->orderPhrase,
|
d->tableName, d->fieldPhrase, d->wherePhrase, d->orderPhrase,
|
||||||
d->relations, d->skip, d->take);
|
d->relations, d->skip, d->take);
|
||||||
|
qDebug() <<d->sql;
|
||||||
QSqlQuery q = d->database->exec(d->sql);
|
QSqlQuery q = d->database->exec(d->sql);
|
||||||
if (q.lastError().isValid()) {
|
if (q.lastError().isValid()) {
|
||||||
qDebug() << q.lastError().text();
|
qDebug() << q.lastError().text();
|
||||||
|
|
@ -151,7 +151,6 @@ Q_OUTOFLINE_TEMPLATE QList<T *> Query<T>::toList(int count)
|
||||||
foreach (RelationModel *rel, d->relations)
|
foreach (RelationModel *rel, d->relations)
|
||||||
relatedTables << rel->slaveTable << rel->masterTable;
|
relatedTables << rel->slaveTable << rel->masterTable;
|
||||||
|
|
||||||
|
|
||||||
struct LevelData{
|
struct LevelData{
|
||||||
QList<int> masters;
|
QList<int> masters;
|
||||||
QList<int> slaves;
|
QList<int> slaves;
|
||||||
|
|
@ -441,7 +440,10 @@ template <class T>
|
||||||
Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::where(const ConditionalPhrase &ph)
|
Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::where(const ConditionalPhrase &ph)
|
||||||
{
|
{
|
||||||
Q_D(Query);
|
Q_D(Query);
|
||||||
d->wherePhrase = d->wherePhrase && ph;
|
if (d->wherePhrase.data)
|
||||||
|
d->wherePhrase = d->wherePhrase && ph;
|
||||||
|
else
|
||||||
|
d->wherePhrase = ph;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -541,32 +543,31 @@ Q_OUTOFLINE_TEMPLATE int Query<T>::remove()
|
||||||
template <class T>
|
template <class T>
|
||||||
Q_OUTOFLINE_TEMPLATE QSqlQueryModel *Query<T>::toModal()
|
Q_OUTOFLINE_TEMPLATE QSqlQueryModel *Query<T>::toModal()
|
||||||
{
|
{
|
||||||
// Q_D(Query);
|
Q_D(Query);
|
||||||
|
|
||||||
|
d->sql = d->database->sqlGenertor()->selectCommand(
|
||||||
|
d->tableName,
|
||||||
|
d->fieldPhrase,
|
||||||
|
d->wherePhrase, d->orderPhrase, d->relations,
|
||||||
|
d->skip, d->take);
|
||||||
|
|
||||||
// QString fff = "";
|
DatabaseModel dbModel = d->database->model();
|
||||||
|
QSqlQueryModel *model = new QSqlQueryModel;
|
||||||
|
model->setQuery(d->sql, d->database->database());
|
||||||
|
|
||||||
// foreach (WherePhrase p, d->fields) {
|
int fieldIndex = 0;
|
||||||
// if (fff != "")
|
foreach (const PhraseData *pd, d->fieldPhrase.data) {
|
||||||
// fff.append(", ");
|
QString displayName = dbModel.tableByClassName(pd->className)
|
||||||
// fff.append(d->database->sqlGenertor()->phraseOrder(p.data()));
|
->field(pd->fieldName)->displayName;
|
||||||
// }
|
|
||||||
|
|
||||||
// d->sql = d->database->sqlGenertor()->selectCommand(
|
qDebug() << "Display name for"<<pd->className<<pd->fieldName
|
||||||
// SqlGeneratorBase::SelectAll, "",
|
<<"="<<displayName;
|
||||||
// d->tableName,
|
model->setHeaderData(fieldIndex++,
|
||||||
// d->wheres, d->orderPhrases, d->relations,
|
Qt::Horizontal,
|
||||||
// d->skip, d->take);
|
displayName);
|
||||||
// qDebug()<<"Model to" << fff;
|
}
|
||||||
// QSqlQueryModel *model = new QSqlQueryModel;
|
|
||||||
// TableModel *tableModel = d->database->model().tableByName(d->tableName);
|
|
||||||
// model->setQuery(d->sql, d->database->database());
|
|
||||||
|
|
||||||
// int fieldIndex = 0;
|
return model;
|
||||||
// foreach (FieldModel *f, tableModel->fields()) {
|
|
||||||
// model->setHeaderData(fieldIndex++, Qt::Horizontal, f->displayName);
|
|
||||||
// }
|
|
||||||
// return model;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
|
|
|
||||||
|
|
@ -264,7 +264,7 @@ TableModel::TableModel(int typeId, QString tableName)
|
||||||
else if(type == __nut_UNIQUE)
|
else if(type == __nut_UNIQUE)
|
||||||
f->isUnique = true;
|
f->isUnique = true;
|
||||||
else if(type == __nut_DISPLAY)
|
else if(type == __nut_DISPLAY)
|
||||||
f->displayName = value;
|
f->displayName = value.mid(1, value.length() - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!findByTypeId(typeId) && !tableName.isNull())
|
if(!findByTypeId(typeId) && !tableName.isNull())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue