Drizzled Public API Documentation

ref.h
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, Inc.
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 #pragma once
21 
22 #include <drizzled/item/ident.h>
23 
24 namespace drizzled {
25 
26 class Item_ref :public Item_ident
27 {
28 protected:
29  void set_properties();
30 public:
31  enum Ref_Type { REF, DIRECT_REF, OUTER_REF };
32  Field *result_field; /* Save result here */
33  Item **ref;
34  Item_ref(Name_resolution_context *context_arg,
35  const char *db_arg, const char *table_name_arg,
36  const char *field_name_arg)
37  :Item_ident(context_arg, db_arg, table_name_arg, field_name_arg),
38  result_field(0), ref(0) {}
39  /*
40  This constructor is used in two scenarios:
41  A) *item = NULL
42  No initialization is performed, fix_fields() call will be necessary.
43 
44  B) *item points to an Item this Item_ref will refer to. This is
45  used for GROUP BY. fix_fields() will not be called in this case,
46  so we call set_properties to make this item "fixed". set_properties
47  performs a subset of action Item_ref::fix_fields does, and this subset
48  is enough for Item_ref's used in GROUP BY.
49 
50  TODO we probably fix a superset of problems like in BUG#6658. Check this
51  with Bar, and if we have a more broader set of problems like this.
52  */
53  Item_ref(Name_resolution_context *context_arg, Item **item,
54  const char *table_name_arg, const char *field_name_arg,
55  bool alias_name_used_arg= false);
56 
57  /* Constructor need to process subselect with temporary tables (see Item) */
58  Item_ref(Session *session, Item_ref *item)
59  :Item_ident(session, item), result_field(item->result_field), ref(item->ref) {}
60  enum Type type() const { return REF_ITEM; }
61  bool eq(const Item *item, bool binary_cmp) const
62  {
63  const Item *it= item->real_item();
64  return ref && (*ref)->eq(it, binary_cmp);
65  }
66  double val_real();
67  int64_t val_int();
69  bool val_bool();
70  String *val_str(String* tmp);
71  bool is_null();
72  bool get_date(type::Time &ltime,uint32_t fuzzydate);
73  double val_result();
74  int64_t val_int_result();
75  String *str_result(String* tmp);
76  type::Decimal *val_decimal_result(type::Decimal *);
77  bool val_bool_result();
78  void send(plugin::Client *client, String *tmp);
79  void make_field(SendField *field);
80  bool fix_fields(Session *, Item **);
81  void fix_after_pullout(Select_Lex *new_parent, Item **ref);
82  int save_in_field(Field *field, bool no_conversions);
83  void save_org_in_field(Field *field);
84  enum Item_result result_type () const { return (*ref)->result_type(); }
85  enum_field_types field_type() const { return (*ref)->field_type(); }
86  Field *get_tmp_table_field()
87  { return result_field ? result_field : (*ref)->get_tmp_table_field(); }
88  Item *get_tmp_table_item(Session *session);
89  table_map used_tables() const
90  {
91  return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();
92  }
93  void update_used_tables()
94  {
95  if (!depended_from)
96  (*ref)->update_used_tables();
97  }
98  table_map not_null_tables() const { return (*ref)->not_null_tables(); }
99  void set_result_field(Field *field) { result_field= field; }
100  bool is_result_field() { return 1; }
101  void save_in_result_field(bool no_conversions)
102  {
103  (*ref)->save_in_field(result_field, no_conversions);
104  }
105  Item *real_item(void)
106  {
107  return ref ? (*ref)->real_item() : this;
108  }
109  const Item *real_item(void) const
110  {
111  return ref ? (*ref)->real_item() : this;
112  }
113  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
114  { return (*ref)->walk(processor, walk_subquery, arg); }
115  virtual void print(String *str);
117  {
118  return (*ref)->result_as_int64_t();
119  }
120  void cleanup();
121  virtual Ref_Type ref_type() { return REF; }
122 
123  // Row emulation: forwarding of ROW-related calls to ref
124  uint32_t cols()
125  {
126  return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
127  }
128  Item* element_index(uint32_t i)
129  {
130  return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
131  }
132  Item** addr(uint32_t i)
133  {
134  return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
135  }
136  bool check_cols(uint32_t c)
137  {
138  return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
139  : Item::check_cols(c);
140  }
141  bool null_inside()
142  {
143  return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0;
144  }
145  void bring_value()
146  {
147  if (ref && result_type() == ROW_RESULT)
148  (*ref)->bring_value();
149  }
150  bool basic_const_item() const
151  {
152  return (*ref)->basic_const_item();
153  }
154 };
155 
156 } /* namespace drizzled */
157 
bool is_null()
Definition: ref.cc:506
int64_t val_int()
Definition: ref.cc:479
bool val_bool()
Definition: ref.cc:488
bool basic_const_item() const
Definition: ref.h:150
TODO: Rename this file - func.h is stupid.
virtual void print(String *str)
Definition: ref.cc:361
table_map used_tables() const
Definition: ref.h:89
bool fix_fields(Session *, Item **)
Definition: ref.cc:113
virtual bool eq(const Item *, bool binary_cmp) const
Definition: item.cc:433
Definition: wakeup.h:27
void set_result_field(Field *field)
Definition: ref.h:99
double val_real()
Definition: ref.cc:470
table_map not_null_tables() const
Definition: ref.h:98
type::Decimal * val_decimal(type::Decimal *)
Definition: ref.cc:519
bool eq(const Item *item, bool binary_cmp) const
Definition: ref.h:61
void fix_after_pullout(Select_Lex *new_parent, Item **ref)
Definition: ref.cc:569
void send(plugin::Client *client, String *tmp)
Definition: ref.cc:378
String * val_str(String *tmp)
Definition: ref.cc:497
bool get_date(type::Time &ltime, uint32_t fuzzydate)
Definition: ref.cc:513
bool result_as_int64_t()
Definition: ref.h:116