Commit 2370eeb0 authored by Anel Husakovic's avatar Anel Husakovic Committed by Sergei Golubchik

MDEV-17654 Incorrect syntax returned for column with CHECK constraint in the...

MDEV-17654 Incorrect syntax returned for column with CHECK constraint in the "SHOW CREATE TABLE ..." result

Prepend COMMENT before CHECK constraint in SHOW CREATE

Closes #924
parent dc8e15db
......@@ -111,3 +111,22 @@ long_enough_name CREATE TABLE `long_enough_name` (
CONSTRAINT `constr` CHECK (`f6` >= 0)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE long_enough_name;
CREATE TABLE test.t(t int COMMENT 't_comment' CHECK(t>0));
SHOW CREATE TABLE test.t;
Table Create Table
t CREATE TABLE `t` (
`t` int(11) DEFAULT NULL COMMENT 't_comment' CHECK (`t` > 0)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP table test.t;
SET @OLD_SQL_MODE=@@SQL_MODE;
SET SQL_MODE='IGNORE_BAD_TABLE_OPTIONS';
CREATE TABLE test.t (f int foo=bar check(f>0));
Warnings:
Warning 1911 Unknown option 'foo'
SHOW CREATE TABLE t;
Table Create Table
t CREATE TABLE `t` (
`f` int(11) DEFAULT NULL `foo`=bar CHECK (`f` > 0)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP table test.t;
SET @@SQL_MODE=@OLD_SQL_MODE;
......@@ -102,3 +102,20 @@ SELECT * FROM long_enough_name AS tbl;
SHOW CREATE TABLE long_enough_name;
DROP TABLE long_enough_name;
#
# MDEV-17654 Incorrect syntax returned for column with CHECK constraint
# in the "SHOW CREATE TABLE ..." result
#
CREATE TABLE test.t(t int COMMENT 't_comment' CHECK(t>0));
SHOW CREATE TABLE test.t;
DROP table test.t;
SET @OLD_SQL_MODE=@@SQL_MODE;
SET SQL_MODE='IGNORE_BAD_TABLE_OPTIONS';
CREATE TABLE test.t (f int foo=bar check(f>0));
SHOW CREATE TABLE t;
DROP table test.t;
SET @@SQL_MODE=@OLD_SQL_MODE;
......@@ -2065,6 +2065,16 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
!(sql_mode & MODE_NO_FIELD_OPTIONS))
packet->append(STRING_WITH_LEN(" AUTO_INCREMENT"));
}
if (field->comment.length)
{
packet->append(STRING_WITH_LEN(" COMMENT "));
append_unescaped(packet, field->comment.str, field->comment.length);
}
append_create_options(thd, packet, field->option_list, check_options,
hton->field_options);
if (field->check_constraint)
{
StringBuffer<MAX_FIELD_WIDTH> str(&my_charset_utf8mb4_general_ci);
......@@ -2074,13 +2084,6 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
packet->append(STRING_WITH_LEN(")"));
}
if (field->comment.length)
{
packet->append(STRING_WITH_LEN(" COMMENT "));
append_unescaped(packet, field->comment.str, field->comment.length);
}
append_create_options(thd, packet, field->option_list, check_options,
hton->field_options);
}
key_info= table->key_info;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment