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

Qt 6.5.3 QByteArray in MySQL BLOB encoded as if UTF-8

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • Not Evaluated
    • None
    • 6.5.3
    • SQL Support
    • None
    • Qt6.5.3 With MSVC2019(2022)
      MySQL 8.0.40-0ubuntu0.22.04.1
      Windows11 23H2
    • Windows

    Description

      demo code:

      QSqlDatabase database(QSqlDatabase::addDatabase("QMYSQL", "TEST"));    database.setUserName("");
          database.setPassword("");
          database.setPort(3306);
          database.setHostName("");
          database.setDatabaseName("");    QString sql = "insert into sem_image_info (image_format, width, height, image_info, image_data)"
                        " values (? ,? ,? ,?, ?)";    if (!database.open()) {
              qDebug() << "open fail";
              return 0;
          }
          QFile file(
              "");
          if (!file.open(QIODevice::ReadOnly)) {
              qDebug() << "open fail";
              return 0;
          }
          QByteArray array = file.readAll();
          file.close();    QSqlQuery query = database.exec(sql);
          query.bindValue(0, 4);
          query.bindValue(1, 512);
          query.bindValue(2, 512);
          query.bindValue(3, "");
          query.bindValue(4, array);
          if (!query.exec()) {
              qDebug() << "save fail";
              return 0;
          }
          database.close(); 
      
      //SQL:
      CREATE TABLE `image_info` (
        `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '',
        `width` int NOT NULL COMMENT '',
        `height` int NOT NULL COMMENT '',
        `image_format` int NOT NULL COMMENT 'QImage Enum format',
        `image_info` mediumtext COLLATE utf8mb4_general_ci COMMENT 'extra info',
        `image_data` longblob COMMENT 'bin data',
        `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '',
        `edit_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '',
        `deleted` tinyint NOT NULL DEFAULT '0' COMMENT '1 - deleted',
        PRIMARY KEY (`id`)
      ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='';

       

      After saving and checking the database field, I found that the saved data does not match the expected result. After comparing the data, it seems that the binary data was forcibly encoded as UTF-8. I am unsure whether this is an issue with MySQL itself or with Qt's plugin, so I am asking here.

       

      I have tried it on 6.8.1 version on different computer, it still not work (uninstall full qt package and re-install in this computer):
      The size of the saved data is 1,048,576 bytes. The extracted bytes are different from version 6.5.3, and version 6.8.1 is larger, with 2,602,378 bytes. I remember version 6.5.3 being around 25xxxx bytes (the computer with 6.5.3 is at the office, and I have already left work).

       

      addition info:
      MySQL 8.0.40-0ubuntu0.22.04.1
      MySQL driver: 8.0.37
      Qt 6.5.3 with msvc 2019(2022)
      Qt 6.8.1 with msvc 2022

      Attachments

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

        Activity

          People

            chehrlic Christian Ehrlicher
            shisan Shisan xing
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes