Uploaded image for project: 'MariaDB Connector/C'
  1. MariaDB Connector/C
  2. CONC-465

[client] default-character-set does not work

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Not a Bug
    • Affects Version/s: 3.1.7
    • Fix Version/s: N/A
    • Labels:
      None
    • Environment:

      Description

      [client] default-character-set does not work

      Summary

      After switching from MariaDB 10.1.44 to MariaDB 10.3.22 on Debian 10 and on Ubuntu 18.04 using apt packages from MariaDB repository we observed that when using the C-API INSERTS of UTF8 encoded text is silently saved as latin1 encoding.

      • Source C-String is UTF8
      • Target table field has character set utf8mb4
      • mariadb.cnf has [client] default-character-set = utf8mb4

      MariaDB [urldb]> show variables like '%character_set%';
      +--------------------------+----------------------------+
      | Variable_name            | Value                      |
      +--------------------------+----------------------------+
      | character_set_client     | utf8mb4                    |
      | character_set_connection | utf8mb4                    |
      | character_set_database   | utf8mb4                    |
      | character_set_filesystem | binary                     |
      | character_set_results    | utf8mb4                    |
      | character_set_server     | utf8mb4                    |
      | character_set_system     | utf8                       |
      | character_sets_dir       | /usr/share/mysql/charsets/ |
      +--------------------------+----------------------------+
      

      Workaround: Since switch to MariaDB v10.3.22 we have to use mysql_set_character_set() on each connection.

      Code to Reproduce Behaviour

      #define _GNU_SOURCE
      #include <stdlib.h>
      #include <stdio.h>
      #include <mariadb/mysql.h>
       
      #define HANDLE_MYSQL_ERR(MYSQL) \
      if (MYSQL && mysql_errno(MYSQL)) {\
          fprintf(stderr, "DB ERROR(%d) [%s] \"%s\"\n", mysql_errno(MYSQL), mysql_sqlstate(MYSQL), mysql_error(MYSQL));\
          exit(-1);\
      }
       
      /**
       * Compile: gcc -Wall main.c -lmariadb
       * Usage..: a.out <host> <user> <passwd> <db> <port> <unix_socket>
       * Example: $ ./a.out localhost harry 1234 mydb 0 /var/run/mysqld/mysqld.sock
       *          Default charachter set: latin1
       *          New     charachter set: utf8mb4
       */
      int main (int argc, char *argv[])
      {
          /* connect to MariaDB server */
          MYSQL *mysql =  mysql_init(NULL);
          // host, user, passwd, db, unix, port, socket
          if (!mysql_real_connect(mysql, argv[1], argv[2], argv[3], argv[4], atoi(argv[5]), argv[6], 0))
              HANDLE_MYSQL_ERR(mysql);
       
          printf("Default charachter set: %s\n", (char*)mysql_character_set_name(mysql));
          if (!mysql_set_character_set(mysql, "utf8mb4"))
              HANDLE_MYSQL_ERR(mysql);
          printf("New     charachter set: %s\n", (char*)mysql_character_set_name(mysql));
       
          mysql_close(mysql);
          return 0;
      }                                        
      

        Attachments

          Activity

            People

            Assignee:
            georg Georg Richter
            Reporter:
            Olaf Olaf Behrendt
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: