summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2023-02-19 16:54:21 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-02-28 15:27:56 +0000
commit965c8da456acf1819170203e2726f11ce5df1d72 (patch)
tree06506ec66d453f8f86642e3b574dd369dcb820b3
parentc4c7bebb6ae18388f67f0c7b015ecb975177b7a7 (diff)
downloadqtbase-965c8da456acf1819170203e2726f11ce5df1d72.tar.gz
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 <volker.hilsheimer@qt.io> (cherry picked from commit 6b9977c4adfa0ffd9cb87b4aec288c7a335aef6c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/plugins/sqldrivers/oci/qsql_oci.cpp13
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 82bf68143e..1dc0c811db 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,