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

haven't check result of function mysql_set_character_set

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 6.0.0
    • 5.13.0 RC 3
    • SQL Support
    • None
    • All

    Description

      In file qsql_mysql.cpp, the function open has code:

          if (mysql_get_client_version() >= 50503 && mysql_get_server_version(d->mysql) >= 50503) {
              // force the communication to be utf8mb4 (only utf8mb4 supports 4-byte characters)
              mysql_set_character_set(d->mysql, "utf8mb4");
      #if QT_CONFIG(textcodec)
              d->tc = QTextCodec::codecForName("UTF-8");
      #endif
          } else
          {
              // force the communication to be utf8
              mysql_set_character_set(d->mysql, "utf8");
      #if QT_CONFIG(textcodec)
              d->tc = codec(d->mysql);
      #endif
          }
      

      On my computer, the function call "mysql_set_character_set(d->mysql, "utf8mb4");" is failed, but d->tc is still set to '"UTF-8", which cause charaster_set error.

      I have modified the source code like this and it works fine to me :

      // Some comments here
       // force the communication to be utf8mb4 (only utf8mb4 supports 4-byte characters)
              int ret = mysql_set_character_set(d->mysql, "utf8mb4");
              if (0 != ret)
              {
                  //  try utf8 if utf8mb4 failed
                  ret = mysql_set_character_set(d->mysql, "utf8");
              }
      
      #if QT_CONFIG(textcodec)
              if (0 != ret)
              {
                  d->tc = QTextCodec::codecForName("UTF-8");
              }
              else
              {
                  d->tc = codec(d->mysql);
              }
      #endif
      

      Attachments

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

        Activity

          People

            mabrand Mark Brand
            moral Minghao Wang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes