diff options
author | unknown <pem@mysql.com> | 2004-02-13 17:39:00 +0100 |
---|---|---|
committer | unknown <pem@mysql.com> | 2004-02-13 17:39:00 +0100 |
commit | 078919ad9e01f074c41d2d8311d3e738d299a5d8 (patch) | |
tree | 8bfbeb69721f881bfc6f0a93e5cb203b9810629f /sql/sql_show.cc | |
parent | b5c8de4c835b493f28acfaca681e982046b8d818 (diff) | |
parent | 9a3a0d7d4062982d0977b9268fd599d7b0745c2d (diff) | |
download | mariadb-git-078919ad9e01f074c41d2d8311d3e738d299a5d8.tar.gz |
Merge mysql.com:/home/pem/work/mysql-4.1
into mysql.com:/home/pem/work/mysql-5.0-merge
client/mysql.cc:
Auto merged
libmysql/libmysql.c:
Auto merged
libmysqld/lib_sql.cc:
Auto merged
mysql-test/r/mysqldump.result:
Auto merged
mysql-test/r/show_check.result:
Auto merged
sql/item.cc:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/sql_class.h:
Auto merged
sql/sql_lex.cc:
Auto merged
sql/sql_parse.cc:
Auto merged
sql-common/client.c:
Auto merged
sql/sql_prepare.cc:
Auto merged
sql/sql_show.cc:
Auto merged
sql/sql_table.cc:
Auto merged
sql/sql_yacc.yy:
Auto merged
tests/client_test.c:
Auto merged
Diffstat (limited to 'sql/sql_show.cc')
-rw-r--r-- | sql/sql_show.cc | 76 |
1 files changed, 68 insertions, 8 deletions
diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 3a5f260bf0f..158d9b1acb0 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1085,8 +1085,7 @@ mysqld_dump_create_info(THD *thd, TABLE *table, int fd) DBUG_RETURN(0); } -/* possible TODO: call find_keyword() from sql_lex.cc here */ -static bool require_quotes(const char *name, uint length) +static inline const char *require_quotes(const char *name, uint length) { uint i, d, c; for (i=0; i<length; i+=d) @@ -1094,7 +1093,37 @@ static bool require_quotes(const char *name, uint length) c=((uchar *)name)[i]; d=my_mbcharlen(system_charset_info, c); if (d==1 && !system_charset_info->ident_map[c]) - return 1; + return name+i; + } + return 0; +} + +/* + Looking for char in multibyte string + + SYNOPSIS + look_for_char() + name string for looking at + length length of name + q '\'' or '\"' for looking for + + RETURN VALUES + # pointer to found char in string + 0 string doesn't contain required char +*/ + +static inline const char *look_for_char(const char *name, + uint length, char q) +{ + const char *cur= name; + const char *end= cur+length; + uint symbol_length; + for (; cur<end; cur+= symbol_length) + { + char c= *cur; + symbol_length= my_mbcharlen(system_charset_info, c); + if (symbol_length==1 && c==q) + return cur; } return 0; } @@ -1103,21 +1132,52 @@ void append_identifier(THD *thd, String *packet, const char *name, uint length) { char qtype; + uint part_len; + const char *qplace; if (thd->variables.sql_mode & MODE_ANSI_QUOTES) qtype= '\"'; else qtype= '`'; - if ((thd->options & OPTION_QUOTE_SHOW_CREATE) || - require_quotes(name, length)) + if (is_keyword(name,length)) { - packet->append(&qtype, 1); + packet->append(&qtype, 1, system_charset_info); packet->append(name, length, system_charset_info); - packet->append(&qtype, 1); + packet->append(&qtype, 1, system_charset_info); } else { - packet->append(name, length, system_charset_info); + if (!(qplace= require_quotes(name, length))) + { + if (!(thd->options & OPTION_QUOTE_SHOW_CREATE)) + packet->append(name, length, system_charset_info); + else + { + packet->append(&qtype, 1, system_charset_info); + packet->append(name, length, system_charset_info); + packet->append(&qtype, 1, system_charset_info); + } + } + else + { + packet->shrink(packet->length()+length+2); + packet->append(&qtype, 1, system_charset_info); + if (*qplace != qtype) + qplace= look_for_char(qplace+1,length-(qplace-name)-1,qtype); + while (qplace) + { + if ((part_len= qplace-name)) + { + packet->append(name, part_len, system_charset_info); + length-= part_len; + } + packet->append(qplace, 1, system_charset_info); + name= qplace; + qplace= look_for_char(name+1,length-1,qtype); + } + packet->append(name, length, system_charset_info); + packet->append(&qtype, 1, system_charset_info); + } } } |