Revision e86c23a2
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
src/entitymanager.cpp | ||
---|---|---|
QHash<QString, QVariant> map = QHash<QString, QVariant>();
|
||
bool ok = true;
|
||
map.insert("version", version);
|
||
if(!this->schema.data()->getTableNames().contains(dbm->getTablename())) {
|
||
this->createTable(ptrDbm,true);
|
||
}
|
||
if (this->findAllByAttributes(map, dbm->getTablename()).isEmpty()) {
|
||
for (int var = 0; var < toInitialize.size(); ++var) {
|
||
if (ok) {
|
||
... | ... | |
this->create(ptrDbm);
|
||
}
|
||
}
|
||
delete dbm;
|
||
return ok;
|
||
}
|
||
|
||
... | ... | |
return this->schema.data()->getQueryBuilder().data()->removeAll(tblname).exec();
|
||
}
|
||
|
||
bool EntityManager::createTable(const QSharedPointer<Entity> &entity) {
|
||
return this->schema.data()->getQueryBuilder().data()->createTable(entity);
|
||
bool EntityManager::createTable(const QSharedPointer<Entity> &entity,bool createRelationTables) {
|
||
return this->schema.data()->getQueryBuilder().data()->createTable(entity,createRelationTables);
|
||
}
|
||
|
||
qint8 EntityManager::count(const QSharedPointer<Entity> &entity,
|
src/entitymanager.h | ||
---|---|---|
bool merge(QSharedPointer<Entity> &entity, bool withRelations = true);
|
||
bool remove(QSharedPointer<Entity> &entity);
|
||
bool removeAll(QString tblname);
|
||
bool createTable(const QSharedPointer<Entity> &entity);
|
||
bool createTable(const QSharedPointer<Entity> &entity, bool createRelationTables=true);
|
||
qint8 count(const QSharedPointer<Entity> &entity, bool ignoreID = true);
|
||
qint8 count(const QString &tableName);
|
||
QSharedPointer<Database> getDb() const;
|
src/querybuilder.cpp | ||
---|---|---|
QueryBuilder::~QueryBuilder() {
|
||
}
|
||
|
||
bool QueryBuilder::createTable(const QSharedPointer<Entity> &entity) const {
|
||
bool QueryBuilder::createTable(const QSharedPointer<Entity> &entity, bool createRelationTables) const {
|
||
bool rc = false;
|
||
if (entity.data()) {
|
||
auto tableDefinition = this->generateTableDefinition(entity);
|
||
... | ... | |
if (!rc) {
|
||
QSqlQuery q = this->database.data()->getQuery(this->createTable(tableName,
|
||
tableDefinition));
|
||
|
||
|
||
if (this->database.data()->transaction(q)) {
|
||
if(createRelationTables) {
|
||
auto relTables = this->generateRelationTables(entity);
|
||
auto i = relTables.constBegin();
|
||
while(i != relTables.constEnd()) {
|
||
this->createTable(i.key(),i.value());
|
||
++i;
|
||
}
|
||
}
|
||
this->schema.data()->getTableSchema(tableName);
|
||
rc = true;
|
||
if (rc) {
|
||
... | ... | |
const QSharedPointer<Entity> &entity, qint64 offset, QString pk) const {
|
||
QSqlQuery q = this->database.data()->getQuery(this->selectBase(QStringList(
|
||
entity.data()->getTablename())) + this->joinSuperClasses(
|
||
entity) + " WHERE " + pk + "= :id" + this->limit(1, offset));
|
||
entity) + " WHERE " + this->schema.data()->quoteColumnName(pk) + "= :id" + this->limit(1, offset));
|
||
q.bindValue(":id", id);
|
||
return q;
|
||
}
|
src/querybuilder.h | ||
---|---|---|
public:
|
||
QueryBuilder(QSharedPointer<Schema> schema, QSharedPointer<Database> database);
|
||
virtual ~QueryBuilder();
|
||
virtual bool createTable(const QSharedPointer<Entity> &entity) const;
|
||
virtual bool createTable(const QSharedPointer<Entity> &entity, bool createRelationTables=true) const;
|
||
virtual bool createIndices(const QSharedPointer<Entity> &entity) const;
|
||
virtual QString createTable(const QString &tableName,
|
||
const QHash<QString, QString> &tableDefinition) const;
|
Auch abrufbar als: Unified diff
quoting