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
36
using namespace std;
43
38
void Item_func::set_arguments(List<Item> &list)
45
40
allowed_arg_cols= 1;
46
41
arg_count=list.elements;
47
42
args= tmp_arg; // If 2 arguments
48
if (arg_count <= 2 || (args=(Item**) memory::sql_alloc(sizeof(Item*)*arg_count)))
43
if (arg_count <= 2 || (args=(Item**) sql_alloc(sizeof(Item*)*arg_count)))
50
45
List_iterator_fast<Item> li(list);
60
55
list.empty(); // Fields are used
63
Item_func::Item_func(List<Item> &list) :
64
_session(*current_session),
66
const_item_cache(false)
58
Item_func::Item_func(List<Item> &list)
68
collation.set(DERIVATION_SYSCONST);
69
61
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)
64
Item_func::Item_func(Session *session, Item_func *item)
65
:Item_result_field(session, item),
66
allowed_arg_cols(item->allowed_arg_cols),
67
arg_count(item->arg_count),
68
used_tables_cache(item->used_tables_cache),
69
not_null_tables_cache(item->not_null_tables_cache),
70
const_item_cache(item->const_item_cache)
87
if (!(args=(Item**) session->getMemRoot()->allocate(sizeof(Item*)*arg_count)))
78
if (!(args=(Item**) session->alloc(sizeof(Item*)*arg_count)))
90
81
memcpy(args, item->args, sizeof(Item*)*arg_count);
92
collation.set(DERIVATION_SYSCONST);
135
125
unsigned char buff[STACK_BUFF_ALLOC]; // Max argument in function
136
126
session->session_marker= 0;
137
127
used_tables_cache= not_null_tables_cache= 0;
138
const_item_cache= true;
140
130
if (check_stack_overrun(session, STACK_MIN_SIZE, buff))
141
131
return true; // Fatal error if flag is set!
285
275
change records at each execution.
287
277
if (*arg != new_item)
288
getSession().change_item_tree(arg, new_item);
278
current_session->change_item_tree(arg, new_item);
291
281
return (this->*transformer)(argument);
438
bool Item_func::get_arg0_date(type::Time <ime, uint32_t fuzzy_date)
428
bool Item_func::get_arg0_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date)
440
430
return (null_value=args[0]->get_date(ltime, fuzzy_date));
444
bool Item_func::get_arg0_time(type::Time <ime)
434
bool Item_func::get_arg0_time(DRIZZLE_TIME *ltime)
446
return (null_value= args[0]->get_time(ltime));
436
return (null_value=args[0]->get_time(ltime));
457
447
Field *Item_func::tmp_table_field(Table *table)
461
451
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);
453
if (max_length > MY_INT32_NUM_DECIMAL_DIGITS)
454
field= new Field_int64_t(max_length, maybe_null, name, unsigned_flag);
473
field= new field::Int32(max_length, maybe_null, name, false);
456
field= new Field_long(max_length, maybe_null, name, unsigned_flag);
478
458
case REAL_RESULT:
479
459
field= new Field_double(max_length, maybe_null, name, decimals);
482
461
case STRING_RESULT:
483
462
return make_string_field(table);
485
463
case DECIMAL_RESULT:
486
field= new Field_decimal(class_decimal_precision_to_length(decimal_precision(),
464
field= new Field_new_decimal(
465
my_decimal_precision_to_length(decimal_precision(),
468
maybe_null, name, decimals, unsigned_flag);
495
472
// This case should never be chosen
501
478
field->init(table);
507
type::Decimal *Item_func::val_decimal(type::Decimal *decimal_value)
483
my_decimal *Item_func::val_decimal(my_decimal *decimal_value)
510
int2_class_decimal(E_DEC_FATAL_ERROR, val_int(), unsigned_flag, decimal_value);
486
int2my_decimal(E_DEC_FATAL_ERROR, val_int(), unsigned_flag, decimal_value);
511
487
return decimal_value;
581
557
set_if_smaller(unsigned_flag, args[i]->unsigned_flag);
583
559
int precision= min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
584
max_length= class_decimal_precision_to_length(precision, decimals,
560
max_length= my_decimal_precision_to_length(precision, decimals,
637
613
void Item_func::signal_divide_by_null()
639
my_error(ER_DIVISION_BY_ZERO, MYF(0));
615
Session *session= current_session;
616
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DIVISION_BY_ZERO, ER(ER_DIVISION_BY_ZERO));