From 0ff64a5b9955e856ccc0edf6d8943a390ccbd348 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Wed, 17 Jul 2024 19:59:59 +0200 Subject: [PATCH] SQL/MySQL: honor schema when retrieving table record Honor the schema when retrieving the table record - otherwise we might end up getting the data for the wrong table (same tablename but wrong schema). Fixes: QTBUG-127129 Task-number: QTBUG-122723 Change-Id: Ia3e9293dbdc77da760dd4d0702104048187fad5f Reviewed-by: Axel Spoerl (cherry picked from commit 920dfb2f443042777ea9547ff7a8beef56e90d92) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/sqldrivers/mysql/qsql_mysql.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp index cfd4931b466..958c542bad5 100644 --- a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp +++ b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp @@ -1508,7 +1508,8 @@ QSqlRecord QMYSQLDriver::record(const QString &tablename) const return r; // no binding of WHERE possible with MySQL // escaping on WHERE clause does not work, so use mysql_real_escape_string() - stmt = "SELECT column_name, column_default FROM information_schema.columns WHERE table_name = '%1'"_L1; + stmt = "SELECT column_name, column_default FROM information_schema.columns WHERE table_schema = '"_L1 + + d->dbName + "' AND table_name = '%1'"_L1; const auto baTableName = tablename.toUtf8(); QVarLengthArray tableNameQuoted(baTableName.size() * 2 + 1); #if defined(MARIADB_VERSION_ID)