Skip to content

Commit 8371d26

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

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pkg/types/field_type.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func SetTypeFlag(flag *uint, flagItem uint, on bool) {
179179
// InferParamTypeFromDatum is used for plan cache to infer the type of a parameter from its datum.
180180
func InferParamTypeFromDatum(d *Datum, tp *FieldType) {
181181
InferParamTypeFromUnderlyingValue(d.GetValue(), tp)
182-
if IsStringKind(d.k) {
182+
if IsStringKind(d.k) || d.GetValue() == nil {
183183
// consider charset and collation here
184184
c, err := collate.GetCollationByName(d.collation)
185185
if err != nil || c == nil {
@@ -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) {

0 commit comments

Comments
 (0)