1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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 */
20
17
/* This file defines structures needed by udf functions */
23
#include "item_func.h"
19
#ifdef USE_PRAGMA_INTERFACE
25
23
enum Item_udftype {UDFTYPE_FUNCTION=1,UDFTYPE_AGGREGATE};
27
typedef Item_func* (*create_func_item)(MEM_ROOT*);
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 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 int64_t (*Udf_func_int64_t)(UDF_INIT *, UDF_ARGS *, uchar *,
34
typedef struct st_udf_func
32
create_func_item create_func;
40
Udf_func_init func_init;
41
Udf_func_deinit func_deinit;
42
Udf_func_clear func_clear;
43
Udf_func_add func_add;
47
class Item_result_field;
49
class udf_handler :public Sql_alloc
62
table_map used_tables_cache;
63
bool const_item_cache;
65
udf_handler(udf_func *udf_arg) :u_d(udf_arg), buffers(0), error(0),
66
is_null(0), initialized(0), not_original(0)
69
const char *name() const { return u_d ? u_d->name.str : "?"; }
70
Item_result result_type () const
71
{ return u_d ? u_d->returns : STRING_RESULT;}
73
bool fix_fields(THD *thd, Item_result_field *item,
74
uint arg_count, Item **args);
76
double val(bool *null_value)
84
Udf_func_double func= (Udf_func_double) u_d->func;
85
double tmp=func(&initid, &f_args, &is_null, &error);
94
int64_t val_int(bool *null_value)
102
Udf_func_int64_t func= (Udf_func_int64_t) u_d->func;
103
int64_t tmp=func(&initid, &f_args, &is_null, &error);
104
if (is_null || error)
112
my_decimal *val_decimal(bool *null_value, my_decimal *dec_buf);
116
Udf_func_clear func= u_d->func_clear;
117
func(&initid, &is_null, &error);
119
void add(bool *null_value)
126
Udf_func_add func= u_d->func_add;
127
func(&initid, &f_args, &is_null, &error);
128
*null_value= (bool) (is_null || error);
130
String *val_str(String *str,String *save_str);
35
134
void udf_init(void),udf_free(void);
36
udf_func *find_udf(const char *name, uint32_t len=0);
135
udf_func *find_udf(const char *name, uint len=0);
37
136
void free_udf(udf_func *udf);
38
int mysql_create_function(Session *session,udf_func *udf);
137
int mysql_create_function(THD *thd,udf_func *udf);