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 */
16
#include <drizzled/mysql_priv.h>
19
#include <drizzled/plugin.h>
22
bool udf_init_crc32udf(UDF_INIT *initid, UDF_ARGS *args, char *message)
24
/* initid->ptr keeps state for between udf_init_foo and udf_deinit_foo */
27
if (args->arg_count != 1)
29
strcpy(message,"CRC32() requires one arguments");
33
if (args->arg_type[0] != STRING_RESULT)
35
strcpy(message,"CRC32() requires a string");
42
long long udf_doit_crc32(UDF_INIT *initid, UDF_ARGS *args, char *result,
43
unsigned long *length, char *is_null, char *error)
50
return (long long) crc32(0L, (uchar*)args->args[0], args->lengths[0]);
53
void udf_deinit_crc32udf(UDF_INIT *initid)
56
/* if we allocated initid->ptr, free it here */
61
static int crc32udf_plugin_init(void *p)
63
udf_func *udff= (udf_func *) p;
64
static char crc32str[6];
66
strcpy(crc32str,"crc32");
68
udff->name.str= crc32str;
69
udff->name.length= strlen("crc32");
70
udff->type= UDFTYPE_FUNCTION;
71
udff->returns= INT_RESULT;
72
udff->func_init= udf_init_crc32udf;
73
udff->func_deinit= udf_deinit_crc32udf;
74
udff->func= (Udf_func_any) udf_doit_crc32;
79
static int crc32udf_plugin_deinit(void *p)
81
udf_func *udff = (udf_func *) p;
86
mysql_declare_plugin(crc32)
92
"UDF for computing CRC32",
94
crc32udf_plugin_init, /* Plugin Init */
95
crc32udf_plugin_deinit, /* Plugin Deinit */
96
NULL, /* status variables */
97
NULL, /* system variables */
98
NULL /* config options */
100
mysql_declare_plugin_end;