1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
4
* Copyright (C) 2008 Sun Microsystems
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include <drizzled/server_includes.h>
22
26
#include <drizzled/sql_string.h>
23
27
#include <drizzled/sql_list.h>
25
#include <drizzled/function/math/int.h>
26
#include <drizzled/field/int32.h>
27
#include <drizzled/field/int64.h>
28
#include <drizzled/field/decimal.h>
29
#include <drizzled/field/double.h>
30
#include <drizzled/field/size.h>
31
#include <drizzled/session.h>
32
#include <drizzled/error.h>
33
#include <drizzled/check_stack_overrun.h>
29
#include <drizzled/functions/int.h>
43
32
void Item_func::set_arguments(List<Item> &list)
60
49
list.empty(); // Fields are used
63
Item_func::Item_func(List<Item> &list) :
64
_session(*current_session),
66
const_item_cache(false)
52
Item_func::Item_func(List<Item> &list)
68
collation.set(DERIVATION_SYSCONST);
69
55
set_arguments(list);
72
Item_func::Item_func(Session *session, Item_func *item) :
73
Item_result_field(session, item),
74
_session(*current_session),
75
allowed_arg_cols(item->allowed_arg_cols),
76
arg_count(item->arg_count),
77
used_tables_cache(item->used_tables_cache),
78
not_null_tables_cache(item->not_null_tables_cache),
79
const_item_cache(item->const_item_cache)
58
Item_func::Item_func(Session *session, Item_func *item)
59
:Item_result_field(session, item),
60
allowed_arg_cols(item->allowed_arg_cols),
61
arg_count(item->arg_count),
62
used_tables_cache(item->used_tables_cache),
63
not_null_tables_cache(item->not_null_tables_cache),
64
const_item_cache(item->const_item_cache)
230
214
Item **arg,**arg_end;
234
218
(*traverser)(this, argument);
235
219
for (arg= args, arg_end= args+arg_count; arg != arg_end; arg++)
237
221
(*arg)->traverse_cond(traverser, argument, order);
241
225
for (arg= args, arg_end= args+arg_count; arg != arg_end; arg++)
243
227
(*arg)->traverse_cond(traverser, argument, order);
349
333
Item **arg, **arg_end;
350
334
for (arg= args, arg_end= args+arg_count; arg != arg_end ; arg++)
351
(*arg)->split_sum_func(session, ref_pointer_array, fields, arg, true);
335
(*arg)->split_sum_func2(session, ref_pointer_array, fields, arg, true);
355
339
void Item_func::update_used_tables()
357
341
used_tables_cache=0;
358
const_item_cache= true;
359
343
for (uint32_t i=0 ; i < arg_count ; i++)
361
345
args[i]->update_used_tables();
438
bool Item_func::get_arg0_date(type::Time <ime, uint32_t fuzzy_date)
422
bool Item_func::get_arg0_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date)
440
424
return (null_value=args[0]->get_date(ltime, fuzzy_date));
444
bool Item_func::get_arg0_time(type::Time <ime)
428
bool Item_func::get_arg0_time(DRIZZLE_TIME *ltime)
446
return (null_value= args[0]->get_time(ltime));
430
return (null_value=args[0]->get_time(ltime));
457
441
Field *Item_func::tmp_table_field(Table *table)
461
445
switch (result_type()) {
465
field= new field::Size(max_length, maybe_null, name, true);
467
else if (max_length > MY_INT32_NUM_DECIMAL_DIGITS)
469
field= new field::Int64(max_length, maybe_null, name, false);
447
if (max_length > MY_INT32_NUM_DECIMAL_DIGITS)
448
field= new Field_int64_t(max_length, maybe_null, name, unsigned_flag);
473
field= new field::Int32(max_length, maybe_null, name, false);
450
field= new Field_long(max_length, maybe_null, name, unsigned_flag);
478
452
case REAL_RESULT:
479
453
field= new Field_double(max_length, maybe_null, name, decimals);
482
455
case STRING_RESULT:
483
456
return make_string_field(table);
485
458
case DECIMAL_RESULT:
486
field= new Field_decimal(class_decimal_precision_to_length(decimal_precision(),
459
field= new Field_new_decimal(
460
my_decimal_precision_to_length(decimal_precision(),
463
maybe_null, name, decimals, unsigned_flag);
495
467
// This case should never be chosen
501
473
field->init(table);
507
type::Decimal *Item_func::val_decimal(type::Decimal *decimal_value)
478
my_decimal *Item_func::val_decimal(my_decimal *decimal_value)
510
int2_class_decimal(E_DEC_FATAL_ERROR, val_int(), unsigned_flag, decimal_value);
481
int2my_decimal(E_DEC_FATAL_ERROR, val_int(), unsigned_flag, decimal_value);
511
482
return decimal_value;
539
510
double Item_func::fix_result(double value)
541
static double fix_infinity= numeric_limits<double>::infinity();
543
if (value != fix_infinity && value != -fix_infinity)
550
void Item_func::fix_num_length_and_dec()
552
uint32_t fl_length= 0;
554
for (uint32_t i=0 ; i < arg_count ; i++)
556
set_if_bigger(decimals,args[i]->decimals);
557
set_if_bigger(fl_length, args[i]->max_length);
559
max_length=float_length(decimals);
560
if (fl_length > max_length)
562
decimals= NOT_FIXED_DEC;
563
max_length= float_length(NOT_FIXED_DEC);
568
Set max_length/decimals of function if function is fixed point and
569
result length/precision depends on argument ones.
572
void Item_func::count_decimal_length()
577
for (uint32_t i= 0 ; i < arg_count ; i++)
579
set_if_bigger(decimals, args[i]->decimals);
580
set_if_bigger(max_int_part, args[i]->decimal_int_part());
581
set_if_smaller(unsigned_flag, args[i]->unsigned_flag);
583
int precision= min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
584
max_length= class_decimal_precision_to_length(precision, decimals,
590
Set max_length of if it is maximum length of its arguments.
593
void Item_func::count_only_length()
597
for (uint32_t i=0 ; i < arg_count ; i++)
599
set_if_bigger(max_length, args[i]->max_length);
600
set_if_bigger(unsigned_flag, args[i]->unsigned_flag);
606
Set max_length/decimals of function if function is floating point and
607
result length/precision depends on argument ones.
610
void Item_func::count_real_length()
615
for (uint32_t i=0 ; i < arg_count ; i++)
617
if (decimals != NOT_FIXED_DEC)
619
set_if_bigger(decimals, args[i]->decimals);
620
set_if_bigger(length, (args[i]->max_length - args[i]->decimals));
622
set_if_bigger(max_length, args[i]->max_length);
624
if (decimals != NOT_FIXED_DEC)
628
if (length < max_length) // If previous operation gave overflow
629
max_length= UINT32_MAX;
637
void Item_func::signal_divide_by_null()
639
my_error(ER_DIVISION_BY_ZERO, MYF(0));
644
Item *Item_func::get_tmp_table_item(Session *session)
646
if (!with_sum_func && !const_item() && functype() != SUSERVAR_FUNC)
647
return new Item_field(result_field);
648
return copy_or_same(session);
652
} /* namespace drizzled */