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
20
#include <drizzled/server_includes.h>
22
22
#include <drizzled/sql_string.h>
23
23
#include <drizzled/sql_list.h>
25
25
#include <drizzled/function/math/int.h>
26
#include <drizzled/field/int32.h>
27
#include <drizzled/field/int64.h>
26
#include <drizzled/field/int64_t.h>
27
#include <drizzled/field/long.h>
28
#include <drizzled/field/double.h>
28
29
#include <drizzled/field/decimal.h>
29
#include <drizzled/field/double.h>
30
#include <drizzled/field/size.h>
31
30
#include <drizzled/session.h>
32
31
#include <drizzled/error.h>
33
32
#include <drizzled/check_stack_overrun.h>
37
35
using namespace std;
43
37
void Item_func::set_arguments(List<Item> &list)
45
39
allowed_arg_cols= 1;
46
40
arg_count=list.elements;
47
41
args= tmp_arg; // If 2 arguments
48
if (arg_count <= 2 || (args=(Item**) memory::sql_alloc(sizeof(Item*)*arg_count)))
42
if (arg_count <= 2 || (args=(Item**) sql_alloc(sizeof(Item*)*arg_count)))
50
44
List_iterator_fast<Item> li(list);
60
54
list.empty(); // Fields are used
63
Item_func::Item_func(List<Item> &list) :
64
_session(*current_session),
66
const_item_cache(false)
57
Item_func::Item_func(List<Item> &list)
68
collation.set(DERIVATION_SYSCONST);
69
60
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)
63
Item_func::Item_func(Session *session, Item_func *item)
64
:Item_result_field(session, item),
65
allowed_arg_cols(item->allowed_arg_cols),
66
arg_count(item->arg_count),
67
used_tables_cache(item->used_tables_cache),
68
not_null_tables_cache(item->not_null_tables_cache),
69
const_item_cache(item->const_item_cache)
87
if (!(args=(Item**) session->getMemRoot()->allocate(sizeof(Item*)*arg_count)))
77
if (!(args=(Item**) session->alloc(sizeof(Item*)*arg_count)))
90
80
memcpy(args, item->args, sizeof(Item*)*arg_count);
92
collation.set(DERIVATION_SYSCONST);
135
124
unsigned char buff[STACK_BUFF_ALLOC]; // Max argument in function
136
125
session->session_marker= 0;
137
126
used_tables_cache= not_null_tables_cache= 0;
138
const_item_cache= true;
140
129
if (check_stack_overrun(session, STACK_MIN_SIZE, buff))
141
130
return true; // Fatal error if flag is set!
285
274
change records at each execution.
287
276
if (*arg != new_item)
288
getSession().change_item_tree(arg, new_item);
277
current_session->change_item_tree(arg, new_item);
291
280
return (this->*transformer)(argument);
438
bool Item_func::get_arg0_date(type::Time <ime, uint32_t fuzzy_date)
427
bool Item_func::get_arg0_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date)
440
429
return (null_value=args[0]->get_date(ltime, fuzzy_date));
444
bool Item_func::get_arg0_time(type::Time <ime)
433
bool Item_func::get_arg0_time(DRIZZLE_TIME *ltime)
446
return (null_value= args[0]->get_time(ltime));
435
return (null_value=args[0]->get_time(ltime));
457
446
Field *Item_func::tmp_table_field(Table *table)
461
450
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);
452
if (max_length > MY_INT32_NUM_DECIMAL_DIGITS)
453
field= new Field_int64_t(max_length, maybe_null, name, unsigned_flag);
473
field= new field::Int32(max_length, maybe_null, name, false);
455
field= new Field_long(max_length, maybe_null, name, unsigned_flag);
478
457
case REAL_RESULT:
479
458
field= new Field_double(max_length, maybe_null, name, decimals);
482
460
case STRING_RESULT:
483
461
return make_string_field(table);
485
462
case DECIMAL_RESULT:
486
field= new Field_decimal(class_decimal_precision_to_length(decimal_precision(),
463
field= new Field_new_decimal(
464
my_decimal_precision_to_length(decimal_precision(),
467
maybe_null, name, decimals, unsigned_flag);
495
471
// This case should never be chosen
501
477
field->init(table);
507
type::Decimal *Item_func::val_decimal(type::Decimal *decimal_value)
482
my_decimal *Item_func::val_decimal(my_decimal *decimal_value)
510
int2_class_decimal(E_DEC_FATAL_ERROR, val_int(), unsigned_flag, decimal_value);
485
int2my_decimal(E_DEC_FATAL_ERROR, val_int(), unsigned_flag, decimal_value);
511
486
return decimal_value;
574
549
int max_int_part= 0;
576
551
unsigned_flag= 1;
577
for (uint32_t i= 0 ; i < arg_count ; i++)
552
for (uint32_t i=0 ; i < arg_count ; i++)
579
554
set_if_bigger(decimals, args[i]->decimals);
580
555
set_if_bigger(max_int_part, args[i]->decimal_int_part());
581
556
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,
558
int precision= cmin(max_int_part + decimals, DECIMAL_MAX_PRECISION);
559
max_length= my_decimal_precision_to_length(precision, decimals,
637
612
void Item_func::signal_divide_by_null()
639
my_error(ER_DIVISION_BY_ZERO, MYF(0));
614
Session *session= current_session;
615
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DIVISION_BY_ZERO, ER(ER_DIVISION_BY_ZERO));