summaryrefslogtreecommitdiff
path: root/sql/sql_show.cc
diff options
context:
space:
mode:
authorunknown <vva@eagle.mysql.r18.ru>2004-02-13 00:31:39 +0400
committerunknown <vva@eagle.mysql.r18.ru>2004-02-13 00:31:39 +0400
commit0bc06e9ec514c618ca2469e284b094fdc6455cc2 (patch)
treec095503979ae96d016976c818eabeaf8c821b7bf /sql/sql_show.cc
parentf2753fe9ac04edac1e8b968d29e77178b4e8c0a5 (diff)
parentb3bf99ed42f6ae344cb646ea421ccba7fbaee69f (diff)
downloadmariadb-git-0bc06e9ec514c618ca2469e284b094fdc6455cc2.tar.gz
Merge eagle.mysql.r18.ru:/home/vva/work/mysql.orig/clear/mysql-4.1
into eagle.mysql.r18.ru:/home/vva/work/BUG_2593/mysql-4.1 sql/mysql_priv.h: Auto merged sql/sql_lex.cc: Auto merged sql/sql_show.cc: Auto merged
Diffstat (limited to 'sql/sql_show.cc')
-rw-r--r--sql/sql_show.cc76
1 files changed, 68 insertions, 8 deletions
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 4da2522bd3f..f076e2fe802 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);
+ }
}
}