Skip to content

Commit e98123e

Browse files
committed
avoid complaining about the binary collation in prepare
Signed-off-by: Yang Keao <[email protected]>
1 parent 1bf1d39 commit e98123e

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

pkg/types/field_type.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ func InferParamTypeFromUnderlyingValue(value any, tp *FieldType) {
197197
tp.SetType(mysql.TypeVarString)
198198
tp.SetFlen(UnspecifiedLength)
199199
tp.SetDecimal(UnspecifiedLength)
200+
// Also set the `charset` and `collation` for it, because some function (e.g. `json_object`) will return error
201+
// if the argument collation is `binary`.
202+
tp.SetCharset(mysql.DefaultCharset)
203+
tp.SetCollate(mysql.DefaultCollationName)
200204
default:
201205
DefaultTypeForValue(value, tp, mysql.DefaultCharset, mysql.DefaultCollationName)
202206
if hasVariantFieldLength(tp) {

tests/integrationtest/r/expression/json.result

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,3 +812,8 @@ SELECT JSON_KEYS(b2) FROM t1;
812812
Error 3144 (HY000): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
813813
SELECT JSON_SCHEMA_VALID(b2, '{}') FROM t1;
814814
Error 3144 (HY000): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
815+
prepare stmt from 'select json_object(?, ?)';
816+
set @a=1;
817+
execute stmt using @a, @a;
818+
json_object(?, ?)
819+
{"1": 1}

tests/integrationtest/t/expression/json.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,3 +533,8 @@ SELECT JSON_SEARCH(b2, 'one', '1') FROM t1;
533533
SELECT JSON_KEYS(b2) FROM t1;
534534
-- error 3144
535535
SELECT JSON_SCHEMA_VALID(b2, '{}') FROM t1;
536+
537+
# TestIssue54044
538+
prepare stmt from 'select json_object(?, ?)';
539+
set @a=1;
540+
execute stmt using @a, @a;

0 commit comments

Comments
 (0)