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
Forum Updated to NodeBB v4.3 + New Features

QT6 Can't read the OUT parameter from MYSQL Database

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 424 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 25 Oct 2023, 18:30 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?

    C 1 Reply Last reply 25 Oct 2023, 19:22
    0
    • R roditu
      26 Oct 2023, 06:40

      @Christian-Ehrlicher added compilable example

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 26 Oct 2023, 17:55 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 27 Oct 2023, 10:54
      3
      • R roditu
        25 Oct 2023, 18:30

        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?

        C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 25 Oct 2023, 19:22 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 25 Oct 2023, 23:51
        0
        • C Christian Ehrlicher
          25 Oct 2023, 19:22

          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 25 Oct 2023, 23:51 last edited by
          #3

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

          1 Reply Last reply
          0
          • C Christian Ehrlicher
            25 Oct 2023, 19:22

            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 26 Oct 2023, 06:40 last edited by
            #4

            @Christian-Ehrlicher added compilable example

            C 1 Reply Last reply 26 Oct 2023, 17:55
            0
            • R roditu
              26 Oct 2023, 06:40

              @Christian-Ehrlicher added compilable example

              C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 26 Oct 2023, 17:55 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 27 Oct 2023, 10:54
              3
              • C Christian Ehrlicher
                26 Oct 2023, 17:55

                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 27 Oct 2023, 10:54 last edited by
                #6

                @Christian-Ehrlicher thank You very much

                1 Reply Last reply
                0
                • SGaistS SGaist has marked this topic as solved on 27 Oct 2023, 11:24

                1/6

                25 Oct 2023, 18:30

                • Login

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