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

View File

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

View File

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

View File

@ -1,6 +1,7 @@
#ifndef CONSTS_H #ifndef CONSTS_H
#define CONSTS_H #define CONSTS_H
#define REGISTER(x) qDebug() << #x << "type id:" << qRegisterMetaType<x*>()
#define PRINT(x) qDebug() << #x "=" << x; #define PRINT(x) qDebug() << #x "=" << x;
#define TIC() QElapsedTimer timer; timer.start() #define TIC() QElapsedTimer timer; timer.start()
#define TOC() qDebug() << QString("Elapsed time: %1ms for %2") \ #define TOC() qDebug() << QString("Elapsed time: %1ms for %2") \
@ -46,9 +47,5 @@
<< "\n\tTest:" << metaObject()->className() \ << "\n\tTest:" << metaObject()->className() \
<< "\n****************************\n"; << "\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 #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, Comment, comments)
//NUT_IMPLEMENT_CHILD_TABLE(Post, Score, scores) NUT_IMPLEMENT_CHILD_TABLE(Post, Score, scores)

View File

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

View File

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

View File

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

View File

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

View File

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