~drizzle-trunk/drizzle/development

1 by brian
clean slate
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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
16
#include <config.h>
550 by Monty Taylor
Moved error.h into just the files that need it.
17
#include <drizzled/error.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
18
#include <drizzled/session.h>
584.4.7 by Monty Taylor
Removed a big bank of includes from item.h.
19
#include <drizzled/item/row.h>
20
2318.7.19 by Olaf van der Spek
Refactor Items
21
namespace drizzled {
1253.1.6 by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace.
22
1 by brian
clean slate
23
/**
24
  Row items used for comparing rows and IN operations on rows:
25
26
  @verbatim
27
  (a, b, c) > (10, 10, 30)
28
  (a, b, c) = (select c, d, e, from t1 where x=12)
29
  (a, b, c) IN ((1,2,2), (3,4,5), (6,7,8)
30
  (a, b, c) IN (select c, d, e, from t1)
31
  @endverbatim
32
33
  @todo
34
    think placing 2-3 component items in item (as it done for function
35
*/
36
37
Item_row::Item_row(List<Item> &arg):
38
  Item(), used_tables_cache(0), const_item_cache(1), with_null(0)
39
{
40
41
  //TODO: think placing 2-3 component items in item (as it done for function)
2183.2.17 by Olaf van der Spek
Use List::size()
42
  if ((arg_count= arg.size()))
1253.1.6 by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace.
43
    items= (Item**) memory::sql_alloc(sizeof(Item*)*arg_count);
1 by brian
clean slate
44
  else
45
    items= 0;
2183.2.11 by Olaf van der Spek
Use List::begin()
46
  List<Item>::iterator li(arg.begin());
482 by Brian Aker
Remove uint.
47
  uint32_t i= 0;
2318.7.19 by Olaf van der Spek
Refactor Items
48
  while (Item* item= li++)
1 by brian
clean slate
49
  {
50
    items[i]= item;
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
51
    i++;
1 by brian
clean slate
52
  }
53
}
54
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
55
void Item_row::illegal_method_call(const char *)
1 by brian
clean slate
56
{
2318.7.19 by Olaf van der Spek
Refactor Items
57
  assert(false);
1 by brian
clean slate
58
  my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
59
}
60
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
61
bool Item_row::fix_fields(Session *session, Item **)
1 by brian
clean slate
62
{
51.1.22 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
63
  assert(fixed == 0);
1 by brian
clean slate
64
  null_value= 0;
65
  maybe_null= 0;
66
  Item **arg, **arg_end;
67
  for (arg= items, arg_end= items+arg_count; arg != arg_end ; arg++)
68
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
69
    if ((*arg)->fix_fields(session, arg))
51.1.22 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
70
      return true;
1 by brian
clean slate
71
    // we can't assign 'item' before, because fix_fields() can change arg
72
    Item *item= *arg;
73
    used_tables_cache |= item->used_tables();
74
    const_item_cache&= item->const_item() && !with_null;
75
    if (const_item_cache)
76
    {
77
      if (item->cols() > 1)
78
	with_null|= item->null_inside();
79
      else
80
      {
81
	if (item->is_null())
82
          with_null|= 1;
83
      }
84
    }
85
    maybe_null|= item->maybe_null;
86
    with_sum_func= with_sum_func || item->with_sum_func;
87
  }
88
  fixed= 1;
51.1.22 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
89
  return false;
1 by brian
clean slate
90
}
91
92
93
void Item_row::cleanup()
94
{
95
  Item::cleanup();
96
  /* Reset to the original values */
97
  used_tables_cache= 0;
2060 by Brian Aker
Added native functions into the function table.
98
  const_item_cache= true;
1 by brian
clean slate
99
  with_null= 0;
100
51.1.22 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
101
  return;
1 by brian
clean slate
102
}
103
104
520.1.22 by Brian Aker
Second pass of thd cleanup
105
void Item_row::split_sum_func(Session *session, Item **ref_pointer_array,
1 by brian
clean slate
106
                              List<Item> &fields)
107
{
108
  Item **arg, **arg_end;
109
  for (arg= items, arg_end= items+arg_count; arg != arg_end ; arg++)
584.4.9 by Monty Taylor
Renamed split_sum_func2 to split_sum_func. It's C++.
110
    (*arg)->split_sum_func(session, ref_pointer_array, fields, arg, true);
1 by brian
clean slate
111
}
112
113
114
void Item_row::update_used_tables()
115
{
116
  used_tables_cache= 0;
2060 by Brian Aker
Added native functions into the function table.
117
  const_item_cache= true;
482 by Brian Aker
Remove uint.
118
  for (uint32_t i= 0; i < arg_count; i++)
1 by brian
clean slate
119
  {
120
    items[i]->update_used_tables();
121
    used_tables_cache|= items[i]->used_tables();
122
    const_item_cache&= items[i]->const_item();
123
  }
124
}
125
846 by Brian Aker
Removing on typedeffed class.
126
void Item_row::fix_after_pullout(Select_Lex *new_parent, Item **)
1 by brian
clean slate
127
{
128
  used_tables_cache= 0;
2060 by Brian Aker
Added native functions into the function table.
129
  const_item_cache= true;
482 by Brian Aker
Remove uint.
130
  for (uint32_t i= 0; i < arg_count; i++)
1 by brian
clean slate
131
  {
132
    items[i]->fix_after_pullout(new_parent, &items[i]);
133
    used_tables_cache|= items[i]->used_tables();
134
    const_item_cache&= items[i]->const_item();
135
  }
136
}
137
482 by Brian Aker
Remove uint.
138
bool Item_row::check_cols(uint32_t c)
1 by brian
clean slate
139
{
140
  if (c != arg_count)
141
  {
142
    my_error(ER_OPERAND_COLUMNS, MYF(0), c);
143
    return 1;
144
  }
145
  return 0;
146
}
147
2215.2.1 by Stewart Smith
remove enum_query_type which was effectively unused. It was set to one value once, compared to it once (i.e. always true) and passed around everywhere doing nothing.
148
void Item_row::print(String *str)
1 by brian
clean slate
149
{
150
  str->append('(');
482 by Brian Aker
Remove uint.
151
  for (uint32_t i= 0; i < arg_count; i++)
1 by brian
clean slate
152
  {
153
    if (i)
154
      str->append(',');
2215.2.1 by Stewart Smith
remove enum_query_type which was effectively unused. It was set to one value once, compared to it once (i.e. always true) and passed around everywhere doing nothing.
155
    items[i]->print(str);
1 by brian
clean slate
156
  }
157
  str->append(')');
158
}
159
160
481 by Brian Aker
Remove all of uchar.
161
bool Item_row::walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
1 by brian
clean slate
162
{
482 by Brian Aker
Remove uint.
163
  for (uint32_t i= 0; i < arg_count; i++)
1 by brian
clean slate
164
  {
165
    if (items[i]->walk(processor, walk_subquery, arg))
166
      return 1;
167
  }
168
  return (this->*processor)(arg);
169
}
170
171
481 by Brian Aker
Remove all of uchar.
172
Item *Item_row::transform(Item_transformer transformer, unsigned char *arg)
1 by brian
clean slate
173
{
482 by Brian Aker
Remove uint.
174
  for (uint32_t i= 0; i < arg_count; i++)
1 by brian
clean slate
175
  {
176
    Item *new_item= items[i]->transform(transformer, arg);
177
    if (!new_item)
178
      return 0;
2197.3.2 by Olaf van der Spek
Remove Session::change_item_tree
179
      items[i]= new_item;
1 by brian
clean slate
180
  }
181
  return (this->*transformer)(arg);
182
}
183
184
void Item_row::bring_value()
185
{
482 by Brian Aker
Remove uint.
186
  for (uint32_t i= 0; i < arg_count; i++)
1 by brian
clean slate
187
    items[i]->bring_value();
188
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
189
190
} /* namespace drizzled */