Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-27763

Regression in Qt5 Beta1 in QSqlQuery::bindValue() and bool param - uncorrect binding in some cases

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Not Evaluated
    • 4.8.x, 5.0.0 RC 1
    • 5.0.0 Beta 1
    • SQL Support
    • None
    • Gentoo Linux amd64, GCC 4.7.2.
    • 593b8f7f0b35ddc424d8ccbd5df11fcf2442858e 8efd01e369d9427db38d9f3c524626607f4f114b

    Description

      In some cases QSqlQuery::bindValue() convert bool value to 127.
      How to reproduce:
      1. create table in mysql

      CREATE TABLE `testbug` (
          `id` INT NOT NULL AUTO_INCREMENT,
          `number` INT,
          `flag` BOOL NOT NULL DEFAULT FALSE,
          PRIMARY KEY(`id`))
      ENGINE=InnoDB DEFAULT CHARSET=utf8;
      

      2. compile this code with Qt5 Beta1 and run

      #include <QtSql/QSqlDatabase>
      #include <QtSql/QSqlError>
      #include <QtSql/QSqlQuery>
      #include <QtCore/QVariant>
      
      class Core {
      public:
          void run();
          QSqlDatabase db;
      };
      
      int main()
      {
          Core core;
          core.run();
          return 0;
      }
      
      void Core::run()
      {
          db = QSqlDatabase::addDatabase("QMYSQL");
          db.setDatabaseName("test");
          db.setHostName("localhost");
          if(!db.open()) {
                  qFatal("%s", qPrintable(db.lastError().databaseText()));
                  return;
          }
      
          for(int i = 0; i < 20; ++i) {
              bool flag = i % 2;
              QSqlQuery q;
              q.prepare("INSERT INTO testbug (`number`, `flag`) VALUES(:number, :flag)");
              q.bindValue(":number", i);
              q.bindValue(":flag", !flag);
              if(!q.exec())
                  qWarning("%s:%d %s", Q_FUNC_INFO, __LINE__, qPrintable(q.lastError().text()));
          }
      }
      

      3. In table 'testbug' flag will be "127" in every record like a:

      +----+--------+------+
      | id | number | flag |
      +----+--------+------+
      |  1 |      0 |  127 |
      |  2 |      1 |  127 |
      |  3 |      2 |  127 |
      

      I test it with Qt4.8.2 - all works fine.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            mabrand Mark Brand
            carelesschaser Chaser
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes