Skip to content

Commit 480d897

Browse files
committed
In convertArg, don't convert binary data to strings.
In this case, the input is binary, and the column type is `binary`. So the output should be binary, not text.
1 parent 698ae27 commit 480d897

2 files changed

Lines changed: 3 additions & 12 deletions

File tree

go/sql/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (this *Column) convertArg(arg interface{}) interface{} {
8484
for i := uint(0); i < (this.BinaryOctetLength - uint(size)); i++ {
8585
buf.Write([]byte{0})
8686
}
87-
arg = buf.String()
87+
arg = buf.Bytes()
8888
}
8989
}
9090

go/sql/types_test.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestConvertArgBinaryColumnPadding(t *testing.T) {
8686
}
8787

8888
result := col.convertArg(truncatedValue)
89-
resultBytes := []byte(result.(string))
89+
resultBytes := result.([]byte)
9090

9191
require.Equal(t, 20, len(resultBytes), "binary column should be padded to declared length")
9292
// First 18 bytes should be unchanged
@@ -110,16 +110,7 @@ func TestConvertArgBinaryColumnNoPaddingWhenFull(t *testing.T) {
110110
}
111111

112112
result := col.convertArg(fullValue)
113-
// When no padding needed, result may be []uint8 or string depending on code path
114-
var resultBytes []byte
115-
switch v := result.(type) {
116-
case string:
117-
resultBytes = []byte(v)
118-
case []uint8:
119-
resultBytes = v
120-
default:
121-
t.Fatalf("unexpected type %T", result)
122-
}
113+
resultBytes := result.([]byte)
123114

124115
require.Equal(t, 20, len(resultBytes))
125116
require.Equal(t, []byte(fullValue), resultBytes)

0 commit comments

Comments
 (0)