MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / append_identifier

Function append_identifier

sql/sql_show.cc:509–550  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

507*/
508
509void
510append_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(&quote_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(&quote_char, 1, system_charset_info);
547 packet->append(name, length, system_charset_info);
548 }
549 packet->append(&quote_char, 1, system_charset_info);
550}
551
552
553/*

Callers

nothing calls this directly

Calls 4

appendMethod · 0.45
charsetMethod · 0.45
reserveMethod · 0.45

Tested by

no test coverage detected