mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV-26713 set console codepage to what user set in --default-character-set
If someone on whatever reasons uses --default-character-set=cp850, this will avoid incorrect display, and inserting incorrect data. Adjusting console codepage sometimes also needs to happen with --default-charset=auto, on older Windows. This is because autodetection is not always exact. For example, console codepage on US editions of Windows is 437. Client autodetects it as cp850, a rather loose approximation, given 46 code point differences. We change the console codepage to cp850, so that there is no discrepancy. That fix is currently Windows-only, and serves people who used combination of chcp to achieve WYSIWYG effect (although, this would mostly likely used with utf8 in the past) Now, --default-character-set would be a replacement for that. Fix fs_character_set() detection of current codepage.
This commit is contained in:
committed by
Sergei Golubchik
parent
74f2e6c85e
commit
9ea83f7fbd
@@ -3304,6 +3304,21 @@ com_clear(String *buffer,char *line __attribute__((unused)))
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void adjust_console_codepage(const char *name __attribute__((unused)))
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (my_set_console_cp(name) < 0)
|
||||
{
|
||||
char buf[128];
|
||||
snprintf(buf, sizeof(buf),
|
||||
"WARNING: Could not determine Windows codepage for charset '%s',"
|
||||
"continue using codepage %u", name, GetConsoleOutputCP());
|
||||
put_info(buf, INFO_INFO);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* ARGSUSED */
|
||||
static int
|
||||
com_charset(String *buffer __attribute__((unused)), char *line)
|
||||
@@ -3325,6 +3340,7 @@ com_charset(String *buffer __attribute__((unused)), char *line)
|
||||
mysql_set_character_set(&mysql, charset_info->cs_name.str);
|
||||
default_charset= (char *)charset_info->cs_name.str;
|
||||
put_info("Charset changed", INFO_INFO);
|
||||
adjust_console_codepage(charset_info->cs_name.str);
|
||||
}
|
||||
else put_info("Charset is not found", INFO_INFO);
|
||||
return 0;
|
||||
@@ -4873,6 +4889,7 @@ sql_real_connect(char *host,char *database,char *user,char *password,
|
||||
put_info(buff, INFO_ERROR);
|
||||
return 1;
|
||||
}
|
||||
adjust_console_codepage(charset_info->cs_name.str);
|
||||
connected=1;
|
||||
#ifndef EMBEDDED_LIBRARY
|
||||
mysql_options(&mysql, MYSQL_OPT_RECONNECT, &debug_info_flag);
|
||||
|
Reference in New Issue
Block a user