Skip to content

Commit

Permalink
MySQL guardrail.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Jul 2, 2024
1 parent c5a81ec commit 7d9afe5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/mysql/schema/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/binary"
"fmt"
"math"
"strings"
"time"
)

Expand Down Expand Up @@ -82,9 +83,8 @@ func ConvertValue(value any, colType DataType) (any, error) {
return nil, fmt.Errorf("expected []byte got %T for value: %v", value, value)
}

if string(bytesValue) == "0000-00-00 00:00:00" {
// MySQL supports '0000-00-00 00:00:00' for datetime columns.
// We are returning `nil` here because this will fail most Time parsers.
if strings.HasSuffix(string(bytesValue), "-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
}

Expand Down

0 comments on commit 7d9afe5

Please sign in to comment.