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, Inc.
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
#include "drizzled/item/ident.h"
28
class Item_ref :public Item_ident
31
void set_properties();
33
enum Ref_Type { REF, DIRECT_REF, OUTER_REF };
34
Field *result_field; /* Save result here */
36
Item_ref(Name_resolution_context *context_arg,
37
const char *db_arg, const char *table_name_arg,
38
const char *field_name_arg)
39
:Item_ident(context_arg, db_arg, table_name_arg, field_name_arg),
40
result_field(0), ref(0) {}
42
This constructor is used in two scenarios:
44
No initialization is performed, fix_fields() call will be necessary.
46
B) *item points to an Item this Item_ref will refer to. This is
47
used for GROUP BY. fix_fields() will not be called in this case,
48
so we call set_properties to make this item "fixed". set_properties
49
performs a subset of action Item_ref::fix_fields does, and this subset
50
is enough for Item_ref's used in GROUP BY.
52
TODO we probably fix a superset of problems like in BUG#6658. Check this
53
with Bar, and if we have a more broader set of problems like this.
55
Item_ref(Name_resolution_context *context_arg, Item **item,
56
const char *table_name_arg, const char *field_name_arg,
57
bool alias_name_used_arg= false);
59
/* Constructor need to process subselect with temporary tables (see Item) */
60
Item_ref(Session *session, Item_ref *item)
61
:Item_ident(session, item), result_field(item->result_field), ref(item->ref) {}
62
enum Type type() const { return REF_ITEM; }
63
bool eq(const Item *item, bool binary_cmp) const
65
const Item *it= item->real_item();
66
return ref && (*ref)->eq(it, binary_cmp);
70
type::Decimal *val_decimal(type::Decimal *);
72
String *val_str(String* tmp);
74
bool get_date(type::Time <ime,uint32_t fuzzydate);
76
int64_t val_int_result();
77
String *str_result(String* tmp);
78
type::Decimal *val_decimal_result(type::Decimal *);
79
bool val_bool_result();
80
bool send(plugin::Client *client, String *tmp);
81
void make_field(SendField *field);
82
bool fix_fields(Session *, Item **);
83
void fix_after_pullout(Select_Lex *new_parent, Item **ref);
84
int save_in_field(Field *field, bool no_conversions);
85
void save_org_in_field(Field *field);
86
enum Item_result result_type () const { return (*ref)->result_type(); }
87
enum_field_types field_type() const { return (*ref)->field_type(); }
88
Field *get_tmp_table_field()
89
{ return result_field ? result_field : (*ref)->get_tmp_table_field(); }
90
Item *get_tmp_table_item(Session *session);
91
table_map used_tables() const
93
return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();
95
void update_used_tables()
98
(*ref)->update_used_tables();
100
table_map not_null_tables() const { return (*ref)->not_null_tables(); }
101
void set_result_field(Field *field) { result_field= field; }
102
bool is_result_field() { return 1; }
103
void save_in_result_field(bool no_conversions)
105
(*ref)->save_in_field(result_field, no_conversions);
107
Item *real_item(void)
109
return ref ? (*ref)->real_item() : this;
111
const Item *real_item(void) const
113
return ref ? (*ref)->real_item() : this;
115
bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
116
{ return (*ref)->walk(processor, walk_subquery, arg); }
117
virtual void print(String *str, enum_query_type query_type);
118
bool result_as_int64_t()
120
return (*ref)->result_as_int64_t();
123
virtual Ref_Type ref_type() { return REF; }
125
// Row emulation: forwarding of ROW-related calls to ref
128
return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
130
Item* element_index(uint32_t i)
132
return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
134
Item** addr(uint32_t i)
136
return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
138
bool check_cols(uint32_t c)
140
return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
141
: Item::check_cols(c);
145
return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0;
149
if (ref && result_type() == ROW_RESULT)
150
(*ref)->bring_value();
152
bool basic_const_item() const
154
return (*ref)->basic_const_item();
158
} /* namespace drizzled */
160
#endif /* DRIZZLED_ITEM_REF_H */