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, bool use_result_field)
32
if (item->real_item()->type() == Item::FIELD_ITEM &&
33
!(((Item_field *) (item->real_item()))->field->flags & BLOB_FLAG))
35
Item_field *real_item= (Item_field *) item->real_item();
36
Field *cached_field= use_result_field ? real_item->result_field :
38
return new Cached_item_field(cached_field);
40
switch (item->result_type()) {
42
return new Cached_item_str(thd, (Item_field *) item);
44
return new Cached_item_int((Item_field *) item);
46
return new Cached_item_real(item);
48
return new Cached_item_decimal(item);
56
Cached_item::~Cached_item() {}
59
Compare with old value and replace value with new value.
62
Return true if values have changed
65
Cached_item_str::Cached_item_str(THD *thd, Item *arg)
66
:item(arg), value(min(arg->max_length, thd->variables.max_sort_length))
69
bool Cached_item_str::cmp(void)
74
DBUG_ENTER("Cached_item_str::cmp");
75
if ((res=item->val_str(&tmp_value)))
76
res->length(min(res->length(), value.alloced_length()));
77
DBUG_PRINT("info", ("old: %s, new: %s",
78
value.c_ptr_safe(), res ? res->c_ptr_safe() : ""));
79
if (null_value != item->null_value)
81
if ((null_value= item->null_value))
82
DBUG_RETURN(TRUE); // New value was null
86
DBUG_RETURN(0); // new and old value was null
88
tmp= sortcmp(&value,res,item->collation.collation) != 0;
90
value.copy(*res); // Remember for next cmp
94
Cached_item_str::~Cached_item_str()
99
bool Cached_item_real::cmp(void)
101
DBUG_ENTER("Cached_item_real::cmp");
102
double nr= item->val_real();
103
DBUG_PRINT("info", ("old: %f, new: %f", value, nr));
104
if (null_value != item->null_value || nr != value)
106
null_value= item->null_value;
113
bool Cached_item_int::cmp(void)
115
DBUG_ENTER("Cached_item_int::cmp");
116
longlong nr=item->val_int();
117
DBUG_PRINT("info", ("old: %Ld, new: %Ld", value, nr));
118
if (null_value != item->null_value || nr != value)
120
null_value= item->null_value;
128
bool Cached_item_field::cmp(void)
130
DBUG_ENTER("Cached_item_field::cmp");
131
bool tmp= field->cmp(buff) != 0; // This is not a blob!
132
DBUG_EXECUTE("info", dbug_print(););
134
field->get_image(buff,length,field->charset());
135
if (null_value != field->is_null())
137
null_value= !null_value;
144
Cached_item_decimal::Cached_item_decimal(Item *it)
147
my_decimal_set_zero(&value);
151
bool Cached_item_decimal::cmp()
154
my_decimal *ptmp= item->val_decimal(&tmp);
155
if (null_value != item->null_value ||
156
(!item->null_value && my_decimal_cmp(&value, ptmp)))
158
null_value= item->null_value;
159
/* Save only not null values */
162
my_decimal2decimal(ptmp, &value);
171
/*****************************************************************************
172
** Instansiate templates
173
*****************************************************************************/
175
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
176
template class List<Cached_item>;
177
template class List_iterator<Cached_item>;