~drizzle-trunk/drizzle/development

584.4.5 by Monty Taylor
Split out cache_row and type_holder.
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
#include <drizzled/server_includes.h>
21
#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.
22
#include <drizzled/table.h>
23
#include <drizzled/session.h>
584.4.5 by Monty Taylor
Split out cache_row and type_holder.
24
25
#include <drizzled/item/cache_row.h>
26
27
28
void Item_cache_row::make_field(Send_field *)
29
{
30
  illegal_method_call((const char*)"make_field");
31
}
32
33
34
double Item_cache_row::val_real()
35
{
36
  illegal_method_call((const char*)"val");
37
  return 0;
38
}
39
40
41
int64_t Item_cache_row::val_int()
42
{
43
  illegal_method_call((const char*)"val_int");
44
  return 0;
45
}
46
47
48
String *Item_cache_row::val_str(String *)
49
{
50
  illegal_method_call((const char*)"val_str");
51
  return 0;
52
}
53
54
55
my_decimal *Item_cache_row::val_decimal(my_decimal *)
56
{
57
  illegal_method_call((const char*)"val_decimal");
58
  return 0;
59
}
60
61
62
enum Item_result Item_cache_row::result_type() const
63
{
64
  return ROW_RESULT;
65
}
66
67
68
uint32_t Item_cache_row::cols()
69
{
70
  return item_count;
71
}
72
73
74
Item *Item_cache_row::element_index(uint32_t i)
75
{
76
  return values[i];
77
}
78
79
80
Item **Item_cache_row::addr(uint32_t i)
81
{
82
  return (Item **) (values + i);
83
}
84
85
86
bool Item_cache_row::allocate(uint32_t num)
87
{
88
  item_count= num;
89
  Session *session= current_session;
90
  return (!(values=
91
            (Item_cache **) session->calloc(sizeof(Item_cache *)*item_count)));
92
}
93
94
95
bool Item_cache_row::setup(Item * item)
96
{
97
  example= item;
98
  if (!values && allocate(item->cols()))
99
    return 1;
100
  for (uint32_t i= 0; i < item_count; i++)
101
  {
102
    Item *el= item->element_index(i);
103
    Item_cache *tmp;
104
    if (!(tmp= values[i]= Item_cache::get_cache(el)))
105
      return 1;
106
    tmp->setup(el);
107
  }
108
  return 0;
109
}
110
111
112
void Item_cache_row::store(Item * item)
113
{
114
  null_value= 0;
115
  item->bring_value();
116
  for (uint32_t i= 0; i < item_count; i++)
117
  {
118
    values[i]->store(item->element_index(i));
119
    null_value|= values[i]->null_value;
120
  }
121
}
122
123
124
void Item_cache_row::illegal_method_call(const char *)
125
{
126
  assert(0);
127
  my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
128
  return;
129
}
130
131
132
bool Item_cache_row::check_cols(uint32_t c)
133
{
134
  if (c != item_count)
135
  {
136
    my_error(ER_OPERAND_COLUMNS, MYF(0), c);
137
    return 1;
138
  }
139
  return 0;
140
}
141
142
143
bool Item_cache_row::null_inside()
144
{
145
  for (uint32_t i= 0; i < item_count; i++)
146
  {
147
    if (values[i]->cols() > 1)
148
    {
149
      if (values[i]->null_inside())
150
        return 1;
151
    }
152
    else
153
    {
154
      values[i]->update_null_value();
155
      if (values[i]->null_value)
156
        return 1;
157
    }
158
  }
159
  return 0;
160
}
161
162
163
void Item_cache_row::bring_value()
164
{
165
  for (uint32_t i= 0; i < item_count; i++)
166
    values[i]->bring_value();
167
  return;
168
}
169
170
171
void Item_cache_row::keep_array()
172
{
173
  save_array= 1;
174
}
175
176
177
void Item_cache_row::cleanup()
178
{
179
  Item_cache::cleanup();
180
  if (save_array)
181
    memset(values, 0, item_count*sizeof(Item**));
182
  else
183
    values= 0;
184
  return;
185
}