QT6 Can't read the OUT parameter from MYSQL Database
-
Hi I have MYSQL Database on Azure, I made a simple Procedure with OUT Parameter and c++ method exactly as documentation instructed me:
https://doc.qt.io/qt-5/qsqlquery.html#approaches-to-binding-valuesCREATE PROCEDURE validate_credentials(IN in_login VARCHAR(20), IN in_password VARCHAR(20), INOUT out_is_valid BOOLEAN) BEGIN SET out_is_valid = TRUE; SELECT TRUE INTO out_is_valid; END;
All it does is set the out_is_valid to TRUE, and it doesn't matter if it's OUT or INOUT in c++ or mysql it won't work regardless.
{ QSqlQuery query{}; bool isValid{false}; //validate_credentials(IN in_login VARCHAR(20), IN in_password VARCHAR(20), OUT out_is_valid BOOLEAN) query.prepare("CALL validate_credentials(?, ?, ?)"); query.bindValue(0, login); query.bindValue(1, password); query.bindValue(2, QVariant(false), QSql::InOut); if(query.exec()){ isValid = query.boundValue(2).toBool(); qInfo() << isValid; } else{ qWarning() << "Failed to execute validate_credentials: " << query.lastError().text(); } return isValid; }
The problem is that it doesn't change the binded OUT parameter, so if it's value like in here it stays as false after reading (in qInfo() << isValid it prints false instead of true).
I truly don't understand why this is wrong, is QT like bugged lol?
-
I had some time and found the reason: https://doc.qt.io/qt-6/sql-driver.html#qmysql-for-mysql-or-mariadb-5-6-and-higher
q.prepare("CALL validate_credentials(?, ?, @outval1)"); q.bindValue(0, "login"); q.bindValue(1, "password"); if (!q.exec()) { qDebug() << q.lastError(); return 1; } if (q.exec("select @outval1")) { if (q.next()) { bool isValid = q.value(0).toBool(); qInfo() << isValid; } } else { qWarning() << "Failed to execute validate_credentials: " << q.lastError().text(); }
-
Can you please fill a bug report with a minimal, compilable example? I can't find a good explanation why it does not work (or even how it was supposed to work) and need some time to investigate. Please also post a link to the bug report here.
-
-
@Christian-Ehrlicher added compilable example
-
I had some time and found the reason: https://doc.qt.io/qt-6/sql-driver.html#qmysql-for-mysql-or-mariadb-5-6-and-higher
q.prepare("CALL validate_credentials(?, ?, @outval1)"); q.bindValue(0, "login"); q.bindValue(1, "password"); if (!q.exec()) { qDebug() << q.lastError(); return 1; } if (q.exec("select @outval1")) { if (q.next()) { bool isValid = q.value(0).toBool(); qInfo() << isValid; } } else { qWarning() << "Failed to execute validate_credentials: " << q.lastError().text(); }
-
@Christian-Ehrlicher thank You very much
-
S SGaist has marked this topic as solved on