~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to drizzled/item/row.cc

  • 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
/* Copyright (C) 2000 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include "config.h"
 
17
#include <drizzled/error.h>
 
18
#include <drizzled/session.h>
 
19
 
 
20
#include <drizzled/item/row.h>
 
21
 
 
22
namespace drizzled
 
23
{
 
24
 
 
25
/**
 
26
  Row items used for comparing rows and IN operations on rows:
 
27
 
 
28
  @verbatim
 
29
  (a, b, c) > (10, 10, 30)
 
30
  (a, b, c) = (select c, d, e, from t1 where x=12)
 
31
  (a, b, c) IN ((1,2,2), (3,4,5), (6,7,8)
 
32
  (a, b, c) IN (select c, d, e, from t1)
 
33
  @endverbatim
 
34
 
 
35
  @todo
 
36
    think placing 2-3 component items in item (as it done for function
 
37
*/
 
38
 
 
39
Item_row::Item_row(List<Item> &arg):
 
40
  Item(), used_tables_cache(0), const_item_cache(1), with_null(0)
 
41
{
 
42
 
 
43
  //TODO: think placing 2-3 component items in item (as it done for function)
 
44
  if ((arg_count= arg.elements))
 
45
    items= (Item**) memory::sql_alloc(sizeof(Item*)*arg_count);
 
46
  else
 
47
    items= 0;
 
48
  List_iterator<Item> li(arg);
 
49
  uint32_t i= 0;
 
50
  Item *item;
 
51
  while ((item= li++))
 
52
  {
 
53
    items[i]= item;
 
54
    i++;
 
55
  }
 
56
}
 
57
 
 
58
void Item_row::illegal_method_call(const char *)
 
59
{
 
60
  assert(0);
 
61
  my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
 
62
  return;
 
63
}
 
64
 
 
65
bool Item_row::fix_fields(Session *session, Item **)
 
66
{
 
67
  assert(fixed == 0);
 
68
  null_value= 0;
 
69
  maybe_null= 0;
 
70
  Item **arg, **arg_end;
 
71
  for (arg= items, arg_end= items+arg_count; arg != arg_end ; arg++)
 
72
  {
 
73
    if ((*arg)->fix_fields(session, arg))
 
74
      return true;
 
75
    // we can't assign 'item' before, because fix_fields() can change arg
 
76
    Item *item= *arg;
 
77
    used_tables_cache |= item->used_tables();
 
78
    const_item_cache&= item->const_item() && !with_null;
 
79
    if (const_item_cache)
 
80
    {
 
81
      if (item->cols() > 1)
 
82
        with_null|= item->null_inside();
 
83
      else
 
84
      {
 
85
        if (item->is_null())
 
86
          with_null|= 1;
 
87
      }
 
88
    }
 
89
    maybe_null|= item->maybe_null;
 
90
    with_sum_func= with_sum_func || item->with_sum_func;
 
91
  }
 
92
  fixed= 1;
 
93
  return false;
 
94
}
 
95
 
 
96
 
 
97
void Item_row::cleanup()
 
98
{
 
99
  Item::cleanup();
 
100
  /* Reset to the original values */
 
101
  used_tables_cache= 0;
 
102
  const_item_cache= 1;
 
103
  with_null= 0;
 
104
 
 
105
  return;
 
106
}
 
107
 
 
108
 
 
109
void Item_row::split_sum_func(Session *session, Item **ref_pointer_array,
 
110
                              List<Item> &fields)
 
111
{
 
112
  Item **arg, **arg_end;
 
113
  for (arg= items, arg_end= items+arg_count; arg != arg_end ; arg++)
 
114
    (*arg)->split_sum_func(session, ref_pointer_array, fields, arg, true);
 
115
}
 
116
 
 
117
 
 
118
void Item_row::update_used_tables()
 
119
{
 
120
  used_tables_cache= 0;
 
121
  const_item_cache= 1;
 
122
  for (uint32_t i= 0; i < arg_count; i++)
 
123
  {
 
124
    items[i]->update_used_tables();
 
125
    used_tables_cache|= items[i]->used_tables();
 
126
    const_item_cache&= items[i]->const_item();
 
127
  }
 
128
}
 
129
 
 
130
void Item_row::fix_after_pullout(Select_Lex *new_parent, Item **)
 
131
{
 
132
  used_tables_cache= 0;
 
133
  const_item_cache= 1;
 
134
  for (uint32_t i= 0; i < arg_count; i++)
 
135
  {
 
136
    items[i]->fix_after_pullout(new_parent, &items[i]);
 
137
    used_tables_cache|= items[i]->used_tables();
 
138
    const_item_cache&= items[i]->const_item();
 
139
  }
 
140
}
 
141
 
 
142
bool Item_row::check_cols(uint32_t c)
 
143
{
 
144
  if (c != arg_count)
 
145
  {
 
146
    my_error(ER_OPERAND_COLUMNS, MYF(0), c);
 
147
    return 1;
 
148
  }
 
149
  return 0;
 
150
}
 
151
 
 
152
void Item_row::print(String *str, enum_query_type query_type)
 
153
{
 
154
  str->append('(');
 
155
  for (uint32_t i= 0; i < arg_count; i++)
 
156
  {
 
157
    if (i)
 
158
      str->append(',');
 
159
    items[i]->print(str, query_type);
 
160
  }
 
161
  str->append(')');
 
162
}
 
163
 
 
164
 
 
165
bool Item_row::walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
 
166
{
 
167
  for (uint32_t i= 0; i < arg_count; i++)
 
168
  {
 
169
    if (items[i]->walk(processor, walk_subquery, arg))
 
170
      return 1;
 
171
  }
 
172
  return (this->*processor)(arg);
 
173
}
 
174
 
 
175
 
 
176
Item *Item_row::transform(Item_transformer transformer, unsigned char *arg)
 
177
{
 
178
  for (uint32_t i= 0; i < arg_count; i++)
 
179
  {
 
180
    Item *new_item= items[i]->transform(transformer, arg);
 
181
    if (!new_item)
 
182
      return 0;
 
183
 
 
184
    /*
 
185
      Session::change_item_tree() should be called only if the tree was
 
186
      really transformed, i.e. when a new item has been created.
 
187
      Otherwise we'll be allocating a lot of unnecessary memory for
 
188
      change records at each execution.
 
189
    */
 
190
    if (items[i] != new_item)
 
191
      current_session->change_item_tree(&items[i], new_item);
 
192
  }
 
193
  return (this->*transformer)(arg);
 
194
}
 
195
 
 
196
void Item_row::bring_value()
 
197
{
 
198
  for (uint32_t i= 0; i < arg_count; i++)
 
199
    items[i]->bring_value();
 
200
}
 
201
 
 
202
} /* namespace drizzled */