@brief Helper function for explain_filename @param thd Thread handle @param to_p Explained name in system_charset_info @param end_p End of the to_p buffer @param name Name to be converted @param name_len Length of the name, in bytes */
| 74 | @param name_len Length of the name, in bytes |
| 75 | */ |
| 76 | static char* add_identifier(THD* thd, char *to_p, const char * end_p, |
| 77 | const char* name, uint name_len) |
| 78 | { |
| 79 | uint res; |
| 80 | uint errors; |
| 81 | const char *conv_name; |
| 82 | char tmp_name[FN_REFLEN]; |
| 83 | char conv_string[FN_REFLEN]; |
| 84 | int quote; |
| 85 | |
| 86 | DBUG_ENTER("add_identifier"); |
| 87 | if (!name[name_len]) |
| 88 | conv_name= name; |
| 89 | else |
| 90 | { |
| 91 | strnmov(tmp_name, name, name_len); |
| 92 | tmp_name[name_len]= 0; |
| 93 | conv_name= tmp_name; |
| 94 | } |
| 95 | res= strconvert(&my_charset_filename, conv_name, system_charset_info, |
| 96 | conv_string, FN_REFLEN, &errors); |
| 97 | if (!res || errors) |
| 98 | { |
| 99 | DBUG_PRINT("error", ("strconvert of '%s' failed with %u (errors: %u)", conv_name, res, errors)); |
| 100 | conv_name= name; |
| 101 | } |
| 102 | else |
| 103 | { |
| 104 | DBUG_PRINT("info", ("conv '%s' -> '%s'", conv_name, conv_string)); |
| 105 | conv_name= conv_string; |
| 106 | } |
| 107 | |
| 108 | quote = thd ? get_quote_char_for_identifier(thd, conv_name, res - 1) : '"'; |
| 109 | |
| 110 | if (quote != EOF && (end_p - to_p > 2)) |
| 111 | { |
| 112 | *(to_p++)= (char) quote; |
| 113 | while (*conv_name && (end_p - to_p - 1) > 0) |
| 114 | { |
| 115 | uint length= my_mbcharlen(system_charset_info, *conv_name); |
| 116 | if (!length) |
| 117 | length= 1; |
| 118 | if (length == 1 && *conv_name == (char) quote) |
| 119 | { |
| 120 | if ((end_p - to_p) < 3) |
| 121 | break; |
| 122 | *(to_p++)= (char) quote; |
| 123 | *(to_p++)= *(conv_name++); |
| 124 | } |
| 125 | else if (((long) length) < (end_p - to_p)) |
| 126 | { |
| 127 | to_p= strnmov(to_p, conv_name, length); |
| 128 | conv_name+= length; |
| 129 | } |
| 130 | else |
| 131 | break; /* string already filled */ |
| 132 | } |
| 133 | if (end_p > to_p) { |
no test coverage detected