Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT6 Can't read the OUT parameter from MYSQL Database
Qt 6.11 is out! See what's new in the release blog

QT6 Can't read the OUT parameter from MYSQL Database

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 674 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    roditu
    wrote on last edited by
    #1

    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-values

    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;
        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?

    Christian EhrlicherC 1 Reply Last reply
    0
    • R roditu

      @Christian-Ehrlicher added compilable example

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #5

      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();
      }
      

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      R 1 Reply Last reply
      3
      • R roditu

        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-values

        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;
            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?

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        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.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        R 2 Replies Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          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.

          R Offline
          R Offline
          roditu
          wrote on last edited by
          #3

          @Christian-Ehrlicher https://bugreports.qt.io/browse/QTBUG-118552

          1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            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.

            R Offline
            R Offline
            roditu
            wrote on last edited by
            #4

            @Christian-Ehrlicher added compilable example

            Christian EhrlicherC 1 Reply Last reply
            0
            • R roditu

              @Christian-Ehrlicher added compilable example

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #5

              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();
              }
              

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              R 1 Reply Last reply
              3
              • Christian EhrlicherC Christian Ehrlicher

                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();
                }
                
                R Offline
                R Offline
                roditu
                wrote on last edited by
                #6

                @Christian-Ehrlicher thank You very much

                1 Reply Last reply
                0
                • SGaistS SGaist has marked this topic as solved on

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved