fix: some values set to empty in update command
This commit is contained in:
parent
08a77bb7a4
commit
2dbe8f3b0e
|
|
@ -465,7 +465,7 @@ QString AbstractSqlGenerator::insertRecord(Table *t, QString tableName)
|
||||||
|
|
||||||
QSet<QString> props = t->changedProperties();
|
QSet<QString> props = t->changedProperties();
|
||||||
QString changedPropertiesText = QString();
|
QString changedPropertiesText = QString();
|
||||||
Q_FOREACH (QString f, props) {
|
for (auto &f : props) {
|
||||||
if (f == key)
|
if (f == key)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
@ -490,11 +490,11 @@ QString AbstractSqlGenerator::updateRecord(Table *t, QString tableName)
|
||||||
QString key = model->primaryKey();
|
QString key = model->primaryKey();
|
||||||
QStringList values;
|
QStringList values;
|
||||||
|
|
||||||
Q_FOREACH (QString f, t->changedProperties())
|
for (auto &f : t->changedProperties())
|
||||||
if (f != key)
|
if (f != key)
|
||||||
values.append(f + QStringLiteral("='")
|
values.append(f + QStringLiteral("=")
|
||||||
+ t->property(f.toLatin1().data()).toString()
|
+ escapeValue(t->property(f.toLatin1().data())));
|
||||||
+ QStringLiteral("'"));
|
|
||||||
sql = QStringLiteral("UPDATE %1 SET %2 WHERE %3=%4")
|
sql = QStringLiteral("UPDATE %1 SET %2 WHERE %3=%4")
|
||||||
.arg(tableName,
|
.arg(tableName,
|
||||||
values.join(QStringLiteral(", ")),
|
values.join(QStringLiteral(", ")),
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ SUBDIRS += \
|
||||||
tst_datatypes \
|
tst_datatypes \
|
||||||
tst_phrases \
|
tst_phrases \
|
||||||
tst_properties \
|
tst_properties \
|
||||||
|
tst_qttypes \
|
||||||
tst_quuid \
|
tst_quuid \
|
||||||
tst_generators \
|
tst_generators \
|
||||||
tst_upgrades \
|
tst_upgrades \
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
#include "db.h"
|
||||||
|
|
||||||
|
#include "sampletable.h"
|
||||||
|
|
||||||
|
DB::DB(): Nut::Database (),
|
||||||
|
m_sampleTables(new Nut::TableSet<SampleTable>(this))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include "sampletable.h"
|
||||||
|
|
||||||
|
SampleTable::SampleTable(QObject *parent) : Nut::Table(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef SAMPLETABLE_H
|
||||||
|
#define SAMPLETABLE_H
|
||||||
|
|
||||||
|
#include <QPoint>
|
||||||
|
#include <QPointF>
|
||||||
|
#include <QPolygon>
|
||||||
|
#include <QPolygonF>
|
||||||
|
#include <QColor>
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
#include "db.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "consts.h"
|
||||||
|
|
||||||
|
#include "sampletable.h"
|
||||||
|
#include "tst_qttypes.h"
|
||||||
|
|
||||||
|
#include <QtNut/Query>
|
||||||
|
|
||||||
|
|
||||||
|
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<SampleTable>();
|
||||||
|
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)
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef TST_QTTYPES_H
|
||||||
|
#define TST_QTTYPES_H
|
||||||
|
|
||||||
|
#include "db.h"
|
||||||
|
|
||||||
|
#include <QtTest>
|
||||||
|
class QtTypes : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
DB db;
|
||||||
|
|
||||||
|
public:
|
||||||
|
QtTypes();
|
||||||
|
~QtTypes();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void insert();
|
||||||
|
void update();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TST_QTTYPES_H
|
||||||
|
|
@ -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
|
||||||
Loading…
Reference in New Issue