Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: Regard TypeNewDecimal as not a hasVariantFieldLength type. (#21849) #21960

Merged
merged 3 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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