new macro
This commit is contained in:
parent
b77fde9358
commit
c5e9d5ec2b
|
|
@ -188,16 +188,20 @@ bool DatabasePrivate::getCurrectScheema()
|
||||||
changeLogs = new TableSet<ChangeLogTable>(q);
|
changeLogs = new TableSet<ChangeLogTable>(q);
|
||||||
|
|
||||||
for (int i = 0; i < q->metaObject()->classInfoCount(); i++) {
|
for (int i = 0; i < q->metaObject()->classInfoCount(); i++) {
|
||||||
QMetaClassInfo ci = q->metaObject()->classInfo(i);
|
QString type;
|
||||||
QString ciName = QString(ci.name())
|
QString name;
|
||||||
.replace(__nut_NAME_PERFIX, "")
|
QString value;
|
||||||
.replace("\"", "");
|
|
||||||
|
|
||||||
if (ciName.startsWith(__nut_TABLE))
|
if (!checkClassInfo(q->metaObject()->classInfo(i),
|
||||||
tables.insert(ciName.split(" ").at(1), ci.value());
|
type, name, value)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (ciName == __nut_DB_VERSION) {
|
if (type == __nut_TABLE)
|
||||||
currentModel.setVersion(QString(ci.value()));
|
tables.insert(name, type);
|
||||||
|
|
||||||
|
if (type == __nut_DB_VERSION)
|
||||||
|
currentModel.setVersion(name);
|
||||||
|
|
||||||
/* TODO: remove
|
/* TODO: remove
|
||||||
QStringList version
|
QStringList version
|
||||||
|
|
@ -213,7 +217,6 @@ bool DatabasePrivate::getCurrectScheema()
|
||||||
if (!ok)
|
if (!ok)
|
||||||
qFatal("NUT_DB_VERSION macro accept version in format 'x' or "
|
qFatal("NUT_DB_VERSION macro accept version in format 'x' or "
|
||||||
"'x[.y]' only, and x,y must be integer values\n");*/
|
"'x[.y]' only, and x,y must be integer values\n");*/
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < q->metaObject()->propertyCount(); i++) {
|
for (int i = 1; i < q->metaObject()->propertyCount(); i++) {
|
||||||
|
|
@ -235,6 +238,23 @@ bool DatabasePrivate::getCurrectScheema()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DatabasePrivate::checkClassInfo(const QMetaClassInfo &classInfo, QString &type, QString &name, QString &value)
|
||||||
|
{
|
||||||
|
if (!QString(classInfo.name()).startsWith(__nut_NAME_PERFIX)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
QStringList parts = QString(classInfo.value()).split("\n");
|
||||||
|
if (parts.count() != 3)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
type = parts[0];
|
||||||
|
name = parts[1];
|
||||||
|
value = parts[2];
|
||||||
|
qDebug() << Q_FUNC_INFO << parts;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DatabaseModel DatabasePrivate::getLastScheema()
|
DatabaseModel DatabasePrivate::getLastScheema()
|
||||||
{
|
{
|
||||||
ChangeLogTable *u = changeLogs->query()
|
ChangeLogTable *u = changeLogs->query()
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,8 @@ public:
|
||||||
DatabaseModel getLastScheema();
|
DatabaseModel getLastScheema();
|
||||||
bool getCurrectScheema();
|
bool getCurrectScheema();
|
||||||
|
|
||||||
|
bool checkClassInfo(const QMetaClassInfo &classInfo,
|
||||||
|
QString &type, QString &name, QString &value);
|
||||||
QSqlDatabase db;
|
QSqlDatabase db;
|
||||||
|
|
||||||
QString hostName;
|
QString hostName;
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ TableModel *DatabaseModel::tableByClassName(QString className) const
|
||||||
|
|
||||||
// qWarning("Table with class name '%s' not found in model",
|
// qWarning("Table with class name '%s' not found in model",
|
||||||
// qUtf8Printable(className));
|
// qUtf8Printable(className));
|
||||||
// Q_UNREACHABLE();
|
Q_UNREACHABLE();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,9 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NUT_INFO(type, name, value) \
|
#define NUT_INFO(type, name, value) \
|
||||||
Q_CLASSINFO(__nut_NAME_PERFIX #type #name #value, #type "\n" #name "\n" #value)
|
Q_CLASSINFO(__nut_NAME_PERFIX type #name #value, type "\n" #name "\n" #value)
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
//TODO: remove minor version
|
|
||||||
#define NUT_DB_VERSION(version) \
|
#define NUT_DB_VERSION(version) \
|
||||||
NUT_INFO(__nut_DB_VERSION, version, 0)
|
NUT_INFO(__nut_DB_VERSION, version, 0)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,10 @@ QString Table::primaryKey() const
|
||||||
|
|
||||||
bool Table::isPrimaryKeyAutoIncrement() const
|
bool Table::isPrimaryKeyAutoIncrement() const
|
||||||
{
|
{
|
||||||
return TableModel::findByClassName(metaObject()->className())->field(primaryKey())->isAutoIncrement;
|
auto m = TableModel::findByClassName(metaObject()->className());
|
||||||
|
auto pk = m->primaryKey();
|
||||||
|
auto f = m->field(pk);
|
||||||
|
return f->isAutoIncrement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,8 @@ bool TableModel::operator !=(const TableModel &t) const
|
||||||
return !(*this == t);
|
return !(*this == t);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TableModel::checkClassInfo(const QMetaClassInfo &classInfo, QString type, QString name, QString value)
|
bool TableModel::checkClassInfo(const QMetaClassInfo &classInfo,
|
||||||
|
QString &type, QString &name, QString &value)
|
||||||
{
|
{
|
||||||
if (!QString(classInfo.name()).startsWith(__nut_NAME_PERFIX)) {
|
if (!QString(classInfo.name()).startsWith(__nut_NAME_PERFIX)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -189,6 +190,7 @@ TableModel::TableModel(int typeId, QString tableName)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug() << "**********" << type << __nut_FIELD << (type == __nut_FIELD);
|
||||||
if(type == __nut_FIELD){
|
if(type == __nut_FIELD){
|
||||||
FieldModel *f = new FieldModel;
|
FieldModel *f = new FieldModel;
|
||||||
f->name = name;
|
f->name = name;
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,8 @@ private:
|
||||||
QList<FieldModel*> _fields;
|
QList<FieldModel*> _fields;
|
||||||
QList<RelationModel*> _foregionKeys;
|
QList<RelationModel*> _foregionKeys;
|
||||||
static QSet<TableModel*>_allModels;
|
static QSet<TableModel*>_allModels;
|
||||||
bool checkClassInfo(const QMetaClassInfo &classInfo, QString type, QString name, QString value);
|
bool checkClassInfo(const QMetaClassInfo &classInfo,
|
||||||
|
QString &type, QString &name, QString &value);
|
||||||
};
|
};
|
||||||
|
|
||||||
NUT_END_NAMESPACE
|
NUT_END_NAMESPACE
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue