~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
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
243.1.17 by Jay Pipes
FINAL PHASE removal of mysql_priv.h (Bye, bye my friend.)
16
#include <drizzled/server_includes.h>
1 by brian
clean slate
17
18
/**
19
  Row items used for comparing rows and IN operations on rows:
20
21
  @verbatim
22
  (a, b, c) > (10, 10, 30)
23
  (a, b, c) = (select c, d, e, from t1 where x=12)
24
  (a, b, c) IN ((1,2,2), (3,4,5), (6,7,8)
25
  (a, b, c) IN (select c, d, e, from t1)
26
  @endverbatim
27
28
  @todo
29
    think placing 2-3 component items in item (as it done for function
30
*/
31
32
Item_row::Item_row(List<Item> &arg):
33
  Item(), used_tables_cache(0), const_item_cache(1), with_null(0)
34
{
35
36
  //TODO: think placing 2-3 component items in item (as it done for function)
37
  if ((arg_count= arg.elements))
38
    items= (Item**) sql_alloc(sizeof(Item*)*arg_count);
39
  else
40
    items= 0;
41
  List_iterator<Item> li(arg);
482 by Brian Aker
Remove uint.
42
  uint32_t i= 0;
1 by brian
clean slate
43
  Item *item;
44
  while ((item= li++))
45
  {
46
    items[i]= item;
47
    i++;    
48
  }
49
}
50
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
51
void Item_row::illegal_method_call(const char *method __attribute__((unused)))
1 by brian
clean slate
52
{
51.1.22 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
53
  assert(0);
1 by brian
clean slate
54
  my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
51.1.22 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
55
  return;
1 by brian
clean slate
56
}
57
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
58
bool Item_row::fix_fields(THD *thd, Item **ref __attribute__((unused)))
1 by brian
clean slate
59
{
51.1.22 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
60
  assert(fixed == 0);
1 by brian
clean slate
61
  null_value= 0;
62
  maybe_null= 0;
63
  Item **arg, **arg_end;
64
  for (arg= items, arg_end= items+arg_count; arg != arg_end ; arg++)
65
  {
66
    if ((*arg)->fix_fields(thd, arg))
51.1.22 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
67
      return true;
1 by brian
clean slate
68
    // we can't assign 'item' before, because fix_fields() can change arg
69
    Item *item= *arg;
70
    used_tables_cache |= item->used_tables();
71
    const_item_cache&= item->const_item() && !with_null;
72
    if (const_item_cache)
73
    {
74
      if (item->cols() > 1)
75
	with_null|= item->null_inside();
76
      else
77
      {
78
	if (item->is_null())
79
          with_null|= 1;
80
      }
81
    }
82
    maybe_null|= item->maybe_null;
83
    with_sum_func= with_sum_func || item->with_sum_func;
84
  }
85
  fixed= 1;
51.1.22 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
86
  return false;
1 by brian
clean slate
87
}
88
89
90
void Item_row::cleanup()
91
{
92
  Item::cleanup();
93
  /* Reset to the original values */
94
  used_tables_cache= 0;
95
  const_item_cache= 1;
96
  with_null= 0;
97
51.1.22 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
98
  return;
1 by brian
clean slate
99
}
100
101
102
void Item_row::split_sum_func(THD *thd, Item **ref_pointer_array,
103
                              List<Item> &fields)
104
{
105
  Item **arg, **arg_end;
106
  for (arg= items, arg_end= items+arg_count; arg != arg_end ; arg++)
51.1.22 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
107
    (*arg)->split_sum_func2(thd, ref_pointer_array, fields, arg, true);
1 by brian
clean slate
108
}
109
110
111
void Item_row::update_used_tables()
112
{
113
  used_tables_cache= 0;
114
  const_item_cache= 1;
482 by Brian Aker
Remove uint.
115
  for (uint32_t i= 0; i < arg_count; i++)
1 by brian
clean slate
116
  {
117
    items[i]->update_used_tables();
118
    used_tables_cache|= items[i]->used_tables();
119
    const_item_cache&= items[i]->const_item();
120
  }
121
}
122
77.1.15 by Monty Taylor
Bunch of warning cleanups.
123
void Item_row::fix_after_pullout(st_select_lex *new_parent,
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
124
                                 Item **ref __attribute__((unused)))
1 by brian
clean slate
125
{
126
  used_tables_cache= 0;
127
  const_item_cache= 1;
482 by Brian Aker
Remove uint.
128
  for (uint32_t i= 0; i < arg_count; i++)
1 by brian
clean slate
129
  {
130
    items[i]->fix_after_pullout(new_parent, &items[i]);
131
    used_tables_cache|= items[i]->used_tables();
132
    const_item_cache&= items[i]->const_item();
133
  }
134
}
135
482 by Brian Aker
Remove uint.
136
bool Item_row::check_cols(uint32_t c)
1 by brian
clean slate
137
{
138
  if (c != arg_count)
139
  {
140
    my_error(ER_OPERAND_COLUMNS, MYF(0), c);
141
    return 1;
142
  }
143
  return 0;
144
}
145
146
void Item_row::print(String *str, enum_query_type query_type)
147
{
148
  str->append('(');
482 by Brian Aker
Remove uint.
149
  for (uint32_t i= 0; i < arg_count; i++)
1 by brian
clean slate
150
  {
151
    if (i)
152
      str->append(',');
153
    items[i]->print(str, query_type);
154
  }
155
  str->append(')');
156
}
157
158
481 by Brian Aker
Remove all of uchar.
159
bool Item_row::walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
1 by brian
clean slate
160
{
482 by Brian Aker
Remove uint.
161
  for (uint32_t i= 0; i < arg_count; i++)
1 by brian
clean slate
162
  {
163
    if (items[i]->walk(processor, walk_subquery, arg))
164
      return 1;
165
  }
166
  return (this->*processor)(arg);
167
}
168
169
481 by Brian Aker
Remove all of uchar.
170
Item *Item_row::transform(Item_transformer transformer, unsigned char *arg)
1 by brian
clean slate
171
{
482 by Brian Aker
Remove uint.
172
  for (uint32_t i= 0; i < arg_count; i++)
1 by brian
clean slate
173
  {
174
    Item *new_item= items[i]->transform(transformer, arg);
175
    if (!new_item)
176
      return 0;
177
178
    /*
179
      THD::change_item_tree() should be called only if the tree was
180
      really transformed, i.e. when a new item has been created.
181
      Otherwise we'll be allocating a lot of unnecessary memory for
182
      change records at each execution.
183
    */
184
    if (items[i] != new_item)
185
      current_thd->change_item_tree(&items[i], new_item);
186
  }
187
  return (this->*transformer)(arg);
188
}
189
190
void Item_row::bring_value()
191
{
482 by Brian Aker
Remove uint.
192
  for (uint32_t i= 0; i < arg_count; i++)
1 by brian
clean slate
193
    items[i]->bring_value();
194
}