Skip to content

Commit d46d968

Browse files
committed
mv errs mysql84 'namespace'
1 parent b6cb946 commit d46d968

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
@@ -23,6 +23,14 @@ import (
2323
"gopkg.in/src-d/go-errors.v1"
2424
)
2525

26+
// MySQL84 contains error definitions that match MySQL 8.4 behavior and formatting
27+
var MySQL84 = struct {
28+
// ErrForeignKeyChildViolation is the MySQL 8.4 compatible error format for foreign key child violations
29+
ErrForeignKeyChildViolation *errors.Kind
30+
}{
31+
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`))"),
32+
}
33+
2634
var (
2735
// ErrSyntaxError is returned when a syntax error in vitess is encountered.
2836
ErrSyntaxError = errors.NewKind("%s")
@@ -420,7 +428,7 @@ var (
420428
ErrInsertIntoNonNullableProvidedNull = errors.NewKind("column name '%v' is non-nullable but attempted to set a value of null")
421429

422430
// 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.
423-
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`))")
431+
ErrForeignKeyChildViolation = errors.NewKind("cannot add or update a child row - Foreign key violation on fk: `%s`, table: `%s`, referenced table: `%s`, key: `%s`")
424432

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