Skip to content

Commit 2ed41c9

Browse files
committed
mv errs mysql84 'namespace'
1 parent ea0916e commit 2ed41c9

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

sql/errors.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ import (
2222
"gopkg.in/src-d/go-errors.v1"
2323
)
2424

25+
// MySQL84 contains error definitions that match MySQL 8.4 behavior and formatting
26+
var MySQL84 = struct {
27+
// ErrForeignKeyChildViolation is the MySQL 8.4 compatible error format for foreign key child violations
28+
ErrForeignKeyChildViolation *errors.Kind
29+
}{
30+
ErrForeignKeyChildViolation: errors.NewKind("cannot add or update a child row: a foreign key constraint fails (`%s`.`%s`, CONSTRAINT `%s` FOREIGN KEY (`%s`) REFERENCES `%s` (`%s`))"),
31+
}
32+
2533
var (
2634
// ErrSyntaxError is returned when a syntax error in vitess is encountered.
2735
ErrSyntaxError = errors.NewKind("%s")
@@ -419,7 +427,7 @@ var (
419427
ErrInsertIntoNonNullableProvidedNull = errors.NewKind("column name '%v' is non-nullable but attempted to set a value of null")
420428

421429
// ErrForeignKeyChildViolation is called when a rows is added but there is no parent row, and a foreign key constraint fails. Add the parent row first.
422-
ErrForeignKeyChildViolation = errors.NewKind("cannot add or update a child row: a foreign key constraint fails (`%s`.`%s`, CONSTRAINT `%s` FOREIGN KEY (`%s`) REFERENCES `%s` (`%s`))")
430+
ErrForeignKeyChildViolation = errors.NewKind("cannot add or update a child row - Foreign key violation on fk: `%s`, table: `%s`, referenced table: `%s`, key: `%s`")
423431

424432
// ErrForeignKeyParentViolation is called when a parent row that is deleted has children, and a foreign key constraint fails. Delete the children first.
425433
ErrForeignKeyParentViolation = errors.NewKind("cannot delete or update a parent row - Foreign key violation on fk: `%s`, table: `%s`, referenced table: `%s`, key: `%s`")
@@ -983,6 +991,8 @@ func CastSQLError(err error) *mysql.SQLError {
983991
code = 1526 // TODO: Needs to be added to vitess
984992
case ErrForeignKeyChildViolation.Is(err):
985993
code = mysql.ErNoReferencedRow2 // test with mysql returns 1452 vs 1216
994+
case MySQL84.ErrForeignKeyChildViolation.Is(err):
995+
code = mysql.ErNoReferencedRow2 // test with mysql returns 1452 vs 1216
986996
case ErrForeignKeyParentViolation.Is(err):
987997
code = mysql.ERRowIsReferenced2 // test with mysql returns 1451 vs 1215
988998
case ErrDuplicateEntry.Is(err):

sql/plan/foreign_key_editor.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,8 @@ func (reference *ForeignKeyReferenceHandler) CheckReference(ctx *sql.Context, ro
514514
if err == nil {
515515
// We have a parent row, but for DECIMAL types we need to be strict about precision/scale
516516
if shouldReject := reference.validateDecimalMatch(ctx, row); shouldReject {
517-
return sql.ErrForeignKeyChildViolation.New(reference.ForeignKey.Database, reference.ForeignKey.Table,
517+
// Use MySQL 8.4 compatible format for DECIMAL foreign key violations
518+
return sql.MySQL84.ErrForeignKeyChildViolation.New(reference.ForeignKey.Database, reference.ForeignKey.Table,
518519
reference.ForeignKey.Name, strings.Join(reference.ForeignKey.Columns, ", "),
519520
reference.ForeignKey.ParentTable, strings.Join(reference.ForeignKey.ParentColumns, ", "))
520521
}
@@ -541,7 +542,8 @@ func (reference *ForeignKeyReferenceHandler) CheckReference(ctx *sql.Context, ro
541542
}
542543
}
543544

544-
return sql.ErrForeignKeyChildViolation.New(reference.ForeignKey.Database, reference.ForeignKey.Table,
545+
// Use MySQL 8.4 compatible format for all foreign key violations going forward
546+
return sql.MySQL84.ErrForeignKeyChildViolation.New(reference.ForeignKey.Database, reference.ForeignKey.Table,
545547
reference.ForeignKey.Name, strings.Join(reference.ForeignKey.Columns, ", "),
546548
reference.ForeignKey.ParentTable, strings.Join(reference.ForeignKey.ParentColumns, ", "))
547549
}

0 commit comments

Comments
 (0)