Skip to content

Commit 7988416

Browse files
committed
fix specific errs
1 parent 97f03f3 commit 7988416

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

enginetest/queries/script_queries.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10131,8 +10131,8 @@ where
1013110131
},
1013210132
},
1013310133
{
10134-
Query: "insert into t2 values ('A,B,c');",
10135-
ExpectedErr: sql.ErrInvalidSetValue,
10134+
Query: "insert into t2 values ('A,B,c');",
10135+
ExpectedErrStr: "Data truncated for column 's' at row 1",
1013610136
},
1013710137
{
1013810138
Query: "select * from t2",
@@ -10145,7 +10145,6 @@ where
1014510145
},
1014610146
},
1014710147
{
10148-
Skip: true,
1014910148
Name: "set with foreign keys",
1015010149
Dialect: "mysql",
1015110150
SetUpScript: []string{
@@ -10325,7 +10324,6 @@ where
1032510324
},
1032610325
},
1032710326
{
10328-
Skip: true,
1032910327
Name: "set with foreign keys and cascade",
1033010328
Dialect: "mysql",
1033110329
SetUpScript: []string{

sql/plan/alter_foreign_key.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,9 @@ func foreignKeyComparableTypes(ctx *sql.Context, type1 sql.Type, type2 sql.Type)
663663
// MySQL allows decimal foreign keys with different precision/scale
664664
// The foreign key constraint validation will handle the actual value comparison
665665
return true
666+
case sqltypes.Set:
667+
// MySQL allows set foreign keys to match based on underlying numeric values.
668+
return true
666669
default:
667670
return false
668671
}

sql/plan/foreign_key_editor.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,11 @@ func (reference *ForeignKeyReferenceHandler) CheckReference(ctx *sql.Context, ro
509509

510510
_, err = rowIter.Next(ctx)
511511
if err != nil && err != io.EOF {
512+
// For SET types, conversion failures during foreign key validation should be treated as foreign key violations
513+
if sql.ErrConvertingToSet.Is(err) || sql.ErrInvalidSetValue.Is(err) {
514+
return sql.ErrForeignKeyChildViolation.New(reference.ForeignKey.Name, reference.ForeignKey.Table,
515+
reference.ForeignKey.ParentTable, reference.RowMapper.GetKeyString(row))
516+
}
512517
return err
513518
}
514519
if err == nil {

sql/rowexec/insert.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ func (i *insertIter) Next(ctx *sql.Context) (returnRow sql.Row, returnErr error)
153153
cErr = sql.ErrNotMatchingSRIDWithColName.New(col.Name, cErr)
154154
} else if types.ErrConvertingToEnum.Is(cErr) {
155155
cErr = types.ErrDataTruncatedForColumnAtRow.New(col.Name, i.rowNumber)
156+
} else if sql.ErrInvalidSetValue.Is(cErr) {
157+
cErr = types.ErrDataTruncatedForColumnAtRow.New(col.Name, i.rowNumber)
158+
} else if sql.ErrConvertingToSet.Is(cErr) {
159+
cErr = types.ErrDataTruncatedForColumnAtRow.New(col.Name, i.rowNumber)
156160
}
157161
return nil, sql.NewWrappedInsertError(origRow, cErr)
158162
}

0 commit comments

Comments
 (0)