diff options
-rw-r--r-- | client/mysql.cc | 20 | ||||
-rw-r--r-- | client/mysqladmin.cc | 5 | ||||
-rw-r--r-- | client/mysqlcheck.c | 14 | ||||
-rw-r--r-- | client/mysqlimport.c | 8 | ||||
-rw-r--r-- | client/mysqlshow.c | 2 | ||||
-rw-r--r-- | configure.in | 3 | ||||
-rw-r--r-- | include/mysql_com.h | 2 | ||||
-rw-r--r-- | mysql-test/include/default_client.cnf | 19 | ||||
-rw-r--r-- | mysql-test/include/default_my.cnf | 1 | ||||
-rw-r--r-- | mysql-test/r/mysql_locale_posix.result | 72 | ||||
-rw-r--r-- | mysql-test/suite/federated/my.cnf | 1 | ||||
-rw-r--r-- | mysql-test/suite/ndb/my.cnf | 1 | ||||
-rw-r--r-- | mysql-test/suite/rpl/my.cnf | 1 | ||||
-rw-r--r-- | mysql-test/suite/rpl/rpl_1slave_base.cnf | 1 | ||||
-rw-r--r-- | mysql-test/suite/rpl_ndb/my.cnf | 1 | ||||
-rw-r--r-- | mysql-test/t/mysql_locale_posix.test | 200 | ||||
-rw-r--r-- | mysql-test/t/mysqladmin.test | 6 | ||||
-rw-r--r-- | mysql-test/t/mysqlcheck.test | 2 | ||||
-rw-r--r-- | sql-common/client.c | 320 |
19 files changed, 609 insertions, 70 deletions
diff --git a/client/mysql.cc b/client/mysql.cc index f98e520d564..0f83f4fee07 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -141,7 +141,7 @@ static my_bool ignore_errors=0,wait_flag=0,quick=0, vertical=0, line_numbers=1, column_names=1,opt_html=0, opt_xml=0,opt_nopager=1, opt_outfile=0, named_cmds= 0, tty_password= 0, opt_nobeep=0, opt_reconnect=1, - default_charset_used= 0, opt_secure_auth= 0, + opt_secure_auth= 0, default_pager_set= 0, opt_sigint_ignore= 0, show_warnings= 0, executing_query= 0, interrupted_query= 0, ignore_spaces= 0; @@ -155,7 +155,7 @@ static char * opt_mysql_unix_port=0; static int connect_flag=CLIENT_INTERACTIVE; static char *current_host,*current_db,*current_user=0,*opt_password=0, *current_prompt=0, *delimiter_str= 0, - *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME, + *default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME, *opt_init_command= 0; static char *histfile; static char *histfile_tmp; @@ -1581,9 +1581,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), strmake(mysql_charsets_dir, argument, sizeof(mysql_charsets_dir) - 1); charsets_dir = mysql_charsets_dir; break; - case OPT_DEFAULT_CHARSET: - default_charset_used= 1; - break; case OPT_DELIMITER: if (argument == disabled_my_option) { @@ -1788,10 +1785,6 @@ static int get_options(int argc, char **argv) connect_flag= 0; /* Not in interactive mode */ } - if (strcmp(default_charset, charset_info->csname) && - !(charset_info= get_charset_by_csname(default_charset, - MY_CS_PRIMARY, MYF(MY_WME)))) - exit(1); if (argc > 1) { usage(0); @@ -2919,7 +2912,6 @@ com_charset(String *buffer __attribute__((unused)), char *line) charset_info= new_cs; mysql_set_character_set(&mysql, charset_info->csname); default_charset= (char *)charset_info->csname; - default_charset_used= 1; put_info("Charset changed", INFO_INFO); } else put_info("Charset is not found", INFO_INFO); @@ -4243,8 +4235,9 @@ sql_real_connect(char *host,char *database,char *user,char *password, select_limit,max_join_size); mysql_options(&mysql, MYSQL_INIT_COMMAND, init_command); } - if (default_charset_used) - mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset); + + mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset); + if (!mysql_real_connect(&mysql, host, user, password, database, opt_mysql_port, opt_mysql_unix_port, connect_flag | CLIENT_MULTI_STATEMENTS)) @@ -4259,6 +4252,9 @@ sql_real_connect(char *host,char *database,char *user,char *password, } return -1; // Retryable } + + charset_info= mysql.charset; + connected=1; #ifndef EMBEDDED_LIBRARY mysql.reconnect= debug_info_flag; // We want to know if this happens diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc index 2b93c149523..a3eee14e0d1 100644 --- a/client/mysqladmin.cc +++ b/client/mysqladmin.cc @@ -30,7 +30,7 @@ #define MAX_TRUNC_LENGTH 3 char *host= NULL, *user= 0, *opt_password= 0, - *default_charset= NULL; + *default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME; char truncated_var_names[MAX_MYSQL_VAR][MAX_TRUNC_LENGTH]; char ex_var_names[MAX_MYSQL_VAR][FN_REFLEN]; ulonglong last_values[MAX_MYSQL_VAR]; @@ -348,8 +348,7 @@ int main(int argc,char *argv[]) if (shared_memory_base_name) mysql_options(&mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name); #endif - if (default_charset) - mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset); + mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset); error_flags= (myf)(opt_nobeep ? 0 : ME_BELL); if (sql_connect(&mysql, option_wait)) diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c index 82aabd77b24..e4561066f9d 100644 --- a/client/mysqlcheck.c +++ b/client/mysqlcheck.c @@ -369,12 +369,15 @@ static int get_options(int *argc, char ***argv) If there's no --default-character-set option given with --fix-table-name or --fix-db-name set the default character set to "utf8". */ - if (!default_charset && (opt_fix_db_names || opt_fix_table_names)) + if (!default_charset) { - default_charset= (char*) "utf8"; + if (opt_fix_db_names || opt_fix_table_names) + default_charset= (char*) "utf8"; + else + default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME; } - if (default_charset && !get_charset_by_csname(default_charset, MY_CS_PRIMARY, - MYF(MY_WME))) + if (strcmp(default_charset, MYSQL_AUTODETECT_CHARSET_NAME) && + !get_charset_by_csname(default_charset, MY_CS_PRIMARY, MYF(MY_WME))) { printf("Unsupported character set: %s\n", default_charset); return 1; @@ -787,8 +790,7 @@ static int dbConnect(char *host, char *user, char *passwd) if (shared_memory_base_name) mysql_options(&mysql_connection,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name); #endif - if (default_charset) - mysql_options(&mysql_connection, MYSQL_SET_CHARSET_NAME, default_charset); + mysql_options(&mysql_connection, MYSQL_SET_CHARSET_NAME, default_charset); if (!(sock = mysql_real_connect(&mysql_connection, host, user, passwd, NULL, opt_mysql_port, opt_mysql_unix_port, 0))) { diff --git a/client/mysqlimport.c b/client/mysqlimport.c index ef38d760e5d..5b8ec95c06d 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -55,11 +55,10 @@ static char *opt_password=0, *current_user=0, *current_host=0, *current_db=0, *fields_terminated=0, *lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0, *opt_columns=0, - *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME; + *default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME; static uint opt_mysql_port= 0, opt_protocol= 0; static char * opt_mysql_unix_port=0; static longlong opt_ignore_lines= -1; -static CHARSET_INFO *charset_info= &my_charset_latin1; #include <sslopt-vars.h> #ifdef HAVE_SMEM @@ -282,10 +281,6 @@ static int get_options(int *argc, char ***argv) fprintf(stderr, "You can't use --ignore (-i) and --replace (-r) at the same time.\n"); return(1); } - if (strcmp(default_charset, charset_info->csname) && - !(charset_info= get_charset_by_csname(default_charset, - MY_CS_PRIMARY, MYF(MY_WME)))) - exit(1); if (*argc < 2) { usage(); @@ -440,6 +435,7 @@ static MYSQL *db_connect(char *host, char *database, if (shared_memory_base_name) mysql_options(mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name); #endif + mysql_options(mysql, MYSQL_SET_CHARSET_NAME, default_charset); if (!(mysql_real_connect(mysql,host,user,passwd, database,opt_mysql_port,opt_mysql_unix_port, 0))) diff --git a/client/mysqlshow.c b/client/mysqlshow.c index 15f791ca8fb..206b86d07cf 100644 --- a/client/mysqlshow.c +++ b/client/mysqlshow.c @@ -32,7 +32,7 @@ static my_bool tty_password= 0, opt_table_type= 0; static my_bool debug_info_flag= 0, debug_check_flag= 0; static uint my_end_arg= 0; static uint opt_verbose=0; -static char *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME; +static char *default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME; #ifdef HAVE_SMEM static char *shared_memory_base_name=0; diff --git a/configure.in b/configure.in index b5f3d46f3f4..953950a2faf 100644 --- a/configure.in +++ b/configure.in @@ -2031,10 +2031,11 @@ AC_SUBST(MAKE_SHELL) AC_CHECK_HEADERS(varargs.h stdarg.h dirent.h locale.h ndir.h sys/dir.h \ sys/file.h sys/ndir.h sys/ptem.h sys/pte.h sys/select.h sys/stream.h \ sys/mman.h curses.h termcap.h termio.h termbits.h asm/termbits.h grp.h \ -paths.h semaphore.h) +paths.h semaphore.h langinfo.h) # Already-done: strcasecmp AC_CHECK_FUNCS(lstat putenv select setenv setlocale strcoll tcgetattr) +AC_CHECK_FUNCS(nl_langinfo) AC_STAT_MACROS_BROKEN MYSQL_SIGNAL_CHECK diff --git a/include/mysql_com.h b/include/mysql_com.h index db5a5eb8741..b571ce3e894 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -27,6 +27,8 @@ #define NAME_LEN (NAME_CHAR_LEN*SYSTEM_CHARSET_MBMAXLEN) #define USERNAME_LENGTH (USERNAME_CHAR_LENGTH*SYSTEM_CHARSET_MBMAXLEN) +#define MYSQL_AUTODETECT_CHARSET_NAME "auto" + #define SERVER_VERSION_LENGTH 60 #define SQLSTATE_LENGTH 5 diff --git a/mysql-test/include/default_client.cnf b/mysql-test/include/default_client.cnf new file mode 100644 index 00000000000..38f0d39127a --- /dev/null +++ b/mysql-test/include/default_client.cnf @@ -0,0 +1,19 @@ +# +# We use default-character-set=latin1 to avoid character set auto-detection +# when running tests - not to depend on the current machine localization. +# + +[mysql] +default-character-set=latin1 + +[mysqlshow] +default-character-set=latin1 + +[mysqlimport] +default-character-set=latin1 + +[mysqlcheck] +default-character-set=latin1 + +[mysql_upgrade] +default-character-set=latin1 diff --git a/mysql-test/include/default_my.cnf b/mysql-test/include/default_my.cnf index d77fee0e200..428c2166947 100644 --- a/mysql-test/include/default_my.cnf +++ b/mysql-test/include/default_my.cnf @@ -1,5 +1,6 @@ # Use default setting for mysqld processes !include default_mysqld.cnf +!include default_client.cnf [mysqld.1] diff --git a/mysql-test/r/mysql_locale_posix.result b/mysql-test/r/mysql_locale_posix.result new file mode 100644 index 00000000000..de92c40f0eb --- /dev/null +++ b/mysql-test/r/mysql_locale_posix.result @@ -0,0 +1,72 @@ +SET NAMES utf8; +DROP DATABASE IF EXISTS `ó`; +DROP DATABASE IF EXISTS `Ăł`; +DROP DATABASE IF EXISTS `цЁ`; +DROP DATABASE IF EXISTS `ó`; + +ISO8859-1 +@@character_set_client +latin1 +Database: ó ++--------+ +| Tables | ++--------+ ++--------+ + +ISO8859-2 +@@character_set_client +latin2 +Database: ó ++--------+ +| Tables | ++--------+ ++--------+ + +KOI8-R +@@character_set_client +koi8r +Database: ó ++--------+ +| Tables | ++--------+ ++--------+ + +UTF-8 +@@character_set_client +utf8 +Database: ó ++--------+ +| Tables | ++--------+ ++--------+ +Database: ó ++--------+ +| Tables | ++--------+ ++--------+ +Database: Ăł ++--------+ +| Tables | ++--------+ ++--------+ +Database: цЁ ++--------+ +| Tables | ++--------+ ++--------+ +SHOW DATABASES LIKE 'ó'; +Database (ó) +ó +SHOW DATABASES LIKE 'Ăł'; +Database (Ăł) +Ăł +SHOW DATABASES LIKE 'цЁ'; +Database (цЁ) +цЁ +SHOW DATABASES LIKE 'ó'; +Database (ó) +ó +DROP DATABASE `ó`; +DROP DATABASE `Ăł`; +DROP DATABASE `цЁ`; +DROP DATABASE `ó`; diff --git a/mysql-test/suite/federated/my.cnf b/mysql-test/suite/federated/my.cnf index 3e84845b945..1cdab9fc158 100644 --- a/mysql-test/suite/federated/my.cnf +++ b/mysql-test/suite/federated/my.cnf @@ -1,5 +1,6 @@ # Use default setting for mysqld processes !include include/default_mysqld.cnf +!include include/default_client.cnf [mysqld.1] log-bin= master-bin diff --git a/mysql-test/suite/ndb/my.cnf b/mysql-test/suite/ndb/my.cnf index a19fdeee302..37dfc3945ce 100644 --- a/mysql-test/suite/ndb/my.cnf +++ b/mysql-test/suite/ndb/my.cnf @@ -1,5 +1,6 @@ !include include/default_mysqld.cnf !include include/default_ndbd.cnf +!include include/default_client.cnf [cluster_config.1] NoOfReplicas= 2 diff --git a/mysql-test/suite/rpl/my.cnf b/mysql-test/suite/rpl/my.cnf index ea4caeb2ddd..4d0e5e51664 100644 --- a/mysql-test/suite/rpl/my.cnf +++ b/mysql-test/suite/rpl/my.cnf @@ -1,6 +1,7 @@ # Use settings from rpl_1slave_base.cnf # add setting to connect the slave to the master by default !include rpl_1slave_base.cnf +!include include/default_client.cnf [mysqld.2] # Hardcode the host to 127.0.0.1 until running on more diff --git a/mysql-test/suite/rpl/rpl_1slave_base.cnf b/mysql-test/suite/rpl/rpl_1slave_base.cnf index 23b7ded9a7d..2c2949bd42c 100644 --- a/mysql-test/suite/rpl/rpl_1slave_base.cnf +++ b/mysql-test/suite/rpl/rpl_1slave_base.cnf @@ -1,5 +1,6 @@ # Use default setting for mysqld processes !include include/default_mysqld.cnf +!include include/default_client.cnf [mysqld.1] diff --git a/mysql-test/suite/rpl_ndb/my.cnf b/mysql-test/suite/rpl_ndb/my.cnf index 58fec36eedd..a0ec3659c18 100644 --- a/mysql-test/suite/rpl_ndb/my.cnf +++ b/mysql-test/suite/rpl_ndb/my.cnf @@ -1,5 +1,6 @@ !include include/default_mysqld.cnf !include include/default_ndbd.cnf +!include include/default_client.cnf [cluster_config.1] NoOfReplicas= 2 diff --git a/mysql-test/t/mysql_locale_posix.test b/mysql-test/t/mysql_locale_posix.test new file mode 100644 index 00000000000..79994480b3d --- /dev/null +++ b/mysql-test/t/mysql_locale_posix.test @@ -0,0 +1,200 @@ +--source include/not_windows.inc +--source include/have_case_sensitive_file_system.inc + + +# +# Note, please keep this file UTF-8 compatible. +# After editing, make sure that +# "file mysql_locale_posix.test" +# says +# "UTF-8 Unicode text" +# or +# "UTF-8 Unicode English text" +# + + +# +# Check if we're running on a POSIX-locale machine +# + +--disable_query_log +--exec locale -a > var/tmp/locale_a.output 2>/dev/null || true +SET @file=REPLACE(LOAD_FILE('../../tmp/locale_a.output'), '-', ''); +# make it case insensitive +SET @file=CAST(@file AS CHAR CHARACTER SET latin1) COLLATE latin1_swedish_ci; +--remove_file var/tmp/locale_a.output + +if (`SELECT (IFNULL(@file,'') NOT LIKE '%\nde_DE.iso88591\n%')`) +{ + Skip Need POSIX locale de_DE.iso88591; +} + +if (`SELECT (IFNULL(@file,'') NOT LIKE '%\nru_RU.koi8r\n%')`) +{ + Skip Need POSIX locale ru_RU.koi8r; +} + +if (`SELECT (IFNULL(@file,'') NOT LIKE '%\ncs_CZ.iso88592\n%')`) +{ + Skip Need POSIX locale cs_CZ.iso88592; +} + +if (`SELECT (IFNULL(@file,'') NOT LIKE '%\nen_US.utf8\n%')`) +{ + Skip Need POSIX locale en_US.utf8; +} +--enable_query_log + + + +SET NAMES utf8; + +--disable_warnings +DROP DATABASE IF EXISTS `ó`; +DROP DATABASE IF EXISTS `Ăł`; +DROP DATABASE IF EXISTS `цЁ`; +DROP DATABASE IF EXISTS `ó`; +--enable_warnings + +# +# Test some of the OS-to-MySQL character set mappings +# + + +# {"ANSI_X3.4-1968", "ascii", my_cs_exact}, +# {"ansi1251", "cp1251", my_cs_exact}, +# {"armscii8", "armscii8", my_cs_exact}, +# {"ASCII", "ascii", my_cs_exact}, +# {"Big5", "big5", my_cs_exact}, +# {"cp1251", "cp1251", my_cs_exact}, +# {"cp1255", "cp1255", my_cs_exact}, +# {"CP866", "cp866", my_cs_exact}, +# {"eucCN", "gb2312", my_cs_exact}, +# {"eucJP", "ujis", my_cs_exact}, +# {"eucKR", "euckr", my_cs_exact}, +# +# {"gb18030", "gb18030", my_cs_exact}, +# +# {"gb2312", "gb2312", my_cs_exact}, +# {"gbk", "gbk", my_cs_exact}, +# {"georgianps", "geostd8", my_cs_exact}, +# {"IBM-1252", "cp1252", my_cs_exact}, +# +# {"iso88591", "latin1", my_cs_approx}, +# {"ISO_8859-1", "latin1", my_cs_approx}, +# {"ISO8859-1", "latin1", my_cs_approx}, +# {"ISO-8859-1", "latin1", my_cs_approx}, + + +# +# _utf8 0xC3B3 = LATIN SMALL LETTER O WITH ACUTE +# _latin1 0xC3 = LATIN CAPITAL LETTER A WITH TILDE +# _latin1 0xB3 = SUPERSCRIPT THREE +# +--echo +--echo ISO8859-1 +--exec LC_ALL=fi_FI.ISO8859-1 $MYSQL --default-character-set=auto test -e "SELECT @@character_set_client" +--exec LC_ALL=fi_FI.ISO8859-1 $MYSQLADMIN -uroot -S $MASTER_MYSOCK -P $MASTER_MYPORT --default-character-set=auto create ó +--exec LC_ALL=fi_FI.ISO8859-1 $MYSQL_SHOW --default-character-set=auto ó +--exec LC_ALL=fi_FI.ISO8859-1 $MYSQL_CHECK --default-character-set=auto "ó" + + +# {"iso885913", "latin7", my_cs_exact}, +# {"ISO_8859-13", "latin7", my_cs_exact}, +# {"ISO8859-13", "latin7", my_cs_exact}, +# {"ISO-8859-13", "latin7", my_cs_exact}, +# +# {"iso885915", "latin9", my_cs_exact}, +# {"ISO_8859-15", "latin9", my_cs_exact}, +# {"ISO8859-15", "latin9", my_cs_exact}, +# {"ISO-8859-15", "latin9", my_cs_exact}, +# +# {"iso88592", "latin2", my_cs_exact}, +# {"ISO_8859-2", "latin2", my_cs_exact}, +# {"ISO8859-2", "latin2", my_cs_exact}, +# {"ISO-8859-2", "latin2", my_cs_exact}, +# + + +# +# _utf8 0xC3B3 = LATIN SMALL LETTER O WITH ACUTE +# _latin2 0xC3 = LATIN CAPITAL LETTER A WITH BREVE +# _latin2 0xB3 = LATIN SMALL LETTER L WITH STROKE +# +--echo +--echo ISO8859-2 +--exec LC_ALL=cs_CZ.ISO8859-2 $MYSQL --character-sets-dir=$CHARSETSDIR --default-character-set=auto test -e "SELECT @@character_set_client" +--exec LC_ALL=cs_CZ.ISO8859-2 $MYSQLADMIN --character-sets-dir=$CHARSETSDIR -uroot -S $MASTER_MYSOCK -P $MASTER_MYPORT --default-character-set=auto create ó +--exec LC_ALL=cs_CZ.ISO8859-2 $MYSQL_SHOW --character-sets-dir=$CHARSETSDIR --default-character-set=auto ó +--exec LC_ALL=cs_CZ.ISO8859-1 $MYSQL_CHECK --character-sets-dir=$CHARSETSDIR--default-character-set=auto "ó" + + +# {"iso88597", "greek", my_cs_exact}, +# {"ISO_8859-7", "greek", my_cs_exact}, +# {"ISO8859-7", "greek", my_cs_exact}, +# {"ISO-8859-7", "greek", my_cs_exact}, +# +# {"iso88598", "hebrew", my_cs_exact}, +# {"ISO_8859-8", "hebrew", my_cs_exact}, +# {"ISO8859-8", "hebrew", my_cs_exact}, +# {"ISO-8859-8", "hebrew", my_cs_exact}, +# +# {"iso88599", "latin5", my_cs_exact}, +# {"ISO_8859-9", "latin5", my_cs_exact}, +# {"ISO8859-9", "latin5", my_cs_exact}, +# {"ISO-8859-9", "latin5", my_cs_exact}, +# +# {"koi8r", "koi8r", my_cs_exact}, +# {"KOI8-R", "koi8r", my_cs_exact}, +# {"koi8u", "koi8u", my_cs_exact}, +# {"KOI8-U", "koi8u", my_cs_exact}, +# + +# +# _utf8 0xC3B3 = LATIN SMALL LETTER O WITH ACUTE +# _koi8r 0xC3 = CYRILLIC SMALL LETTER TSE +# _koi8r 0xB3 = CYRILLIC CAPITAL LETTER IO +# + +--echo +--echo KOI8-R +--exec LC_ALL=ru_RU.KOI8-R $MYSQL --character-sets-dir=$CHARSETSDIR --default-character-set=auto test -e "SELECT @@character_set_client" +--exec LC_ALL=ru_RU.KOI8-R $MYSQLADMIN --character-sets-dir=$CHARSETSDIR -uroot -S $MASTER_MYSOCK -P $MASTER_MYPORT --default-character-set=auto create ó +--exec LC_ALL=ru_RU.KOI8-R $MYSQL_SHOW --character-sets-dir=$CHARSETSDIR --default-character-set=auto ó +--exec LC_ALL=ru_RU.ISO8859-1 $MYSQL_CHECK --character-sets-dir=$CHARSETSDIR --default-character-set=auto "ó" + + +# {"Shift_JIS", "sjis", my_cs_exact}, +# {"SJIS", "sjis", my_cs_exact}, +# +# {"tis620", "tis620", my_cs_exact}, +# +# {"ujis", "ujis", my_cs_exact}, +# +# {"US-ASCII", "ascii", my_cs_exact}, +# +# {"utf8", "utf8", my_cs_exact}, +# {"utf-8", "utf8", my_cs_exact}, + +--echo +--echo UTF-8 +--exec LC_ALL=en_US.UTF-8 $MYSQL --default-character-set=auto test -e "SELECT @@character_set_client" +--exec LC_ALL=en_US.UTF-8 $MYSQLADMIN -uroot -S $MASTER_MYSOCK -P $MASTER_MYPORT --default-character-set=auto create ó +--exec LC_ALL=en_US.UTF-8 $MYSQL_SHOW --default-character-set=auto ó +--exec LC_ALL=en_US.UTF-8 $MYSQL_SHOW --default-character-set=auto "ó" +--exec LC_ALL=en_US.UTF-8 $MYSQL_SHOW --default-character-set=auto "Ăł" +--exec LC_ALL=en_US.UTF-8 $MYSQL_SHOW --default-character-set=auto "цЁ" +--exec LC_ALL=en_US.UTF-8 $MYSQL_CHECK --default-character-set=auto ó +--exec LC_ALL=en_US.UTF-8 $MYSQL_CHECK --default-character-set=auto "ó" +--exec LC_ALL=en_US.UTF-8 $MYSQL_CHECK --default-character-set=auto "Ăł" +--exec LC_ALL=en_US.UTF-8 $MYSQL_CHECK --default-character-set=auto "цЁ" + +SHOW DATABASES LIKE 'ó'; +SHOW DATABASES LIKE 'Ăł'; +SHOW DATABASES LIKE 'цЁ'; +SHOW DATABASES LIKE 'ó'; + +DROP DATABASE `ó`; +DROP DATABASE `Ăł`; +DROP DATABASE `цЁ`; +DROP DATABASE `ó`; diff --git a/mysql-test/t/mysqladmin.test b/mysql-test/t/mysqladmin.test index 839ecf00b60..eb59e60eefe 100644 --- a/mysql-test/t/mysqladmin.test +++ b/mysql-test/t/mysqladmin.test @@ -4,7 +4,7 @@ # Test "mysqladmin ping" # ---exec $MYSQLADMIN --no-defaults -S $MASTER_MYSOCK -P $MASTER_MYPORT -u root --password= ping 2>&1 +--exec $MYSQLADMIN --no-defaults --default-character-set=latin1 -S $MASTER_MYSOCK -P $MASTER_MYPORT -u root --password= ping 2>&1 # @@ -19,7 +19,7 @@ EOF --replace_regex /.*mysqladmin.*: unknown/mysqladmin: unknown/ --error 7 ---exec $MYSQLADMIN --defaults-file=$MYSQLTEST_VARDIR/tmp/bug10608.cnf -S $MASTER_MYSOCK -P $MASTER_MYPORT -u root --password= ping 2>&1 +--exec $MYSQLADMIN --defaults-file=$MYSQLTEST_VARDIR/tmp/bug10608.cnf --default-character-set=latin1 -S $MASTER_MYSOCK -P $MASTER_MYPORT -u root --password= ping 2>&1 remove_file $MYSQLTEST_VARDIR/tmp/bug10608.cnf; # When mysqladmin finds "loose-database" in .cnf file it shall print @@ -30,6 +30,6 @@ loose-database=db2 EOF --replace_regex /Warning: .*mysqladmin.*: unknown/Warning: mysqladmin: unknown/ ---exec $MYSQLADMIN --defaults-file=$MYSQLTEST_VARDIR/tmp/bug10608.cnf -S $MASTER_MYSOCK -P $MASTER_MYPORT -u root --password= ping 2>&1 +--exec $MYSQLADMIN --defaults-file=$MYSQLTEST_VARDIR/tmp/bug10608.cnf --default-character-set=latin1 -S $MASTER_MYSOCK -P $MASTER_MYPORT -u root --password= ping 2>&1 remove_file $MYSQLTEST_VARDIR/tmp/bug10608.cnf; diff --git a/mysql-test/t/mysqlcheck.test b/mysql-test/t/mysqlcheck.test index 986b5aba385..831aba72fb5 100644 --- a/mysql-test/t/mysqlcheck.test +++ b/mysql-test/t/mysqlcheck.test @@ -178,7 +178,7 @@ SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_SCHEMA="#mysql50#a@b" ORDER BY trigger_name; --echo mysqlcheck --fix-db-names --fix-table-names --all-databases ---exec $MYSQL_CHECK --fix-db-names --fix-table-names --all-databases +--exec $MYSQL_CHECK --default-character-set=utf8 --fix-db-names --fix-table-names --all-databases USE `a@b`; SELECT * FROM INFORMATION_SCHEMA.TRIGGERS diff --git a/sql-common/client.c b/sql-common/client.c index 3ee6c600387..5ae3a2816a5 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -1819,52 +1819,298 @@ static MYSQL_METHODS client_methods= #endif }; + + +typedef enum my_cs_match_type_enum +{ + /* MySQL and OS charsets are fully compatible */ + my_cs_exact, + /* MySQL charset is very close to OS charset */ + my_cs_approx, + /* + MySQL knows this charset, but it is not supported as client character set. + */ + my_cs_unsupp +} my_cs_match_type; + + +typedef struct str2str_st +{ + const char *os_name; + const char *my_name; + my_cs_match_type param; +} MY_CSET_OS_NAME; + +const MY_CSET_OS_NAME charsets[]= +{ +#ifdef __WIN__ + {"cp437", "cp850", my_cs_approx}, + {"cp850", "cp850", my_cs_exact}, + {"cp852", "cp852", my_cs_exact}, + {"cp858", "cp850", my_cs_approx}, + {"cp866", "cp866", my_cs_exact}, + {"cp874", "tis620", my_cs_approx}, + {"cp932", "cp932", my_cs_exact}, + {"cp936", "gbk", my_cs_approx}, + {"cp949", "euckr", my_cs_approx}, + {"cp950", "big5", my_cs_exact}, + {"cp1200", "utf16le", my_cs_unsupp}, + {"cp1201", "utf16", my_cs_unsupp}, + {"cp1250", "cp1250", my_cs_exact}, + {"cp1251", "cp1251", my_cs_exact}, + {"cp1252", "latin1", my_cs_exact}, + {"cp1253", "greek", my_cs_exact}, + {"cp1254", "latin5", my_cs_exact}, + {"cp1255", "hebrew", my_cs_approx}, + {"cp1256", "cp1256", my_cs_exact}, + {"cp1257", "cp1257", my_cs_exact}, + {"cp10000", "macroman", my_cs_exact}, + {"cp10001", "sjis", my_cs_approx}, + {"cp10002", "big5", my_cs_approx}, + {"cp10008", "gb2312", my_cs_approx}, + {"cp10021", "tis620", my_cs_approx}, + {"cp10029", "macce", my_cs_exact}, + {"cp12001", "utf32", my_cs_unsupp}, + {"cp20107", "swe7", my_cs_exact}, + {"cp20127", "ascii", my_cs_exact}, + {"cp20866", "koi8r", my_cs_exact}, + {"cp20932", "ujis", my_cs_exact}, + {"cp20936", "gb2312", my_cs_approx}, + {"cp20949", "euckr", my_cs_approx}, + {"cp21866", "koi8u", my_cs_exact}, + {"cp28591", "latin1", my_cs_approx}, + {"cp28592", "latin2", my_cs_exact}, + {"cp28597", "greek", my_cs_exact}, + {"cp28598", "hebrew", my_cs_exact}, + {"cp28599", "latin5", my_cs_exact}, + {"cp28603", "latin7", my_cs_exact}, +#ifdef UNCOMMENT_THIS_WHEN_WL_4579_IS_DONE + {"cp28605", "latin9", my_cs_exact}, +#endif + {"cp38598", "hebrew", my_cs_exact}, + {"cp51932", "ujis", my_cs_exact}, + {"cp51936", "gb2312", my_cs_exact}, + {"cp51949", "euckr", my_cs_exact}, + {"cp51950", "big5", my_cs_exact}, +#ifdef UNCOMMENT_THIS_WHEN_WL_WL_4024_IS_DONE + {"cp54936", "gb18030", my_cs_exact}, +#endif + {"cp65001", "utf8", my_cs_exact}, + +#else /* not Windows */ + + {"646", "latin1", my_cs_approx}, /* Default on Solaris */ + {"ANSI_X3.4-1968", "ascii", my_cs_exact}, + {"ansi1251", "cp1251", my_cs_exact}, + {"armscii8", "armscii8", my_cs_exact}, + {"armscii-8", "armscii8", my_cs_exact}, + {"ASCII", "ascii", my_cs_exact}, + {"Big5", "big5", my_cs_exact}, + {"cp1251", "cp1251", my_cs_exact}, + {"cp1255", "hebrew", my_cs_approx}, + {"CP866", "cp866", my_cs_exact}, + {"eucCN", "gb2312", my_cs_exact}, + {"euc-CN", "gb2312", my_cs_exact}, + {"eucJP", "ujis", my_cs_exact}, + {"euc-JP", "ujis", my_cs_exact}, + {"eucKR", "euckr", my_cs_exact}, + {"euc-KR", "euckr", my_cs_exact}, +#ifdef UNCOMMENT_THIS_WHEN_WL_WL_4024_IS_DONE + {"gb18030", "gb18030", my_cs_exact}, +#endif + {"gb2312", "gb2312", my_cs_exact}, + {"gbk", "gbk", my_cs_exact}, + {"georgianps", "geostd8", my_cs_exact}, + {"georgian-ps", "geostd8", my_cs_exact}, + {"IBM-1252", "cp1252", my_cs_exact}, + + {"iso88591", "latin1", my_cs_approx}, + {"ISO_8859-1", "latin1", my_cs_approx}, + {"ISO8859-1", "latin1", my_cs_approx}, + {"ISO-8859-1", "latin1", my_cs_approx}, + + {"iso885913", "latin7", my_cs_exact}, + {"ISO_8859-13", "latin7", my_cs_exact}, + {"ISO8859-13", "latin7", my_cs_exact}, + {"ISO-8859-13", "latin7", my_cs_exact}, + +#ifdef UNCOMMENT_THIS_WHEN_WL_4579_IS_DONE + {"iso885915", "latin9", my_cs_exact}, + {"ISO_8859-15", "latin9", my_cs_exact}, + {"ISO8859-15", "latin9", my_cs_exact}, + {"ISO-8859-15", "latin9", my_cs_exact}, +#endif + + {"iso88592", "latin2", my_cs_exact}, + {"ISO_8859-2", "latin2", my_cs_exact}, + {"ISO8859-2", "latin2", my_cs_exact}, + {"ISO-8859-2", "latin2", my_cs_exact}, + + {"iso88597", "greek", my_cs_exact}, + {"ISO_8859-7", "greek", my_cs_exact}, + {"ISO8859-7", "greek", my_cs_exact}, + {"ISO-8859-7", "greek", my_cs_exact}, + + {"iso88598", "hebrew", my_cs_exact}, + {"ISO_8859-8", "hebrew", my_cs_exact}, + {"ISO8859-8", "hebrew", my_cs_exact}, + {"ISO-8859-8", "hebrew", my_cs_exact}, + + {"iso88599", "latin5", my_cs_exact}, + {"ISO_8859-9", "latin5", my_cs_exact}, + {"ISO8859-9", "latin5", my_cs_exact}, + {"ISO-8859-9", "latin5", my_cs_exact}, + + {"koi8r", "koi8r", my_cs_exact}, + {"KOI8-R", "koi8r", my_cs_exact}, + {"koi8u", "koi8u", my_cs_exact}, + {"KOI8-U", "koi8u", my_cs_exact}, + + {"roman8", "hp8", my_cs_exact}, /* Default on HP UX */ + + {"Shift_JIS", "sjis", my_cs_exact}, + {"SJIS", "sjis", my_cs_exact}, + {"shiftjisx0213", "sjis", my_cs_exact}, + + {"tis620", "tis620", my_cs_exact}, + {"tis-620", "tis620", my_cs_exact}, + + {"ujis", "ujis", my_cs_exact}, + + {"US-ASCII", "ascii", my_cs_exact}, + + {"utf8", "utf8", my_cs_exact}, + {"utf-8", "utf8", my_cs_exact}, +#endif + {NULL, NULL, 0} +}; + + +static const char * +my_os_charset_to_mysql_charset(const char *csname) +{ + const MY_CSET_OS_NAME *csp; + for (csp= charsets; csp->os_name; csp++) + { + if (!my_strcasecmp(&my_charset_latin1, csp->os_name, csname)) + { + switch (csp->param) + { + case my_cs_exact: + return csp->my_name; + + case my_cs_approx: + /* + Maybe we should print a warning eventually: + character set correspondence is not exact. + */ + return csp->my_name; + + default: + my_printf_error(ER_UNKNOWN_ERROR, + "OS character set '%s'" + " is not supported by MySQL client", + MYF(0), csp->my_name); + goto def; + } + } + } + + my_printf_error(ER_UNKNOWN_ERROR, + "Unknown OS character set '%s'.", + MYF(0), csname); + +def: + csname= MYSQL_DEFAULT_CHARSET_NAME; + my_printf_error(ER_UNKNOWN_ERROR, + "Switching to the default character set '%s'.", + MYF(0), csname); + return csname; +} + + +#ifndef __WIN__ +#include <stdlib.h> /* for getenv() */ +#ifdef HAVE_LANGINFO_H +#include <langinfo.h> +#endif +#ifdef HAVE_LOCALE_H +#include <locale.h> +#endif +#endif /* __WIN__ */ + + +static int +mysql_autodetect_character_set(MYSQL *mysql) +{ + const char *csname= MYSQL_DEFAULT_CHARSET_NAME; + +#ifdef __WIN__ + char cpbuf[64]; + { + my_snprintf(cpbuf, sizeof(cpbuf), "cp%d", (int) GetConsoleCP()); + csname= my_os_charset_to_mysql_charset(cpbuf); + } +#elif defined(HAVE_SETLOCALE) && defined(HAVE_NL_LANGINFO) + { + if (setlocale(LC_CTYPE, "") && (csname= nl_langinfo(CODESET))) + csname= my_os_charset_to_mysql_charset(csname); + } +#endif + + if (!(mysql->options.charset_name= my_strdup(csname, MYF(MY_WME)))) + return 1; + return 0; +} + + +static void +mysql_set_character_set_with_default_collation(MYSQL *mysql) +{ + const char *save= charsets_dir; + if (mysql->options.charset_dir) + charsets_dir=mysql->options.charset_dir; + + if ((mysql->charset= get_charset_by_csname(mysql->options.charset_name, + MY_CS_PRIMARY, MYF(MY_WME)))) + { + /* Try to set compiled default collation when it's possible. */ + CHARSET_INFO *collation; + if ((collation= + get_charset_by_name(MYSQL_DEFAULT_COLLATION_NAME, MYF(MY_WME))) && + my_charset_same(mysql->charset, collation)) + { + mysql->charset= collation; + } + else + { + /* + Default compiled collation not found, or is not applicable + to the requested character set. + Continue with the default collation of the character set. + */ + } + } + charsets_dir= save; +} + + C_MODE_START int mysql_init_character_set(MYSQL *mysql) { - const char *default_collation_name; - /* Set character set */ if (!mysql->options.charset_name) { - default_collation_name= MYSQL_DEFAULT_COLLATION_NAME; if (!(mysql->options.charset_name= my_strdup(MYSQL_DEFAULT_CHARSET_NAME,MYF(MY_WME)))) - return 1; - } - else - default_collation_name= NULL; - - { - const char *save= charsets_dir; - if (mysql->options.charset_dir) - charsets_dir=mysql->options.charset_dir; - mysql->charset=get_charset_by_csname(mysql->options.charset_name, - MY_CS_PRIMARY, MYF(MY_WME)); - if (mysql->charset && default_collation_name) - { - CHARSET_INFO *collation; - if ((collation= - get_charset_by_name(default_collation_name, MYF(MY_WME)))) - { - if (!my_charset_same(mysql->charset, collation)) - { - my_printf_error(ER_UNKNOWN_ERROR, - "COLLATION %s is not valid for CHARACTER SET %s", - MYF(0), - default_collation_name, mysql->options.charset_name); - mysql->charset= NULL; - } - else - { - mysql->charset= collation; - } - } - else - mysql->charset= NULL; - } - charsets_dir= save; + return 1; } + else if (!strcmp(mysql->options.charset_name, + MYSQL_AUTODETECT_CHARSET_NAME) && + mysql_autodetect_character_set(mysql)) + return 1; + + mysql_set_character_set_with_default_collation(mysql); if (!mysql->charset) { |