~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/ident.h>
593
593
#include <drizzled/item/field.h>
 
594
#include <drizzled/item/null.h>
594
595
#include <drizzled/item/num.h>
 
596
#include <drizzled/item/param.h>
595
597
 
596
598
void mark_as_dependent(Session *session,
597
599
                       st_select_lex *last,
603
605
                                       Item_ident *ref,
604
606
                                       st_select_lex *select);
605
607
 
606
 
class Item_null :public Item_basic_constant
607
 
{
608
 
public:
609
 
  Item_null(char *name_par=0)
610
 
  {
611
 
    maybe_null= null_value= true;
612
 
    max_length= 0;
613
 
    name= name_par ? name_par : (char*) "NULL";
614
 
    fixed= 1;
615
 
    collation.set(&my_charset_bin, DERIVATION_IGNORABLE);
616
 
  }
617
 
  enum Type type() const { return NULL_ITEM; }
618
 
  bool eq(const Item *item, bool binary_cmp) const;
619
 
  double val_real();
620
 
  int64_t val_int();
621
 
  String *val_str(String *str);
622
 
  my_decimal *val_decimal(my_decimal *);
623
 
  int save_in_field(Field *field, bool no_conversions);
624
 
  int save_safe_in_field(Field *field);
625
 
  bool send(Protocol *protocol, String *str);
626
 
  enum Item_result result_type () const { return STRING_RESULT; }
627
 
  enum_field_types field_type() const   { return DRIZZLE_TYPE_NULL; }
628
 
  bool basic_const_item() const { return 1; }
629
 
  Item *clone_item() { return new Item_null(name); }
630
 
  bool is_null() { return 1; }
631
 
 
632
 
  virtual inline void print(String *str, enum_query_type)
633
 
  {
634
 
    str->append(STRING_WITH_LEN("NULL"));
635
 
  }
636
 
 
637
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
638
 
  bool check_vcol_func_processor(unsigned char *)
639
 
  { return false; }
640
 
};
641
 
 
642
 
class Item_null_result :public Item_null
643
 
{
644
 
public:
645
 
  Field *result_field;
646
 
  Item_null_result() : Item_null(), result_field(0) {}
647
 
  bool is_result_field() { return result_field != 0; }
648
 
  void save_in_result_field(bool no_conversions)
649
 
  {
650
 
    save_in_field(result_field, no_conversions);
651
 
  }
652
 
  bool check_vcol_func_processor(unsigned char *)
653
 
  { return true; }
654
 
};
655
 
 
656
 
/* Item represents one placeholder ('?') of prepared statement */
657
 
 
658
 
class Item_param :public Item
659
 
{
660
 
  char cnvbuf[MAX_FIELD_WIDTH];
661
 
  String cnvstr;
662
 
  Item *cnvitem;
663
 
 
664
 
public:
665
 
  enum enum_item_param_state
666
 
  {
667
 
    NO_VALUE, NULL_VALUE, INT_VALUE, REAL_VALUE,
668
 
    STRING_VALUE, TIME_VALUE, LONG_DATA_VALUE,
669
 
    DECIMAL_VALUE
670
 
  } state;
671
 
 
672
 
  /*
673
 
    A buffer for string and long data values. Historically all allocated
674
 
    values returned from val_str() were treated as eligible to
675
 
    modification. I. e. in some cases Item_func_concat can append it's
676
 
    second argument to return value of the first one. Because of that we
677
 
    can't return the original buffer holding string data from val_str(),
678
 
    and have to have one buffer for data and another just pointing to
679
 
    the data. This is the latter one and it's returned from val_str().
680
 
    Can not be declared inside the union as it's not a POD type.
681
 
  */
682
 
  String str_value_ptr;
683
 
  my_decimal decimal_value;
684
 
  union
685
 
  {
686
 
    int64_t integer;
687
 
    double   real;
688
 
    /*
689
 
      Character sets conversion info for string values.
690
 
      Character sets of client and connection defined at bind time are used
691
 
      for all conversions, even if one of them is later changed (i.e.
692
 
      between subsequent calls to mysql_stmt_execute).
693
 
    */
694
 
    struct CONVERSION_INFO
695
 
    {
696
 
      const CHARSET_INFO *character_set_client;
697
 
      const CHARSET_INFO *character_set_of_placeholder;
698
 
      /*
699
 
        This points at character set of connection if conversion
700
 
        to it is required (i. e. if placeholder typecode is not BLOB).
701
 
        Otherwise it's equal to character_set_client (to simplify
702
 
        check in convert_str_value()).
703
 
      */
704
 
      const CHARSET_INFO *final_character_set_of_str_value;
705
 
    } cs_info;
706
 
    DRIZZLE_TIME     time;
707
 
  } value;
708
 
 
709
 
  /* Cached values for virtual methods to save us one switch.  */
710
 
  enum Item_result item_result_type;
711
 
  enum Type item_type;
712
 
 
713
 
  /*
714
 
    Used when this item is used in a temporary table.
715
 
    This is NOT placeholder metadata sent to client, as this value
716
 
    is assigned after sending metadata (in setup_one_conversion_function).
717
 
    For example in case of 'SELECT ?' you'll get DRIZZLE_TYPE_STRING both
718
 
    in result set and placeholders metadata, no matter what type you will
719
 
    supply for this placeholder in mysql_stmt_execute.
720
 
  */
721
 
  enum enum_field_types param_type;
722
 
  /*
723
 
    Offset of placeholder inside statement text. Used to create
724
 
    no-placeholders version of this statement for the binary log.
725
 
  */
726
 
  uint32_t pos_in_query;
727
 
 
728
 
  Item_param(uint32_t pos_in_query_arg);
729
 
 
730
 
  enum Item_result result_type () const { return item_result_type; }
731
 
  enum Type type() const { return item_type; }
732
 
  enum_field_types field_type() const { return param_type; }
733
 
 
734
 
  double val_real();
735
 
  int64_t val_int();
736
 
  my_decimal *val_decimal(my_decimal*);
737
 
  String *val_str(String*);
738
 
  bool get_time(DRIZZLE_TIME *tm);
739
 
  bool get_date(DRIZZLE_TIME *tm, uint32_t fuzzydate);
740
 
  int  save_in_field(Field *field, bool no_conversions);
741
 
 
742
 
  void set_null();
743
 
  void set_int(int64_t i, uint32_t max_length_arg);
744
 
  void set_double(double i);
745
 
  void set_decimal(char *str, ulong length);
746
 
  bool set_str(const char *str, ulong length);
747
 
  bool set_longdata(const char *str, ulong length);
748
 
  void set_time(DRIZZLE_TIME *tm, enum enum_drizzle_timestamp_type type,
749
 
                uint32_t max_length_arg);
750
 
  bool set_from_user_var(Session *session, const user_var_entry *entry);
751
 
  void reset();
752
 
  /*
753
 
    Assign placeholder value from bind data.
754
 
    Note, that 'len' has different semantics in embedded library (as we
755
 
    don't need to check that packet is not broken there). See
756
 
    sql_prepare.cc for details.
757
 
  */
758
 
  void (*set_param_func)(Item_param *param, unsigned char **pos, ulong len);
759
 
 
760
 
  const String *query_val_str(String *str) const;
761
 
 
762
 
  bool convert_str_value(Session *session);
763
 
 
764
 
  /*
765
 
    If value for parameter was not set we treat it as non-const
766
 
    so noone will use parameters value in fix_fields still
767
 
    parameter is constant during execution.
768
 
  */
769
 
  virtual table_map used_tables() const
770
 
  { return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT; }
771
 
  virtual void print(String *str, enum_query_type query_type);
772
 
  bool is_null()
773
 
  { assert(state != NO_VALUE); return state == NULL_VALUE; }
774
 
  bool basic_const_item() const;
775
 
  /*
776
 
    This method is used to make a copy of a basic constant item when
777
 
    propagating constants in the optimizer. The reason to create a new
778
 
    item and not use the existing one is not precisely known (2005/04/16).
779
 
    Probably we are trying to preserve tree structure of items, in other
780
 
    words, avoid pointing at one item from two different nodes of the tree.
781
 
    Return a new basic constant item if parameter value is a basic
782
 
    constant, assert otherwise. This method is called only if
783
 
    basic_const_item returned true.
784
 
  */
785
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
786
 
  Item *clone_item();
787
 
  /*
788
 
    Implement by-value equality evaluation if parameter value
789
 
    is set and is a basic constant (integer, real or string).
790
 
    Otherwise return false.
791
 
  */
792
 
  bool eq(const Item *item, bool binary_cmp) const;
793
 
  /** Item is a argument to a limit clause. */
794
 
  bool limit_clause_param;
795
 
};
796
 
 
797
 
 
798
608
class Item_int :public Item_num
799
609
{
800
610
public: