17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include <drizzled/sql_string.h>
23
#include <drizzled/sql_list.h>
25
#include <drizzled/function/math/int.h>
22
#include <drizzled/check_stack_overrun.h>
23
#include <drizzled/current_session.h>
24
#include <drizzled/error.h>
25
#include <drizzled/field/decimal.h>
26
#include <drizzled/field/double.h>
26
27
#include <drizzled/field/int32.h>
27
28
#include <drizzled/field/int64.h>
28
#include <drizzled/field/double.h>
29
#include <drizzled/field/decimal.h>
29
#include <drizzled/field/size.h>
30
#include <drizzled/function/math/int.h>
31
#include <drizzled/item/field.h>
30
32
#include <drizzled/session.h>
31
#include <drizzled/error.h>
32
#include <drizzled/check_stack_overrun.h>
33
#include <drizzled/sql_list.h>
34
#include <drizzled/sql_string.h>
34
37
#include <algorithm>
45
Item_func::Item_func(void):
46
_session(*current_session),
47
allowed_arg_cols(1), arg_count(0),
48
const_item_cache(false)
51
collation.set(DERIVATION_SYSCONST);
54
Item_func::Item_func(Item *a):
55
_session(*current_session),
56
allowed_arg_cols(1), arg_count(1),
57
const_item_cache(false)
61
with_sum_func= a->with_sum_func;
62
collation.set(DERIVATION_SYSCONST);
65
Item_func::Item_func(Item *a,Item *b):
66
_session(*current_session),
67
allowed_arg_cols(1), arg_count(2),
68
const_item_cache(false)
71
args[0]= a; args[1]= b;
72
with_sum_func= a->with_sum_func || b->with_sum_func;
73
collation.set(DERIVATION_SYSCONST);
76
Item_func::Item_func(Item *a,Item *b,Item *c):
77
_session(*current_session),
79
const_item_cache(false)
82
if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*3)))
85
args[0]= a; args[1]= b; args[2]= c;
86
with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func;
88
collation.set(DERIVATION_SYSCONST);
91
Item_func::Item_func(Item *a,Item *b,Item *c,Item *d):
92
_session(*current_session),
94
const_item_cache(false)
97
if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*4)))
100
args[0]= a; args[1]= b; args[2]= c; args[3]= d;
101
with_sum_func= a->with_sum_func || b->with_sum_func ||
102
c->with_sum_func || d->with_sum_func;
104
collation.set(DERIVATION_SYSCONST);
107
Item_func::Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
108
_session(*current_session),
110
const_item_cache(false)
113
if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*5)))
115
args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
116
with_sum_func= a->with_sum_func || b->with_sum_func ||
117
c->with_sum_func || d->with_sum_func || e->with_sum_func ;
119
collation.set(DERIVATION_SYSCONST);
42
123
void Item_func::set_arguments(List<Item> &list)
44
125
allowed_arg_cols= 1;
45
arg_count=list.elements;
126
arg_count=list.size();
46
127
args= tmp_arg; // If 2 arguments
47
128
if (arg_count <= 2 || (args=(Item**) memory::sql_alloc(sizeof(Item*)*arg_count)))
49
List_iterator_fast<Item> li(list);
130
List<Item>::iterator li(list.begin());
51
132
Item **save_args= args;
275
357
Item *new_item= (*arg)->transform(transformer, argument);
280
Session::change_item_tree() should be called only if the tree was
281
really transformed, i.e. when a new item has been created.
282
Otherwise we'll be allocating a lot of unnecessary memory for
283
change records at each execution.
285
if (*arg != new_item)
286
getSession().change_item_tree(arg, new_item);
289
363
return (this->*transformer)(argument);
331
405
unsigned char *arg_v= *arg_p;
332
406
Item *new_item= (*arg)->compile(analyzer, &arg_v, transformer, arg_t);
333
407
if (new_item && *arg != new_item)
334
current_session->change_item_tree(arg, new_item);
337
411
return (this->*transformer)(arg_t);
378
void Item_func::print(String *str, enum_query_type query_type)
452
void Item_func::print(String *str)
380
454
str->append(func_name());
381
455
str->append('(');
382
print_args(str, 0, query_type);
383
457
str->append(')');
387
void Item_func::print_args(String *str, uint32_t from, enum_query_type query_type)
461
void Item_func::print_args(String *str, uint32_t from)
389
463
for (uint32_t i=from ; i < arg_count ; i++)
392
466
str->append(',');
393
args[i]->print(str, query_type);
398
void Item_func::print_op(String *str, enum_query_type query_type)
472
void Item_func::print_op(String *str)
400
474
str->append('(');
401
475
for (uint32_t i=0 ; i < arg_count-1 ; i++)
403
args[i]->print(str, query_type);
404
478
str->append(' ');
405
479
str->append(func_name());
406
480
str->append(' ');
408
args[arg_count-1]->print(str, query_type);
482
args[arg_count-1]->print(str);
409
483
str->append(')');
436
bool Item_func::get_arg0_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date)
510
bool Item_func::get_arg0_date(type::Time <ime, uint32_t fuzzy_date)
438
512
return (null_value=args[0]->get_date(ltime, fuzzy_date));
442
bool Item_func::get_arg0_time(DRIZZLE_TIME *ltime)
516
bool Item_func::get_arg0_time(type::Time <ime)
444
return (null_value=args[0]->get_time(ltime));
518
return (null_value= args[0]->get_time(ltime));
459
533
switch (result_type()) {
461
if (max_length > MY_INT32_NUM_DECIMAL_DIGITS)
462
field= new field::Int64(max_length, maybe_null, name, unsigned_flag);
537
field= new field::Size(max_length, maybe_null, name, true);
539
else if (max_length > MY_INT32_NUM_DECIMAL_DIGITS)
541
field= new field::Int64(max_length, maybe_null, name, false);
464
field= new field::Int32(max_length, maybe_null, name, unsigned_flag);
545
field= new field::Int32(max_length, maybe_null, name, false);
467
550
case REAL_RESULT:
496
my_decimal *Item_func::val_decimal(my_decimal *decimal_value)
579
type::Decimal *Item_func::val_decimal(type::Decimal *decimal_value)
499
int2my_decimal(E_DEC_FATAL_ERROR, val_int(), unsigned_flag, decimal_value);
582
int2_class_decimal(E_DEC_FATAL_ERROR, val_int(), unsigned_flag, decimal_value);
500
583
return decimal_value;
570
653
set_if_smaller(unsigned_flag, args[i]->unsigned_flag);
572
655
int precision= min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
573
max_length= my_decimal_precision_to_length(precision, decimals,
656
max_length= class_decimal_precision_to_length(precision, decimals,