Skip to content

Commit

Permalink
cherry pick pingcap#21849 to release-4.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
LittleFall authored and ti-srebot committed Dec 23, 2020
1 parent 6304fe6 commit 6b20245
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 6b20245

Please sign in to comment.