~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 *
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; version 2 of the License.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <config.h>

#include <drizzled/error.h>
#include <drizzled/table.h>
#include <drizzled/session.h>

#include <drizzled/item/cache_row.h>

namespace drizzled {

void Item_cache_row::make_field(SendField *)
{
  illegal_method_call("make_field");
}

double Item_cache_row::val_real()
{
  illegal_method_call("val");
  return 0;
}

int64_t Item_cache_row::val_int()
{
  illegal_method_call("val_int");
  return 0;
}

String *Item_cache_row::val_str(String *)
{
  illegal_method_call("val_str");
  return 0;
}

type::Decimal *Item_cache_row::val_decimal(type::Decimal *)
{
  illegal_method_call("val_decimal");
  return 0;
}

enum Item_result Item_cache_row::result_type() const
{
  return ROW_RESULT;
}

uint32_t Item_cache_row::cols()
{
  return item_count;
}

Item *Item_cache_row::element_index(uint32_t i)
{
  return values[i];
}

Item **Item_cache_row::addr(uint32_t i)
{
  return (Item **) (values + i);
}

void Item_cache_row::allocate(uint32_t num)
{
  item_count= num;
  values= (Item_cache **) getSession().mem.calloc(sizeof(Item_cache *)*item_count);
}

bool Item_cache_row::setup(Item * item)
{
  example= item;
  if (!values)
    allocate(item->cols());
  for (uint32_t i= 0; i < item_count; i++)
  {
    Item *el= item->element_index(i);
    Item_cache *tmp= values[i]= Item_cache::get_cache(el);
    if (!tmp)
      return 1;
    tmp->setup(el);
  }
  return 0;
}

void Item_cache_row::store(Item * item)
{
  null_value= 0;
  item->bring_value();
  for (uint32_t i= 0; i < item_count; i++)
  {
    values[i]->store(item->element_index(i));
    null_value|= values[i]->null_value;
  }
}

void Item_cache_row::illegal_method_call(const char*)
{
  assert(false);
  my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
}

bool Item_cache_row::check_cols(uint32_t c)
{
  if (c != item_count)
  {
    my_error(ER_OPERAND_COLUMNS, MYF(0), c);
    return 1;
  }
  return 0;
}

bool Item_cache_row::null_inside()
{
  for (uint32_t i= 0; i < item_count; i++)
  {
    if (values[i]->cols() > 1)
    {
      if (values[i]->null_inside())
        return 1;
    }
    else
    {
      values[i]->update_null_value();
      if (values[i]->null_value)
        return 1;
    }
  }
  return 0;
}

void Item_cache_row::bring_value()
{
  for (uint32_t i= 0; i < item_count; i++)
    values[i]->bring_value();
  return;
}

void Item_cache_row::keep_array()
{
  save_array= 1;
}

void Item_cache_row::cleanup()
{
  Item_cache::cleanup();
  if (save_array)
    memset(values, 0, item_count*sizeof(Item**));
  else
    values= 0;
  return;
}

} /* namespace drizzled */