Skip to content

Commit

Permalink
util/types: address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood committed Sep 6, 2015
1 parent be56437 commit 0054f81
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions util/types/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,15 @@ func Convert(val interface{}, target *FieldType) (v interface{}, err error) { //
// TODO: check Flen
return x, nil
case mysql.TypeYear:
var intVal int64
var err error
var (
intVal int64
err error
)
switch x := val.(type) {
case string:
intVal, err = StrToInt(x)
default:
intVal, err = ToInt64(val)
intVal, err = ToInt64(x)
}
if err != nil {
return InvConv(val, tp)
Expand Down
2 changes: 1 addition & 1 deletion util/types/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (s *testTypeConvertSuite) TestConvertType(c *C) {
c.Assert(err, IsNil)
c.Assert(v.(mysql.Decimal).String(), Equals, "3.14159")

// Fot TypeYear
// For TypeYear
ft = NewFieldType(mysql.TypeYear)
v, err = Convert("2015-11-11", ft)
c.Assert(err, IsNil)
Expand Down

1 comment on commit 0054f81

@qiuyesuifeng
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Please sign in to comment.