SQL/MySQL: fix QSqlDatabase::tables() with MySQL 8.0.x
The (undocumented) struct MYSQL returned by mysql_real_connect() no longer stores the db name in MYSQL.db but something else. This leads to a wrong select statement within QMYSQLDriver::tables(). Therefore store the current database name in QMYSQLDriverPrivate to be able to use it in tables() later on. Pick-to: 6.5 6.2 5.15 Change-Id: I27d3345dd44a0d8642ca120cddc5c151b8bed85d Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
6852627777
commit
3b2c09a13c
@ -61,6 +61,7 @@ public:
|
|||||||
QMYSQLDriverPrivate() : QSqlDriverPrivate(QSqlDriver::MySqlServer)
|
QMYSQLDriverPrivate() : QSqlDriverPrivate(QSqlDriver::MySqlServer)
|
||||||
{}
|
{}
|
||||||
MYSQL *mysql = nullptr;
|
MYSQL *mysql = nullptr;
|
||||||
|
QString dbName;
|
||||||
bool preparedQuerysEnabled = false;
|
bool preparedQuerysEnabled = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1342,6 +1343,7 @@ bool QMYSQLDriver::open(const QString &db,
|
|||||||
}
|
}
|
||||||
|
|
||||||
d->preparedQuerysEnabled = checkPreparedQueries(d->mysql);
|
d->preparedQuerysEnabled = checkPreparedQueries(d->mysql);
|
||||||
|
d->dbName = db;
|
||||||
|
|
||||||
#if QT_CONFIG(thread)
|
#if QT_CONFIG(thread)
|
||||||
mysql_thread_init();
|
mysql_thread_init();
|
||||||
@ -1361,6 +1363,7 @@ void QMYSQLDriver::close()
|
|||||||
#endif
|
#endif
|
||||||
mysql_close(d->mysql);
|
mysql_close(d->mysql);
|
||||||
d->mysql = nullptr;
|
d->mysql = nullptr;
|
||||||
|
d->dbName.clear();
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
setOpenError(false);
|
setOpenError(false);
|
||||||
}
|
}
|
||||||
@ -1377,14 +1380,14 @@ QStringList QMYSQLDriver::tables(QSql::TableType type) const
|
|||||||
QStringList tl;
|
QStringList tl;
|
||||||
QSqlQuery q(createResult());
|
QSqlQuery q(createResult());
|
||||||
if (type & QSql::Tables) {
|
if (type & QSql::Tables) {
|
||||||
QString sql = "select table_name from information_schema.tables where table_schema = '"_L1 + QLatin1StringView(d->mysql->db) + "' and table_type = 'BASE TABLE'"_L1;
|
QString sql = "select table_name from information_schema.tables where table_schema = '"_L1 + d->dbName + "' and table_type = 'BASE TABLE'"_L1;
|
||||||
q.exec(sql);
|
q.exec(sql);
|
||||||
|
|
||||||
while (q.next())
|
while (q.next())
|
||||||
tl.append(q.value(0).toString());
|
tl.append(q.value(0).toString());
|
||||||
}
|
}
|
||||||
if (type & QSql::Views) {
|
if (type & QSql::Views) {
|
||||||
QString sql = "select table_name from information_schema.tables where table_schema = '"_L1 + QLatin1StringView(d->mysql->db) + "' and table_type = 'VIEW'"_L1;
|
QString sql = "select table_name from information_schema.tables where table_schema = '"_L1 + d->dbName + "' and table_type = 'VIEW'"_L1;
|
||||||
q.exec(sql);
|
q.exec(sql);
|
||||||
|
|
||||||
while (q.next())
|
while (q.next())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user