diff --git a/src/nut/generators/abstractsqlgenerator.cpp b/src/nut/generators/abstractsqlgenerator.cpp index f041cfb..d176b24 100644 --- a/src/nut/generators/abstractsqlgenerator.cpp +++ b/src/nut/generators/abstractsqlgenerator.cpp @@ -465,7 +465,7 @@ QString AbstractSqlGenerator::insertRecord(Table *t, QString tableName) QSet props = t->changedProperties(); QString changedPropertiesText = QString(); - Q_FOREACH (QString f, props) { + for (auto &f : props) { if (f == key) continue; @@ -490,11 +490,11 @@ QString AbstractSqlGenerator::updateRecord(Table *t, QString tableName) QString key = model->primaryKey(); QStringList values; - Q_FOREACH (QString f, t->changedProperties()) + for (auto &f : t->changedProperties()) if (f != key) - values.append(f + QStringLiteral("='") - + t->property(f.toLatin1().data()).toString() - + QStringLiteral("'")); + values.append(f + QStringLiteral("=") + + escapeValue(t->property(f.toLatin1().data()))); + sql = QStringLiteral("UPDATE %1 SET %2 WHERE %3=%4") .arg(tableName, values.join(QStringLiteral(", ")), diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 3bca532..4fa7fa1 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -6,6 +6,7 @@ SUBDIRS += \ tst_datatypes \ tst_phrases \ tst_properties \ + tst_qttypes \ tst_quuid \ tst_generators \ tst_upgrades \ diff --git a/tests/auto/tst_qttypes/db.cpp b/tests/auto/tst_qttypes/db.cpp new file mode 100644 index 0000000..e4ed911 --- /dev/null +++ b/tests/auto/tst_qttypes/db.cpp @@ -0,0 +1,9 @@ +#include "db.h" + +#include "sampletable.h" + +DB::DB(): Nut::Database (), + m_sampleTables(new Nut::TableSet(this)) +{ + +} diff --git a/tests/auto/tst_qttypes/db.h b/tests/auto/tst_qttypes/db.h new file mode 100644 index 0000000..6beb344 --- /dev/null +++ b/tests/auto/tst_qttypes/db.h @@ -0,0 +1,19 @@ +#ifndef DB_H +#define DB_H + +#include "database.h" + +class SampleTable; +class DB : public Nut::Database +{ + Q_OBJECT + + NUT_DB_VERSION(1) + + NUT_DECLARE_TABLE(SampleTable, sampleTables) + +public: + DB(); +}; + +#endif // DB_H diff --git a/tests/auto/tst_qttypes/sampletable.cpp b/tests/auto/tst_qttypes/sampletable.cpp new file mode 100644 index 0000000..9cafb3c --- /dev/null +++ b/tests/auto/tst_qttypes/sampletable.cpp @@ -0,0 +1,6 @@ +#include "sampletable.h" + +SampleTable::SampleTable(QObject *parent) : Nut::Table(parent) +{ + +} diff --git a/tests/auto/tst_qttypes/sampletable.h b/tests/auto/tst_qttypes/sampletable.h new file mode 100644 index 0000000..52d4d66 --- /dev/null +++ b/tests/auto/tst_qttypes/sampletable.h @@ -0,0 +1,29 @@ +#ifndef SAMPLETABLE_H +#define SAMPLETABLE_H + +#include +#include +#include +#include +#include + +#include "table.h" + +class SampleTable : public Nut::Table +{ + Q_OBJECT + + NUT_PRIMARY_AUTO_INCREMENT(id) + NUT_DECLARE_FIELD(int, id, id, setId) + + 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) + +public: + SampleTable(QObject *parent = nullptr); +}; + +#endif // SAMPLETABLE_H diff --git a/tests/auto/tst_qttypes/tst_qttypes.cpp b/tests/auto/tst_qttypes/tst_qttypes.cpp new file mode 100644 index 0000000..fdcb4e9 --- /dev/null +++ b/tests/auto/tst_qttypes/tst_qttypes.cpp @@ -0,0 +1,53 @@ +#include "db.h" + + +#include "consts.h" + +#include "sampletable.h" +#include "tst_qttypes.h" + +#include + + +QtTypes::QtTypes() +{ + REGISTER(SampleTable); + REGISTER(DB); + + db.setDriver(DRIVER); + db.setHostName(HOST); + db.setDatabaseName(DATABASE); + db.setUserName(USERNAME); + db.setPassword(PASSWORD); + + QFile::remove(DATABASE); + + QVERIFY(db.open()); +} + +QtTypes::~QtTypes() +{ + +} + +void QtTypes::insert() +{ + auto t = Nut::create(); + t->setPointf({1.2, 3.4}); + db.sampleTables()->append(t); + db.saveChanges(); + + auto t2 = db.sampleTables()->query().first(); + QCOMPARE(t->f_pointf(), t2->f_pointf()); +} + +void QtTypes::update(){ + auto t = db.sampleTables()->query().first(); + t->setPointf({5.6, 7.8}); + db.saveChanges(); + + auto t2 = db.sampleTables()->query().first(); + QCOMPARE(t->f_pointf(), t2->f_pointf()); +} + +QTEST_APPLESS_MAIN(QtTypes) diff --git a/tests/auto/tst_qttypes/tst_qttypes.h b/tests/auto/tst_qttypes/tst_qttypes.h new file mode 100644 index 0000000..e09ed16 --- /dev/null +++ b/tests/auto/tst_qttypes/tst_qttypes.h @@ -0,0 +1,23 @@ +#ifndef TST_QTTYPES_H +#define TST_QTTYPES_H + +#include "db.h" + +#include +class QtTypes : public QObject +{ + Q_OBJECT + + DB db; + +public: + QtTypes(); + ~QtTypes(); + +private slots: + void insert(); + void update(); + +}; + +#endif // TST_QTTYPES_H diff --git a/tests/auto/tst_qttypes/tst_qttypes.pro b/tests/auto/tst_qttypes/tst_qttypes.pro new file mode 100644 index 0000000..08b2017 --- /dev/null +++ b/tests/auto/tst_qttypes/tst_qttypes.pro @@ -0,0 +1,17 @@ +QT += testlib sql gui + +CONFIG += qt console warn_on depend_includepath testcase +CONFIG -= app_bundle + +TEMPLATE = app + +SOURCES += tst_qttypes.cpp \ + db.cpp \ + sampletable.cpp + +include(../common/nut-lib.pri) + +HEADERS += \ + db.h \ + sampletable.h \ + tst_qttypes.h