wip: CONSTRAINT [skip ci]

This commit is contained in:
Hamed Masafi 2019-03-02 19:21:43 +03:30
parent a6f6217d89
commit bb55b4b743
7 changed files with 53 additions and 37 deletions

View File

@ -249,6 +249,7 @@ QStringList SqlGeneratorBase::diff(TableModel *oldTable, TableModel *newTable)
QString pkCon = primaryKeyConstraint(newTable);
if (!pkCon.isEmpty())
columnSql << pkCon;
columnSql << constraints(newTable);
}
sql = QString("CREATE TABLE %1 \n(%2)")
@ -853,7 +854,7 @@ QString SqlGeneratorBase::escapeValue(const QVariant &v) const
}
}
QVariant SqlGeneratorBase::readValue(const QMetaType::Type &type,
QVariant SqlGeneratorBase::unescapeValue(const QMetaType::Type &type,
const QVariant &dbValue)
{
return _serializer->deserialize(dbValue.toString(), type);

View File

@ -96,9 +96,9 @@ QString SqliteGenerator::fieldDeclare(FieldModel *field)
return type;
if (field->isPrimaryKey) {
type.append(" PRIMARY KEY");
type.append("INTEGER PRIMARY KEY");
if (field->isAutoIncrement)
type = "INTEGER PRIMARY KEY AUTOINCREMENT";
type.append(" AUTOINCREMENT");
}
if (field->notNull)

View File

@ -33,6 +33,7 @@ public:
QString fieldType(FieldModel *field) override;
QString fieldDeclare(FieldModel *field) override;
bool supportAutoIncrement(const QMetaType::Type &type) override;
void appendSkipTake(QString &sql, int skip, int take) override;

View File

@ -31,7 +31,7 @@ void BasicTest::initTestCase()
db.setDriver(DRIVER);
db.setHostName(HOST);
db.setDatabaseName("nut_tst_basic");
db.setDatabaseName(DATABASE);
db.setUserName(USERNAME);
db.setPassword(PASSWORD);

View File

@ -1,17 +1,19 @@
#ifndef SAMPLETABLE_H
#define SAMPLETABLE_H
#include <QColor>
#include <QPoint>
#include <QTime>
#include <QDate>
#include <QDateTime>
#include <QPolygon>
#include <QUrl>
#include <QUuid>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#ifdef QT_GUI_LIB
#include <QColor>
#include <QPolygon>
#endif
#include "table.h"
@ -38,10 +40,6 @@ class SampleTable : public Nut::Table
NUT_DECLARE_FIELD(float, f_float, f_float, setFloat)
// NUT_DECLARE_FIELD(long double, fldouble, fldouble, setFldouble)
NUT_DECLARE_FIELD(QString, f_string, f_string, setString)
NUT_DECLARE_FIELD(QPoint, f_point, f_point, setPoint)
NUT_DECLARE_FIELD(QPointF, f_pointf, f_pointf, setPointf)
NUT_DECLARE_FIELD(QPolygon, f_polygon, f_polygon, setPolygon)
NUT_DECLARE_FIELD(QPolygonF, f_polygonf, f_polygonf, setPolygonf)
NUT_DECLARE_FIELD(QTime, f_time, f_time, setTime)
NUT_DECLARE_FIELD(QDate, f_date, f_date, setDate)
@ -58,8 +56,13 @@ class SampleTable : public Nut::Table
NUT_DECLARE_FIELD(QStringList, f_stringList, f_stringList, setStringList)
NUT_DECLARE_FIELD(QChar, f_qchar, f_qchar, setQchar)
#ifdef QT_GUI_LIB
NUT_DECLARE_FIELD(QPoint, f_point, f_point, setPoint)
NUT_DECLARE_FIELD(QPointF, f_pointf, f_pointf, setPointf)
NUT_DECLARE_FIELD(QPolygon, f_polygon, f_polygon, setPolygon)
NUT_DECLARE_FIELD(QPolygonF, f_polygonf, f_polygonf, setPolygonf)
NUT_DECLARE_FIELD(QColor, f_color, f_color, setColor)
#endif
public:
Q_INVOKABLE SampleTable(QObject *parent = Q_NULLPTR);
};

View File

@ -44,10 +44,6 @@ void DataTypesTest::initTestCase()
f_uint64 = 64ull;
f_real = 1.2;
f_float = 2.3f;
f_point = QPoint(1, 2);
f_pointf = QPointF(1.2, 3.4);
f_polygon = QPolygon() << QPoint(1, 2) << QPoint(3, 4) << QPoint(5, 6);
f_polygonf = QPolygonF() << QPointF(1.2, 2.3) << QPointF(3.4, 4.5) << QPointF(5.6, 6.7);
f_url = QUrl("http://google.com/search?q=nut");
@ -74,7 +70,13 @@ void DataTypesTest::initTestCase()
f_qchar = QChar('z');
#ifdef QT_GUI_LIB
f_point = QPoint(1, 2);
f_pointf = QPointF(1.2, 3.4);
f_polygon = QPolygon() << QPoint(1, 2) << QPoint(3, 4) << QPoint(5, 6);
f_polygonf = QPolygonF() << QPointF(1.2, 2.3) << QPointF(3.4, 4.5) << QPointF(5.6, 6.7);
f_color = Qt::red;
#endif
QTEST_ASSERT(ok);
@ -97,12 +99,6 @@ void DataTypesTest::insert()
t.setReal(f_real);
t.setFloat(f_float);
t.setPoint(f_point);
t.setPointf(f_pointf);
t.setPolygon(f_polygon);
t.setPolygonf(f_polygonf);
t.setUrl(f_url);
t.setTime(f_time);
@ -118,8 +114,15 @@ void DataTypesTest::insert()
t.setString(f_string);
t.setStringList(f_stringList);
t.setQchar(f_qchar);
#ifdef QT_GUI_LIB
t.setColor(f_color);
t.setPoint(f_point);
t.setPointf(f_pointf);
t.setPolygon(f_polygon);
t.setPolygonf(f_polygonf);
#endif
db.sampleTables()->append(&t);
db.saveChanges();
}
@ -143,11 +146,6 @@ void DataTypesTest::retrive()
QTEST_ASSERT(qFuzzyCompare(t->f_real(), f_real));
QTEST_ASSERT(qFuzzyCompare(t->f_float(), f_float));
QTEST_ASSERT(t->f_point() == f_point);
QTEST_ASSERT(t->f_pointf() == f_pointf);
QTEST_ASSERT(t->f_polygon() == f_polygon);
QTEST_ASSERT(t->f_polygonf() == f_polygonf);
QTEST_ASSERT(t->f_url() == f_url);
QTEST_ASSERT(t->f_uuid() == f_uuid);
@ -164,7 +162,14 @@ void DataTypesTest::retrive()
QTEST_ASSERT(t->f_string() == f_string);
QTEST_ASSERT(t->f_stringList() == f_stringList);
QTEST_ASSERT(t->f_qchar() == f_qchar);
#ifdef QT_GUI_LIB
QTEST_ASSERT(t->f_point() == f_point);
QTEST_ASSERT(t->f_pointf() == f_pointf);
QTEST_ASSERT(t->f_polygon() == f_polygon);
QTEST_ASSERT(t->f_polygonf() == f_polygonf);
QTEST_ASSERT(t->f_color() == f_color);
#endif
}
#define CHECK(name) \
@ -187,10 +192,6 @@ void DataTypesTest::check()
CHECK(uint64)
CHECK(real)
CHECK(float)
CHECK(point)
CHECK(pointf)
CHECK(polygon)
CHECK(polygonf)
CHECK(url)
CHECK(time)
@ -207,7 +208,13 @@ void DataTypesTest::check()
CHECK(stringList)
CHECK(qchar)
#ifdef QT_GUI_LIB
CHECK(point)
CHECK(pointf)
CHECK(polygon)
CHECK(polygonf)
CHECK(color)
#endif
}
void DataTypesTest::cleanupTestCase()

View File

@ -4,12 +4,14 @@
#include <QtCore/QObject>
#include <QtCore/qglobal.h>
#include <QColor>
#include <QDateTime>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#ifdef QT_GUI_LIB
#include <QColor>
#include <QPolygonF>
#endif
#include <QUrl>
#include <QUuid>
@ -29,17 +31,11 @@ class DataTypesTest : public QObject
quint64 f_uint64;
qreal f_real;
float f_float;
QPoint f_point;
QPointF f_pointf;
QPolygon f_polygon;
QPolygonF f_polygonf;
QUrl f_url;
QTime f_time;
QDate f_date;
QDateTime f_dateTime;
QUuid f_uuid;
QJsonDocument f_jsonDoc;
QJsonObject f_jsonObj;
QJsonArray f_jsonArray;
@ -49,7 +45,15 @@ class DataTypesTest : public QObject
QStringList f_stringList;
QChar f_qchar;
QUrl f_url;
QUuid f_uuid;
#ifdef QT_GUI_LIB
QPoint f_point;
QPointF f_pointf;
QPolygon f_polygon;
QPolygonF f_polygonf;
QColor f_color;
#endif
public:
explicit DataTypesTest(QObject *parent = nullptr);