| 507 | */ |
| 508 | |
| 509 | void |
| 510 | append_identifier(THD *thd, String *packet, const char *name, uint length) |
| 511 | { |
| 512 | const char *name_end; |
| 513 | char quote_char; |
| 514 | int q; |
| 515 | q= thd ? get_quote_char_for_identifier(thd, name, length) : '`'; |
| 516 | |
| 517 | if (q == EOF) |
| 518 | { |
| 519 | packet->append(name, length, packet->charset()); |
| 520 | return; |
| 521 | } |
| 522 | |
| 523 | /* |
| 524 | The identifier must be quoted as it includes a quote character or |
| 525 | it's a keyword |
| 526 | */ |
| 527 | |
| 528 | (void) packet->reserve(length*2 + 2); |
| 529 | quote_char= (char) q; |
| 530 | packet->append("e_char, 1, system_charset_info); |
| 531 | |
| 532 | for (name_end= name+length ; name < name_end ; name+= length) |
| 533 | { |
| 534 | uchar chr= (uchar) *name; |
| 535 | length= my_mbcharlen(system_charset_info, chr); |
| 536 | /* |
| 537 | my_mbcharlen can return 0 on a wrong multibyte |
| 538 | sequence. It is possible when upgrading from 4.0, |
| 539 | and identifier contains some accented characters. |
| 540 | The manual says it does not work. So we'll just |
| 541 | change length to 1 not to hang in the endless loop. |
| 542 | */ |
| 543 | if (!length) |
| 544 | length= 1; |
| 545 | if (length == 1 && chr == (uchar) quote_char) |
| 546 | packet->append("e_char, 1, system_charset_info); |
| 547 | packet->append(name, length, system_charset_info); |
| 548 | } |
| 549 | packet->append("e_char, 1, system_charset_info); |
| 550 | } |
| 551 | |
| 552 | |
| 553 | /* |
nothing calls this directly
no test coverage detected