~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

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