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

fix invalid YEAR string is not compatible with Mysql #9856

Merged
merged 7 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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