Commit 5f22379f authored by Sergei Golubchik's avatar Sergei Golubchik

fix for CREATE ... ( ... DEFAULT const_expr ... )

make it return same errors on CREATE as

CREATE ... ( ... DEFAULT const ... )
parent 70390771
......@@ -732,57 +732,20 @@ DROP TABLE t1;
CREATE TABLE t1 (a INT DEFAULT 'x');
ERROR 42000: Invalid default value for 'a'
CREATE TABLE t1 (a INT DEFAULT CONCAT('x'));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT CONCAT('x')
) ENGINE=MyISAM DEFAULT CHARSET=latin1
insert into t1 values();
Warnings:
Warning 1366 Incorrect integer value: 'x' for column 'a' at row 1
DROP TABLE t1;
ERROR 42000: Invalid default value for 'a'
CREATE TABLE t1 (a INT DEFAULT COALESCE('x'));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT COALESCE('x')
) ENGINE=MyISAM DEFAULT CHARSET=latin1
insert into t1 values();
Warnings:
Warning 1366 Incorrect integer value: 'x' for column 'a' at row 1
DROP TABLE t1;
ERROR 42000: Invalid default value for 'a'
CREATE TABLE t1 (a INT DEFAULT (((((COALESCE('x')))))));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT ((((COALESCE('x')))))
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
ERROR 42000: Invalid default value for 'a'
#
# INT: string expressions with numbers + garbage
#
CREATE TABLE t1 (a INT DEFAULT '1x');
ERROR 42000: Invalid default value for 'a'
CREATE TABLE t1 (a INT DEFAULT COALESCE('1x'));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT COALESCE('1x')
) ENGINE=MyISAM DEFAULT CHARSET=latin1
insert into t1 values();
Warnings:
Warning 1265 Data truncated for column 'a' at row 1
DROP TABLE t1;
ERROR 42000: Invalid default value for 'a'
CREATE TABLE t1 (a INT DEFAULT CONCAT('1x'));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT CONCAT('1x')
) ENGINE=MyISAM DEFAULT CHARSET=latin1
insert into t1 values();
Warnings:
Warning 1265 Data truncated for column 'a' at row 1
DROP TABLE t1;
ERROR 42000: Invalid default value for 'a'
#
# INT: string expressions with numbers + trailing space
#
......@@ -800,6 +763,8 @@ a
1
DROP TABLE t1;
CREATE TABLE t1 (a INT DEFAULT CONCAT('1 '));
Warnings:
Note 1265 Data truncated for column 'a' at row 1
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
......@@ -813,6 +778,8 @@ a
1
DROP TABLE t1;
CREATE TABLE t1 (a INT DEFAULT COALESCE('1 '));
Warnings:
Note 1265 Data truncated for column 'a' at row 1
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
......@@ -910,55 +877,23 @@ DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(2) DEFAULT 'xxx' NOT NULL);
ERROR 42000: Invalid default value for 'a'
CREATE TABLE t1 (a VARCHAR(2) DEFAULT CONCAT('xxx') NOT NULL);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` varchar(2) NOT NULL DEFAULT CONCAT('xxx')
) ENGINE=MyISAM DEFAULT CHARSET=latin1
insert into t1 values();
Warnings:
Warning 1265 Data truncated for column 'a' at row 1
DROP TABLE t1;
ERROR 42000: Invalid default value for 'a'
#
# VARCHAR: Too long default with non-important data
#
CREATE TABLE t1 (a VARCHAR(2) DEFAULT 'xx ' NOT NULL);
ERROR 42000: Invalid default value for 'a'
CREATE TABLE t1 (a VARCHAR(2) DEFAULT CONCAT('xx ') NOT NULL);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` varchar(2) NOT NULL DEFAULT CONCAT('xx ')
) ENGINE=MyISAM DEFAULT CHARSET=latin1
insert into t1 values();
Warnings:
Note 1265 Data truncated for column 'a' at row 1
DROP TABLE t1;
ERROR 42000: Invalid default value for 'a'
#
# VARCHAR: conversion failures
#
CREATE TABLE t1 (a VARCHAR(2) CHARACTER SET latin1 DEFAULT _utf8 X'D18F' NOT NULL);
ERROR 42000: Invalid default value for 'a'
CREATE TABLE t1 (a VARCHAR(2) CHARACTER SET latin1 DEFAULT CONCAT(_utf8 X'D18F') NOT NULL);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` varchar(2) NOT NULL DEFAULT CONCAT(_utf8 X'D18F')
) ENGINE=MyISAM DEFAULT CHARSET=latin1
insert into t1 values();
Warnings:
Warning 1366 Incorrect string value: '\xD1\x8F' for column 'a' at row 1
DROP TABLE t1;
ERROR 42000: Invalid default value for 'a'
CREATE TABLE t1 (a VARCHAR(2) CHARACTER SET latin1 DEFAULT CONCAT(_utf8 0xD18F) NOT NULL);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` varchar(2) NOT NULL DEFAULT CONCAT(_utf8 0xD18F)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
insert into t1 values();
Warnings:
Warning 1366 Incorrect string value: '\xD1\x8F' for column 'a' at row 1
DROP TABLE t1;
ERROR 42000: Invalid default value for 'a'
#
# Field as a default value
#
......
......@@ -580,24 +580,12 @@ DROP TABLE t1;
--echo #
--error ER_INVALID_DEFAULT
CREATE TABLE t1 (a INT DEFAULT 'x');
--error ER_INVALID_DEFAULT
CREATE TABLE t1 (a INT DEFAULT CONCAT('x'));
SHOW CREATE TABLE t1;
insert into t1 values();
DROP TABLE t1;
--error ER_INVALID_DEFAULT
CREATE TABLE t1 (a INT DEFAULT COALESCE('x'));
SHOW CREATE TABLE t1;
insert into t1 values();
DROP TABLE t1;
# QQ: shouldn't extra parentheses be removed:
# so SHOW CREATE TABLE reports DEFAULT COALESCE('x')
# rather than DEFAULT ((((COALESCE('x'))))?
--error ER_INVALID_DEFAULT
CREATE TABLE t1 (a INT DEFAULT (((((COALESCE('x')))))));
SHOW CREATE TABLE t1;
DROP TABLE t1;
--echo #
--echo # INT: string expressions with numbers + garbage
......@@ -605,17 +593,10 @@ DROP TABLE t1;
--error ER_INVALID_DEFAULT
CREATE TABLE t1 (a INT DEFAULT '1x');
--error ER_INVALID_DEFAULT
CREATE TABLE t1 (a INT DEFAULT COALESCE('1x'));
SHOW CREATE TABLE t1;
insert into t1 values();
DROP TABLE t1;
--error ER_INVALID_DEFAULT
CREATE TABLE t1 (a INT DEFAULT CONCAT('1x'));
SHOW CREATE TABLE t1;
insert into t1 values();
DROP TABLE t1;
--echo #
--echo # INT: string expressions with numbers + trailing space
......@@ -696,21 +677,16 @@ DROP TABLE t1;
--echo #
--error ER_INVALID_DEFAULT
CREATE TABLE t1 (a VARCHAR(2) DEFAULT 'xxx' NOT NULL);
--error ER_INVALID_DEFAULT
CREATE TABLE t1 (a VARCHAR(2) DEFAULT CONCAT('xxx') NOT NULL);
SHOW CREATE TABLE t1;
insert into t1 values();
DROP TABLE t1;
--echo #
--echo # VARCHAR: Too long default with non-important data
--echo #
--error ER_INVALID_DEFAULT
CREATE TABLE t1 (a VARCHAR(2) DEFAULT 'xx ' NOT NULL);
--error ER_INVALID_DEFAULT
CREATE TABLE t1 (a VARCHAR(2) DEFAULT CONCAT('xx ') NOT NULL);
SHOW CREATE TABLE t1;
insert into t1 values();
DROP TABLE t1;
--echo #
--echo # VARCHAR: conversion failures
......@@ -719,16 +695,10 @@ DROP TABLE t1;
# DEFAULT with a Cyrillic letter for a Latin1 column
--error ER_INVALID_DEFAULT
CREATE TABLE t1 (a VARCHAR(2) CHARACTER SET latin1 DEFAULT _utf8 X'D18F' NOT NULL);
--error ER_INVALID_DEFAULT
CREATE TABLE t1 (a VARCHAR(2) CHARACTER SET latin1 DEFAULT CONCAT(_utf8 X'D18F') NOT NULL);
SHOW CREATE TABLE t1;
insert into t1 values();
DROP TABLE t1;
--error ER_INVALID_DEFAULT
CREATE TABLE t1 (a VARCHAR(2) CHARACTER SET latin1 DEFAULT CONCAT(_utf8 0xD18F) NOT NULL);
SHOW CREATE TABLE t1;
insert into t1 values();
DROP TABLE t1;
--echo #
--echo # Field as a default value
......
......@@ -2995,64 +2995,76 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,
/* Reuse the same loop both for virtual, default and check fields */
for (field_ptr= outparam->field; *field_ptr; field_ptr++)
{
if ((*field_ptr)->vcol_info)
Field *field= *field_ptr;
if (field->vcol_info)
{
Virtual_column_info *vcol;
(*field_ptr)->vcol_info->name.str= (char*) (*field_ptr)->field_name;
if (!(vcol= unpack_vcol_info_from_frm(thd,
&outparam->mem_root,
outparam,
*field_ptr,
(*field_ptr)->vcol_info,
field->vcol_info->name.str= (char*) field->field_name;
if (!(vcol= unpack_vcol_info_from_frm(thd, &outparam->mem_root,
outparam, *field_ptr,
field->vcol_info,
&error_reported)))
{
error= OPEN_FRM_CORRUPTED;
goto err;
}
(*field_ptr)->vcol_info= vcol;
field->vcol_info= vcol;
*(vfield_ptr++)= *field_ptr;
}
if ((*field_ptr)->check_constraint)
if (field->check_constraint)
{
Virtual_column_info *vcol;
(*field_ptr)->check_constraint->name.str=
(char*) (*field_ptr)->field_name;
if (!(vcol= unpack_vcol_info_from_frm(thd,
&outparam->mem_root,
outparam,
0,
(*field_ptr)->check_constraint,
field->check_constraint->name.str=
(char*) field->field_name;
if (!(vcol= unpack_vcol_info_from_frm(thd, &outparam->mem_root,
outparam, 0,
field->check_constraint,
&error_reported)))
{
error= OPEN_FRM_CORRUPTED;
goto err;
}
(*field_ptr)->check_constraint= vcol;
field->check_constraint= vcol;
*(check_constraint_ptr++)= vcol;
}
if ((*field_ptr)->default_value)
if (field->default_value)
{
Virtual_column_info *vcol;
(*field_ptr)->default_value->name.str=
(char*) (*field_ptr)->field_name;
if (!(vcol= unpack_vcol_info_from_frm(thd,
&outparam->mem_root,
outparam,
*field_ptr,
(*field_ptr)->default_value,
field->default_value->name.str=
(char*) field->field_name;
if (!(vcol= unpack_vcol_info_from_frm(thd, &outparam->mem_root,
outparam, *field_ptr,
field->default_value,
&error_reported)))
{
error= OPEN_FRM_CORRUPTED;
goto err;
}
(*field_ptr)->default_value= vcol;
field->default_value= vcol;
if (is_create_table && vcol->expr_item->const_item() &&
!(vcol->flags & (VCOL_NON_DETERMINISTIC | VCOL_TIME_FUNC)))
{
enum_check_fields old_count_cuted_fields= thd->count_cuted_fields;
thd->count_cuted_fields= CHECK_FIELD_WARN; // To find wrong default values
my_ptrdiff_t off= share->default_values - outparam->record[0];
field->move_field_offset(off);
int res= vcol->expr_item->save_in_field(field, 1);
field->move_field_offset(-off);
thd->count_cuted_fields= old_count_cuted_fields;
if (res != 0 && res != 3)
{
my_error(ER_INVALID_DEFAULT, MYF(0), field->field_name);
error= OPEN_FRM_CORRUPTED;
goto err;
}
}
*(dfield_ptr++)= *field_ptr;
}
if (((*field_ptr)->has_insert_default_function() ||
(*field_ptr)->has_update_default_function()))
else
if ((field->has_insert_default_function() ||
field->has_update_default_function()))
*(dfield_ptr++)= *field_ptr;
}
......
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