support PostGis types with equal operator [skip ci]
This commit is contained in:
parent
d2822e3ef3
commit
5f60b325aa
|
|
@ -62,6 +62,16 @@ bool PostgreSqlGenerator::readInsideParentese(QString &text, QString &out)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool PostgreSqlGenerator::isPostGisType(const QVariant::Type &t) const
|
||||
{
|
||||
return t == QVariant::Point
|
||||
|| t == QVariant::PointF
|
||||
|| t == QVariant::Rect
|
||||
|| t == QVariant::RectF
|
||||
|| t == QVariant::Polygon
|
||||
|| t == QVariant::PolygonF;
|
||||
}
|
||||
|
||||
PostgreSqlGenerator::PostgreSqlGenerator(Database *parent) : SqlGeneratorBase (parent)
|
||||
{
|
||||
|
||||
|
|
@ -215,14 +225,14 @@ QString PostgreSqlGenerator::escapeValue(const QVariant &v) const
|
|||
|
||||
if (v.type() == QVariant::Point) {
|
||||
QPoint pt = v.toPoint();
|
||||
return QString("'(%1, %2)'").arg(pt.x()).arg(pt.y());
|
||||
return QString("point(%1, %2)").arg(pt.x()).arg(pt.y());
|
||||
}
|
||||
if (v.type() == QVariant::PointF) {
|
||||
QPointF pt = v.toPointF();
|
||||
return QString("'(%1, %2)'").arg(pt.x()).arg(pt.y());
|
||||
return QString("point(%1, %2)").arg(pt.x()).arg(pt.y());
|
||||
}
|
||||
if (v.userType() == QMetaType::QJsonDocument) {
|
||||
return "'" + QString(v.toJsonDocument().toJson()) + "'";
|
||||
return "'" + QString(v.toJsonDocument().toJson(QJsonDocument::Compact)) + "'";
|
||||
}
|
||||
|
||||
#ifdef QT_GUI_LIB
|
||||
|
|
@ -313,5 +323,21 @@ QVariant PostgreSqlGenerator::unescapeValue(const QMetaType::Type &type, const Q
|
|||
return SqlGeneratorBase::unescapeValue(type, dbValue);
|
||||
}
|
||||
|
||||
QString PostgreSqlGenerator::createConditionalPhrase(const PhraseData *d) const
|
||||
{
|
||||
if (!d)
|
||||
return QString();
|
||||
|
||||
if (d->type == PhraseData::WithVariant) {
|
||||
if (isPostGisType(d->operand.type()) && d->operatorCond == PhraseData::Equal) {
|
||||
return QString("%1 ~= %2")
|
||||
.arg(SqlGeneratorBase::createConditionalPhrase(d->left),
|
||||
escapeValue(d->operand));
|
||||
}
|
||||
}
|
||||
|
||||
return SqlGeneratorBase::createConditionalPhrase(d);
|
||||
}
|
||||
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -30,18 +30,22 @@ class PostgreSqlGenerator : public SqlGeneratorBase
|
|||
{
|
||||
private:
|
||||
bool readInsideParentese(QString &ref, QString &out);
|
||||
|
||||
bool isPostGisType(const QVariant::Type &t) const;
|
||||
public:
|
||||
explicit PostgreSqlGenerator(Database *parent = nullptr);
|
||||
|
||||
QString fieldType(FieldModel *field);
|
||||
QString fieldType(FieldModel *field) override;
|
||||
|
||||
QString diff(FieldModel *oldField, FieldModel *newField);
|
||||
QString diff(FieldModel *oldField, FieldModel *newField) override;
|
||||
|
||||
// SqlGeneratorBase interface
|
||||
public:
|
||||
QString escapeValue(const QVariant &v) const;
|
||||
QVariant unescapeValue(const QMetaType::Type &type, const QVariant &dbValue);
|
||||
QString escapeValue(const QVariant &v) const override;
|
||||
QVariant unescapeValue(const QMetaType::Type &type, const QVariant &dbValue) override;
|
||||
|
||||
// SqlGeneratorBase interface
|
||||
protected:
|
||||
QString createConditionalPhrase(const PhraseData *d) const override;
|
||||
};
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ public:
|
|||
virtual QString primaryKeyConstraint(const TableModel *table) const;
|
||||
|
||||
protected:
|
||||
QString createConditionalPhrase(const PhraseData *d) const;
|
||||
virtual QString createConditionalPhrase(const PhraseData *d) const;
|
||||
QString createFieldPhrase(const PhraseList &ph);
|
||||
QString createOrderPhrase(const PhraseList &ph);
|
||||
void createInsertPhrase(const AssignmentPhraseList &ph, QString &fields, QString &values);
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ Q_OUTOFLINE_TEMPLATE Query<T>::Query(Database *database, TableSetBase *tableSet,
|
|||
d->className = T::staticMetaObject.className();
|
||||
d->tableName =
|
||||
d->database->model()
|
||||
.tableByClassName(T::staticMetaObject.className())
|
||||
.tableByClassName(d->className)
|
||||
->name();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ void TestJson::initTestCase()
|
|||
|
||||
void TestJson::store()
|
||||
{
|
||||
DB db;
|
||||
initDb(db);
|
||||
|
||||
db.open();
|
||||
|
|
@ -57,5 +56,10 @@ void TestJson::store()
|
|||
Q_ASSERT(newObj->doc() == t->doc());
|
||||
}
|
||||
|
||||
void TestJson::cleanupTestCase()
|
||||
{
|
||||
PRINT_FORM(db);
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(TestJson)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef TST_TESTJSON_H
|
||||
#define TST_TESTJSON_H
|
||||
|
||||
#include "db.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace Nut {
|
||||
|
|
@ -10,6 +12,8 @@ class TestJson : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
|
||||
DB db;
|
||||
|
||||
void initDb(Nut::Database &db);
|
||||
|
||||
int id;
|
||||
|
|
@ -22,6 +26,8 @@ private slots:
|
|||
|
||||
void store();
|
||||
|
||||
void cleanupTestCase();
|
||||
|
||||
};
|
||||
|
||||
#endif // TST_TESTJSON_H
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ void Upgrades::version1()
|
|||
DB1 db;
|
||||
initDb(db);
|
||||
QTEST_ASSERT(db.open());
|
||||
db.sampleTable()->query()->remove();
|
||||
}
|
||||
|
||||
void Upgrades::version2()
|
||||
|
|
@ -75,6 +76,13 @@ void Upgrades::version3()
|
|||
QTEST_ASSERT(id == t->id());
|
||||
}
|
||||
|
||||
void Upgrades::cleanupTestCase()
|
||||
{
|
||||
DB1 db;
|
||||
initDb(db);
|
||||
PRINT_FORM(db);
|
||||
}
|
||||
|
||||
|
||||
QTEST_APPLESS_MAIN(Upgrades)
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ private slots:
|
|||
void version2();
|
||||
void version3();
|
||||
|
||||
void cleanupTestCase();
|
||||
|
||||
};
|
||||
|
||||
#endif // TST_UPGRADES_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue