~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.h

move functions from item.cc/item.h to item directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
591
591
#include <drizzled/item/basic_constant.h>
592
592
#include <drizzled/item/bin_string.h>
593
593
#include <drizzled/item/blob.h>
 
594
#include <drizzled/item/copy_string.h>
594
595
#include <drizzled/item/ident.h>
595
596
#include <drizzled/item/decimal.h>
 
597
#include <drizzled/item/direct_ref.h>
596
598
#include <drizzled/item/empty_string.h>
597
599
#include <drizzled/item/field.h>
598
600
#include <drizzled/item/hex_string.h>
599
601
#include <drizzled/item/ifloat.h>
600
602
#include <drizzled/item/istring.h>
601
603
#include <drizzled/item/int.h>
 
604
#include <drizzled/item/int_with_ref.h>
602
605
#include <drizzled/item/null.h>
603
606
#include <drizzled/item/num.h>
 
607
#include <drizzled/item/outer_ref.h>
604
608
#include <drizzled/item/param.h>
605
609
#include <drizzled/item/ref.h>
 
610
#include <drizzled/item/ref_null_helper.h>
606
611
#include <drizzled/item/return_date_time.h>
607
612
#include <drizzled/item/return_int.h>
608
613
#include <drizzled/item/uint.h>
618
623
                                       st_select_lex *select);
619
624
 
620
625
 
621
 
/*
622
 
  The same as Item_ref, but get value from val_* family of method to get
623
 
  value of item on which it referred instead of result* family.
624
 
*/
625
 
class Item_direct_ref :public Item_ref
626
 
{
627
 
public:
628
 
  Item_direct_ref(Name_resolution_context *context_arg, Item **item,
629
 
                  const char *table_name_arg,
630
 
                  const char *field_name_arg,
631
 
                  bool alias_name_used_arg= false)
632
 
    :Item_ref(context_arg, item, table_name_arg,
633
 
              field_name_arg, alias_name_used_arg)
634
 
  {}
635
 
  /* Constructor need to process subselect with temporary tables (see Item) */
636
 
  Item_direct_ref(Session *session, Item_direct_ref *item) : Item_ref(session, item) {}
637
 
 
638
 
  double val_real();
639
 
  int64_t val_int();
640
 
  String *val_str(String* tmp);
641
 
  my_decimal *val_decimal(my_decimal *);
642
 
  bool val_bool();
643
 
  bool is_null();
644
 
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
645
 
  virtual Ref_Type ref_type() { return DIRECT_REF; }
646
 
};
647
 
 
648
 
/*
649
 
  Class for outer fields.
650
 
  An object of this class is created when the select where the outer field was
651
 
  resolved is a grouping one. After it has been fixed the ref field will point
652
 
  to either an Item_ref or an Item_direct_ref object which will be used to
653
 
  access the field.
654
 
  See also comments for the fix_inner_refs() and the
655
 
  Item_field::fix_outer_field() functions.
656
 
*/
657
 
 
658
 
class Item_outer_ref :public Item_direct_ref
659
 
{
660
 
public:
661
 
  Item *outer_ref;
662
 
  /* The aggregate function under which this outer ref is used, if any. */
663
 
  Item_sum *in_sum_func;
664
 
  /*
665
 
    true <=> that the outer_ref is already present in the select list
666
 
    of the outer select.
667
 
  */
668
 
  bool found_in_select_list;
669
 
  Item_outer_ref(Name_resolution_context *context_arg,
670
 
                 Item_field *outer_field_arg)
671
 
    :Item_direct_ref(context_arg, 0, outer_field_arg->table_name,
672
 
                     outer_field_arg->field_name),
673
 
    outer_ref(outer_field_arg), in_sum_func(0),
674
 
    found_in_select_list(0)
675
 
  {
676
 
    ref= &outer_ref;
677
 
    set_properties();
678
 
    fixed= 0;
679
 
  }
680
 
  Item_outer_ref(Name_resolution_context *context_arg, Item **item,
681
 
                 const char *table_name_arg, const char *field_name_arg,
682
 
                 bool alias_name_used_arg)
683
 
    :Item_direct_ref(context_arg, item, table_name_arg, field_name_arg,
684
 
                     alias_name_used_arg),
685
 
    outer_ref(0), in_sum_func(0), found_in_select_list(1)
686
 
  {}
687
 
  void save_in_result_field(bool)
688
 
  {
689
 
    outer_ref->save_org_in_field(result_field);
690
 
  }
691
 
  bool fix_fields(Session *, Item **);
692
 
  void fix_after_pullout(st_select_lex *new_parent, Item **ref);
693
 
  table_map used_tables() const
694
 
  {
695
 
    return (*ref)->const_item() ? 0 : OUTER_REF_TABLE_BIT;
696
 
  }
697
 
  virtual Ref_Type ref_type() { return OUTER_REF; }
698
 
};
699
 
 
700
 
 
701
 
 
702
 
/*
703
 
  An object of this class:
704
 
   - Converts val_XXX() calls to ref->val_XXX_result() calls, like Item_ref.
705
 
   - Sets owner->was_null=true if it has returned a NULL value from any
706
 
     val_XXX() function. This allows to inject an Item_ref_null_helper
707
 
     object into subquery and then check if the subquery has produced a row
708
 
     with NULL value.
709
 
*/
710
 
 
711
 
class Item_ref_null_helper: public Item_ref
712
 
{
713
 
protected:
714
 
  Item_in_subselect* owner;
715
 
public:
716
 
  Item_ref_null_helper(Name_resolution_context *context_arg,
717
 
                       Item_in_subselect* master, Item **item,
718
 
                       const char *table_name_arg, const char *field_name_arg)
719
 
    :Item_ref(context_arg, item, table_name_arg, field_name_arg),
720
 
     owner(master) {}
721
 
  double val_real();
722
 
  int64_t val_int();
723
 
  String* val_str(String* s);
724
 
  my_decimal *val_decimal(my_decimal *);
725
 
  bool val_bool();
726
 
  bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate);
727
 
  virtual void print(String *str, enum_query_type query_type);
728
 
  /*
729
 
    we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
730
 
  */
731
 
  table_map used_tables() const
732
 
  {
733
 
    return (depended_from ?
734
 
            OUTER_REF_TABLE_BIT :
735
 
            (*ref)->used_tables() | RAND_TABLE_BIT);
736
 
  }
737
 
};
738
 
 
739
 
/*
740
 
  The following class is used to optimize comparing of date and bigint columns
741
 
  We need to save the original item ('ref') to be able to call
742
 
  ref->save_in_field(). This is used to create index search keys.
743
 
 
744
 
  An instance of Item_int_with_ref may have signed or unsigned integer value.
745
 
 
746
 
*/
747
 
 
748
 
class Item_int_with_ref :public Item_int
749
 
{
750
 
  Item *ref;
751
 
public:
752
 
  Item_int_with_ref(int64_t i, Item *ref_arg, bool unsigned_arg) :
753
 
    Item_int(i), ref(ref_arg)
754
 
  {
755
 
    unsigned_flag= unsigned_arg;
756
 
  }
757
 
  int save_in_field(Field *field, bool no_conversions)
758
 
  {
759
 
    return ref->save_in_field(field, no_conversions);
760
 
  }
761
 
  Item *clone_item();
762
 
  virtual Item *real_item() { return ref; }
763
 
};
764
 
 
765
 
 
766
 
class Item_copy_string :public Item
767
 
{
768
 
  enum enum_field_types cached_field_type;
769
 
public:
770
 
  Item *item;
771
 
  Item_copy_string(Item *i) :item(i)
772
 
  {
773
 
    null_value= maybe_null= item->maybe_null;
774
 
    decimals=item->decimals;
775
 
    max_length=item->max_length;
776
 
    name=item->name;
777
 
    cached_field_type= item->field_type();
778
 
  }
779
 
  enum Type type() const { return COPY_STR_ITEM; }
780
 
  enum Item_result result_type () const { return STRING_RESULT; }
781
 
  enum_field_types field_type() const { return cached_field_type; }
782
 
  double val_real()
783
 
  {
784
 
    int err_not_used;
785
 
    char *end_not_used;
786
 
    return (null_value ? 0.0 :
787
 
            my_strntod(str_value.charset(), (char*) str_value.ptr(),
788
 
                       str_value.length(), &end_not_used, &err_not_used));
789
 
  }
790
 
  int64_t val_int()
791
 
  {
792
 
    int err;
793
 
    return null_value ? 0 : my_strntoll(str_value.charset(),str_value.ptr(),
794
 
                                        str_value.length(),10, (char**) 0,
795
 
                                        &err);
796
 
  }
797
 
  String *val_str(String*);
798
 
  my_decimal *val_decimal(my_decimal *);
799
 
  void make_field(Send_field *field) { item->make_field(field); }
800
 
  void copy();
801
 
  int save_in_field(Field *field, bool)
802
 
  {
803
 
    return save_str_value_in_field(field, &str_value);
804
 
  }
805
 
  table_map used_tables() const { return (table_map) 1L; }
806
 
  bool const_item() const { return 0; }
807
 
  bool is_null() { return null_value; }
808
 
};
809
 
class Item_default_value : public Item_field
810
 
{
811
 
public:
812
 
  Item *arg;
813
 
  Item_default_value(Name_resolution_context *context_arg)
814
 
    :Item_field(context_arg, (const char *)NULL, (const char *)NULL,
815
 
               (const char *)NULL),
816
 
     arg(NULL) {}
817
 
  Item_default_value(Name_resolution_context *context_arg, Item *a)
818
 
    :Item_field(context_arg, (const char *)NULL, (const char *)NULL,
819
 
                (const char *)NULL),
820
 
     arg(a) {}
821
 
  enum Type type() const { return DEFAULT_VALUE_ITEM; }
822
 
  bool eq(const Item *item, bool binary_cmp) const;
823
 
  bool fix_fields(Session *, Item **);
824
 
  virtual void print(String *str, enum_query_type query_type);
825
 
  int save_in_field(Field *field_arg, bool no_conversions);
826
 
  table_map used_tables() const { return (table_map)0L; }
827
 
 
828
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
829
 
  {
830
 
    return arg->walk(processor, walk_subquery, args) ||
831
 
      (this->*processor)(args);
832
 
  }
833
 
 
834
 
  Item *transform(Item_transformer transformer, unsigned char *args);
835
 
};
836
626
 
837
627
/*
838
628
  Item_insert_value -- an implementation of VALUES() function.