uuid detect
This commit is contained in:
parent
8af466e480
commit
1713a237eb
|
|
@ -23,6 +23,7 @@
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QPointF>
|
#include <QPointF>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
#include <QUuid>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
#include "sqlgeneratorbase_p.h"
|
#include "sqlgeneratorbase_p.h"
|
||||||
|
|
@ -381,6 +382,17 @@ QString SqlGeneratorBase::selectCommand(SqlGeneratorBase::AgregateType t,
|
||||||
QList<WherePhrase> &wheres,
|
QList<WherePhrase> &wheres,
|
||||||
QList<WherePhrase> &orders,
|
QList<WherePhrase> &orders,
|
||||||
QStringList joins, int skip, int take)
|
QStringList joins, int skip, int take)
|
||||||
|
{
|
||||||
|
return selectCommand(t, agregateArg, wheres, orders, joins, skip, take);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString SqlGeneratorBase::selectCommand(SqlGeneratorBase::AgregateType t,
|
||||||
|
QString agregateArg,
|
||||||
|
QList<WherePhrase> &wheres,
|
||||||
|
QList<WherePhrase> &orders,
|
||||||
|
QStringList joins,
|
||||||
|
int skip, int take,
|
||||||
|
QStringList *order)
|
||||||
{
|
{
|
||||||
Q_UNUSED(take);
|
Q_UNUSED(take);
|
||||||
Q_UNUSED(skip);
|
Q_UNUSED(skip);
|
||||||
|
|
@ -389,12 +401,14 @@ QString SqlGeneratorBase::selectCommand(SqlGeneratorBase::AgregateType t,
|
||||||
QString select = agregateText(t, agregateArg);
|
QString select = agregateText(t, agregateArg);
|
||||||
QString from = join(joins, &joinedOrders);
|
QString from = join(joins, &joinedOrders);
|
||||||
QString where = createWhere(wheres);
|
QString where = createWhere(wheres);
|
||||||
QString order = joinedOrders.join(", ");
|
QString orderText = joinedOrders.join(", ");
|
||||||
|
if (order != Q_NULLPTR)
|
||||||
|
order = joinedOrders;
|
||||||
|
|
||||||
foreach (WherePhrase p, orders) {
|
foreach (WherePhrase p, orders) {
|
||||||
if (order != "")
|
if (orderText != "")
|
||||||
order.append(", ");
|
orderText.append(", ");
|
||||||
order.append(phraseOrder(p.data()));
|
orderText.append(phraseOrder(p.data()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString sql = "SELECT " + select + " FROM " + from;
|
QString sql = "SELECT " + select + " FROM " + from;
|
||||||
|
|
@ -402,8 +416,8 @@ QString SqlGeneratorBase::selectCommand(SqlGeneratorBase::AgregateType t,
|
||||||
if (where != "")
|
if (where != "")
|
||||||
sql.append(" WHERE " + where);
|
sql.append(" WHERE " + where);
|
||||||
|
|
||||||
if (order != "")
|
if (orderText != "")
|
||||||
sql.append(" ORDER BY " + order);
|
sql.append(" ORDER BY " + orderText);
|
||||||
|
|
||||||
for (int i = 0; i < _database->model().count(); i++)
|
for (int i = 0; i < _database->model().count(); i++)
|
||||||
sql = sql.replace(_database->model().at(i)->className() + ".",
|
sql = sql.replace(_database->model().at(i)->className() + ".",
|
||||||
|
|
@ -479,14 +493,6 @@ QString SqlGeneratorBase::updateCommand(WherePhrase &phrase,
|
||||||
return sql;
|
return sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SqlGeneratorBase::joinTables(QStringList tables)
|
|
||||||
{
|
|
||||||
Q_UNUSED(tables);
|
|
||||||
//TODO: implement me
|
|
||||||
// _database->model().relationByClassNames()
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
QString SqlGeneratorBase::escapeValue(const QVariant &v) const
|
QString SqlGeneratorBase::escapeValue(const QVariant &v) const
|
||||||
{
|
{
|
||||||
switch (v.type()) {
|
switch (v.type()) {
|
||||||
|
|
@ -502,18 +508,22 @@ QString SqlGeneratorBase::escapeValue(const QVariant &v) const
|
||||||
return v.toString();
|
return v.toString();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case QVariant::Uuid:
|
||||||
|
return v.toUuid().toString();
|
||||||
|
break;
|
||||||
|
|
||||||
case QVariant::Char:
|
case QVariant::Char:
|
||||||
case QVariant::String:
|
case QVariant::String:
|
||||||
return "'" + v.toString() + "'";
|
return "'" + v.toString() + "'";
|
||||||
|
|
||||||
case QVariant::DateTime:
|
case QVariant::DateTime:
|
||||||
return "'" + v.toDateTime().toString() + "'";
|
return "'" + v.toDateTime().toString(Qt::ISODate) + "'";
|
||||||
|
|
||||||
case QVariant::Date:
|
case QVariant::Date:
|
||||||
return "'" + v.toDate().toString() + "'";
|
return "'" + v.toDate().toString(Qt::ISODate) + "'";
|
||||||
|
|
||||||
case QVariant::Time:
|
case QVariant::Time:
|
||||||
return "'" + v.toTime().toString() + "'";
|
return "'" + v.toTime().toString(Qt::ISODate) + "'";
|
||||||
|
|
||||||
case QVariant::StringList:
|
case QVariant::StringList:
|
||||||
case QVariant::List:
|
case QVariant::List:
|
||||||
|
|
@ -534,6 +544,7 @@ QString SqlGeneratorBase::escapeValue(const QVariant &v) const
|
||||||
return "<FAIL>";
|
return "<FAIL>";
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Q_UNREACHABLE();
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,11 +71,10 @@ public:
|
||||||
virtual QString join(const QStringList &list, QStringList *order = Q_NULLPTR);
|
virtual QString join(const QStringList &list, QStringList *order = Q_NULLPTR);
|
||||||
|
|
||||||
virtual QString saveRecord(Table *t, QString tableName);
|
virtual QString saveRecord(Table *t, QString tableName);
|
||||||
|
|
||||||
virtual QString insertRecord(Table *t, QString tableName);
|
virtual QString insertRecord(Table *t, QString tableName);
|
||||||
virtual QString updateRecord(Table *t, QString tableName);
|
virtual QString updateRecord(Table *t, QString tableName);
|
||||||
virtual QString deleteRecord(Table *t, QString tableName);
|
virtual QString deleteRecord(Table *t, QString tableName);
|
||||||
|
|
||||||
|
|
||||||
virtual QString deleteRecords(QString tableName, QString where);
|
virtual QString deleteRecords(QString tableName, QString where);
|
||||||
|
|
||||||
virtual QString selectCommand(AgregateType t,
|
virtual QString selectCommand(AgregateType t,
|
||||||
|
|
@ -84,13 +83,18 @@ public:
|
||||||
QList<WherePhrase> &orders,
|
QList<WherePhrase> &orders,
|
||||||
QStringList joins,
|
QStringList joins,
|
||||||
int skip = -1, int take = -1);
|
int skip = -1, int take = -1);
|
||||||
|
virtual QString selectCommand(AgregateType t,
|
||||||
|
QString agregateArg,
|
||||||
|
QList<WherePhrase> &wheres,
|
||||||
|
QList<WherePhrase> &orders,
|
||||||
|
QStringList joins,
|
||||||
|
int skip = -1, int take = -1,
|
||||||
|
QStringList *order = Q_NULLPTR);
|
||||||
|
|
||||||
virtual QString deleteCommand(QList<WherePhrase> &wheres, QString tableName);
|
virtual QString deleteCommand(QList<WherePhrase> &wheres, QString tableName);
|
||||||
|
|
||||||
virtual QString updateCommand(WherePhrase &phrase, QList<WherePhrase> &wheres, QString tableName);
|
virtual QString updateCommand(WherePhrase &phrase, QList<WherePhrase> &wheres, QString tableName);
|
||||||
|
|
||||||
virtual QString joinTables(QStringList tables);
|
|
||||||
|
|
||||||
virtual QString escapeValue(const QVariant &v) const;
|
virtual QString escapeValue(const QVariant &v) const;
|
||||||
virtual QVariant readValue(const QVariant::Type &type, const QVariant &dbValue);
|
virtual QVariant readValue(const QVariant::Type &type, const QVariant &dbValue);
|
||||||
virtual QString phrase(const PhraseData *d) const;
|
virtual QString phrase(const PhraseData *d) const;
|
||||||
|
|
|
||||||
|
|
@ -131,12 +131,16 @@ Q_OUTOFLINE_TEMPLATE QList<T *> Query<T>::toList(int count)
|
||||||
// QSqlQuery q =
|
// QSqlQuery q =
|
||||||
// d->database->exec(d->database->sqlGenertor()->selectCommand(d->wheres,
|
// d->database->exec(d->database->sqlGenertor()->selectCommand(d->wheres,
|
||||||
// d->orders, d->tableName, d->joinClassName));
|
// d->orders, d->tableName, d->joinClassName));
|
||||||
|
QStringList orders;
|
||||||
d->sql = d->database->sqlGenertor()->selectCommand(
|
d->sql = d->database->sqlGenertor()->selectCommand(
|
||||||
SqlGeneratorBase::SelectAll, "", d->wheres, d->orderPhrases,
|
SqlGeneratorBase::SelectAll, "", d->wheres, d->orderPhrases,
|
||||||
d->joins, d->skip, d->take);
|
d->joins, d->skip, d->take, &orders);
|
||||||
QSqlQuery q = d->database->exec(d->sql);
|
QSqlQuery q = d->database->exec(d->sql);
|
||||||
|
|
||||||
// QString pk = TableModel::findByName(d->tableName)->primaryKey();
|
while (q.next()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
QString pk = d->database->model().tableByName(d->tableName)->primaryKey();
|
QString pk = d->database->model().tableByName(d->tableName)->primaryKey();
|
||||||
QVariant lastPkValue = QVariant();
|
QVariant lastPkValue = QVariant();
|
||||||
int childTypeId = 0;
|
int childTypeId = 0;
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,16 @@ void MainTest::dataScheema()
|
||||||
|
|
||||||
// qDebug() << model.toJson();
|
// qDebug() << model.toJson();
|
||||||
// qDebug() << db.model().toJson();
|
// qDebug() << db.model().toJson();
|
||||||
// QTEST_ASSERT(model == db.model());
|
// QTEST_ASSERT(model == db.model());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainTest::createUser()
|
||||||
|
{
|
||||||
|
user = new User;
|
||||||
|
user->setUsername("admin");
|
||||||
|
user->setPassword("123456");
|
||||||
|
db.users()->append(user);
|
||||||
|
db.saveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::createPost()
|
void MainTest::createPost()
|
||||||
|
|
@ -84,6 +93,7 @@ void MainTest::createPost2()
|
||||||
Comment *comment = new Comment;
|
Comment *comment = new Comment;
|
||||||
comment->setMessage("comment #" + QString::number(i));
|
comment->setMessage("comment #" + QString::number(i));
|
||||||
comment->setSaveDate(QDateTime::currentDateTime());
|
comment->setSaveDate(QDateTime::currentDateTime());
|
||||||
|
comment->setAuthor(user);
|
||||||
comment->setPostId(newPost->id());
|
comment->setPostId(newPost->id());
|
||||||
db.comments()->append(comment);
|
db.comments()->append(comment);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,14 @@
|
||||||
|
|
||||||
#include "weblogdatabase.h"
|
#include "weblogdatabase.h"
|
||||||
class Post;
|
class Post;
|
||||||
|
class User;
|
||||||
class MainTest : public QObject
|
class MainTest : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
WeblogDatabase db;
|
WeblogDatabase db;
|
||||||
int postId;
|
int postId;
|
||||||
Post *post;
|
Post *post;
|
||||||
|
User *User;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainTest(QObject *parent = 0);
|
explicit MainTest(QObject *parent = 0);
|
||||||
|
|
@ -22,6 +24,7 @@ private slots:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
|
|
||||||
void dataScheema();
|
void dataScheema();
|
||||||
|
void createUser();
|
||||||
void createPost();
|
void createPost();
|
||||||
void createPost2();
|
void createPost2();
|
||||||
void selectPosts();
|
void selectPosts();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue