Skip to content

Commit

Permalink
types: fix wrong truncated val for bit type (#25198)
Browse files Browse the repository at this point in the history
  • Loading branch information
wshwsh12 authored Jun 7, 2021
1 parent 3947c5c commit 2017d2f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,15 @@ func (s *testIntegrationSuite) TestConvertToBit(c *C) {
"Warning 1690 constant 599999999 overflows tinyint",
"Warning 1406 Data Too Long, field len 63"))
tk.MustQuery("select * from t;").Check(testkit.Rows("127 \u007f\xff\xff\xff\xff\xff\xff\xff"))

// For issue 24900
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t(b bit(16));")
tk.MustExec("insert ignore into t values(0x3635313836),(0x333830);")
tk.MustQuery("show warnings;").Check(testkit.Rows(
"Warning 1406 Data Too Long, field len 16",
"Warning 1406 Data Too Long, field len 16"))
tk.MustQuery("select * from t;").Check(testkit.Rows("\xff\xff", "\xff\xff"))
}

func (s *testIntegrationSuite2) TestMathBuiltin(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion types/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ func (d *Datum) convertToMysqlBit(sc *stmtctx.StatementContext, target *FieldTyp
return Datum{}, errors.Trace(ErrDataTooLong.GenWithStack("Data Too Long, field len %d", target.Flen))
}
if target.Flen < 64 && uintValue >= 1<<(uint64(target.Flen)) {
uintValue &= (1 << (uint64(target.Flen))) - 1
uintValue = (1 << (uint64(target.Flen))) - 1
err = ErrDataTooLong.GenWithStack("Data Too Long, field len %d", target.Flen)
}
byteSize := (target.Flen + 7) >> 3
Expand Down

0 comments on commit 2017d2f

Please sign in to comment.