Skip to content

Commit

Permalink
pkg/param: add correct fsp for duration (#48564)
Browse files Browse the repository at this point in the history
close #48563
  • Loading branch information
YangKeao authored Nov 14, 2023
1 parent 69028f1 commit 4793a04
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pkg/param/binary_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func ExecArgs(typectx types.Context, binaryParams []BinaryParam) (params []expre
continue

case mysql.TypeDuration:
fsp := 0
switch len(binaryParams[i].Val) {
case 0:
tmp = "0"
Expand All @@ -155,13 +156,14 @@ func ExecArgs(typectx types.Context, binaryParams []BinaryParam) (params []expre
return
}
_, tmp = binaryDurationWithMS(1, binaryParams[i].Val, isNegative)
fsp = types.MaxFsp
default:
err = mysql.ErrMalformPacket
return
}
// TODO: generate the duration datum directly
var dur types.Duration
dur, _, err = types.ParseDuration(typectx, tmp.(string), types.MaxFsp)
dur, _, err = types.ParseDuration(typectx, tmp.(string), fsp)
err = typectx.HandleTruncate(err)
if err != nil {
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/conn_stmt_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func TestParseExecArgs(t *testing.T) {
},
nil,
types.ErrTruncatedWrongVal,
types.Duration{Duration: types.MinTime, Fsp: types.MaxFsp},
types.Duration{Duration: types.MinTime, Fsp: 0},
},
{
args{
Expand All @@ -226,7 +226,7 @@ func TestParseExecArgs(t *testing.T) {
},
nil,
nil,
types.Duration{Duration: time.Duration(0), Fsp: types.MaxFsp},
types.Duration{Duration: time.Duration(0), Fsp: 0},
},
// For error test
{
Expand Down

0 comments on commit 4793a04

Please sign in to comment.