~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_udf.cc

  • Committer: Monty Taylor
  • Date: 2008-08-04 19:37:18 UTC
  • mto: (261.2.2 codestyle)
  • mto: This revision was merged to the branch mainline in revision 262.
  • Revision ID: monty@inaugust.com-20080804193718-f0rz13uli4429ozb
Changed gettext_noop() to N_()

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* This implements 'user defined functions' */
17
 
#include <drizzled/server_includes.h>
18
 
#include <drizzled/gettext.h>
 
17
 
 
18
/*
 
19
   Known bugs:
 
20
  
 
21
*/
 
22
 
 
23
#ifdef USE_PRAGMA_IMPLEMENTATION
 
24
#pragma implementation                          // gcc: Class implementation
 
25
#endif
 
26
 
 
27
#include "mysql_priv.h"
 
28
#include <mysys/my_pthread.h>
 
29
 
 
30
extern "C"
 
31
{
 
32
#include <stdarg.h>
19
33
#include <mysys/hash.h>
20
 
#include <drizzled/sql_udf.h>
 
34
}
21
35
 
22
36
static bool udf_startup= false; /* We do not lock because startup is single threaded */
23
37
static MEM_ROOT mem;
24
38
static HASH udf_hash;
25
39
 
26
 
extern "C" unsigned char* get_hash_key(const unsigned char *buff, size_t *length,
 
40
extern "C" uchar* get_hash_key(const uchar *buff, size_t *length,
27
41
                               bool not_used __attribute__((unused)))
28
42
{
29
43
  udf_func *udf= (udf_func*) buff;
30
44
  *length= (uint) udf->name.length;
31
 
  return (unsigned char*) udf->name.str;
 
45
  return (uchar*) udf->name.str;
32
46
}
33
47
 
34
48
 
38
52
 
39
53
  if (hash_init(&udf_hash, system_charset_info, 32, 0, 0, get_hash_key, NULL, 0))
40
54
  {
41
 
    sql_print_error(_("Can't allocate memory for udf structures"));
 
55
    sql_print_error("Can't allocate memory for udf structures");
42
56
    hash_free(&udf_hash);
43
57
    free_root(&mem, MYF(0));
44
58
    return;
53
67
}
54
68
 
55
69
/* This is only called if using_udf_functions != 0 */
56
 
udf_func *find_udf(const char *name, uint32_t length)
 
70
udf_func *find_udf(const char *name, uint length)
57
71
{
58
72
  udf_func *udf;
59
73
 
61
75
    return NULL;
62
76
 
63
77
  udf= (udf_func*) hash_search(&udf_hash,
64
 
                               (unsigned char*) name,
 
78
                               (uchar*) name,
65
79
                               length ? length : (uint) strlen(name));
66
80
 
67
81
  return (udf);
69
83
 
70
84
static bool add_udf(udf_func *udf)
71
85
{
72
 
  if (my_hash_insert(&udf_hash, (unsigned char*) udf))
 
86
  if (my_hash_insert(&udf_hash, (uchar*) udf))
73
87
    return false;
74
88
 
75
89
  using_udf_functions= 1;
79
93
 
80
94
int initialize_udf(st_plugin_int *plugin)
81
95
{
82
 
  udf_func *f;
 
96
  udf_func *udff;
83
97
 
84
98
  if (udf_startup == false)
85
99
  {
86
100
    udf_init();
87
101
    udf_startup= true;
88
102
  }
 
103
          
 
104
  /* allocate the udf_func structure */
 
105
  udff = (udf_func *)my_malloc(sizeof(udf_func), MYF(MY_WME | MY_ZEROFILL));
 
106
  if (udff == NULL) return 1;
 
107
 
 
108
  plugin->data= (void *)udff;
89
109
 
90
110
  if (plugin->plugin->init)
91
111
  {
92
 
    int r;
93
 
    if ((r= plugin->plugin->init((void *)&f)))
 
112
    /* todo, if the plugin doesnt have an init, bail out */
 
113
 
 
114
    if (plugin->plugin->init((void *)udff))
94
115
    {
95
 
      sql_print_error("Plugin '%s' init function returned error %d.",
96
 
                      plugin->name.str, r);
97
 
      return r;
 
116
      sql_print_error("Plugin '%s' init function returned error.",
 
117
                      plugin->name.str);
 
118
      goto err;
98
119
    }
99
120
  }
100
 
  else
101
 
    return 1;
102
 
 
103
 
  if(!add_udf(f))
104
 
    return 2;
 
121
  
 
122
  add_udf(udff);
105
123
 
106
124
  return 0;
107
 
 
 
125
err:
 
126
  my_free(udff, MYF(0));
 
127
  return 1;
108
128
}
109
129
 
110
130
int finalize_udf(st_plugin_int *plugin)
116
136
    (void)plugin->plugin->deinit(udff);
117
137
 
118
138
  if (udff)
119
 
    free(udff);
 
139
    my_free(udff, MYF(0));
120
140
 
121
141
  return 0;
122
142
}