Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Not a Bug
-
3.1.7
-
None
-
None
-
Windows
Description
With MySQL 6.1.x a call to mysql_options with the attribute MYSQL_SET_CHARSET_NAME and the value MYSQL_AUTODETECT_CHARSET_NAME would result in the connection correctly identifying the client character set.
When using the MariaDB C client 3.1.7 it appears this option is ignored and the client character set remains set to the server character set value.
Test Case
#include <stdio.h>
|
#include <mysql.h>
|
|
#include <windows.h>
|
|
void
|
checkClientCharacterSet(MYSQL* mysql) {
|
mysql_query(mysql, "SHOW SESSION VARIABLES LIKE 'character_set_client'");
|
MYSQL_RES* result = mysql_store_result(mysql);
|
int totalrows = mysql_num_rows(result);
|
int numfields = mysql_num_fields(result);
|
MYSQL_ROW row = mysql_fetch_row(result);
|
fprintf(stdout, "%s \t %s\n", row[0], row[1]);
|
}
|
|
int
|
main(int argc, char *argv[]) {
|
if (argc <2) {
|
fprintf(stderr, "Please enter server host name\n");
|
return 1;
|
}
|
// Set to Windows UTF-8 code page
|
// Note without this using the default code page of 437 the character_set_client will return 'latin1'
|
SetConsoleCP(65001);
|
|
mysql_library_init(0, NULL, NULL);
|
|
MYSQL* mysql_ = mysql_init(NULL);
|
|
//mysql_optionsv(mysql_, MYSQL_SET_CHARSET_NAME, "utf8"); // This works
|
mysql_optionsv(mysql_, MYSQL_SET_CHARSET_NAME, MYSQL_AUTODETECT_CHARSET_NAME);
|
|
if(!mysql_real_connect(mysql_, argv[1], "user", "pass", "db", 3306, NULL, 0)) {
|
fprintf(stderr, "Connection to %s failed\n", argv[1]);
|
mysql_close(mysql_);
|
return 1;
|
}
|
|
checkClientCharacterSet(mysql_);
|
|
mysql_close(mysql_);
|
mysql_library_end();
|
|
return 0;
|
}
|
Output
MySQL 6.1.x
- The following output is observed (when the code page is left to the default of 437):
character_set_client latin1
- The following output is observed (when setting the code page to 65001):
character_set_client utf8
MariaDB 3.1.7
- The following output is observed (when the code page is left to the default of 437):
character_set_client latin1
- The following output is observed (when setting the code page to 65001):
character_set_client latin1