~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
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
584.4.5 by Monty Taylor
Split out cache_row and type_holder.
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
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
20
#include "config.h"
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
21
584.4.5 by Monty Taylor
Split out cache_row and type_holder.
22
#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.
23
#include <drizzled/table.h>
24
#include <drizzled/session.h>
584.4.5 by Monty Taylor
Split out cache_row and type_holder.
25
26
#include <drizzled/item/cache_row.h>
27
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
28
namespace drizzled
29
{
584.4.5 by Monty Taylor
Split out cache_row and type_holder.
30
1052.2.4 by Nathan Williams
No actual code changes. Changed Send_field to SendField to be consistent with coding standards.
31
void Item_cache_row::make_field(SendField *)
584.4.5 by Monty Taylor
Split out cache_row and type_holder.
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
2030.1.4 by Brian Aker
Change my_decimal to Decimal
58
type::Decimal *Item_cache_row::val_decimal(type::Decimal *)
584.4.5 by Monty Taylor
Split out cache_row and type_holder.
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
  return (!(values=
2137.1.10 by Brian Aker
Fix item so that we have session (ie, it always exists within the context so
93
            (Item_cache **) getSession().calloc(sizeof(Item_cache *)*item_count)));
584.4.5 by Monty Taylor
Split out cache_row and type_holder.
94
}
95
96
97
bool Item_cache_row::setup(Item * item)
98
{
99
  example= item;
100
  if (!values && allocate(item->cols()))
101
    return 1;
102
  for (uint32_t i= 0; i < item_count; i++)
103
  {
104
    Item *el= item->element_index(i);
105
    Item_cache *tmp;
106
    if (!(tmp= values[i]= Item_cache::get_cache(el)))
107
      return 1;
108
    tmp->setup(el);
109
  }
110
  return 0;
111
}
112
113
114
void Item_cache_row::store(Item * item)
115
{
116
  null_value= 0;
117
  item->bring_value();
118
  for (uint32_t i= 0; i < item_count; i++)
119
  {
120
    values[i]->store(item->element_index(i));
121
    null_value|= values[i]->null_value;
122
  }
123
}
124
125
126
void Item_cache_row::illegal_method_call(const char *)
127
{
128
  assert(0);
129
  my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
130
  return;
131
}
132
133
134
bool Item_cache_row::check_cols(uint32_t c)
135
{
136
  if (c != item_count)
137
  {
138
    my_error(ER_OPERAND_COLUMNS, MYF(0), c);
139
    return 1;
140
  }
141
  return 0;
142
}
143
144
145
bool Item_cache_row::null_inside()
146
{
147
  for (uint32_t i= 0; i < item_count; i++)
148
  {
149
    if (values[i]->cols() > 1)
150
    {
151
      if (values[i]->null_inside())
152
        return 1;
153
    }
154
    else
155
    {
156
      values[i]->update_null_value();
157
      if (values[i]->null_value)
158
        return 1;
159
    }
160
  }
161
  return 0;
162
}
163
164
165
void Item_cache_row::bring_value()
166
{
167
  for (uint32_t i= 0; i < item_count; i++)
168
    values[i]->bring_value();
169
  return;
170
}
171
172
173
void Item_cache_row::keep_array()
174
{
175
  save_array= 1;
176
}
177
178
179
void Item_cache_row::cleanup()
180
{
181
  Item_cache::cleanup();
182
  if (save_array)
183
    memset(values, 0, item_count*sizeof(Item**));
184
  else
185
    values= 0;
186
  return;
187
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
188
189
190
} /* namespace drizzled */