16
16
/* This implements 'user defined functions' */
17
17
#include <drizzled/server_includes.h>
19
static bool udf_startup= false; /* We do not lock because startup is single threaded */
23
extern "C" uchar* get_hash_key(const uchar *buff, size_t *length,
24
bool not_used __attribute__((unused)))
26
udf_func *udf= (udf_func*) buff;
27
*length= (uint) udf->name.length;
28
return (uchar*) udf->name.str;
34
init_sql_alloc(&mem, UDF_ALLOC_BLOCK_SIZE, 0);
36
if (hash_init(&udf_hash, system_charset_info, 32, 0, 0, get_hash_key, NULL, 0))
38
sql_print_error("Can't allocate memory for udf structures");
40
free_root(&mem, MYF(0));
45
/* called by mysqld.cc clean_up() */
49
free_root(&mem, MYF(0));
18
#include <drizzled/gettext.h>
19
#include <drizzled/sql_udf.h>
20
#include <drizzled/registry.h>
21
#include "drizzled/plugin_registry.h"
27
static drizzled::Registry<Function_builder *> udf_registry;
52
29
/* This is only called if using_udf_functions != 0 */
53
udf_func *find_udf(const char *name, uint length)
57
if (udf_startup == false)
60
udf= (udf_func*) hash_search(&udf_hash,
62
length ? length : (uint) strlen(name));
67
static bool add_udf(udf_func *udf)
69
if (my_hash_insert(&udf_hash, (uchar*) udf))
72
using_udf_functions= 1;
77
int initialize_udf(st_plugin_int *plugin)
81
if (udf_startup == false)
87
/* allocate the udf_func structure */
88
udff = (udf_func *)my_malloc(sizeof(udf_func), MYF(MY_WME | MY_ZEROFILL));
89
if (udff == NULL) return 1;
91
plugin->data= (void *)udff;
93
if (plugin->plugin->init)
95
/* todo, if the plugin doesnt have an init, bail out */
97
if (plugin->plugin->init((void *)udff))
99
sql_print_error("Plugin '%s' init function returned error.",
109
my_free(udff, MYF(0));
113
int finalize_udf(st_plugin_int *plugin)
115
udf_func *udff = (udf_func *)plugin->data;
117
/* TODO: Issue warning on failure */
118
if (udff && plugin->plugin->deinit)
119
(void)plugin->plugin->deinit(udff);
122
my_free(udff, MYF(0));
30
Function_builder *find_udf(const char *name, uint32_t length)
32
return udf_registry.find(name, length);
35
void add_udf(Function_builder *udf)
37
udf_registry.add(udf);
40
void remove_udf(Function_builder *udf)
42
udf_registry.remove(udf);