Skip to content

Commit 9598a36

Browse files
author
James Cor
committed
adding enum test
1 parent 7c2fb42 commit 9598a36

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

enginetest/queries/script_queries.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2914,6 +2914,20 @@ var ScriptTests = []ScriptTest{
29142914
"insert into set_tbl values (6, 'b,c');",
29152915
"insert into set_tbl values (7, 'a,c');",
29162916
"insert into set_tbl values (8, 'a,b,c');",
2917+
2918+
"create table collate_tbl (i int primary key, s varchar(10) collate utf8mb4_0900_ai_ci);",
2919+
"insert into collate_tbl values (0, '');",
2920+
"insert into collate_tbl values (1, 'a');",
2921+
"insert into collate_tbl values (2, 'b');",
2922+
"insert into collate_tbl values (3, 'c');",
2923+
"insert into collate_tbl values (4, 'a,b');",
2924+
"insert into collate_tbl values (6, 'b,c');",
2925+
"insert into collate_tbl values (7, 'a,c');",
2926+
"insert into collate_tbl values (8, 'a,b,c');",
2927+
2928+
"create table enum_tbl (i int primary key, s enum('a','b','c'));",
2929+
"insert into enum_tbl values (0, 'a'), (1, 'b'), (2, 'c');",
2930+
"select i, s, find_in_set('a', s) from enum_tbl;",
29172931
},
29182932
Assertions: []ScriptTestAssertion{
29192933
{
@@ -2929,22 +2943,6 @@ var ScriptTests = []ScriptTest{
29292943
{8, 1},
29302944
},
29312945
},
2932-
},
2933-
},
2934-
{
2935-
Name: "find_in_set tests",
2936-
SetUpScript: []string{
2937-
"create table collate_tbl (i int primary key, s varchar(10) collate utf8mb4_0900_ai_ci);",
2938-
"insert into collate_tbl values (0, '');",
2939-
"insert into collate_tbl values (1, 'a');",
2940-
"insert into collate_tbl values (2, 'b');",
2941-
"insert into collate_tbl values (3, 'c');",
2942-
"insert into collate_tbl values (4, 'a,b');",
2943-
"insert into collate_tbl values (6, 'b,c');",
2944-
"insert into collate_tbl values (7, 'a,c');",
2945-
"insert into collate_tbl values (8, 'a,b,c');",
2946-
},
2947-
Assertions: []ScriptTestAssertion{
29482946
{
29492947
Query: "select i, find_in_set('A', s) from collate_tbl;",
29502948
Expected: []sql.Row{
@@ -2958,6 +2956,14 @@ var ScriptTests = []ScriptTest{
29582956
{8, 1},
29592957
},
29602958
},
2959+
{
2960+
Query: "select i, find_in_set('a', s) from enum_tbl;",
2961+
Expected: []sql.Row{
2962+
{0, 1},
2963+
{1, 0},
2964+
{2, 0},
2965+
},
2966+
},
29612967
},
29622968
},
29632969
}

sql/expression/function/find_in_set.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ func (f *FindInSet) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
110110
if err != nil {
111111
return nil, err
112112
}
113+
} else if enumType, ok := rType.(types.EnumType); ok {
114+
r, ok = enumType.At(int(right.(uint16)))
115+
if !ok {
116+
return nil, fmt.Errorf("enum missing index %v", r)
117+
}
113118
} else {
114119
var rVal interface{}
115120
rVal, _, err = types.LongText.Convert(right)

0 commit comments

Comments
 (0)