@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 */
| 144 | @param name_len Length of the name, in bytes |
| 145 | */ |
| 146 | static char* add_identifier(THD* thd, char *to_p, const char * end_p, |
| 147 | const char* name, size_t name_len) |
| 148 | { |
| 149 | uint res; |
| 150 | uint errors; |
| 151 | const char *conv_name, *conv_name_end; |
| 152 | char tmp_name[FN_REFLEN]; |
| 153 | char conv_string[FN_REFLEN]; |
| 154 | int quote; |
| 155 | |
| 156 | DBUG_ENTER("add_identifier"); |
| 157 | if (!name[name_len]) |
| 158 | conv_name= name; |
| 159 | else |
| 160 | { |
| 161 | strnmov(tmp_name, name, name_len); |
| 162 | tmp_name[name_len]= 0; |
| 163 | conv_name= tmp_name; |
| 164 | } |
| 165 | res= strconvert(&my_charset_filename, conv_name, name_len, |
| 166 | system_charset_info, |
| 167 | conv_string, FN_REFLEN, &errors); |
| 168 | if (unlikely(!res || errors)) |
| 169 | { |
| 170 | DBUG_PRINT("error", ("strconvert of '%s' failed with %u (errors: %u)", conv_name, res, errors)); |
| 171 | conv_name= name; |
| 172 | conv_name_end= name + name_len; |
| 173 | } |
| 174 | else |
| 175 | { |
| 176 | DBUG_PRINT("info", ("conv '%s' -> '%s'", conv_name, conv_string)); |
| 177 | conv_name= conv_string; |
| 178 | conv_name_end= conv_string + res; |
| 179 | } |
| 180 | |
| 181 | quote= (likely(thd) ? |
| 182 | get_quote_char_for_identifier(thd, conv_name, res - 1) : |
| 183 | '`'); |
| 184 | |
| 185 | if (quote != EOF && (end_p - to_p > 2)) |
| 186 | { |
| 187 | *(to_p++)= (char) quote; |
| 188 | while (*conv_name && (end_p - to_p - 1) > 0) |
| 189 | { |
| 190 | int length= system_charset_info->charlen(conv_name, conv_name_end); |
| 191 | if (length <= 0) |
| 192 | length= 1; |
| 193 | if (length == 1 && *conv_name == (char) quote) |
| 194 | { |
| 195 | if ((end_p - to_p) < 3) |
| 196 | break; |
| 197 | *(to_p++)= (char) quote; |
| 198 | *(to_p++)= *(conv_name++); |
| 199 | } |
| 200 | else if (((long) length) < (end_p - to_p)) |
| 201 | { |
| 202 | to_p= strnmov(to_p, conv_name, length); |
| 203 | conv_name+= length; |
no test coverage detected