SQL/PostgreSQL: fix comment for formatting QDateTime

The comment to convert a QDateTime to a PostgreSQL compatible string was
outdated. Adjust it to the current state and make clear that the
PostgreSQL documentation is unclear here.

Task-number: QTBUG-129983
Change-Id: I46e45082f2154881ab34278c5e9887cb2274dd64
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
(cherry picked from commit d6a7e51fa36c51a39c609ff0b2cd8bc10bd01e86)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Christian Ehrlicher 2024-10-18 18:30:38 +02:00 committed by Qt Cherry-pick Bot
parent 97d342f0c4
commit df1118b4e0

View File

@ -1454,9 +1454,9 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const
case QMetaType::QDateTime: { case QMetaType::QDateTime: {
const auto dt = field.value().toDateTime(); const auto dt = field.value().toDateTime();
if (dt.isValid()) { if (dt.isValid()) {
// we force the value to be considered with a timezone information, and we force it to be UTC // even though the documentation (https://www.postgresql.org/docs/current/datatype-datetime.html)
// this is safe since postgresql stores only the UTC value and not the timezone offset (only used // states that any time zone indication for 'timestamp without tz' columns will be ignored,
// while parsing), so we have correct behavior in both case of with timezone and without tz // it is stored as the correct utc timestamp - so we can pass the utc offset here
r = QStringLiteral("TIMESTAMP WITH TIME ZONE ") + u'\'' + r = QStringLiteral("TIMESTAMP WITH TIME ZONE ") + u'\'' +
dt.toOffsetFromUtc(dt.offsetFromUtc()).toString(Qt::ISODateWithMs) + u'\''; dt.toOffsetFromUtc(dt.offsetFromUtc()).toString(Qt::ISODateWithMs) + u'\'';
} else { } else {