Skip to content

Commit 432a3d4

Browse files
elianddbclaude
andcommitted
Add row number information to enum error messages for 100% MySQL compatibility
- Added rowCounter field to insertIter struct for tracking row position - Created ErrDataTruncatedForColumnAtRow error type with row number support - Enhanced INSERT error handling to include row numbers (e.g., 'at row 2') - Added new error type to IgnorableErrors list for INSERT IGNORE compatibility - Updated test expectations to match new MySQL-compatible error format - UPDATE operations keep original format (row numbers don't apply to WHERE-based updates) Before: 'Data truncated for column 'enum_col'' After: 'Data truncated for column 'enum_col' at row 2' 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent af12f0a commit 432a3d4

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

enginetest/queries/insert_queries.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2836,7 +2836,7 @@ var InsertIgnoreScripts = []ScriptTest{
28362836
Assertions: []ScriptTestAssertion{
28372837
{
28382838
Query: "insert into test_table values (1, 'invalid'), (2, 'comparative politics'), (3, null)",
2839-
ExpectedErr: types.ErrDataTruncatedForColumn,
2839+
ExpectedErr: types.ErrDataTruncatedForColumnAtRow,
28402840
},
28412841
{
28422842
Query: "insert ignore into test_table values (1, 'invalid'), (2, 'bye'), (3, null)",
@@ -2862,11 +2862,11 @@ var InsertIgnoreScripts = []ScriptTest{
28622862
},
28632863
{
28642864
Query: "insert into enum_zero_test (enum_col) values (0)",
2865-
ExpectedErr: types.ErrDataTruncatedForColumn,
2865+
ExpectedErr: types.ErrDataTruncatedForColumnAtRow,
28662866
},
28672867
{
28682868
Query: "insert into enum_zero_test (enum_col) values ('invalid')",
2869-
ExpectedErr: types.ErrDataTruncatedForColumn,
2869+
ExpectedErr: types.ErrDataTruncatedForColumnAtRow,
28702870
},
28712871
{
28722872
Query: "set sql_mode = ''",

enginetest/queries/script_queries.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ CREATE TABLE tab3 (
12021202
{
12031203
// enum values must match EXACTLY for case-sensitive collations
12041204
Query: "INSERT INTO enumtest1 VALUES (10, 'ABC'), (11, 'aBc'), (12, 'xyz');",
1205-
ExpectedErrStr: "Data truncated for column 'e'",
1205+
ExpectedErrStr: "Data truncated for column 'e' at row 1",
12061206
},
12071207
{
12081208
Query: "SHOW CREATE TABLE enumtest1;",
@@ -8053,11 +8053,11 @@ where
80538053
Assertions: []ScriptTestAssertion{
80548054
{
80558055
Query: "insert into t values (1, 500)",
8056-
ExpectedErrStr: "Data truncated for column 'e'",
8056+
ExpectedErrStr: "Data truncated for column 'e' at row 1",
80578057
},
80588058
{
80598059
Query: "insert into t values (1, -1)",
8060-
ExpectedErrStr: "Data truncated for column 'e'",
8060+
ExpectedErrStr: "Data truncated for column 'e' at row 1",
80618061
},
80628062
},
80638063
},

sql/plan/insert.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var IgnorableErrors = []*errors.Kind{sql.ErrInsertIntoNonNullableProvidedNull,
5656
sql.ErrUniqueKeyViolation,
5757
sql.ErrCheckConstraintViolated,
5858
types.ErrDataTruncatedForColumn,
59+
types.ErrDataTruncatedForColumnAtRow,
5960
}
6061

6162
// InsertInto is the top level node for INSERT INTO statements. It has a source for rows and a destination to insert

sql/rowexec/insert.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type insertIter struct {
4949
firstGeneratedAutoIncRowIdx int
5050

5151
deferredDefaults sql.FastIntSet
52+
rowCounter int
5253
}
5354

5455
func getInsertExpressions(values sql.Node) []sql.Expression {
@@ -74,6 +75,9 @@ func (i *insertIter) Next(ctx *sql.Context) (returnRow sql.Row, returnErr error)
7475
return nil, i.ignoreOrClose(ctx, row, err)
7576
}
7677

78+
// Increment row counter for error reporting (1-based indexing)
79+
i.rowCounter++
80+
7781
// Prune the row down to the size of the schema. It can be larger in the case of running with an outer scope, in which
7882
// case the additional scope variables are prepended to the row.
7983
if len(row) > len(i.schema) {
@@ -141,7 +145,7 @@ func (i *insertIter) Next(ctx *sql.Context) (returnRow sql.Row, returnErr error)
141145
} else if sql.ErrNotMatchingSRID.Is(cErr) {
142146
cErr = sql.ErrNotMatchingSRIDWithColName.New(col.Name, cErr)
143147
} else if types.ErrDataTruncatedForColumn.Is(cErr) {
144-
cErr = types.ErrDataTruncatedForColumn.New(col.Name)
148+
cErr = types.ErrDataTruncatedForColumnAtRow.New(col.Name, i.rowCounter)
145149
}
146150
return nil, sql.NewWrappedInsertError(origRow, cErr)
147151
}

sql/types/enum.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ var (
4444

4545
ErrDataTruncatedForColumn = errors.NewKind("Data truncated for column '%s'")
4646

47+
ErrDataTruncatedForColumnAtRow = errors.NewKind("Data truncated for column '%s' at row %d")
48+
4749
enumValueType = reflect.TypeOf(uint16(0))
4850
)
4951

0 commit comments

Comments
 (0)