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 <mysql_priv.h>
19
#include <drizzle_version.h>
20
#include <drizzle/plugin.h>
21
#include <my_global.h>
25
bool udf_init_crc32udf(UDF_INIT *initid, UDF_ARGS *args, char *message)
27
/* initid->ptr keeps state for between udf_init_foo and udf_deinit_foo */
30
if (args->arg_count != 1)
32
strcpy(message,"CRC32() requires one arguments");
36
if (args->arg_type[0] != STRING_RESULT)
38
strcpy(message,"CRC32() requires a string");
45
long long udf_doit_crc32(UDF_INIT *initid, UDF_ARGS *args, char *result,
46
unsigned long *length, char *is_null, char *error)
53
return (long long) crc32(0L, (uchar*)args->args[0], args->lengths[0]);
56
void udf_deinit_crc32udf(UDF_INIT *initid)
59
/* if we allocated initid->ptr, free it here */
64
static int crc32udf_plugin_init(void *p)
66
udf_func *udff= (udf_func *) p;
67
static char crc32str[6];
69
strcpy(crc32str,"crc32");
71
udff->name.str= crc32str;
72
udff->name.length= strlen("crc32");
73
udff->type= UDFTYPE_FUNCTION;
74
udff->returns= INT_RESULT;
75
udff->func_init= udf_init_crc32udf;
76
udff->func_deinit= udf_deinit_crc32udf;
77
udff->func= (Udf_func_any) udf_doit_crc32;
82
static int crc32udf_plugin_deinit(void *p)
84
udf_func *udff = (udf_func *) p;
89
mysql_declare_plugin(crc32)
95
"UDF for computing CRC32",
97
crc32udf_plugin_init, /* Plugin Init */
98
crc32udf_plugin_deinit, /* Plugin Deinit */
99
NULL, /* status variables */
100
NULL, /* system variables */
101
NULL /* config options */
103
mysql_declare_plugin_end;