~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/sum.h

Merge Nathan

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
 
#ifndef DRIZZLED_ITEM_SUM_H
21
 
#define DRIZZLED_ITEM_SUM_H
 
20
#ifndef DRIZZLED_SUM_H
 
21
#define DRIZZLED_SUM_H
22
22
 
23
23
/* classes for sum functions */
24
24
 
25
 
#include "drizzled/tree.h"
 
25
 
 
26
#include <mysys/my_tree.h>
26
27
#include <drizzled/hybrid_type.h>
27
28
#include <drizzled/item.h>
28
29
#include <drizzled/item/field.h>
29
30
#include <drizzled/item/bin_string.h>
30
 
#include <drizzled/charset_info.h>
31
 
 
32
 
namespace drizzled
33
 
{
34
 
 
 
31
 
 
32
extern "C"
35
33
int group_concat_key_cmp_with_distinct(void* arg, const void* key1,
36
34
                                       const void* key2);
37
35
 
 
36
extern "C"
38
37
int group_concat_key_cmp_with_order(void* arg, const void* key1,
39
38
                                    const void* key2);
40
39
 
41
40
class Select_Lex;
42
 
struct Order;
 
41
struct order_st;
43
42
 
44
43
/*
45
44
  Class Item_sum is the base class used for special expressions that SQL calls
416
415
  bool fix_fields(Session *, Item **);
417
416
  int64_t val_int();
418
417
  String *val_str(String*str);
419
 
  type::Decimal *val_decimal(type::Decimal *);
 
418
  my_decimal *val_decimal(my_decimal *);
420
419
  void reset_field();
421
420
};
422
421
 
429
428
  Item_sum_int(Session *session, Item_sum_int *item) :Item_sum_num(session, item) {}
430
429
  double val_real() { assert(fixed == 1); return (double) val_int(); }
431
430
  String *val_str(String*str);
432
 
  type::Decimal *val_decimal(type::Decimal *);
 
431
  my_decimal *val_decimal(my_decimal *);
433
432
  enum Item_result result_type () const { return INT_RESULT; }
434
433
  void fix_length_and_dec()
435
434
  { decimals=0; max_length=21; maybe_null=null_value=0; }
441
440
protected:
442
441
  Item_result hybrid_type;
443
442
  double sum;
444
 
  type::Decimal dec_buffs[2];
 
443
  my_decimal dec_buffs[2];
445
444
  uint32_t curr_dec_buff;
446
445
  void fix_length_and_dec();
447
446
 
454
453
  double val_real();
455
454
  int64_t val_int();
456
455
  String *val_str(String*str);
457
 
  type::Decimal *val_decimal(type::Decimal *);
 
456
  my_decimal *val_decimal(my_decimal *);
458
457
  enum Item_result result_type () const { return hybrid_type; }
459
458
  void reset_field();
460
459
  void update_field();
491
490
  void cleanup();
492
491
  bool add();
493
492
  double val_real();
494
 
  type::Decimal *val_decimal(type::Decimal *);
 
493
  my_decimal *val_decimal(my_decimal *);
495
494
  int64_t val_int();
496
495
  String *val_str(String *str);
497
496
 
657
656
  enum Type type() const { return FIELD_AVG_ITEM; }
658
657
  double val_real();
659
658
  int64_t val_int();
660
 
  type::Decimal *val_decimal(type::Decimal *);
 
659
  my_decimal *val_decimal(my_decimal *);
661
660
  bool is_null() { update_null_value(); return null_value; }
662
661
  String *val_str(String*);
663
662
  enum_field_types field_type() const
664
663
  {
665
664
    return hybrid_type == DECIMAL_RESULT ?
666
 
      DRIZZLE_TYPE_DECIMAL : DRIZZLE_TYPE_DOUBLE;
 
665
      DRIZZLE_TYPE_NEWDECIMAL : DRIZZLE_TYPE_DOUBLE;
667
666
  }
668
667
  void fix_length_and_dec() {}
669
668
  enum Item_result result_type () const { return hybrid_type; }
689
688
  double val_real();
690
689
  // In SPs we might force the "wrong" type with select into a declare variable
691
690
  int64_t val_int();
692
 
  type::Decimal *val_decimal(type::Decimal *);
 
691
  my_decimal *val_decimal(my_decimal *);
693
692
  String *val_str(String *str);
694
693
  void reset_field();
695
694
  void update_field();
724
723
  int64_t val_int();
725
724
  String *val_str(String *str)
726
725
  { return val_string_from_real(str); }
727
 
  type::Decimal *val_decimal(type::Decimal *dec_buf)
 
726
  my_decimal *val_decimal(my_decimal *dec_buf)
728
727
  { return val_decimal_from_real(dec_buf); }
729
728
  bool is_null() { update_null_value(); return null_value; }
730
729
  enum_field_types field_type() const
731
730
  {
732
731
    return hybrid_type == DECIMAL_RESULT ?
733
 
      DRIZZLE_TYPE_DECIMAL : DRIZZLE_TYPE_DOUBLE;
 
732
      DRIZZLE_TYPE_NEWDECIMAL : DRIZZLE_TYPE_DOUBLE;
734
733
  }
735
734
  void fix_length_and_dec() {}
736
735
  enum Item_result result_type () const { return hybrid_type; }
781
780
  bool add();
782
781
  double val_real();
783
782
  int64_t val_int();
784
 
  type::Decimal *val_decimal(type::Decimal *);
 
783
  my_decimal *val_decimal(my_decimal *);
785
784
  void reset_field();
786
785
  void update_field();
787
786
  Item *result_item(Field *)
807
806
  Item_std_field(Item_sum_std *item);
808
807
  enum Type type() const { return FIELD_STD_ITEM; }
809
808
  double val_real();
810
 
  type::Decimal *val_decimal(type::Decimal *);
 
809
  my_decimal *val_decimal(my_decimal *);
811
810
  enum Item_result result_type () const { return REAL_RESULT; }
812
811
  enum_field_types field_type() const { return DRIZZLE_TYPE_DOUBLE;}
813
812
};
842
841
  String value,tmp_value;
843
842
  double sum;
844
843
  int64_t sum_int;
845
 
  type::Decimal sum_dec;
 
844
  my_decimal sum_dec;
846
845
  Item_result hybrid_type;
847
846
  enum_field_types hybrid_field_type;
848
847
  int cmp_sign;
859
858
  void clear();
860
859
  double val_real();
861
860
  int64_t val_int();
862
 
  type::Decimal *val_decimal(type::Decimal *);
 
861
  my_decimal *val_decimal(my_decimal *);
863
862
  void reset_field();
864
863
  String *val_str(String *);
865
864
  bool keep_field_type(void) const { return 1; }
982
981
   */
983
982
  Unique *unique_filter;
984
983
  Table *table;
985
 
  Order **order;
 
984
  order_st **order;
986
985
  Name_resolution_context *context;
987
986
  /** The number of ORDER BY items. */
988
987
  uint32_t arg_count_order;
1004
1003
                                                const void* key2);
1005
1004
  friend int group_concat_key_cmp_with_order(void* arg, const void* key1,
1006
1005
                                             const void* key2);
1007
 
  friend int dump_leaf_key(unsigned char* key, uint32_t,
 
1006
  friend int dump_leaf_key(unsigned char* key, element_count,
1008
1007
                           Item_func_group_concat *group_concat_item);
1009
1008
 
1010
1009
public:
1033
1032
  bool fix_fields(Session *,Item **);
1034
1033
  bool setup(Session *session);
1035
1034
  void make_unique();
1036
 
  double val_real();
1037
 
  int64_t val_int();
1038
 
  type::Decimal *val_decimal(type::Decimal *decimal_value)
 
1035
  double val_real()
 
1036
  {
 
1037
    String *res;  res=val_str(&str_value);
 
1038
    return res ? my_atof(res->c_ptr()) : 0.0;
 
1039
  }
 
1040
  int64_t val_int()
 
1041
  {
 
1042
    String *res;
 
1043
    char *end_ptr;
 
1044
    int error;
 
1045
    if (!(res= val_str(&str_value)))
 
1046
      return (int64_t) 0;
 
1047
    end_ptr= (char*) res->ptr()+ res->length();
 
1048
    return my_strtoll10(res->ptr(), &end_ptr, &error);
 
1049
  }
 
1050
  my_decimal *val_decimal(my_decimal *decimal_value)
1039
1051
  {
1040
1052
    return val_decimal_from_string(decimal_value);
1041
1053
  }
1047
1059
    { context= (Name_resolution_context *)cntx; return false; }
1048
1060
};
1049
1061
 
1050
 
} /* namespace drizzled */
1051
 
 
1052
1062
#endif /* DRIZZLED_ITEM_SUM_H */