diff options
author | Rucha Deodhar <rucha.deodhar@mariadb.com> | 2021-02-15 01:39:37 +0530 |
---|---|---|
committer | Oleksandr Byelkin <sanja@mariadb.com> | 2021-05-19 06:48:36 +0200 |
commit | 2fdb556e045e9918410086eeaac5a94a4c028626 (patch) | |
tree | 1420013b4e76b3192cb8ac33406c818d3ecfc3af /mysys | |
parent | c366845a0b5c08285c958cf1500b3b7906ecf8d4 (diff) | |
download | mariadb-git-2fdb556e045e9918410086eeaac5a94a4c028626.tar.gz |
MDEV-8334: Rename utf8 to utf8mb3
This patch changes the main name of 3 byte character set from utf8 to
utf8mb3. New old_mode UTF8_IS_UTF8MB3 is added and set TRUE by default,
so that utf8 would mean utf8mb3. If not set, utf8 would mean utf8mb4.
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/charset.c | 47 | ||||
-rw-r--r-- | mysys/test_charset.c | 2 |
2 files changed, 23 insertions, 26 deletions
diff --git a/mysys/charset.c b/mysys/charset.c index 32cfeb56e2d..c786488d09f 100644 --- a/mysys/charset.c +++ b/mysys/charset.c @@ -722,25 +722,26 @@ void free_charsets(void) static const char* -get_collation_name_alias(const char *name, char *buf, size_t bufsize) +get_collation_name_alias(const char *name, char *buf, size_t bufsize, myf flags) { - if (!strncasecmp(name, "utf8mb3_", 8)) + if (!strncasecmp(name, "utf8_", 5)) { - my_snprintf(buf, bufsize, "utf8_%s", name + 8); + my_snprintf(buf, bufsize, "utf8mb%c_%s", + flags & MY_UTF8_IS_UTF8MB3 ? '3' : '4', name + 5); return buf; } return NULL; } -uint get_collation_number(const char *name) +uint get_collation_number(const char *name, myf flags) { uint id; char alias[64]; my_pthread_once(&charsets_initialized, init_available_charsets); if ((id= get_collation_number_internal(name))) return id; - if ((name= get_collation_name_alias(name, alias, sizeof(alias)))) + if ((name= get_collation_name_alias(name, alias, sizeof(alias),flags))) return get_collation_number_internal(name); return 0; } @@ -763,22 +764,16 @@ get_charset_number_internal(const char *charset_name, uint cs_flags) } -static const char* -get_charset_name_alias(const char *name) -{ - if (!my_strcasecmp(&my_charset_latin1, name, "utf8mb3")) - return "utf8"; - return NULL; -} - - -uint get_charset_number(const char *charset_name, uint cs_flags) +uint get_charset_number(const char *charset_name, uint cs_flags, myf flags) { uint id; + const char *new_charset_name= flags & MY_UTF8_IS_UTF8MB3 ? "utf8mb3" : + "utf8mb4"; my_pthread_once(&charsets_initialized, init_available_charsets); if ((id= get_charset_number_internal(charset_name, cs_flags))) return id; - if ((charset_name= get_charset_name_alias(charset_name))) + if ((charset_name= !my_strcasecmp(&my_charset_latin1, charset_name, "utf8") ? + new_charset_name : NULL)) return get_charset_number_internal(charset_name, cs_flags); return 0; } @@ -809,7 +804,7 @@ static CHARSET_INFO *inheritance_source_by_id(CHARSET_INFO *cs, uint refid) } -static CHARSET_INFO *find_collation_data_inheritance_source(CHARSET_INFO *cs) +static CHARSET_INFO *find_collation_data_inheritance_source(CHARSET_INFO *cs, myf flags) { const char *beg, *end; if (cs->tailoring && @@ -820,7 +815,7 @@ static CHARSET_INFO *find_collation_data_inheritance_source(CHARSET_INFO *cs) char name[MY_CS_NAME_SIZE + 1]; memcpy(name, beg, end - beg); name[end - beg]= '\0'; - return inheritance_source_by_id(cs, get_collation_number(name)); + return inheritance_source_by_id(cs, get_collation_number(name,MYF(flags))); } return NULL; } @@ -875,7 +870,7 @@ get_internal_charset(MY_CHARSET_LOADER *loader, uint cs_number, myf flags) } if (!simple_8bit_collation_data_is_full(cs)) { - CHARSET_INFO *refcl= find_collation_data_inheritance_source(cs); + CHARSET_INFO *refcl= find_collation_data_inheritance_source(cs, flags); if (refcl) inherit_collation_data(cs, refcl); } @@ -944,7 +939,7 @@ my_collation_get_by_name(MY_CHARSET_LOADER *loader, CHARSET_INFO *cs; my_pthread_once(&charsets_initialized, init_available_charsets); - cs_number= get_collation_number(name); + cs_number= get_collation_number(name,flags); my_charset_loader_init_mysys(loader); cs= cs_number ? get_internal_charset(loader, cs_number, flags) : NULL; @@ -986,7 +981,7 @@ my_charset_get_by_name(MY_CHARSET_LOADER *loader, my_pthread_once(&charsets_initialized, init_available_charsets); - cs_number= get_charset_number(cs_name, cs_flags); + cs_number= get_charset_number(cs_name, cs_flags, flags); cs= cs_number ? get_internal_charset(loader, cs_number, flags) : NULL; if (!cs && (flags & MY_WME)) @@ -1027,9 +1022,10 @@ get_charset_by_csname(const char *cs_name, uint cs_flags, myf flags) my_bool resolve_charset(const char *cs_name, CHARSET_INFO *default_cs, - CHARSET_INFO **cs) + CHARSET_INFO **cs, + myf flags) { - *cs= get_charset_by_csname(cs_name, MY_CS_PRIMARY, MYF(0)); + *cs= get_charset_by_csname(cs_name, MY_CS_PRIMARY, flags); if (*cs == NULL) { @@ -1059,9 +1055,10 @@ my_bool resolve_charset(const char *cs_name, my_bool resolve_collation(const char *cl_name, CHARSET_INFO *default_cl, - CHARSET_INFO **cl) + CHARSET_INFO **cl, + myf my_flags) { - *cl= get_charset_by_name(cl_name, MYF(0)); + *cl= get_charset_by_name(cl_name, my_flags); if (*cl == NULL) { diff --git a/mysys/test_charset.c b/mysys/test_charset.c index f8392a9d3a9..133a5ca1cbf 100644 --- a/mysys/test_charset.c +++ b/mysys/test_charset.c @@ -70,7 +70,7 @@ int main(int argc, char **argv) { if (argc > argcnt) charsets_dir = argv[argcnt++]; - if (!(cs= get_charset_by_name(the_set, MYF(MY_WME)))) + if (!(cs= get_charset_by_name(the_set, MYF(MY_UTF8_IS_UTF8MB3 | MY_WME)))) return 1; puts("CHARSET INFO:"); |