19
19
#include <mysys/hash.h>
20
20
#include <drizzled/sql_udf.h>
22
27
static bool udf_startup= false; /* We do not lock because startup is single threaded */
23
28
static MEM_ROOT mem;
29
static map<string, udf_func *> udf_map;
26
31
extern "C" unsigned char* get_hash_key(const unsigned char *buff, size_t *length,
37
42
init_sql_alloc(&mem, UDF_ALLOC_BLOCK_SIZE, 0);
39
if (hash_init(&udf_hash, system_charset_info, 32, 0, 0, get_hash_key, NULL, 0))
41
errmsg_printf(ERRMSG_LVL_ERROR, _("Can't allocate memory for udf structures"));
43
free_root(&mem, MYF(0));
48
45
/* called by mysqld.cc clean_up() */
52
48
free_root(&mem, MYF(0));
55
51
/* This is only called if using_udf_functions != 0 */
56
52
udf_func *find_udf(const char *name, uint32_t length)
60
56
if (udf_startup == false)
63
udf= (udf_func*) hash_search(&udf_hash,
64
(unsigned char*) name,
65
length ? length : (uint) strlen(name));
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;
70
71
static bool add_udf(udf_func *udf)
72
if (my_hash_insert(&udf_hash, (unsigned char*) 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;
75
79
using_udf_functions= 1;