17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include <drizzled/server_includes.h>
26
22
#include <drizzled/sql_string.h>
27
23
#include <drizzled/sql_list.h>
29
#include <drizzled/functions/int.h>
25
#include <drizzled/function/math/int.h>
30
26
#include <drizzled/field/int64_t.h>
31
27
#include <drizzled/field/long.h>
32
28
#include <drizzled/field/double.h>
33
#include <drizzled/field/fdecimal.h>
35
#include <drizzled/util/math.h>
29
#include <drizzled/field/decimal.h>
36
30
#include <drizzled/session.h>
38
#if defined(CMATH_NAMESPACE)
39
using namespace CMATH_NAMESPACE;
31
#include <drizzled/error.h>
32
#include <drizzled/check_stack_overrun.h>
44
42
void Item_func::set_arguments(List<Item> &list)
61
59
list.empty(); // Fields are used
64
Item_func::Item_func(List<Item> &list)
62
Item_func::Item_func(List<Item> &list) :
63
_session(*current_session),
66
collation.set(DERIVATION_SYSCONST);
67
67
set_arguments(list);
70
Item_func::Item_func(Session *session, Item_func *item)
71
:Item_result_field(session, item),
72
allowed_arg_cols(item->allowed_arg_cols),
73
arg_count(item->arg_count),
74
used_tables_cache(item->used_tables_cache),
75
not_null_tables_cache(item->not_null_tables_cache),
76
const_item_cache(item->const_item_cache)
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)
226
228
Item **arg,**arg_end;
230
232
(*traverser)(this, argument);
231
233
for (arg= args, arg_end= args+arg_count; arg != arg_end; arg++)
233
235
(*arg)->traverse_cond(traverser, argument, order);
237
239
for (arg= args, arg_end= args+arg_count; arg != arg_end; arg++)
239
241
(*arg)->traverse_cond(traverser, argument, order);
467
469
case STRING_RESULT:
468
470
return make_string_field(table);
470
471
case DECIMAL_RESULT:
471
field= new Field_new_decimal(
472
my_decimal_precision_to_length(decimal_precision(),
475
maybe_null, name, decimals, unsigned_flag);
472
field= new Field_decimal(my_decimal_precision_to_length(decimal_precision(),
522
525
double Item_func::fix_result(double value)
527
static double fix_infinity= numeric_limits<double>::infinity();
529
if (value != fix_infinity && value != -fix_infinity)
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
my_error(ER_DIVISION_BY_ZERO, MYF(0));
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 */