14
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
16
#include <drizzled/common_includes.h>
17
#include <drizzled/item_func.h>
18
#include <drizzled/item_strfunc.h>
18
bool udf_init_hello_world(UDF_INIT *initid, UDF_ARGS *args, char *message)
20
class Item_func_hello_world : public Item_str_func
20
/* this is how to fail */
21
if (args->arg_count != 0) {
22
strncpy(message, "Too many arguments", DRIZZLE_ERRMSG_SIZE);
23
const char *func_name() const { return "hello_world"; }
24
String *val_str(String* s) {
25
s->set(STRING_WITH_LEN("Hello World!"),system_charset_info);
28
void fix_length_and_dec() {
29
max_length=strlen("Hello World!");
26
/* initid->ptr keeps state for between udf_init_foo and udf_deinit_foo */
32
char *udf_doit_hello_world(UDF_INIT *initid, UDF_ARGS *args, char *result,
33
unsigned long *length, char *is_null, char *error)
35
/* We don't use these, so void them out */
39
/* "result" is preallocated 255 bytes for me, if i want to use it */
40
strncpy(result, "Hello, world!", 255);
42
/* if set to 255 or less, MySQL treats the result as a varchar
43
if set to greater than 255, MySQL treats the result as a blob */
44
*length= strlen("Hello, world!");
46
/* is_null is already zero, this is a demonstration */
49
/* error is already zero, this is a demonstration */
55
void udf_deinit_hello_world(UDF_INIT *initid)
57
/* We don't use this, so void it out */
60
/* if we allocated initid->ptr, free it here */
33
Item_func* create_hello_world_udf_item(MEM_ROOT* m)
35
return new (m) Item_func_hello_world();
38
static struct udf_func hello_world_udf = {
39
{ C_STRING_WITH_LEN("hello_world") },
40
create_hello_world_udf_item
65
43
static int hello_world_plugin_init(void *p)
67
udf_func *udff= (udf_func *) p;
45
udf_func **f = (udf_func**) p;
69
udff->name.str= (char *)"hello_world";
70
udff->name.length= strlen("hello_world");
71
udff->type= UDFTYPE_FUNCTION;
72
udff->returns= STRING_RESULT;
73
udff->func_init= udf_init_hello_world;
74
udff->func_deinit= udf_deinit_hello_world;
75
udff->func= (Udf_func_any) udf_doit_hello_world;
80
52
static int hello_world_plugin_deinit(void *p)
82
/* We don't use this, so void it out */
85
/* There is nothing to de-init here, but if
86
* something is needed from the udf_func, it
87
* can be had from p with:
88
* udf_func *udff = (udf_func *) p;
54
udf_func *udff = (udf_func *) p;
94
60
mysql_declare_plugin(hello_world)
96
62
DRIZZLE_UDF_PLUGIN,