[CONC-465] [client] default-character-set does not work Created: 2020-03-27 Updated: 2020-03-28 Resolved: 2020-03-27 |
|
| Status: | Closed |
| Project: | MariaDB Connector/C |
| Component/s: | None |
| Affects Version/s: | 3.1.7 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Olaf Behrendt | Assignee: | Georg Richter |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Linux 4.15.0-91-generic #92-Ubuntu SMP Fri Feb 28 11:09:48 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux |
||
| Description |
| Comments |
| Comment by Georg Richter [ 2020-03-27 ] | ||||||||
|
The default character set in Connector/C is latin1 unless you build it with cmake option -DDEFAULT_CHARSET=another_charset. Entries in configuration file have no effect, unless you force Connector/C to read the configuration. From MariaDB Connector/C documentation: MYSQL_READ_DEFAULT_FILE | ||||||||
| Comment by Olaf Behrendt [ 2020-03-28 ] | ||||||||
|
Dear @georg, thank you for your immediate reply! You are absolutely right, we have to explicitly call mysql_optionsv() in order to enable parsing of config files. This is also documented in Configuring MariaDB Connector/C with Option Files. Nevertheless the fact that reading config file options by C-client library is not done by default, seems counter-intuitive to me. That's probably the reason I did not read the documentation intensely enough. I try to do better next time | ||||||||
| Comment by Olaf Behrendt [ 2020-03-28 ] | ||||||||
|
In order to test MYSQL_READ_DEFAULT_FILE I modified my little test program (see above) by adding immediately after mysql_init() (as documented here):
When running the modified a.out program I get
Same result after I copied /etc/mysql/my.cnf to ~/.my.cnf, So seemingly setting mysql_optionsv(mysql, MYSQL_READ_DEFAULT_FILE, NULL) did not change the default client character set. I also double checked by copying my.cnf to the current working directory (where a.out test program is located) and re-compiled and ran a.out with mysql_optionsv(mysql, MYSQL_READ_DEFAULT_FILE, "my.cnf"). That means I expect my.cnf in the current working directory to be read. And voila, now the output is as expected:
To check the default location of config files I ran mysql --help --verbose (see Configuring MariaDB with Option Files:
.h2 Summary
Should I open a new ticket, or did I overlook anything in the documentation or other? | ||||||||
| Comment by Georg Richter [ 2020-03-28 ] | ||||||||
|
You're right - thats a bug in documentation (already fixed). You need to pass NULL pointer or empty string to MYSQL_READ_DEFAULT_GROUP, not to MYSQL_READ_DEFAULT_FILE. Reading configuration file is not enabled by default (also not in libmysql). Consider you have several configuration files, which contain a server section only. Now for every single connect the client library needs to search for various configuration files at different places and process these files. This wouldn't be effective nor performant. | ||||||||
| Comment by Olaf Behrendt [ 2020-03-28 ] | ||||||||
|
Yes, MYSQL_READ_DEFAULT_GROUP worked as expected. Thanks, your feedback is much appreciated! |