~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/functions/func.cc

  • Committer: Lee
  • Date: 2008-12-02 05:31:51 UTC
  • mto: (632.1.18 devel)
  • mto: This revision was merged to the branch mainline in revision 637.
  • Revision ID: lbieber@lbieber-desktop-20081202053151-qri9jcyrnlyym1eu
final clean up of item/func functions moving them to the functions directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#include CMATH_H
35
35
#include <drizzled/util/math.h>
36
36
#include <drizzled/session.h>
 
37
#include <drizzled/error.h>
37
38
 
38
39
#if defined(CMATH_NAMESPACE)
39
40
using namespace CMATH_NAMESPACE;
526
527
  null_value=1;
527
528
  return 0.0;
528
529
}
 
530
 
 
531
 
 
532
void Item_func::fix_num_length_and_dec()
 
533
{
 
534
  uint32_t fl_length= 0;
 
535
  decimals=0;
 
536
  for (uint32_t i=0 ; i < arg_count ; i++)
 
537
  {
 
538
    set_if_bigger(decimals,args[i]->decimals);
 
539
    set_if_bigger(fl_length, args[i]->max_length);
 
540
  }
 
541
  max_length=float_length(decimals);
 
542
  if (fl_length > max_length)
 
543
  {
 
544
    decimals= NOT_FIXED_DEC;
 
545
    max_length= float_length(NOT_FIXED_DEC);
 
546
  }
 
547
}
 
548
 
 
549
/**
 
550
  Set max_length/decimals of function if function is fixed point and
 
551
  result length/precision depends on argument ones.
 
552
*/
 
553
 
 
554
void Item_func::count_decimal_length()
 
555
{
 
556
  int max_int_part= 0;
 
557
  decimals= 0;
 
558
  unsigned_flag= 1;
 
559
  for (uint32_t i=0 ; i < arg_count ; i++)
 
560
  {
 
561
    set_if_bigger(decimals, args[i]->decimals);
 
562
    set_if_bigger(max_int_part, args[i]->decimal_int_part());
 
563
    set_if_smaller(unsigned_flag, args[i]->unsigned_flag);
 
564
  }
 
565
  int precision= cmin(max_int_part + decimals, DECIMAL_MAX_PRECISION);
 
566
  max_length= my_decimal_precision_to_length(precision, decimals,
 
567
                                             unsigned_flag);
 
568
}
 
569
 
 
570
 
 
571
/**
 
572
  Set max_length of if it is maximum length of its arguments.
 
573
*/
 
574
 
 
575
void Item_func::count_only_length()
 
576
{
 
577
  max_length= 0;
 
578
  unsigned_flag= 0;
 
579
  for (uint32_t i=0 ; i < arg_count ; i++)
 
580
  {
 
581
    set_if_bigger(max_length, args[i]->max_length);
 
582
    set_if_bigger(unsigned_flag, args[i]->unsigned_flag);
 
583
  }
 
584
}
 
585
 
 
586
 
 
587
/**
 
588
  Set max_length/decimals of function if function is floating point and
 
589
  result length/precision depends on argument ones.
 
590
*/
 
591
 
 
592
void Item_func::count_real_length()
 
593
{
 
594
  uint32_t length= 0;
 
595
  decimals= 0;
 
596
  max_length= 0;
 
597
  for (uint32_t i=0 ; i < arg_count ; i++)
 
598
  {
 
599
    if (decimals != NOT_FIXED_DEC)
 
600
    {
 
601
      set_if_bigger(decimals, args[i]->decimals);
 
602
      set_if_bigger(length, (args[i]->max_length - args[i]->decimals));
 
603
    }
 
604
    set_if_bigger(max_length, args[i]->max_length);
 
605
  }
 
606
  if (decimals != NOT_FIXED_DEC)
 
607
  {
 
608
    max_length= length;
 
609
    length+= decimals;
 
610
    if (length < max_length)  // If previous operation gave overflow
 
611
      max_length= UINT32_MAX;
 
612
    else
 
613
      max_length= length;
 
614
  }
 
615
}
 
616
 
 
617
 
 
618
 
 
619
void Item_func::signal_divide_by_null()
 
620
{
 
621
  Session *session= current_session;
 
622
  push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DIVISION_BY_ZERO, ER(ER_DIVISION_BY_ZERO));
 
623
  null_value= 1;
 
624
}
 
625
 
 
626
 
 
627
Item *Item_func::get_tmp_table_item(Session *session)
 
628
{
 
629
  if (!with_sum_func && !const_item() && functype() != SUSERVAR_FUNC)
 
630
    return new Item_field(result_field);
 
631
  return copy_or_same(session);
 
632
}
 
633
 
 
634