~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_udf.h

Removed dead bits to HA_CREATE_INFO

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#pragma interface
24
24
#endif
25
25
 
 
26
#include "item_func.h"
 
27
 
26
28
enum Item_udftype {UDFTYPE_FUNCTION=1,UDFTYPE_AGGREGATE};
27
29
 
28
 
typedef void (*Udf_func_clear)(UDF_INIT *, uchar *, uchar *);
29
 
typedef void (*Udf_func_add)(UDF_INIT *, UDF_ARGS *, uchar *, uchar *);
30
 
typedef void (*Udf_func_deinit)(UDF_INIT*);
31
 
typedef bool (*Udf_func_init)(UDF_INIT *, UDF_ARGS *,  char *);
32
 
typedef void (*Udf_func_any)();
33
 
typedef double (*Udf_func_double)(UDF_INIT *, UDF_ARGS *, uchar *, uchar *);
34
 
typedef int64_t (*Udf_func_int64_t)(UDF_INIT *, UDF_ARGS *, uchar *,
35
 
                                      uchar *);
 
30
typedef Item_func* (*create_func_item)(MEM_ROOT*);
36
31
 
37
 
typedef struct st_udf_func
 
32
struct udf_func
38
33
{
39
34
  LEX_STRING name;
40
 
  Item_result returns;
41
 
  Item_udftype type;
42
 
  Udf_func_any func;
43
 
  Udf_func_init func_init;
44
 
  Udf_func_deinit func_deinit;
45
 
  Udf_func_clear func_clear;
46
 
  Udf_func_add func_add;
47
 
  void *data;
48
 
} udf_func;
49
 
 
50
 
class Item_result_field;
51
 
 
52
 
class udf_handler :public Sql_alloc
53
 
{
54
 
 protected:
55
 
  udf_func *u_d;
56
 
  String *buffers;
57
 
  UDF_ARGS f_args;
58
 
  UDF_INIT initid;
59
 
  char *num_buffer;
60
 
  uchar error, is_null;
61
 
  bool initialized;
62
 
  Item **args;
63
 
 
64
 
 public:
65
 
  table_map used_tables_cache;
66
 
  bool const_item_cache;
67
 
  bool not_original;
68
 
  udf_handler(udf_func *udf_arg) :u_d(udf_arg), buffers(0), error(0),
69
 
    is_null(0), initialized(0), not_original(0)
70
 
  {}
71
 
  ~udf_handler();
72
 
  const char *name() const { return u_d ? u_d->name.str : "?"; }
73
 
  Item_result result_type () const
74
 
  { return u_d  ? u_d->returns : STRING_RESULT;}
75
 
  bool get_arguments();
76
 
  bool fix_fields(THD *thd, Item_result_field *item,
77
 
                  uint arg_count, Item **args);
78
 
  void cleanup();
79
 
  double val(bool *null_value)
80
 
  {
81
 
    is_null= 0;
82
 
    if (get_arguments())
83
 
    {
84
 
      *null_value=1;
85
 
      return 0.0;
86
 
    }
87
 
    Udf_func_double func= (Udf_func_double) u_d->func;
88
 
    double tmp=func(&initid, &f_args, &is_null, &error);
89
 
    if (is_null || error)
90
 
    {
91
 
      *null_value=1;
92
 
      return 0.0;
93
 
    }
94
 
    *null_value=0;
95
 
    return tmp;
96
 
  }
97
 
  int64_t val_int(bool *null_value)
98
 
  {
99
 
    is_null= 0;
100
 
    if (get_arguments())
101
 
    {
102
 
      *null_value=1;
103
 
      return 0LL;
104
 
    }
105
 
    Udf_func_int64_t func= (Udf_func_int64_t) u_d->func;
106
 
    int64_t tmp=func(&initid, &f_args, &is_null, &error);
107
 
    if (is_null || error)
108
 
    {
109
 
      *null_value=1;
110
 
      return 0LL;
111
 
    }
112
 
    *null_value=0;
113
 
    return tmp;
114
 
  }
115
 
  my_decimal *val_decimal(bool *null_value, my_decimal *dec_buf);
116
 
  void clear()
117
 
  {
118
 
    is_null= 0;
119
 
    Udf_func_clear func= u_d->func_clear;
120
 
    func(&initid, &is_null, &error);
121
 
  }
122
 
  void add(bool *null_value)
123
 
  {
124
 
    if (get_arguments())
125
 
    {
126
 
      *null_value=1;
127
 
      return;
128
 
    }
129
 
    Udf_func_add func= u_d->func_add;
130
 
    func(&initid, &f_args, &is_null, &error);
131
 
    *null_value= (bool) (is_null || error);
132
 
  }
133
 
  String *val_str(String *str,String *save_str);
 
35
  create_func_item create_func;
134
36
};
135
37
 
136
 
 
137
38
void udf_init(void),udf_free(void);
138
39
udf_func *find_udf(const char *name, uint len=0);
139
40
void free_udf(udf_func *udf);