Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 8fea42af

Von Christian Ehringfeld vor fast 9 Jahren hinzugefügt

  • ID 8fea42af2ffe30dca862a043fea27805a56b48e7
  • Vorgänger 2316d17f
  • Nachfolger 73f81d04

wip

Unterschiede anzeigen:

src/query.cpp
#include "query.h"
#include "entity.h"
#include "querybuilder.h"
#include "entityinstancefactory.h"
using namespace CuteEntityManager;
Query::Query() {
}
src/querybuilder.cpp
return true;
}
//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 r;
//}
void QueryBuilder::createRelationFK(QStringList &queries,
const QSharedPointer<Entity> &entity, const Relation &relation,
const QMetaProperty &metaProperty, const QString &update,
src/queryinterpreter.cpp
#include "orderby.h"
#include "expression.h"
#include "schema.h"
#include "entityinstancefactory.h"
using namespace CuteEntityManager;
......
}
QSqlQuery QueryInterpreter::build(Query &q, const QMetaObject *obj) {
if(obj) {
this->resolveRelations(q, obj);
}
QList<QString> clauses = QList<QString>();
clauses.append(this->buildSelect(q, q.getSelect(), q.getDistinct(),
q.getSelectOption()));
......
return sqlOrder;
}
QString QueryInterpreter::buildCondition(Query &q,
const QList<Expression> &conditions) const {
if (conditions.isEmpty()) {
......
return sqlCondition;
}
QVariant QueryInterpreter::convertParamValue(const QVariant val) const {
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 r;
}
void QueryInterpreter::resolveRelations(Query &q, const QMetaObject *obj) {
q.getSelect();
q.getWhere();
q.getGroupBy();
q.getHaving();
}
QList<Expression> QueryInterpreter::resolve(Query &q, const QMetaObject *obj,
QList<Expression> exp) {
}
void QueryInterpreter::convertParams(const QString &prefix,
QHash<QString, QVariant> &params, QString &condition, int &start) const {
auto keys = params.keys();
......
QString val = prefix + QString::number(start);
condition.replace(this->ar->getQb()->placeHolder(keys.at(i)),
this->ar->getQb()->placeHolder(val));
params.insert(val, params.value(keys.at(i)));
params.insert(val, this->convertParamValue(params.value(keys.at(i))));
params.remove(keys.at(i));
++start;
}
src/queryinterpreter.h
class QueryInterpreter {
public:
QueryInterpreter(QSharedPointer<AttributeResolver> ar);
QSqlQuery build(Query &q, const QMetaObject *obj=nullptr);
QSqlQuery build(Query &q, const QMetaObject *obj = nullptr);
protected:
QString buildSelect(Query &q, const QList<Expression> &columns,
......
QString buildCondition(Query &q, const QList<Expression> &conditions) const;
void convertParams(const QString &prefix,
QHash<QString, QVariant> &params, QString &condition, int &start) const;
QVariant convertParamValue(const QVariant val) const;
void resolveRelations(Query &q, const QMetaObject *obj);
QList<Expression> resolve(Query &q, const QMetaObject *obj, QList<Expression> exp);
private:
QSharedPointer<AttributeResolver> ar;

Auch abrufbar als: Unified diff