This commit is contained in:
Hamed Masafi 2019-02-08 12:41:53 +03:30
parent f5c10e8759
commit 6f31c4e6b9
11 changed files with 38 additions and 39 deletions

View File

@ -795,6 +795,9 @@ void SqlGeneratorBase::removeTableNames(QString &command)
QString SqlGeneratorBase::escapeValue(const QVariant &v) const
{
if (v.type() == QVariant::String && v.toString().isEmpty())
return "''";
QString serialized = _serializer->toString(v);
if (serialized.isEmpty()) {
qWarning("No field escape rule for: %s", v.typeName());
@ -843,7 +846,6 @@ QString SqlGeneratorBase::escapeValue(const QVariant &v) const
qFatal("Invalud field value");
default:
qDebug() << v.type();
qWarning("No field escape rule for: %s", v.typeName());
Q_UNREACHABLE();
return QString();

View File

@ -126,7 +126,6 @@ TableModel *TableModel::findByTypeId(int typeId)
TableModel *TableModel::findByClassName(QString className)
{
foreach (TableModel *model, _allModels){
qDebug() << model->className();
if(model->className() == className)
return model;
}

View File

@ -3,7 +3,6 @@
#include <QtCore/qglobal.h>
#include <QtCore/QDateTime>
#include <QtCore/QUuid>
#include "table.h"
#ifdef NUT_NAMESPACE
@ -16,14 +15,14 @@ class Comment : public Table
{
Q_OBJECT
NUT_PRIMARY_KEY(id)
NUT_DECLARE_FIELD(QUuid, id, id, setId)
NUT_PRIMARY_AUTO_INCREMENT(id)
NUT_DECLARE_FIELD(int, id, id, setId)
NUT_DECLARE_FIELD(QString, message, message, setMessage)
NUT_DECLARE_FIELD(QDateTime, saveDate, saveDate, setSaveDate)
NUT_DECLARE_FIELD(qreal, point, point, setPoint)
NUT_FOREGION_KEY(Post, int, post, post, setPost)
NUT_FOREGION_KEY(User, QUuid, author, author, setAuthor)
NUT_FOREGION_KEY(User, int, author, author, setAuthor)
public:
Q_INVOKABLE explicit Comment(QObject *parentTableSet = nullptr);

View File

@ -1,6 +1,7 @@
#ifndef CONSTS_H
#define CONSTS_H
#define REGISTER(x) qDebug() << #x << "type id:" << qRegisterMetaType<x*>()
#define PRINT(x) qDebug() << #x "=" << x;
#define TIC() QElapsedTimer timer; timer.start()
#define TOC() qDebug() << QString("Elapsed time: %1ms for %2") \
@ -46,9 +47,5 @@
<< "\n\tTest:" << metaObject()->className() \
<< "\n****************************\n";
#define TIC() QElapsedTimer timer; timer.start()
#define TOC() qDebug() << QString("Elapsed time: %1ms for %2") \
.arg(timer.elapsed() / 1000.) \
.arg(__func__)
#endif // CONSTS_H

View File

@ -11,5 +11,5 @@ Post::Post(QObject *parent) : Table(parent),
}
//NUT_IMPLEMENT_CHILD_TABLE(Post, Comment, comments)
//NUT_IMPLEMENT_CHILD_TABLE(Post, Score, scores)
NUT_IMPLEMENT_CHILD_TABLE(Post, Comment, comments)
NUT_IMPLEMENT_CHILD_TABLE(Post, Score, scores)

View File

@ -17,8 +17,8 @@ class User : public Nut::Table
{
Q_OBJECT
NUT_PRIMARY_KEY(id)
NUT_DECLARE_FIELD(QUuid, id, id, setId)
NUT_PRIMARY_AUTO_INCREMENT(id)
NUT_DECLARE_FIELD(int, id, id, setId)
NUT_NOT_NULL(username)
NUT_LEN(username, 50)

View File

@ -1,11 +1,11 @@
TEMPLATE = subdirs
SUBDIRS += \
tst_basic \
tst_basic \
tst_benckmark \
tst_commands \
tst_datatypes \
# tst_commands \
tst_datatypes
#tst_join \
tst_phrases \
tst_quuid
# tst_phrases
# tst_quuid

View File

@ -16,14 +16,6 @@
#include "comment.h"
#include "score.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__)
#define REGISTER(x) qDebug() << #x << "type id:" << qRegisterMetaType<x*>()
MainTest::MainTest(QObject *parent) : QObject(parent)
{
}
@ -65,7 +57,6 @@ void MainTest::dataScheema()
void MainTest::createUser()
{
user = new User;
user->setId(QUuid::createUuid());
user->setUsername("admin");
user->setPassword("123456");
db.users()->append(user);
@ -84,7 +75,6 @@ void MainTest::createPost()
for(int i = 0 ; i < 3; i++){
Comment *comment = new Comment;
comment->setId(QUuid::createUuid());
comment->setMessage("comment #" + QString::number(i));
comment->setSaveDate(QDateTime::currentDateTime());
comment->setAuthorId(user->id());
@ -117,7 +107,6 @@ void MainTest::createPost2()
for(int i = 0 ; i < 3; i++){
Comment *comment = new Comment;
comment->setId(QUuid::createUuid());
comment->setMessage("comment #" + QString::number(i + 2));
comment->setSaveDate(QDateTime::currentDateTime());
comment->setAuthor(user);
@ -290,6 +279,9 @@ void MainTest::cleanupTestCase()
//release models before exiting
qDeleteAll(TableModel::allModels());
if (QFile::remove("nut_tst_basic"))
qDebug() << "database removed";
PRINT_FORM(db);
}

View File

@ -10,8 +10,10 @@
#include "tablemodel.h"
#include "databasemodel.h"
#include "user.h"
#include "post.h"
#include "comment.h"
#include "score.h"
MainTest::MainTest(QObject *parent) : QObject(parent)
{
@ -20,9 +22,11 @@ MainTest::MainTest(QObject *parent) : QObject(parent)
void MainTest::initTestCase()
{
qDebug() << "User type id:" << qRegisterMetaType<Post*>();
qDebug() << "Comment type id:" << qRegisterMetaType<Comment*>();
qDebug() << "DB type id:" << qRegisterMetaType<WeblogDatabase*>();
REGISTER(User);
REGISTER(Post);
REGISTER(Score);
REGISTER(Comment);
REGISTER(WeblogDatabase);
db.setDriver(DRIVER);
db.setHostName(HOST);

View File

@ -1,21 +1,27 @@
QT += qml quick testlib sql
QT -= gui
TARGET = tst_nut
TARGET = tst_benchmark
TEMPLATE = app
CONFIG += warn_on qmltestcase c++11
INCLUDEPATH += $$PWD/../../src $$PWD/../common
include(../../nut.pri)
TEMPLATE = app
IMPORTPATH += $$OUT_PWD/../src/imports
SOURCES += \
maintest.cpp \
../common/comment.cpp \
../common/post.cpp \
../common/weblogdatabase.cpp
../common/user.cpp \
../common/weblogdatabase.cpp \
../common/score.cpp
HEADERS += \
maintest.h \
../common/consts.h \
../common/comment.h \
../common/post.h \
../common/weblogdatabase.h
../common/user.h \
../common/weblogdatabase.h \
../common/score.h

View File

@ -1,7 +1,7 @@
QT += qml quick testlib sql
QT -= gui
TARGET = tst_nut
TARGET = tst_datatypes
TEMPLATE = app
CONFIG += warn_on qmltestcase c++11