~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.h

  • Committer: Brian Aker
  • Date: 2008-12-06 23:57:32 UTC
  • mfrom: (656.1.10 devel)
  • Revision ID: brian@tangent.org-20081206235732-jx228bczpvmxu8ww
Merge from Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
 
78
78
public:
79
79
 
80
 
  enum Type {FIELD_ITEM= 0, 
 
80
  enum Type {FIELD_ITEM= 0,
81
81
    FUNC_ITEM,
82
82
    SUM_FUNC_ITEM,
83
83
    STRING_ITEM,
588
588
 
589
589
};
590
590
 
591
 
 
592
 
class Item_basic_constant :public Item
593
 
{
594
 
public:
595
 
  /* to prevent drop fixed flag (no need parent cleanup call) */
596
 
  void cleanup()
597
 
  {
598
 
    /*
599
 
      Restore the original field name as it might not have been allocated
600
 
      in the statement memory. If the name is auto generated, it must be
601
 
      done again between subsequent executions of a prepared statement.
602
 
    */
603
 
    if (orig_name)
604
 
      name= orig_name;
605
 
  }
606
 
};
607
 
 
608
 
 
609
 
class Item_num: public Item_basic_constant
610
 
{
611
 
public:
612
 
  Item_num() {}                               /* Remove gcc warning */
613
 
  virtual Item_num *neg()= 0;
614
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
615
 
};
616
 
 
617
 
class Item_ident :public Item
618
 
{
619
 
protected:
620
 
  /* 
621
 
    We have to store initial values of db_name, table_name and field_name
622
 
    to be able to restore them during cleanup() because they can be 
623
 
    updated during fix_fields() to values from Field object and life-time 
624
 
    of those is shorter than life-time of Item_field.
625
 
  */
626
 
  const char *orig_db_name;
627
 
  const char *orig_table_name;
628
 
  const char *orig_field_name;
629
 
 
630
 
public:
631
 
  Name_resolution_context *context;
632
 
  const char *db_name;
633
 
  const char *table_name;
634
 
  const char *field_name;
635
 
  bool alias_name_used; /* true if item was resolved against alias */
636
 
  /* 
637
 
    Cached value of index for this field in table->field array, used by prep. 
638
 
    stmts for speeding up their re-execution. Holds NO_CACHED_FIELD_INDEX
639
 
    if index value is not known.
640
 
  */
641
 
  uint32_t cached_field_index;
642
 
  /*
643
 
    Cached pointer to table which contains this field, used for the same reason
644
 
    by prep. stmt. too in case then we have not-fully qualified field.
645
 
    0 - means no cached value.
646
 
  */
647
 
  TableList *cached_table;
648
 
  st_select_lex *depended_from;
649
 
  Item_ident(Name_resolution_context *context_arg,
650
 
             const char *db_name_arg, const char *table_name_arg,
651
 
             const char *field_name_arg);
652
 
  Item_ident(Session *session, Item_ident *item);
653
 
  const char *full_name() const;
654
 
  void cleanup();
655
 
  bool remove_dependence_processor(unsigned char * arg);
656
 
  virtual void print(String *str, enum_query_type query_type);
657
 
  virtual bool change_context_processor(unsigned char *cntx)
658
 
    { context= (Name_resolution_context *)cntx; return false; }
659
 
  friend bool insert_fields(Session *session, Name_resolution_context *context,
660
 
                            const char *db_name,
661
 
                            const char *table_name, List_iterator<Item> *it,
662
 
                            bool any_privileges);
663
 
};
664
 
 
665
 
 
666
 
class Item_ident_for_show :public Item
667
 
{
668
 
public:
669
 
  Field *field;
670
 
  const char *db_name;
671
 
  const char *table_name;
672
 
 
673
 
  Item_ident_for_show(Field *par_field, const char *db_arg,
674
 
                      const char *table_name_arg)
675
 
    :field(par_field), db_name(db_arg), table_name(table_name_arg)
676
 
  {}
677
 
 
678
 
  enum Type type() const { return FIELD_ITEM; }
679
 
  double val_real();
680
 
  int64_t val_int();
681
 
  String *val_str(String *str);
682
 
  my_decimal *val_decimal(my_decimal *dec);
683
 
  void make_field(Send_field *tmp_field);
684
 
};
685
 
 
686
 
 
687
 
class Item_field :public Item_ident
688
 
{
689
 
protected:
690
 
  void set_field(Field *field);
691
 
public:
692
 
  Field *field,*result_field;
693
 
  Item_equal *item_equal;
694
 
  bool no_const_subst;
695
 
  /*
696
 
    if any_privileges set to true then here real effective privileges will
697
 
    be stored
698
 
  */
699
 
  uint32_t have_privileges;
700
 
  /* field need any privileges (for VIEW creation) */
701
 
  bool any_privileges;
702
 
  Item_field(Name_resolution_context *context_arg,
703
 
             const char *db_arg,const char *table_name_arg,
704
 
             const char *field_name_arg);
705
 
  /*
706
 
    Constructor needed to process subselect with temporary tables (see Item)
707
 
  */
708
 
  Item_field(Session *session, Item_field *item);
709
 
  /*
710
 
    Constructor used inside setup_wild(), ensures that field, table,
711
 
    and database names will live as long as Item_field (this is important
712
 
    in prepared statements).
713
 
  */
714
 
  Item_field(Session *session, Name_resolution_context *context_arg, Field *field);
715
 
  /*
716
 
    If this constructor is used, fix_fields() won't work, because
717
 
    db_name, table_name and column_name are unknown. It's necessary to call
718
 
    reset_field() before fix_fields() for all fields created this way.
719
 
  */
720
 
  Item_field(Field *field);
721
 
  enum Type type() const { return FIELD_ITEM; }
722
 
  bool eq(const Item *item, bool binary_cmp) const;
723
 
  double val_real();
724
 
  int64_t val_int();
725
 
  my_decimal *val_decimal(my_decimal *);
726
 
  String *val_str(String*);
727
 
  double val_result();
728
 
  int64_t val_int_result();
729
 
  String *str_result(String* tmp);
730
 
  my_decimal *val_decimal_result(my_decimal *);
731
 
  bool val_bool_result();
732
 
  bool send(Protocol *protocol, String *str_arg);
733
 
  void reset_field(Field *f);
734
 
  bool fix_fields(Session *, Item **);
735
 
  void fix_after_pullout(st_select_lex *new_parent, Item **ref);
736
 
  void make_field(Send_field *tmp_field);
737
 
  int save_in_field(Field *field,bool no_conversions);
738
 
  void save_org_in_field(Field *field);
739
 
  table_map used_tables() const;
740
 
  enum Item_result result_type () const;
741
 
  Item_result cast_to_int_type() const;
742
 
  enum_field_types field_type() const;
743
 
  enum_monotonicity_info get_monotonicity_info() const
744
 
  {
745
 
    return MONOTONIC_STRICT_INCREASING;
746
 
  }
747
 
  int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
748
 
  Field *get_tmp_table_field() { return result_field; }
749
 
  Field *tmp_table_field(Table *) { return result_field; }
750
 
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
751
 
  bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
752
 
  bool get_time(DRIZZLE_TIME *ltime);
753
 
  bool is_null();
754
 
  void update_null_value();
755
 
  Item *get_tmp_table_item(Session *session);
756
 
  bool collect_item_field_processor(unsigned char * arg);
757
 
  bool find_item_in_field_list_processor(unsigned char *arg);
758
 
  bool register_field_in_read_map(unsigned char *arg);
759
 
  bool register_field_in_bitmap(unsigned char *arg);
760
 
  bool check_vcol_func_processor(unsigned char *)
761
 
  { return false; }
762
 
  void cleanup();
763
 
  bool result_as_int64_t();
764
 
  Item_equal *find_item_equal(COND_EQUAL *cond_equal);
765
 
  bool subst_argument_checker(unsigned char **arg);
766
 
  Item *equal_fields_propagator(unsigned char *arg);
767
 
  bool set_no_const_sub(unsigned char *arg);
768
 
  Item *replace_equal_field(unsigned char *arg);
769
 
  uint32_t max_disp_length();
770
 
  Item_field *filed_for_view_update() { return this; }
771
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
772
 
  int fix_outer_field(Session *session, Field **field, Item **reference);
773
 
  virtual Item *update_value_transformer(unsigned char *select_arg);
774
 
  virtual void print(String *str, enum_query_type query_type);
775
 
 
776
 
  friend class Item_default_value;
777
 
  friend class Item_insert_value;
778
 
  friend class st_select_lex_unit;
779
 
};
 
591
#include <drizzled/item/basic_constant.h>
 
592
#include <drizzled/item/ident.h>
 
593
#include <drizzled/item/field.h>
 
594
#include <drizzled/item/num.h>
 
595
 
 
596
void mark_as_dependent(Session *session,
 
597
                       st_select_lex *last,
 
598
                       st_select_lex *current,
 
599
                       Item_ident *resolved_item,
 
600
                       Item_ident *mark_item);
 
601
 
 
602
Item** resolve_ref_in_select_and_group(Session *session,
 
603
                                       Item_ident *ref,
 
604
                                       st_select_lex *select);
780
605
 
781
606
class Item_null :public Item_basic_constant
782
607
{
826
651
  }
827
652
  bool check_vcol_func_processor(unsigned char *)
828
653
  { return true; }
829
 
};  
 
654
};
830
655
 
831
656
/* Item represents one placeholder ('?') of prepared statement */
832
657
 
1190
1015
  enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
1191
1016
  bool basic_const_item() const { return 1; }
1192
1017
  bool eq(const Item *item, bool binary_cmp) const;
1193
 
  Item *clone_item() 
 
1018
  Item *clone_item()
1194
1019
  {
1195
 
    return new Item_string(name, str_value.ptr(), 
 
1020
    return new Item_string(name, str_value.ptr(),
1196
1021
                           str_value.length(), collation.collation);
1197
1022
  }
1198
1023
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1330
1155
  Item_hex_string(const char *str,uint32_t str_length);
1331
1156
  enum Type type() const { return VARBIN_ITEM; }
1332
1157
  double val_real()
1333
 
  { 
1334
 
    assert(fixed == 1); 
 
1158
  {
 
1159
    assert(fixed == 1);
1335
1160
    return (double) (uint64_t) Item_hex_string::val_int();
1336
1161
  }
1337
1162
  int64_t val_int();
1400
1225
    This constructor is used in two scenarios:
1401
1226
    A) *item = NULL
1402
1227
      No initialization is performed, fix_fields() call will be necessary.
1403
 
      
1404
 
    B) *item points to an Item this Item_ref will refer to. This is 
 
1228
 
 
1229
    B) *item points to an Item this Item_ref will refer to. This is
1405
1230
      used for GROUP BY. fix_fields() will not be called in this case,
1406
1231
      so we call set_properties to make this item "fixed". set_properties
1407
1232
      performs a subset of action Item_ref::fix_fields does, and this subset
1408
1233
      is enough for Item_ref's used in GROUP BY.
1409
 
    
1410
 
    TODO we probably fix a superset of problems like in BUG#6658. Check this 
 
1234
 
 
1235
    TODO we probably fix a superset of problems like in BUG#6658. Check this
1411
1236
         with Bar, and if we have a more broader set of problems like this.
1412
1237
  */
1413
1238
  Item_ref(Name_resolution_context *context_arg, Item **item,
1419
1244
    :Item_ident(session, item), result_field(item->result_field), ref(item->ref) {}
1420
1245
  enum Type type() const                { return REF_ITEM; }
1421
1246
  bool eq(const Item *item, bool binary_cmp) const
1422
 
  { 
 
1247
  {
1423
1248
    Item *it= ((Item *) item)->real_item();
1424
1249
    return ref && (*ref)->eq(it, binary_cmp);
1425
1250
  }
1446
1271
  Field *get_tmp_table_field()
1447
1272
  { return result_field ? result_field : (*ref)->get_tmp_table_field(); }
1448
1273
  Item *get_tmp_table_item(Session *session);
1449
 
  table_map used_tables() const         
 
1274
  table_map used_tables() const
1450
1275
  {
1451
 
    return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables(); 
 
1276
    return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();
1452
1277
  }
1453
 
  void update_used_tables() 
1454
 
  { 
1455
 
    if (!depended_from) 
1456
 
      (*ref)->update_used_tables(); 
 
1278
  void update_used_tables()
 
1279
  {
 
1280
    if (!depended_from)
 
1281
      (*ref)->update_used_tables();
1457
1282
  }
1458
1283
  table_map not_null_tables() const { return (*ref)->not_null_tables(); }
1459
1284
  void set_result_field(Field *field)   { result_field= field; }
1493
1318
  }
1494
1319
  bool check_cols(uint32_t c)
1495
1320
  {
1496
 
    return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c) 
 
1321
    return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
1497
1322
                                              : Item::check_cols(c);
1498
1323
  }
1499
1324
  bool null_inside()
1501
1326
    return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0;
1502
1327
  }
1503
1328
  void bring_value()
1504
 
  { 
 
1329
  {
1505
1330
    if (ref && result_type() == ROW_RESULT)
1506
1331
      (*ref)->bring_value();
1507
1332
  }
1631
1456
  The following class is used to optimize comparing of date and bigint columns
1632
1457
  We need to save the original item ('ref') to be able to call
1633
1458
  ref->save_in_field(). This is used to create index search keys.
1634
 
  
 
1459
 
1635
1460
  An instance of Item_int_with_ref may have signed or unsigned integer value.
1636
 
  
 
1461
 
1637
1462
*/
1638
1463
 
1639
1464
class Item_int_with_ref :public Item_int
1750
1575
  {
1751
1576
    return Item_field::save_in_field(field_arg, no_conversions);
1752
1577
  }
1753
 
  /* 
 
1578
  /*
1754
1579
   We use RAND_TABLE_BIT to prevent Item_insert_value from
1755
1580
   being treated as a constant and precalculated before execution
1756
1581
  */
1772
1597
  Item *example;
1773
1598
  table_map used_table_map;
1774
1599
  /*
1775
 
    Field that this object will get value from. This is set/used by 
1776
 
    index-based subquery engines to detect and remove the equality injected 
 
1600
    Field that this object will get value from. This is set/used by
 
1601
    index-based subquery engines to detect and remove the equality injected
1777
1602
    by IN->EXISTS transformation.
1778
1603
    For all other uses of Item_cache, cached_field doesn't matter.
1779
 
  */  
 
1604
  */
1780
1605
  Field *cached_field;
1781
1606
  enum enum_field_types cached_field_type;
1782
1607
public:
1783
 
  Item_cache(): 
1784
 
    example(0), used_table_map(0), cached_field(0), cached_field_type(DRIZZLE_TYPE_VARCHAR) 
 
1608
  Item_cache():
 
1609
    example(0), used_table_map(0), cached_field(0), cached_field_type(DRIZZLE_TYPE_VARCHAR)
1785
1610
  {
1786
 
    fixed= 1; 
 
1611
    fixed= 1;
1787
1612
    null_value= 1;
1788
1613
  }
1789
1614
  Item_cache(enum_field_types field_type_arg):