mysql passed upgrade test [skip ci]
This commit is contained in:
parent
f3748241ff
commit
762481ba2f
|
|
@ -249,4 +249,27 @@ DatabaseModel operator +(const DatabaseModel &l, const DatabaseModel &r)
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DatabaseModel operator |(const DatabaseModel &l, const DatabaseModel &r)
|
||||||
|
{
|
||||||
|
DatabaseModel ret;
|
||||||
|
DatabaseModel::const_iterator i;
|
||||||
|
QSet<QString> tables;
|
||||||
|
|
||||||
|
for (i = r.constBegin(); i != r.constEnd(); ++i) {
|
||||||
|
if (tables.contains((*i)->name()))
|
||||||
|
continue;
|
||||||
|
ret.append(*i);
|
||||||
|
tables.insert((*i)->name());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = l.constBegin(); i != l.constEnd(); ++i) {
|
||||||
|
if (tables.contains((*i)->name()))
|
||||||
|
continue;
|
||||||
|
ret.append(*i);
|
||||||
|
tables.insert((*i)->name());
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
NUT_END_NAMESPACE
|
NUT_END_NAMESPACE
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
DatabaseModel operator +(const DatabaseModel &l, const DatabaseModel &r);
|
DatabaseModel operator +(const DatabaseModel &l, const DatabaseModel &r);
|
||||||
|
DatabaseModel operator |(const DatabaseModel &l, const DatabaseModel &r);
|
||||||
|
|
||||||
NUT_END_NAMESPACE
|
NUT_END_NAMESPACE
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -127,14 +127,16 @@ QStringList SqlGeneratorBase::diff(const DatabaseModel &lastModel,
|
||||||
{
|
{
|
||||||
QStringList ret;
|
QStringList ret;
|
||||||
|
|
||||||
DatabaseModel unionModel = lastModel + newModel;
|
DatabaseModel unionModel = lastModel | newModel;
|
||||||
|
DatabaseModel::iterator i;
|
||||||
|
|
||||||
foreach (TableModel *table, unionModel) {
|
for (i = unionModel.begin(); i != unionModel.end(); ++i) {
|
||||||
TableModel *oldTable = lastModel.tableByName(table->name());
|
TableModel *oldTable = lastModel.tableByName((*i)->name());
|
||||||
TableModel *newTable = newModel.tableByName(table->name());
|
TableModel *newTable = newModel.tableByName((*i)->name());
|
||||||
QStringList sql = diff(oldTable, newTable);
|
QStringList sql = diff(oldTable, newTable);
|
||||||
if (!sql.isEmpty())
|
if (!sql.isEmpty())
|
||||||
ret << sql;
|
ret << sql;
|
||||||
|
|
||||||
// QString sqlRel = diffRelation(oldTable, newTable);
|
// QString sqlRel = diffRelation(oldTable, newTable);
|
||||||
// if (!sqlRel.isEmpty())
|
// if (!sqlRel.isEmpty())
|
||||||
// ret << sqlRel;
|
// ret << sqlRel;
|
||||||
|
|
|
||||||
|
|
@ -123,9 +123,14 @@ public:
|
||||||
QList<RelationModel *> foregionKeys() const;
|
QList<RelationModel *> foregionKeys() const;
|
||||||
QStringList fieldsNames() const;
|
QStringList fieldsNames() const;
|
||||||
|
|
||||||
|
Q_DECL_DEPRECATED
|
||||||
static QSet<TableModel *> allModels();
|
static QSet<TableModel *> allModels();
|
||||||
|
|
||||||
|
Q_DECL_DEPRECATED
|
||||||
static TableModel *findByTypeId(int typeId);
|
static TableModel *findByTypeId(int typeId);
|
||||||
// static TableModel *findByName(QString name);
|
// static TableModel *findByName(QString name);
|
||||||
|
|
||||||
|
Q_DECL_DEPRECATED
|
||||||
static TableModel *findByClassName(const QString &className);
|
static TableModel *findByClassName(const QString &className);
|
||||||
|
|
||||||
bool operator ==(const TableModel &t) const;
|
bool operator ==(const TableModel &t) const;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
.arg(timer.elapsed() / 1000.) \
|
.arg(timer.elapsed() / 1000.) \
|
||||||
.arg(__func__)
|
.arg(__func__)
|
||||||
|
|
||||||
#define DRIVER "QSQLITE"
|
#define DRIVER "QMYSQL"
|
||||||
#define DATABASE QString(metaObject()->className()).toLower() + "_db"
|
#define DATABASE QString(metaObject()->className()).toLower() + "_db"
|
||||||
#define HOST "localhost"
|
#define HOST "localhost"
|
||||||
#define USERNAME "root"
|
#define USERNAME "root"
|
||||||
|
|
|
||||||
|
|
@ -34,47 +34,47 @@ void DataTypesTest::initTestCase()
|
||||||
|
|
||||||
QFile::remove(DATABASE);
|
QFile::remove(DATABASE);
|
||||||
bool ok = db.open();
|
bool ok = db.open();
|
||||||
n8 = 8;
|
f_int8 = 8;
|
||||||
n16 = 16;
|
f_int16 = 16;
|
||||||
n32 = 32l;
|
f_int32 = 32l;
|
||||||
n64 = 64ll;
|
f_int64 = 64ll;
|
||||||
nu8 = 8u;
|
f_uint8 = 8u;
|
||||||
nu16 = 16u;
|
f_uint16 = 16u;
|
||||||
nu32 = 32ul;
|
f_uint32 = 32ul;
|
||||||
nu64 = 64ull;
|
f_uint64 = 64ull;
|
||||||
r = 1.2;
|
f_real = 1.2;
|
||||||
f = 2.3f;
|
f_float = 2.3f;
|
||||||
point = QPoint(1, 2);
|
f_point = QPoint(1, 2);
|
||||||
pointf = QPointF(1.2, 3.4);
|
f_pointf = QPointF(1.2, 3.4);
|
||||||
polygon = QPolygon() << QPoint(1, 2) << QPoint(3, 4) << QPoint(5, 6);
|
f_polygon = QPolygon() << QPoint(1, 2) << QPoint(3, 4) << QPoint(5, 6);
|
||||||
polygonf = QPolygonF() << QPointF(1.2, 2.3) << QPointF(3.4, 4.5) << QPointF(5.6, 6.7);
|
f_polygonf = QPolygonF() << QPointF(1.2, 2.3) << QPointF(3.4, 4.5) << QPointF(5.6, 6.7);
|
||||||
|
|
||||||
url = QUrl("http://google.com/search?q=nut");
|
f_url = QUrl("http://google.com/search?q=nut");
|
||||||
|
|
||||||
time = QTime::currentTime();
|
f_time = QTime::currentTime();
|
||||||
time.setHMS(time.hour(), time.minute(), time.second());
|
f_time.setHMS(f_time.hour(), f_time.minute(), f_time.second());
|
||||||
|
|
||||||
date = QDate::currentDate();
|
f_date = QDate::currentDate();
|
||||||
dateTime = QDateTime::currentDateTime();
|
f_dateTime = QDateTime::currentDateTime();
|
||||||
dateTime.setTime(time);
|
f_dateTime.setTime(f_time);
|
||||||
|
|
||||||
uuid = QUuid::createUuid();
|
f_uuid = QUuid::createUuid();
|
||||||
jsonDoc = QJsonDocument::fromJson("{\"a\": 1}");
|
f_jsonDoc = QJsonDocument::fromJson("{\"a\": 1}");
|
||||||
jsonObj = jsonDoc.object();
|
f_jsonObj = f_jsonDoc.object();
|
||||||
jsonArr.insert(0, QJsonValue(1));
|
f_jsonArray.insert(0, QJsonValue(1));
|
||||||
jsonArr.insert(1, QJsonValue("Hi"));
|
f_jsonArray.insert(1, QJsonValue("Hi"));
|
||||||
jsonArr.insert(2, QJsonValue(true));
|
f_jsonArray.insert(2, QJsonValue(true));
|
||||||
|
|
||||||
jsonValue = QJsonValue(true);
|
f_jsonValue = QJsonValue(true);
|
||||||
|
|
||||||
stringList.append("One");
|
f_stringList.append("One");
|
||||||
stringList.append("Two");
|
f_stringList.append("Two");
|
||||||
stringList.append("Three");
|
f_stringList.append("Three");
|
||||||
string = "this is \n sample ' unescapped \r\n text";
|
f_string = "this is \n sample ' unescapped \r\n text";
|
||||||
|
|
||||||
qchar = QChar('z');
|
f_qchar = QChar('z');
|
||||||
|
|
||||||
color = Qt::red;
|
f_color = Qt::red;
|
||||||
|
|
||||||
QTEST_ASSERT(ok);
|
QTEST_ASSERT(ok);
|
||||||
|
|
||||||
|
|
@ -84,41 +84,41 @@ void DataTypesTest::initTestCase()
|
||||||
void DataTypesTest::insert()
|
void DataTypesTest::insert()
|
||||||
{
|
{
|
||||||
SampleTable t;
|
SampleTable t;
|
||||||
t.setInt8(n8);
|
t.setInt8(f_int8);
|
||||||
t.setInt16(n16);
|
t.setInt16(f_int16);
|
||||||
t.setInt32(n32);
|
t.setInt32(f_int32);
|
||||||
t.setInt64(n64);
|
t.setInt64(f_int64);
|
||||||
|
|
||||||
t.setUint8(nu8);
|
t.setUint8(f_uint8);
|
||||||
t.setUint16(nu16);
|
t.setUint16(f_uint16);
|
||||||
t.setUint32(nu32);
|
t.setUint32(f_uint32);
|
||||||
t.setUint64(nu64);
|
t.setUint64(f_uint64);
|
||||||
|
|
||||||
t.setReal(r);
|
t.setReal(f_real);
|
||||||
t.setFloat(f);
|
t.setFloat(f_float);
|
||||||
|
|
||||||
t.setPoint(point);
|
t.setPoint(f_point);
|
||||||
t.setPointf(pointf);
|
t.setPointf(f_pointf);
|
||||||
|
|
||||||
t.setPolygon(polygon);
|
t.setPolygon(f_polygon);
|
||||||
t.setPolygonf(polygonf);
|
t.setPolygonf(f_polygonf);
|
||||||
|
|
||||||
t.setUrl(url);
|
t.setUrl(f_url);
|
||||||
|
|
||||||
t.setTime(time);
|
t.setTime(f_time);
|
||||||
t.setDate(date);
|
t.setDate(f_date);
|
||||||
t.setDateTime(dateTime);
|
t.setDateTime(f_dateTime);
|
||||||
t.setUuid(uuid);
|
t.setUuid(f_uuid);
|
||||||
|
|
||||||
t.setJsonDoc(jsonDoc);
|
t.setJsonDoc(f_jsonDoc);
|
||||||
t.setJsonObj(jsonObj);
|
t.setJsonObj(f_jsonObj);
|
||||||
t.setJsonArray(jsonArr);
|
t.setJsonArray(f_jsonArray);
|
||||||
t.setJsonValue(jsonValue);
|
t.setJsonValue(f_jsonValue);
|
||||||
|
|
||||||
t.setString(string);
|
t.setString(f_string);
|
||||||
t.setStringList(stringList);
|
t.setStringList(f_stringList);
|
||||||
t.setQchar(qchar);
|
t.setQchar(f_qchar);
|
||||||
t.setColor(color);
|
t.setColor(f_color);
|
||||||
|
|
||||||
db.sampleTables()->append(&t);
|
db.sampleTables()->append(&t);
|
||||||
db.saveChanges();
|
db.saveChanges();
|
||||||
|
|
@ -129,42 +129,85 @@ void DataTypesTest::retrive()
|
||||||
QList<SampleTable*> list = db.sampleTables()->query()->toList();
|
QList<SampleTable*> list = db.sampleTables()->query()->toList();
|
||||||
QTEST_ASSERT(list.count() == 1);
|
QTEST_ASSERT(list.count() == 1);
|
||||||
SampleTable *t = list.first();
|
SampleTable *t = list.first();
|
||||||
qDebug() << time << t->f_time();
|
|
||||||
QTEST_ASSERT(t->f_int8() == n8);
|
|
||||||
QTEST_ASSERT(t->f_int16() == n16);
|
|
||||||
QTEST_ASSERT(t->f_int32() == n32);
|
|
||||||
QTEST_ASSERT(t->f_int64() == n64);
|
|
||||||
|
|
||||||
QTEST_ASSERT(t->f_uint8() == nu8);
|
QTEST_ASSERT(t->f_int8() == f_int8);
|
||||||
QTEST_ASSERT(t->f_uint16() == nu16);
|
QTEST_ASSERT(t->f_int16() == f_int16);
|
||||||
QTEST_ASSERT(t->f_uint32() == nu32);
|
QTEST_ASSERT(t->f_int32() == f_int32);
|
||||||
QTEST_ASSERT(t->f_uint64() == nu64);
|
QTEST_ASSERT(t->f_int64() == f_int64);
|
||||||
|
|
||||||
QTEST_ASSERT(qFuzzyCompare(t->f_real(), r));
|
QTEST_ASSERT(t->f_uint8() == f_uint8);
|
||||||
QTEST_ASSERT(qFuzzyCompare(t->f_float(), f));
|
QTEST_ASSERT(t->f_uint16() == f_uint16);
|
||||||
|
QTEST_ASSERT(t->f_uint32() == f_uint32);
|
||||||
|
QTEST_ASSERT(t->f_uint64() == f_uint64);
|
||||||
|
|
||||||
QTEST_ASSERT(t->f_point() == point);
|
QTEST_ASSERT(qFuzzyCompare(t->f_real(), f_real));
|
||||||
QTEST_ASSERT(t->f_pointf() == pointf);
|
QTEST_ASSERT(qFuzzyCompare(t->f_float(), f_float));
|
||||||
|
|
||||||
QTEST_ASSERT(t->f_polygon() == polygon);
|
QTEST_ASSERT(t->f_point() == f_point);
|
||||||
QTEST_ASSERT(t->f_polygonf() == polygonf);
|
QTEST_ASSERT(t->f_pointf() == f_pointf);
|
||||||
|
|
||||||
QTEST_ASSERT(t->f_url() == url);
|
QTEST_ASSERT(t->f_polygon() == f_polygon);
|
||||||
QTEST_ASSERT(t->f_uuid() == uuid);
|
QTEST_ASSERT(t->f_polygonf() == f_polygonf);
|
||||||
|
|
||||||
QTEST_ASSERT(t->f_time() == time);
|
QTEST_ASSERT(t->f_url() == f_url);
|
||||||
QTEST_ASSERT(t->f_date() == date);
|
QTEST_ASSERT(t->f_uuid() == f_uuid);
|
||||||
QTEST_ASSERT(t->f_dateTime() == dateTime);
|
|
||||||
|
|
||||||
QTEST_ASSERT(t->f_jsonDoc() == jsonDoc);
|
QTEST_ASSERT(t->f_time() == f_time);
|
||||||
QTEST_ASSERT(t->f_jsonObj() == jsonObj);
|
QTEST_ASSERT(t->f_date() == f_date);
|
||||||
QTEST_ASSERT(t->f_jsonArray() == jsonArr);
|
QTEST_ASSERT(t->f_dateTime() == f_dateTime);
|
||||||
QTEST_ASSERT(t->f_jsonValue() == jsonValue);
|
|
||||||
|
|
||||||
QTEST_ASSERT(t->f_string() == string);
|
QTEST_ASSERT(t->f_jsonDoc() == f_jsonDoc);
|
||||||
QTEST_ASSERT(t->f_stringList() == stringList);
|
QTEST_ASSERT(t->f_jsonObj() == f_jsonObj);
|
||||||
QTEST_ASSERT(t->f_qchar() == qchar);
|
QTEST_ASSERT(t->f_jsonArray() == f_jsonArray);
|
||||||
QTEST_ASSERT(t->f_color() == color);
|
QTEST_ASSERT(t->f_jsonValue() == f_jsonValue);
|
||||||
|
|
||||||
|
QTEST_ASSERT(t->f_string() == f_string);
|
||||||
|
QTEST_ASSERT(t->f_stringList() == f_stringList);
|
||||||
|
QTEST_ASSERT(t->f_qchar() == f_qchar);
|
||||||
|
QTEST_ASSERT(t->f_color() == f_color);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CHECK(name) \
|
||||||
|
c = db.sampleTables()->query() \
|
||||||
|
->where(SampleTable::f_ ## name ## Field() == f_ ## name) \
|
||||||
|
->count(); \
|
||||||
|
QTEST_ASSERT(c == 1);
|
||||||
|
|
||||||
|
void DataTypesTest::check()
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
|
||||||
|
CHECK(int8)
|
||||||
|
CHECK(int16)
|
||||||
|
CHECK(int32)
|
||||||
|
CHECK(int64)
|
||||||
|
CHECK(uint8)
|
||||||
|
CHECK(uint16)
|
||||||
|
CHECK(uint32)
|
||||||
|
CHECK(uint64)
|
||||||
|
CHECK(real)
|
||||||
|
CHECK(float)
|
||||||
|
CHECK(point)
|
||||||
|
CHECK(pointf)
|
||||||
|
CHECK(polygon)
|
||||||
|
CHECK(polygonf)
|
||||||
|
CHECK(url)
|
||||||
|
|
||||||
|
CHECK(time)
|
||||||
|
CHECK(date)
|
||||||
|
CHECK(dateTime)
|
||||||
|
|
||||||
|
CHECK(uuid)
|
||||||
|
CHECK(jsonDoc)
|
||||||
|
CHECK(jsonObj)
|
||||||
|
CHECK(jsonArray)
|
||||||
|
CHECK(jsonValue)
|
||||||
|
|
||||||
|
CHECK(string)
|
||||||
|
CHECK(stringList)
|
||||||
|
|
||||||
|
CHECK(qchar)
|
||||||
|
CHECK(color)
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataTypesTest::cleanupTestCase()
|
void DataTypesTest::cleanupTestCase()
|
||||||
|
|
|
||||||
|
|
@ -19,37 +19,37 @@ class DataTypesTest : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
DB db;
|
DB db;
|
||||||
|
|
||||||
qint8 n8;
|
qint8 f_int8;
|
||||||
qint16 n16;
|
qint16 f_int16;
|
||||||
qint32 n32;
|
qint32 f_int32;
|
||||||
qint64 n64;
|
qint64 f_int64;
|
||||||
quint8 nu8;
|
quint8 f_uint8;
|
||||||
quint16 nu16;
|
quint16 f_uint16;
|
||||||
quint32 nu32;
|
quint32 f_uint32;
|
||||||
quint64 nu64;
|
quint64 f_uint64;
|
||||||
qreal r;
|
qreal f_real;
|
||||||
float f;
|
float f_float;
|
||||||
QPoint point;
|
QPoint f_point;
|
||||||
QPointF pointf;
|
QPointF f_pointf;
|
||||||
QPolygon polygon;
|
QPolygon f_polygon;
|
||||||
QPolygonF polygonf;
|
QPolygonF f_polygonf;
|
||||||
QUrl url;
|
QUrl f_url;
|
||||||
|
|
||||||
QTime time;
|
QTime f_time;
|
||||||
QDate date;
|
QDate f_date;
|
||||||
QDateTime dateTime;
|
QDateTime f_dateTime;
|
||||||
|
|
||||||
QUuid uuid;
|
QUuid f_uuid;
|
||||||
QJsonDocument jsonDoc;
|
QJsonDocument f_jsonDoc;
|
||||||
QJsonObject jsonObj;
|
QJsonObject f_jsonObj;
|
||||||
QJsonArray jsonArr;
|
QJsonArray f_jsonArray;
|
||||||
QJsonValue jsonValue;
|
QJsonValue f_jsonValue;
|
||||||
|
|
||||||
QString string;
|
QString f_string;
|
||||||
QStringList stringList;
|
QStringList f_stringList;
|
||||||
|
|
||||||
QChar qchar;
|
QChar f_qchar;
|
||||||
QColor color;
|
QColor f_color;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DataTypesTest(QObject *parent = nullptr);
|
explicit DataTypesTest(QObject *parent = nullptr);
|
||||||
|
|
@ -61,6 +61,7 @@ private slots:
|
||||||
|
|
||||||
void insert();
|
void insert();
|
||||||
void retrive();
|
void retrive();
|
||||||
|
void check();
|
||||||
void cleanupTestCase();
|
void cleanupTestCase();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue