diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-12-03 15:31:07 +0000 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-12-06 20:16:17 +0000 |
commit | d69a4e95b1a30a505e70000305213b6727b85630 (patch) | |
tree | 9929d238ecc70a425045f656327352e450b3e5fd /src/plugins/sqldrivers | |
parent | 6f542f19bfe7bf3c0729f33d163841fbb6f169e7 (diff) |
Revert "Don't allocate an OCIDateTime object unless we're going to use it"
This reverts commit 064c3d35e6809672323e8d912e9140ddd0ad48cd.
Reason for revert: Causes crashes on querying. Better to endure the non-NULL representations of null QDateTime values.
Change-Id: I33dd3b95ab35d8e3accb864aec13d21764b1270d
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'src/plugins/sqldrivers')
-rw-r--r-- | src/plugins/sqldrivers/oci/qsql_oci.cpp | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/src/plugins/sqldrivers/oci/qsql_oci.cpp b/src/plugins/sqldrivers/oci/qsql_oci.cpp index b395c41d0f..5ba862f430 100644 --- a/src/plugins/sqldrivers/oci/qsql_oci.cpp +++ b/src/plugins/sqldrivers/oci/qsql_oci.cpp @@ -168,27 +168,16 @@ public: QOCIDateTime::QOCIDateTime(OCIEnv *env, OCIError *err, const QDateTime &dt) : dateTime(nullptr) { - if (!dt.isValid()) { - // nothing to do, leave dateTime null - } else if (OCIDescriptorAlloc(env, reinterpret_cast<void**>(&dateTime), - OCI_DTYPE_TIMESTAMP_TZ, 0, 0) == OCI_SUCCESS) { - Q_ASSERT(!dt.isNull()); + OCIDescriptorAlloc(env, reinterpret_cast<void**>(&dateTime), OCI_DTYPE_TIMESTAMP_TZ, 0, 0); + if (dt.isValid()) { const QDate date = dt.date(); - Q_ASSERT(date.isValid()); const QTime time = dt.time(); - Q_ASSERT(time.isValid()); // Zone in +hh:mm format (stripping UTC prefix from OffsetName) - QString timeZone = dt.timeZone().displayName(dt, QTimeZone::OffsetName); - Q_ASSERT(timeZone.startsWith(u"UTC")); - timeZone = std::move(timeZone).sliced(3); + QString timeZone = dt.timeZone().displayName(dt, QTimeZone::OffsetName).mid(3); const OraText *tz = reinterpret_cast<const OraText *>(timeZone.utf16()); - if (OCIDateTimeConstruct(env, err, dateTime, date.year(), date.month(), date.day(), - time.hour(), time.minute(), time.second(), time.msec() * 1000000, - const_cast<OraText *>(tz), timeZone.length() * sizeof(QChar))) { - qWarning("QOCIDateTime: Failed to construct the OCIDateTime descriptor"); - } - } else { - qWarning("QOCIDateTime: Failed to allocate the OCIDateTime descriptor"); + OCIDateTimeConstruct(env, err, dateTime, date.year(), date.month(), date.day(), time.hour(), + time.minute(), time.second(), time.msec() * 1000000, + const_cast<OraText *>(tz), timeZone.length() * sizeof(QChar)); } } @@ -200,9 +189,6 @@ QOCIDateTime::~QOCIDateTime() QDateTime QOCIDateTime::fromOCIDateTime(OCIEnv *env, OCIError *err, OCIDateTime *dateTime) { - if (!dateTime) - return QDateTime(); - sb2 year; ub1 month, day, hour, minute, second; ub4 nsec; @@ -951,8 +937,7 @@ QOCICols::QOCICols(int size, QOCIResultPrivate* dp) switch (ofi.type.id()) { case QMetaType::QDateTime: - r = OCIDescriptorAlloc(d->env, static_cast<void **>(&fieldInf[idx].dataPtr), - OCI_DTYPE_TIMESTAMP_TZ, 0, 0); + r = OCIDescriptorAlloc(d->env, (void **)&fieldInf[idx].dataPtr, OCI_DTYPE_TIMESTAMP_TZ, 0, 0); if (r != OCI_SUCCESS) { qWarning("QOCICols: Unable to allocate the OCIDateTime descriptor"); break; |