~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_string.cc

merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1063
1063
  }
1064
1064
}
1065
1065
 
 
1066
/*
 
1067
  Quote the given identifier.
 
1068
  If the given identifier is empty, it will be quoted.
 
1069
 
 
1070
  SYNOPSIS
 
1071
  append_identifier()
 
1072
  name                  the identifier to be appended
 
1073
  name_length           length of the appending identifier
 
1074
*/
 
1075
 
 
1076
/* Factor the extern out */
 
1077
extern const CHARSET_INFO *system_charset_info, *files_charset_info;
 
1078
 
 
1079
void String::append_identifier(const char *name, uint32_t length)
 
1080
{
 
1081
  const char *name_end;
 
1082
  char quote_char;
 
1083
  int q= '`';
 
1084
 
 
1085
  /*
 
1086
    The identifier must be quoted as it includes a quote character or
 
1087
   it's a keyword
 
1088
  */
 
1089
 
 
1090
  reserve(length*2 + 2);
 
1091
  quote_char= (char) q;
 
1092
  append(&quote_char, 1, system_charset_info);
 
1093
 
 
1094
  for (name_end= name+length ; name < name_end ; name+= length)
 
1095
  {
 
1096
    unsigned char chr= (unsigned char) *name;
 
1097
    length= my_mbcharlen(system_charset_info, chr);
 
1098
    /*
 
1099
      my_mbcharlen can return 0 on a wrong multibyte
 
1100
      sequence. It is possible when upgrading from 4.0,
 
1101
      and identifier contains some accented characters.
 
1102
      The manual says it does not work. So we'll just
 
1103
      change length to 1 not to hang in the endless loop.
 
1104
    */
 
1105
    if (!length)
 
1106
      length= 1;
 
1107
    if (length == 1 && chr == (unsigned char) quote_char)
 
1108
      append(&quote_char, 1, system_charset_info);
 
1109
    append(name, length, system_charset_info);
 
1110
  }
 
1111
  append(&quote_char, 1, system_charset_info);
 
1112
}
 
1113
 
1066
1114
 
1067
1115
/*
1068
1116
  Exchange state of this object and argument.