~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_udf.cc

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* This implements 'user defined functions' */
17
17
#include <drizzled/server_includes.h>
18
 
#include <drizzled/gettext.h>
 
18
#include <libdrizzle/gettext.h>
19
19
 
20
20
static bool udf_startup= false; /* We do not lock because startup is single threaded */
21
21
static MEM_ROOT mem;
22
22
static HASH udf_hash;
23
23
 
24
 
extern "C" unsigned char* get_hash_key(const unsigned char *buff, size_t *length,
 
24
extern "C" uchar* get_hash_key(const uchar *buff, size_t *length,
25
25
                               bool not_used __attribute__((unused)))
26
26
{
27
27
  udf_func *udf= (udf_func*) buff;
28
28
  *length= (uint) udf->name.length;
29
 
  return (unsigned char*) udf->name.str;
 
29
  return (uchar*) udf->name.str;
30
30
}
31
31
 
32
32
 
51
51
}
52
52
 
53
53
/* This is only called if using_udf_functions != 0 */
54
 
udf_func *find_udf(const char *name, uint32_t length)
 
54
udf_func *find_udf(const char *name, uint length)
55
55
{
56
56
  udf_func *udf;
57
57
 
59
59
    return NULL;
60
60
 
61
61
  udf= (udf_func*) hash_search(&udf_hash,
62
 
                               (unsigned char*) name,
 
62
                               (uchar*) name,
63
63
                               length ? length : (uint) strlen(name));
64
64
 
65
65
  return (udf);
67
67
 
68
68
static bool add_udf(udf_func *udf)
69
69
{
70
 
  if (my_hash_insert(&udf_hash, (unsigned char*) udf))
 
70
  if (my_hash_insert(&udf_hash, (uchar*) udf))
71
71
    return false;
72
72
 
73
73
  using_udf_functions= 1;
77
77
 
78
78
int initialize_udf(st_plugin_int *plugin)
79
79
{
80
 
  udf_func *f;
 
80
  udf_func *udff;
81
81
 
82
82
  if (udf_startup == false)
83
83
  {
84
84
    udf_init();
85
85
    udf_startup= true;
86
86
  }
 
87
          
 
88
  /* allocate the udf_func structure */
 
89
  udff = (udf_func *)my_malloc(sizeof(udf_func), MYF(MY_WME | MY_ZEROFILL));
 
90
  if (udff == NULL) return 1;
 
91
 
 
92
  plugin->data= (void *)udff;
87
93
 
88
94
  if (plugin->plugin->init)
89
95
  {
90
 
    int r;
91
 
    if ((r= plugin->plugin->init((void *)&f)))
 
96
    /* todo, if the plugin doesnt have an init, bail out */
 
97
 
 
98
    if (plugin->plugin->init((void *)udff))
92
99
    {
93
 
      sql_print_error("Plugin '%s' init function returned error %d.",
94
 
                      plugin->name.str, r);
95
 
      return r;
 
100
      sql_print_error(_("Plugin '%s' init function returned error."),
 
101
                      plugin->name.str);
 
102
      goto err;
96
103
    }
97
104
  }
98
 
  else
99
 
    return 1;
100
 
 
101
 
  if(!add_udf(f))
102
 
    return 2;
 
105
  
 
106
  add_udf(udff);
103
107
 
104
108
  return 0;
105
 
 
 
109
err:
 
110
  my_free(udff, MYF(0));
 
111
  return 1;
106
112
}
107
113
 
108
114
int finalize_udf(st_plugin_int *plugin)
114
120
    (void)plugin->plugin->deinit(udff);
115
121
 
116
122
  if (udff)
117
 
    free(udff);
 
123
    my_free(udff, MYF(0));
118
124
 
119
125
  return 0;
120
126
}