Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql/mysql: add table+column context to parse type errors #2023

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions sql/mysql/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ func FormatType(t schema.Type) (string, error) {
}
case *schema.DecimalType:
if f = strings.ToLower(t.T); f != TypeDecimal && f != TypeNumeric {
return "", fmt.Errorf("mysql: unexpected decimal type: %q", t.T)
return "", fmt.Errorf("unexpected decimal type: %q", t.T)
}
switch p, s := t.Precision, t.Scale; {
case p < 0 || s < 0:
return "", fmt.Errorf("mysql: decimal type must have precision > 0 and scale >= 0: %d, %d", p, s)
return "", fmt.Errorf("decimal type must have precision > 0 and scale >= 0: %d, %d", p, s)
case p < s:
return "", fmt.Errorf("mysql: decimal type must have precision >= scale: %d < %d", p, s)
return "", fmt.Errorf("decimal type must have precision >= scale: %d < %d", p, s)
case p == 0 && s == 0:
// The default value for precision is 10 (i.e. decimal(0,0) = decimal(10)).
p = 10
Expand Down Expand Up @@ -205,7 +205,7 @@ func ParseType(raw string) (schema.Type, error) {
// github.com/mysql/mysql-server/blob/8.0/sql/field.cc#Field_enum::sql_type
rv := strings.TrimSuffix(strings.TrimPrefix(raw, t+"("), ")")
if rv == "" {
return nil, fmt.Errorf("mysql: unexpected enum type: %q", raw)
return nil, fmt.Errorf("unexpected enum type: %q", raw)
}
values := strings.Split(rv, "','")
for i := range values {
Expand Down
2 changes: 1 addition & 1 deletion sql/mysql/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (i *inspect) addColumn(s *schema.Schema, rows *sql.Rows) error {
}
ct, err := ParseType(c.Type.Raw)
if err != nil {
return err
return fmt.Errorf("parse %q.%q type %q: %w", t.Name, c.Name, c.Type.Raw, err)
}
c.Type.Type = ct
attr, err := parseExtra(extra.String)
Expand Down