1
/* Copyright (C) 2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
19
#include <drizzled/common_includes.h>
20
#include <drizzled/item_func.h>
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include <drizzled/server_includes.h>
21
#include <drizzled/plugin/function.h>
22
#include <drizzled/item/func.h>
23
class Item_func_crc32 :public Item_int_func
28
using namespace drizzled;
30
class Crc32Function :public Item_int_func
27
Item_func_crc32() :Item_int_func() { unsigned_flag= 1; }
28
const char *func_name() const { return "crc32"; }
29
void fix_length_and_dec() { max_length=10; }
36
Crc32Function() :Item_int_func()
41
const char *func_name() const
46
void fix_length_and_dec()
51
bool check_argument_count(int n)
33
int64_t Item_func_crc32::val_int()
57
int64_t Crc32Function::val_int()
59
assert(fixed == true);
36
60
String *res=args[0]->val_str(&value);
40
return 0; /* purecov: inspected */
43
69
return (int64_t) crc32(0L, (unsigned char*)res->ptr(), res->length());
46
Item_func* create_crc32udf_item(MEM_ROOT* m)
48
return new (m) Item_func_crc32();
51
static struct udf_func crc32udf = {
52
{ C_STRING_WITH_LEN("crc32") },
56
static int crc32udf_plugin_init(void *p)
58
udf_func **f = (udf_func**) p;
65
static int crc32udf_plugin_deinit(void *p)
67
udf_func *udff = (udf_func *) p;
72
mysql_declare_plugin(crc32)
72
plugin::Create_function<Crc32Function> *crc32udf= NULL;
74
static int initialize(plugin::Registry ®istry)
76
crc32udf= new plugin::Create_function<Crc32Function>("crc32");
77
registry.add(crc32udf);
81
static int finalize(plugin::Registry ®istry)
83
registry.remove(crc32udf);
88
drizzle_declare_plugin(crc32)
78
93
"UDF for computing CRC32",
79
94
PLUGIN_LICENSE_GPL,
80
crc32udf_plugin_init, /* Plugin Init */
81
crc32udf_plugin_deinit, /* Plugin Deinit */
95
initialize, /* Plugin Init */
96
finalize, /* Plugin Deinit */
82
97
NULL, /* status variables */
83
98
NULL, /* system variables */
84
99
NULL /* config options */
86
mysql_declare_plugin_end;
101
drizzle_declare_plugin_end;