Workinsg
This commit is contained in:
parent
5e5471fdeb
commit
dc99f3ed01
|
|
@ -1 +1 @@
|
|||
Subproject commit e2d8a726ef1396c47bf35347ea8b55ca47c6af3b
|
||||
Subproject commit b3c550c5bb7c570b1b10492fcedf287c1915af39
|
||||
|
|
@ -209,6 +209,15 @@ inline Row<T> create() {
|
|||
return QSharedPointer<T>(new T);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T *get(T *row) {
|
||||
return row;
|
||||
}
|
||||
template<class T>
|
||||
inline T *get(const QSharedPointer<T> row) {
|
||||
return row.data();
|
||||
}
|
||||
|
||||
#else
|
||||
template <typename T>
|
||||
using RowList = QList<T*>;
|
||||
|
|
@ -223,6 +232,17 @@ template<class T>
|
|||
inline Row<T> create() {
|
||||
return new T;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T *get(const Row<T> row) {
|
||||
return row;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T *get(const QSharedPointer<T> row) {
|
||||
return row.data();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
|
|||
d->sql = d->database->sqlGenertor()->selectCommand(
|
||||
d->tableName, d->fieldPhrase, d->wherePhrase, d->orderPhrase,
|
||||
d->relations, d->skip, d->take);
|
||||
|
||||
qDebug()<<d->sql;
|
||||
QSqlQuery q = d->database->exec(d->sql);
|
||||
if (q.lastError().isValid()) {
|
||||
qDebug() << q.lastError().text();
|
||||
|
|
@ -346,7 +346,7 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
|
|||
if (m_autoDelete)
|
||||
deleteLater();
|
||||
#endif
|
||||
|
||||
qDebug() << "len="<<returnList.count();
|
||||
return returnList;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@
|
|||
#include "tablesetbase_p.h"
|
||||
#include "table.h"
|
||||
#include "bulkinserter.h"
|
||||
//#include "database.h"
|
||||
#include "databasemodel.h"
|
||||
#include "tablesetbasedata.h"
|
||||
|
||||
|
|
@ -41,6 +40,7 @@ class Query;
|
|||
|
||||
class BulkInserter;
|
||||
class Database;
|
||||
|
||||
template<class T>
|
||||
class NUT_EXPORT TableSet : public TableSetBase
|
||||
{
|
||||
|
|
@ -114,7 +114,7 @@ Q_OUTOFLINE_TEMPLATE void TableSet<T>::append(Row<T> t)
|
|||
{
|
||||
data->tables.insert(t.data());
|
||||
data->childRows.append(t.data());
|
||||
|
||||
data->rowList.append(t);
|
||||
// if (_database)
|
||||
// t->setModel(_database->model().tableByClassName(t->metaObject()->className()));
|
||||
|
||||
|
|
@ -133,6 +133,7 @@ Q_OUTOFLINE_TEMPLATE void TableSet<T>::append(RowList<T> t)
|
|||
template<class T>
|
||||
Q_OUTOFLINE_TEMPLATE void TableSet<T>::remove(T *t)
|
||||
{
|
||||
data->rowList.removeOne(t);
|
||||
data->tables.remove(t);
|
||||
t->setStatus(Table::Deleted);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ int TableSetBase::save(Database *db, bool cleanUp)
|
|||
if (data->table)
|
||||
masterModel = db->model().tableByClassName(data->table->metaObject()->className());
|
||||
|
||||
foreach (Row<Table> t, data->childRows) {
|
||||
foreach (Table *t, data->childRows) {
|
||||
if(data->table)
|
||||
t->setParentTable(data->table,
|
||||
masterModel,
|
||||
|
|
@ -82,18 +82,20 @@ void TableSetBase::clearChilds()
|
|||
data->childRows.clear();
|
||||
}
|
||||
|
||||
void TableSetBase::add(Row<Table> t)
|
||||
void TableSetBase::add(Table *t)
|
||||
{
|
||||
if(!data->tables.contains(t.data())){
|
||||
data->tables.insert(t.data());
|
||||
data->childRows.append(t);
|
||||
if(!data->tables.contains(get(t))){
|
||||
data.detach();
|
||||
data->tables.insert(get(t));
|
||||
data->childRows.append(get(t));
|
||||
}
|
||||
}
|
||||
|
||||
void TableSetBase::remove(Row<Table> t)
|
||||
void TableSetBase::remove(Table *t)
|
||||
{
|
||||
data->tables.remove(t.data());
|
||||
data->childRows.removeOne(t);
|
||||
data.detach();
|
||||
data->tables.remove(get(t));
|
||||
data->childRows.removeOne(get(t));
|
||||
}
|
||||
|
||||
QString TableSetBase::childClassName() const
|
||||
|
|
@ -108,6 +110,7 @@ Database *TableSetBase::database() const
|
|||
|
||||
void TableSetBase::setDatabase(Database *database)
|
||||
{
|
||||
data.detach();
|
||||
data->database = database;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,8 +58,8 @@ protected:
|
|||
QExplicitlySharedDataPointer<TableSetBaseData> data;
|
||||
|
||||
private:
|
||||
void add(Row<Table> t);
|
||||
void remove(Row<Table> t);
|
||||
void add(Nut::Table *t);
|
||||
void remove(Nut::Table *t);
|
||||
|
||||
friend class Table;
|
||||
friend class QueryBase;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ public:
|
|||
TableSetBaseData(Database *parent) :
|
||||
database(parent), table(nullptr)
|
||||
{ }
|
||||
|
||||
TableSetBaseData(Table *parent) :
|
||||
database(nullptr), table(parent)
|
||||
{ }
|
||||
|
|
@ -43,6 +44,7 @@ public:
|
|||
Database *database;
|
||||
Table *table;
|
||||
QString childClassName;
|
||||
RowList<Table> rowList;
|
||||
};
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ void BasicTest::createPost()
|
|||
comment->setMessage("comment #" + QString::number(i));
|
||||
comment->setSaveDate(QDateTime::currentDateTime());
|
||||
comment->setAuthorId(user->id());
|
||||
newPost->comments()->append(comment);
|
||||
db.comments()->append(comment);
|
||||
}
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
auto score = Nut::create<Score>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue