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 <mysql/plugin.h>
21
#include <my_global.h>
25
my_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)
48
return (longlong) crc32(0L, (uchar*)args->args[0], args->lengths[0]);
51
void udf_deinit_crc32udf(UDF_INIT *initid)
53
/* if we allocated initid->ptr, free it here */
58
static int crc32udf_plugin_init(void *p)
60
udf_func *udff= (udf_func *) p;
62
udff->name.str= "crc32";
63
udff->name.length= strlen("crc32");
64
udff->type= UDFTYPE_FUNCTION;
65
udff->returns= INT_RESULT;
66
udff->func_init= udf_init_crc32udf;
67
udff->func_deinit= udf_deinit_crc32udf;
68
udff->func= (Udf_func_any) udf_doit_crc32;
73
static int crc32udf_plugin_deinit(void *p)
75
udf_func *udff = (udf_func *) p;
80
struct st_mysql_udf crc32udf_plugin=
81
{ MYSQL_UDF_INTERFACE_VERSION };
83
mysql_declare_plugin(crc32udf)
89
"UDF for computing CRC32",
91
crc32udf_plugin_init, /* Plugin Init */
92
crc32udf_plugin_deinit, /* Plugin Deinit */
94
NULL, /* status variables */
95
NULL, /* system variables */
96
NULL /* config options */
98
mysql_declare_plugin_end;