Skip to content

Commit

Permalink
fix invalid YEAR string is not compatible with Mysql (#9856)
Browse files Browse the repository at this point in the history
  • Loading branch information
b41sh authored and lzmhhh123 committed Mar 25, 2019
1 parent c451f00 commit 5025d58
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions types/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,9 @@ func (s *testTypeConvertSuite) TestConvert(c *C) {
signedDeny(c, mysql.TypeYear, 123, "<nil>")
signedDeny(c, mysql.TypeYear, 3000, "<nil>")
signedAccept(c, mysql.TypeYear, "2000", "2000")
signedAccept(c, mysql.TypeYear, "abc", "0")
signedAccept(c, mysql.TypeYear, "00abc", "2000")
signedAccept(c, mysql.TypeYear, "0019", "2019")

// time from string
signedAccept(c, mysql.TypeDate, "2012-08-23", "2012-08-23")
Expand Down
4 changes: 3 additions & 1 deletion types/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,9 @@ func (d *Datum) convertToMysqlYear(sc *stmtctx.StatementContext, target *FieldTy
if err != nil {
return ret, errors.Trace(err)
}
adjust = len(s) < 4
if len(s) != 4 && len(s) > 0 && s[0:1] == "0" {
adjust = true
}
case KindMysqlTime:
y = int64(d.GetMysqlTime().Time.Year())
case KindMysqlDuration:
Expand Down

0 comments on commit 5025d58

Please sign in to comment.