584.4.10
by Monty Taylor
Broke out cached_item. |
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
|
|
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 |
*/
|
|
1
by brian
clean slate |
19 |
|
20 |
/**
|
|
21 |
@file
|
|
22 |
||
23 |
@brief
|
|
24 |
Buffers to save and compare item values
|
|
25 |
*/
|
|
26 |
||
243.1.17
by Jay Pipes
FINAL PHASE removal of mysql_priv.h (Bye, bye my friend.) |
27 |
#include <drizzled/server_includes.h> |
584.4.10
by Monty Taylor
Broke out cached_item. |
28 |
#include <drizzled/cached_item.h> |
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
29 |
#include <drizzled/sql_string.h> |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
30 |
#include <drizzled/session.h> |
1067.4.1
by Nathan Williams
First few changes at converting cmin to std::min. |
31 |
#include <algorithm> |
32 |
||
33 |
using namespace std; |
|
1
by brian
clean slate |
34 |
|
35 |
/**
|
|
36 |
Create right type of Cached_item for an item.
|
|
37 |
*/
|
|
38 |
||
584.4.10
by Monty Taylor
Broke out cached_item. |
39 |
Cached_item *new_Cached_item(Session *session, Item *item, |
40 |
bool use_result_field) |
|
1
by brian
clean slate |
41 |
{
|
42 |
if (item->real_item()->type() == Item::FIELD_ITEM && |
|
43 |
!(((Item_field *) (item->real_item()))->field->flags & BLOB_FLAG)) |
|
44 |
{
|
|
45 |
Item_field *real_item= (Item_field *) item->real_item(); |
|
46 |
Field *cached_field= use_result_field ? real_item->result_field : |
|
47 |
real_item->field; |
|
48 |
return new Cached_item_field(cached_field); |
|
49 |
}
|
|
50 |
switch (item->result_type()) { |
|
51 |
case STRING_RESULT: |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
52 |
return new Cached_item_str(session, (Item_field *) item); |
1
by brian
clean slate |
53 |
case INT_RESULT: |
54 |
return new Cached_item_int((Item_field *) item); |
|
55 |
case REAL_RESULT: |
|
56 |
return new Cached_item_real(item); |
|
57 |
case DECIMAL_RESULT: |
|
58 |
return new Cached_item_decimal(item); |
|
59 |
case ROW_RESULT: |
|
60 |
default: |
|
51.1.14
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
61 |
assert(0); |
1
by brian
clean slate |
62 |
return 0; |
63 |
}
|
|
64 |
}
|
|
65 |
||
66 |
Cached_item::~Cached_item() {} |
|
67 |
||
68 |
/**
|
|
69 |
Compare with old value and replace value with new value.
|
|
70 |
||
71 |
@return
|
|
72 |
Return true if values have changed
|
|
73 |
*/
|
|
74 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
75 |
Cached_item_str::Cached_item_str(Session *session, Item *arg) |
1067.4.1
by Nathan Williams
First few changes at converting cmin to std::min. |
76 |
:item(arg), value(min(arg->max_length, |
77 |
(uint32_t)session->variables.max_sort_length)) |
|
1
by brian
clean slate |
78 |
{}
|
79 |
||
80 |
bool Cached_item_str::cmp(void) |
|
81 |
{
|
|
82 |
String *res; |
|
83 |
bool tmp; |
|
84 |
||
85 |
if ((res=item->val_str(&tmp_value))) |
|
1067.4.1
by Nathan Williams
First few changes at converting cmin to std::min. |
86 |
res->length(min(res->length(), value.alloced_length())); |
51.1.14
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
87 |
|
1
by brian
clean slate |
88 |
if (null_value != item->null_value) |
89 |
{
|
|
90 |
if ((null_value= item->null_value)) |
|
584.4.10
by Monty Taylor
Broke out cached_item. |
91 |
// New value was null
|
92 |
return(true); |
|
51.1.14
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
93 |
tmp=true; |
1
by brian
clean slate |
94 |
}
|
95 |
else if (null_value) |
|
584.4.10
by Monty Taylor
Broke out cached_item. |
96 |
// new and old value was null
|
97 |
return(0); |
|
1
by brian
clean slate |
98 |
else
|
99 |
tmp= sortcmp(&value,res,item->collation.collation) != 0; |
|
100 |
if (tmp) |
|
584.4.10
by Monty Taylor
Broke out cached_item. |
101 |
// Remember for next cmp
|
102 |
value.copy(*res); |
|
51.1.14
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
103 |
return(tmp); |
1
by brian
clean slate |
104 |
}
|
105 |
||
106 |
Cached_item_str::~Cached_item_str() |
|
107 |
{
|
|
584.4.10
by Monty Taylor
Broke out cached_item. |
108 |
// Safety
|
109 |
item=0; |
|
1
by brian
clean slate |
110 |
}
|
111 |
||
112 |
bool Cached_item_real::cmp(void) |
|
113 |
{
|
|
114 |
double nr= item->val_real(); |
|
115 |
if (null_value != item->null_value || nr != value) |
|
116 |
{
|
|
117 |
null_value= item->null_value; |
|
118 |
value=nr; |
|
51.1.14
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
119 |
return(true); |
1
by brian
clean slate |
120 |
}
|
51.1.14
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
121 |
return(false); |
1
by brian
clean slate |
122 |
}
|
123 |
||
124 |
bool Cached_item_int::cmp(void) |
|
125 |
{
|
|
152
by Brian Aker
longlong replacement |
126 |
int64_t nr=item->val_int(); |
1
by brian
clean slate |
127 |
if (null_value != item->null_value || nr != value) |
128 |
{
|
|
129 |
null_value= item->null_value; |
|
130 |
value=nr; |
|
51.1.14
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
131 |
return(true); |
1
by brian
clean slate |
132 |
}
|
51.1.14
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
133 |
return(false); |
1
by brian
clean slate |
134 |
}
|
135 |
||
136 |
||
137 |
bool Cached_item_field::cmp(void) |
|
138 |
{
|
|
584.4.10
by Monty Taylor
Broke out cached_item. |
139 |
// This is not a blob!
|
140 |
bool tmp= field->cmp(buff) != 0; |
|
141 |
||
1
by brian
clean slate |
142 |
if (tmp) |
143 |
field->get_image(buff,length,field->charset()); |
|
144 |
if (null_value != field->is_null()) |
|
145 |
{
|
|
146 |
null_value= !null_value; |
|
51.1.14
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
147 |
tmp=true; |
1
by brian
clean slate |
148 |
}
|
51.1.14
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
149 |
return(tmp); |
1
by brian
clean slate |
150 |
}
|
151 |
||
152 |
||
153 |
Cached_item_decimal::Cached_item_decimal(Item *it) |
|
154 |
:item(it) |
|
155 |
{
|
|
156 |
my_decimal_set_zero(&value); |
|
157 |
}
|
|
158 |
||
159 |
||
160 |
bool Cached_item_decimal::cmp() |
|
161 |
{
|
|
162 |
my_decimal tmp; |
|
163 |
my_decimal *ptmp= item->val_decimal(&tmp); |
|
164 |
if (null_value != item->null_value || |
|
165 |
(!item->null_value && my_decimal_cmp(&value, ptmp))) |
|
166 |
{
|
|
167 |
null_value= item->null_value; |
|
168 |
/* Save only not null values */
|
|
169 |
if (!null_value) |
|
170 |
{
|
|
171 |
my_decimal2decimal(ptmp, &value); |
|
51.1.14
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
172 |
return true; |
1
by brian
clean slate |
173 |
}
|
51.1.14
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
174 |
return false; |
1
by brian
clean slate |
175 |
}
|
51.1.14
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
176 |
return false; |
1
by brian
clean slate |
177 |
}
|
178 |
||
179 |