17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include <drizzled/server_includes.h>
25
#include <drizzled/version.h>
22
27
#include <drizzled/sql_string.h>
23
28
#include <drizzled/sql_list.h>
25
#include <drizzled/function/math/int.h>
26
#include <drizzled/field/int64_t.h>
27
#include <drizzled/field/long.h>
28
#include <drizzled/field/double.h>
29
#include <drizzled/field/decimal.h>
30
#include <drizzled/session.h>
31
#include <drizzled/error.h>
32
#include <drizzled/check_stack_overrun.h>
30
#include <drizzled/functions/int.h>
42
33
void Item_func::set_arguments(List<Item> &list)
59
50
list.empty(); // Fields are used
62
Item_func::Item_func(List<Item> &list) :
63
_session(*current_session),
53
Item_func::Item_func(List<Item> &list)
66
collation.set(DERIVATION_SYSCONST);
67
56
set_arguments(list);
70
Item_func::Item_func(Session *session, Item_func *item) :
71
Item_result_field(session, item),
72
_session(*current_session),
73
allowed_arg_cols(item->allowed_arg_cols),
74
arg_count(item->arg_count),
75
used_tables_cache(item->used_tables_cache),
76
not_null_tables_cache(item->not_null_tables_cache),
77
const_item_cache(item->const_item_cache)
59
Item_func::Item_func(THD *thd, Item_func *item)
60
:Item_result_field(thd, item),
61
allowed_arg_cols(item->allowed_arg_cols),
62
arg_count(item->arg_count),
63
used_tables_cache(item->used_tables_cache),
64
not_null_tables_cache(item->not_null_tables_cache),
65
const_item_cache(item->const_item_cache)
128
Item_func::fix_fields(Session *session, Item **)
115
Item_func::fix_fields(THD *thd, Item **ref __attribute__((unused)))
130
117
assert(fixed == 0);
131
118
Item **arg,**arg_end;
132
void *save_session_marker= session->session_marker;
119
void *save_thd_marker= thd->thd_marker;
133
120
unsigned char buff[STACK_BUFF_ALLOC]; // Max argument in function
134
session->session_marker= 0;
135
122
used_tables_cache= not_null_tables_cache= 0;
136
123
const_item_cache=1;
138
if (check_stack_overrun(session, STACK_MIN_SIZE, buff))
125
if (check_stack_overrun(thd, STACK_MIN_SIZE, buff))
139
126
return true; // Fatal error if flag is set!
141
128
{ // Print purify happy
176
163
fix_length_and_dec();
177
if (session->is_error()) // An error inside fix_length_and_dec occured
164
if (thd->is_error()) // An error inside fix_length_and_dec occured
180
session->session_marker= save_session_marker;
167
thd->thd_marker= save_thd_marker;
185
void Item_func::fix_after_pullout(Select_Lex *new_parent,
172
void Item_func::fix_after_pullout(st_select_lex *new_parent,
173
Item **ref __attribute__((unused)))
188
175
Item **arg,**arg_end;
228
215
Item **arg,**arg_end;
232
219
(*traverser)(this, argument);
233
220
for (arg= args, arg_end= args+arg_count; arg != arg_end; arg++)
235
222
(*arg)->traverse_cond(traverser, argument, order);
239
226
for (arg= args, arg_end= args+arg_count; arg != arg_end; arg++)
241
228
(*arg)->traverse_cond(traverser, argument, order);
280
Session::change_item_tree() should be called only if the tree was
267
THD::change_item_tree() should be called only if the tree was
281
268
really transformed, i.e. when a new item has been created.
282
269
Otherwise we'll be allocating a lot of unnecessary memory for
283
270
change records at each execution.
285
272
if (*arg != new_item)
286
getSession().change_item_tree(arg, new_item);
273
current_thd->change_item_tree(arg, new_item);
289
276
return (this->*transformer)(argument);
331
318
unsigned char *arg_v= *arg_p;
332
319
Item *new_item= (*arg)->compile(analyzer, &arg_v, transformer, arg_t);
333
320
if (new_item && *arg != new_item)
334
current_session->change_item_tree(arg, new_item);
321
current_thd->change_item_tree(arg, new_item);
337
324
return (this->*transformer)(arg_t);
341
328
See comments in Item_cmp_func::split_sum_func()
344
void Item_func::split_sum_func(Session *session, Item **ref_pointer_array,
331
void Item_func::split_sum_func(THD *thd, Item **ref_pointer_array,
345
332
List<Item> &fields)
347
334
Item **arg, **arg_end;
348
335
for (arg= args, arg_end= args+arg_count; arg != arg_end ; arg++)
349
(*arg)->split_sum_func(session, ref_pointer_array, fields, arg, true);
336
(*arg)->split_sum_func2(thd, ref_pointer_array, fields, arg, true);
469
456
case STRING_RESULT:
470
457
return make_string_field(table);
471
459
case DECIMAL_RESULT:
472
field= new Field_decimal(my_decimal_precision_to_length(decimal_precision(),
460
field= new Field_new_decimal(
461
my_decimal_precision_to_length(decimal_precision(),
464
maybe_null, name, decimals, unsigned_flag);
525
511
double Item_func::fix_result(double value)
527
static double fix_infinity= numeric_limits<double>::infinity();
529
if (value != fix_infinity && value != -fix_infinity)
513
if (CMATH_NAMESPACE::isfinite(value))
536
void Item_func::fix_num_length_and_dec()
538
uint32_t fl_length= 0;
540
for (uint32_t i=0 ; i < arg_count ; i++)
542
set_if_bigger(decimals,args[i]->decimals);
543
set_if_bigger(fl_length, args[i]->max_length);
545
max_length=float_length(decimals);
546
if (fl_length > max_length)
548
decimals= NOT_FIXED_DEC;
549
max_length= float_length(NOT_FIXED_DEC);
554
Set max_length/decimals of function if function is fixed point and
555
result length/precision depends on argument ones.
558
void Item_func::count_decimal_length()
563
for (uint32_t i= 0 ; i < arg_count ; i++)
565
set_if_bigger(decimals, args[i]->decimals);
566
set_if_bigger(max_int_part, args[i]->decimal_int_part());
567
set_if_smaller(unsigned_flag, args[i]->unsigned_flag);
569
int precision= min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
570
max_length= my_decimal_precision_to_length(precision, decimals,
576
Set max_length of if it is maximum length of its arguments.
579
void Item_func::count_only_length()
583
for (uint32_t i=0 ; i < arg_count ; i++)
585
set_if_bigger(max_length, args[i]->max_length);
586
set_if_bigger(unsigned_flag, args[i]->unsigned_flag);
592
Set max_length/decimals of function if function is floating point and
593
result length/precision depends on argument ones.
596
void Item_func::count_real_length()
601
for (uint32_t i=0 ; i < arg_count ; i++)
603
if (decimals != NOT_FIXED_DEC)
605
set_if_bigger(decimals, args[i]->decimals);
606
set_if_bigger(length, (args[i]->max_length - args[i]->decimals));
608
set_if_bigger(max_length, args[i]->max_length);
610
if (decimals != NOT_FIXED_DEC)
614
if (length < max_length) // If previous operation gave overflow
615
max_length= UINT32_MAX;
623
void Item_func::signal_divide_by_null()
625
push_warning(getSessionPtr(), DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DIVISION_BY_ZERO, ER(ER_DIVISION_BY_ZERO));
630
Item *Item_func::get_tmp_table_item(Session *session)
632
if (!with_sum_func && !const_item() && functype() != SUSERVAR_FUNC)
633
return new Item_field(result_field);
634
return copy_or_same(session);
638
} /* namespace drizzled */