20
20
Functions to create an item. Used by sql_yac.yy
24
24
#include <drizzled/item/create.h>
25
25
#include <drizzled/item/func.h>
26
26
#include <drizzled/error.h>
27
#include <drizzled/system_variables.h>
28
#include "drizzled/function_container.h"
29
#include <drizzled/function_container.h>
30
31
#include <drizzled/function/str/binary.h>
31
32
#include <drizzled/function/str/concat.h>
83
84
#include <drizzled/function/math/tan.h>
84
85
#include <drizzled/function/units.h>
87
#include <drizzled/function/cast/boolean.h>
88
#include <drizzled/function/cast/signed.h>
89
#include <drizzled/function/cast/time.h>
90
#include <drizzled/function/cast/unsigned.h>
86
92
using namespace std;
95
97
=============================================================================
1066
1068
Create_udf_func::create(Session *session, LEX_STRING name, List<Item> *item_list)
1068
const plugin::Function *udf= plugin::Function::get(name.str, name.length);
1070
const plugin::Function *udf= plugin::Function::get(std::string(name.str, name.length));
1070
1072
return create(session, udf, item_list);
2053
2055
find_native_function_builder(LEX_STRING name)
2055
Native_func_registry *func;
2056
2057
Create_func *builder= NULL;
2058
2059
string func_name(name.str, name.length);
2060
NativeFunctionsMap::iterator func_iter=
2061
FunctionContainer::Map::iterator func_iter=
2061
2062
FunctionContainer::getMap().find(func_name);
2063
2064
if (func_iter != FunctionContainer::getMap().end())
2065
func= (*func_iter).second;
2066
builder= func->builder;
2066
builder= (*func_iter).second;
2069
2069
return builder;
2074
create_func_char_cast(Session *session, Item *a, int len, const CHARSET_INFO * const cs)
2074
create_func_char_cast(Session *session, Item *a, int len, const charset_info_st * const cs)
2076
const CHARSET_INFO * const real_cs= (cs ? cs : session->variables.getCollation());
2076
const charset_info_st * const real_cs= (cs ? cs : session->variables.getCollation());
2077
2077
return new (session->mem_root) Item_char_typecast(a, len, real_cs);
2082
2082
create_func_cast(Session *session, Item *a, Cast_target cast_type,
2083
2083
const char *c_len, const char *c_dec,
2084
const CHARSET_INFO * const cs)
2084
const charset_info_st * const cs)
2090
2090
switch (cast_type) {
2091
case ITEM_CAST_SIGNED:
2092
res= new (session->mem_root) function::cast::Signed(a);
2095
case ITEM_CAST_UNSIGNED:
2096
res= new (session->mem_root) function::cast::Unsigned(a);
2091
2099
case ITEM_CAST_BINARY:
2092
2100
res= new (session->mem_root) Item_func_binary(a);
2103
case ITEM_CAST_BOOLEAN:
2104
res= new (session->mem_root) function::cast::Boolean(a);
2107
case ITEM_CAST_TIME:
2108
res= new (session->mem_root) function::cast::Time(a);
2094
2111
case ITEM_CAST_DATE:
2095
2112
res= new (session->mem_root) Item_date_typecast(a);
2097
2115
case ITEM_CAST_DATETIME:
2098
2116
res= new (session->mem_root) Item_datetime_typecast(a);
2100
2119
case ITEM_CAST_DECIMAL:
2102
len= c_len ? atoi(c_len) : 0;
2103
dec= c_dec ? atoi(c_dec) : 0;
2104
my_decimal_trim(&len, &dec);
2107
my_error(ER_M_BIGGER_THAN_D, MYF(0), "");
2110
if (len > DECIMAL_MAX_PRECISION)
2112
my_error(ER_TOO_BIG_PRECISION, MYF(0), len, a->name,
2113
DECIMAL_MAX_PRECISION);
2116
if (dec > DECIMAL_MAX_SCALE)
2118
my_error(ER_TOO_BIG_SCALE, MYF(0), dec, a->name,
2122
res= new (session->mem_root) Item_decimal_typecast(a, len, dec);
2121
len= c_len ? atoi(c_len) : 0;
2122
dec= c_dec ? atoi(c_dec) : 0;
2123
class_decimal_trim(&len, &dec);
2126
my_error(ER_M_BIGGER_THAN_D, MYF(0), "");
2129
if (len > DECIMAL_MAX_PRECISION)
2131
my_error(ER_TOO_BIG_PRECISION, MYF(0), len, a->name,
2132
DECIMAL_MAX_PRECISION);
2135
if (dec > DECIMAL_MAX_SCALE)
2137
my_error(ER_TOO_BIG_SCALE, MYF(0), dec, a->name,
2141
res= new (session->mem_root) Item_decimal_typecast(a, len, dec);
2125
2144
case ITEM_CAST_CHAR:
2127
len= c_len ? atoi(c_len) : -1;
2128
res= create_func_char_cast(session, a, len, cs);
2146
len= c_len ? atoi(c_len) : -1;
2147
res= create_func_char_cast(session, a, len, cs);