~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/func.cc

  • Committer: Brian Aker
  • Date: 2011-01-06 20:35:26 UTC
  • mto: This revision was merged to the branch mainline in revision 2064.
  • Revision ID: brian@tangent.org-20110106203526-p9k1sub71wqajv7y
We no longer look at the sign of a timestamp.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
21
 
 
22
 
#include <drizzled/check_stack_overrun.h>
23
 
#include <drizzled/current_session.h>
24
 
#include <drizzled/error.h>
 
20
#include "config.h"
 
21
 
 
22
#include <drizzled/sql_string.h>
 
23
#include <drizzled/sql_list.h>
 
24
 
 
25
#include <drizzled/function/math/int.h>
 
26
#include <drizzled/field/int32.h>
 
27
#include <drizzled/field/int64.h>
25
28
#include <drizzled/field/decimal.h>
26
29
#include <drizzled/field/double.h>
27
 
#include <drizzled/field/int32.h>
28
 
#include <drizzled/field/int64.h>
29
30
#include <drizzled/field/size.h>
30
 
#include <drizzled/function/math/int.h>
31
31
#include <drizzled/session.h>
32
 
#include <drizzled/sql_list.h>
33
 
#include <drizzled/sql_string.h>
34
 
 
 
32
#include <drizzled/error.h>
 
33
#include <drizzled/check_stack_overrun.h>
35
34
#include <limits>
36
35
#include <algorithm>
37
36
 
41
40
{
42
41
 
43
42
 
44
 
Item_func::Item_func(void):
45
 
  _session(*current_session),
46
 
  allowed_arg_cols(1), arg_count(0),
47
 
  const_item_cache(false)
48
 
  {
49
 
    with_sum_func= 0;
50
 
    collation.set(DERIVATION_SYSCONST);
51
 
  }
52
 
 
53
 
Item_func::Item_func(Item *a):
54
 
  _session(*current_session),
55
 
  allowed_arg_cols(1), arg_count(1),
56
 
  const_item_cache(false)
57
 
  {
58
 
    args= tmp_arg;
59
 
    args[0]= a;
60
 
    with_sum_func= a->with_sum_func;
61
 
    collation.set(DERIVATION_SYSCONST);
62
 
  }
63
 
 
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)
68
 
  {
69
 
    args= tmp_arg;
70
 
    args[0]= a; args[1]= b;
71
 
    with_sum_func= a->with_sum_func || b->with_sum_func;
72
 
    collation.set(DERIVATION_SYSCONST);
73
 
  }
74
 
 
75
 
Item_func::Item_func(Item *a,Item *b,Item *c):
76
 
  _session(*current_session),
77
 
  allowed_arg_cols(1),
78
 
  const_item_cache(false)
79
 
  {
80
 
    arg_count= 0;
81
 
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*3)))
82
 
    {
83
 
      arg_count= 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;
86
 
    }
87
 
    collation.set(DERIVATION_SYSCONST);
88
 
  }
89
 
 
90
 
Item_func::Item_func(Item *a,Item *b,Item *c,Item *d):
91
 
  _session(*current_session),
92
 
  allowed_arg_cols(1),
93
 
  const_item_cache(false)
94
 
  {
95
 
    arg_count= 0;
96
 
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*4)))
97
 
    {
98
 
      arg_count= 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;
102
 
    }
103
 
    collation.set(DERIVATION_SYSCONST);
104
 
  }
105
 
 
106
 
Item_func::Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
107
 
  _session(*current_session),
108
 
  allowed_arg_cols(1),
109
 
  const_item_cache(false)
110
 
  {
111
 
    arg_count= 5;
112
 
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*5)))
113
 
    {
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 ;
117
 
    }
118
 
    collation.set(DERIVATION_SYSCONST);
119
 
  }
120
 
 
121
 
 
122
43
void Item_func::set_arguments(List<Item> &list)
123
44
{
124
45
  allowed_arg_cols= 1;
126
47
  args= tmp_arg;                                // If 2 arguments
127
48
  if (arg_count <= 2 || (args=(Item**) memory::sql_alloc(sizeof(Item*)*arg_count)))
128
49
  {
129
 
    List<Item>::iterator li(list.begin());
 
50
    List_iterator_fast<Item> li(list);
130
51
    Item *item;
131
52
    Item **save_args= args;
132
53
 
136
57
      with_sum_func|=item->with_sum_func;
137
58
    }
138
59
  }
139
 
  list.clear();          // Fields are used
 
60
  list.empty();          // Fields are used
140
61
}
141
62
 
142
63
Item_func::Item_func(List<Item> &list) :
143
64
  _session(*current_session),
144
 
  allowed_arg_cols(1),
145
 
  const_item_cache(false)
 
65
  allowed_arg_cols(1)
146
66
{
147
67
  collation.set(DERIVATION_SYSCONST);
148
68
  set_arguments(list);
163
83
      args= tmp_arg;
164
84
    else
165
85
    {
166
 
      if (!(args=(Item**) session->getMemRoot()->allocate(sizeof(Item*)*arg_count)))
 
86
      if (!(args=(Item**) session->alloc(sizeof(Item*)*arg_count)))
167
87
        return;
168
88
    }
169
89
    memcpy(args, item->args, sizeof(Item*)*arg_count);
214
134
  unsigned char buff[STACK_BUFF_ALLOC];      // Max argument in function
215
135
  session->session_marker= 0;
216
136
  used_tables_cache= not_null_tables_cache= 0;
217
 
  const_item_cache= true;
 
137
  const_item_cache=1;
218
138
 
219
139
  if (check_stack_overrun(session, STACK_MIN_SIZE, buff))
220
140
    return true;        // Fatal error if flag is set!
269
189
  Item **arg,**arg_end;
270
190
 
271
191
  used_tables_cache= not_null_tables_cache= 0;
272
 
  const_item_cache= false;
 
192
  const_item_cache=1;
273
193
 
274
194
  if (arg_count)
275
195
  {
434
354
void Item_func::update_used_tables()
435
355
{
436
356
  used_tables_cache=0;
437
 
  const_item_cache= true;
 
357
  const_item_cache=1;
438
358
  for (uint32_t i=0 ; i < arg_count ; i++)
439
359
  {
440
360
    args[i]->update_used_tables();
514
434
}
515
435
 
516
436
 
517
 
bool Item_func::get_arg0_date(type::Time &ltime, uint32_t fuzzy_date)
 
437
bool Item_func::get_arg0_date(type::Time *ltime, uint32_t fuzzy_date)
518
438
{
519
439
  return (null_value=args[0]->get_date(ltime, fuzzy_date));
520
440
}
521
441
 
522
442
 
523
 
bool Item_func::get_arg0_time(type::Time &ltime)
 
443
bool Item_func::get_arg0_time(type::Time *ltime)
524
444
{
525
445
  return (null_value= args[0]->get_time(ltime));
526
446
}