SQL/MySQL: Fix compilation with MySQL 8.3
With MySQL 8.3 mysql_fetch_field() was removed which was used in QMYSQLDriver::record(). There is no real replacement function so we use 'SELECT * from table LIMIT 0' to retrieve the schema information. Additionally mysql_stmt_bind_param() was deprecated and needs to be replaced by mysql_stmt_bind_named_param(). [ChangeLog][SQL][MySQL] Fixed compilation with MySQL 8.3. Pick-to: 6.6 6.5 6.2 5.15 Fixes: QTBUG-121183 Change-Id: I149836bd5674d0784255baf416d437c424992f20 Reviewed-by: silverqx <silver.zachara@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 41c842d3f7eecdf736d26026427033791586c83a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
d688eab7da
commit
b9bcaae226
@ -919,9 +919,8 @@ bool QMYSQLResult::exec()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mysql_stmt_param_count(d->stmt) > 0 &&
|
const unsigned long paramCount = mysql_stmt_param_count(d->stmt);
|
||||||
mysql_stmt_param_count(d->stmt) == (uint)values.size()) {
|
if (paramCount > 0 && paramCount == static_cast<size_t>(values.size())) {
|
||||||
|
|
||||||
nullVector.resize(values.size());
|
nullVector.resize(values.size());
|
||||||
for (qsizetype i = 0; i < values.size(); ++i) {
|
for (qsizetype i = 0; i < values.size(); ++i) {
|
||||||
const QVariant &val = boundValues().at(i);
|
const QVariant &val = boundValues().at(i);
|
||||||
@ -1003,7 +1002,11 @@ bool QMYSQLResult::exec()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(MARIADB_VERSION_ID) || MYSQL_VERSION_ID < 80300
|
||||||
r = mysql_stmt_bind_param(d->stmt, d->outBinds);
|
r = mysql_stmt_bind_param(d->stmt, d->outBinds);
|
||||||
|
#else
|
||||||
|
r = mysql_stmt_bind_named_param(d->stmt, d->outBinds, paramCount, nullptr);
|
||||||
|
#endif
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
setLastError(qMakeStmtError(QCoreApplication::translate("QMYSQLResult",
|
setLastError(qMakeStmtError(QCoreApplication::translate("QMYSQLResult",
|
||||||
"Unable to bind value"), QSqlError::StatementError, d->stmt));
|
"Unable to bind value"), QSqlError::StatementError, d->stmt));
|
||||||
@ -1472,21 +1475,12 @@ QSqlIndex QMYSQLDriver::primaryIndex(const QString &tablename) const
|
|||||||
|
|
||||||
QSqlRecord QMYSQLDriver::record(const QString &tablename) const
|
QSqlRecord QMYSQLDriver::record(const QString &tablename) const
|
||||||
{
|
{
|
||||||
Q_D(const QMYSQLDriver);
|
|
||||||
const QString table = stripDelimiters(tablename, QSqlDriver::TableName);
|
|
||||||
|
|
||||||
QSqlRecord info;
|
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
return info;
|
return {};
|
||||||
MYSQL_RES *r = mysql_list_fields(d->mysql, table.toUtf8().constData(), nullptr);
|
QSqlQuery i(createResult());
|
||||||
if (!r)
|
QString stmt("SELECT * FROM %1 LIMIT 0"_L1);
|
||||||
return info;
|
i.exec(stmt.arg(escapeIdentifier(tablename, QSqlDriver::TableName)));
|
||||||
|
return i.record();
|
||||||
MYSQL_FIELD *field;
|
|
||||||
while ((field = mysql_fetch_field(r)))
|
|
||||||
info.append(qToField(field));
|
|
||||||
mysql_free_result(r);
|
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant QMYSQLDriver::handle() const
|
QVariant QMYSQLDriver::handle() const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user