16
16
/* This implements 'user defined functions' */
17
17
#include <drizzled/server_includes.h>
18
18
#include <drizzled/gettext.h>
19
#include <mysys/hash.h>
20
19
#include <drizzled/sql_udf.h>
20
#include <drizzled/registry.h>
21
#include "drizzled/plugin_registry.h"
25
25
using namespace std;
27
static bool udf_startup= false; /* We do not lock because startup is single threaded */
29
static map<string, udf_func *> udf_map;
31
extern "C" unsigned char* get_hash_key(const unsigned char *buff, size_t *length,
34
udf_func *udf= (udf_func*) buff;
35
*length= (uint32_t) udf->name.length;
36
return (unsigned char*) udf->name.str;
42
init_sql_alloc(&mem, UDF_ALLOC_BLOCK_SIZE, 0);
45
/* called by mysqld.cc clean_up() */
48
free_root(&mem, MYF(0));
27
static drizzled::Registry<Function_builder *> udf_registry;
51
29
/* This is only called if using_udf_functions != 0 */
52
udf_func *find_udf(const char *name, uint32_t length)
56
if (udf_startup == false)
59
string find_str(name, length);
60
transform(find_str.begin(), find_str.end(),
61
find_str.begin(), ::tolower);
63
map<string, udf_func *>::iterator find_iter;
64
find_iter= udf_map.find(find_str);
65
if (find_iter != udf_map.end())
66
udf= (*find_iter).second;
71
static bool add_udf(udf_func *udf)
73
string add_str(udf->name.str, udf->name.length);
74
transform(add_str.begin(), add_str.end(),
75
add_str.begin(), ::tolower);
77
udf_map[add_str]= udf;
79
using_udf_functions= 1;
84
int initialize_udf(st_plugin_int *plugin)
88
if (udf_startup == false)
94
if (plugin->plugin->init)
97
if ((r= plugin->plugin->init((void *)&f)))
99
errmsg_printf(ERRMSG_LVL_ERROR, "Plugin '%s' init function returned error %d.",
100
plugin->name.str, r);
110
plugin->state= PLUGIN_IS_READY;
116
int finalize_udf(st_plugin_int *plugin)
118
udf_func *udff = (udf_func *)plugin->data;
120
/* TODO: Issue warning on failure */
121
if (udff && plugin->plugin->deinit)
122
(void)plugin->plugin->deinit(udff);
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);