Skip to content

Commit

Permalink
Cast once.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Jul 2, 2024
1 parent 7d9afe5 commit 97dacfa
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/mysql/schema/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ func ConvertValue(value any, colType DataType) (any, error) {
return nil, fmt.Errorf("expected []byte got %T for value: %v", value, value)
}

if strings.HasSuffix(string(bytesValue), "-00-00 00:00:00") {
stringValue := string(bytesValue)
if strings.HasSuffix(stringValue, "-00-00 00:00:00") {
// If MySQL strict mode isn't turned on, it can allow invalid dates like 2020-00-00 00:00:00 or 0000-00-00 00:00:00
return nil, nil
}

timeValue, err := time.Parse(DateTimeFormat, string(bytesValue))
timeValue, err := time.Parse(DateTimeFormat, stringValue)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 97dacfa

Please sign in to comment.