Revision 4750b097
Von Christian Ehringfeld vor fast 10 Jahren hinzugefügt
| src/querybuilder.cpp | ||
|---|---|---|
|
if (!rc) {
|
||
|
QSqlQuery q = this->database->getQuery(this->createTable(tableName,
|
||
|
tableDefinition));
|
||
|
if (this->database->exec(q) && (!createRelationTables || this->createRelationTables(entity))) {
|
||
|
if (this->database->exec(q) && (!createRelationTables ||
|
||
|
this->createRelationTables(entity))) {
|
||
|
rc = true;
|
||
|
} else {
|
||
|
this->database->getLogger()->logMsg("Table " + entity->getTablename() +
|
||
| ... | ... | |
|
QStringList(this->generateColumnNameID(relation.getPropertyName())),
|
||
|
ptr->getTablename(),
|
||
|
QStringList(ptr->getPrimaryKey()), remove, update));
|
||
|
|
||
|
} else if (relation.getType() == RelationType::MANY_TO_MANY) {
|
||
|
QString tableName = this->generateManyToManyTableName(entity, ptr, relation);
|
||
|
queries.append(this->createForeignKeyManyToMany(tableName, entity, update,
|
||
| ... | ... | |
|
} else {
|
||
|
s += ", ";
|
||
|
}
|
||
|
s+= this->schema->quoteColumnName(i.key()) + " " + this->getColumnType(i.value());
|
||
|
s += this->schema->quoteColumnName(i.key()) + " " + this->getColumnType(i.value());
|
||
|
++i;
|
||
|
}
|
||
|
s += ");";
|
||
| ... | ... | |
|
}
|
||
|
|
||
|
QHash<QString, QHash<QString, QString>> QueryBuilder::generateRelationTables(
|
||
|
const QSharedPointer<Entity> &entity)
|
||
|
const {
|
||
|
const QSharedPointer<Entity> &entity) const {
|
||
|
auto relations = QHash<QString, QHash<QString, QString>>();
|
||
|
//QHash<QString, Relation> m = (entity->getInheritanceStrategy() ==
|
||
|
// InheritanceStrategy::PER_CLASS_TABLE ? entity->getRelations() :
|
||
|
// EntityHelper::getNonInheritedRelations(entity.data()));
|
||
|
QHash<QString, Relation> m = entity->getRelations();
|
||
|
QHash<QString, Relation> m = (entity->getInheritanceStrategy() ==
|
||
|
InheritanceStrategy::PER_CLASS_TABLE ? entity->getRelations() :
|
||
|
EntityHelper::getNonInheritedRelations(entity.data()));
|
||
|
//QHash<QString, Relation> m = entity->getRelations();
|
||
|
auto props = EntityHelper::getMetaProperties(entity.data());
|
||
|
for (auto i = m.begin(); i != m.end(); ++i) {
|
||
|
Relation r = i.value();
|
||
| ... | ... | |
|
sql += " " + this->whereKeyword() + " ";
|
||
|
sql += this->schema->quoteColumnName(
|
||
|
attribute);
|
||
|
sql += " " + this->equalOperator()+" " + this->placeHolder(pk) + ";";
|
||
|
sql += " " + this->equalOperator() + " " + this->placeHolder(pk) + ";";
|
||
|
q.prepare(sql);
|
||
|
this->bindValue(pk, id, q);
|
||
|
return q;
|
||
| ... | ... | |
|
} else {
|
||
|
usedProperties.insert(i.key(), i.value());
|
||
|
}
|
||
|
|
||
|
}
|
||
|
return properties;
|
||
|
}
|
||
| ... | ... | |
|
ignoreID, primaryKey);
|
||
|
}
|
||
|
|
||
|
QString QueryBuilder::where(const QString &key, const QVariant &var, bool withKeyword, bool select, bool notEqual) const {
|
||
|
QString QueryBuilder::where(const QString &key, const QVariant &var, bool withKeyword,
|
||
|
bool select, bool notEqual) const {
|
||
|
QString r = (withKeyword ? " WHERE " : "");
|
||
|
r += this->schema->quoteColumnName(key) + (var.isNull() && select
|
||
|
? (" " +(notEqual ? this->isNotNullKeywords(): this->isNullKeywords()))
|
||
|
: (notEqual ? this->notEqualOperator() : this->equalOperator() ) + this->placeHolder(key));
|
||
|
? (" " + (notEqual ? this->isNotNullKeywords() : this->isNullKeywords()))
|
||
|
: (notEqual ? this->notEqualOperator() : this->equalOperator() ) + this->placeHolder(
|
||
|
key));
|
||
|
return r;
|
||
|
}
|
||
|
|
||
| ... | ... | |
|
|
||
|
Expression QueryBuilder::equal(QString &key, QVariant &value) {
|
||
|
Expression exp = Expression(this->where(key, value, false, true, false));
|
||
|
exp.appendParam(key,value);
|
||
|
exp.appendParam(key, value);
|
||
|
return exp;
|
||
|
}
|
||
|
|
||
|
Expression QueryBuilder::notEqual(QString &key, QVariant &value) {
|
||
|
Expression exp = Expression(this->where(key, value, false, true, true));
|
||
|
exp.appendParam(key,value);
|
||
|
exp.appendParam(key, value);
|
||
|
return exp;
|
||
|
}
|
||
|
|
||
Auch abrufbar als: Unified diff
wip