1+ // Copyright 2020-2021 Dolthub, Inc.
2+ //
3+ // Licensed under the Apache License, Version 2.0 (the "License");
4+ // you may not use this file except in compliance with the License.
5+ // You may obtain a copy of the License at
6+ //
7+ // http://www.apache.org/licenses/LICENSE-2.0
8+ //
9+ // Unless required by applicable law or agreed to in writing, software
10+ // distributed under the License is distributed on an "AS IS" BASIS,
11+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ // See the License for the specific language governing permissions and
13+ // limitations under the License.
14+
15+ package queries
16+
17+ import (
18+ "github.com/dolthub/go-mysql-server/sql"
19+ "github.com/dolthub/go-mysql-server/sql/types"
20+ )
21+
22+ var AutoIncrementOverflowTests = []QueryTest {
23+ {
24+ Query : "CREATE TABLE test_tinyint (id TINYINT AUTO_INCREMENT PRIMARY KEY, value VARCHAR(50))" ,
25+ Expected : []sql.Row {
26+ {types .NewOkResult (0 )},
27+ },
28+ },
29+ {
30+ Query : "INSERT INTO test_tinyint (id, value) VALUES (127, 'test127')" ,
31+ Expected : []sql.Row {
32+ {types .NewOkResult (1 )},
33+ },
34+ },
35+ {
36+ Query : "SHOW CREATE TABLE test_tinyint" ,
37+ Expected : []sql.Row {
38+ {"test_tinyint" , "CREATE TABLE `test_tinyint` (\n `id` tinyint NOT NULL AUTO_INCREMENT,\n `value` varchar(50),\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB AUTO_INCREMENT=127 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin" },
39+ },
40+ },
41+ {
42+ Query : "CREATE TABLE test_smallint (id SMALLINT AUTO_INCREMENT PRIMARY KEY, value VARCHAR(50))" ,
43+ Expected : []sql.Row {
44+ {types .NewOkResult (0 )},
45+ },
46+ },
47+ {
48+ Query : "INSERT INTO test_smallint (id, value) VALUES (32767, 'test32767')" ,
49+ Expected : []sql.Row {
50+ {types .NewOkResult (1 )},
51+ },
52+ },
53+ {
54+ Query : "SHOW CREATE TABLE test_smallint" ,
55+ Expected : []sql.Row {
56+ {"test_smallint" , "CREATE TABLE `test_smallint` (\n `id` smallint NOT NULL AUTO_INCREMENT,\n `value` varchar(50),\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB AUTO_INCREMENT=32767 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin" },
57+ },
58+ },
59+ {
60+ Query : "CREATE TABLE test_int (id INT AUTO_INCREMENT PRIMARY KEY, value VARCHAR(50))" ,
61+ Expected : []sql.Row {
62+ {types .NewOkResult (0 )},
63+ },
64+ },
65+ {
66+ Query : "INSERT INTO test_int (id, value) VALUES (2147483647, 'test2147483647')" ,
67+ Expected : []sql.Row {
68+ {types .NewOkResult (1 )},
69+ },
70+ },
71+ {
72+ Query : "SHOW CREATE TABLE test_int" ,
73+ Expected : []sql.Row {
74+ {"test_int" , "CREATE TABLE `test_int` (\n `id` int NOT NULL AUTO_INCREMENT,\n `value` varchar(50),\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB AUTO_INCREMENT=2147483647 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin" },
75+ },
76+ },
77+ {
78+ Query : "CREATE TABLE test_bigint (id BIGINT AUTO_INCREMENT PRIMARY KEY, value VARCHAR(50))" ,
79+ Expected : []sql.Row {
80+ {types .NewOkResult (0 )},
81+ },
82+ },
83+ {
84+ Query : "INSERT INTO test_bigint (id, value) VALUES (9223372036854775807, 'test9223372036854775807')" ,
85+ Expected : []sql.Row {
86+ {types .NewOkResult (1 )},
87+ },
88+ },
89+ {
90+ Query : "SHOW CREATE TABLE test_bigint" ,
91+ Expected : []sql.Row {
92+ {"test_bigint" , "CREATE TABLE `test_bigint` (\n `id` bigint NOT NULL AUTO_INCREMENT,\n `value` varchar(50),\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB AUTO_INCREMENT=9223372036854775807 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin" },
93+ },
94+ },
95+ }
96+
97+ var AutoIncrementOverflowErrorTests = []QueryErrorTest {
98+ {
99+ Query : "INSERT INTO test_tinyint (value) VALUES ('test_overflow')" ,
100+ ExpectedErr : sql .ErrPrimaryKeyViolation ,
101+ },
102+ {
103+ Query : "INSERT INTO test_smallint (value) VALUES ('test_overflow')" ,
104+ ExpectedErr : sql .ErrPrimaryKeyViolation ,
105+ },
106+ {
107+ Query : "INSERT INTO test_int (value) VALUES ('test_overflow')" ,
108+ ExpectedErr : sql .ErrPrimaryKeyViolation ,
109+ },
110+ {
111+ Query : "INSERT INTO test_bigint (value) VALUES ('test_overflow')" ,
112+ ExpectedErr : sql .ErrPrimaryKeyViolation ,
113+ },
114+ }
0 commit comments