Skip to content

Commit 270a87e

Browse files
committed
add sys var enum test
1 parent da613f1 commit 270a87e

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

enginetest/queries/script_queries.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9136,6 +9136,33 @@ where
91369136
},
91379137
},
91389138
},
9139+
{
9140+
Name: "enum conversion with system variables",
9141+
Dialect: "mysql",
9142+
SetUpScript: []string{
9143+
"create table t (e enum('ON', 'OFF', 'AUTO'));",
9144+
"set autocommit = 'ON';",
9145+
"insert into t values(@@autocommit), ('OFF'), ('AUTO');",
9146+
},
9147+
Assertions: []ScriptTestAssertion{
9148+
{
9149+
Query: "select e, @@autocommit, e = @@autocommit from t order by e;",
9150+
Expected: []sql.Row{
9151+
{"ON", 1, true},
9152+
{"OFF", 1, false},
9153+
{"AUTO", 1, false},
9154+
},
9155+
},
9156+
{
9157+
Query: "select e, concat(e, @@version_comment) from t order by e;",
9158+
Expected: []sql.Row{
9159+
{"ON", "ONDolt"},
9160+
{"OFF", "OFFDolt"},
9161+
{"AUTO", "AUTODolt"},
9162+
},
9163+
},
9164+
},
9165+
},
91399166
{
91409167
Skip: true,
91419168
Name: "enums with foreign keys",

sql/types/strings.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -554,14 +554,12 @@ func ConvertToCollatedString(ctx context.Context, val interface{}, typ sql.Type)
554554
} else {
555555
collation = sql.Collation_Default
556556
// Handle enum types in string context even without collation
557-
if IsEnum(typ) {
558-
if enumType, ok := typ.(sql.EnumType); ok {
559-
content, err = convertEnumToString(ctx, val, enumType)
560-
if err != nil {
561-
return "", sql.Collation_Unspecified, err
562-
}
563-
return content, collation, nil
557+
if enumType, ok := typ.(sql.EnumType); ok {
558+
content, err = convertEnumToString(ctx, val, enumType)
559+
if err != nil {
560+
return "", sql.Collation_Unspecified, err
564561
}
562+
return content, collation, nil
565563
}
566564
content, err = convertToLongTextString(ctx, val)
567565
if err != nil {

0 commit comments

Comments
 (0)