1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
4
* Copyright (C) 2008 Sun Microsystems
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include <drizzled/plugin.h>
23
#include <drizzled/plugin/function.h>
20
#include <drizzled/server_includes.h>
21
#include <drizzled/sql_udf.h>
24
22
#include <drizzled/item/func.h>
25
#include <drizzled/algorithm/crc32.h>
30
using namespace drizzled;
32
class Crc32Function :public Item_int_func
25
class Item_func_crc32 :public Item_int_func
29
Item_func_crc32() :Item_int_func() { unsigned_flag= 1; }
30
const char *func_name() const { return "crc32"; }
31
void fix_length_and_dec() { max_length=10; }
37
Crc32Function() :Item_int_func()
42
const char *func_name() const
47
void fix_length_and_dec()
52
bool check_argument_count(int n)
58
int64_t Crc32Function::val_int()
35
int64_t Item_func_crc32::val_int()
60
assert(fixed == true);
62
38
String *res=args[0]->val_str(&value);
42
return 0; /* purecov: inspected */
71
return static_cast<int64_t>(drizzled::algorithm::crc32(res->ptr(), res->length()));
74
plugin::Create_function<Crc32Function> *crc32udf= NULL;
76
static int initialize(module::Context &context)
78
crc32udf= new plugin::Create_function<Crc32Function>("crc32");
79
context.add(crc32udf);
83
DRIZZLE_PLUGIN(initialize, NULL, NULL);
45
return (int64_t) crc32(0L, (unsigned char*)res->ptr(), res->length());
48
Item_func* create_crc32udf_item(MEM_ROOT* m)
50
return new (m) Item_func_crc32();
53
static struct udf_func crc32udf = {
54
{ C_STRING_WITH_LEN("crc32") },
58
static int crc32udf_plugin_init(void *p)
60
udf_func **f = (udf_func**) p;
67
static int crc32udf_plugin_deinit(void *p)
69
udf_func *udff = (udf_func *) p;
74
mysql_declare_plugin(crc32)
80
"UDF for computing CRC32",
82
crc32udf_plugin_init, /* Plugin Init */
83
crc32udf_plugin_deinit, /* Plugin Deinit */
84
NULL, /* status variables */
85
NULL, /* system variables */
86
NULL /* config options */
88
mysql_declare_plugin_end;