merbe back
This commit is contained in:
parent
9626e5f863
commit
370d5234e0
|
|
@ -25,6 +25,7 @@
|
|||
#include <QPolygonF>
|
||||
#endif
|
||||
#include <QVariant>
|
||||
#include <QJsonDocument>
|
||||
|
||||
#include "postgresqlgenerator.h"
|
||||
#include "../table.h"
|
||||
|
|
@ -220,6 +221,9 @@ QString PostgreSqlGenerator::escapeValue(const QVariant &v) const
|
|||
QPointF pt = v.toPointF();
|
||||
return QString("'(%1, %2)'").arg(pt.x()).arg(pt.y());
|
||||
}
|
||||
if (v.userType() == QMetaType::QJsonDocument) {
|
||||
return "'" + QString(v.toJsonDocument().toJson()) + "'";
|
||||
}
|
||||
|
||||
#ifdef QT_GUI_LIB
|
||||
if (v.type() == QVariant::Polygon) {
|
||||
|
|
|
|||
|
|
@ -468,7 +468,8 @@ QString SqlGeneratorBase::insertRecord(Table *t, QString tableName)
|
|||
QString SqlGeneratorBase::updateRecord(Table *t, QString tableName)
|
||||
{
|
||||
QString sql = QString();
|
||||
QString key = t->primaryKey();
|
||||
auto model = _database->model().tableByName(tableName);
|
||||
QString key = model->primaryKey();
|
||||
QStringList values;
|
||||
|
||||
foreach (QString f, t->changedProperties())
|
||||
|
|
@ -477,7 +478,7 @@ QString SqlGeneratorBase::updateRecord(Table *t, QString tableName)
|
|||
+ "'");
|
||||
sql = QString("UPDATE %1 SET %2 WHERE %3=%4")
|
||||
.arg(tableName, values.join(", "),
|
||||
key, t->primaryValue().toString());
|
||||
key, t->property(key.toUtf8().data()).toString());
|
||||
|
||||
removeTableNames(sql);
|
||||
|
||||
|
|
@ -486,8 +487,10 @@ QString SqlGeneratorBase::updateRecord(Table *t, QString tableName)
|
|||
|
||||
QString SqlGeneratorBase::deleteRecord(Table *t, QString tableName)
|
||||
{
|
||||
auto model = _database->model().tableByName(tableName);
|
||||
QString key = model->primaryKey();
|
||||
QString sql = QString("DELETE FROM %1 WHERE %2='%3'")
|
||||
.arg(tableName, t->primaryKey(), t->primaryValue().toString());
|
||||
.arg(tableName, key, t->property(key.toUtf8().data()).toString());
|
||||
replaceTableNames(sql);
|
||||
return sql;
|
||||
}
|
||||
|
|
@ -595,9 +598,9 @@ QString SqlGeneratorBase::selectCommand(const QString &tableName,
|
|||
if (orderText != "")
|
||||
sql.append(" ORDER BY " + orderText);
|
||||
|
||||
for (int i = 0; i < _database->model().count(); i++)
|
||||
sql = sql.replace(_database->model().at(i)->className() + ".",
|
||||
_database->model().at(i)->name() + ".");
|
||||
// for (int i = 0; i < _database->model().count(); i++)
|
||||
// sql = sql.replace(_database->model().at(i)->className() + ".",
|
||||
// _database->model().at(i)->name() + ".");
|
||||
|
||||
appendSkipTake(sql, skip, take);
|
||||
replaceTableNames(sql);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
#define DRIVER "QPSQL"
|
||||
#define DATABASE QString("nut_test_%1_db").arg(metaObject()->className()).toLower()
|
||||
#define HOST "127.0.0.1"
|
||||
#define USERNAME "nut"
|
||||
#define USERNAME "postgres"
|
||||
#define PASSWORD "856856"
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
|
|
|
|||
|
|
@ -41,12 +41,20 @@ void TestJson::store()
|
|||
db.open();
|
||||
|
||||
Table *t = new Table;
|
||||
QJsonDocument doc = QJsonDocument::fromJson("{a: 4, b:3.14}");
|
||||
QJsonParseError e;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(R"({"a": 4, "b":3.14})", &e);
|
||||
qDebug() << e.errorString();
|
||||
t->setDoc(doc);
|
||||
db.sampleTable()->append(t);
|
||||
db.saveChanges(true);
|
||||
|
||||
// QTEST_ASSERT(db.open());
|
||||
int id = t->id();
|
||||
auto newObj = db.sampleTable()->query()
|
||||
->where(Table::idField() == id)
|
||||
->first();
|
||||
|
||||
Q_ASSERT(newObj != nullptr);
|
||||
Q_ASSERT(newObj->doc() == t->doc());
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(TestJson)
|
||||
|
|
|
|||
Loading…
Reference in New Issue