1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
20
#ifndef DRIZZLED_ITEM_REF_H
21
#define DRIZZLED_ITEM_REF_H
23
class Item_ref :public Item_ident
26
void set_properties();
28
enum Ref_Type { REF, DIRECT_REF, OUTER_REF };
29
Field *result_field; /* Save result here */
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) {}
37
This constructor is used in two scenarios:
39
No initialization is performed, fix_fields() call will be necessary.
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.
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.
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);
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
60
Item *it= ((Item *) item)->real_item();
61
return ref && (*ref)->eq(it, binary_cmp);
65
my_decimal *val_decimal(my_decimal *);
67
String *val_str(String* tmp);
69
bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
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
88
return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();
90
void update_used_tables()
93
(*ref)->update_used_tables();
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)
100
(*ref)->save_in_field(result_field, no_conversions);
104
return ref ? (*ref)->real_item() : this;
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()
111
return (*ref)->result_as_int64_t();
114
Item_field *filed_for_view_update()
115
{ return (*ref)->filed_for_view_update(); }
116
virtual Ref_Type ref_type() { return REF; }
118
// Row emulation: forwarding of ROW-related calls to ref
121
return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
123
Item* element_index(uint32_t i)
125
return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
127
Item** addr(uint32_t i)
129
return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
131
bool check_cols(uint32_t c)
133
return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
134
: Item::check_cols(c);
138
return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0;
142
if (ref && result_type() == ROW_RESULT)
143
(*ref)->bring_value();
148
#endif /* DRIZZLED_ITEM_REF_H */