Commit 11ff9014 authored by Alexander Barkov's avatar Alexander Barkov Committed by Sergei Golubchik

More tests for MDEV-7563 Support CHECK constraint

Adding tests for cast, bit functions, string functions.
parent ba6646f7
This diff is collapsed.
......@@ -935,6 +935,8 @@ INSERT INTO t1 VALUES ('01,5,2013','%d,%m,%Y', DEFAULT);
SELECT * FROM t1;
DROP TABLE t1;
--error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
CREATE TABLE t1 (a VARCHAR(30), b VARCHAR(30) DEFAULT DATE_FORMAT(a,'%W %M %Y'));
--echo # Item_datefunc
......@@ -1032,6 +1034,139 @@ SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # Functions with temporal input
--echo #
CREATE TABLE t1 (a INT, b INT, c INT DEFAULT PERIOD_ADD(a,b));
INSERT INTO t1 (a,b) VALUES (200801, 2);
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a INT, b INT, c INT DEFAULT PERIOD_DIFF(a,b));
INSERT INTO t1 (a,b) VALUES (200802, 200703);
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a INT, b INT DEFAULT TO_DAYS(a));
INSERT INTO t1 (a) VALUES (950501);
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a DATE, b INT DEFAULT TO_DAYS(a));
INSERT INTO t1 (a) VALUES ('2007-10-07');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a INT, b BIGINT DEFAULT TO_SECONDS(a));
INSERT INTO t1 (a) VALUES (950501);
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a DATE, b BIGINT DEFAULT TO_SECONDS(a));
INSERT INTO t1 (a) VALUES ('2009-11-29');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a DATETIME, b BIGINT DEFAULT TO_SECONDS(a));
INSERT INTO t1 (a) VALUES ('2009-11-29 13:43:32');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a DATE, b BIGINT DEFAULT DAYOFMONTH(a));
INSERT INTO t1 (a) VALUES ('2007-02-03');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a DATE, b BIGINT DEFAULT DAYOFWEEK(a));
INSERT INTO t1 (a) VALUES ('2007-02-03');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a DATE, b BIGINT DEFAULT DAYOFYEAR(a));
INSERT INTO t1 (a) VALUES ('2007-02-03');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a TIME, b INT DEFAULT HOUR(a));
INSERT INTO t1 (a) VALUES ('10:05:03');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a TIME, b INT DEFAULT MINUTE(a));
INSERT INTO t1 (a) VALUES ('10:05:03');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a TIME, b INT DEFAULT SECOND(a));
INSERT INTO t1 (a) VALUES ('10:05:03');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a DATETIME(6), b INT DEFAULT MICROSECOND(a));
INSERT INTO t1 (a) VALUES ('2009-12-31 23:59:59.000010');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a DATE, b INT DEFAULT YEAR(a));
INSERT INTO t1 (a) VALUES ('1987-01-01');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a DATE, b INT DEFAULT MONTH(a));
INSERT INTO t1 (a) VALUES ('1987-01-01');
SELECT * FROM t1;
DROP TABLE t1;
# QQ: this depends on @@default_week_format.
CREATE TABLE t1 (a DATE, b INT DEFAULT WEEK(a));
INSERT INTO t1 (a) VALUES ('1987-02-01');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a DATE, b INT DEFAULT YEARWEEK(a));
INSERT INTO t1 (a) VALUES ('2000-01-01');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a DATE, b INT DEFAULT QUARTER(a));
INSERT INTO t1 (a) VALUES ('2008-04-01');
SELECT * FROM t1;
DROP TABLE t1;
# QQ: this depends on @@lc_time_names
--error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
CREATE TABLE t1 (a DATE, b VARCHAR(30) DEFAULT DAYNAME(a));
--error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
CREATE TABLE t1 (a DATE, b VARCHAR(30) DEFAULT MONTHNAME(a));
CREATE TABLE t1 (a DATE, b INT DEFAULT EXTRACT(YEAR FROM a));
INSERT INTO t1 (a) VALUES ('2009-07-02');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a DATETIME, b INT DEFAULT EXTRACT(YEAR_MONTH FROM a));
INSERT INTO t1 (a) VALUES ('2009-07-02 01:02:03');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a DATETIME, b INT DEFAULT EXTRACT(DAY_MINUTE FROM a));
INSERT INTO t1 (a) VALUES ('2009-07-02 01:02:03');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a DATETIME(6), b INT DEFAULT EXTRACT(MICROSECOND FROM a));
INSERT INTO t1 (a) VALUES ('2009-07-02 01:02:03.000123');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a DATE, b DATE, c INT DEFAULT TIMESTAMPDIFF(MONTH,a,b));
INSERT INTO t1 (a,b) VALUES ('2003-02-01','2003-05-01');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a DATE, b DATE, c INT DEFAULT TIMESTAMPDIFF(YEAR,a,b));
INSERT INTO t1 (a,b) VALUES ('2002-05-01','2001-01-01');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a DATE, b DATETIME, c INT DEFAULT TIMESTAMPDIFF(MINUTE,a,b));
INSERT INTO t1 (a,b) VALUES ('2003-02-01','2003-05-01 12:05:55');
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # Hybrid type functions
......@@ -1117,3 +1252,167 @@ CREATE TABLE t1 (a INT, b INT, c INT DEFAULT LAST_VALUE(a,b));
INSERT INTO t1 VALUES (1, 2, DEFAULT);
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # CAST
--echo #
CREATE TABLE t1 (a VARCHAR(30), b DECIMAL(10,6) DEFAULT CAST(a AS DECIMAL(10,1)));
INSERT INTO t1 (a) VALUES ('123.456');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a DECIMAL(10,3),
b VARCHAR(10) DEFAULT CAST(a AS CHAR(10)),
c VARCHAR(10) DEFAULT CAST(a AS CHAR(4)));
INSERT INTO t1 (a) VALUES (123.456);
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a INT, b INT UNSIGNED DEFAULT CAST(a AS UNSIGNED));
INSERT INTO t1 (a) VALUES (-1);
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a BIGINT UNSIGNED, b BIGINT SIGNED DEFAULT CAST(a AS SIGNED));
INSERT INTO t1 (a) VALUES (0xFFFFFFFFFFFFFFFF);
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # Bit functions
--echo #
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);
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);
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);
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);
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);
INSERT INTO t1 (a,b) VALUES (5,1);
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # String functions
--echo #
CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(20) DEFAULT REVERSE(a));
INSERT INTO t1 (a) VALUES ('abcd');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10) DEFAULT UPPER(a), c VARCHAR(10) DEFAULT LOWER(a));
INSERT INTO t1 (a) VALUES ('ABcd');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10) DEFAULT LEFT(a,1), c VARCHAR(10) DEFAULT RIGHT(a,1), d VARCHAR(10) DEFAULT SUBSTR(a,2,2));
INSERT INTO t1 (a) VALUES ('abcd');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(20), b VARCHAR(20) DEFAULT SUBSTRING_INDEX(a,'.',2));
INSERT INTO t1 (a) VALUES ('www.mariadb.org');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10), c VARCHAR(20) DEFAULT CONCAT(a,b));
INSERT INTO t1 (a,b) VALUES ('a','b');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10), c VARCHAR(20) DEFAULT CONCAT_WS(',',a,b));
INSERT INTO t1 (a,b) VALUES ('a','b');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10) DEFAULT REPLACE(a,'a','A'));
INSERT INTO t1 (a) VALUES ('abc');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10) DEFAULT REGEXP_REPLACE(a,'[0-9]','.'));
INSERT INTO t1 (a) VALUES ('a1b2c');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10) DEFAULT REGEXP_SUBSTR(a,'[0-9]+'));
INSERT INTO t1 (a) VALUES ('ab12cd');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(20), b VARCHAR(20) DEFAULT SOUNDEX(a));
INSERT INTO t1 (a) VALUES ('tester');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(20), b VARCHAR(20) DEFAULT QUOTE(a));
INSERT INTO t1 (a) VALUES ('a\'b');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10) DEFAULT LPAD(a,10,'.'), c VARCHAR(10) DEFAULT RPAD(a,10,'.'));
INSERT INTO t1 (a) VALUES ('ab');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10) DEFAULT LTRIM(a), c VARCHAR(10) DEFAULT RTRIM(a));
INSERT INTO t1 (a) VALUES (' ab ');
SELECT a, HEX(b), HEX(c) FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10) DEFAULT TRIM(BOTH 'a' FROM a));
INSERT INTO t1 (a) VALUES ('abba');
SELECT a, b FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a INT, b VARCHAR(10) DEFAULT SPACE(a));
INSERT INTO t1 (a) VALUES (3);
SELECT a, HEX(b) FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a INT, b VARCHAR(10), c VARCHAR(10) DEFAULT REPEAT(b,a));
INSERT INTO t1 (a,b) VALUES (3,'x');
SELECT a, b, c FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (str VARCHAR(10), pos INT, len INT, newstr VARCHAR(10), result VARCHAR(10) DEFAULT INSERT(str,pos,len,newstr));
INSERT INTO t1 (str,pos,len,newstr) VALUES ('Quadratic', 3, 4, 'What');
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (n INT, res VARCHAR(10) DEFAULT ELT(n,'ej', 'Heja', 'hej', 'foo'));
INSERT INTO t1 (n) VALUES (1);
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (bits INT, res VARCHAR(10) DEFAULT MAKE_SET(bits,'a','b','c','d'));
INSERT INTO t1 (bits) VALUES (1|4);
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a INT, b VARCHAR(10) DEFAULT CHAR(a));
INSERT INTO t1 (a) VALUES (77);
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a INT, b VARCHAR(10) DEFAULT CONV(a,10,16));
INSERT INTO t1 (a) VALUES (64);
SELECT * FROM t1;
DROP TABLE t1;
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