summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2021-08-09 13:04:45 -0700
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-08-10 18:28:10 +0000
commitdde4061f37071b265162ab986d7dc1d3726390a1 (patch)
treefa6b81cec30d73ddfe560d84793b8820a2876706 /src
parentffea4525a591110cbcf414f371f18f4101e063d8 (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>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/sqldrivers/mysql/qsql_mysql.cpp17
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 e76ff8db3a..1cec527037 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<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();