summaryrefslogtreecommitdiff
path: root/mysql-test/suite/storage_engine/autoincrement.test
blob: ddb0ab1b464111caad91efeab9e8b54859e8b4e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# 
# Basic AUTO_INCREMENT capabilities
#

--source have_engine.inc

--let $skip = 1
--source have_default_index.inc

--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings

--let $create_definition = a $int_indexed_col AUTO_INCREMENT, b $char_col, $default_index(a)
--source create_table.inc
if ($mysql_errname)
{
  --let $functionality = AUTO_INCREMENT
  --source unexpected_result.inc
}
if (!$mysql_errname)
{
  --source mask_engine.inc
  SHOW CREATE TABLE t1;

  # Automatic values

  INSERT INTO t1 (b) VALUES ('a'),('b');
  SELECT a,b FROM t1 ORDER BY a;
  SELECT LAST_INSERT_ID();

  INSERT INTO t1 (a,b) VALUES (NULL,'c'),(0,'d');
  SELECT a,b FROM t1 ORDER BY a;
  SELECT LAST_INSERT_ID();

  let $sql_mode = `SELECT @@sql_mode`;
  SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';

  INSERT INTO t1 (a,b) VALUES (NULL,'e');
  SELECT a,b FROM t1 ORDER BY a;
  SELECT LAST_INSERT_ID();

  INSERT INTO t1 (a,b) VALUES (0,'f');
  SELECT a,b FROM t1 ORDER BY a;
  SELECT LAST_INSERT_ID();

  --replace_result $sql_mode <INITIAL_SQL_MODE>
  eval SET sql_mode = '$sql_mode';

  # SHOW TABLE STATUS shows the auto-increment value in column 11, 
  # that's all we need here and further
  --source mask_engine.inc
  --replace_column 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 #
  SHOW TABLE STATUS FROM test LIKE 't1';

  # Mix of automatic and explicit values

  INSERT INTO t1 (a,b) VALUES (6,'g'),(7,'h');
  SELECT LAST_INSERT_ID();

  --replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 #
  SHOW TABLE STATUS FROM test LIKE 't1';


  INSERT INTO t1 (a,b) VALUES (NULL,'i'),(9,'j');
  SELECT a,b FROM t1 ORDER BY a;
  SELECT LAST_INSERT_ID();

  --replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 #
  SHOW TABLE STATUS FROM test LIKE 't1';

  # Creating a gap in the sequence

  INSERT INTO t1 (a,b) VALUES (20,'k');

  --replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 #
  SHOW TABLE STATUS FROM test LIKE 't1';

  INSERT INTO t1 (a,b) VALUES (NULL,'l');
  SELECT a,b FROM t1 ORDER BY a;
  SELECT LAST_INSERT_ID();

  --replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 #
  SHOW TABLE STATUS FROM test LIKE 't1';

  # Negative values: we will try to insert one just to check that it does not cause a crash,
  # but won't check what happens to the sequence after that, since the behavior is undefined

  INSERT INTO t1 (a,b) VALUES (-5,'m');
  SELECT a,b FROM t1 ORDER BY a;

  DROP TABLE t1;
}

# Autoincrement with table option AUTO_INCREMENT

--let $create_definition = a $int_indexed_col AUTO_INCREMENT, b $char_col, $default_index(a)
--let $table_options = AUTO_INCREMENT = 100
--source create_table.inc
if ($mysql_errname)
{
  --let $functionality = AUTO_INCREMENT column or table option
  --source unexpected_result.inc
}
if (!$mysql_errname)
{
  INSERT INTO t1 (a,b) VALUES (NULL,'a'),(NULL,'b');
  --sorted_result
  SELECT a,b FROM t1;
  SELECT LAST_INSERT_ID();
  DROP TABLE t1;
}
--source cleanup_engine.inc