Revision b7446f4c
Von Christian Ehringfeld vor mehr als 10 Jahren hinzugefügt
| src/querybuilder.cpp | ||
|---|---|---|
|
QueryBuilder::~QueryBuilder() {
|
||
|
}
|
||
|
|
||
|
bool QueryBuilder::createTable(const QSharedPointer<Entity> &entity, bool createRelationTables) const {
|
||
|
bool QueryBuilder::createTable(const QSharedPointer<Entity> &entity,
|
||
|
bool createRelationTables) const {
|
||
|
bool rc = false;
|
||
|
if (entity.data()) {
|
||
|
auto tableDefinition = this->generateTableDefinition(entity);
|
||
| ... | ... | |
|
QSqlQuery q = this->database.data()->getQuery(this->createTable(tableName,
|
||
|
tableDefinition));
|
||
|
if (this->database.data()->transaction(q)) {
|
||
|
if(createRelationTables) {
|
||
|
if (createRelationTables) {
|
||
|
auto relTables = this->generateRelationTables(entity);
|
||
|
auto i = relTables.constBegin();
|
||
|
while(i != relTables.constEnd()) {
|
||
|
auto query = this->database.data()->getQuery(this->createTable(i.key(),i.value()));
|
||
|
while (i != relTables.constEnd()) {
|
||
|
auto query = this->database.data()->getQuery(this->createTable(i.key(),
|
||
|
i.value()));
|
||
|
this->database.data()->exec(query);
|
||
|
++i;
|
||
|
}
|
||
| ... | ... | |
|
this->schema.data()->TYPE_BIGINT);
|
||
|
auto meta = props.value(r.getPropertyName());
|
||
|
QSharedPointer<Entity> ptr = QSharedPointer<Entity>
|
||
|
(EntityInstanceFactory::createInstance(EntityInstanceFactory::extractEntityType(QMetaType::typeName(meta.userType()))));
|
||
|
(EntityInstanceFactory::createInstance(EntityInstanceFactory::extractEntityType(
|
||
|
QMetaType::typeName(meta.userType()))));
|
||
|
h.insert(this->generateManyToManyColumnName(ptr),
|
||
|
this->schema.data()->TYPE_BIGINT);
|
||
|
relations.insert(this->generateManyToManyTableName(entity, ptr), h);
|
||
| ... | ... | |
|
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 " + this->schema.data()->quoteColumnName(pk) + "= :id" + this->limit(1, offset));
|
||
|
entity) + " WHERE " + this->schema.data()->quoteColumnName(
|
||
|
pk) + "= :id" + this->limit(1, offset));
|
||
|
q.bindValue(":id", id);
|
||
|
return q;
|
||
|
}
|
||
| ... | ... | |
|
QSqlQuery QueryBuilder::insert(const QString &tableName,
|
||
|
QHash<QString, QVariant> &attributes, const QString &primaryKey) const {
|
||
|
//if(attributes.size() == 1) {
|
||
|
// attributes.insert(primaryKey,QVariant("null"));
|
||
|
// } else {
|
||
|
attributes.remove(primaryKey);
|
||
|
// attributes.insert(primaryKey,QVariant("null"));
|
||
|
// } else {
|
||
|
attributes.remove(primaryKey);
|
||
|
// }
|
||
|
QSqlQuery q = this->database.data()->getQuery();
|
||
|
QString p1 = "INSERT INTO " + this->schema.data()->quoteTableName(
|
||
| ... | ... | |
|
|
||
|
QString QueryBuilder::generateManyToManyColumnName(const QSharedPointer<Entity>
|
||
|
&entity) const {
|
||
|
return this->generateColumnNameID(entity.data()->getTablename());
|
||
|
if (entity) {
|
||
|
return this->generateColumnNameID(entity.data()->getTablename());
|
||
|
}
|
||
|
qDebug() << "Entity is empty!";
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
QSqlQuery QueryBuilder::getQuery() const {
|
||
Auch abrufbar als: Unified diff
fix in em, samples updated