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>
24
my_bool udf_init_hello_world(UDF_INIT *initid, UDF_ARGS *args, char *message)
26
/* this is how to fail */
27
if (args->arg_count != 0) {
28
strncpy(message, "Too many arguments", MYSQL_ERRMSG_SIZE);
32
/* initid->ptr keeps state for between udf_init_foo and udf_deinit_foo */
38
char *udf_doit_hello_world(UDF_INIT *initid, UDF_ARGS *args, char *result,
39
unsigned long *length, char *is_null, char *error)
41
/* "result" is preallocated 255 bytes for me, if i want to use it */
42
strncpy(result, "Hello, world!", 255);
44
/* if set to 255 or less, MySQL treats the result as a varchar
45
if set to greater than 255, MySQL treats the result as a blob */
46
*length= strlen("Hello, world!");
48
/* is_null is already zero, this is a demonstration */
51
/* error is already zero, this is a demonstration */
57
void udf_deinit_hello_world(UDF_INIT *initid)
59
/* if we allocated initid->ptr, free it here */
64
static int hello_world_plugin_init(void *p)
66
udf_func *udff= (udf_func *) p;
68
udff->name.str= "hello_world";
69
udff->name.length= strlen("hello_world");
70
udff->type= UDFTYPE_FUNCTION;
71
udff->returns= STRING_RESULT;
72
udff->func_init= udf_init_hello_world;
73
udff->func_deinit= udf_deinit_hello_world;
74
udff->func= (Udf_func_any) udf_doit_hello_world;
79
static int hello_world_plugin_deinit(void *p)
81
udf_func *udff = (udf_func *) p;
86
struct st_mysql_udf hello_world_plugin=
87
{ MYSQL_UDF_INTERFACE_VERSION };
89
mysql_declare_plugin(hello_world)
97
hello_world_plugin_init, /* Plugin Init */
98
hello_world_plugin_deinit, /* Plugin Deinit */
100
NULL, /* status variables */
101
NULL, /* system variables */
102
NULL /* config options */
104
mysql_declare_plugin_end;