diff options
author | Christian Ehrlicher <[email protected]> | 2023-02-19 16:54:21 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <[email protected]> | 2023-02-28 16:25:31 +0000 |
commit | fb004f0f4431752fe9b166849ac70326c5b47c00 (patch) | |
tree | f69afdebcf12a40f7e8cfdfd6bbd7a1cff7b5a88 | |
parent | 655fdae1235476b43fb9d5bd43d12853ed7008c5 (diff) |
SQL/OCI: Correctly calculate utc offset string when icu is not available
When ICU is not available, QTimeZone::displayName() does not return a
valid timezone offset string so the OCI driver will get a wrong utc
offset string and inserting a QDateTime will go wrong.
Fix it by creating the utc offset string by ourself (toOffsetString()
inside qdatetime.cpp is static and therefore not accessible for us).
Fixes: QTBUG-111275
Change-Id: Ib724d760688614e162246e1e028ee5e004cc9477
Reviewed-by: Volker Hilsheimer <[email protected]>
(cherry picked from commit 6b9977c4adfa0ffd9cb87b4aec288c7a335aef6c)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
-rw-r--r-- | src/plugins/sqldrivers/oci/qsql_oci.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/plugins/sqldrivers/oci/qsql_oci.cpp b/src/plugins/sqldrivers/oci/qsql_oci.cpp index 82bf68143e9..1dc0c811db6 100644 --- a/src/plugins/sqldrivers/oci/qsql_oci.cpp +++ b/src/plugins/sqldrivers/oci/qsql_oci.cpp @@ -131,6 +131,15 @@ public: ~QOCIDateTime(); OCIDateTime *dateTime; static QDateTime fromOCIDateTime(OCIEnv *env, OCIError *err, OCIDateTime *dt); + static QString toOffsetString(const QDateTime &dt) + { + const auto offset = dt.offsetFromUtc(); + const auto offsetAbs = qAbs(offset) / 60; + return QString::asprintf("%c%02d:%02d", + offset >= 0 ? '+' : '-', + offsetAbs / 60, + offsetAbs % 60); + } }; QOCIDateTime::QOCIDateTime(OCIEnv *env, OCIError *err, const QDateTime &dt) @@ -140,8 +149,8 @@ QOCIDateTime::QOCIDateTime(OCIEnv *env, OCIError *err, const QDateTime &dt) if (dt.isValid()) { const QDate date = dt.date(); const QTime time = dt.time(); - // Zone in +hh:mm format (stripping UTC prefix from OffsetName) - QString timeZone = dt.timeZone().displayName(dt, QTimeZone::OffsetName).mid(3); + // Zone in +hh:mm format + const QString timeZone = toOffsetString(dt); const OraText *tz = reinterpret_cast<const OraText *>(timeZone.utf16()); OCIDateTimeConstruct(env, err, dateTime, date.year(), date.month(), date.day(), time.hour(), time.minute(), time.second(), time.msec() * 1000000, |