Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision c6e41b5c

Von Christian Ehringfeld vor fast 9 Jahren hinzugefügt

  • ID c6e41b5c5dbddc4e194143856f1f7e0cbc8a74e5
  • Vorgänger 77cccf8a
  • Nachfolger 2316d17f

wip

Unterschiede anzeigen:

src/query.cpp
return qb->like(conditions, conjunction, jp, wildcard);
}
QVariant Query::convertParam(QVariant &val) {
if(QString(val.typeName()).contains("QSharedPointer")) {
auto entity = EntityInstanceFactory::castQVariant(val);
if(entity && entity->getId() != -1) {
return entity->getProperty(entity->getPrimaryKey());
QVariant Query::convertParam(const QVariant val) {
auto typeName = QString(val.typeName());
QVariant r = val;
if(typeName.contains("QSharedPointer")) {
if(typeName.contains("QList")) {
auto entities = EntityInstanceFactory::castQVariantList(r);
QList<QVariant> ids;
for (int i = 0; i < entities.size(); ++i) {
if(entities.at(i)) {
ids.append(entities.at(i)->getProperty(entities.at(i)->getPrimaryKey()));
}
}
r.setValue<QList<QVariant>>(ids);
} else {
auto entity = EntityInstanceFactory::castQVariant(r);
if(entity && entity->getId() != -1) {
r = entity->getProperty(entity->getPrimaryKey());
}
}
}
return val;
return r;
}
QString Query::getSelectOption() const {
......
}
void Query::appendParam(const QString &column, QVariant value) {
this->params.insert(column, value);
this->params.insert(column, this->convertParam(value));
}
void Query::appendParams(const QHash<QString, QVariant> &params) {
for (auto i = params.constBegin(); i != params.constEnd(); ++i) {
this->params.insert(i.key(), i.value());
this->params.insert(i.key(), this->convertParam(i.value()));
}
}
src/query.h
QString conjunction = QStringLiteral("AND"),
JokerPosition jp = JokerPosition::BOTH, QChar wildcard = '%');
protected:
QVariant convertParam(QVariant &val);
QVariant convertParam(const QVariant val);
private:
QList<Expression> select;
tests/em/tst_querybuilder.cpp
QSharedPointer<Person> p = this->e->findEntityByAttributes<Person>(attributes, true);
QVERIFY(p);
attributes.clear();
attributes["leader"] = QVariant(p);
QVariant var;
var.setValue<QSharedPointer<Entity>>(p);
attributes["leader"] = var;
QSharedPointer<Group> group = e->findEntityByAttributes<Group>
(attributes, true);
QVERIFY(group);
......
QCOMPARE(list.size(), 1);
QCOMPARE(list.at(0)->getNickName(), QString("Lotta"));
q = Query();
q.appendWhere(q.equal(qb, "leader", QVariant(list.at(0))));
QVariant var;
var.setValue<QSharedPointer<Entity>>(list.at(0));
q.appendWhere(q.equal(qb, "leader", QVariant(var)));
QList<QSharedPointer<Group>> groupList = e->find<Group>(q, false);
QCOMPARE(groupList.size(), 1);
QCOMPARE(groupList.at(0)->getName(), QString("Group Health"));
......
QCOMPARE(list.size(), 1);
QCOMPARE(list.at(0)->getNickName(), QString("Lotta"));
q = Query();
q.appendWhere(q.equal(qb, "persons", QVariant(list.at(0))));
QVariant var;
var.setValue<QSharedPointer<Entity>>(list.at(0));
q.appendWhere(q.equal(qb, "persons", QVariant(var)));
QList<QSharedPointer<Group>> groupList = e->find<Group>(q, false);
QCOMPARE(groupList.size(), 1);
QCOMPARE(groupList.at(0)->getName(), QString("Group Health"));

Auch abrufbar als: Unified diff