~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/ref.h

MergeĀ fromĀ Lee.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#ifndef DRIZZLED_ITEM_REF_H
 
21
#define DRIZZLED_ITEM_REF_H
 
22
 
 
23
class Item_ref :public Item_ident
 
24
{
 
25
protected:
 
26
  void set_properties();
 
27
public:
 
28
  enum Ref_Type { REF, DIRECT_REF, OUTER_REF };
 
29
  Field *result_field;                   /* Save result here */
 
30
  Item **ref;
 
31
  Item_ref(Name_resolution_context *context_arg,
 
32
           const char *db_arg, const char *table_name_arg,
 
33
           const char *field_name_arg)
 
34
    :Item_ident(context_arg, db_arg, table_name_arg, field_name_arg),
 
35
     result_field(0), ref(0) {}
 
36
  /*
 
37
    This constructor is used in two scenarios:
 
38
    A) *item = NULL
 
39
      No initialization is performed, fix_fields() call will be necessary.
 
40
 
 
41
    B) *item points to an Item this Item_ref will refer to. This is
 
42
      used for GROUP BY. fix_fields() will not be called in this case,
 
43
      so we call set_properties to make this item "fixed". set_properties
 
44
      performs a subset of action Item_ref::fix_fields does, and this subset
 
45
      is enough for Item_ref's used in GROUP BY.
 
46
 
 
47
    TODO we probably fix a superset of problems like in BUG#6658. Check this
 
48
         with Bar, and if we have a more broader set of problems like this.
 
49
  */
 
50
  Item_ref(Name_resolution_context *context_arg, Item **item,
 
51
           const char *table_name_arg, const char *field_name_arg,
 
52
           bool alias_name_used_arg= false);
 
53
 
 
54
  /* Constructor need to process subselect with temporary tables (see Item) */
 
55
  Item_ref(Session *session, Item_ref *item)
 
56
    :Item_ident(session, item), result_field(item->result_field), ref(item->ref) {}
 
57
  enum Type type() const                { return REF_ITEM; }
 
58
  bool eq(const Item *item, bool binary_cmp) const
 
59
  {
 
60
    Item *it= ((Item *) item)->real_item();
 
61
    return ref && (*ref)->eq(it, binary_cmp);
 
62
  }
 
63
  double val_real();
 
64
  int64_t val_int();
 
65
  my_decimal *val_decimal(my_decimal *);
 
66
  bool val_bool();
 
67
  String *val_str(String* tmp);
 
68
  bool is_null();
 
69
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
70
  double val_result();
 
71
  int64_t val_int_result();
 
72
  String *str_result(String* tmp);
 
73
  my_decimal *val_decimal_result(my_decimal *);
 
74
  bool val_bool_result();
 
75
  bool send(Protocol *prot, String *tmp);
 
76
  void make_field(Send_field *field);
 
77
  bool fix_fields(Session *, Item **);
 
78
  void fix_after_pullout(st_select_lex *new_parent, Item **ref);
 
79
  int save_in_field(Field *field, bool no_conversions);
 
80
  void save_org_in_field(Field *field);
 
81
  enum Item_result result_type () const { return (*ref)->result_type(); }
 
82
  enum_field_types field_type() const   { return (*ref)->field_type(); }
 
83
  Field *get_tmp_table_field()
 
84
  { return result_field ? result_field : (*ref)->get_tmp_table_field(); }
 
85
  Item *get_tmp_table_item(Session *session);
 
86
  table_map used_tables() const
 
87
  {
 
88
    return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();
 
89
  }
 
90
  void update_used_tables()
 
91
  {
 
92
    if (!depended_from)
 
93
      (*ref)->update_used_tables();
 
94
  }
 
95
  table_map not_null_tables() const { return (*ref)->not_null_tables(); }
 
96
  void set_result_field(Field *field)   { result_field= field; }
 
97
  bool is_result_field() { return 1; }
 
98
  void save_in_result_field(bool no_conversions)
 
99
  {
 
100
    (*ref)->save_in_field(result_field, no_conversions);
 
101
  }
 
102
  Item *real_item()
 
103
  {
 
104
    return ref ? (*ref)->real_item() : this;
 
105
  }
 
106
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
 
107
  { return (*ref)->walk(processor, walk_subquery, arg); }
 
108
  virtual void print(String *str, enum_query_type query_type);
 
109
  bool result_as_int64_t()
 
110
  {
 
111
    return (*ref)->result_as_int64_t();
 
112
  }
 
113
  void cleanup();
 
114
  Item_field *filed_for_view_update()
 
115
    { return (*ref)->filed_for_view_update(); }
 
116
  virtual Ref_Type ref_type() { return REF; }
 
117
 
 
118
  // Row emulation: forwarding of ROW-related calls to ref
 
119
  uint32_t cols()
 
120
  {
 
121
    return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
 
122
  }
 
123
  Item* element_index(uint32_t i)
 
124
  {
 
125
    return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
 
126
  }
 
127
  Item** addr(uint32_t i)
 
128
  {
 
129
    return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
 
130
  }
 
131
  bool check_cols(uint32_t c)
 
132
  {
 
133
    return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
 
134
                                              : Item::check_cols(c);
 
135
  }
 
136
  bool null_inside()
 
137
  {
 
138
    return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0;
 
139
  }
 
140
  void bring_value()
 
141
  {
 
142
    if (ref && result_type() == ROW_RESULT)
 
143
      (*ref)->bring_value();
 
144
  }
 
145
 
 
146
};
 
147
 
 
148
#endif /* DRIZZLED_ITEM_REF_H */