Skip to content

Commit

Permalink
expression: unset the flen for string type builtin control
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta committed Nov 2, 2022
1 parent 8db7c3b commit bddb16c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions expression/builtin_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func InferType4ControlFuncs(ctx sessionctx.Context, funcName string, lexp, rexp
} else if resultEvalType == types.ETString {
if lhs.GetType() != mysql.TypeNull || rhs.GetType() != mysql.TypeNull {
resultFieldType.SetDecimal(types.UnspecifiedLength)
resultFieldType.SetFlen(types.UnspecifiedLength)
}
if resultFieldType.GetType() == mysql.TypeEnum || resultFieldType.GetType() == mysql.TypeSet {
resultFieldType.SetType(mysql.TypeVarchar)
Expand Down
11 changes: 11 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7805,3 +7805,14 @@ func TestJSONExtractRange(t *testing.T) {
tk.MustQuery(`select json_extract('[{"a": [1,2,3,4]}]', '$[0].a[0 to last]')`).Check(testkit.Rows("[1, 2, 3, 4]"))
tk.MustQuery(`select json_extract('[{"a": [1,2,3,4]}]', '$[0].a[0 to 2]')`).Check(testkit.Rows("[1, 2, 3]"))
}

func TestIfNullParamMarker(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t (c1 varchar(100), c2 varchar(128));")
tk.MustExec(`prepare pr1 from "insert into t values(ifnull(?,' '),ifnull(?,' '))";`)
tk.MustExec(`set @a='1',@b=repeat('x', 80);`)
// Should not report 'Data too long for column' error.
tk.MustExec(`execute pr1 using @a,@b;`)
}

0 comments on commit bddb16c

Please sign in to comment.