Revision 24425325
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
src/entity.cpp | ||
---|---|---|
return QString(this->metaObject()->className());
|
||
}
|
||
|
||
QList<Relation> Entity::getRelations() {
|
||
return QList<Relation>();
|
||
QHash<QString, Relation> Entity::getRelations() {
|
||
return QHash<QString, Relation>();
|
||
}
|
||
|
||
QStringList Entity::getTransientAttributes() {
|
||
... | ... | |
QString Entity::getPrimaryKey() {
|
||
return "id";
|
||
}
|
||
qint32 Entity::getId() const
|
||
{
|
||
qint32 Entity::getId() const {
|
||
return id;
|
||
}
|
||
|
||
void Entity::setId(const qint32 &value)
|
||
{
|
||
void Entity::setId(const qint32 &value) {
|
||
id = value;
|
||
}
|
src/entity.h | ||
---|---|---|
virtual QString toString();
|
||
virtual ~Entity();
|
||
virtual QString getTablename();
|
||
virtual QList<Relation> getRelations();
|
||
virtual QHash<QString, Relation> getRelations();
|
||
/**
|
||
* You should return the names of properties which should not persisted e.g. Properties which are only exposed to qml
|
||
* @brief getTransientAttributes
|
src/querybuilder.cpp | ||
---|---|---|
this->database = database;
|
||
}
|
||
|
||
QueryBuilder::~QueryBuilder() {
|
||
|
||
}
|
||
|
||
bool QueryBuilder::createTable(const QSharedPointer<Entity> &entity) const {
|
||
return this->createTable(entity.data()->getTablename(), this->generateTableDefinition(entity));
|
||
}
|
||
... | ... | |
return s;
|
||
}
|
||
|
||
bool QueryBuilder::renameTable(QString tableName, QString newName) const {
|
||
|
||
}
|
||
|
||
bool QueryBuilder::dropTable(QString tableName) const {
|
||
|
||
}
|
||
|
||
bool QueryBuilder::truncateTable(QString tableName) const {
|
||
|
||
}
|
||
|
||
bool QueryBuilder::addColumn(QString tableName, QString columnName, QString columnType) const {
|
||
|
||
}
|
||
|
||
QString QueryBuilder::dropColumn(QString tableName, QString columName) const {
|
||
|
||
}
|
||
|
||
QString QueryBuilder::renameColumn(QString tableName, QString oldName, QString newName) const {
|
||
|
||
}
|
||
|
||
QString QueryBuilder::alterColumn(QString tableName, QString columnName, QString newType) const {
|
||
|
||
}
|
||
|
||
QString QueryBuilder::addPrimaryKey(QString name, QString tableName, QStringList columns) const {
|
||
|
||
}
|
||
|
||
QString QueryBuilder::dropPrimaryKey(QString name, QString tableName) const {
|
||
|
||
}
|
||
|
||
QString QueryBuilder::addForeignKey(QString name, QString tableName, QStringList columns, QString refTableName,
|
||
QStringList refColumns, QString deleteConstraint, QString updateConstraint) {
|
||
|
||
}
|
||
|
||
QString QueryBuilder::dropForeignKey(QString name, QString tableName) const {
|
||
|
||
}
|
||
|
||
QString QueryBuilder::createIndex(QString name, QString tableName, QStringList columns, bool unique) const {
|
||
|
||
}
|
||
|
||
QString QueryBuilder::dropIndex(QString name, QString tableName) const {
|
||
|
||
}
|
||
|
||
QSharedPointer<Database> QueryBuilder::getDatabase() const {
|
||
return database;
|
||
}
|
||
... | ... | |
for (int var = 0; var < o->propertyCount(); ++var) {
|
||
auto m = o->property(var);
|
||
if (m.isReadable() && !entity.data()->getTransientAttributes().contains(m.name())) {
|
||
m.typeName();
|
||
/**
|
||
@TODO
|
||
*/
|
||
... | ... | |
return map;
|
||
}
|
||
|
||
QString QueryBuilder::transformTypeToAbstractDbType(QString typeName) {
|
||
QHash<QString, QString> *m = this->schema.data()->getAbstractTypeMap().data();
|
||
if (m->contains(typeName)) {
|
||
return m->value(typeName);
|
||
}
|
||
QHash<QString, QString>::iterator i;
|
||
for (i = m->begin(); i != m->end(); ++i) {
|
||
if (i.key().contains(typeName)) {
|
||
return i.value();
|
||
}
|
||
}
|
||
return this->schema.data()->TYPE_TEXT;
|
||
}
|
||
|
||
QHash<QString, QVariant> QueryBuilder::getEntityAttributes(const QSharedPointer<Entity> &entity) {
|
||
Entity *e = entity.data();
|
||
auto map = QHash<QString, QVariant>();
|
src/querybuilder.h | ||
---|---|---|
virtual bool truncateTable(QString tableName) const;
|
||
virtual bool addColumn(QString tableName, QString columnName, QString columnType) const;
|
||
virtual QString dropColumn(QString tableName, QString columName)const;
|
||
virtual QString renameColumn(QString tableName, QString oldName, QString newName);
|
||
virtual QString renameColumn(QString tableName, QString oldName, QString newName) const;
|
||
virtual QString alterColumn(QString tableName, QString columnName, QString newType)const;
|
||
virtual QString addPrimaryKey(QString name, QString tableName, QStringList columns)const;
|
||
virtual QString dropPrimaryKey(QString name, QString tableName) const;
|
||
... | ... | |
|
||
QHash<QString, QString> generateTableDefinition(const QSharedPointer<Entity> &entity) const;
|
||
|
||
QString transformTypeToAbstractDbType(QString typeName);
|
||
|
||
protected:
|
||
void insertRelationId(const Entity *e, QHash<QString, QVariant> &map, QString relName);
|
src/schema.cpp | ||
---|---|---|
|
||
Schema::Schema(QSharedPointer<Database> database) {
|
||
this->database = database;
|
||
this->typeMap = QSharedPointer<QHash<QString, QString>>(new QHash<QString, QString>());
|
||
this->abstractTypeMap = QSharedPointer<QHash<QString, QString>>(new QHash<QString, QString>());
|
||
this->queryBuilder = QSharedPointer<QueryBuilder>();
|
||
this->initAbstractDatabaseTypes();
|
||
}
|
||
|
||
Schema::~Schema() {
|
||
|
||
}
|
||
|
||
QHash<QString, QString> Schema::getAbstractDatabaseTypes() {
|
||
auto typeMap = QHash<QString, QString>();
|
||
typeMap.insert("bool", TYPE_SMALLINT);
|
||
typeMap.insert("short", TYPE_SMALLINT);
|
||
typeMap.insert("int", TYPE_INTEGER);
|
||
typeMap.insert("long", TYPE_INTEGER);
|
||
typeMap.insert("long long", TYPE_INTEGER);
|
||
typeMap.insert("float", TYPE_FLOAT);
|
||
typeMap.insert("double", TYPE_FLOAT);
|
||
typeMap.insert("long double", TYPE_FLOAT);
|
||
typeMap.insert("qint", TYPE_INTEGER);
|
||
typeMap.insert("quint", TYPE_INTEGER);
|
||
typeMap.insert("quuid", TYPE_INTEGER);
|
||
typeMap.insert("qfloat", TYPE_FLOAT);
|
||
typeMap.insert("unsigned short", TYPE_SMALLINT);
|
||
typeMap.insert("unsigned int", TYPE_INTEGER);
|
||
typeMap.insert("unsigned long", TYPE_INTEGER);
|
||
typeMap.insert("unsigned long long", TYPE_INTEGER);
|
||
typeMap.insert("char",TYPE_CHAR);
|
||
typeMap.insert("std::string", TYPE_TEXT);
|
||
typeMap.insert("std::wstring", TYPE_TEXT);
|
||
typeMap.insert("QString", TYPE_TEXT);
|
||
typeMap.insert("QVariant", TYPE_TEXT);
|
||
typeMap.insert("QUuid", TYPE_TEXT);
|
||
typeMap.insert("QDate", TYPE_DATE);
|
||
typeMap.insert("QTime", TYPE_TIME);
|
||
typeMap.insert("QDateTime", TYPE_DATETIME);
|
||
typeMap.insert("QByteArray", TYPE_BINARY);
|
||
typeMap.insert("QBitArray", TYPE_BINARY);
|
||
return typeMap;
|
||
void Schema::initAbstractDatabaseTypes() {
|
||
this->abstractTypeMap.create();
|
||
this->abstractTypeMap.data()->insert("bool", TYPE_SMALLINT);
|
||
this->abstractTypeMap.data()->insert("short", TYPE_SMALLINT);
|
||
this->abstractTypeMap.data()->insert("int", TYPE_INTEGER);
|
||
this->abstractTypeMap.data()->insert("long", TYPE_INTEGER);
|
||
this->abstractTypeMap.data()->insert("long long", TYPE_INTEGER);
|
||
this->abstractTypeMap.data()->insert("qlonglong", TYPE_INTEGER);
|
||
this->abstractTypeMap.data()->insert("float", TYPE_FLOAT);
|
||
this->abstractTypeMap.data()->insert("double", TYPE_FLOAT);
|
||
this->abstractTypeMap.data()->insert("long double", TYPE_FLOAT);
|
||
this->abstractTypeMap.data()->insert("qint", TYPE_INTEGER);
|
||
this->abstractTypeMap.data()->insert("quint", TYPE_INTEGER);
|
||
this->abstractTypeMap.data()->insert("quuid", TYPE_INTEGER);
|
||
this->abstractTypeMap.data()->insert("qfloat", TYPE_FLOAT);
|
||
this->abstractTypeMap.data()->insert("unsigned short", TYPE_SMALLINT);
|
||
this->abstractTypeMap.data()->insert("unsigned int", TYPE_INTEGER);
|
||
this->abstractTypeMap.data()->insert("unsigned long", TYPE_INTEGER);
|
||
this->abstractTypeMap.data()->insert("unsigned long long", TYPE_INTEGER);
|
||
this->abstractTypeMap.data()->insert("char", TYPE_CHAR);
|
||
this->abstractTypeMap.data()->insert("std::string", TYPE_TEXT);
|
||
this->abstractTypeMap.data()->insert("std::wstring", TYPE_TEXT);
|
||
this->abstractTypeMap.data()->insert("QString", TYPE_TEXT);
|
||
this->abstractTypeMap.data()->insert("QVariant", TYPE_TEXT);
|
||
this->abstractTypeMap.data()->insert("QUuid", TYPE_TEXT);
|
||
this->abstractTypeMap.data()->insert("QDate", TYPE_DATE);
|
||
this->abstractTypeMap.data()->insert("QTime", TYPE_TIME);
|
||
this->abstractTypeMap.data()->insert("QDateTime", TYPE_DATETIME);
|
||
this->abstractTypeMap.data()->insert("QByteArray", TYPE_BINARY);
|
||
this->abstractTypeMap.data()->insert("QBitArray", TYPE_BINARY);
|
||
}
|
||
|
||
QString Schema::quoteSimpleTableName(QString name) {
|
||
... | ... | |
return queryBuilder;
|
||
}
|
||
|
||
QSharedPointer<QHash<QString, QString> > Schema::getAbstractTypeMap() const {
|
||
return abstractTypeMap;
|
||
}
|
||
|
||
void Schema::setAbstractTypeMap(const QSharedPointer<QHash<QString, QString> > &value) {
|
||
abstractTypeMap = value;
|
||
}
|
||
|
||
|
||
QHash<QString, QSharedPointer<TableSchema> > Schema::getTables() const {
|
||
return this->tables;
|
||
}
|
src/schema.h | ||
---|---|---|
const QString TYPE_BOOLEAN = "boolean";
|
||
const QString TYPE_MONEY = "money";
|
||
|
||
// /**
|
||
// * @var array list of ALL table names in the database
|
||
// */
|
||
// private $_tableNames = [];
|
||
// /**
|
||
// * @var array list of loaded table metadata (table name => TableSchema)
|
||
// */
|
||
// private $_tables = [];
|
||
// /**
|
||
// * @var QueryBuilder the query builder for this database
|
||
// */
|
||
// private $_builder;
|
||
|
||
|
||
virtual QHash<QString, QString> *getTypeMap() = 0;
|
||
QHash<QString, QString> getAbstractDatabaseTypes();
|
||
virtual QSharedPointer<QHash<QString, QString> >getTypeMap() = 0;
|
||
virtual QString quoteSimpleTableName(QString name);
|
||
virtual QString quoteTableName(QString name);
|
||
virtual QString quoteColumnName(QString name);
|
||
... | ... | |
virtual void refresh();
|
||
virtual QString getRawTable(QString name);
|
||
virtual bool containsTable(QString tblname);
|
||
virtual void initQueryBuilder();
|
||
|
||
QHash<QString, QSharedPointer<TableSchema> > getTables() const;
|
||
void setTables(const QHash<QString, QSharedPointer<TableSchema> > &value);
|
||
... | ... | |
|
||
QSharedPointer<QueryBuilder> getQueryBuilder() const;
|
||
|
||
QSharedPointer<QHash<QString, QString> > getAbstractTypeMap() const;
|
||
void setAbstractTypeMap(const QSharedPointer<QHash<QString, QString> > &value);
|
||
|
||
protected:
|
||
virtual QStringList findTableNames(QString schema = "") = 0;
|
||
virtual QHash<QString, QStringList> findUniqueIndexes(const QSharedPointer<TableSchema> &table) = 0;
|
||
virtual void findConstraints(const QSharedPointer<TableSchema> &ts) = 0;
|
||
virtual bool findColumns(const QSharedPointer<TableSchema> &ts) = 0;
|
||
virtual QSharedPointer<TableSchema> loadTableSchema(QString name) = 0;
|
||
void initAbstractDatabaseTypes();
|
||
QSharedPointer<Database> database;
|
||
QSharedPointer<QHash<QString, QString>> typeMap;
|
||
QSharedPointer<QHash<QString, QString>> abstractTypeMap;
|
||
QHash<QString, QSharedPointer<TableSchema>> tables;
|
||
QSharedPointer<QueryBuilder> queryBuilder;
|
||
|
src/schema/sqliteschema.cpp | ||
---|---|---|
|
||
}
|
||
|
||
QHash<QString, QString> *SqliteSchema::getTypeMap() {
|
||
QSharedPointer<QHash<QString, QString>> SqliteSchema::getTypeMap() {
|
||
if (this->typeMap.data()->empty()) {
|
||
this->typeMap.data()->insert(TYPE_SMALLINT, "tinyint");
|
||
this->typeMap.data()->insert(TYPE_BOOLEAN, "boolean");
|
||
... | ... | |
this->typeMap.data()->insert(TYPE_TIME, "time");
|
||
this->typeMap.data()->insert(TYPE_TIMESTAMP, "timestamp");
|
||
}
|
||
return this->typeMap.data();
|
||
return this->typeMap;
|
||
}
|
||
|
||
QStringList SqliteSchema::findTableNames(QString schema) {
|
src/schema/sqliteschema.h | ||
---|---|---|
public:
|
||
SqliteSchema(QSharedPointer<Database> database);
|
||
~SqliteSchema();
|
||
QHash<QString, QString> *getTypeMap();
|
||
protected:
|
||
QSharedPointer<QHash<QString, QString> > getTypeMap();
|
||
protected:
|
||
|
||
virtual QStringList findTableNames(QString schema = "");
|
||
virtual QHash<QString, QStringList> findUniqueIndexes(const QSharedPointer<TableSchema> &table);
|
Auch abrufbar als: Unified diff
wip