From 211369133cf40b2f522caaff259c19069ed23ca4 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 9 Aug 2021 13:04:45 -0700 Subject: 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 Pick-to: 5.15 6.2 Change-Id: I4a40ccbd3321467a8429fffd1699bc089ba706e6 Reviewed-by: Andy Shaw Reviewed-by: Fabian Vogt --- src/plugins/sqldrivers/mysql/qsql_mysql.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/plugins/sqldrivers') diff --git a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp index 12e15bfc47..5358d6a94e 100644 --- a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp +++ b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp @@ -121,6 +121,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 @@ -1276,8 +1290,7 @@ bool QMYSQLDriver::open(const QString& db, qWarning() << "MySQL: Unable to set the client character set to utf8."; } - 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(); -- cgit v1.2.3