Skip to content

Commit

Permalink
*: make string in select result convert to bit correctly. (pingcap#3188)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobotu authored and XuHuaiyu committed May 3, 2017
1 parent 3f296ed commit 67c62b3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1323,3 +1323,32 @@ func (s *testSuite) TestSimpleDAG(c *C) {
tk.MustQuery("select a from t where c = 1 order by a limit 1").Check(testkit.Rows("1"))
tk.MustQuery("select count(*) from t where c = 1 ").Check(testkit.Rows("2"))
}

func (s *testSuite) TestConvertToBit(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t, t1")
tk.MustExec("create table t (a bit(64))")
tk.MustExec("create table t1 (a varchar(2))")
tk.MustExec(`insert t1 value ('10')`)
tk.MustExec(`insert t select a from t1`)
tk.MustQuery("select a+0 from t").Check(testkit.Rows("12592"))

tk.MustExec("drop table if exists t, t1")
tk.MustExec("create table t (a bit(64))")
tk.MustExec("create table t1 (a binary(2))")
tk.MustExec(`insert t1 value ('10')`)
tk.MustExec(`insert t select a from t1`)
tk.MustQuery("select a+0 from t").Check(testkit.Rows("12592"))

tk.MustExec("drop table if exists t, t1")
tk.MustExec("create table t (a bit(64))")
tk.MustExec("create table t1 (a datetime)")
tk.MustExec(`insert t1 value ('09-01-01')`)
tk.MustExec(`insert t select a from t1`)
tk.MustQuery("select a+0 from t").Check(testkit.Rows("20090101000000"))
}
2 changes: 1 addition & 1 deletion util/types/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ func (d *Datum) convertToMysqlBit(sc *variable.StatementContext, target *FieldTy
x Datum
err error
)
if d.Kind() == KindString {
if d.Kind() == KindString || d.Kind() == KindBytes {
var n uint64
n, err = ParseStringToBitValue(d.GetString(), target.Flen)
x = NewUintDatum(n)
Expand Down

0 comments on commit 67c62b3

Please sign in to comment.