File MySQL-remove-the-version-number-checks-in-favor-of-actual.patch of Package libqt4
From c11a4d34321e2d615c22aa068dbb185656e9d6c9 Mon Sep 17 00:00:00 2001
From: Thiago Macieira <thiago.macieira@intel.com>
Date: Mon, 09 Aug 2021 13:04:45 -0700
Subject: [PATCH] MySQL: remove the version number checks in favor of actual functionality
MariaDB library version 3.2 no longer returns the server version in the
10.x range but the library version itself, which is lower than 4.x. That
meant we concluded the server did not support prepared statements.
And because of the lack of prepared statements, all QDateTime
conversions failed, because of the timezone. I don't know if this was
intended or what, but it's a side issue.
[ChangeLog][QtSql][MySQL] Fixed the detection of whether the client and
server support prepared statements. This was caused by the mariadb
connector library reporting its own version numbers (starting in version
3.2) instead of the server version.
Fixes: QTBUG-95071
Change-Id: I4a40ccbd3321467a8429fffd1699bc089ba706e6
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Reviewed-by: Fabian Vogt <fabian@ritter-vogt.de>
(cherry picked from commit 211369133cf40b2f522caaff259c19069ed23ca4)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
---
diff --git a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp
index 554f4d9..ea8a15e 100644
--- a/src/sql/drivers/mysql/qsql_mysql.cpp
+++ b/src/sql/drivers/mysql/qsql_mysql.cpp
@@ -162,6 +162,20 @@
#endif
}
+// check if this client and server version of MySQL/MariaDB support prepared statements
+static inline bool checkPreparedQueries(MYSQL *mysql)
+{
+ bool result = false;
+ MYSQL_STMT *stmt = mysql_stmt_init(mysql);
+ if (stmt) {
+ static const char dummyQuery[] = "SELECT ? + ?";
+ if (mysql_stmt_prepare(stmt, dummyQuery, sizeof(dummyQuery) - 1) == 0)
+ result = mysql_stmt_param_count(stmt) == 2;
+ mysql_stmt_close(stmt);
+ }
+ return result;
+}
+
class QMYSQLResultPrivate : public QObject
{
Q_OBJECT
@@ -1317,8 +1331,7 @@
#endif
#if MYSQL_VERSION_ID >= 40108
- d->preparedQuerysEnabled = mysql_get_client_version() >= 40108
- && mysql_get_server_version(d->mysql) >= 40100;
+ d->preparedQuerysEnabled = checkPreparedQueries(d->mysql);
#else
d->preparedQuerysEnabled = false;
#endif