~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/cache.h>
594
595
#include <drizzled/item/copy_string.h>
595
596
#include <drizzled/item/ident.h>
596
597
#include <drizzled/item/decimal.h>
623
624
                                       st_select_lex *select);
624
625
 
625
626
 
626
 
 
627
 
/*
628
 
  Item_insert_value -- an implementation of VALUES() function.
629
 
  You can use the VALUES(col_name) function in the UPDATE clause
630
 
  to refer to column values from the INSERT portion of the INSERT
631
 
  ... UPDATE statement. In other words, VALUES(col_name) in the
632
 
  UPDATE clause refers to the value of col_name that would be
633
 
  inserted, had no duplicate-key conflict occurred.
634
 
  In all other places this function returns NULL.
635
 
*/
636
 
 
637
 
class Item_insert_value : public Item_field
638
 
{
639
 
public:
640
 
  Item *arg;
641
 
  Item_insert_value(Name_resolution_context *context_arg, Item *a)
642
 
    :Item_field(context_arg, (const char *)NULL, (const char *)NULL,
643
 
               (const char *)NULL),
644
 
     arg(a) {}
645
 
  bool eq(const Item *item, bool binary_cmp) const;
646
 
  bool fix_fields(Session *, Item **);
647
 
  virtual void print(String *str, enum_query_type query_type);
648
 
  int save_in_field(Field *field_arg, bool no_conversions)
649
 
  {
650
 
    return Item_field::save_in_field(field_arg, no_conversions);
651
 
  }
652
 
  /*
653
 
   We use RAND_TABLE_BIT to prevent Item_insert_value from
654
 
   being treated as a constant and precalculated before execution
655
 
  */
656
 
  table_map used_tables() const { return RAND_TABLE_BIT; }
657
 
 
658
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
659
 
  {
660
 
    return arg->walk(processor, walk_subquery, args) ||
661
 
            (this->*processor)(args);
662
 
  }
663
 
  bool check_vcol_func_processor(unsigned char *)
664
 
  { return true; }
665
 
};
666
 
 
667
 
 
668
 
class Item_cache: public Item_basic_constant
669
 
{
670
 
protected:
671
 
  Item *example;
672
 
  table_map used_table_map;
673
 
  /*
674
 
    Field that this object will get value from. This is set/used by
675
 
    index-based subquery engines to detect and remove the equality injected
676
 
    by IN->EXISTS transformation.
677
 
    For all other uses of Item_cache, cached_field doesn't matter.
678
 
  */
679
 
  Field *cached_field;
680
 
  enum enum_field_types cached_field_type;
681
 
public:
682
 
  Item_cache():
683
 
    example(0), used_table_map(0), cached_field(0), cached_field_type(DRIZZLE_TYPE_VARCHAR)
684
 
  {
685
 
    fixed= 1;
686
 
    null_value= 1;
687
 
  }
688
 
  Item_cache(enum_field_types field_type_arg):
689
 
    example(0), used_table_map(0), cached_field(0), cached_field_type(field_type_arg)
690
 
  {
691
 
    fixed= 1;
692
 
    null_value= 1;
693
 
  }
694
 
 
695
 
  void set_used_tables(table_map map) { used_table_map= map; }
696
 
 
697
 
  virtual bool allocate(uint32_t)
698
 
  { return 0; }
699
 
  virtual bool setup(Item *item)
700
 
  {
701
 
    example= item;
702
 
    max_length= item->max_length;
703
 
    decimals= item->decimals;
704
 
    collation.set(item->collation);
705
 
    unsigned_flag= item->unsigned_flag;
706
 
    if (item->type() == FIELD_ITEM)
707
 
      cached_field= ((Item_field *)item)->field;
708
 
    return 0;
709
 
  };
710
 
  virtual void store(Item *)= 0;
711
 
  enum Type type() const { return CACHE_ITEM; }
712
 
  enum_field_types field_type() const { return cached_field_type; }
713
 
  static Item_cache* get_cache(const Item *item);
714
 
  table_map used_tables() const { return used_table_map; }
715
 
  virtual void keep_array() {}
716
 
  virtual void print(String *str, enum_query_type query_type);
717
 
  bool eq_def(Field *field);
718
 
  bool eq(const Item *item, bool) const
719
 
  {
720
 
    return this == item;
721
 
  }
722
 
};
723
 
 
724
 
 
725
 
class Item_cache_int: public Item_cache
726
 
{
727
 
protected:
728
 
  int64_t value;
729
 
public:
730
 
  Item_cache_int(): Item_cache(), value(0) {}
731
 
  Item_cache_int(enum_field_types field_type_arg):
732
 
    Item_cache(field_type_arg), value(0) {}
733
 
 
734
 
  void store(Item *item);
735
 
  void store(Item *item, int64_t val_arg);
736
 
  double val_real() { assert(fixed == 1); return (double) value; }
737
 
  int64_t val_int() { assert(fixed == 1); return value; }
738
 
  String* val_str(String *str);
739
 
  my_decimal *val_decimal(my_decimal *);
740
 
  enum Item_result result_type() const { return INT_RESULT; }
741
 
  bool result_as_int64_t() { return true; }
742
 
};
743
 
 
744
 
 
745
 
class Item_cache_real: public Item_cache
746
 
{
747
 
  double value;
748
 
public:
749
 
  Item_cache_real(): Item_cache(), value(0) {}
750
 
 
751
 
  void store(Item *item);
752
 
  double val_real() { assert(fixed == 1); return value; }
753
 
  int64_t val_int();
754
 
  String* val_str(String *str);
755
 
  my_decimal *val_decimal(my_decimal *);
756
 
  enum Item_result result_type() const { return REAL_RESULT; }
757
 
};
758
 
 
759
 
 
760
 
class Item_cache_decimal: public Item_cache
761
 
{
762
 
protected:
763
 
  my_decimal decimal_value;
764
 
public:
765
 
  Item_cache_decimal(): Item_cache() {}
766
 
 
767
 
  void store(Item *item);
768
 
  double val_real();
769
 
  int64_t val_int();
770
 
  String* val_str(String *str);
771
 
  my_decimal *val_decimal(my_decimal *);
772
 
  enum Item_result result_type() const { return DECIMAL_RESULT; }
773
 
};
774
 
 
775
 
 
776
 
class Item_cache_str: public Item_cache
777
 
{
778
 
  char buffer[STRING_BUFFER_USUAL_SIZE];
779
 
  String *value, value_buff;
780
 
  bool is_varbinary;
781
 
 
782
 
public:
783
 
  Item_cache_str(const Item *item);
784
 
  void store(Item *item);
785
 
  double val_real();
786
 
  int64_t val_int();
787
 
  String* val_str(String *) { assert(fixed == 1); return value; }
788
 
  my_decimal *val_decimal(my_decimal *);
789
 
  enum Item_result result_type() const { return STRING_RESULT; }
790
 
  const CHARSET_INFO *charset() const { return value->charset(); };
791
 
  int save_in_field(Field *field, bool no_conversions);
792
 
};
793
 
 
794
 
 
795
 
 
796
627
void mark_select_range_as_dependent(Session *session,
797
628
                                    st_select_lex *last_select,
798
629
                                    st_select_lex *current_sel,