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 */
21
Buffers to save and compare item values
24
#include "mysql_priv.h"
27
Create right type of Cached_item for an item.
30
Cached_item *new_Cached_item(THD *thd, Item *item)
32
if (item->real_item()->type() == Item::FIELD_ITEM &&
33
!(((Item_field *) (item->real_item()))->field->flags & BLOB_FLAG))
34
return new Cached_item_field((Item_field *) (item->real_item()));
35
switch (item->result_type()) {
37
return new Cached_item_str(thd, (Item_field *) item);
39
return new Cached_item_int((Item_field *) item);
41
return new Cached_item_real(item);
43
return new Cached_item_decimal(item);
51
Cached_item::~Cached_item() {}
54
Compare with old value and replace value with new value.
57
Return true if values have changed
60
Cached_item_str::Cached_item_str(THD *thd, Item *arg)
61
:item(arg), value(min(arg->max_length, thd->variables.max_sort_length))
64
bool Cached_item_str::cmp(void)
69
if ((res=item->val_str(&tmp_value)))
70
res->length(min(res->length(), value.alloced_length()));
71
if (null_value != item->null_value)
73
if ((null_value= item->null_value))
74
return TRUE; // New value was null
78
return 0; // new and old value was null
80
tmp= sortcmp(&value,res,item->collation.collation) != 0;
82
value.copy(*res); // Remember for next cmp
86
Cached_item_str::~Cached_item_str()
91
bool Cached_item_real::cmp(void)
93
double nr= item->val_real();
94
if (null_value != item->null_value || nr != value)
96
null_value= item->null_value;
103
bool Cached_item_int::cmp(void)
105
longlong nr=item->val_int();
106
if (null_value != item->null_value || nr != value)
108
null_value= item->null_value;
116
bool Cached_item_field::cmp(void)
118
bool tmp= field->cmp(buff) != 0; // This is not a blob!
120
field->get_image(buff,length,field->charset());
121
if (null_value != field->is_null())
123
null_value= !null_value;
130
Cached_item_decimal::Cached_item_decimal(Item *it)
133
my_decimal_set_zero(&value);
137
bool Cached_item_decimal::cmp()
140
my_decimal *ptmp= item->val_decimal(&tmp);
141
if (null_value != item->null_value ||
142
(!item->null_value && my_decimal_cmp(&value, ptmp)))
144
null_value= item->null_value;
145
/* Save only not null values */
148
my_decimal2decimal(ptmp, &value);
157
/*****************************************************************************
158
** Instansiate templates
159
*****************************************************************************/
161
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
162
template class List<Cached_item>;
163
template class List_iterator<Cached_item>;