Skip to content

Commit 88265e9

Browse files
author
James Cor
committed
reorganize enum and set tests
1 parent c5c4097 commit 88265e9

File tree

2 files changed

+565
-555
lines changed

2 files changed

+565
-555
lines changed

enginetest/queries/alter_table_queries.go

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,163 @@ var AlterTableScripts = []ScriptTest{
10621062
},
10631063
},
10641064
},
1065+
1066+
// Enum tests
1067+
{
1068+
Name: "alter nil enum",
1069+
Dialect: "mysql",
1070+
SetUpScript: []string{
1071+
"create table xy (x int primary key, y enum ('a', 'b'));",
1072+
"insert into xy values (0, NULL),(1, 'b')",
1073+
},
1074+
Assertions: []ScriptTestAssertion{
1075+
{
1076+
Query: "alter table xy modify y enum('a','b','c')",
1077+
},
1078+
{
1079+
Query: "alter table xy modify y enum('a')",
1080+
ExpectedErr: types.ErrDataTruncatedForColumn,
1081+
},
1082+
},
1083+
},
1084+
{
1085+
Name: "alter keyless table",
1086+
Dialect: "mysql",
1087+
SetUpScript: []string{
1088+
"create table t (c1 int, c2 varchar(200), c3 enum('one', 'two'));",
1089+
"insert into t values (1, 'one', NULL);",
1090+
},
1091+
Assertions: []ScriptTestAssertion{
1092+
{
1093+
Query: `alter table t modify column c1 int unsigned`,
1094+
Expected: []sql.Row{{types.NewOkResult(0)}},
1095+
},
1096+
{
1097+
Query: "describe t;",
1098+
Expected: []sql.Row{
1099+
{"c1", "int unsigned", "YES", "", nil, ""},
1100+
{"c2", "varchar(200)", "YES", "", nil, ""},
1101+
{"c3", "enum('one','two')", "YES", "", nil, ""},
1102+
},
1103+
},
1104+
{
1105+
Query: `alter table t drop column c1;`,
1106+
Expected: []sql.Row{{types.NewOkResult(0)}},
1107+
},
1108+
{
1109+
Query: "describe t;",
1110+
Expected: []sql.Row{
1111+
{"c2", "varchar(200)", "YES", "", nil, ""},
1112+
{"c3", "enum('one','two')", "YES", "", nil, ""},
1113+
},
1114+
},
1115+
{
1116+
Query: "alter table t add column new3 int;",
1117+
Expected: []sql.Row{{types.NewOkResult(0)}},
1118+
},
1119+
{
1120+
Query: `insert into t values ('two', 'two', -2);`,
1121+
Expected: []sql.Row{{types.NewOkResult(1)}},
1122+
},
1123+
{
1124+
Query: "describe t;",
1125+
Expected: []sql.Row{
1126+
{"c2", "varchar(200)", "YES", "", nil, ""},
1127+
{"c3", "enum('one','two')", "YES", "", nil, ""},
1128+
{"new3", "int", "YES", "", nil, ""},
1129+
},
1130+
},
1131+
{
1132+
Query: "select * from t;",
1133+
Expected: []sql.Row{{"one", nil, nil}, {"two", "two", -2}},
1134+
},
1135+
},
1136+
},
1137+
{
1138+
Name: "preserve enums through alter statements",
1139+
SetUpScript: []string{
1140+
"create table t (i int primary key, e enum('a', 'b', 'c'));",
1141+
"insert ignore into t values (0, 'error');",
1142+
"insert into t values (1, 'a');",
1143+
"insert into t values (2, 'b');",
1144+
"insert into t values (3, 'c');",
1145+
},
1146+
Assertions: []ScriptTestAssertion{
1147+
{
1148+
Query: "select i, e, e + 0 from t;",
1149+
Expected: []sql.Row{
1150+
{0, "", float64(0)},
1151+
{1, "a", float64(1)},
1152+
{2, "b", float64(2)},
1153+
{3, "c", float64(3)},
1154+
},
1155+
},
1156+
{
1157+
Query: "alter table t modify column e enum('c', 'a', 'b');",
1158+
Expected: []sql.Row{
1159+
{types.NewOkResult(0)},
1160+
},
1161+
},
1162+
{
1163+
Query: "select i, e, e + 0 from t;",
1164+
Expected: []sql.Row{
1165+
{0, "", float64(0)},
1166+
{1, "a", float64(2)},
1167+
{2, "b", float64(3)},
1168+
{3, "c", float64(1)},
1169+
},
1170+
},
1171+
{
1172+
Query: "alter table t modify column e enum('asdf', 'a', 'b', 'c');",
1173+
Expected: []sql.Row{
1174+
{types.NewOkResult(0)},
1175+
},
1176+
},
1177+
{
1178+
Query: "select i, e, e + 0 from t;",
1179+
Expected: []sql.Row{
1180+
{0, "", float64(0)},
1181+
{1, "a", float64(2)},
1182+
{2, "b", float64(3)},
1183+
{3, "c", float64(4)},
1184+
},
1185+
},
1186+
{
1187+
Query: "alter table t modify column e enum('asdf', 'a', 'b', 'c', 'd');",
1188+
Expected: []sql.Row{
1189+
{types.NewOkResult(0)},
1190+
},
1191+
},
1192+
{
1193+
Query: "select i, e, e + 0 from t;",
1194+
Expected: []sql.Row{
1195+
{0, "", float64(0)},
1196+
{1, "a", float64(2)},
1197+
{2, "b", float64(3)},
1198+
{3, "c", float64(4)},
1199+
},
1200+
},
1201+
{
1202+
Query: "alter table t modify column e enum('a', 'b', 'c');",
1203+
Expected: []sql.Row{
1204+
{types.NewOkResult(0)},
1205+
},
1206+
},
1207+
{
1208+
Query: "select i, e, e + 0 from t;",
1209+
Expected: []sql.Row{
1210+
{0, "", float64(0)},
1211+
{1, "a", float64(1)},
1212+
{2, "b", float64(2)},
1213+
{3, "c", float64(3)},
1214+
},
1215+
},
1216+
{
1217+
Query: "alter table t modify column e enum('abc');",
1218+
ExpectedErr: types.ErrDataTruncatedForColumn,
1219+
},
1220+
},
1221+
},
10651222
}
10661223

10671224
var RenameTableScripts = []ScriptTest{

0 commit comments

Comments
 (0)