Revision 6dc7d533
Von Christian Ehringfeld vor fast 10 Jahren hinzugefügt
src/querybuilder.cpp | ||
---|---|---|
auto map = QHash<QString, QString>();
|
||
auto o = entity.data()->metaObject();
|
||
for (int var = 0; var < o->propertyCount(); ++var) {
|
||
o->property(var);
|
||
auto m = o->property(var);
|
||
if (m.isReadable() && !entity.data()->getTransientAttributes().contains(m.name())) {
|
||
/**
|
||
@TODO
|
||
*/
|
||
if (m.isEnumType()) {
|
||
map.insert(m.name(), this->schema.data()->getTypeMap().data()->value(this->schema.data()->TYPE_INTEGER));
|
||
} else if (entity.data()->getRelations().contains(m.name())) {
|
||
map.insert(QString(m.name()) + "_id", this->schema.data()->TYPE_INTEGER);
|
||
} else if (entity.data()->getBLOBColumns().contains(m.name())) {
|
||
map.insert(m.name(), this->schema.data()->getTypeMap().data()->value(this->schema.data()->TYPE_BINARY));
|
||
} else {
|
||
map.insert(m.name(), this->transformAbstractTypeToRealDbType(this->transformTypeToAbstractDbType(m.typeName())));
|
||
}
|
||
}
|
||
}
|
||
QString pkType = map.value(entity.data()->getPrimaryKey());
|
||
if (pkType == this->schema.data()->TYPE_BIGINT) {
|
||
map.insert(entity.data()->getPrimaryKey(), this->schema.data()->TYPE_BIGPK);
|
||
} else {
|
||
map.insert(entity.data()->getPrimaryKey(), this->schema.data()->TYPE_PK);
|
||
}
|
||
return map;
|
||
}
|
||
|
||
QString QueryBuilder::transformTypeToAbstractDbType(QString typeName) {
|
||
QString QueryBuilder::transformTypeToAbstractDbType(QString typeName) const {
|
||
QHash<QString, QString> *m = this->schema.data()->getAbstractTypeMap().data();
|
||
if (m->contains(typeName)) {
|
||
return m->value(typeName);
|
||
... | ... | |
return this->schema.data()->TYPE_TEXT;
|
||
}
|
||
|
||
QString QueryBuilder::transformAbstractTypeToRealDbType(QString typeName) const {
|
||
return this->schema.data()->getTypeMap().data()->value(typeName);
|
||
}
|
||
|
||
QHash<QString, QVariant> QueryBuilder::getEntityAttributes(const QSharedPointer<Entity> &entity) {
|
||
Entity *e = entity.data();
|
||
auto map = QHash<QString, QVariant>();
|
src/querybuilder.h | ||
---|---|---|
|
||
QHash<QString, QString> generateTableDefinition(const QSharedPointer<Entity> &entity) const;
|
||
|
||
QString transformTypeToAbstractDbType(QString typeName);
|
||
QString transformTypeToAbstractDbType(QString typeName) const;
|
||
QString transformAbstractTypeToRealDbType(QString typeName) const;
|
||
|
||
protected:
|
||
void insertRelationId(const Entity *e, QHash<QString, QVariant> &map, QString relName);
|
src/schema/sqliteschema.cpp | ||
---|---|---|
|
||
QSharedPointer<QHash<QString, QString>> SqliteSchema::getTypeMap() {
|
||
if (this->typeMap.data()->empty()) {
|
||
this->typeMap.data()->insert(TYPE_SMALLINT, "tinyint");
|
||
this->typeMap.data()->insert(TYPE_PK, "integer PRIMARY KEY AUTOINCREMENT NOT NULL");
|
||
this->typeMap.data()->insert(TYPE_BIGPK, "integer PRIMARY KEY AUTOINCREMENT NOT NULL");
|
||
this->typeMap.data()->insert(TYPE_BOOLEAN, "boolean");
|
||
this->typeMap.data()->insert(TYPE_SMALLINT, "smallint");
|
||
this->typeMap.data()->insert(TYPE_INTEGER, "int");
|
||
this->typeMap.data()->insert(TYPE_INTEGER, "integer");
|
||
this->typeMap.data()->insert(TYPE_BIGINT, "bigint");
|
||
this->typeMap.data()->insert(TYPE_FLOAT, "float");
|
||
this->typeMap.data()->insert(TYPE_DOUBLE, "double");
|
||
this->typeMap.data()->insert(TYPE_FLOAT, "real");
|
||
this->typeMap.data()->insert(TYPE_DECIMAL, "decimal");
|
||
this->typeMap.data()->insert(TYPE_DECIMAL, "decimal(10,0)");
|
||
this->typeMap.data()->insert(TYPE_TEXT, "text");
|
||
this->typeMap.data()->insert(TYPE_STRING, "varchar");
|
||
this->typeMap.data()->insert(TYPE_STRING, "text");
|
||
this->typeMap.data()->insert(TYPE_CHAR, "char");
|
||
this->typeMap.data()->insert(TYPE_BINARY, "blob");
|
||
this->typeMap.data()->insert(TYPE_DATETIME, "datetime");
|
||
this->typeMap.data()->insert(TYPE_DATE, "date");
|
||
this->typeMap.data()->insert(TYPE_TIME, "time");
|
||
this->typeMap.data()->insert(TYPE_TIMESTAMP, "timestamp");
|
||
this->typeMap.data()->insert(TYPE_MONEY, "decimal(19,4)");
|
||
}
|
||
return this->typeMap;
|
||
}
|
Auch abrufbar als: Unified diff
...