summaryrefslogtreecommitdiffstats
path: root/src/plugins/sqldrivers/psql
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2024-03-13 19:56:04 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2024-03-15 12:42:36 +0100
commitf813b76fb2b4189fc18d0b5a75faf1eea2bb1de2 (patch)
tree284f90ea23c1d0ae71fab115f3a39733e7207532 /src/plugins/sqldrivers/psql
parentf76af5f78c8a6eeb8966f045a678cb1cc74e6052 (diff)
SQL/PostgreSQL: cleanup usage of QT_CONFIG(datestring)
Creating a QString from a QDate/QTime works even when QT_CONFIG(datestring) is not defined, so no need to ifdef it out. Pick-to: 6.7 Change-Id: Ib3594036f309393b612d3fbf21f51be9c36a9391 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/plugins/sqldrivers/psql')
-rw-r--r--src/plugins/sqldrivers/psql/qsql_psql.cpp39
1 files changed, 15 insertions, 24 deletions
diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp
index 348e8c30d0..76e3d427b0 100644
--- a/src/plugins/sqldrivers/psql/qsql_psql.cpp
+++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp
@@ -641,23 +641,18 @@ QVariant QPSQLResult::data(int i)
}
return dbl;
}
- case QMetaType::QDate:
#if QT_CONFIG(datestring)
+ case QMetaType::QDate:
return QVariant(QDate::fromString(QString::fromLatin1(val), Qt::ISODate));
-#else
- return QVariant(QString::fromLatin1(val));
-#endif
case QMetaType::QTime:
-#if QT_CONFIG(datestring)
return QVariant(QTime::fromString(QString::fromLatin1(val), Qt::ISODate));
-#else
- return QVariant(QString::fromLatin1(val));
-#endif
case QMetaType::QDateTime:
-#if QT_CONFIG(datestring)
return QVariant(QDateTime::fromString(QString::fromLatin1(val),
Qt::ISODate).toLocalTime());
#else
+ case QMetaType::QDate:
+ case QMetaType::QTime:
+ case QMetaType::QDateTime:
return QVariant(QString::fromLatin1(val));
#endif
case QMetaType::QByteArray: {
@@ -1437,32 +1432,28 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const
r = nullStr();
} else {
switch (field.metaType().id()) {
- case QMetaType::QDateTime:
-#if QT_CONFIG(datestring)
- if (field.value().toDateTime().isValid()) {
+ case QMetaType::QDateTime: {
+ const auto dt = field.value().toDateTime();
+ if (dt.isValid()) {
// we force the value to be considered with a timezone information, and we force it to be UTC
// this is safe since postgresql stores only the UTC value and not the timezone offset (only used
// while parsing), so we have correct behavior in both case of with timezone and without tz
r = QStringLiteral("TIMESTAMP WITH TIME ZONE ") + u'\'' +
- QLocale::c().toString(field.value().toDateTime().toUTC(), u"yyyy-MM-ddThh:mm:ss.zzz") +
+ QLocale::c().toString(dt.toUTC(), u"yyyy-MM-ddThh:mm:ss.zzz") +
u'Z' + u'\'';
} else {
r = nullStr();
}
-#else
- r = nullStr();
-#endif // datestring
break;
- case QMetaType::QTime:
-#if QT_CONFIG(datestring)
- if (field.value().toTime().isValid()) {
- r = u'\'' + field.value().toTime().toString(u"hh:mm:ss.zzz") + u'\'';
- } else
-#endif
- {
+ }
+ case QMetaType::QTime: {
+ const auto t = field.value().toTime();
+ if (t.isValid())
+ r = u'\'' + QLocale::c().toString(t, u"hh:mm:ss.zzz") + u'\'';
+ else
r = nullStr();
- }
break;
+ }
case QMetaType::QString:
r = QSqlDriver::formatValue(field, trimStrings);
if (d->hasBackslashEscape)