@@ -61,6 +61,7 @@ class QMYSQLDriverPrivate : public QSqlDriverPrivate
6161 QMYSQLDriverPrivate () : QSqlDriverPrivate(QSqlDriver::MySqlServer)
6262 {}
6363 MYSQL *mysql = nullptr ;
64+ QString dbName;
6465 bool preparedQuerysEnabled = false ;
6566};
6667
@@ -859,9 +860,9 @@ bool QMYSQLResult::prepare(const QString& query)
859860 return false ;
860861 }
861862
862- if ( mysql_stmt_param_count (d->stmt ) > 0 ) { // allocate memory for outvalues
863- d-> outBinds = new MYSQL_BIND[ mysql_stmt_param_count (d-> stmt )];
864- }
863+ const auto paramCount = mysql_stmt_param_count (d->stmt );
864+ if (paramCount > 0 ) // allocate memory for outvalues
865+ d-> outBinds = new MYSQL_BIND[paramCount]();
865866
866867 setSelect (d->bindInValues ());
867868 d->preparedQuery = true ;
@@ -1322,6 +1323,7 @@ bool QMYSQLDriver::open(const QString &db,
13221323 }
13231324
13241325 d->preparedQuerysEnabled = checkPreparedQueries (d->mysql );
1326+ d->dbName = db;
13251327
13261328#if QT_CONFIG(thread)
13271329 mysql_thread_init ();
@@ -1341,6 +1343,7 @@ void QMYSQLDriver::close()
13411343#endif
13421344 mysql_close (d->mysql );
13431345 d->mysql = nullptr ;
1346+ d->dbName .clear ();
13441347 setOpen (false );
13451348 setOpenError (false );
13461349 }
@@ -1357,14 +1360,14 @@ QStringList QMYSQLDriver::tables(QSql::TableType type) const
13571360 QStringList tl;
13581361 QSqlQuery q (createResult ());
13591362 if (type & QSql::Tables) {
1360- QString sql = " select table_name from information_schema.tables where table_schema = '" _L1 + QLatin1StringView ( d->mysql -> db ) + " ' and table_type = 'BASE TABLE'" _L1;
1363+ QString sql = " select table_name from information_schema.tables where table_schema = '" _L1 + d->dbName + " ' and table_type = 'BASE TABLE'" _L1;
13611364 q.exec (sql);
13621365
13631366 while (q.next ())
13641367 tl.append (q.value (0 ).toString ());
13651368 }
13661369 if (type & QSql::Views) {
1367- QString sql = " select table_name from information_schema.tables where table_schema = '" _L1 + QLatin1StringView ( d->mysql -> db ) + " ' and table_type = 'VIEW'" _L1;
1370+ QString sql = " select table_name from information_schema.tables where table_schema = '" _L1 + d->dbName + " ' and table_type = 'VIEW'" _L1;
13681371 q.exec (sql);
13691372
13701373 while (q.next ())
0 commit comments