1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
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.
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.
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
1
/* Copyright (C) 2000-2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
24
21
Buffers to save and compare item values
28
#include <drizzled/cached_item.h>
29
#include <drizzled/sql_string.h>
30
#include <drizzled/session.h>
24
#include <drizzled/server_includes.h>
39
27
Create right type of Cached_item for an item.
42
Cached_item *new_Cached_item(Session *session, Item *item)
30
Cached_item *new_Cached_item(Session *session, Item *item, bool use_result_field)
44
32
if (item->real_item()->type() == Item::FIELD_ITEM &&
45
33
!(((Item_field *) (item->real_item()))->field->flags & BLOB_FLAG))
47
35
Item_field *real_item= (Item_field *) item->real_item();
48
Field *cached_field= real_item->field;
36
Field *cached_field= use_result_field ? real_item->result_field :
49
38
return new Cached_item_field(cached_field);
52
40
switch (item->result_type()) {
53
41
case STRING_RESULT:
54
42
return new Cached_item_str(session, (Item_field *) item);
78
65
Cached_item_str::Cached_item_str(Session *session, Item *arg)
79
:item(arg), value(min(arg->max_length,
80
(uint32_t)session->variables.max_sort_length))
66
:item(arg), value(cmin(arg->max_length, (uint32_t)session->variables.max_sort_length))
83
69
bool Cached_item_str::cmp(void)
88
74
if ((res=item->val_str(&tmp_value)))
89
res->length(min(res->length(), value.alloced_length()));
75
res->length(cmin(res->length(), value.alloced_length()));
91
77
if (null_value != item->null_value)
93
79
if ((null_value= item->null_value))
80
return(true); // New value was null
98
83
else if (null_value)
99
// new and old value was null
84
return(0); // new and old value was null
102
86
tmp= sortcmp(&value,res,item->collation.collation) != 0;
104
// Remember for next cmp
88
value.copy(*res); // Remember for next cmp
109
92
Cached_item_str::~Cached_item_str()
115
97
bool Cached_item_real::cmp(void)
140
Cached_item_field::Cached_item_field(Field *arg_field)
144
/* TODO: take the memory allocation below out of the constructor. */
145
buff= (unsigned char*) memory::sql_calloc(length= field->pack_length());
148
122
bool Cached_item_field::cmp(void)
150
// This is not a blob!
151
bool tmp= field->cmp_internal(buff) != 0;
124
bool tmp= field->cmp(buff) != 0; // This is not a blob!
154
126
field->get_image(buff,length,field->charset());
155
127
if (null_value != field->is_null())
164
136
Cached_item_decimal::Cached_item_decimal(Item *it)
139
my_decimal_set_zero(&value);
171
143
bool Cached_item_decimal::cmp()
174
type::Decimal *ptmp= item->val_decimal(&tmp);
146
my_decimal *ptmp= item->val_decimal(&tmp);
175
147
if (null_value != item->null_value ||
176
(!item->null_value && class_decimal_cmp(&value, ptmp)))
148
(!item->null_value && my_decimal_cmp(&value, ptmp)))
178
150
null_value= item->null_value;
179
151
/* Save only not null values */
182
class_decimal2decimal(ptmp, &value);
154
my_decimal2decimal(ptmp, &value);
190
} /* namespace drizzled */
163
/*****************************************************************************
164
** Instansiate templates
165
*****************************************************************************/
167
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
168
template class List<Cached_item>;
169
template class List_iterator<Cached_item>;