diff --git a/src/query.h b/src/query.h index 31456bf..ce9ec0b 100644 --- a/src/query.h +++ b/src/query.h @@ -27,8 +27,7 @@ #include #include #include -#include -#include +#include #include "query_p.h" #include "database.h" @@ -66,7 +65,6 @@ public: return this; } - // Query *orderBy(QString fieldName, QString type); Query *skip(int n); Query *take(int n); @@ -109,8 +107,7 @@ Q_OUTOFLINE_TEMPLATE Query::Query(Database *database, TableSetBase *tableSet, d->database = database; d->tableSet = tableSet; d->className = T::staticMetaObject.className(); - d->tableName - = // TableModel::findByClassName(T::staticMetaObject.className())->name(); + d->tableName = d->database->model() .tableByClassName(T::staticMetaObject.className()) ->name(); @@ -130,9 +127,6 @@ Q_OUTOFLINE_TEMPLATE QList Query::toList(int count) Q_D(Query); QList returnList; d->select = "*"; - QElapsedTimer t; - t.start(); - d->sql = d->database->sqlGenertor()->selectCommand( SqlGeneratorBase::SelectAll, "", @@ -179,7 +173,6 @@ Q_OUTOFLINE_TEMPLATE QList Query::toList(int count) for (int j = 0; j < levels.count(); ++j) { LevelData &dt = levels[j]; - qDebug() <<"[check]"<name() << dt.table->name(); QHashIterator it(masters); while (it.hasNext()) { @@ -192,7 +185,7 @@ Q_OUTOFLINE_TEMPLATE QList Query::toList(int count) } } } - qDebug() << data.table->name() <<"added"; + levels.append(data); }; for (int i = 0; i < d->relations.count(); ++i) { @@ -214,12 +207,11 @@ Q_OUTOFLINE_TEMPLATE QList Query::toList(int count) checked.reserve(levels.count()); for (int i = 0; i < levels.count(); ++i) checked.append(false); - qDebug() << "Elapsed time:" << QString("%1ms").arg(t.elapsed() / 1000.); + while (q.next()) { checked.fill(false); int p = levels.count(); - qDebug() << "p is"< Query::toList(int count) table = qobject_cast(childMetaObject->newInstance()); } - qDebug() << "table created" << table; QStringList childFields = data.table->fieldsNames(); foreach (QString field, childFields) @@ -272,12 +263,9 @@ Q_OUTOFLINE_TEMPLATE QList Query::toList(int count) table->setProperty(data.masterFields[i].toLocal8Bit().data(), QVariant::fromValue(levels[master].lastRow)); - table->setParentTableSet(levels[master].lastRow->childTableSet(data.table->className())); - TableSetBase *ts = levels[master].lastRow->childTableSet(data.table->className()); - qDebug() << table << "added to" - << levels[master].lastRow - << ts->childClassName() - << data.masterFields[i]; + table->setParentTableSet( + levels[master].lastRow->childTableSet( + data.table->className())); } table->setStatus(Table::FeatchedFromDB); @@ -287,15 +275,12 @@ Q_OUTOFLINE_TEMPLATE QList Query::toList(int count) //set last created row data.lastRow = table; - - lastP = p; } //while } // while if (m_autoDelete) deleteLater(); - qDebug() << "Elapsed time:" << QString("%1ms").arg(t.elapsed() / 1000.); return returnList; } @@ -413,9 +398,11 @@ Q_OUTOFLINE_TEMPLATE Query *Query::join(const QString &className) { Q_D(Query); - RelationModel *rel = d->database->model().relationByClassNames(d->className, className); + RelationModel *rel = d->database->model() + .relationByClassNames(d->className, className); if (!rel) - rel = d->database->model().relationByClassNames(className, d->className); + rel = d->database->model() + .relationByClassNames(className, d->className); if (!rel) { qInfo("No relation between %s and %s", diff --git a/test/basic/maintest.cpp b/test/basic/maintest.cpp index 65536cf..1fc16a1 100644 --- a/test/basic/maintest.cpp +++ b/test/basic/maintest.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "consts.h" @@ -15,6 +16,11 @@ #include "comment.h" #define PRINT(x) qDebug() << #x "=" << x; +#define TIC() QElapsedTimer timer; timer.start() +#define TOC() qDebug() << QString("Elapsed time: %1ms for %2") \ + .arg(timer.elapsed() / 1000.) \ + .arg(__func__) + MainTest::MainTest(QObject *parent) : QObject(parent) { } @@ -130,11 +136,9 @@ void MainTest::selectPosts() void MainTest::selectFirst() { - auto q = db.posts()->query(); + auto posts = db.posts()->query() + ->first(); - auto posts = q->first(); - - qDebug() << q->sqlCommand(); QTEST_ASSERT(posts != Q_NULLPTR); } @@ -176,14 +180,14 @@ void MainTest::testDate() void MainTest::join() { + TIC(); auto q = db.comments()->query() ->join() ->join(); -// Comment *comment = q->first(); auto comments = q->toList(); -// Comment *comment = q->toList().first(); - qDebug() << q->sqlCommand(); + + TOC(); QTEST_ASSERT(comments.length()); QTEST_ASSERT(comments[0]->author()); QTEST_ASSERT(comments[0]->author()->username() == "admin"); diff --git a/test/basic/maintest.h b/test/basic/maintest.h index 74bd47a..49b1956 100644 --- a/test/basic/maintest.h +++ b/test/basic/maintest.h @@ -34,7 +34,6 @@ private slots: void selectPostIds(); void testDate(); void selectWithInvalidRelation(); - void select10NewstPosts(); void modifyPost(); void emptyDatabase(); };