459
Go through all character combinations and ensure that sql_lex.cc can
460
parse it as an identifier.
465
name_length length of name
468
# Pointer to conflicting character
469
0 No conflicting character
472
static const char *require_quotes(const char *name, uint32_t name_length)
475
bool pure_digit= true;
476
const char *end= name + name_length;
478
for (; name < end ; name++)
480
unsigned char chr= (unsigned char) *name;
481
length= my_mbcharlen(system_charset_info, chr);
482
if (length == 1 && !system_charset_info->ident_map[chr])
484
if (length == 1 && (chr < '0' || chr > '9'))
494
Quote the given identifier if needed and append it to the target string.
495
If the given identifier is empty, it will be quoted.
499
session thread handler
501
name the identifier to be appended
502
name_length length of the appending identifier
506
append_identifier(Session *session, String *packet, const char *name, uint32_t length)
508
const char *name_end;
510
int q= get_quote_char_for_identifier(session, name, length);
514
packet->append(name, length, packet->charset());
519
The identifier must be quoted as it includes a quote character or
523
packet->reserve(length*2 + 2);
524
quote_char= (char) q;
525
packet->append("e_char, 1, system_charset_info);
527
for (name_end= name+length ; name < name_end ; name+= length)
529
unsigned char chr= (unsigned char) *name;
530
length= my_mbcharlen(system_charset_info, chr);
532
my_mbcharlen can return 0 on a wrong multibyte
533
sequence. It is possible when upgrading from 4.0,
534
and identifier contains some accented characters.
535
The manual says it does not work. So we'll just
536
change length to 1 not to hang in the endless loop.
540
if (length == 1 && chr == (unsigned char) quote_char)
541
packet->append("e_char, 1, system_charset_info);
542
packet->append(name, length, system_charset_info);
544
packet->append("e_char, 1, system_charset_info);
549
459
Get the quote character for displaying an identifier.
568
478
# Quote character
571
int get_quote_char_for_identifier(Session *session, const char *name, uint32_t length)
481
int get_quote_char_for_identifier(Session *, const char *, uint32_t)
574
!is_keyword(name,length) &&
575
!require_quotes(name, length) &&
576
!(session->options & OPTION_QUOTE_SHOW_CREATE))
715
620
alias= share->table_name.str;
718
append_identifier(session, packet, alias, strlen(alias));
623
packet->append_identifier(alias, strlen(alias));
719
624
packet->append(STRING_WITH_LEN(" (\n"));
721
626
We need this to get default values from the table
732
637
packet->append(STRING_WITH_LEN(",\n"));
734
639
packet->append(STRING_WITH_LEN(" "));
735
append_identifier(session,packet,field->field_name, strlen(field->field_name));
640
packet->append_identifier(field->field_name, strlen(field->field_name));
736
641
packet->append(' ');
737
642
// check for surprises from the previous call to Field::sql_type()
738
643
if (type.ptr() != tmp)
854
759
packet->append(STRING_WITH_LEN("KEY "));
856
761
if (!found_primary)
857
append_identifier(session, packet, key_info->name, strlen(key_info->name));
762
packet->append_identifier(key_info->name, strlen(key_info->name));
859
764
packet->append(STRING_WITH_LEN(" ("));
1054
959
if (create_options & HA_LEX_CREATE_IF_NOT_EXISTS)
1055
960
buffer->append(STRING_WITH_LEN("IF NOT EXISTS "));
1057
append_identifier(session, buffer, dbname, strlen(dbname));
962
buffer->append_identifier(dbname, strlen(dbname));