~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/func.cc

  • Committer: Patrick Crews
  • Date: 2010-09-14 20:21:03 UTC
  • mto: (1771.1.1 pcrews)
  • mto: This revision was merged to the branch mainline in revision 1772.
  • Revision ID: gleebix@gmail.com-20100914202103-1db2n0bshzafep19
Moved transaction_log tests into updated non-publisher-based tree

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