merge ok [slip ci]

This commit is contained in:
Hamed Masafi 2019-06-19 11:25:46 +04:30
commit dfb5df6af9
6 changed files with 28 additions and 13 deletions

View File

@ -210,8 +210,12 @@ inline Row<T> create() {
}
template<class T>
inline Row<T> create(QObject *parent) {
return QSharedPointer<T>(new T(parent));
inline T *get(T *row) {
return row;
}
template<class T>
inline T *get(const QSharedPointer<T> row) {
return row.data();
}
#else
@ -228,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

View File

@ -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;
}

View File

@ -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
{

View File

@ -84,20 +84,18 @@ void TableSetBase::clearChilds()
void TableSetBase::add(Table *t)
{
if(!data->tables.contains(t)){
if(!data->tables.contains(get(t))){
data.detach();
data->tables.insert(t);
data->childRows.append(t);
// data->childs.append(t);
data->tables.insert(get(t));
data->childRows.append(get(t));
}
}
void TableSetBase::remove(Table *t)
{
data.detach();
data->tables.remove(t);
data->childRows.removeOne(t);
// data->childs.removeOne(t);
data->tables.remove(get(t));
data->childRows.removeOne(get(t));
}
QString TableSetBase::childClassName() const
@ -112,6 +110,7 @@ Database *TableSetBase::database() const
void TableSetBase::setDatabase(Database *database)
{
data.detach();
data->database = database;
}

View File

@ -34,6 +34,7 @@ public:
TableSetBaseData(Database *parent) :
database(parent), table(nullptr)
{ }
TableSetBaseData(Table *parent) :
database(nullptr), table(parent)
{ }

View File

@ -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>();