~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:
589
589
};
590
590
 
591
591
#include <drizzled/item/basic_constant.h>
 
592
#include <drizzled/item/bin_string.h>
 
593
#include <drizzled/item/blob.h>
592
594
#include <drizzled/item/ident.h>
593
595
#include <drizzled/item/decimal.h>
 
596
#include <drizzled/item/empty_string.h>
594
597
#include <drizzled/item/field.h>
 
598
#include <drizzled/item/hex_string.h>
595
599
#include <drizzled/item/ifloat.h>
596
600
#include <drizzled/item/istring.h>
597
601
#include <drizzled/item/int.h>
598
602
#include <drizzled/item/null.h>
599
603
#include <drizzled/item/num.h>
600
604
#include <drizzled/item/param.h>
 
605
#include <drizzled/item/ref.h>
601
606
#include <drizzled/item/return_date_time.h>
 
607
#include <drizzled/item/return_int.h>
602
608
#include <drizzled/item/uint.h>
603
609
 
604
610
void mark_as_dependent(Session *session,
612
618
                                       st_select_lex *select);
613
619
 
614
620
 
615
 
class Item_blob :public Item_string
616
 
{
617
 
public:
618
 
  Item_blob(const char *name, uint32_t length) :
619
 
    Item_string(name, length, &my_charset_bin)
620
 
  { max_length= length; }
621
 
  enum Type type() const { return TYPE_HOLDER; }
622
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_BLOB; }
623
 
};
624
 
 
625
 
 
626
 
/**
627
 
  Item_empty_string -- is a utility class to put an item into List<Item>
628
 
  which is then used in protocol.send_fields() when sending SHOW output to
629
 
  the client.
630
 
*/
631
 
 
632
 
class Item_empty_string :public Item_string
633
 
{
634
 
public:
635
 
  Item_empty_string(const char *header,uint32_t length, const CHARSET_INFO * cs= NULL) :
636
 
    Item_string("",0, cs ? cs : &my_charset_utf8_general_ci)
637
 
    { name=(char*) header; max_length= cs ? length * cs->mbmaxlen : length; }
638
 
  void make_field(Send_field *field);
639
 
};
640
 
 
641
 
 
642
 
class Item_return_int :public Item_int
643
 
{
644
 
  enum_field_types int_field_type;
645
 
public:
646
 
  Item_return_int(const char *name_arg, uint32_t length,
647
 
                  enum_field_types field_type_arg, int64_t value= 0)
648
 
    :Item_int(name_arg, value, length), int_field_type(field_type_arg)
649
 
  {
650
 
    unsigned_flag=1;
651
 
  }
652
 
  enum_field_types field_type() const { return int_field_type; }
653
 
};
654
 
 
655
 
 
656
 
class Item_hex_string: public Item_basic_constant
657
 
{
658
 
public:
659
 
  Item_hex_string() {}
660
 
  Item_hex_string(const char *str,uint32_t str_length);
661
 
  enum Type type() const { return VARBIN_ITEM; }
662
 
  double val_real()
663
 
  {
664
 
    assert(fixed == 1);
665
 
    return (double) (uint64_t) Item_hex_string::val_int();
666
 
  }
667
 
  int64_t val_int();
668
 
  bool basic_const_item() const { return 1; }
669
 
  String *val_str(String*) { assert(fixed == 1); return &str_value; }
670
 
  my_decimal *val_decimal(my_decimal *);
671
 
  int save_in_field(Field *field, bool no_conversions);
672
 
  enum Item_result result_type () const { return STRING_RESULT; }
673
 
  enum Item_result cast_to_int_type() const { return INT_RESULT; }
674
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
675
 
  virtual void print(String *str, enum_query_type query_type);
676
 
  bool eq(const Item *item, bool binary_cmp) const;
677
 
  virtual Item *safe_charset_converter(const CHARSET_INFO * const tocs);
678
 
  bool check_vcol_func_processor(unsigned char *)
679
 
  { return false; }
680
 
};
681
 
 
682
 
 
683
 
class Item_bin_string: public Item_hex_string
684
 
{
685
 
public:
686
 
  Item_bin_string(const char *str,uint32_t str_length);
687
 
};
688
 
 
689
 
class Item_result_field :public Item    /* Item with result field */
690
 
{
691
 
public:
692
 
  Field *result_field;                          /* Save result here */
693
 
  Item_result_field() :result_field(0) {}
694
 
  // Constructor used for Item_sum/Item_cond_and/or (see Item comment)
695
 
  Item_result_field(Session *session, Item_result_field *item):
696
 
    Item(session, item), result_field(item->result_field)
697
 
  {}
698
 
  ~Item_result_field() {}                       /* Required with gcc 2.95 */
699
 
  Field *get_tmp_table_field() { return result_field; }
700
 
  Field *tmp_table_field(Table *)
701
 
  { return result_field; }
702
 
  table_map used_tables() const { return 1; }
703
 
  virtual void fix_length_and_dec()=0;
704
 
  void set_result_field(Field *field) { result_field= field; }
705
 
  bool is_result_field() { return 1; }
706
 
  void save_in_result_field(bool no_conversions)
707
 
  {
708
 
    save_in_field(result_field, no_conversions);
709
 
  }
710
 
  void cleanup();
711
 
  bool check_vcol_func_processor(unsigned char *)
712
 
  { return false; }
713
 
};
714
 
 
715
 
 
716
 
class Item_ref :public Item_ident
717
 
{
718
 
protected:
719
 
  void set_properties();
720
 
public:
721
 
  enum Ref_Type { REF, DIRECT_REF, OUTER_REF };
722
 
  Field *result_field;                   /* Save result here */
723
 
  Item **ref;
724
 
  Item_ref(Name_resolution_context *context_arg,
725
 
           const char *db_arg, const char *table_name_arg,
726
 
           const char *field_name_arg)
727
 
    :Item_ident(context_arg, db_arg, table_name_arg, field_name_arg),
728
 
     result_field(0), ref(0) {}
729
 
  /*
730
 
    This constructor is used in two scenarios:
731
 
    A) *item = NULL
732
 
      No initialization is performed, fix_fields() call will be necessary.
733
 
 
734
 
    B) *item points to an Item this Item_ref will refer to. This is
735
 
      used for GROUP BY. fix_fields() will not be called in this case,
736
 
      so we call set_properties to make this item "fixed". set_properties
737
 
      performs a subset of action Item_ref::fix_fields does, and this subset
738
 
      is enough for Item_ref's used in GROUP BY.
739
 
 
740
 
    TODO we probably fix a superset of problems like in BUG#6658. Check this
741
 
         with Bar, and if we have a more broader set of problems like this.
742
 
  */
743
 
  Item_ref(Name_resolution_context *context_arg, Item **item,
744
 
           const char *table_name_arg, const char *field_name_arg,
745
 
           bool alias_name_used_arg= false);
746
 
 
747
 
  /* Constructor need to process subselect with temporary tables (see Item) */
748
 
  Item_ref(Session *session, Item_ref *item)
749
 
    :Item_ident(session, item), result_field(item->result_field), ref(item->ref) {}
750
 
  enum Type type() const                { return REF_ITEM; }
751
 
  bool eq(const Item *item, bool binary_cmp) const
752
 
  {
753
 
    Item *it= ((Item *) item)->real_item();
754
 
    return ref && (*ref)->eq(it, binary_cmp);
755
 
  }
756
 
  double val_real();
757
 
  int64_t val_int();
758
 
  my_decimal *val_decimal(my_decimal *);
759
 
  bool val_bool();
760
 
  String *val_str(String* tmp);
761
 
  bool is_null();
762
 
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
763
 
  double val_result();
764
 
  int64_t val_int_result();
765
 
  String *str_result(String* tmp);
766
 
  my_decimal *val_decimal_result(my_decimal *);
767
 
  bool val_bool_result();
768
 
  bool send(Protocol *prot, String *tmp);
769
 
  void make_field(Send_field *field);
770
 
  bool fix_fields(Session *, Item **);
771
 
  void fix_after_pullout(st_select_lex *new_parent, Item **ref);
772
 
  int save_in_field(Field *field, bool no_conversions);
773
 
  void save_org_in_field(Field *field);
774
 
  enum Item_result result_type () const { return (*ref)->result_type(); }
775
 
  enum_field_types field_type() const   { return (*ref)->field_type(); }
776
 
  Field *get_tmp_table_field()
777
 
  { return result_field ? result_field : (*ref)->get_tmp_table_field(); }
778
 
  Item *get_tmp_table_item(Session *session);
779
 
  table_map used_tables() const
780
 
  {
781
 
    return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();
782
 
  }
783
 
  void update_used_tables()
784
 
  {
785
 
    if (!depended_from)
786
 
      (*ref)->update_used_tables();
787
 
  }
788
 
  table_map not_null_tables() const { return (*ref)->not_null_tables(); }
789
 
  void set_result_field(Field *field)   { result_field= field; }
790
 
  bool is_result_field() { return 1; }
791
 
  void save_in_result_field(bool no_conversions)
792
 
  {
793
 
    (*ref)->save_in_field(result_field, no_conversions);
794
 
  }
795
 
  Item *real_item()
796
 
  {
797
 
    return ref ? (*ref)->real_item() : this;
798
 
  }
799
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
800
 
  { return (*ref)->walk(processor, walk_subquery, arg); }
801
 
  virtual void print(String *str, enum_query_type query_type);
802
 
  bool result_as_int64_t()
803
 
  {
804
 
    return (*ref)->result_as_int64_t();
805
 
  }
806
 
  void cleanup();
807
 
  Item_field *filed_for_view_update()
808
 
    { return (*ref)->filed_for_view_update(); }
809
 
  virtual Ref_Type ref_type() { return REF; }
810
 
 
811
 
  // Row emulation: forwarding of ROW-related calls to ref
812
 
  uint32_t cols()
813
 
  {
814
 
    return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
815
 
  }
816
 
  Item* element_index(uint32_t i)
817
 
  {
818
 
    return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
819
 
  }
820
 
  Item** addr(uint32_t i)
821
 
  {
822
 
    return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
823
 
  }
824
 
  bool check_cols(uint32_t c)
825
 
  {
826
 
    return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
827
 
                                              : Item::check_cols(c);
828
 
  }
829
 
  bool null_inside()
830
 
  {
831
 
    return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0;
832
 
  }
833
 
  void bring_value()
834
 
  {
835
 
    if (ref && result_type() == ROW_RESULT)
836
 
      (*ref)->bring_value();
837
 
  }
838
 
 
839
 
};
840
 
 
841
 
 
842
621
/*
843
622
  The same as Item_ref, but get value from val_* family of method to get
844
623
  value of item on which it referred instead of result* family.