~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/cache_row.cc

Merged from fix-headers.

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