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 */
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
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
24
27
#include <drizzled/server_includes.h>
28
#include <drizzled/cached_item.h>
29
#include <drizzled/sql_string.h>
30
#include <drizzled/session.h>
27
36
Create right type of Cached_item for an item.
30
Cached_item *new_Cached_item(THD *thd, Item *item, bool use_result_field)
39
Cached_item *new_Cached_item(Session *session, Item *item,
40
bool use_result_field)
32
42
if (item->real_item()->type() == Item::FIELD_ITEM &&
33
43
!(((Item_field *) (item->real_item()))->field->flags & BLOB_FLAG))
40
50
switch (item->result_type()) {
41
51
case STRING_RESULT:
42
return new Cached_item_str(thd, (Item_field *) item);
52
return new Cached_item_str(session, (Item_field *) item);
44
54
return new Cached_item_int((Item_field *) item);
62
72
Return true if values have changed
65
Cached_item_str::Cached_item_str(THD *thd, Item *arg)
66
:item(arg), value(cmin(arg->max_length, (uint32_t)thd->variables.max_sort_length))
75
Cached_item_str::Cached_item_str(Session *session, Item *arg)
76
:item(arg), value(min(arg->max_length,
77
(uint32_t)session->variables.max_sort_length))
69
80
bool Cached_item_str::cmp(void)
74
85
if ((res=item->val_str(&tmp_value)))
75
res->length(cmin(res->length(), value.alloced_length()));
86
res->length(min(res->length(), value.alloced_length()));
77
88
if (null_value != item->null_value)
79
90
if ((null_value= item->null_value))
80
return(true); // New value was null
83
95
else if (null_value)
84
return(0); // new and old value was null
96
// new and old value was null
86
99
tmp= sortcmp(&value,res,item->collation.collation) != 0;
88
value.copy(*res); // Remember for next cmp
101
// Remember for next cmp
92
106
Cached_item_str::~Cached_item_str()
97
112
bool Cached_item_real::cmp(void)
122
137
bool Cached_item_field::cmp(void)
124
bool tmp= field->cmp(buff) != 0; // This is not a blob!
139
// This is not a blob!
140
bool tmp= field->cmp(buff) != 0;
126
143
field->get_image(buff,length,field->charset());
127
144
if (null_value != field->is_null())
163
/*****************************************************************************
164
** Instansiate templates
165
*****************************************************************************/
167
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
168
template class List<Cached_item>;
169
template class List_iterator<Cached_item>;