diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item_create.cc | 24 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 13 | ||||
-rw-r--r-- | sql/item_strfunc.h | 19 |
3 files changed, 56 insertions, 0 deletions
diff --git a/sql/item_create.cc b/sql/item_create.cc index 1aa7d02e76b..e8921b274ad 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -525,6 +525,19 @@ protected: }; +class Create_func_crc32c : public Create_func_arg1 +{ +public: + virtual Item *create_1_arg(THD *thd, Item *arg1); + + static Create_func_crc32c s_singleton; + +protected: + Create_func_crc32c() {} + virtual ~Create_func_crc32c() {} +}; + + class Create_func_datediff : public Create_func_arg2 { public: @@ -3123,6 +3136,16 @@ Create_func_crc32::create_1_arg(THD *thd, Item *arg1) return new (thd->mem_root) Item_func_crc32(thd, arg1); } + +Create_func_crc32c Create_func_crc32c::s_singleton; + +Item* +Create_func_crc32c::create_1_arg(THD *thd, Item *arg1) +{ + return new (thd->mem_root) Item_func_crc32c(thd, arg1); +} + + Create_func_datediff Create_func_datediff::s_singleton; Item* @@ -5555,6 +5578,7 @@ Native_func_registry func_array[] = { { STRING_WITH_LEN("COS") }, BUILDER(Create_func_cos)}, { { STRING_WITH_LEN("COT") }, BUILDER(Create_func_cot)}, { { STRING_WITH_LEN("CRC32") }, BUILDER(Create_func_crc32)}, + { { STRING_WITH_LEN("CRC32C") }, BUILDER(Create_func_crc32c)}, { { STRING_WITH_LEN("DATEDIFF") }, BUILDER(Create_func_datediff)}, { { STRING_WITH_LEN("DAYNAME") }, BUILDER(Create_func_dayname)}, { { STRING_WITH_LEN("DAYOFMONTH") }, BUILDER(Create_func_dayofmonth)}, diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index d4bf28a9c21..a29580b7a54 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -4387,6 +4387,19 @@ longlong Item_func_crc32::val_int() return (longlong) my_checksum(0L, (uchar*)res->ptr(), res->length()); } +longlong Item_func_crc32c::val_int() +{ + DBUG_ASSERT(fixed()); + String *res=args[0]->val_str(&value); + if (!res) + { + null_value=1; + return 0; /* purecov: inspected */ + } + null_value=0; + return my_crc32c(0, res->ptr(), res->length()); +} + #ifdef HAVE_COMPRESS #include "zlib.h" diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index ba61206d8d9..c455a2b642a 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -1961,6 +1961,25 @@ public: { return get_item_copy<Item_func_crc32>(thd, this); } }; +class Item_func_crc32c :public Item_long_func +{ + bool check_arguments() const override + { return args[0]->check_type_can_return_str(func_name_cstring()); } + String value; +public: + Item_func_crc32c(THD *thd, Item *a): Item_long_func(thd, a) + { unsigned_flag= 1; } + LEX_CSTRING func_name_cstring() const override + { + static LEX_CSTRING name= {STRING_WITH_LEN("crc32c") }; + return name; + } + bool fix_length_and_dec() override { max_length=10; return FALSE; } + longlong val_int() override; + Item *get_copy(THD *thd) override + { return get_item_copy<Item_func_crc32c>(thd, this); } +}; + class Item_func_uncompressed_length : public Item_long_func_length { String value; |