~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_udf.cc

  • Committer: Monty Taylor
  • Date: 2009-02-12 04:30:42 UTC
  • mto: This revision was merged to the branch mainline in revision 885.
  • Revision ID: mordred@inaugust.com-20090212043042-s2cd9n5q4bc2b1sw
Got rid of my_hash_sort_utf8mb4 for udfs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include <mysys/hash.h>
20
20
#include <drizzled/sql_udf.h>
21
21
 
 
22
#include <map>
 
23
#include <string>
 
24
 
 
25
using namespace std;
 
26
 
22
27
static bool udf_startup= false; /* We do not lock because startup is single threaded */
23
28
static MEM_ROOT mem;
24
 
static HASH udf_hash;
 
29
static map<string, udf_func *> udf_map;
25
30
 
26
31
extern "C" unsigned char* get_hash_key(const unsigned char *buff, size_t *length,
27
32
                               bool )
35
40
void udf_init()
36
41
{
37
42
  init_sql_alloc(&mem, UDF_ALLOC_BLOCK_SIZE, 0);
38
 
 
39
 
  if (hash_init(&udf_hash, system_charset_info, 32, 0, 0, get_hash_key, NULL, 0))
40
 
  {
41
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Can't allocate memory for udf structures"));
42
 
    hash_free(&udf_hash);
43
 
    free_root(&mem, MYF(0));
44
 
    return;
45
 
  }
46
43
}
47
44
 
48
45
/* called by mysqld.cc clean_up() */
49
46
void udf_free()
50
47
{
51
 
  hash_free(&udf_hash);
52
48
  free_root(&mem, MYF(0));
53
49
}
54
50
 
55
51
/* This is only called if using_udf_functions != 0 */
56
52
udf_func *find_udf(const char *name, uint32_t length)
57
53
{
58
 
  udf_func *udf;
 
54
  udf_func *udf= NULL;
59
55
 
60
56
  if (udf_startup == false)
61
57
    return NULL;
62
58
 
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);
 
62
 
 
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;
66
67
 
67
68
  return (udf);
68
69
}
69
70
 
70
71
static bool add_udf(udf_func *udf)
71
72
{
72
 
  if (my_hash_insert(&udf_hash, (unsigned char*) udf))
73
 
    return false;
 
73
  string add_str(udf->name.str, udf->name.length);
 
74
  transform(add_str.begin(), add_str.end(),
 
75
            add_str.begin(), ::tolower);
 
76
 
 
77
  udf_map[add_str]= udf;
74
78
 
75
79
  using_udf_functions= 1;
76
80