Skip to content

Commit f9762c4

Browse files
author
gluh@eagle.intranet.mysql.r18.ru
committed
Fix for bug #7977 in sql_mode=ANSI, show create table ignores auto_increment
"CHARACTER SET", "COLLATE", and "DEFAULT" are always printed(excepting MODE_MYSQL323 and MODE_MYSQL40) "AUTO_INCREMENT", "ON UPDATE CURRENT_TIMESTAMP" are printed only if NO_FIELD_OPTIONS is not set.
1 parent 68bc5a3 commit f9762c4

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

mysql-test/r/sql_mode.result

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ sql_mode NO_FIELD_OPTIONS,MYSQL323,MYSQL40
6565
show create table t1;
6666
Table Create Table
6767
t1 CREATE TABLE `t1` (
68-
`a` int(11) NOT NULL auto_increment,
68+
`a` int(11) NOT NULL,
6969
`pseudo` varchar(35) NOT NULL default '',
7070
`email` varchar(60) NOT NULL default '',
7171
PRIMARY KEY (`a`),
@@ -79,8 +79,8 @@ show create table t1;
7979
Table Create Table
8080
t1 CREATE TABLE "t1" (
8181
"a" int(11) NOT NULL,
82-
"pseudo" varchar(35) NOT NULL default '',
83-
"email" varchar(60) NOT NULL default '',
82+
"pseudo" varchar(35) character set latin2 NOT NULL default '',
83+
"email" varchar(60) character set latin2 NOT NULL default '',
8484
PRIMARY KEY ("a"),
8585
UNIQUE KEY "email" ("email")
8686
)
@@ -140,3 +140,23 @@ t1 CREATE TABLE `t1` (
140140
drop table t1 ;
141141
set @@SQL_MODE=NULL;
142142
ERROR 42000: Variable 'sql_mode' can't be set to the value of 'NULL'
143+
set session sql_mode=ansi;
144+
create table t1
145+
(f1 integer auto_increment primary key,
146+
f2 timestamp default current_timestamp on update current_timestamp);
147+
show create table t1;
148+
Table Create Table
149+
t1 CREATE TABLE "t1" (
150+
"f1" int(11) NOT NULL auto_increment,
151+
"f2" timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
152+
PRIMARY KEY ("f1")
153+
)
154+
set session sql_mode=no_field_options;
155+
show create table t1;
156+
Table Create Table
157+
t1 CREATE TABLE `t1` (
158+
`f1` int(11) NOT NULL,
159+
`f2` timestamp NOT NULL default CURRENT_TIMESTAMP,
160+
PRIMARY KEY (`f1`)
161+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
162+
drop table t1;

mysql-test/t/sql_mode.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,16 @@ drop table t1 ;
8686
--error 1231
8787
set @@SQL_MODE=NULL;
8888

89+
#
90+
# Bug #797: in sql_mode=ANSI, show create table ignores auto_increment
91+
#
92+
set session sql_mode=ansi;
93+
create table t1
94+
(f1 integer auto_increment primary key,
95+
f2 timestamp default current_timestamp on update current_timestamp);
96+
show create table t1;
97+
set session sql_mode=no_field_options;
98+
show create table t1;
99+
drop table t1;
100+
89101
# End of 4.1 tests

sql/sql_show.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,8 @@ store_create_info(THD *thd, TABLE *table, String *packet)
12991299
field->sql_type(type);
13001300
packet->append(type.ptr(), type.length(), system_charset_info);
13011301

1302-
if (field->has_charset() && !limited_mysql_mode && !foreign_db_mode)
1302+
if (field->has_charset() &&
1303+
!(thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40)))
13031304
{
13041305
if (field->charset() != table->table_charset)
13051306
{
@@ -1337,7 +1338,7 @@ store_create_info(THD *thd, TABLE *table, String *packet)
13371338

13381339
has_default= (field->type() != FIELD_TYPE_BLOB &&
13391340
field->unireg_check != Field::NEXT_NUMBER &&
1340-
!((foreign_db_mode || limited_mysql_mode) &&
1341+
!((thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40)) &&
13411342
has_now_default));
13421343

13431344
if (has_default)
@@ -1367,12 +1368,13 @@ store_create_info(THD *thd, TABLE *table, String *packet)
13671368
packet->append(tmp);
13681369
}
13691370

1370-
if (!foreign_db_mode && !limited_mysql_mode &&
1371+
if (!(thd->variables.sql_mode & MODE_NO_FIELD_OPTIONS) &&
13711372
table->timestamp_field == field &&
13721373
field->unireg_check != Field::TIMESTAMP_DN_FIELD)
13731374
packet->append(" on update CURRENT_TIMESTAMP",28);
13741375

1375-
if (field->unireg_check == Field::NEXT_NUMBER && !foreign_db_mode)
1376+
if (field->unireg_check == Field::NEXT_NUMBER &&
1377+
!(thd->variables.sql_mode & MODE_NO_FIELD_OPTIONS))
13761378
packet->append(" auto_increment", 15 );
13771379

13781380
if (field->comment.length)

0 commit comments

Comments
 (0)