~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/func.cc

  • Committer: Olaf van der Spek
  • Date: 2011-07-04 19:11:47 UTC
  • mto: This revision was merged to the branch mainline in revision 2367.
  • Revision ID: olafvdspek@gmail.com-20110704191147-s99ojek811zi1fzj
Remove unused Name_resolution_context::error_reporter

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/sql_string.h>
23
 
#include <drizzled/sql_list.h>
24
 
 
25
 
#include <drizzled/function/math/int.h>
 
20
#include <config.h>
 
21
 
 
22
#include <drizzled/check_stack_overrun.h>
 
23
#include <drizzled/current_session.h>
 
24
#include <drizzled/error.h>
 
25
#include <drizzled/field/decimal.h>
 
26
#include <drizzled/field/double.h>
26
27
#include <drizzled/field/int32.h>
27
28
#include <drizzled/field/int64.h>
28
 
#include <drizzled/field/decimal.h>
29
 
#include <drizzled/field/double.h>
30
29
#include <drizzled/field/size.h>
 
30
#include <drizzled/function/math/int.h>
 
31
#include <drizzled/item/field.h>
31
32
#include <drizzled/session.h>
32
 
#include <drizzled/error.h>
33
 
#include <drizzled/check_stack_overrun.h>
 
33
#include <drizzled/sql_list.h>
 
34
#include <drizzled/sql_string.h>
 
35
 
34
36
#include <limits>
35
37
#include <algorithm>
36
38
 
40
42
{
41
43
 
42
44
 
 
45
Item_func::Item_func(void):
 
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
  allowed_arg_cols(1), arg_count(1),
 
55
  const_item_cache(false)
 
56
  {
 
57
    args= tmp_arg;
 
58
    args[0]= a;
 
59
    with_sum_func= a->with_sum_func;
 
60
    collation.set(DERIVATION_SYSCONST);
 
61
  }
 
62
 
 
63
Item_func::Item_func(Item *a,Item *b):
 
64
  allowed_arg_cols(1), arg_count(2),
 
65
  const_item_cache(false)
 
66
  {
 
67
    args= tmp_arg;
 
68
    args[0]= a; args[1]= b;
 
69
    with_sum_func= a->with_sum_func || b->with_sum_func;
 
70
    collation.set(DERIVATION_SYSCONST);
 
71
  }
 
72
 
 
73
Item_func::Item_func(Item *a,Item *b,Item *c):
 
74
  allowed_arg_cols(1),
 
75
  const_item_cache(false)
 
76
  {
 
77
    arg_count= 0;
 
78
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*3)))
 
79
    {
 
80
      arg_count= 3;
 
81
      args[0]= a; args[1]= b; args[2]= c;
 
82
      with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func;
 
83
    }
 
84
    collation.set(DERIVATION_SYSCONST);
 
85
  }
 
86
 
 
87
Item_func::Item_func(Item *a,Item *b,Item *c,Item *d):
 
88
  allowed_arg_cols(1),
 
89
  const_item_cache(false)
 
90
  {
 
91
    arg_count= 0;
 
92
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*4)))
 
93
    {
 
94
      arg_count= 4;
 
95
      args[0]= a; args[1]= b; args[2]= c; args[3]= d;
 
96
      with_sum_func= a->with_sum_func || b->with_sum_func ||
 
97
        c->with_sum_func || d->with_sum_func;
 
98
    }
 
99
    collation.set(DERIVATION_SYSCONST);
 
100
  }
 
101
 
 
102
Item_func::Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
 
103
  allowed_arg_cols(1),
 
104
  const_item_cache(false)
 
105
  {
 
106
    arg_count= 5;
 
107
    if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*5)))
 
108
    {
 
109
      args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
 
110
      with_sum_func= a->with_sum_func || b->with_sum_func ||
 
111
        c->with_sum_func || d->with_sum_func || e->with_sum_func ;
 
112
    }
 
113
    collation.set(DERIVATION_SYSCONST);
 
114
  }
 
115
 
 
116
 
43
117
void Item_func::set_arguments(List<Item> &list)
44
118
{
45
119
  allowed_arg_cols= 1;
46
 
  arg_count=list.elements;
 
120
  arg_count=list.size();
47
121
  args= tmp_arg;                                // If 2 arguments
48
122
  if (arg_count <= 2 || (args=(Item**) memory::sql_alloc(sizeof(Item*)*arg_count)))
49
123
  {
50
 
    List_iterator_fast<Item> li(list);
51
 
    Item *item;
 
124
    List<Item>::iterator li(list.begin());
52
125
    Item **save_args= args;
53
126
 
54
 
    while ((item=li++))
 
127
    while (Item* item=li++)
55
128
    {
56
129
      *(save_args++)= item;
57
130
      with_sum_func|=item->with_sum_func;
58
131
    }
59
132
  }
60
 
  list.empty();          // Fields are used
 
133
  list.clear();          // Fields are used
61
134
}
62
135
 
63
136
Item_func::Item_func(List<Item> &list) :
64
 
  _session(*current_session),
65
137
  allowed_arg_cols(1),
66
138
  const_item_cache(false)
67
139
{
71
143
 
72
144
Item_func::Item_func(Session *session, Item_func *item) :
73
145
  Item_result_field(session, item),
74
 
  _session(*current_session),
75
146
  allowed_arg_cols(item->allowed_arg_cols),
76
147
  arg_count(item->arg_count),
77
148
  used_tables_cache(item->used_tables_cache),
84
155
      args= tmp_arg;
85
156
    else
86
157
    {
87
 
      if (!(args=(Item**) session->getMemRoot()->allocate(sizeof(Item*)*arg_count)))
88
 
        return;
 
158
      args= new (getSession().mem) Item*[arg_count];
89
159
    }
90
160
    memcpy(args, item->args, sizeof(Item*)*arg_count);
91
161
  }
277
347
      Item *new_item= (*arg)->transform(transformer, argument);
278
348
      if (!new_item)
279
349
        return 0;
280
 
 
281
 
      /*
282
 
        Session::change_item_tree() should be called only if the tree was
283
 
        really transformed, i.e. when a new item has been created.
284
 
        Otherwise we'll be allocating a lot of unnecessary memory for
285
 
        change records at each execution.
286
 
      */
287
 
      if (*arg != new_item)
288
 
        getSession().change_item_tree(arg, new_item);
 
350
      *arg= new_item;
289
351
    }
290
352
  }
291
353
  return (this->*transformer)(argument);
333
395
      unsigned char *arg_v= *arg_p;
334
396
      Item *new_item= (*arg)->compile(analyzer, &arg_v, transformer, arg_t);
335
397
      if (new_item && *arg != new_item)
336
 
        current_session->change_item_tree(arg, new_item);
 
398
        *arg= new_item;
337
399
    }
338
400
  }
339
401
  return (this->*transformer)(arg_t);
377
439
}
378
440
 
379
441
 
380
 
void Item_func::print(String *str, enum_query_type query_type)
 
442
void Item_func::print(String *str)
381
443
{
382
444
  str->append(func_name());
383
445
  str->append('(');
384
 
  print_args(str, 0, query_type);
 
446
  print_args(str, 0);
385
447
  str->append(')');
386
448
}
387
449
 
388
450
 
389
 
void Item_func::print_args(String *str, uint32_t from, enum_query_type query_type)
 
451
void Item_func::print_args(String *str, uint32_t from)
390
452
{
391
453
  for (uint32_t i=from ; i < arg_count ; i++)
392
454
  {
393
455
    if (i != from)
394
456
      str->append(',');
395
 
    args[i]->print(str, query_type);
 
457
    args[i]->print(str);
396
458
  }
397
459
}
398
460
 
399
461
 
400
 
void Item_func::print_op(String *str, enum_query_type query_type)
 
462
void Item_func::print_op(String *str)
401
463
{
402
464
  str->append('(');
403
465
  for (uint32_t i=0 ; i < arg_count-1 ; i++)
404
466
  {
405
 
    args[i]->print(str, query_type);
 
467
    args[i]->print(str);
406
468
    str->append(' ');
407
469
    str->append(func_name());
408
470
    str->append(' ');
409
471
  }
410
 
  args[arg_count-1]->print(str, query_type);
 
472
  args[arg_count-1]->print(str);
411
473
  str->append(')');
412
474
}
413
475