~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/item/ref.h

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

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
#include "drizzled/item/ident.h"
 
24
 
 
25
namespace drizzled
 
26
{
 
27
 
 
28
class Item_ref :public Item_ident
 
29
{
 
30
protected:
 
31
  void set_properties();
 
32
public:
 
33
  enum Ref_Type { REF, DIRECT_REF, OUTER_REF };
 
34
  Field *result_field;                   /* Save result here */
 
35
  Item **ref;
 
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) {}
 
41
  /*
 
42
    This constructor is used in two scenarios:
 
43
    A) *item = NULL
 
44
      No initialization is performed, fix_fields() call will be necessary.
 
45
 
 
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.
 
51
 
 
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.
 
54
  */
 
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);
 
58
 
 
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
 
64
  {
 
65
    const Item *it= item->real_item();
 
66
    return ref && (*ref)->eq(it, binary_cmp);
 
67
  }
 
68
  double val_real();
 
69
  int64_t val_int();
 
70
  my_decimal *val_decimal(my_decimal *);
 
71
  bool val_bool();
 
72
  String *val_str(String* tmp);
 
73
  bool is_null();
 
74
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
75
  double val_result();
 
76
  int64_t val_int_result();
 
77
  String *str_result(String* tmp);
 
78
  my_decimal *val_decimal_result(my_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
 
92
  {
 
93
    return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();
 
94
  }
 
95
  void update_used_tables()
 
96
  {
 
97
    if (!depended_from)
 
98
      (*ref)->update_used_tables();
 
99
  }
 
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)
 
104
  {
 
105
    (*ref)->save_in_field(result_field, no_conversions);
 
106
  }
 
107
  Item *real_item(void)
 
108
  {
 
109
    return ref ? (*ref)->real_item() : this;
 
110
  }
 
111
  const Item *real_item(void) const
 
112
  {
 
113
    return ref ? (*ref)->real_item() : this;
 
114
  }
 
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()
 
119
  {
 
120
    return (*ref)->result_as_int64_t();
 
121
  }
 
122
  void cleanup();
 
123
  virtual Ref_Type ref_type() { return REF; }
 
124
 
 
125
  // Row emulation: forwarding of ROW-related calls to ref
 
126
  uint32_t cols()
 
127
  {
 
128
    return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
 
129
  }
 
130
  Item* element_index(uint32_t i)
 
131
  {
 
132
    return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
 
133
  }
 
134
  Item** addr(uint32_t i)
 
135
  {
 
136
    return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
 
137
  }
 
138
  bool check_cols(uint32_t c)
 
139
  {
 
140
    return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
 
141
                                              : Item::check_cols(c);
 
142
  }
 
143
  bool null_inside()
 
144
  {
 
145
    return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0;
 
146
  }
 
147
  void bring_value()
 
148
  {
 
149
    if (ref && result_type() == ROW_RESULT)
 
150
      (*ref)->bring_value();
 
151
  }
 
152
  bool basic_const_item() const
 
153
  {
 
154
    return (*ref)->basic_const_item();
 
155
  }
 
156
};
 
157
 
 
158
} /* namespace drizzled */
 
159
 
 
160
#endif /* DRIZZLED_ITEM_REF_H */