From 72024244b8b5ba88af5ba0dd5dfc68cc5e1c9027 Mon Sep 17 00:00:00 2001 From: Bill Meek Date: Sun, 16 Apr 2023 23:59:37 -0500 Subject: [PATCH] mythdbcon: force QMetaType::QDateTime values to use MythDate::kDatabase This cares for a recent ibqt5sql5-mysql update in at least one distribution where it isn't removing timezone information from a query causing it to fail. Log example without patch: MSqlQuery::exec(DBManager16) UPDATE recorded SET recgroup = 'Deleted', recgroupid = 3 WHERE chanid = '10901' AND starttime = '2023-04-08T05:00:00.000Z' ; <<<< Took 0ms Log example with patch: MSqlQuery::exec(DBManager1) UPDATE recorded SET recgroup = 'Deleted', recgroupid = 3 WHERE chanid = '10901' AND starttime = '2023-04-07 05:30:00' ; <<<< Took 0ms Results seen by users on the Forum and mailing list. Credits to Mark, Roland and Klaas. See: https://forum.mythtv.org/viewtopic.php?p=25833#p25833 The Debian solution is due 4/31/2023. --- mythtv/libs/libmythbase/mythdbcon.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mythtv/libs/libmythbase/mythdbcon.cpp b/mythtv/libs/libmythbase/mythdbcon.cpp index 33bf128c860..71cb9ed8e7d 100644 --- a/mythtv/libs/libmythbase/mythdbcon.cpp +++ b/mythtv/libs/libmythbase/mythdbcon.cpp @@ -881,6 +881,15 @@ bool MSqlQuery::testDBConnection() void MSqlQuery::bindValue(const QString &placeholder, const QVariant &val) { +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) + if (static_cast(val.type()) == QMetaType::QDateTime) + { + QSqlQuery::bindValue(placeholder, + MythDate::toString(val.toDateTime(), MythDate::kDatabase), + QSql::In); + return; + } +#endif QSqlQuery::bindValue(placeholder, val, QSql::In); } @@ -896,6 +905,15 @@ void MSqlQuery::bindValueNoNull(const QString &placeholder, const QVariant &val) QSqlQuery::bindValue(placeholder, QString(""), QSql::In); return; } +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) + if (type == QMetaType::QDateTime) + { + QSqlQuery::bindValue(placeholder, + MythDate::toString(val.toDateTime(), MythDate::kDatabase), + QSql::In); + return; + } +#endif QSqlQuery::bindValue(placeholder, val, QSql::In); }