Ticket #177 (closed defect: fixed)

Opened 10 months ago

Last modified 9 months ago

utf8: mysql_set_character_set better set names utf8

Reported by: uvi Owned by: smoku
Priority: major Component: storage
Version: 2.1.19 Keywords:
Cc: Tracforge_linkmap:
Blocking: Blocked By:

Description

According to http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html "If you are using the mysql client with auto-reconnect enabled (which is not recommended), it is preferable to use the charset command rather than SET NAMES". It's true.
After some idle storage_mysql.c reconnects with auto-reconnect and libmysql fallback to latin1 instead of utf8.
Solution is to use http://dev.mysql.com/doc/refman/5.0/en/mysql-set-character-set.html, this do set names and also set mysql->charset. After reconnect utf8 preserved.

//mysql_query(conn, "SET NAMES 'utf8'"); 

if (mysql_set_character_set(conn, "utf8")) {
    log_write(drv->st->sm->log, LOG_ERR, "mysql: cannot set character set: %s", mysql_error(conn));
    mysql_close(conn);
    return st_FAILED;
}

Attachments

mysql-utf8.patch (0.9 kB) - added by harry 9 months ago.
use utf8 on reconnect

Change History

Changed 10 months ago by smoku

This function was added in MySQL 5.0.7.

Is there a solution that will work with older (4.x) MySQL versions?

Changed 10 months ago by uvi

I don't know, but may be at least provide solution with #ifdef for 5.x.

Also I found "This function was added in MySQL 4.1.13." (http://dev.mysql.com/doc/refman/4.1/en/mysql-set-character-set.html)

Changed 10 months ago by uvi

I think for 4.0 such problem doesn't exists. This function must be called for 4.1 and greater.

Changed 9 months ago by harry

This bug got me, too.

There is another solution (patch attached), which should also work with 4.0. I've only tested with 5.0.32 though.

How to reproduce:

- set the name of one of your contacts to include special characters.

- connect to your mysql server with the mysql client

- issue

set global interactive_timeout=30;

- restart sm

- wait for the interactive_timeout to expire

- log on to the jabber server

As a work-around add the following to your mysql configuration file:

[jabberd]
default-character-set = utf8

Changed 9 months ago by harry

use utf8 on reconnect

Changed 9 months ago by smoku

  • status changed from new to closed
  • resolution set to fixed

(In [497]) Changed the way UTF-8 is selected on MySQL connection. Fixes #177

Note: See TracTickets for help on using tickets.