remove the version number checks in favor of actual functionality
authorDebian Qt/KDE Maintainers <debian-qt-kde@lists.debian.org>
Fri, 1 Jul 2022 19:49:23 +0000 (20:49 +0100)
committerDmitry Shachnev <mitya57@debian.org>
Fri, 1 Jul 2022 19:49:23 +0000 (20:49 +0100)
Origin: upstream, https://code.qt.io/cgit/qt/qtbase.git/commit/?id=211369133cf40b2f
Last-Update: 2021-08-10

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.

Gbp-Pq: Name mysql_remove_version_checks.diff

src/plugins/sqldrivers/mysql/qsql_mysql.cpp

index a641935dc557979c0425d205c26f656f570a4ec8..7ca055eea24a979d0b2f2a9776649b3f5a2a1b19 100644 (file)
@@ -158,6 +158,20 @@ static inline QVariant qDateTimeFromString(QString &val)
 #endif
 }
 
+// check if this client and server version of MySQL/MariaDB support prepared statements
+static inline bool checkPreparedQueries(MYSQL *mysql)
+{
+    std::unique_ptr<MYSQL_STMT, decltype(&mysql_stmt_close)> stmt(mysql_stmt_init(mysql), &mysql_stmt_close);
+    if (!stmt)
+        return false;
+
+    static const char dummyQuery[] = "SELECT ? + ?";
+    if (mysql_stmt_prepare(stmt.get(), dummyQuery, sizeof(dummyQuery) - 1))
+        return false;
+
+    return mysql_stmt_param_count(stmt.get()) == 2;
+}
+
 class QMYSQLResultPrivate;
 
 class QMYSQLResult : public QSqlResult
@@ -1371,8 +1385,7 @@ bool QMYSQLDriver::open(const QString& db,
     }
 #endif  // MYSQL_VERSION_ID >= 50007
 
-    d->preparedQuerysEnabled = mysql_get_client_version() >= 40108
-                        && mysql_get_server_version(d->mysql) >= 40100;
+    d->preparedQuerysEnabled = checkPreparedQueries(d->mysql);
 
 #if QT_CONFIG(thread)
     mysql_thread_init();