summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/show_check.result25
-rw-r--r--mysql-test/t/show_check.test9
-rw-r--r--sql/sql_show.cc16
3 files changed, 43 insertions, 7 deletions
diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result
index f39fa3e7576..290f916ae72 100644
--- a/mysql-test/r/show_check.result
+++ b/mysql-test/r/show_check.result
@@ -88,20 +88,37 @@ drop table t2;
create table t1 (
test_set set( 'val1', 'val2', 'val3' ) not null default '',
name char(20) default 'O''Brien' comment 'O''Brien as default',
-c int not null comment 'int column'
- ) comment = 'it\'s a table' ;
-show create table t1 ;
+c int not null comment 'int column',
+`c-b` int comment 'name with a space',
+`space ` int comment 'name with a space',
+) comment = 'it\'s a table' ;
+show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`test_set` set('val1','val2','val3') NOT NULL default '',
`name` char(20) default 'O''Brien' COMMENT 'O''Brien as default',
- `c` int(11) NOT NULL default '0' COMMENT 'int column'
+ `c` int(11) NOT NULL default '0' COMMENT 'int column',
+ `c-b` int(11) default NULL COMMENT 'name with a space',
+ `space ` int(11) default NULL COMMENT 'name with a space'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='it''s a table'
+set sql_quote_show_create=0;
+show create table t1;
+Table Create Table
+t1 CREATE TABLE t1 (
+ test_set set('val1','val2','val3') NOT NULL default '',
+ name char(20) default 'O''Brien' COMMENT 'O''Brien as default',
+ c int(11) NOT NULL default '0' COMMENT 'int column',
+ `c-b` int(11) default NULL COMMENT 'name with a space',
+ `space ` int(11) default NULL COMMENT 'name with a space'
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='it''s a table'
+set sql_quote_show_create=1;
show full columns from t1;
Field Type Collation Null Key Default Extra Privileges Comment
test_set set('val1','val2','val3') latin1_swedish_ci select,insert,update,references
name char(20) latin1_swedish_ci YES O'Brien select,insert,update,references O'Brien as default
c int(11) NULL 0 select,insert,update,references int column
+c-b int(11) NULL YES NULL select,insert,update,references name with a space
+space int(11) NULL YES NULL select,insert,update,references name with a space
drop table t1;
create table t1 (a int not null, unique aa (a));
show create table t1;
diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test
index 4ab39e3ccbc..d262f02c978 100644
--- a/mysql-test/t/show_check.test
+++ b/mysql-test/t/show_check.test
@@ -53,9 +53,14 @@ drop table t2;
create table t1 (
test_set set( 'val1', 'val2', 'val3' ) not null default '',
name char(20) default 'O''Brien' comment 'O''Brien as default',
- c int not null comment 'int column'
+ c int not null comment 'int column',
+ `c-b` int comment 'name with a space',
+ `space ` int comment 'name with a space',
) comment = 'it\'s a table' ;
-show create table t1 ;
+show create table t1;
+set sql_quote_show_create=0;
+show create table t1;
+set sql_quote_show_create=1;
show full columns from t1;
drop table t1;
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 984d57fc354..4ae59093a0e 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -997,6 +997,19 @@ 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;
+ for (i=0; i<length; i+=d)
+ {
+ c=((uchar *)name)[i];
+ d=my_mbcharlen(system_charset_info, c);
+ if (d==1 && !system_charset_info->ident_map[c])
+ return 1;
+ }
+ return 0;
+}
void
append_identifier(THD *thd, String *packet, const char *name, uint length)
@@ -1007,7 +1020,8 @@ append_identifier(THD *thd, String *packet, const char *name, uint length)
else
qtype= '`';
- if (thd->options & OPTION_QUOTE_SHOW_CREATE)
+ if ((thd->options & OPTION_QUOTE_SHOW_CREATE) ||
+ require_quotes(name, length))
{
packet->append(&qtype, 1);
packet->append(name, length, system_charset_info);