working to remove extra model check [skip ci]
This commit is contained in:
parent
ae1ee06f85
commit
27a8908e26
|
|
@ -57,7 +57,7 @@ DatabaseModel::DatabaseModel(const QJsonObject &json) :
|
|||
}
|
||||
}
|
||||
|
||||
TableModel *DatabaseModel::tableByName(QString tableName) const
|
||||
TableModel *DatabaseModel::tableByName(const QString &tableName) const
|
||||
{
|
||||
for(int i = 0; i < size(); i++){
|
||||
TableModel *s = at(i);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public:
|
|||
DatabaseModel(const QJsonObject &json);
|
||||
~DatabaseModel() = default;
|
||||
|
||||
TableModel *tableByName(QString tableName) const;
|
||||
TableModel *tableByName(const QString &tableName) const;
|
||||
TableModel *tableByClassName(QString className) const;
|
||||
|
||||
RelationModel *relationByClassNames(const QString &masterClassName,
|
||||
|
|
|
|||
|
|
@ -440,7 +440,8 @@ QString SqlGeneratorBase::join(const QStringList &list, QStringList *order)
|
|||
QString SqlGeneratorBase::insertRecord(Table *t, QString tableName)
|
||||
{
|
||||
QString sql = QString();
|
||||
QString key = t->isPrimaryKeyAutoIncrement() ? t->primaryKey() : QString();
|
||||
auto model = _database->model().tableByName(tableName);
|
||||
QString key = model->isPrimaryKeyAutoIncrement() ? model->primaryKey() : QString();
|
||||
|
||||
QStringList values;
|
||||
|
||||
|
|
|
|||
|
|
@ -61,3 +61,6 @@ SOURCES += \
|
|||
$$PWD/phrases/phrasedatalist.cpp \
|
||||
$$PWD/phrases/phraselist.cpp \
|
||||
$$PWD/phrases/datephrase.cpp
|
||||
|
||||
|
||||
include($$PWD/../3rdparty/serializer/src/src.pri)
|
||||
|
|
|
|||
|
|
@ -8,5 +8,4 @@ CONFIG += staticlib
|
|||
DEFINES += QT_DEPRECATED_WARNINGS NUT_COMPILE_STATIC
|
||||
|
||||
include($$PWD/src.pri)
|
||||
include($$PWD/../3rdparty/serializer/src/src.pri)
|
||||
include($$PWD/../ci-test-init.pri)
|
||||
|
|
|
|||
|
|
@ -164,8 +164,9 @@ int Table::save(Database *db)
|
|||
|
||||
QSqlQuery q = db->exec(db->sqlGenertor()->saveRecord(this, db->tableName(metaObject()->className())));
|
||||
|
||||
if(status() == Added && isPrimaryKeyAutoIncrement())
|
||||
setProperty(primaryKey().toLatin1().data(), q.lastInsertId());
|
||||
auto model = db->model().tableByName(metaObject()->className());
|
||||
if(status() == Added && model->isPrimaryKeyAutoIncrement())
|
||||
setProperty(model->primaryKey().toLatin1().data(), q.lastInsertId());
|
||||
|
||||
foreach(TableSetBase *ts, d->childTableSets)
|
||||
ts->save(db);
|
||||
|
|
|
|||
|
|
@ -55,8 +55,13 @@ public:
|
|||
|
||||
int save(Database *db);
|
||||
|
||||
Q_DECL_DEPRECATED
|
||||
QString primaryKey() const;
|
||||
|
||||
Q_DECL_DEPRECATED
|
||||
bool isPrimaryKeyAutoIncrement() const;
|
||||
|
||||
Q_DECL_DEPRECATED
|
||||
QVariant primaryValue() const;
|
||||
Status status() const;
|
||||
void setStatus(const Status &status);
|
||||
|
|
|
|||
|
|
@ -411,6 +411,14 @@ QString TableModel::primaryKey() const
|
|||
return QString();
|
||||
}
|
||||
|
||||
bool TableModel::isPrimaryKeyAutoIncrement() const
|
||||
{
|
||||
FieldModel *pk = field(primaryKey());
|
||||
if (!pk)
|
||||
return false;
|
||||
return pk->isAutoIncrement;
|
||||
}
|
||||
|
||||
FieldModel::FieldModel(const QJsonObject &json)
|
||||
{
|
||||
name = json.value(__NAME).toString();
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ public:
|
|||
QString toString() const;
|
||||
|
||||
QString primaryKey() const;
|
||||
bool isPrimaryKeyAutoIncrement() const;
|
||||
|
||||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
#win32 {
|
||||
# CONFIG(debug,debug|release): LIBDIR = $$absolute_path($$OUT_PWD/../../src/debug)
|
||||
# CONFIG(release,debug|release): LIBDIR = $$absolute_path($$OUT_PWD/../../src/release)
|
||||
#} else {
|
||||
# LIBDIR = $$absolute_path($$OUT_PWD/../../src)
|
||||
#}
|
||||
win32 {
|
||||
CONFIG(debug,debug|release): LIBDIR = $$absolute_path($$OUT_PWD/../../src/debug)
|
||||
CONFIG(release,debug|release): LIBDIR = $$absolute_path($$OUT_PWD/../../src/release)
|
||||
} else {
|
||||
LIBDIR = $$absolute_path($$OUT_PWD/../../src)
|
||||
}
|
||||
|
||||
#LIBS += -L$$LIBDIR -lnut
|
||||
include(../../src/src.pri)
|
||||
INCLUDEPATH += $$PWD/../../src $$PWD/../common
|
||||
include(../../src/src.pri)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
QT += testlib sql
|
||||
|
||||
TARGET = tst_nut
|
||||
TARGET = tst_basic
|
||||
TEMPLATE = app
|
||||
|
||||
CONFIG += warn_on c++11
|
||||
|
|
|
|||
Loading…
Reference in New Issue