1
/* Copyright (C) 2000-2001, 2003-2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
/* This file defines structures needed by udf functions */
19
#ifdef USE_PRAGMA_INTERFACE
23
enum Item_udftype {UDFTYPE_FUNCTION=1,UDFTYPE_AGGREGATE};
25
typedef void (*Udf_func_clear)(UDF_INIT *, uchar *, uchar *);
26
typedef void (*Udf_func_add)(UDF_INIT *, UDF_ARGS *, uchar *, uchar *);
27
typedef void (*Udf_func_deinit)(UDF_INIT*);
28
typedef my_bool (*Udf_func_init)(UDF_INIT *, UDF_ARGS *, char *);
29
typedef void (*Udf_func_any)();
30
typedef double (*Udf_func_double)(UDF_INIT *, UDF_ARGS *, uchar *, uchar *);
31
typedef longlong (*Udf_func_longlong)(UDF_INIT *, UDF_ARGS *, uchar *,
34
typedef struct st_udf_func
42
Udf_func_init func_init;
43
Udf_func_deinit func_deinit;
44
Udf_func_clear func_clear;
45
Udf_func_add func_add;
49
class Item_result_field;
51
class udf_handler :public Sql_alloc
64
table_map used_tables_cache;
65
bool const_item_cache;
67
udf_handler(udf_func *udf_arg) :u_d(udf_arg), buffers(0), error(0),
68
is_null(0), initialized(0), not_original(0)
71
const char *name() const { return u_d ? u_d->name.str : "?"; }
72
Item_result result_type () const
73
{ return u_d ? u_d->returns : STRING_RESULT;}
75
bool fix_fields(THD *thd, Item_result_field *item,
76
uint arg_count, Item **args);
78
double val(my_bool *null_value)
86
Udf_func_double func= (Udf_func_double) u_d->func;
87
double tmp=func(&initid, &f_args, &is_null, &error);
96
longlong val_int(my_bool *null_value)
104
Udf_func_longlong func= (Udf_func_longlong) u_d->func;
105
longlong tmp=func(&initid, &f_args, &is_null, &error);
106
if (is_null || error)
114
my_decimal *val_decimal(my_bool *null_value, my_decimal *dec_buf);
118
Udf_func_clear func= u_d->func_clear;
119
func(&initid, &is_null, &error);
121
void add(my_bool *null_value)
128
Udf_func_add func= u_d->func_add;
129
func(&initid, &f_args, &is_null, &error);
130
*null_value= (my_bool) (is_null || error);
132
String *val_str(String *str,String *save_str);
137
void udf_init(void),udf_free(void);
138
udf_func *find_udf(const char *name, uint len=0,bool mark_used=0);
139
void free_udf(udf_func *udf);
140
int mysql_create_function(THD *thd,udf_func *udf);
141
int mysql_drop_function(THD *thd,const LEX_STRING *name);