Debian Codegraph @

mysql-test/suite/storage_engine/autoincrement.test

raw
1 #
2 # Basic AUTO_INCREMENT capabilities
3 #
4
5 --source have_engine.inc
6
7 --let $skip = 1
8 --source have_default_index.inc
9
10 --disable_warnings
11 DROP TABLE IF EXISTS t1;
12 --enable_warnings
13
14 --let $create_definition = a $int_indexed_col AUTO_INCREMENT, b $char_col, $default_index(a)
15 --source create_table.inc
16 if ($mysql_errname)
17 {
18 --let $functionality = AUTO_INCREMENT
19 --source unexpected_result.inc
20 }
21 if (!$mysql_errname)
22 {
23 --source mask_engine.inc
24 SHOW CREATE TABLE t1;
25
26 # Automatic values
27
28 INSERT INTO t1 (b) VALUES ('a'),('b');
29 SELECT a,b FROM t1 ORDER BY a;
30 SELECT LAST_INSERT_ID();
31
32 INSERT INTO t1 (a,b) VALUES (NULL,'c'),(0,'d');
33 SELECT a,b FROM t1 ORDER BY a;
34 SELECT LAST_INSERT_ID();
35
36 let $sql_mode = `SELECT @@sql_mode`;
37 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
38
39 INSERT INTO t1 (a,b) VALUES (NULL,'e');
40 SELECT a,b FROM t1 ORDER BY a;
41 SELECT LAST_INSERT_ID();
42
43 INSERT INTO t1 (a,b) VALUES (0,'f');
44 SELECT a,b FROM t1 ORDER BY a;
45 SELECT LAST_INSERT_ID();
46
47 --replace_result $sql_mode <INITIAL_SQL_MODE>
48 eval SET sql_mode = '$sql_mode';
49
50 # SHOW TABLE STATUS shows the auto-increment value in column 11,
51 # that's all we need here and further
52 --source mask_engine.inc
53 --replace_column 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 # 19 #
54 SHOW TABLE STATUS FROM test LIKE 't1';
55
56 # Mix of automatic and explicit values
57
58 INSERT INTO t1 (a,b) VALUES (6,'g'),(7,'h');
59 SELECT LAST_INSERT_ID();
60
61 --replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 # 19 #
62 SHOW TABLE STATUS FROM test LIKE 't1';
63
64
65 INSERT INTO t1 (a,b) VALUES (NULL,'i'),(9,'j');
66 SELECT a,b FROM t1 ORDER BY a;
67 SELECT LAST_INSERT_ID();
68
69 --replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 # 19 #
70 SHOW TABLE STATUS FROM test LIKE 't1';
71
72 # Creating a gap in the sequence
73
74 INSERT INTO t1 (a,b) VALUES (20,'k');
75
76 --replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 # 19 #
77 SHOW TABLE STATUS FROM test LIKE 't1';
78
79 INSERT INTO t1 (a,b) VALUES (NULL,'l');
80 SELECT a,b FROM t1 ORDER BY a;
81 SELECT LAST_INSERT_ID();
82
83 --replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 # 19 #
84 SHOW TABLE STATUS FROM test LIKE 't1';
85
86 # Negative values: we will try to insert one just to check that it does not cause a crash,
87 # but won't check what happens to the sequence after that, since the behavior is undefined
88
89 INSERT INTO t1 (a,b) VALUES (-5,'m');
90 SELECT a,b FROM t1 ORDER BY a;
91
92 DROP TABLE t1;
93 }
94
95 # Autoincrement with table option AUTO_INCREMENT
96
97 --let $create_definition = a $int_indexed_col AUTO_INCREMENT, b $char_col, $default_index(a)
98 --let $table_options = AUTO_INCREMENT = 100
99 --source create_table.inc
100 if ($mysql_errname)
101 {
102 --let $functionality = AUTO_INCREMENT column or table option
103 --source unexpected_result.inc
104 }
105 if (!$mysql_errname)
106 {
107 INSERT INTO t1 (a,b) VALUES (NULL,'a'),(NULL,'b');
108 --sorted_result
109 SELECT a,b FROM t1;
110 SELECT LAST_INSERT_ID();
111 DROP TABLE t1;
112 }
113 --source cleanup_engine.inc
114