summaryrefslogtreecommitdiffstats
path: root/src/plugins/sqldrivers/mysql/qsql_mysql.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2021-08-09 13:04:45 -0700
committerThiago Macieira <thiago.macieira@intel.com>2021-08-10 10:43:03 -0700
commit211369133cf40b2f522caaff259c19069ed23ca4 (patch)
tree70babf1ea272bd1e4a0176b725c2739a3282a396 /src/plugins/sqldrivers/mysql/qsql_mysql.cpp
parentd055abd1958879ff1775772cfb0d5039e975fe9c (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 Pick-to: 5.15 6.2 Change-Id: I4a40ccbd3321467a8429fffd1699bc089ba706e6 Reviewed-by: Andy Shaw <andy.shaw@qt.io> Reviewed-by: Fabian Vogt <fabian@ritter-vogt.de>
Diffstat (limited to 'src/plugins/sqldrivers/mysql/qsql_mysql.cpp')
-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 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<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();