Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: fix wrong behavior in values function for Bit(1). #15350

Merged
merged 8 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions expression/builtin_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,19 @@ func (b *builtinValuesIntSig) evalInt(_ chunk.Row) (int64, bool, error) {
if row.IsNull(b.offset) {
return 0, true, nil
}
// For BinaryLiteral, see issue #15310
val := row.GetRaw(b.offset)
if len(val) > 8 {
return 0, true, errors.New("Session current insert values is too long")
}
if len(val) < 8 {
qw4990 marked this conversation as resolved.
Show resolved Hide resolved
var binary types.BinaryLiteral = val
v, err := binary.ToInt(b.ctx.GetSessionVars().StmtCtx)
if err != nil {
return 0, true, errors.Trace(err)
}
return int64(v), false, nil
}
return row.GetInt64(b.offset), false, nil
}
return 0, true, errors.Errorf("Session current insert values len %d and column's offset %v don't match", row.Len(), b.offset)
Expand Down
15 changes: 15 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5341,6 +5341,21 @@ func (s *testIntegrationSuite) TestCastStrToInt(c *C) {
}
}

func (s *testIntegrationSuite) TestValuesForBinaryLiteral(c *C) {
// See issue #15310
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("create table testValuesBinary(id int primary key auto_increment, a bit(1));")
tk.MustExec("insert into testValuesBinary values(1,1);")
err := tk.ExecToErr("insert into testValuesBinary values(1,1) on duplicate key update id = values(id),a = values(a);")
c.Assert(err, IsNil)
tk.MustQuery("select a=0 from testValuesBinary;").Check(testkit.Rows("0"))
err = tk.ExecToErr("insert into testValuesBinary values(1,0) on duplicate key update id = values(id),a = values(a);")
c.Assert(err, IsNil)
tk.MustQuery("select a=0 from testValuesBinary;").Check(testkit.Rows("1"))
tk.MustExec("drop table testValuesBinary;")
}

func (s *testIntegrationSuite) TestIssue14159(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("DROP TABLE IF EXISTS t")
Expand Down