Skip to content

Commit 101873e

Browse files
committed
fix blob type print
1 parent 832ec94 commit 101873e

File tree

2 files changed

+8
-25
lines changed

2 files changed

+8
-25
lines changed

sql/types/strings.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,14 @@ func (t StringType) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqltypes.
712712
return sqltypes.Value{}, err
713713
}
714714

715-
// Format binary data as hexadecimal with 0x prefix to match MySQL's display behavior
716-
result := append([]byte("0x"), bytes.ToUpper([]byte(fmt.Sprintf("%x", binaryBytes)))...)
717-
val = result
715+
// Apply hex formatting only to VARBINARY and BINARY types, not BLOB types
716+
// This ensures function results (which typically use BLOB types) display as raw bytes
717+
if t.baseType == sqltypes.VarBinary || t.baseType == sqltypes.Binary {
718+
result := append([]byte("0x"), bytes.ToUpper([]byte(fmt.Sprintf("%x", binaryBytes)))...)
719+
val = result
720+
} else {
721+
val = binaryBytes
722+
}
718723
} else {
719724
var valueBytes []byte
720725
switch v := v.(type) {

sql/types/strings_test.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -379,28 +379,6 @@ func TestStringConvert(t *testing.T) {
379379
}
380380
}
381381

382-
func TestBinaryDataSQLFormatting(t *testing.T) {
383-
ctx := sql.NewEmptyContext()
384-
tests := []struct {
385-
name string
386-
typ sql.StringType
387-
val interface{}
388-
expectedVal interface{}
389-
}{
390-
{"binary hex", MustCreateBinary(sqltypes.Binary, 4), []byte{0x0A, 0x00, 0x00, 0x00}, []byte{'0', 'x', '0', 'A', '0', '0', '0', '0', '0', '0'}},
391-
{"varbinary hex", MustCreateBinary(sqltypes.VarBinary, 4), []byte{0x0A, 0x00, 0x40, 0x00}, []byte{'0', 'x', '0', 'A', '0', '0', '4', '0', '0', '0'}},
392-
{"blob hex", MustCreateBinary(sqltypes.Blob, 4), []byte{0x0A, 0x00, 0x80, 0x00}, []byte{'0', 'x', '0', 'A', '0', '0', '8', '0', '0', '0'}},
393-
}
394-
395-
for _, test := range tests {
396-
t.Run(test.name, func(t *testing.T) {
397-
val, err := test.typ.SQL(ctx, nil, test.val)
398-
require.NoError(t, err)
399-
actual := val.Raw()
400-
assert.Equal(t, test.expectedVal, actual)
401-
})
402-
}
403-
}
404382

405383
func TestStringString(t *testing.T) {
406384
tests := []struct {

0 commit comments

Comments
 (0)