diff options
author | Michael Widenius <monty@mariadb.org> | 2016-06-24 23:42:35 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2016-06-30 11:43:02 +0200 |
commit | fb67cde2370f7427b3279309daac712c369f1cf8 (patch) | |
tree | 94eecb3c669fdf00957f49741b75ee6eec057826 /mysql-test | |
parent | 8f226121e52cbaa332964b24bd27e8babf9f2b06 (diff) | |
download | mariadb-git-fb67cde2370f7427b3279309daac712c369f1cf8.tar.gz |
Use default character set for expressions
- Force usage of () around complex DEFAULT expressions
- Give error if DEFAULT expression contains invalid characters
- Don't use const_charset_conversion for stored Item_func_sysconf expressions
as the result is not constaint over different executions
- Fixed Item_func_user() to not store calculated value in str_value
Diffstat (limited to 'mysql-test')
-rw-r--r-- | mysql-test/r/default.result | 183 | ||||
-rw-r--r-- | mysql-test/suite/rpl/r/rpl_default.result | 4 | ||||
-rw-r--r-- | mysql-test/suite/rpl/t/rpl_default.test | 2 | ||||
-rw-r--r-- | mysql-test/t/default.test | 116 |
4 files changed, 191 insertions, 114 deletions
diff --git a/mysql-test/r/default.result b/mysql-test/r/default.result index b3e00c092c1..26d04cc2656 100644 --- a/mysql-test/r/default.result +++ b/mysql-test/r/default.result @@ -264,13 +264,13 @@ drop table t1; Check default expressions -create or replace table t1 (a int default 1, b int default a+1, c int default a+b) engine myisam; +create or replace table t1 (a int default 1, b int default (a+1), c int default (a+b)) engine myisam; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `a` int(11) DEFAULT '1', - `b` int(11) DEFAULT a+1, - `c` int(11) DEFAULT a+b + `b` int(11) DEFAULT (a+1), + `c` int(11) DEFAULT (a+b) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 insert into t1 values (); insert into t1 (a) values (2); @@ -299,9 +299,9 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `a` int(11) DEFAULT NULL, - `b` blob DEFAULT (1), - `c` blob DEFAULT ("hello"), - `t` text DEFAULT (concat(a,b,c)) + `b` blob DEFAULT 1, + `c` blob DEFAULT "hello", + `t` text DEFAULT concat(a,b,c) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 insert into t1 (a) values (2); insert into t1 (a,b) values (10,"test1"); @@ -323,16 +323,17 @@ a > 0 drop table t1; create or replace table t1 (param_list int DEFAULT (1+1) NOT NULL); create or replace table t1 (param_list int DEFAULT 1+1 NOT NULL); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '+1 NOT NULL)' at line 1 create or replace table t1 (param_list blob DEFAULT "" NOT NULL); drop table t1; create table t1 (a int); insert into t1 values(-1); -alter table t1 add b int default 1, add c int default -1, add d int default 1+1, add e timestamp; +alter table t1 add b int default 1, add c int default -1, add d int default (1+1), add e timestamp; select a,b,c,d,e > 0 from t1; a b c d e > 0 -1 1 -1 2 1 insert into t1 values(10,10,10,10,0); -alter table t1 add f int default 1+1+1 null, add g int default 1+1+1+1 not null,add h int default (2+2+2+2); +alter table t1 add f int default (1+1+1) null, add g int default (1+1+1+1) not null,add h int default (2+2+2+2); select a,b,c,d,e > 0,f,g,h from t1; a b c d e > 0 f g h -1 1 -1 2 1 3 4 8 @@ -343,10 +344,10 @@ t1 CREATE TABLE `t1` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT '1', `c` int(11) DEFAULT '-1', - `d` int(11) DEFAULT 1+1, + `d` int(11) DEFAULT (1+1), `e` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `f` int(11) DEFAULT 1+1+1, - `g` int(11) NOT NULL DEFAULT 1+1+1+1, + `f` int(11) DEFAULT (1+1+1), + `g` int(11) NOT NULL DEFAULT (1+1+1+1), `h` int(11) DEFAULT (2+2+2+2) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 create table t2 like t1; @@ -356,10 +357,10 @@ t2 CREATE TABLE `t2` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT '1', `c` int(11) DEFAULT '-1', - `d` int(11) DEFAULT 1+1, + `d` int(11) DEFAULT (1+1), `e` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `f` int(11) DEFAULT 1+1+1, - `g` int(11) NOT NULL DEFAULT 1+1+1+1, + `f` int(11) DEFAULT (1+1+1), + `g` int(11) NOT NULL DEFAULT (1+1+1+1), `h` int(11) DEFAULT (2+2+2+2) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 insert into t2 (a) values (100); @@ -367,18 +368,21 @@ select a,b,c,d,e > 0,f,g,h from t2; a b c d e > 0 f g h 100 1 -1 2 1 3 4 8 drop table t1,t2; -create table t1 (a int default 1----1); +create table t1 (a int default (1----1), b int default - 1, c int default +1, e int default (--1)); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `a` int(11) DEFAULT 1----1 + `a` int(11) DEFAULT (1----1), + `b` int(11) DEFAULT '-1', + `c` int(11) DEFAULT '1', + `e` int(11) DEFAULT '1' ) ENGINE=MyISAM DEFAULT CHARSET=latin1 insert into t1 values(); insert into t1 values(); select * from t1; -a -2 -2 +a b c e +2 -1 1 1 +2 -1 1 1 drop table t1; create or replace can delete a table on error @@ -395,15 +399,15 @@ create or replace table t1 (a int default 1, b int default a); create or replace table t1 (a int default 1, b int as (a)); create or replace table t1 (a int default b, b int default 1); create or replace table t1 (a int as (b), b int default 1); -create or replace table t1 (a int as (b), b int default 1+1); +create or replace table t1 (a int as (b), b int default (1+1)); create or replace table t1 (a int default 1, b int as (c), c int default (a+1)); -create or replace table t1 (a int default 1+1, b int as (c), c int default (a+1)); +create or replace table t1 (a int default (1+1), b int as (c), c int default (a+1)); create or replace table t1 (a VARCHAR(128) DEFAULT @@version); create or replace table t1 (a int not null, b int as (a)); -create or replace table t1 (a int not null, b int default a+1); +create or replace table t1 (a int not null, b int default (a+1)); create or replace table t1 (a int default a); ERROR 01000: Expression for field `a` is refering to uninitialized field `a` -create or replace table t1 (a int default b, b int default 1+1); +create or replace table t1 (a int default b, b int default (1+1)); ERROR 01000: Expression for field `a` is refering to uninitialized field `b` create or replace table t1 (a int default 1, b int as (c), c int as (a+1)); ERROR 01000: Expression for field `b` is refering to uninitialized field `c` @@ -446,16 +450,22 @@ Error handling create or replace table t1 (a bigint default xxx()); ERROR HY000: Function or expression '`xxx`' is not allowed for 'DEFAULT' of column/constraint 'a' create or replace table t1 (a bigint default (select (1))); -ERROR HY000: Function or expression 'subselect' is not allowed for 'DEFAULT' of column/constraint 'a' -create or replace table t1 (a bigint default (1,2,3))); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'select (1)))' at line 1 +create or replace table t1 (a bigint default (1,2,3)); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '2,3))' at line 1 +create or replace table t1 (a bigint default ((1,2,3))); ERROR 21000: Operand should contain 1 column(s) +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a DIV b); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DIV b)' at line 1 +CREATE TABLE t1 (a INT, b INT DEFAULT -a); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'a)' at line 1 drop table if exists t1; Warnings: Note 1051 Unknown table 'test.t1' # # Invalid DEFAULT expressions # -CREATE TABLE t1 (a INT DEFAULT (SELECT 1)); +CREATE TABLE t1 (a INT DEFAULT ((SELECT 1))); ERROR HY000: Function or expression 'subselect' is not allowed for 'DEFAULT' of column/constraint 'a' CREATE TABLE t1 (a INT DEFAULT (EXISTS (SELECT 1))); ERROR HY000: Function or expression 'subselect' is not allowed for 'DEFAULT' of column/constraint 'a' @@ -463,14 +473,12 @@ CREATE TABLE t1 (a INT DEFAULT (1=ANY (SELECT 1))); ERROR HY000: Function or expression 'subselect' is not allowed for 'DEFAULT' of column/constraint 'a' CREATE TABLE t1 (a INT DEFAULT ROW(1,1)); ERROR 21000: Operand should contain 1 column(s) -CREATE TABLE t1 (a INT DEFAULT (1,1)); -ERROR 21000: Operand should contain 1 column(s) CREATE TABLE t1 (a INT DEFAULT ((1,1))); ERROR 21000: Operand should contain 1 column(s) CREATE TABLE t1 (a INT DEFAULT ?); -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?)' at line 1 +Got one of the listed errors CREATE TABLE t1 (a INT DEFAULT(?)); -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?))' at line 1 +Got one of the listed errors CREATE TABLE t1 (a INT DEFAULT (b), b INT DEFAULT(a)); ERROR 01000: Expression for field `a` is refering to uninitialized field `b` CREATE TABLE t1 (a INT DEFAULT @v); @@ -546,7 +554,7 @@ DEALLOCATE PREPARE stmt; PREPARE stmt FROM 'CREATE TABLE t1 (a INT DEFAULT(?+?))'; set @a=1; execute stmt using @a,@a; -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?+?))' at line 1 +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?+?)' at line 1 DEALLOCATE PREPARE stmt; # # Parenthesized Item_basic_constant @@ -920,7 +928,7 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `a` int(11) DEFAULT NULL, - `b` int(11) DEFAULT (a) + `b` int(11) DEFAULT a ) ENGINE=MyISAM DEFAULT CHARSET=latin1 INSERT INTO t1 VALUES (1, 1); INSERT INTO t1 VALUES (DEFAULT, DEFAULT); @@ -940,7 +948,7 @@ CREATE TABLE t1 (a INT DEFAULT(DEFAULT(b)), b INT DEFAULT 1); SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( - `a` int(11) DEFAULT (DEFAULT(b)), + `a` int(11) DEFAULT DEFAULT(b), `b` int(11) DEFAULT '1' ) ENGINE=MyISAM DEFAULT CHARSET=latin1 INSERT INTO t1 VALUES (DEFAULT, DEFAULT); @@ -953,7 +961,7 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `a` int(11) DEFAULT '1', - `b` int(11) DEFAULT (DEFAULT(a)) + `b` int(11) DEFAULT DEFAULT(a) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 INSERT INTO t1 VALUES (DEFAULT, DEFAULT); SELECT * FROM t1; @@ -1135,7 +1143,7 @@ DROP TABLE t1; # # Check DEFAULT() function # -CREATE TABLE `t1` (`a` int(11) DEFAULT 3+3,`b` int(11) DEFAULT '1000'); +CREATE TABLE `t1` (`a` int(11) DEFAULT (3+3),`b` int(11) DEFAULT '1000'); insert into t1 values (1,1),(2,2); insert into t1 values (default,default); select * from t1; @@ -1210,7 +1218,7 @@ SELECT * FROM t1; a b 34 3 DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a DIV b); +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a DIV b)); INSERT INTO t1 (a, b) VALUES (13, 3); SELECT * FROM t1; a b c @@ -1268,6 +1276,8 @@ CREATE TABLE t1 (a INT DEFAULT MASTER_POS_WAIT('test',100)); ERROR HY000: Function or expression 'master_pos_wait' is not allowed for 'DEFAULT' of column/constraint 'a' CREATE TABLE t1 (a INT DEFAULT MASTER_GTID_WAIT('test')); ERROR HY000: Function or expression 'master_gtid_wait' is not allowed for 'DEFAULT' of column/constraint 'a' +CREATE TABLE t1 (a VARCHAR(30), b DOUBLE DEFAULT MATCH (a) AGAINST('bbbb' IN BOOLEAN MODE)); +ERROR HY000: Function or expression 'match' is not allowed for 'DEFAULT' of column/constraint 'b' # # Temporal functions # @@ -1601,7 +1611,13 @@ a b c 0 1 2 1 1 1 DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT DEFAULT -a); +CREATE TABLE t1 (a INT, b INT DEFAULT (-a)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT (-a) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 INSERT INTO t1 VALUES (10, DEFAULT); SELECT * FROM t1; a b @@ -1621,13 +1637,22 @@ a b c d 1.5 2 1 2 -1.5 -1 -2 -2 DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a+b, d INT DEFAULT a-b); +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a+b), d INT DEFAULT (a-b)); INSERT INTO t1 VALUES (2, 1, DEFAULT, DEFAULT); SELECT * FROM t1; a b c d 2 1 3 1 DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a*b, d INT DEFAULT a/b, e INT DEFAULT a MOD b); +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a*b), d INT DEFAULT (a/b), e INT DEFAULT (a MOD b)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL, + `c` int(11) DEFAULT (a*b), + `d` int(11) DEFAULT (a/b), + `e` int(11) DEFAULT (a MOD b) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 INSERT INTO t1 VALUES (7, 3, DEFAULT, DEFAULT, DEFAULT); SELECT * FROM t1; a b c d e @@ -1699,8 +1724,16 @@ CREATE TABLE t1 ( a VARCHAR(10) CHARACTER SET latin1, b VARCHAR(10) CHARACTER SET latin1 DEFAULT a COLLATE latin1_bin, c VARCHAR(10) CHARACTER SET utf8 DEFAULT CONVERT(a USING utf8), -d VARBINARY(10) DEFAULT BINARY(a) +d VARBINARY(10) DEFAULT (BINARY(a)) ); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(10) DEFAULT NULL, + `b` varchar(10) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT a, + `c` varchar(10) CHARACTER SET utf8 DEFAULT CONVERT(a USING utf8), + `d` varbinary(10) DEFAULT (BINARY(a)) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 INSERT INTO t1 (a) VALUES ('a'); SELECT * FROM t1; a b c d @@ -1715,31 +1748,39 @@ SELECT * FROM t1; a b 7 3 DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a|b); +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a|b)); INSERT INTO t1 (a,b) VALUES (1,2); SELECT * FROM t1; a b c 1 2 3 DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a&b); +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a&b)); INSERT INTO t1 (a,b) VALUES (5,4); SELECT * FROM t1; a b c 5 4 4 DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a^b); +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a^b)); INSERT INTO t1 (a,b) VALUES (11,3); SELECT * FROM t1; a b c 11 3 8 DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a&~b); +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a&~b)); INSERT INTO t1 (a,b) VALUES (5,1); SELECT * FROM t1; a b c 5 1 4 DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a<<b, d INT DEFAULT a>>b); +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a<<b), d INT DEFAULT (a>>b)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL, + `c` int(11) DEFAULT (a<<b), + `d` int(11) DEFAULT (a>>b) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 INSERT INTO t1 (a,b) VALUES (5,1); SELECT * FROM t1; a b c d @@ -1918,7 +1959,13 @@ ERROR HY000: Function or expression 'load_file' is not allowed for 'DEFAULT' of # # Predicates # -CREATE TABLE t1 (a INT, b INT DEFAULT NOT a); +CREATE TABLE t1 (a INT, b INT DEFAULT (NOT a)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT (NOT a) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 INSERT INTO t1 (a) VALUES (NULL),(0),(1); SELECT * FROM t1; a b @@ -1926,7 +1973,7 @@ NULL NULL 0 1 1 0 DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT, x INT DEFAULT a XOR b); +CREATE TABLE t1 (a INT, b INT, x INT DEFAULT (a XOR b)); INSERT INTO t1 (a,b) VALUES (0,0),(0,1),(1,0),(1,1); SELECT * FROM t1; a b x @@ -1935,7 +1982,14 @@ a b x 1 0 1 1 1 0 DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT DEFAULT a IS TRUE, c INT DEFAULT a IS NOT TRUE); +CREATE TABLE t1 (a INT, b INT DEFAULT (a IS TRUE), c INT DEFAULT (a IS NOT TRUE)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT (a IS TRUE), + `c` int(11) DEFAULT (a IS NOT TRUE) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 INSERT INTO t1 (a) VALUES (NULL),(0),(1); SELECT * FROM t1; a b c @@ -1943,7 +1997,7 @@ NULL 0 1 0 0 1 1 1 0 DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT DEFAULT a IS FALSE, c INT DEFAULT a IS NOT FALSE); +CREATE TABLE t1 (a INT, b INT DEFAULT (a IS FALSE), c INT DEFAULT (a IS NOT FALSE)); INSERT INTO t1 (a) VALUES (NULL),(0),(1); SELECT * FROM t1; a b c @@ -1951,7 +2005,7 @@ NULL 0 1 0 1 0 1 0 1 DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT DEFAULT a IS NULL, c INT DEFAULT a IS NOT NULL); +CREATE TABLE t1 (a INT, b INT DEFAULT (a IS NULL), c INT DEFAULT (a IS NOT NULL)); INSERT INTO t1 (a) VALUES (NULL),(0),(1); SELECT * FROM t1; a b c @@ -1959,7 +2013,7 @@ NULL 1 0 0 0 1 1 0 1 DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT DEFAULT a IS UNKNOWN, c INT DEFAULT a IS NOT UNKNOWN); +CREATE TABLE t1 (a INT, b INT DEFAULT (a IS UNKNOWN), c INT DEFAULT (a IS NOT UNKNOWN)); INSERT INTO t1 (a) VALUES (NULL),(0),(1); SELECT * FROM t1; a b c @@ -1968,10 +2022,10 @@ NULL 1 0 1 0 1 DROP TABLE t1; CREATE TABLE t1 (a INT, -eq INT DEFAULT a=0, equal INT DEFAULT a<=>0, -ne INT DEFAULT a<>0, -lt INT DEFAULT a<0, le INT DEFAULT a<=0, -gt INT DEFAULT a>0, ge INT DEFAULT a>=0); +eq INT DEFAULT (a=0), equal INT DEFAULT (a<=>0), +ne INT DEFAULT (a<>0), +lt INT DEFAULT (a<0), le INT DEFAULT (a<=0), +gt INT DEFAULT (a>0), ge INT DEFAULT (a>=0)); INSERT INTO t1 (a) VALUES (NULL),(-1),(0),(1); SELECT * FROM t1; a eq equal ne lt le gt ge @@ -1980,7 +2034,7 @@ NULL NULL 0 NULL NULL NULL NULL NULL 0 1 1 0 0 1 0 1 1 0 0 1 0 0 1 1 DROP TABLE t1; -CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT a LIKE 'a%'); +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT (a LIKE 'a%')); INSERT INTO t1 (a) VALUES ('AAA'),('aaa'),('bbb'); SELECT * FROM t1; a b @@ -1988,7 +2042,7 @@ AAA 1 aaa 1 bbb 0 DROP TABLE t1; -CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT a RLIKE 'a$'); +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT (a RLIKE 'a$')); INSERT INTO t1 (a) VALUES ('AAA'),('aaa'),('bbb'); SELECT * FROM t1; a b @@ -1996,7 +2050,7 @@ AAA 1 aaa 1 bbb 0 DROP TABLE t1; -CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT a IN ('aaa','bbb')); +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT (a IN ('aaa','bbb'))); INSERT INTO t1 (a) VALUES ('AAA'),('aaa'),('bbb'),('ccc'); SELECT * FROM t1; a b @@ -2005,7 +2059,7 @@ aaa 1 bbb 1 ccc 0 DROP TABLE t1; -CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT a NOT IN ('aaa','bbb')); +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT (a NOT IN ('aaa','bbb'))); INSERT INTO t1 (a) VALUES ('AAA'),('aaa'),('bbb'),('ccc'); SELECT * FROM t1; a b @@ -2014,7 +2068,7 @@ aaa 0 bbb 0 ccc 1 DROP TABLE t1; -CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT a BETWEEN 'aaa' AND 'bbb'); +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT (a BETWEEN 'aaa' AND 'bbb')); INSERT INTO t1 (a) VALUES ('AAA'),('aaa'),('bbb'),('ccc'); SELECT * FROM t1; a b @@ -2023,7 +2077,7 @@ aaa 1 bbb 1 ccc 0 DROP TABLE t1; -CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT a NOT BETWEEN 'aaa' AND 'bbb'); +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT (a NOT BETWEEN 'aaa' AND 'bbb')); INSERT INTO t1 (a) VALUES ('AAA'),('aaa'),('bbb'),('ccc'); SELECT * FROM t1; a b @@ -2159,3 +2213,10 @@ SELECT c FROM t1; c test DROP TABLE t1; +# +# Collations +# +CREATE TABLE t1 (a VARCHAR(20) CHARACTER SET latin1 DEFAULT CONCAT('ö')) CHARACTER SET koi8r COLLATE koi8r_bin; +ERROR 22007: Encountered illegal value 'ö' when converting to koi8r +CREATE OR REPLACE TABLE t1 (a char(2) default concat('A') COLLATE utf8mb4_unicode_ci); +DROP TABLE t1; diff --git a/mysql-test/suite/rpl/r/rpl_default.result b/mysql-test/suite/rpl/r/rpl_default.result index 5edd01a60b2..a1629b99bb3 100644 --- a/mysql-test/suite/rpl/r/rpl_default.result +++ b/mysql-test/suite/rpl/r/rpl_default.result @@ -1,14 +1,14 @@ include/master-slave.inc [connection master] connection master; -create table t1 (a int DEFAULT 1+1, b bigint default uuid_short(), u blob default user()); +create table t1 (a int DEFAULT (1+1), b bigint default uuid_short(), u blob default user()); insert into t1 (a) values(1); connection slave; connection slave; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `a` int(11) DEFAULT 1+1, + `a` int(11) DEFAULT (1+1), `b` bigint(20) DEFAULT uuid_short(), `u` blob DEFAULT user() ) ENGINE=MyISAM DEFAULT CHARSET=latin1 diff --git a/mysql-test/suite/rpl/t/rpl_default.test b/mysql-test/suite/rpl/t/rpl_default.test index 03f24418f77..9adf15c93ac 100644 --- a/mysql-test/suite/rpl/t/rpl_default.test +++ b/mysql-test/suite/rpl/t/rpl_default.test @@ -9,7 +9,7 @@ connection master; -create table t1 (a int DEFAULT 1+1, b bigint default uuid_short(), u blob default user()); +create table t1 (a int DEFAULT (1+1), b bigint default uuid_short(), u blob default user()); insert into t1 (a) values(1); let $b=query_get_value(select * from t1, b, 1); diff --git a/mysql-test/t/default.test b/mysql-test/t/default.test index 7969016c2ee..f56b559991a 100644 --- a/mysql-test/t/default.test +++ b/mysql-test/t/default.test @@ -207,7 +207,7 @@ drop table t1; --echo Check default expressions --echo -create or replace table t1 (a int default 1, b int default a+1, c int default a+b) engine myisam; +create or replace table t1 (a int default 1, b int default (a+1), c int default (a+b)) engine myisam; show create table t1; insert into t1 values (); insert into t1 (a) values (2); @@ -238,16 +238,18 @@ select a > 0 from t1; drop table t1; create or replace table t1 (param_list int DEFAULT (1+1) NOT NULL); +--error ER_PARSE_ERROR create or replace table t1 (param_list int DEFAULT 1+1 NOT NULL); create or replace table t1 (param_list blob DEFAULT "" NOT NULL); + drop table t1; create table t1 (a int); insert into t1 values(-1); -alter table t1 add b int default 1, add c int default -1, add d int default 1+1, add e timestamp; +alter table t1 add b int default 1, add c int default -1, add d int default (1+1), add e timestamp; select a,b,c,d,e > 0 from t1; insert into t1 values(10,10,10,10,0); -alter table t1 add f int default 1+1+1 null, add g int default 1+1+1+1 not null,add h int default (2+2+2+2); +alter table t1 add f int default (1+1+1) null, add g int default (1+1+1+1) not null,add h int default (2+2+2+2); select a,b,c,d,e > 0,f,g,h from t1; show create table t1; @@ -257,7 +259,7 @@ insert into t2 (a) values (100); select a,b,c,d,e > 0,f,g,h from t2; drop table t1,t2; -create table t1 (a int default 1----1); +create table t1 (a int default (1----1), b int default - 1, c int default +1, e int default (--1)); show create table t1; insert into t1 values(); insert into t1 values(); @@ -281,18 +283,18 @@ create or replace table t1 (a int default 1, b int default a); create or replace table t1 (a int default 1, b int as (a)); create or replace table t1 (a int default b, b int default 1); create or replace table t1 (a int as (b), b int default 1); -create or replace table t1 (a int as (b), b int default 1+1); +create or replace table t1 (a int as (b), b int default (1+1)); create or replace table t1 (a int default 1, b int as (c), c int default (a+1)); -create or replace table t1 (a int default 1+1, b int as (c), c int default (a+1)); +create or replace table t1 (a int default (1+1), b int as (c), c int default (a+1)); create or replace table t1 (a VARCHAR(128) DEFAULT @@version); create or replace table t1 (a int not null, b int as (a)); -create or replace table t1 (a int not null, b int default a+1); +create or replace table t1 (a int not null, b int default (a+1)); --error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD create or replace table t1 (a int default a); --error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD -create or replace table t1 (a int default b, b int default 1+1); +create or replace table t1 (a int default b, b int default (1+1)); --error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD create or replace table t1 (a int default 1, b int as (c), c int as (a+1)); --error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD @@ -323,10 +325,16 @@ drop table t1; --error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED create or replace table t1 (a bigint default xxx()); ---error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED +--error ER_PARSE_ERROR create or replace table t1 (a bigint default (select (1))); +--error ER_PARSE_ERROR +create or replace table t1 (a bigint default (1,2,3)); --error ER_OPERAND_COLUMNS -create or replace table t1 (a bigint default (1,2,3))); +create or replace table t1 (a bigint default ((1,2,3))); +--error ER_PARSE_ERROR +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a DIV b); +--error ER_PARSE_ERROR +CREATE TABLE t1 (a INT, b INT DEFAULT -a); # Cleanup drop table if exists t1; @@ -336,7 +344,7 @@ drop table if exists t1; --echo # --error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED -CREATE TABLE t1 (a INT DEFAULT (SELECT 1)); +CREATE TABLE t1 (a INT DEFAULT ((SELECT 1))); --error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED CREATE TABLE t1 (a INT DEFAULT (EXISTS (SELECT 1))); @@ -348,14 +356,11 @@ CREATE TABLE t1 (a INT DEFAULT (1=ANY (SELECT 1))); CREATE TABLE t1 (a INT DEFAULT ROW(1,1)); --error ER_OPERAND_COLUMNS -CREATE TABLE t1 (a INT DEFAULT (1,1)); - ---error ER_OPERAND_COLUMNS CREATE TABLE t1 (a INT DEFAULT ((1,1))); ---error ER_PARSE_ERROR +--error ER_PARSE_ERROR,2031 CREATE TABLE t1 (a INT DEFAULT ?); ---error ER_PARSE_ERROR +--error ER_PARSE_ERROR,2031 CREATE TABLE t1 (a INT DEFAULT(?)); --error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD @@ -864,7 +869,7 @@ DROP TABLE t1; --echo # Check DEFAULT() function --echo # -CREATE TABLE `t1` (`a` int(11) DEFAULT 3+3,`b` int(11) DEFAULT '1000'); +CREATE TABLE `t1` (`a` int(11) DEFAULT (3+3),`b` int(11) DEFAULT '1000'); insert into t1 values (1,1),(2,2); insert into t1 values (default,default); select * from t1; @@ -919,12 +924,6 @@ INSERT INTO t1 VALUES (PI(), DEFAULT, DEFAULT); SELECT * FROM t1; DROP TABLE t1; -# QQ: this sets "b" to (-1), which looks wrong -#CREATE TABLE t1 (a VARCHAR(30), b DOUBLE DEFAULT MATCH (a) AGAINST('bbbb' IN BOOLEAN MODE)); -#INSERT INTO t1 VALUES ('aaaa bbbb cccc dddd', DEFAULT); -#SELECT * FROM t1; -#DROP TABLE t1; - --echo # --echo # INT result functions --echo # @@ -934,7 +933,7 @@ INSERT INTO t1 (a) VALUES (34); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a DIV b); +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a DIV b)); INSERT INTO t1 (a, b) VALUES (13, 3); SELECT * FROM t1; DROP TABLE t1; @@ -994,6 +993,9 @@ CREATE TABLE t1 (a INT DEFAULT MASTER_POS_WAIT('test',100)); --error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED CREATE TABLE t1 (a INT DEFAULT MASTER_GTID_WAIT('test')); +--error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a VARCHAR(30), b DOUBLE DEFAULT MATCH (a) AGAINST('bbbb' IN BOOLEAN MODE)); + --echo # --echo # Temporal functions --echo # @@ -1283,8 +1285,8 @@ INSERT INTO t1 VALUES (1, 1, DEFAULT); SELECT * FROM t1; DROP TABLE t1; - -CREATE TABLE t1 (a INT, b INT DEFAULT -a); +CREATE TABLE t1 (a INT, b INT DEFAULT (-a)); +SHOW CREATE TABLE t1; INSERT INTO t1 VALUES (10, DEFAULT); SELECT * FROM t1; DROP TABLE t1; @@ -1300,12 +1302,13 @@ INSERT INTO t1 VALUES (-1.5, DEFAULT, DEFAULT, DEFAULT); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a+b, d INT DEFAULT a-b); +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a+b), d INT DEFAULT (a-b)); INSERT INTO t1 VALUES (2, 1, DEFAULT, DEFAULT); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a*b, d INT DEFAULT a/b, e INT DEFAULT a MOD b); +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a*b), d INT DEFAULT (a/b), e INT DEFAULT (a MOD b)); +SHOW CREATE TABLE t1; INSERT INTO t1 VALUES (7, 3, DEFAULT, DEFAULT, DEFAULT); SELECT * FROM t1; DROP TABLE t1; @@ -1362,8 +1365,9 @@ CREATE TABLE t1 ( a VARCHAR(10) CHARACTER SET latin1, b VARCHAR(10) CHARACTER SET latin1 DEFAULT a COLLATE latin1_bin, c VARCHAR(10) CHARACTER SET utf8 DEFAULT CONVERT(a USING utf8), - d VARBINARY(10) DEFAULT BINARY(a) + d VARBINARY(10) DEFAULT (BINARY(a)) ); +SHOW CREATE TABLE t1; INSERT INTO t1 (a) VALUES ('a'); SELECT * FROM t1; DROP TABLE t1; @@ -1377,23 +1381,24 @@ CREATE TABLE t1 (a INT, b INT DEFAULT BIT_COUNT(a)); INSERT INTO t1 (a) VALUES (7); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a|b); +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a|b)); INSERT INTO t1 (a,b) VALUES (1,2); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a&b); +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a&b)); INSERT INTO t1 (a,b) VALUES (5,4); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a^b); +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a^b)); INSERT INTO t1 (a,b) VALUES (11,3); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a&~b); +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a&~b)); INSERT INTO t1 (a,b) VALUES (5,1); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a<<b, d INT DEFAULT a>>b); +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a<<b), d INT DEFAULT (a>>b)); +SHOW CREATE TABLE t1; INSERT INTO t1 (a,b) VALUES (5,1); SELECT * FROM t1; DROP TABLE t1; @@ -1543,71 +1548,73 @@ CREATE TABLE t1 (a VARCHAR(30), b BLOB DEFAULT LOAD_FILE(a)); --echo # Predicates --echo # -CREATE TABLE t1 (a INT, b INT DEFAULT NOT a); +CREATE TABLE t1 (a INT, b INT DEFAULT (NOT a)); +SHOW CREATE TABLE t1; INSERT INTO t1 (a) VALUES (NULL),(0),(1); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT, x INT DEFAULT a XOR b); +CREATE TABLE t1 (a INT, b INT, x INT DEFAULT (a XOR b)); INSERT INTO t1 (a,b) VALUES (0,0),(0,1),(1,0),(1,1); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT DEFAULT a IS TRUE, c INT DEFAULT a IS NOT TRUE); +CREATE TABLE t1 (a INT, b INT DEFAULT (a IS TRUE), c INT DEFAULT (a IS NOT TRUE)); +SHOW CREATE TABLE t1; INSERT INTO t1 (a) VALUES (NULL),(0),(1); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT DEFAULT a IS FALSE, c INT DEFAULT a IS NOT FALSE); +CREATE TABLE t1 (a INT, b INT DEFAULT (a IS FALSE), c INT DEFAULT (a IS NOT FALSE)); INSERT INTO t1 (a) VALUES (NULL),(0),(1); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT DEFAULT a IS NULL, c INT DEFAULT a IS NOT NULL); +CREATE TABLE t1 (a INT, b INT DEFAULT (a IS NULL), c INT DEFAULT (a IS NOT NULL)); INSERT INTO t1 (a) VALUES (NULL),(0),(1); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a INT, b INT DEFAULT a IS UNKNOWN, c INT DEFAULT a IS NOT UNKNOWN); +CREATE TABLE t1 (a INT, b INT DEFAULT (a IS UNKNOWN), c INT DEFAULT (a IS NOT UNKNOWN)); INSERT INTO t1 (a) VALUES (NULL),(0),(1); SELECT * FROM t1; DROP TABLE t1; CREATE TABLE t1 (a INT, - eq INT DEFAULT a=0, equal INT DEFAULT a<=>0, - ne INT DEFAULT a<>0, - lt INT DEFAULT a<0, le INT DEFAULT a<=0, - gt INT DEFAULT a>0, ge INT DEFAULT a>=0); + eq INT DEFAULT (a=0), equal INT DEFAULT (a<=>0), + ne INT DEFAULT (a<>0), + lt INT DEFAULT (a<0), le INT DEFAULT (a<=0), + gt INT DEFAULT (a>0), ge INT DEFAULT (a>=0)); INSERT INTO t1 (a) VALUES (NULL),(-1),(0),(1); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT a LIKE 'a%'); +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT (a LIKE 'a%')); INSERT INTO t1 (a) VALUES ('AAA'),('aaa'),('bbb'); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT a RLIKE 'a$'); +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT (a RLIKE 'a$')); INSERT INTO t1 (a) VALUES ('AAA'),('aaa'),('bbb'); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT a IN ('aaa','bbb')); +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT (a IN ('aaa','bbb'))); INSERT INTO t1 (a) VALUES ('AAA'),('aaa'),('bbb'),('ccc'); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT a NOT IN ('aaa','bbb')); +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT (a NOT IN ('aaa','bbb'))); INSERT INTO t1 (a) VALUES ('AAA'),('aaa'),('bbb'),('ccc'); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT a BETWEEN 'aaa' AND 'bbb'); +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT (a BETWEEN 'aaa' AND 'bbb')); INSERT INTO t1 (a) VALUES ('AAA'),('aaa'),('bbb'),('ccc'); SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT a NOT BETWEEN 'aaa' AND 'bbb'); +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT (a NOT BETWEEN 'aaa' AND 'bbb')); INSERT INTO t1 (a) VALUES ('AAA'),('aaa'),('bbb'),('ccc'); SELECT * FROM t1; DROP TABLE t1; @@ -1716,3 +1723,12 @@ CREATE TABLE t1 ( INSERT INTO t1 (a) VALUES ('test'); SELECT c FROM t1; DROP TABLE t1; + +--echo # +--echo # Collations +--echo # + +--error ER_BAD_DATA +CREATE TABLE t1 (a VARCHAR(20) CHARACTER SET latin1 DEFAULT CONCAT('ö')) CHARACTER SET koi8r COLLATE koi8r_bin; +CREATE OR REPLACE TABLE t1 (a char(2) default concat('A') COLLATE utf8mb4_unicode_ci); +DROP TABLE t1; |