mirror of
https://github.com/MariaDB/server.git
synced 2025-12-24 11:21:21 +03:00
New CRC32() SQL function
This commit is contained in:
@@ -86,6 +86,11 @@ Item *create_func_cot(Item* a)
|
||||
new Item_func_tan(a));
|
||||
}
|
||||
|
||||
Item *create_func_crc32(Item* a)
|
||||
{
|
||||
return new Item_func_crc32(a);
|
||||
}
|
||||
|
||||
Item *create_func_date_format(Item* a,Item *b)
|
||||
{
|
||||
return new Item_func_date_format(a,b,0);
|
||||
|
||||
@@ -29,6 +29,7 @@ Item *create_func_connection_id(void);
|
||||
Item *create_func_conv(Item* a, Item *b, Item *c);
|
||||
Item *create_func_cos(Item* a);
|
||||
Item *create_func_cot(Item* a);
|
||||
Item *create_func_crc32(Item* a);
|
||||
Item *create_func_date_format(Item* a,Item *b);
|
||||
Item *create_func_dayname(Item* a);
|
||||
Item *create_func_dayofmonth(Item* a);
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <hash.h>
|
||||
#include <time.h>
|
||||
#include <ft_global.h>
|
||||
#include <zlib.h>
|
||||
#include "slave.h" // for wait_for_master_pos
|
||||
#include "gstream.h"
|
||||
|
||||
@@ -801,6 +802,18 @@ longlong Item_func_min_max::val_int()
|
||||
return value;
|
||||
}
|
||||
|
||||
longlong Item_func_crc32::val_int()
|
||||
{
|
||||
String *res=args[0]->val_str(&value);
|
||||
if (!res)
|
||||
{
|
||||
null_value=1;
|
||||
return 0; /* purecov: inspected */
|
||||
}
|
||||
null_value=0;
|
||||
return (longlong) crc32(0L, (Bytef*)res->ptr(), res->length());
|
||||
}
|
||||
|
||||
|
||||
longlong Item_func_length::val_int()
|
||||
{
|
||||
|
||||
@@ -518,6 +518,16 @@ public:
|
||||
const char *func_name() const { return "greatest"; }
|
||||
};
|
||||
|
||||
class Item_func_crc32 :public Item_int_func
|
||||
{
|
||||
String value;
|
||||
public:
|
||||
Item_func_crc32(Item *a) :Item_int_func(a) {}
|
||||
longlong val_int();
|
||||
const char *func_name() const { return "crc32"; }
|
||||
void fix_length_and_dec() { max_length=10; }
|
||||
};
|
||||
|
||||
|
||||
class Item_func_length :public Item_int_func
|
||||
{
|
||||
|
||||
@@ -430,6 +430,7 @@ static SYMBOL sql_functions[] = {
|
||||
{ "COUNT", SYM(COUNT_SYM),0,0},
|
||||
{ "COS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_cos)},
|
||||
{ "COT", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_cot)},
|
||||
{ "CRC32", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_crc32)},
|
||||
{ "CROSSES", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_crosses)},
|
||||
{ "CURDATE", SYM(CURDATE),0,0},
|
||||
{ "CURTIME", SYM(CURTIME),0,0},
|
||||
|
||||
Reference in New Issue
Block a user