1SET global default_storage_engine=MyISAM;
2SET session default_storage_engine=MyISAM;
3# Test for warnings on column creation
4CREATE TABLE t1 (y YEAR(4) NOT NULL);
5SHOW CREATE TABLE t1;
6Table	Create Table
7t1	CREATE TABLE `t1` (
8  `y` year(4) NOT NULL
9) ENGINE=MyISAM DEFAULT CHARSET=latin1
10DROP TABLE t1;
11CREATE TABLE t1 (y YEAR(-4) NOT NULL);
12ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-4) NOT NULL)' at line 1
13CREATE TABLE t1 (y YEAR(0) NOT NULL);
14ERROR HY000: Supports only YEAR or YEAR(4) column.
15CREATE TABLE t1 (y YEAR(1) NOT NULL);
16ERROR HY000: Supports only YEAR or YEAR(4) column.
17CREATE TABLE t1 (y YEAR(2) NOT NULL);
18ERROR HY000: Supports only YEAR or YEAR(4) column.
19CREATE TABLE t1 (y YEAR(5) NOT NULL);
20ERROR HY000: Supports only YEAR or YEAR(4) column.
21CREATE TABLE t1 (y YEAR(10240) NOT NULL);
22ERROR HY000: Supports only YEAR or YEAR(4) column.
23CREATE TABLE t1 (y YEAR(-1) NOT NULL);
24ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1) NOT NULL)' at line 1
25CREATE TABLE t1 (y YEAR(-4294967296) NOT NULL);
26ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-4294967296) NOT NULL)' at line 1
27CREATE TABLE t1 (y YEAR(-4294967295) NOT NULL);
28ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-4294967295) NOT NULL)' at line 1
29CREATE TABLE t1 (y YEAR(NULL) NOT NULL);
30ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL) NOT NULL)' at line 1
31CREATE TABLE t1 (y YEAR('') NOT NULL);
32ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''') NOT NULL)' at line 1
33CREATE TABLE t1 (y YEAR('a') NOT NULL);
34ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''a') NOT NULL)' at line 1
35CREATE TABLE t1 (y YEAR('-a') NOT NULL);
36ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''-a') NOT NULL)' at line 1
37CREATE TABLE t1 (y YEAR(4294967296) NOT NULL);
38ERROR HY000: Supports only YEAR or YEAR(4) column.
39CREATE TABLE t1 (y YEAR(4294967295) NOT NULL);
40ERROR HY000: Supports only YEAR or YEAR(4) column.
41# Test for default column width value
42CREATE TABLE t1 (y YEAR NOT NULL);
43SHOW CREATE TABLE t1;
44Table	Create Table
45t1	CREATE TABLE `t1` (
46  `y` year(4) NOT NULL
47) ENGINE=MyISAM DEFAULT CHARSET=latin1
48DROP TABLE t1;
49#
50# Check various ALTER TABLE operations on YEAR(2) type
51#
52CREATE TABLE t1 (i INT NOT NULL);
53# Try to create new YEAR(2) column with ALTER TABLE
54ALTER TABLE t1 ADD COLUMN y YEAR(2) NOT NULL;
55ERROR HY000: Supports only YEAR or YEAR(4) column.
56SHOW CREATE TABLE t1;
57Table	Create Table
58t1	CREATE TABLE `t1` (
59  `i` int(11) NOT NULL
60) ENGINE=MyISAM DEFAULT CHARSET=latin1
61# Try to convert YEAR(4) column to YEAR(2) with ALTER TABLE
62ALTER TABLE t1 MODIFY COLUMN y YEAR(2) NOT NULL;
63ERROR HY000: Supports only YEAR or YEAR(4) column.
64SHOW CREATE TABLE t1;
65Table	Create Table
66t1	CREATE TABLE `t1` (
67  `i` int(11) NOT NULL
68) ENGINE=MyISAM DEFAULT CHARSET=latin1
69ALTER TABLE t1 MODIFY COLUMN i YEAR(2) NOT NULL;
70ERROR HY000: Supports only YEAR or YEAR(4) column.
71SHOW CREATE TABLE t1;
72Table	Create Table
73t1	CREATE TABLE `t1` (
74  `i` int(11) NOT NULL
75) ENGINE=MyISAM DEFAULT CHARSET=latin1
76ALTER TABLE t1 MODIFY COLUMN i INT NOT NULL;
77DROP TABLE t1;
78#
79# Regression tests
80#
81CREATE TABLE t1 (y YEAR NOT NULL DEFAULT 0,
82i INT NOT NULL DEFAULT 0,
83c VARCHAR(20) NOT NULL DEFAULT '');
84# insert [1901..2155]
85# insert [0..99]
86UPDATE t1 SET i = c;
87# should return no warnings
88UPDATE t1 SET y = c;
89# should return no warnings
90UPDATE t1 SET y = i;
91# should return no warnings
92INSERT INTO t1 (y) VALUES (0), ('00'), ('0000');
93TRUNCATE t1;
94# test out-of-range values, should return warnings
95INSERT INTO t1 (i) VALUES (-1), (1800), (2156), (2147483647);
96# should return 4 warnings
97UPDATE IGNORE t1 SET y = i;
98Warnings:
99Warning	1264	Out of range value for column 'y' at row 1
100Warning	1264	Out of range value for column 'y' at row 2
101Warning	1264	Out of range value for column 'y' at row 3
102Warning	1264	Out of range value for column 'y' at row 4
103SELECT y, i FROM t1;
104y	i
1050000	-1
1060000	1800
1070000	2147483647
1080000	2156
109TRUNCATE t1;
110# should return 4 warnings
111INSERT INTO t1 (c) VALUES (''), (' '), ('2012qwer'), ('qwer');
112UPDATE IGNORE t1 SET y = c;
113Warnings:
114Warning	1366	Incorrect integer value: '' for column 'y' at row 1
115Warning	1366	Incorrect integer value: ' ' for column 'y' at row 2
116Warning	1265	Data truncated for column 'y' at row 3
117Warning	1366	Incorrect integer value: 'qwer' for column 'y' at row 4
118SELECT y, CONCAT('"', c, '"') FROM t1;
119y	CONCAT('"', c, '"')
1200000	" "
1210000	""
1220000	"qwer"
1232012	"2012qwer"
124DROP TABLE t1;
125SET @@global.default_storage_engine = MyISAM;
126SET @@session.default_storage_engine = MyISAM;
127#
128