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

UNHEX now returns []byte #619

Merged
merged 3 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions sql/expression/function/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func assertResultType(t *testing.T, expectedType sql.Type, result interface{}) {
assert.Equal(t, expectedType, sql.Datetime)
case bool:
assert.Equal(t, expectedType, sql.Boolean)
case []byte:
assert.Equal(t, expectedType, sql.LongBlob)
default:
assert.Fail(t, "unhandled case")
}
Expand Down
5 changes: 4 additions & 1 deletion sql/expression/function/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ func (h *Hex) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {

return hexForString(s), nil

case []byte:
return hexForString(string(val)), nil

default:
return nil, ErrInvalidArgument.New("crc32", fmt.Sprint(arg))
}
Expand Down Expand Up @@ -258,7 +261,7 @@ func (h *Unhex) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
return nil, err
}

return string(res), nil
return res, nil
}

// WithChildren implements the sql.Expression interface
Expand Down
16 changes: 8 additions & 8 deletions sql/expression/function/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ func TestUnhexFunc(t *testing.T) {
f := sql.Function1{Name: "unhex", Fn: NewUnhex}
tf := NewTestFactory(f.Fn)
tf.AddSucceeding(nil, nil)
tf.AddSucceeding("MySQL", "4D7953514C")
tf.AddSucceeding("\x01#Eg\x89\xab\xcd\xef", "0123456789abcdef")
tf.AddSucceeding("\x8f", "8F")
tf.AddSucceeding("\x8f", "8f")
tf.AddSucceeding("\x0b", "B")
tf.AddSucceeding([]byte("MySQL"), "4D7953514C")
tf.AddSucceeding([]byte{0x1, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, "0123456789abcdef")
tf.AddSucceeding([]byte{0x8f}, "8F")
tf.AddSucceeding([]byte{0x8f}, "8f")
tf.AddSucceeding([]byte{0x0b}, "B")
tf.AddSucceeding(nil, "gh")
tf.AddSignedVariations("5", 35)
tf.AddSignedVariations("\x01", 1)
tf.AddSignedVariations([]byte{0x35}, 35)
tf.AddSignedVariations([]byte{0x01}, 1)
tf.AddSignedVariations(nil, -1)
tf.AddUnsignedVariations("5", 35)
tf.AddUnsignedVariations([]byte{0x35}, 35)
tf.AddFloatVariations(nil, 35.5)
tf.AddSucceeding(nil, time.Now())

Expand Down