~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/func.cc

  • Committer: Brian Aker
  • Date: 2009-05-26 20:45:27 UTC
  • mto: This revision was merged to the branch mainline in revision 1040.
  • Revision ID: brian@gaz-20090526204527-27uxzwkkitgoxjaz
Bits of dead code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
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
18
18
 */
19
19
 
20
 
#include "config.h"
 
20
#include <drizzled/server_includes.h>
21
21
 
22
22
#include <drizzled/sql_string.h>
23
23
#include <drizzled/sql_list.h>
24
24
 
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>
34
33
#include <limits>
35
 
#include <algorithm>
36
34
 
37
35
using namespace std;
38
36
 
39
 
namespace drizzled
40
 
{
41
 
 
42
 
 
43
37
void Item_func::set_arguments(List<Item> &list)
44
38
{
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)))
49
43
  {
50
44
    List_iterator_fast<Item> li(list);
51
45
    Item *item;
60
54
  list.empty();          // Fields are used
61
55
}
62
56
 
63
 
Item_func::Item_func(List<Item> &list) :
64
 
  _session(*current_session),
65
 
  allowed_arg_cols(1),
66
 
  const_item_cache(false)
 
57
Item_func::Item_func(List<Item> &list)
 
58
  :allowed_arg_cols(1)
67
59
{
68
 
  collation.set(DERIVATION_SYSCONST);
69
60
  set_arguments(list);
70
61
}
71
62
 
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)
80
70
{
81
71
  if (arg_count)
82
72
  {
84
74
      args= tmp_arg;
85
75
    else
86
76
    {
87
 
      if (!(args=(Item**) session->getMemRoot()->allocate(sizeof(Item*)*arg_count)))
 
77
      if (!(args=(Item**) session->alloc(sizeof(Item*)*arg_count)))
88
78
        return;
89
79
    }
90
80
    memcpy(args, item->args, sizeof(Item*)*arg_count);
91
81
  }
92
 
  collation.set(DERIVATION_SYSCONST);
93
82
}
94
83
 
95
84
 
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;
 
127
  const_item_cache=1;
139
128
 
140
129
  if (check_stack_overrun(session, STACK_MIN_SIZE, buff))
141
130
    return true;        // Fatal error if flag is set!
149
138
        We shouldn't call fix_fields() twice, so check 'fixed' field first
150
139
      */
151
140
      if ((!(*arg)->fixed && (*arg)->fix_fields(session, arg)))
152
 
        return true;
 
141
        return true;        /* purecov: inspected */
153
142
      item= *arg;
154
143
 
155
144
      if (allowed_arg_cols)
190
179
  Item **arg,**arg_end;
191
180
 
192
181
  used_tables_cache= not_null_tables_cache= 0;
193
 
  const_item_cache= false;
 
182
  const_item_cache=1;
194
183
 
195
184
  if (arg_count)
196
185
  {
285
274
        change records at each execution.
286
275
      */
287
276
      if (*arg != new_item)
288
 
        getSession().change_item_tree(arg, new_item);
 
277
        current_session->change_item_tree(arg, new_item);
289
278
    }
290
279
  }
291
280
  return (this->*transformer)(argument);
355
344
void Item_func::update_used_tables()
356
345
{
357
346
  used_tables_cache=0;
358
 
  const_item_cache= true;
 
347
  const_item_cache=1;
359
348
  for (uint32_t i=0 ; i < arg_count ; i++)
360
349
  {
361
350
    args[i]->update_used_tables();
435
424
}
436
425
 
437
426
 
438
 
bool Item_func::get_arg0_date(type::Time &ltime, uint32_t fuzzy_date)
 
427
bool Item_func::get_arg0_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date)
439
428
{
440
429
  return (null_value=args[0]->get_date(ltime, fuzzy_date));
441
430
}
442
431
 
443
432
 
444
 
bool Item_func::get_arg0_time(type::Time &ltime)
 
433
bool Item_func::get_arg0_time(DRIZZLE_TIME *ltime)
445
434
{
446
 
  return (null_value= args[0]->get_time(ltime));
 
435
  return (null_value=args[0]->get_time(ltime));
447
436
}
448
437
 
449
438
 
456
445
 
457
446
Field *Item_func::tmp_table_field(Table *table)
458
447
{
459
 
  Field *field= NULL;
 
448
  Field *field;
460
449
 
461
450
  switch (result_type()) {
462
451
  case INT_RESULT:
463
 
    if (unsigned_flag)
464
 
    {
465
 
      field= new field::Size(max_length, maybe_null, name, true);
466
 
    } 
467
 
    else if (max_length > MY_INT32_NUM_DECIMAL_DIGITS)
468
 
    {
469
 
      field= new field::Int64(max_length, maybe_null, name, false);
470
 
    }
 
452
    if (max_length > MY_INT32_NUM_DECIMAL_DIGITS)
 
453
      field= new Field_int64_t(max_length, maybe_null, name, unsigned_flag);
471
454
    else
472
 
    {
473
 
      field= new field::Int32(max_length, maybe_null, name, false);
474
 
    }
475
 
 
 
455
      field= new Field_long(max_length, maybe_null, name, unsigned_flag);
476
456
    break;
477
 
 
478
457
  case REAL_RESULT:
479
458
    field= new Field_double(max_length, maybe_null, name, decimals);
480
459
    break;
481
 
 
482
460
  case STRING_RESULT:
483
461
    return make_string_field(table);
484
 
 
485
462
  case DECIMAL_RESULT:
486
 
    field= new Field_decimal(class_decimal_precision_to_length(decimal_precision(),
487
 
                                                            decimals,
488
 
                                                            unsigned_flag),
489
 
                             maybe_null,
490
 
                             name,
491
 
                             decimals,
492
 
                             unsigned_flag);
 
463
    field= new Field_new_decimal(
 
464
                       my_decimal_precision_to_length(decimal_precision(),
 
465
                                                      decimals,
 
466
                                                      unsigned_flag),
 
467
                       maybe_null, name, decimals, unsigned_flag);
493
468
    break;
494
469
  case ROW_RESULT:
 
470
  default:
495
471
    // This case should never be chosen
496
472
    assert(0);
 
473
    field= 0;
497
474
    break;
498
475
  }
499
 
 
500
476
  if (field)
501
477
    field->init(table);
502
 
 
503
478
  return field;
504
479
}
505
480
 
506
481
 
507
 
type::Decimal *Item_func::val_decimal(type::Decimal *decimal_value)
 
482
my_decimal *Item_func::val_decimal(my_decimal *decimal_value)
508
483
{
509
484
  assert(fixed);
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;
512
487
}
513
488
 
574
549
  int max_int_part= 0;
575
550
  decimals= 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++)
578
553
  {
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);
582
557
  }
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,
585
560
                                             unsigned_flag);
586
561
}
587
562
 
636
611
 
637
612
void Item_func::signal_divide_by_null()
638
613
{
639
 
  my_error(ER_DIVISION_BY_ZERO, MYF(0));
640
 
  null_value= 0;
 
614
  Session *session= current_session;
 
615
  push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DIVISION_BY_ZERO, ER(ER_DIVISION_BY_ZERO));
 
616
  null_value= 1;
641
617
}
642
618
 
643
619
 
649
625
}
650
626
 
651
627
 
652
 
} /* namespace drizzled */