create model without extra property
This commit is contained in:
parent
e4f1c4c266
commit
cd1bf90608
|
|
@ -205,12 +205,20 @@ bool DatabasePrivate::getCurrectScheema()
|
||||||
|
|
||||||
if (!nutClassInfoString(q->metaObject()->classInfo(i),
|
if (!nutClassInfoString(q->metaObject()->classInfo(i),
|
||||||
type, name, value)) {
|
type, name, value)) {
|
||||||
|
qDebug() << "No valid table in" << q->metaObject()->classInfo(i).value();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (type == __nut_TABLE) {
|
||||||
if (type == __nut_TABLE)
|
//name: table class name
|
||||||
|
//value: table variable name (table name in db)
|
||||||
tables.insert(name, value);
|
tables.insert(name, value);
|
||||||
|
|
||||||
|
int typeId = QMetaType::type(name.toLocal8Bit() + "*");
|
||||||
|
qDebug() << type << name << value << typeId;
|
||||||
|
TableModel *sch = new TableModel(typeId, value);
|
||||||
|
currentModel.append(sch);
|
||||||
|
}
|
||||||
|
|
||||||
if (type == __nut_DB_VERSION)
|
if (type == __nut_DB_VERSION)
|
||||||
currentModel.setVersion(name);
|
currentModel.setVersion(name);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -229,13 +229,13 @@ DatabaseModel *DatabaseModel::modelByName(const QString &name)
|
||||||
|
|
||||||
void DatabaseModel::deleteAllModels()
|
void DatabaseModel::deleteAllModels()
|
||||||
{
|
{
|
||||||
QMapIterator<QString, DatabaseModel*> i(_models);
|
// QMapIterator<QString, DatabaseModel*> i(_models);
|
||||||
while (i.hasNext()) {
|
// while (i.hasNext()) {
|
||||||
i.next();
|
// i.next();
|
||||||
// cout << i.key() << ": " << i.value() << endl;
|
//// cout << i.key() << ": " << i.value() << endl;
|
||||||
delete i.value();
|
// delete i.value();
|
||||||
}
|
// }
|
||||||
// qDeleteAll(_models.values());
|
qDeleteAll(_models.values());
|
||||||
_models.clear();
|
_models.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,10 +126,11 @@ inline bool nutClassInfoInt(const QMetaClassInfo &classInfo,
|
||||||
NUT_INFO(__nut_TABLE, type, name) \
|
NUT_INFO(__nut_TABLE, type, name) \
|
||||||
Q_PROPERTY(NUT_WRAP_NAMESPACE(TableSet<type>) name READ name) \
|
Q_PROPERTY(NUT_WRAP_NAMESPACE(TableSet<type>) name READ name) \
|
||||||
NUT_WRAP_NAMESPACE(TableSet<type>) *m_##name; \
|
NUT_WRAP_NAMESPACE(TableSet<type>) *m_##name; \
|
||||||
public: \
|
public: \
|
||||||
static const type *_##name; \
|
static const type *_##name; \
|
||||||
NUT_WRAP_NAMESPACE(TableSet<type>) *name() const \
|
NUT_WRAP_NAMESPACE(TableSet<type>) *name() const \
|
||||||
{ return m_##name; }
|
{ return m_##name; } \
|
||||||
|
private:
|
||||||
|
|
||||||
//Table
|
//Table
|
||||||
#define NUT_DECLARE_FIELD(type, name, read, write) \
|
#define NUT_DECLARE_FIELD(type, name, read, write) \
|
||||||
|
|
|
||||||
|
|
@ -395,13 +395,13 @@ QString SqlGeneratorBase::join(const QStringList &list, QStringList *order)
|
||||||
QString SqlGeneratorBase::insertRecord(Table *t, QString tableName)
|
QString SqlGeneratorBase::insertRecord(Table *t, QString tableName)
|
||||||
{
|
{
|
||||||
QString sql = QString();
|
QString sql = QString();
|
||||||
QString key = t->primaryKey();
|
QString key = t->isPrimaryKeyAutoIncrement() ? t->primaryKey() : QString();
|
||||||
|
|
||||||
QStringList values;
|
QStringList values;
|
||||||
|
|
||||||
foreach (QString f, t->changedProperties())
|
foreach (QString f, t->changedProperties())
|
||||||
if (f != key)
|
if (f != key)
|
||||||
values.append("'" + t->property(f.toLatin1().data()).toString()
|
values.append(escapeValue(t->property(f.toLatin1().data())));
|
||||||
+ "'");
|
|
||||||
|
|
||||||
QString changedPropertiesText = QString();
|
QString changedPropertiesText = QString();
|
||||||
QSet<QString> props = t->changedProperties();
|
QSet<QString> props = t->changedProperties();
|
||||||
|
|
@ -785,7 +785,7 @@ QString SqlGeneratorBase::escapeValue(const QVariant &v) const
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QVariant::Uuid:
|
case QVariant::Uuid:
|
||||||
return v.toUuid().toString();
|
return "'" + v.toUuid().toString() + "'";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QVariant::Char:
|
case QVariant::Char:
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,9 @@ QString SqliteGenerator::fieldType(FieldModel *field)
|
||||||
else
|
else
|
||||||
dbType = "text";
|
dbType = "text";
|
||||||
break;
|
break;
|
||||||
|
case QVariant::Uuid:
|
||||||
|
dbType = "text";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
dbType = QString();
|
dbType = QString();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,8 +74,9 @@ void Table::propertyChanged(QString propName)
|
||||||
if (!myModel)
|
if (!myModel)
|
||||||
qFatal ("model for this class not found");
|
qFatal ("model for this class not found");
|
||||||
|
|
||||||
if (propName == primaryKey())
|
foreach (FieldModel *f, myModel->fields())
|
||||||
return;
|
if(f->isPrimaryKey && propName == f->name && f->isAutoIncrement)
|
||||||
|
return;
|
||||||
|
|
||||||
_changedProperties.insert(propName);
|
_changedProperties.insert(propName);
|
||||||
if (_status == FeatchedFromDB)
|
if (_status == FeatchedFromDB)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
Test::Test(QObject *parentTableSet)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef TEST_H
|
||||||
|
#define TEST_H
|
||||||
|
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
#include "table.h"
|
||||||
|
|
||||||
|
class Test : public Nut::Table
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
NUT_PRIMARY_KEY(id)
|
||||||
|
NUT_DECLARE_FIELD(QUuid, id, id, setId)
|
||||||
|
|
||||||
|
NUT_NOT_NULL(username)
|
||||||
|
NUT_LEN(username, 50)
|
||||||
|
NUT_DECLARE_FIELD(QString, username, username, setUsername)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE Test(QObject *parentTableSet = 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(Test*)
|
||||||
|
|
||||||
|
#endif // TEST_H
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
#include "testdatabase.h"
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
TestDatabase::TestDatabase(QObject *parent)
|
||||||
|
: Database(parent), m_tests(new Nut::TableSet<Test>(this))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef TESTDATABASE_H
|
||||||
|
#define TESTDATABASE_H
|
||||||
|
|
||||||
|
#include <Database>
|
||||||
|
|
||||||
|
class Test;
|
||||||
|
class TestDatabase : public Nut::Database
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
NUT_DB_VERSION(1)
|
||||||
|
|
||||||
|
NUT_DECLARE_TABLE(Test, tests)
|
||||||
|
public:
|
||||||
|
TestDatabase(QObject *parent = nullptr);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TESTDATABASE_H
|
||||||
Loading…
Reference in New Issue