~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/sum.h

  • Committer: patrick crews
  • Date: 2011-06-08 03:02:27 UTC
  • mto: This revision was merged to the branch mainline in revision 2329.
  • Revision ID: gleebix@gmail.com-20110608030227-updkyv2652zvfajc
Initial voodoo worked to give us a crashme mode.  Need docs still

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
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
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
#pragma once
22
21
 
23
22
/* classes for sum functions */
24
23
 
25
 
 
26
 
#include "drizzled/tree.h"
 
24
#include <drizzled/tree.h>
27
25
#include <drizzled/hybrid_type.h>
28
26
#include <drizzled/item.h>
29
27
#include <drizzled/item/field.h>
30
28
#include <drizzled/item/bin_string.h>
31
 
 
32
 
namespace drizzled
33
 
{
34
 
 
35
 
int group_concat_key_cmp_with_distinct(void* arg, const void* key1,
36
 
                                       const void* key2);
37
 
 
38
 
int group_concat_key_cmp_with_order(void* arg, const void* key1,
39
 
                                    const void* key2);
40
 
 
41
 
class Select_Lex;
42
 
struct Order;
 
29
#include <drizzled/charset.h>
 
30
 
 
31
namespace drizzled {
 
32
 
 
33
int group_concat_key_cmp_with_distinct(void* arg, const void* key1, const void* key2);
 
34
 
 
35
int group_concat_key_cmp_with_order(void* arg, const void* key1, const void* key2);
43
36
 
44
37
/*
45
38
  Class Item_sum is the base class used for special expressions that SQL calls
366
359
    forced_const= true;
367
360
  }
368
361
  virtual bool const_item() const { return forced_const; }
 
362
  virtual bool const_during_execution() const { return false; }
369
363
  void make_field(SendField *field);
370
 
  virtual void print(String *str, enum_query_type query_type);
 
364
  virtual void print(String *str);
371
365
  void fix_num_length_and_dec();
372
366
 
373
367
  /*
416
410
  bool fix_fields(Session *, Item **);
417
411
  int64_t val_int();
418
412
  String *val_str(String*str);
419
 
  my_decimal *val_decimal(my_decimal *);
 
413
  type::Decimal *val_decimal(type::Decimal *);
420
414
  void reset_field();
421
415
};
422
416
 
429
423
  Item_sum_int(Session *session, Item_sum_int *item) :Item_sum_num(session, item) {}
430
424
  double val_real() { assert(fixed == 1); return (double) val_int(); }
431
425
  String *val_str(String*str);
432
 
  my_decimal *val_decimal(my_decimal *);
 
426
  type::Decimal *val_decimal(type::Decimal *);
433
427
  enum Item_result result_type () const { return INT_RESULT; }
434
428
  void fix_length_and_dec()
435
429
  { decimals=0; max_length=21; maybe_null=null_value=0; }
441
435
protected:
442
436
  Item_result hybrid_type;
443
437
  double sum;
444
 
  my_decimal dec_buffs[2];
 
438
  type::Decimal dec_buffs[2];
445
439
  uint32_t curr_dec_buff;
446
440
  void fix_length_and_dec();
447
441
 
454
448
  double val_real();
455
449
  int64_t val_int();
456
450
  String *val_str(String*str);
457
 
  my_decimal *val_decimal(my_decimal *);
 
451
  type::Decimal *val_decimal(type::Decimal *);
458
452
  enum Item_result result_type () const { return hybrid_type; }
459
453
  void reset_field();
460
454
  void update_field();
467
461
 
468
462
/* Common class for SUM(DISTINCT), AVG(DISTINCT) */
469
463
 
470
 
class Unique;
471
 
 
472
464
class Item_sum_distinct :public Item_sum_num
473
465
{
474
466
protected:
491
483
  void cleanup();
492
484
  bool add();
493
485
  double val_real();
494
 
  my_decimal *val_decimal(my_decimal *);
 
486
  type::Decimal *val_decimal(type::Decimal *);
495
487
  int64_t val_int();
496
488
  String *val_str(String *str);
497
489
 
576
568
};
577
569
 
578
570
 
579
 
class Tmp_Table_Param;
580
 
 
581
571
class Item_sum_count_distinct :public Item_sum_int
582
572
{
583
573
  Table *table;
644
634
 
645
635
/* Item to get the value of a stored sum function */
646
636
 
647
 
class Item_sum_avg;
648
 
 
649
637
class Item_avg_field :public Item_result_field
650
638
{
651
639
public:
657
645
  enum Type type() const { return FIELD_AVG_ITEM; }
658
646
  double val_real();
659
647
  int64_t val_int();
660
 
  my_decimal *val_decimal(my_decimal *);
 
648
  type::Decimal *val_decimal(type::Decimal *);
661
649
  bool is_null() { update_null_value(); return null_value; }
662
650
  String *val_str(String*);
663
651
  enum_field_types field_type() const
689
677
  double val_real();
690
678
  // In SPs we might force the "wrong" type with select into a declare variable
691
679
  int64_t val_int();
692
 
  my_decimal *val_decimal(my_decimal *);
 
680
  type::Decimal *val_decimal(type::Decimal *);
693
681
  String *val_str(String *str);
694
682
  void reset_field();
695
683
  void update_field();
706
694
  }
707
695
};
708
696
 
709
 
class Item_sum_variance;
710
 
 
711
697
class Item_variance_field :public Item_result_field
712
698
{
713
699
public:
724
710
  int64_t val_int();
725
711
  String *val_str(String *str)
726
712
  { return val_string_from_real(str); }
727
 
  my_decimal *val_decimal(my_decimal *dec_buf)
 
713
  type::Decimal *val_decimal(type::Decimal *dec_buf)
728
714
  { return val_decimal_from_real(dec_buf); }
729
715
  bool is_null() { update_null_value(); return null_value; }
730
716
  enum_field_types field_type() const
781
767
  bool add();
782
768
  double val_real();
783
769
  int64_t val_int();
784
 
  my_decimal *val_decimal(my_decimal *);
 
770
  type::Decimal *val_decimal(type::Decimal *);
785
771
  void reset_field();
786
772
  void update_field();
787
773
  Item *result_item(Field *)
799
785
  }
800
786
};
801
787
 
802
 
class Item_sum_std;
803
 
 
804
788
class Item_std_field :public Item_variance_field
805
789
{
806
790
public:
807
791
  Item_std_field(Item_sum_std *item);
808
792
  enum Type type() const { return FIELD_STD_ITEM; }
809
793
  double val_real();
810
 
  my_decimal *val_decimal(my_decimal *);
 
794
  type::Decimal *val_decimal(type::Decimal *);
811
795
  enum Item_result result_type () const { return REAL_RESULT; }
812
796
  enum_field_types field_type() const { return DRIZZLE_TYPE_DOUBLE;}
813
797
};
842
826
  String value,tmp_value;
843
827
  double sum;
844
828
  int64_t sum_int;
845
 
  my_decimal sum_dec;
 
829
  type::Decimal sum_dec;
846
830
  Item_result hybrid_type;
847
831
  enum_field_types hybrid_field_type;
848
832
  int cmp_sign;
859
843
  void clear();
860
844
  double val_real();
861
845
  int64_t val_int();
862
 
  my_decimal *val_decimal(my_decimal *);
 
846
  type::Decimal *val_decimal(type::Decimal *);
863
847
  void reset_field();
864
848
  String *val_str(String *);
865
849
  bool keep_field_type(void) const { return 1; }
960
944
  Item *copy_or_same(Session* session);
961
945
};
962
946
 
963
 
 
964
 
 
965
 
class DRIZZLE_ERROR;
966
 
 
967
947
class Item_func_group_concat : public Item_sum
968
948
{
969
949
  Tmp_Table_Param *tmp_table_param;
1035
1015
  void make_unique();
1036
1016
  double val_real();
1037
1017
  int64_t val_int();
1038
 
  my_decimal *val_decimal(my_decimal *decimal_value)
 
1018
  type::Decimal *val_decimal(type::Decimal *decimal_value)
1039
1019
  {
1040
1020
    return val_decimal_from_string(decimal_value);
1041
1021
  }
1042
1022
  String* val_str(String* str);
1043
1023
  Item *copy_or_same(Session* session);
1044
1024
  void no_rows_in_result() {}
1045
 
  virtual void print(String *str, enum_query_type query_type);
 
1025
  virtual void print(String *str);
1046
1026
  virtual bool change_context_processor(unsigned char *cntx)
1047
1027
    { context= (Name_resolution_context *)cntx; return false; }
1048
1028
};
1049
1029
 
1050
1030
} /* namespace drizzled */
1051
1031
 
1052
 
#endif /* DRIZZLED_ITEM_SUM_H */