Skip to content

Commit

Permalink
executor, util: fix gorm-test when cast a value to varbinary(N) (#3379)
Browse files Browse the repository at this point in the history
  • Loading branch information
XuHuaiyu authored and coocood committed Jun 4, 2017
1 parent 62450b9 commit cae65ff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions executor/write_test.go
Expand Up @@ -145,6 +145,21 @@ func (s *testSuite) TestInsert(c *C) {
c.Assert(err, IsNil)
_, err = tk.Exec("insert into t value(1)")
c.Assert(types.ErrOverflow.Equal(err), IsTrue)

tk.MustExec("drop table if exists t")
tk.MustExec("create table t(c binary(255))")
_, err = tk.Exec("insert into t value(1)")
c.Assert(err, IsNil)
r = tk.MustQuery("select length(c) from t;")
r.Check(testkit.Rows("255"))

tk.MustExec("drop table if exists t")
tk.MustExec("create table t(c varbinary(255))")
_, err = tk.Exec("insert into t value(1)")
c.Assert(err, IsNil)
r = tk.MustQuery("select length(c) from t;")
r.Check(testkit.Rows("1"))

}

func (s *testSuite) TestInsertAutoInc(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion util/types/datum.go
Expand Up @@ -861,7 +861,7 @@ func produceStrWithSpecifiedTp(s string, tp *FieldType, sc *variable.StatementCo
} else if len(s) > flen {
err = ErrDataTooLong.Gen("Data Too Long, field len %d, data len %d", flen, len(s))
s = truncateStr(s, flen)
} else if len(s) < flen {
} else if tp.Tp == mysql.TypeString && len(s) < flen {
padding := make([]byte, flen-len(s))
s = string(append([]byte(s), padding...))
}
Expand Down

0 comments on commit cae65ff

Please sign in to comment.