Skip to content

Commit 5d8690a

Browse files
elianddbclaude
andcommitted
Fix enum zero strict mode validation to match MySQL exactly
After MySQL comparison server testing, corrected logic to reject 0 values in strict mode regardless of enum definition, matching MySQL behavior exactly. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent b81d549 commit 5d8690a

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

enginetest/queries/script_queries.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8715,10 +8715,8 @@ where
87158715
},
87168716
},
87178717
{
8718-
Query: "insert into et values (0);",
8719-
Expected: []sql.Row{
8720-
{types.NewOkResult(1)},
8721-
},
8718+
Query: "insert into et values (0);",
8719+
ExpectedErrStr: "Data truncated for column 'e' at row 1",
87228720
},
87238721
},
87248722
},

sql/types/enum.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,9 @@ func (t EnumType) Convert(ctx context.Context, v interface{}) (interface{}, sql.
166166
switch value := v.(type) {
167167
case int:
168168
// Check for 0 value in strict mode - MySQL behavior
169+
// MySQL rejects 0 values in strict mode regardless of enum definition
169170
if value == 0 && t.isStrictMode(ctx) {
170-
// Check if empty string is explicitly defined as a valid enum value
171-
if t.IndexOf("") == -1 {
172-
return nil, sql.OutOfRange, ErrDataTruncatedForColumn.New("(unknown)")
173-
}
171+
return nil, sql.OutOfRange, ErrDataTruncatedForColumn.New("(unknown)")
174172
}
175173
if _, ok := t.At(value); ok {
176174
return uint16(value), sql.InRange, nil

0 commit comments

Comments
 (0)