Skip to content

Commit

Permalink
cherry pick #21849 to release-4.0 (#21960)
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>

Co-authored-by: Zhi Qi <30543181+LittleFall@users.noreply.github.com>
Co-authored-by: Kenan Yao <cauchy1992@gmail.com>
  • Loading branch information
3 people authored Jan 8, 2021
1 parent 1b9ef96 commit c2c767a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
32 changes: 26 additions & 6 deletions executor/seqtest/prepared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,19 +741,39 @@ func (s *seqTestSuite) TestPreparedIssue8644(c *C) {
c.Assert(err, IsNil)

tk.MustExec("use test")

tk.MustExec("drop table if exists t")
tk.MustExec("create table t(data mediumblob)")

tk.MustExec(`prepare stmt1 from 'insert t (data) values (?)'`)

tk.MustExec(`prepare stmt from 'insert t (data) values (?)'`)
tk.MustExec(`set @a = 'a'`)
tk.MustExec(`execute stmt1 using @a;`)

tk.MustExec(`execute stmt using @a;`)
tk.MustExec(`set @b = 'aaaaaaaaaaaaaaaaaa'`)
tk.MustExec(`execute stmt1 using @b;`)
tk.MustExec(`execute stmt using @b;`)

r := tk.MustQuery(`select * from t`)
r.Check(testkit.Rows("a", "aaaaaaaaaaaaaaaaaa"))

tk.MustExec("drop table if exists t")
tk.MustExec("create table t(data decimal)")
tk.MustExec(`prepare stmt from 'insert t (data) values (?)'`)
tk.MustExec(`set @a = '1'`)
tk.MustExec(`execute stmt using @a;`)
tk.MustExec(`set @b = '11111.11111'`) // '.11111' will be truncated.
tk.MustExec(`execute stmt using @b;`)

r = tk.MustQuery(`select * from t`)
r.Check(testkit.Rows("1", "11111"))

tk.MustExec("drop table if exists t")
tk.MustExec("create table t(data decimal(10,3));")
tk.MustExec("prepare stmt from 'insert t (data) values (?)';")
tk.MustExec("set @a = 1.1;")
tk.MustExec("execute stmt using @a;")
tk.MustExec("set @b = 11.11;")
tk.MustExec("execute stmt using @b;")

r = tk.MustQuery(`select * from t`)
r.Check(testkit.Rows("1.100", "11.110"))
}
}

Expand Down
2 changes: 1 addition & 1 deletion types/field_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func DefaultParamTypeForValue(value interface{}, tp *FieldType) {
func hasVariantFieldLength(tp *FieldType) bool {
switch tp.Tp {
case mysql.TypeLonglong, mysql.TypeVarString, mysql.TypeDouble, mysql.TypeBlob,
mysql.TypeBit, mysql.TypeDuration, mysql.TypeNewDecimal, mysql.TypeEnum, mysql.TypeSet:
mysql.TypeBit, mysql.TypeDuration, mysql.TypeEnum, mysql.TypeSet:
return true
}
return false
Expand Down

0 comments on commit c2c767a

Please sign in to comment.