Skip to content

Commit

Permalink
types: Add missing TypeNewDate in ConvertTo (pingcap#2962)
Browse files Browse the repository at this point in the history
  • Loading branch information
shenli authored and coocood committed Mar 30, 2017
1 parent 9041012 commit d87afa1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions util/types/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ func (s *testTypeConvertSuite) TestConvertType(c *C) {
c.Assert(err, IsNil)
c.Assert(vv.(Time).String(), Equals, "2010-10-10 10:11:11.1")

// For mysql.TypeNewDate.
ft = NewFieldType(mysql.TypeNewDate)
ft.Decimal = 3
v, err = Convert("2010-10-10 10:11:11.12345", ft)
c.Assert(err, IsNil)
c.Assert(v.(Time).String(), Equals, "2010-10-10 10:11:11.123")

// For TypeLonglong
ft = NewFieldType(mysql.TypeLonglong)
v, err = Convert("100", ft)
Expand Down
2 changes: 1 addition & 1 deletion util/types/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ func (d *Datum) ConvertTo(sc *variable.StatementContext, target *FieldType) (Dat
case mysql.TypeBlob, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob,
mysql.TypeString, mysql.TypeVarchar, mysql.TypeVarString:
return d.convertToString(sc, target)
case mysql.TypeTimestamp, mysql.TypeDatetime, mysql.TypeDate:
case mysql.TypeTimestamp, mysql.TypeDatetime, mysql.TypeDate, mysql.TypeNewDate:
return d.convertToMysqlTime(sc, target)
case mysql.TypeDuration:
return d.convertToMysqlDuration(sc, target)
Expand Down

0 comments on commit d87afa1

Please sign in to comment.