psql passes datatypes test
This commit is contained in:
parent
b3e23864ce
commit
49f006e2d5
|
|
@ -22,15 +22,45 @@
|
|||
#include <QPoint>
|
||||
#ifdef QT_GUI_LIB
|
||||
#include <QPolygon>
|
||||
#include <QPolygonF>
|
||||
#endif
|
||||
#include <QVariant>
|
||||
|
||||
#include "postgresqlgenerator.h"
|
||||
#include "../table.h"
|
||||
#include "../tablemodel.h"
|
||||
#include "sqlserializer.h"
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
bool PostgreSqlGenerator::readInsideParentese(QString &text, QString &out)
|
||||
{
|
||||
int start = -1;
|
||||
int end = -1;
|
||||
int pc = 0;
|
||||
for (int i = 0; i < text.length(); ++i) {
|
||||
QChar ch = text.at(i);
|
||||
|
||||
if (ch == '(') {
|
||||
if (start == -1)
|
||||
start = i;
|
||||
pc++;
|
||||
}
|
||||
if (ch == ')') {
|
||||
pc--;
|
||||
|
||||
if (!pc && end == -1)
|
||||
end = i;
|
||||
}
|
||||
if (start != -1 && end != -1){
|
||||
out = text.mid(start + 1, end - start - 1);
|
||||
text = text.mid(end + 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
PostgreSqlGenerator::PostgreSqlGenerator(Database *parent) : SqlGeneratorBase (parent)
|
||||
{
|
||||
|
||||
|
|
@ -228,16 +258,58 @@ QString PostgreSqlGenerator::escapeValue(const QVariant &v) const
|
|||
QVariant PostgreSqlGenerator::readValue(const QMetaType::Type &type, const QVariant &dbValue)
|
||||
{
|
||||
if (type == QMetaType::QDateTime)
|
||||
return dbValue.toDateTime();// QDateTime::fromString(dbValue.toString(), "yyyy-MM-dd HH:mm:ss");
|
||||
return dbValue.toDateTime();
|
||||
|
||||
if (type == QMetaType::QPoint) {
|
||||
if (type == QMetaType::QTime)
|
||||
return dbValue.toTime();
|
||||
|
||||
if (type == QMetaType::QDate)
|
||||
return dbValue.toDate();
|
||||
|
||||
if (type == QMetaType::QPoint)
|
||||
return SqlGeneratorBase::readValue(QMetaType::QPoint, dbValue.toString()
|
||||
.replace("(", "").replace(")", ""));
|
||||
}
|
||||
if (type == QMetaType::QPointF) {
|
||||
if (type == QMetaType::QPointF)
|
||||
return SqlGeneratorBase::readValue(QMetaType::QPointF, dbValue.toString()
|
||||
.replace("(", "").replace(")", ""));
|
||||
if (type == QMetaType::QStringList)
|
||||
return dbValue.toString().replace("{", "").replace("}", "")
|
||||
.split(",");
|
||||
|
||||
#ifdef QT_GUI_LIB
|
||||
if (type == QMetaType::QPolygon) {
|
||||
QString p;
|
||||
QString ref = dbValue.toString();
|
||||
QPolygon pol;
|
||||
if (!readInsideParentese(ref, p))
|
||||
return pol;
|
||||
|
||||
ref = p;
|
||||
while (readInsideParentese(ref, p)) {
|
||||
QList<int> l = _serializer->toListInt(p);
|
||||
if (l.count() != 2)
|
||||
return QPolygon();
|
||||
pol.append(QPoint(l.at(0), l.at(1)));
|
||||
}
|
||||
return pol;
|
||||
}
|
||||
if (type == QMetaType::QPolygonF) {
|
||||
QString p;
|
||||
QString ref = dbValue.toString();
|
||||
QPolygonF pol;
|
||||
if (!readInsideParentese(ref, p))
|
||||
return pol;
|
||||
|
||||
ref = p;
|
||||
while (readInsideParentese(ref, p)) {
|
||||
QList<qreal> l = _serializer->toListReal(p);
|
||||
if (l.count() != 2)
|
||||
return QPolygonF();
|
||||
pol.append(QPointF(l.at(0), l.at(1)));
|
||||
}
|
||||
return pol;
|
||||
}
|
||||
#endif
|
||||
return SqlGeneratorBase::readValue(type, dbValue);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@ NUT_BEGIN_NAMESPACE
|
|||
|
||||
class PostgreSqlGenerator : public SqlGeneratorBase
|
||||
{
|
||||
private:
|
||||
bool readInsideParentese(QString &ref, QString &out);
|
||||
|
||||
public:
|
||||
explicit PostgreSqlGenerator(Database *parent = nullptr);
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ class SqlGeneratorBase : public QObject
|
|||
// Q_OBJECT
|
||||
|
||||
Database *_database;
|
||||
protected:
|
||||
SqlSerializer *_serializer;
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -52,8 +52,11 @@ void DataTypesTest::initTestCase()
|
|||
url = QUrl("http://google.com/search?q=nut");
|
||||
|
||||
time = QTime::currentTime();
|
||||
time.setHMS(time.hour(), time.minute(), time.second());
|
||||
|
||||
date = QDate::currentDate();
|
||||
dateTime = QDateTime::currentDateTime();
|
||||
dateTime.setTime(time);
|
||||
|
||||
uuid = QUuid::createUuid();
|
||||
jsonDoc = QJsonDocument::fromJson("{\"a\": 1}");
|
||||
|
|
@ -158,7 +161,6 @@ void DataTypesTest::retrive()
|
|||
QTEST_ASSERT(t->f_jsonArray() == jsonArr);
|
||||
QTEST_ASSERT(t->f_jsonValue() == jsonValue);
|
||||
|
||||
qDebug() << t->f_string() << string;
|
||||
QTEST_ASSERT(t->f_string() == string);
|
||||
QTEST_ASSERT(t->f_stringList() == stringList);
|
||||
QTEST_ASSERT(t->f_qchar() == qchar);
|
||||
|
|
|
|||
Loading…
Reference in New Issue