diff options
author | Sergei Golubchik <serg@mariadb.org> | 2021-09-14 12:08:01 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2021-10-29 18:29:02 +0200 |
commit | b1fab9bf4e8a0d807c1076b6610c7208f40ca0c1 (patch) | |
tree | 4c6fb986cedca81eca9827a501ec38c2d1d5a092 /plugin | |
parent | 7ab11f2bdaab0ab4c28982bd07bc3a28422664e4 (diff) | |
download | mariadb-git-b1fab9bf4e8a0d807c1076b6610c7208f40ca0c1.tar.gz |
UUID() function should return UUID, not VARCHAR(36)
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/type_uuid/item_uuidfunc.cc | 41 | ||||
-rw-r--r-- | plugin/type_uuid/item_uuidfunc.h | 35 | ||||
-rw-r--r-- | plugin/type_uuid/plugin.cc | 4 |
3 files changed, 49 insertions, 31 deletions
diff --git a/plugin/type_uuid/item_uuidfunc.cc b/plugin/type_uuid/item_uuidfunc.cc index 0c79cbbd5b8..725b696f905 100644 --- a/plugin/type_uuid/item_uuidfunc.cc +++ b/plugin/type_uuid/item_uuidfunc.cc @@ -18,26 +18,29 @@ #include "item_uuidfunc.h" #include "sql_type_uuid.h" -class UUID_generated : public UUIDBundle::Fbt -{ -public: - UUID_generated() { my_uuid((uchar *) m_buffer); } - bool to_string(String *to, bool with_separators) const - { - if (to->alloc(max_char_length() + 1)) - return true; - to->set_charset(system_charset_info); - to->length(MY_UUID_BARE_STRING_LENGTH + with_separators*MY_UUID_SEPARATORS); - my_uuid2str((const uchar *) m_buffer, (char *) to->ptr(), with_separators); - return false; - } -}; - -String *Item_func_uuid::val_str(String *str) +String *Item_func_sys_guid::val_str(String *str) { DBUG_ASSERT(fixed()); - if (!UUID_generated().to_string(str, with_separators)) - return str; - str->set("", 0, collation.collation); + str->alloc(uuid_len()+1); + str->length(uuid_len()); + str->set_charset(collation.collation); + + uchar buf[MY_UUID_SIZE]; + my_uuid(buf); + my_uuid2str(buf, const_cast<char*>(str->ptr()), with_dashes); return str; } + +const Type_handler *Item_func_uuid::type_handler() const +{ + return UUIDBundle::type_handler_fbt(); +} + +bool Item_func_uuid::val_native(THD *, Native *to) +{ + DBUG_ASSERT(fixed()); + to->alloc(MY_UUID_SIZE); + to->length(MY_UUID_SIZE); + my_uuid((uchar*)to->ptr()); + return 0; +} diff --git a/plugin/type_uuid/item_uuidfunc.h b/plugin/type_uuid/item_uuidfunc.h index 3756d70ba3d..add4f202784 100644 --- a/plugin/type_uuid/item_uuidfunc.h +++ b/plugin/type_uuid/item_uuidfunc.h @@ -19,33 +19,48 @@ #include "item.h" -class Item_func_uuid: public Item_str_func +class Item_func_sys_guid: public Item_str_func { - bool with_separators; +protected: + bool with_dashes; + size_t uuid_len() const + { return MY_UUID_BARE_STRING_LENGTH + with_dashes*MY_UUID_SEPARATORS; } public: - Item_func_uuid(THD *thd, bool with_separators_arg): - Item_str_func(thd), with_separators(with_separators_arg) {} + Item_func_sys_guid(THD *thd): Item_str_func(thd), with_dashes(false) {} bool fix_length_and_dec() { collation.set(DTCollation_numeric()); - fix_char_length(with_separators ? MY_UUID_STRING_LENGTH - : MY_UUID_BARE_STRING_LENGTH); + fix_char_length(uuid_len()); return FALSE; } bool const_item() const { return false; } table_map used_tables() const { return RAND_TABLE_BIT; } LEX_CSTRING func_name_cstring() const override { - static LEX_CSTRING name1= {STRING_WITH_LEN("uuid") }; - static LEX_CSTRING name2= {STRING_WITH_LEN("sys_guid") }; - return with_separators ? name1 : name2; + static LEX_CSTRING name= {STRING_WITH_LEN("sys_guid") }; + return name; } - String *val_str(String *); + String *val_str(String *) override; bool check_vcol_func_processor(void *arg) { return mark_unsupported_function(func_name(), "()", arg, VCOL_NON_DETERMINISTIC); } Item *get_copy(THD *thd) + { return get_item_copy<Item_func_sys_guid>(thd, this); } +}; + +class Item_func_uuid: public Item_func_sys_guid +{ +public: + Item_func_uuid(THD *thd): Item_func_sys_guid(thd) { with_dashes= true; } + const Type_handler *type_handler() const override; + LEX_CSTRING func_name_cstring() const override + { + static LEX_CSTRING name= {STRING_WITH_LEN("uuid") }; + return name; + } + bool val_native(THD *thd, Native *to) override; + Item *get_copy(THD *thd) { return get_item_copy<Item_func_uuid>(thd, this); } }; diff --git a/plugin/type_uuid/plugin.cc b/plugin/type_uuid/plugin.cc index ae511b95456..6e7df8897fb 100644 --- a/plugin/type_uuid/plugin.cc +++ b/plugin/type_uuid/plugin.cc @@ -37,7 +37,7 @@ public: DBUG_ENTER("Create_func_uuid::create"); thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION); thd->lex->safe_to_cache_query= 0; - DBUG_RETURN(new (thd->mem_root) Item_func_uuid(thd, true)); + DBUG_RETURN(new (thd->mem_root) Item_func_uuid(thd)); } static Create_func_uuid s_singleton; @@ -55,7 +55,7 @@ public: DBUG_ENTER("Create_func_sys_guid::create"); thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION); thd->lex->safe_to_cache_query= 0; - DBUG_RETURN(new (thd->mem_root) Item_func_uuid(thd, false)); + DBUG_RETURN(new (thd->mem_root) Item_func_sys_guid(thd)); } static Create_func_sys_guid s_singleton; |