00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include <drizzled/plugin.h>
00023 #include <drizzled/plugin/function.h>
00024 #include <drizzled/item/func.h>
00025 #include <drizzled/algorithm/crc32.h>
00026
00027 #include <string>
00028
00029 using namespace std;
00030 using namespace drizzled;
00031
00032 class Crc32Function :public Item_int_func
00033 {
00034 public:
00035 int64_t val_int();
00036
00037 Crc32Function() :Item_int_func()
00038 {
00039 unsigned_flag= true;
00040 }
00041
00042 const char *func_name() const
00043 {
00044 return "crc32";
00045 }
00046
00047 void fix_length_and_dec()
00048 {
00049 max_length= 10;
00050 }
00051
00052 bool check_argument_count(int n)
00053 {
00054 return (n == 1);
00055 }
00056 };
00057
00058 int64_t Crc32Function::val_int()
00059 {
00060 assert(fixed == true);
00061 String value;
00062 String *res=args[0]->val_str(&value);
00063
00064 if (res == NULL)
00065 {
00066 null_value= true;
00067 return 0;
00068 }
00069
00070 null_value= false;
00071 return static_cast<int64_t>(drizzled::algorithm::crc32(res->ptr(), res->length()));
00072 }
00073
00074 plugin::Create_function<Crc32Function> *crc32udf= NULL;
00075
00076 static int initialize(module::Context &context)
00077 {
00078 crc32udf= new plugin::Create_function<Crc32Function>("crc32");
00079 context.add(crc32udf);
00080 return 0;
00081 }
00082
00083 DRIZZLE_PLUGIN(initialize, NULL, NULL);