1
0
mirror of https://github.com/MariaDB/server.git synced 2025-12-24 11:21:21 +03:00

1. fixed bug @2593 "SHOW CREATE TABLE doesn't properly double quotes"

2. added automatic quotation of keywords in SHOW CREATE TABLE
This commit is contained in:
vva@eagle.mysql.r18.ru
2004-02-07 00:57:22 +04:00
parent ed75a5da76
commit e8fb5a1d68
5 changed files with 168 additions and 5 deletions

View File

@@ -1086,7 +1086,6 @@ 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)
{
uint i, d, c;
@@ -1100,17 +1099,47 @@ static bool require_quotes(const char *name, uint length)
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 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;
}
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(name, length, system_charset_info);
@@ -1118,7 +1147,35 @@ append_identifier(THD *thd, String *packet, const char *name, uint length)
}
else
{
packet->append(name, length, system_charset_info);
if (!require_quotes(name, length))
{
if (!(thd->options & OPTION_QUOTE_SHOW_CREATE))
packet->append(name, length, system_charset_info);
else
{
packet->append(&qtype, 1);
packet->append(name, length, system_charset_info);
packet->append(&qtype, 1);
}
}
else
{
packet->append(&qtype, 1);
qplace= look_for_char(name,length,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);
}
}
}