diff --git a/sql/item.cc b/sql/item.cc index 5bcb47d..854e63c 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -6962,8 +6962,8 @@ inline uint char_val(char X) { Item_hex_string::Item_hex_string() { hex_string_init("", 0); } -Item_hex_string::Item_hex_string(const char *str, uint str_length) { - hex_string_init(str, str_length); +Item_hex_string::Item_hex_string(const char *str, uint str_length, bool is_hex_str) { + hex_string_init(str, str_length, is_hex_str); } Item_hex_string::Item_hex_string(const POS &pos, const LEX_STRING &literal) @@ -6987,6 +6987,15 @@ LEX_CSTRING Item_hex_string::make_hex_str(const char *str, size_t str_length) { return ret; } +LEX_CSTRING Item_hex_string::make_hex_bytes(const char *str, size_t str_length) { + char *ptr = (char *)(*THR_MALLOC)->Alloc(str_length + 1); + if (ptr == nullptr) return NULL_CSTR; + LEX_CSTRING ret = {ptr, str_length}; + memcpy(ptr, str, str_length); + *(ptr + str_length) = 0; // needed if printed in error message + return ret; +} + uint Item_hex_string::decimal_precision() const { switch (max_length) { case 0: @@ -7013,8 +7022,15 @@ uint Item_hex_string::decimal_precision() const { } } -void Item_hex_string::hex_string_init(const char *str, uint str_length) { - LEX_CSTRING s = make_hex_str(str, str_length); +void Item_hex_string::hex_string_init(const char *str, uint str_length, bool is_hex_str) { + LEX_CSTRING s; + + if (is_hex_str) { + s = make_hex_str(str, str_length); + } else { + s = make_hex_bytes(str, str_length); + } + str_value.set(s.str, s.length, &my_charset_bin); set_data_type(MYSQL_TYPE_VARCHAR); max_length = s.length; diff --git a/sql/item.h b/sql/item.h index 1787916..df3bf87 100644 --- a/sql/item.h +++ b/sql/item.h @@ -5489,7 +5489,7 @@ class Item_hex_string : public Item_basic_constant { set_data_type(MYSQL_TYPE_VARCHAR); } - Item_hex_string(const char *str, uint str_length); + Item_hex_string(const char *str, uint str_length, bool is_hex_str = true); Item_hex_string(const POS &pos, const LEX_STRING &literal); enum Type type() const override { return VARBIN_ITEM; } @@ -5499,7 +5499,7 @@ class Item_hex_string : public Item_basic_constant { } longlong val_int() override; Item *clone_item() const override { - return new Item_hex_string(str_value.ptr(), max_length); + return new Item_hex_string(str_value.ptr(), max_length, false); } String *val_str(String *) override { assert(fixed); @@ -5523,10 +5523,11 @@ class Item_hex_string : public Item_basic_constant { Item *safe_charset_converter(THD *thd, const CHARSET_INFO *tocs) override; bool check_partition_func_processor(uchar *) override { return false; } static LEX_CSTRING make_hex_str(const char *str, size_t str_length); + static LEX_CSTRING make_hex_bytes(const char *str, size_t str_length); uint decimal_precision() const override; private: - void hex_string_init(const char *str, uint str_length); + void hex_string_init(const char *str, uint str_length, bool is_hex_str = true); }; class Item_bin_string final : public Item_hex_string {