From 6b202455fbdd67f36863879cfc9dc5d52cf1f3b7 Mon Sep 17 00:00:00 2001 From: Zhi Qi <30543181+LittleFall@users.noreply.github.com> Date: Wed, 23 Dec 2020 12:59:48 +0800 Subject: [PATCH] cherry pick #21849 to release-4.0 Signed-off-by: ti-srebot --- executor/seqtest/prepared_test.go | 32 +++++++++++++++++++++++++------ types/field_type.go | 2 +- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/executor/seqtest/prepared_test.go b/executor/seqtest/prepared_test.go index d01f596d2b68b..1626fb08cbf16 100644 --- a/executor/seqtest/prepared_test.go +++ b/executor/seqtest/prepared_test.go @@ -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")) } } diff --git a/types/field_type.go b/types/field_type.go index dbcf7c3632eb7..cb7d43ebbaaaf 100644 --- a/types/field_type.go +++ b/types/field_type.go @@ -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