Drizzled Public API Documentation

cache_row.cc
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, Inc.
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 void Item_cache_row::make_field(SendField *)
31 {
32  illegal_method_call("make_field");
33 }
34 
36 {
37  illegal_method_call("val");
38  return 0;
39 }
40 
42 {
43  illegal_method_call("val_int");
44  return 0;
45 }
46 
48 {
49  illegal_method_call("val_str");
50  return 0;
51 }
52 
54 {
55  illegal_method_call("val_decimal");
56  return 0;
57 }
58 
59 enum Item_result Item_cache_row::result_type() const
60 {
61  return ROW_RESULT;
62 }
63 
64 uint32_t Item_cache_row::cols()
65 {
66  return item_count;
67 }
68 
69 Item *Item_cache_row::element_index(uint32_t i)
70 {
71  return values[i];
72 }
73 
74 Item **Item_cache_row::addr(uint32_t i)
75 {
76  return (Item **) (values + i);
77 }
78 
79 void Item_cache_row::allocate(uint32_t num)
80 {
81  item_count= num;
82  values= (Item_cache **) getSession().mem.calloc(sizeof(Item_cache *)*item_count);
83 }
84 
85 bool Item_cache_row::setup(Item * item)
86 {
87  example= item;
88  if (!values)
89  allocate(item->cols());
90  for (uint32_t i= 0; i < item_count; i++)
91  {
92  Item *el= item->element_index(i);
93  Item_cache *tmp= values[i]= Item_cache::get_cache(el);
94  if (!tmp)
95  return 1;
96  tmp->setup(el);
97  }
98  return 0;
99 }
100 
101 void Item_cache_row::store(Item * item)
102 {
103  null_value= 0;
104  item->bring_value();
105  for (uint32_t i= 0; i < item_count; i++)
106  {
107  values[i]->store(item->element_index(i));
108  null_value|= values[i]->null_value;
109  }
110 }
111 
112 void Item_cache_row::illegal_method_call(const char*)
113 {
114  assert(false);
115  my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
116 }
117 
118 bool Item_cache_row::check_cols(uint32_t c)
119 {
120  if (c != item_count)
121  {
122  my_error(ER_OPERAND_COLUMNS, MYF(0), c);
123  return 1;
124  }
125  return 0;
126 }
127 
128 bool Item_cache_row::null_inside()
129 {
130  for (uint32_t i= 0; i < item_count; i++)
131  {
132  if (values[i]->cols() > 1)
133  {
134  if (values[i]->null_inside())
135  return 1;
136  }
137  else
138  {
139  values[i]->update_null_value();
140  if (values[i]->null_value)
141  return 1;
142  }
143  }
144  return 0;
145 }
146 
147 void Item_cache_row::bring_value()
148 {
149  for (uint32_t i= 0; i < item_count; i++)
150  values[i]->bring_value();
151  return;
152 }
153 
154 void Item_cache_row::keep_array()
155 {
156  save_array= 1;
157 }
158 
159 void Item_cache_row::cleanup()
160 {
161  Item_cache::cleanup();
162  if (save_array)
163  memset(values, 0, item_count*sizeof(Item**));
164  else
165  values= 0;
166  return;
167 }
168 
169 } /* namespace drizzled */
TODO: Rename this file - func.h is stupid.
bool null_value
Definition: item.h:122
virtual void update_null_value()
Definition: item.cc:518
type::Decimal * val_decimal(type::Decimal *val)
Definition: cache_row.cc:53
String * val_str(String *val)
Definition: cache_row.cc:47