QT6 C++ Obtaining value from SQL Procedure OUT parameter

44 views Asked by At

I'm having method in c++:

bool User::checkCredentials(){

    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.addBindValue(login);
    query.addBindValue(password);
    query.addBindValue(isValid, QSql::Out);

    if(query.exec()){
        isValid = query.boundValue(2).toBool();
        qInfo() << isValid;
    }

    else{
        qWarning() << "Failed to execute validate_credentials: " << query.lastError().text();
    }

    return isValid;
}

And a very simple procedure in SQL:

CREATE PROCEDURE validate_credentials(IN in_login VARCHAR(20), IN in_password VARCHAR(20), INOUT out_is_valid BOOLEAN)
BEGIN
SET out_is_valid = TRUE;
END;

The problem is that the isValid always prints false even though I'm literally setting it to true. Also won't work if argument is just OUT.

I tried to solve the problem on my own of course and I ran out of options, this c++ code that You see is literally as QT's documentation suggests. Of course, probably I made a mistake somewhere, or I'm missing something, but I can't figure out what.

Documentation I checked: https://doc.qt.io/qt-5/qsqlquery.html#approaches-to-binding-values

0

There are 0 answers