summaryrefslogtreecommitdiffstats
path: root/src/plugins/sqldrivers/mysql/qsql_mysql.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/sqldrivers/mysql/qsql_mysql.cpp')
-rw-r--r--src/plugins/sqldrivers/mysql/qsql_mysql.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp
index 5358d6a94e..ed304d807d 100644
--- a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp
+++ b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp
@@ -1465,6 +1465,20 @@ QString QMYSQLDriver::formatValue(const QSqlField &field, bool trimStrings) cons
qWarning("QMYSQLDriver::formatValue: Database not open");
}
Q_FALLTHROUGH();
+ case QMetaType::QDateTime:
+ if (QDateTime dt = field.value().toDateTime(); dt.isValid()) {
+ // MySQL format doesn't like the "Z" at the end, but does allow
+ // "+00:00" starting in version 8.0.19. However, if we got here,
+ // it's because the MySQL server is too old for prepared queries
+ // in the first place, so it won't understand timezones either.
+ // Besides, MYSQL_TIME does not support timezones, so match it.
+ r = QLatin1Char('\'') +
+ dt.date().toString(Qt::ISODate) +
+ QLatin1Char('T') +
+ dt.time().toString(Qt::ISODate) +
+ QLatin1Char('\'');
+ }
+ break;
default:
r = QSqlDriver::formatValue(field, trimStrings);
}