fix: crash when table destroyed and new query going to execute [skip ci]
This commit is contained in:
parent
c9250482b2
commit
ac2fa1a4ae
6
nut.pri
6
nut.pri
|
|
@ -39,7 +39,8 @@ HEADERS += \
|
|||
$$PWD/src/phrases/phrasedata.h \
|
||||
$$PWD/src/phrases/assignmentphrase.h \
|
||||
$$PWD/src/phrases/numericphrase.h \
|
||||
$$PWD/src/phrases/datephrase.h
|
||||
$$PWD/src/phrases/datephrase.h \
|
||||
$$PWD/src/bulkinserter.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/src/generators/sqlgeneratorbase.cpp \
|
||||
|
|
@ -70,4 +71,5 @@ SOURCES += \
|
|||
$$PWD/src/phrases/phrasedata.cpp \
|
||||
$$PWD/src/phrases/assignmentphrase.cpp \
|
||||
$$PWD/src/phrases/numericphrase.cpp \
|
||||
$$PWD/src/phrases/datephrase.cpp
|
||||
$$PWD/src/phrases/datephrase.cpp \
|
||||
$$PWD/src/bulkinserter.cpp
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
#include "bulkinserter.h"
|
||||
#include "phrases/phraselist.h"
|
||||
|
||||
Nut::BulkInserter::BulkInserter(QString &className)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Nut::BulkInserter::setFields(const Nut::PhraseList &ph)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Nut::BulkInserter::insert(std::initializer_list<QVariant> vars)
|
||||
{
|
||||
std::initializer_list<QVariant>::iterator it; // same as: const int* it
|
||||
for (it = vars.begin(); it != vars.end(); ++it)
|
||||
qDebug() << *it;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef BULKINSERTER_H
|
||||
#define BULKINSERTER_H
|
||||
|
||||
#include <initializer_list>
|
||||
#include <QDebug>
|
||||
#include "defines.h"
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
class PhraseList;
|
||||
class BulkInserter
|
||||
{
|
||||
public:
|
||||
BulkInserter(QString &className);
|
||||
void setFields(const PhraseList &ph);
|
||||
|
||||
void insert(std::initializer_list<QVariant> vars);
|
||||
template<typename... Args>
|
||||
void insert(Args... args) {
|
||||
insert({args...});
|
||||
}
|
||||
};
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
||||
#endif // BULKINSERTER_H
|
||||
|
|
@ -135,6 +135,8 @@ bool DatabasePrivate::updateDatabase()
|
|||
|
||||
if (last == current) {
|
||||
qDebug("Databse is up-to-date");
|
||||
//TODO: crash without this and I don't know why!
|
||||
changeLogs->clearChilds();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -348,7 +350,7 @@ bool DatabasePrivate::putModelToDatabase()
|
|||
changeLog->setData(QJsonDocument(current.toJson()).toJson(QJsonDocument::Compact));
|
||||
changeLog->setVersion(current.version());
|
||||
changeLogs->append(changeLog);
|
||||
q->saveChanges();
|
||||
q->saveChanges(true);
|
||||
changeLog->deleteLater();
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -44,9 +44,18 @@ Table::Table(QObject *parent) : QObject(parent),
|
|||
d_ptr(new TablePrivate(this))
|
||||
{
|
||||
Q_D(Table);
|
||||
d->status = NewCreated;
|
||||
d->model = TableModel::findByClassName(metaObject()->className());
|
||||
}
|
||||
|
||||
Table::~Table()
|
||||
{
|
||||
Q_D(Table);
|
||||
|
||||
if (d->parentTableSet)
|
||||
d->parentTableSet->remove(this);
|
||||
}
|
||||
|
||||
void Table::add(TableSetBase *t)
|
||||
{
|
||||
Q_D(Table);
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ class NUT_EXPORT Table : public QObject
|
|||
|
||||
public:
|
||||
explicit Table(QObject *parentTableSet = nullptr);
|
||||
virtual ~Table();
|
||||
|
||||
enum Status{
|
||||
NewCreated,
|
||||
|
|
|
|||
|
|
@ -29,12 +29,14 @@
|
|||
|
||||
#include "tablesetbase_p.h"
|
||||
#include "table.h"
|
||||
#include "bulkinserter.h"
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
template<class T>
|
||||
class Query;
|
||||
|
||||
class BulkInserter;
|
||||
template<class T>
|
||||
class NUT_EXPORT TableSet : public TableSetBase
|
||||
{
|
||||
|
|
@ -54,6 +56,7 @@ public:
|
|||
const T &operator[](int i) const;
|
||||
|
||||
Query<T> *query(bool autoDelete = true);
|
||||
BulkInserter *bulkInserter();
|
||||
};
|
||||
|
||||
template<class T>
|
||||
|
|
@ -76,6 +79,14 @@ Q_OUTOFLINE_TEMPLATE Query<T> *TableSet<T>::query(bool autoDelete)
|
|||
return q;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
Q_OUTOFLINE_TEMPLATE BulkInserter *TableSet<T>::bulkInserter()
|
||||
{
|
||||
BulkInserter *bi = new BulkInserter(_childClassName);
|
||||
return bi;
|
||||
|
||||
}
|
||||
|
||||
template<class T>
|
||||
Q_OUTOFLINE_TEMPLATE int TableSet<T>::length() const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -75,6 +75,12 @@ void TableSetBase::add(Table *t)
|
|||
}
|
||||
}
|
||||
|
||||
void TableSetBase::remove(Table *t)
|
||||
{
|
||||
_tables.remove(t);
|
||||
_tablesList.removeOne(t);
|
||||
}
|
||||
|
||||
QString TableSetBase::childClassName() const
|
||||
{
|
||||
return _childClassName;
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ protected:
|
|||
|
||||
private:
|
||||
void add(Table* t);
|
||||
void remove(Table* t);
|
||||
|
||||
friend class Table;
|
||||
friend class QueryBase;
|
||||
|
|
|
|||
Loading…
Reference in New Issue