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
22
#include <drizzled/check_stack_overrun.h>
23
#include <drizzled/current_session.h>
24
#include <drizzled/error.h>
22
#include <drizzled/sql_string.h>
23
#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>
25
29
#include <drizzled/field/decimal.h>
26
#include <drizzled/field/double.h>
27
#include <drizzled/field/int32.h>
28
#include <drizzled/field/int64.h>
29
#include <drizzled/field/size.h>
30
#include <drizzled/function/math/int.h>
31
30
#include <drizzled/session.h>
32
#include <drizzled/sql_list.h>
33
#include <drizzled/sql_string.h>
31
#include <drizzled/error.h>
32
#include <drizzled/check_stack_overrun.h>
36
34
#include <algorithm>
44
Item_func::Item_func(void):
45
_session(*current_session),
46
allowed_arg_cols(1), arg_count(0),
47
const_item_cache(false)
50
collation.set(DERIVATION_SYSCONST);
53
Item_func::Item_func(Item *a):
54
_session(*current_session),
55
allowed_arg_cols(1), arg_count(1),
56
const_item_cache(false)
60
with_sum_func= a->with_sum_func;
61
collation.set(DERIVATION_SYSCONST);
64
Item_func::Item_func(Item *a,Item *b):
65
_session(*current_session),
66
allowed_arg_cols(1), arg_count(2),
67
const_item_cache(false)
70
args[0]= a; args[1]= b;
71
with_sum_func= a->with_sum_func || b->with_sum_func;
72
collation.set(DERIVATION_SYSCONST);
75
Item_func::Item_func(Item *a,Item *b,Item *c):
76
_session(*current_session),
78
const_item_cache(false)
81
if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*3)))
84
args[0]= a; args[1]= b; args[2]= c;
85
with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func;
87
collation.set(DERIVATION_SYSCONST);
90
Item_func::Item_func(Item *a,Item *b,Item *c,Item *d):
91
_session(*current_session),
93
const_item_cache(false)
96
if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*4)))
99
args[0]= a; args[1]= b; args[2]= c; args[3]= d;
100
with_sum_func= a->with_sum_func || b->with_sum_func ||
101
c->with_sum_func || d->with_sum_func;
103
collation.set(DERIVATION_SYSCONST);
106
Item_func::Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
107
_session(*current_session),
109
const_item_cache(false)
112
if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*5)))
114
args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
115
with_sum_func= a->with_sum_func || b->with_sum_func ||
116
c->with_sum_func || d->with_sum_func || e->with_sum_func ;
118
collation.set(DERIVATION_SYSCONST);
122
42
void Item_func::set_arguments(List<Item> &list)
124
44
allowed_arg_cols= 1;
136
56
with_sum_func|=item->with_sum_func;
139
list.clear(); // Fields are used
59
list.empty(); // Fields are used
142
Item_func::Item_func(List<Item> &list) :
143
_session(*current_session),
145
const_item_cache(false)
62
Item_func::Item_func(List<Item> &list)
147
collation.set(DERIVATION_SYSCONST);
148
65
set_arguments(list);
151
Item_func::Item_func(Session *session, Item_func *item) :
152
Item_result_field(session, item),
153
_session(*current_session),
154
allowed_arg_cols(item->allowed_arg_cols),
155
arg_count(item->arg_count),
156
used_tables_cache(item->used_tables_cache),
157
not_null_tables_cache(item->not_null_tables_cache),
158
const_item_cache(item->const_item_cache)
68
Item_func::Item_func(Session *session, Item_func *item)
69
:Item_result_field(session, item),
70
allowed_arg_cols(item->allowed_arg_cols),
71
arg_count(item->arg_count),
72
used_tables_cache(item->used_tables_cache),
73
not_null_tables_cache(item->not_null_tables_cache),
74
const_item_cache(item->const_item_cache)
214
129
unsigned char buff[STACK_BUFF_ALLOC]; // Max argument in function
215
130
session->session_marker= 0;
216
131
used_tables_cache= not_null_tables_cache= 0;
217
const_item_cache= true;
219
134
if (check_stack_overrun(session, STACK_MIN_SIZE, buff))
220
135
return true; // Fatal error if flag is set!
517
bool Item_func::get_arg0_date(type::Time <ime, uint32_t fuzzy_date)
432
bool Item_func::get_arg0_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date)
519
434
return (null_value=args[0]->get_date(ltime, fuzzy_date));
523
bool Item_func::get_arg0_time(type::Time <ime)
438
bool Item_func::get_arg0_time(DRIZZLE_TIME *ltime)
525
return (null_value= args[0]->get_time(ltime));
440
return (null_value=args[0]->get_time(ltime));
536
451
Field *Item_func::tmp_table_field(Table *table)
540
455
switch (result_type()) {
544
field= new field::Size(max_length, maybe_null, name, true);
546
else if (max_length > MY_INT32_NUM_DECIMAL_DIGITS)
548
field= new field::Int64(max_length, maybe_null, name, false);
457
if (max_length > MY_INT32_NUM_DECIMAL_DIGITS)
458
field= new Field_int64_t(max_length, maybe_null, name, unsigned_flag);
552
field= new field::Int32(max_length, maybe_null, name, false);
460
field= new Field_long(max_length, maybe_null, name, unsigned_flag);
557
462
case REAL_RESULT:
558
463
field= new Field_double(max_length, maybe_null, name, decimals);
561
465
case STRING_RESULT:
562
466
return make_string_field(table);
564
467
case DECIMAL_RESULT:
565
field= new Field_decimal(class_decimal_precision_to_length(decimal_precision(),
468
field= new Field_decimal(my_decimal_precision_to_length(decimal_precision(),
574
478
// This case should never be chosen
580
484
field->init(table);
586
type::Decimal *Item_func::val_decimal(type::Decimal *decimal_value)
489
my_decimal *Item_func::val_decimal(my_decimal *decimal_value)
589
int2_class_decimal(E_DEC_FATAL_ERROR, val_int(), unsigned_flag, decimal_value);
492
int2my_decimal(E_DEC_FATAL_ERROR, val_int(), unsigned_flag, decimal_value);
590
493
return decimal_value;
660
563
set_if_smaller(unsigned_flag, args[i]->unsigned_flag);
662
565
int precision= min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
663
max_length= class_decimal_precision_to_length(precision, decimals,
566
max_length= my_decimal_precision_to_length(precision, decimals,
716
619
void Item_func::signal_divide_by_null()
718
my_error(ER_DIVISION_BY_ZERO, MYF(0));
621
Session *session= current_session;
622
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DIVISION_BY_ZERO, ER(ER_DIVISION_BY_ZERO));