Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b0e92bc6

Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt

  • ID b0e92bc613953f25368ba575d62528e10b025a53
  • Vorgänger 47f9301a
  • Nachfolger 696666eb

fks

Unterschiede anzeigen:

src/querybuilder.cpp
QStringList QueryBuilder::relationFks(const QSharedPointer<Entity> &entity)
const {
QStringList queries = QStringList();
auto relations = entity.data()->getNonInheritedRelations();
auto props = entity.data()->getMetaProperties();
auto iterator = relations.constBegin();
while (iterator != relations.constEnd()) {
auto relation = iterator.value();
if (relation.getMappedBy().isEmpty() && !relation.getCascadeType().isEmpty()) {
QString update = relation.getCascadeType().contains(MERGE)
|| relation.getCascadeType().contains(ALL) ? this->getForeignKeyCascade(
CASCADE) : this->getForeignKeyCascade(NO_ACTION);
QString remove = relation.getCascadeType().contains(REMOVE)
|| relation.getCascadeType().contains(ALL) ? this->getForeignKeyCascade(
CASCADE) : this->getForeignKeyCascade(SET_NULL);
this->createRelationFK(queries, entity, relation,
props.value(relation.getPropertyName()), update, remove);
if (this->supportsForeignKeys()) {
auto relations = entity.data()->getNonInheritedRelations();
auto props = entity.data()->getMetaProperties();
auto iterator = relations.constBegin();
while (iterator != relations.constEnd()) {
auto relation = iterator.value();
if (relation.getMappedBy().isEmpty() && !relation.getCascadeType().isEmpty()) {
QString update = relation.getCascadeType().contains(MERGE)
|| relation.getCascadeType().contains(ALL) ? this->getForeignKeyCascade(
CASCADE) : this->getForeignKeyCascade(NO_ACTION);
QString remove = relation.getCascadeType().contains(REMOVE)
|| relation.getCascadeType().contains(ALL) ? this->getForeignKeyCascade(
CASCADE) : this->getForeignKeyCascade(SET_NULL);
this->createRelationFK(queries, entity, relation,
props.value(relation.getPropertyName()), update, remove);
}
++iterator;
}
++iterator;
}
return queries;
}
bool QueryBuilder::supportsForeignKeys() const {
return true;
}
void QueryBuilder::createRelationFK(QStringList &queries,
const QSharedPointer<Entity> &entity, const Relation &relation,
const QMetaProperty &metaProperty, const QString &update,
src/querybuilder.h
&props,
const QSharedPointer<Entity> &entity) const;
virtual QStringList relationFks(const QSharedPointer<Entity> &entity) const;
virtual bool supportsForeignKeys() const;
virtual QString createForeignKeyManyToMany(const QString &tableName,
const QSharedPointer<Entity> &entity, const QString &update,
src/schema/sqlitequerybuilder.cpp
//not supported
return "";
}
bool CuteEntityManager::SqliteQueryBuilder::supportsForeignKeys() const {
return false;
}
src/schema/sqlitequerybuilder.h
virtual QString addPrimaryKey(QString name, QString tableName,
QStringList columns) const;
virtual QString dropPrimaryKey(QString name, QString tableName) const;
virtual bool supportsForeignKeys() const;
};
}
src/schema/sqliteschema.cpp
}
QStringList SqliteSchema::findTableNames(QString schema) {
Q_UNUSED(schema)
auto l = QStringList();
QString sql =
"SELECT DISTINCT tbl_name FROM sqlite_master WHERE tbl_name<>'sqlite_sequence' ORDER BY tbl_name";
src/tableschema.cpp
const QHash<QString, QSharedPointer<QSqlRelation> > &value) {
relations = value;
}
QSharedPointer<QSqlRelationalTableModel> TableSchema::getTableModel() const {
QSqlRelationalTableModel *model = new QSqlRelationalTableModel;
model->setTable(this->getName());
return QSharedPointer<QSqlRelationalTableModel>(model);
}
src/tableschema.h
#include <QSharedPointer>
#include <QSqlField>
#include <QSqlRelation>
#include <QSqlRelationalTableModel>
namespace CuteEntityManager {
class TableSchema {
......
QHash<QString, QSharedPointer<QSqlRelation> > getRelations() const;
void setRelations(const QHash<QString, QSharedPointer<QSqlRelation> > &value);
QSharedPointer<QSqlRelationalTableModel> getTableModel() const;
private:
QString schemaName;
QString name;
......
QString sequenceName;
QHash<QString, QSharedPointer<QSqlRelation>> relations;
QHash<QString, QSharedPointer<QSqlField>> columns;
};
}

Auch abrufbar als: Unified diff