From f8ba3147d05ff56bfd888b69b85b1efb2ced040e Mon Sep 17 00:00:00 2001 From: Debian Qt/KDE Maintainers Date: Fri, 1 Jul 2022 20:49:23 +0100 Subject: [PATCH] remove the version number checks in favor of actual functionality 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 | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp index a641935dc..7ca055eea 100644 --- a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp +++ b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp @@ -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 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(); -- 2.30.2