diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2021-08-09 13:04:45 -0700 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-08-10 19:34:15 +0000 |
commit | c11a4d34321e2d615c22aa068dbb185656e9d6c9 (patch) | |
tree | 88fd13b67c6f483db8190d5263490e4493d4bbe4 | |
parent | 4ba1faef68679cedecab64aaa78778fd660802b8 (diff) |
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>
-rw-r--r-- | src/plugins/sqldrivers/mysql/qsql_mysql.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp index 554f4d91a4..ea8a15ebfb 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<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 @@ -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(); |