~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/func.cc

  • Committer: Brian Aker
  • Date: 2010-06-28 16:17:36 UTC
  • mfrom: (1637.4.1 drizzle)
  • Revision ID: brian@gaz-20100628161736-eormhb2mnd551i2h
MergeĀ unused

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
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>
62
61
 
63
62
Item_func::Item_func(List<Item> &list) :
64
63
  _session(*current_session),
65
 
  allowed_arg_cols(1),
66
 
  const_item_cache(false)
 
64
  allowed_arg_cols(1)
67
65
{
68
 
  collation.set(DERIVATION_SYSCONST);
69
66
  set_arguments(list);
70
67
}
71
68
 
84
81
      args= tmp_arg;
85
82
    else
86
83
    {
87
 
      if (!(args=(Item**) session->getMemRoot()->allocate(sizeof(Item*)*arg_count)))
 
84
      if (!(args=(Item**) session->alloc(sizeof(Item*)*arg_count)))
88
85
        return;
89
86
    }
90
87
    memcpy(args, item->args, sizeof(Item*)*arg_count);
91
88
  }
92
 
  collation.set(DERIVATION_SYSCONST);
93
89
}
94
90
 
95
91
 
135
131
  unsigned char buff[STACK_BUFF_ALLOC];      // Max argument in function
136
132
  session->session_marker= 0;
137
133
  used_tables_cache= not_null_tables_cache= 0;
138
 
  const_item_cache= true;
 
134
  const_item_cache=1;
139
135
 
140
136
  if (check_stack_overrun(session, STACK_MIN_SIZE, buff))
141
137
    return true;        // Fatal error if flag is set!
190
186
  Item **arg,**arg_end;
191
187
 
192
188
  used_tables_cache= not_null_tables_cache= 0;
193
 
  const_item_cache= false;
 
189
  const_item_cache=1;
194
190
 
195
191
  if (arg_count)
196
192
  {
355
351
void Item_func::update_used_tables()
356
352
{
357
353
  used_tables_cache=0;
358
 
  const_item_cache= true;
 
354
  const_item_cache=1;
359
355
  for (uint32_t i=0 ; i < arg_count ; i++)
360
356
  {
361
357
    args[i]->update_used_tables();
435
431
}
436
432
 
437
433
 
438
 
bool Item_func::get_arg0_date(type::Time &ltime, uint32_t fuzzy_date)
 
434
bool Item_func::get_arg0_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date)
439
435
{
440
436
  return (null_value=args[0]->get_date(ltime, fuzzy_date));
441
437
}
442
438
 
443
439
 
444
 
bool Item_func::get_arg0_time(type::Time &ltime)
 
440
bool Item_func::get_arg0_time(DRIZZLE_TIME *ltime)
445
441
{
446
 
  return (null_value= args[0]->get_time(ltime));
 
442
  return (null_value=args[0]->get_time(ltime));
447
443
}
448
444
 
449
445
 
456
452
 
457
453
Field *Item_func::tmp_table_field(Table *table)
458
454
{
459
 
  Field *field= NULL;
 
455
  Field *field;
460
456
 
461
457
  switch (result_type()) {
462
458
  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
 
    }
 
459
    if (max_length > MY_INT32_NUM_DECIMAL_DIGITS)
 
460
      field= new Field_int64_t(max_length, maybe_null, name, unsigned_flag);
471
461
    else
472
 
    {
473
 
      field= new field::Int32(max_length, maybe_null, name, false);
474
 
    }
475
 
 
 
462
      field= new Field_long(max_length, maybe_null, name, unsigned_flag);
476
463
    break;
477
 
 
478
464
  case REAL_RESULT:
479
465
    field= new Field_double(max_length, maybe_null, name, decimals);
480
466
    break;
481
 
 
482
467
  case STRING_RESULT:
483
468
    return make_string_field(table);
484
 
 
485
469
  case DECIMAL_RESULT:
486
 
    field= new Field_decimal(class_decimal_precision_to_length(decimal_precision(),
 
470
    field= new Field_decimal(my_decimal_precision_to_length(decimal_precision(),
487
471
                                                            decimals,
488
472
                                                            unsigned_flag),
489
473
                             maybe_null,
492
476
                             unsigned_flag);
493
477
    break;
494
478
  case ROW_RESULT:
 
479
  default:
495
480
    // This case should never be chosen
496
481
    assert(0);
 
482
    field= 0;
497
483
    break;
498
484
  }
499
 
 
500
485
  if (field)
501
486
    field->init(table);
502
 
 
503
487
  return field;
504
488
}
505
489
 
506
490
 
507
 
type::Decimal *Item_func::val_decimal(type::Decimal *decimal_value)
 
491
my_decimal *Item_func::val_decimal(my_decimal *decimal_value)
508
492
{
509
493
  assert(fixed);
510
 
  int2_class_decimal(E_DEC_FATAL_ERROR, val_int(), unsigned_flag, decimal_value);
 
494
  int2my_decimal(E_DEC_FATAL_ERROR, val_int(), unsigned_flag, decimal_value);
511
495
  return decimal_value;
512
496
}
513
497
 
581
565
    set_if_smaller(unsigned_flag, args[i]->unsigned_flag);
582
566
  }
583
567
  int precision= min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
584
 
  max_length= class_decimal_precision_to_length(precision, decimals,
 
568
  max_length= my_decimal_precision_to_length(precision, decimals,
585
569
                                             unsigned_flag);
586
570
}
587
571
 
636
620
 
637
621
void Item_func::signal_divide_by_null()
638
622
{
639
 
  my_error(ER_DIVISION_BY_ZERO, MYF(0));
640
 
  null_value= 0;
 
623
  push_warning(getSessionPtr(), DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DIVISION_BY_ZERO, ER(ER_DIVISION_BY_ZERO));
 
624
  null_value= 1;
641
625
}
642
626
 
643
627