From ef6d7c9af4883068724878eb08ef92126ed17d39 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 21 Jan 2024 17:21:38 +0100 Subject: [PATCH] SQL/ODBC: convert QVariant to QDateTime only once ... instead three times in a row. Change-Id: If08b4c092cfb5b7d224f9a94afb7d395ce2b2eca Reviewed-by: Axel Spoerl (cherry picked from commit efd6786e52639ef1ceab819265b0c33d7ef8294e) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/sqldrivers/odbc/qsql_odbc.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp index 2cd57f3f415..fb1ed75deb4 100644 --- a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp +++ b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp @@ -2521,9 +2521,10 @@ QString QODBCDriver::formatValue(const QSqlField &field, r = "NULL"_L1; } else if (field.metaType().id() == QMetaType::QDateTime) { // Use an escape sequence for the datetime fields - if (field.value().toDateTime().isValid()){ - QDate dt = field.value().toDateTime().date(); - QTime tm = field.value().toDateTime().time(); + const QDateTime dateTime = field.value().toDateTime(); + if (dateTime.isValid()) { + const QDate dt = dateTime.date(); + const QTime tm = dateTime.time(); // Dateformat has to be "yyyy-MM-dd hh:mm:ss", with leading zeroes if month or day < 10 r = "{ ts '"_L1 + QString::number(dt.year()) + u'-' +