642.1.8
by Lee
move functions from item.cc/item.h to item directory |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
4 |
* Copyright (C) 2008 Sun Microsystems, Inc.
|
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
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 |
*/
|
|
19 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
20 |
#include <config.h> |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
21 |
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
22 |
#include <drizzled/session.h> |
23 |
#include <drizzled/error.h> |
|
24 |
#include <drizzled/show.h> |
|
25 |
#include <drizzled/item/ref.h> |
|
26 |
#include <drizzled/plugin/client.h> |
|
27 |
#include <drizzled/item/sum.h> |
|
2198.1.2
by Olaf van der Spek
Refactor includes |
28 |
#include <drizzled/item/subselect.h> |
2234.1.3
by Olaf van der Spek
Refactor includes |
29 |
#include <drizzled/sql_lex.h> |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
30 |
|
2234.1.3
by Olaf van der Spek
Refactor includes |
31 |
namespace drizzled { |
971.3.65
by Eric Day
Namespace cleanup for Protocol and Listen. |
32 |
|
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
33 |
Item_ref::Item_ref(Name_resolution_context *context_arg, |
34 |
Item **item, const char *table_name_arg, |
|
35 |
const char *field_name_arg, |
|
36 |
bool alias_name_used_arg) |
|
37 |
:Item_ident(context_arg, NULL, table_name_arg, field_name_arg), |
|
38 |
result_field(0), ref(item) |
|
39 |
{
|
|
40 |
alias_name_used= alias_name_used_arg; |
|
41 |
/*
|
|
42 |
This constructor used to create some internals references over fixed items
|
|
43 |
*/
|
|
44 |
if (ref && *ref && (*ref)->fixed) |
|
45 |
set_properties(); |
|
46 |
}
|
|
47 |
||
48 |
||
49 |
/**
|
|
50 |
Resolve the name of a reference to a column reference.
|
|
51 |
||
52 |
The method resolves the column reference represented by 'this' as a column
|
|
53 |
present in one of: GROUP BY clause, SELECT clause, outer queries. It is
|
|
54 |
used typically for columns in the HAVING clause which are not under
|
|
55 |
aggregate functions.
|
|
56 |
||
57 |
POSTCONDITION @n
|
|
58 |
Item_ref::ref is 0 or points to a valid item.
|
|
59 |
||
60 |
@note
|
|
61 |
The name resolution algorithm used is (where [T_j] is an optional table
|
|
62 |
name that qualifies the column name):
|
|
63 |
||
64 |
@code
|
|
65 |
resolve_extended([T_j].col_ref_i)
|
|
66 |
{
|
|
67 |
Search for a column or derived column named col_ref_i [in table T_j]
|
|
68 |
in the SELECT and GROUP clauses of Q.
|
|
69 |
||
70 |
if such a column is NOT found AND // Lookup in outer queries.
|
|
71 |
there are outer queries
|
|
72 |
{
|
|
73 |
for each outer query Q_k beginning from the inner-most one
|
|
74 |
{
|
|
75 |
Search for a column or derived column named col_ref_i
|
|
76 |
[in table T_j] in the SELECT and GROUP clauses of Q_k.
|
|
77 |
||
78 |
if such a column is not found AND
|
|
79 |
- Q_k is not a group query AND
|
|
80 |
- Q_k is not inside an aggregate function
|
|
81 |
OR
|
|
82 |
- Q_(k-1) is not in a HAVING or SELECT clause of Q_k
|
|
83 |
{
|
|
84 |
search for a column or derived column named col_ref_i
|
|
85 |
[in table T_j] in the FROM clause of Q_k;
|
|
86 |
}
|
|
87 |
}
|
|
88 |
}
|
|
89 |
}
|
|
90 |
@endcode
|
|
91 |
@n
|
|
92 |
This procedure treats GROUP BY and SELECT clauses as one namespace for
|
|
93 |
column references in HAVING. Notice that compared to
|
|
94 |
Item_field::fix_fields, here we first search the SELECT and GROUP BY
|
|
95 |
clauses, and then we search the FROM clause.
|
|
96 |
||
97 |
@param[in] session current thread
|
|
98 |
@param[in,out] reference view column if this item was resolved to a
|
|
99 |
view column
|
|
100 |
||
101 |
@todo
|
|
102 |
Here we could first find the field anyway, and then test this
|
|
103 |
condition, so that we can give a better error message -
|
|
104 |
ER_WRONG_FIELD_WITH_GROUP, instead of the less informative
|
|
105 |
ER_BAD_FIELD_ERROR which we produce now.
|
|
106 |
||
107 |
@retval
|
|
108 |
true if error
|
|
109 |
@retval
|
|
110 |
false on success
|
|
111 |
*/
|
|
112 |
||
113 |
bool Item_ref::fix_fields(Session *session, Item **reference) |
|
114 |
{
|
|
115 |
enum_parsing_place place= NO_MATTER; |
|
116 |
assert(fixed == 0); |
|
2227.4.8
by Olaf van der Spek
Session::lex() |
117 |
Select_Lex *current_sel= session->lex().current_select; |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
118 |
|
119 |
if (!ref || ref == not_found_item) |
|
120 |
{
|
|
2318.7.15
by Olaf van der Spek
Remove unused Name_resolution_context::error_reporter |
121 |
if (!(ref= resolve_ref_in_select_and_group(session, this, context->select_lex))) |
122 |
return true; /* Some error occurred (e.g. ambiguous names). */ |
|
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
123 |
|
124 |
if (ref == not_found_item) /* This reference was not resolved. */ |
|
125 |
{
|
|
126 |
Name_resolution_context *last_checked_context= context; |
|
127 |
Name_resolution_context *outer_context= context->outer_context; |
|
128 |
Field *from_field; |
|
129 |
ref= 0; |
|
130 |
||
131 |
if (!outer_context) |
|
132 |
{
|
|
133 |
/* The current reference cannot be resolved in this query. */
|
|
2318.7.15
by Olaf van der Spek
Remove unused Name_resolution_context::error_reporter |
134 |
my_error(ER_BAD_FIELD_ERROR,MYF(0), full_name(), session->where()); |
135 |
return true; |
|
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
136 |
}
|
137 |
||
138 |
/*
|
|
139 |
If there is an outer context (select), and it is not a derived table
|
|
140 |
(which do not support the use of outer fields for now), try to
|
|
141 |
resolve this reference in the outer select(s).
|
|
142 |
||
143 |
We treat each subselect as a separate namespace, so that different
|
|
144 |
subselects may contain columns with the same names. The subselects are
|
|
145 |
searched starting from the innermost.
|
|
146 |
*/
|
|
147 |
from_field= (Field*) not_found_field; |
|
148 |
||
149 |
do
|
|
150 |
{
|
|
846
by Brian Aker
Removing on typedeffed class. |
151 |
Select_Lex *select= outer_context->select_lex; |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
152 |
Item_subselect *prev_subselect_item= |
153 |
last_checked_context->select_lex->master_unit()->item; |
|
154 |
last_checked_context= outer_context; |
|
155 |
||
156 |
/* Search in the SELECT and GROUP lists of the outer select. */
|
|
157 |
if (outer_context->resolve_in_select_list) |
|
158 |
{
|
|
159 |
if (!(ref= resolve_ref_in_select_and_group(session, this, select))) |
|
2318.7.15
by Olaf van der Spek
Remove unused Name_resolution_context::error_reporter |
160 |
return true; /* Some error occurred (e.g. ambiguous names). */ |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
161 |
if (ref != not_found_item) |
162 |
{
|
|
163 |
assert(*ref && (*ref)->fixed); |
|
164 |
prev_subselect_item->used_tables_cache|= (*ref)->used_tables(); |
|
165 |
prev_subselect_item->const_item_cache&= (*ref)->const_item(); |
|
166 |
break; |
|
167 |
}
|
|
168 |
/*
|
|
169 |
Set ref to 0 to ensure that we get an error in case we replaced
|
|
170 |
this item with another item and still use this item in some
|
|
171 |
other place of the parse tree.
|
|
172 |
*/
|
|
173 |
ref= 0; |
|
174 |
}
|
|
175 |
||
176 |
place= prev_subselect_item->parsing_place; |
|
177 |
/*
|
|
178 |
Check table fields only if the subquery is used somewhere out of
|
|
179 |
HAVING or the outer SELECT does not use grouping (i.e. tables are
|
|
180 |
accessible).
|
|
181 |
TODO:
|
|
182 |
Here we could first find the field anyway, and then test this
|
|
183 |
condition, so that we can give a better error message -
|
|
184 |
ER_WRONG_FIELD_WITH_GROUP, instead of the less informative
|
|
185 |
ER_BAD_FIELD_ERROR which we produce now.
|
|
1669.3.2
by Brian Aker
This fixes the issue with case and unordered map. |
186 |
|
187 |
@todo determine if this is valid.
|
|
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
188 |
*/
|
189 |
if ((place != IN_HAVING || |
|
190 |
(!select->with_sum_func && |
|
191 |
select->group_list.elements == 0))) |
|
192 |
{
|
|
193 |
/*
|
|
194 |
In case of view, find_field_in_tables() write pointer to view
|
|
195 |
field expression to 'reference', i.e. it substitute that
|
|
196 |
expression instead of this Item_ref
|
|
197 |
*/
|
|
198 |
from_field= find_field_in_tables(session, this, |
|
199 |
outer_context-> |
|
200 |
first_name_resolution_table, |
|
201 |
outer_context-> |
|
202 |
last_name_resolution_table, |
|
203 |
reference, |
|
1113.1.1
by Brian Aker
Dead code removal around LCOV finds. |
204 |
IGNORE_EXCEPT_NON_UNIQUE, true); |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
205 |
if (! from_field) |
2318.7.15
by Olaf van der Spek
Remove unused Name_resolution_context::error_reporter |
206 |
return true; |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
207 |
if (from_field == view_ref_found) |
208 |
{
|
|
209 |
Item::Type refer_type= (*reference)->type(); |
|
210 |
prev_subselect_item->used_tables_cache|= |
|
211 |
(*reference)->used_tables(); |
|
212 |
prev_subselect_item->const_item_cache&= |
|
213 |
(*reference)->const_item(); |
|
214 |
assert((*reference)->type() == REF_ITEM); |
|
215 |
mark_as_dependent(session, last_checked_context->select_lex, |
|
216 |
context->select_lex, this, |
|
217 |
((refer_type == REF_ITEM || |
|
218 |
refer_type == FIELD_ITEM) ? |
|
219 |
(Item_ident*) (*reference) : |
|
220 |
0)); |
|
221 |
/*
|
|
222 |
view reference found, we substituted it instead of this
|
|
223 |
Item, so can quit
|
|
224 |
*/
|
|
225 |
return false; |
|
226 |
}
|
|
227 |
if (from_field != not_found_field) |
|
228 |
{
|
|
229 |
if (cached_table && cached_table->select_lex && |
|
230 |
outer_context->select_lex && |
|
231 |
cached_table->select_lex != outer_context->select_lex) |
|
232 |
{
|
|
233 |
/*
|
|
234 |
Due to cache, find_field_in_tables() can return field which
|
|
235 |
doesn't belong to provided outer_context. In this case we have
|
|
236 |
to find proper field context in order to fix field correcly.
|
|
237 |
*/
|
|
238 |
do
|
|
239 |
{
|
|
240 |
outer_context= outer_context->outer_context; |
|
241 |
select= outer_context->select_lex; |
|
242 |
prev_subselect_item= |
|
243 |
last_checked_context->select_lex->master_unit()->item; |
|
244 |
last_checked_context= outer_context; |
|
245 |
} while (outer_context && outer_context->select_lex && |
|
246 |
cached_table->select_lex != outer_context->select_lex); |
|
247 |
}
|
|
1660.1.3
by Brian Aker
Encapsulate Table in field |
248 |
prev_subselect_item->used_tables_cache|= from_field->getTable()->map; |
2060
by Brian Aker
Added native functions into the function table. |
249 |
prev_subselect_item->const_item_cache= false; |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
250 |
break; |
251 |
}
|
|
252 |
}
|
|
253 |
assert(from_field == not_found_field); |
|
254 |
||
255 |
/* Reference is not found => depend on outer (or just error). */
|
|
256 |
prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT; |
|
2060
by Brian Aker
Added native functions into the function table. |
257 |
prev_subselect_item->const_item_cache= false; |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
258 |
|
259 |
outer_context= outer_context->outer_context; |
|
260 |
} while (outer_context); |
|
261 |
||
262 |
assert(from_field != 0 && from_field != view_ref_found); |
|
263 |
if (from_field != not_found_field) |
|
264 |
{
|
|
265 |
Item_field* fld; |
|
2318.6.90
by Olaf van der Spek
Refactor |
266 |
fld= new Item_field(from_field); |
2197.3.1
by Olaf van der Spek
Remove Session::change_item_tree |
267 |
*reference= fld; |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
268 |
mark_as_dependent(session, last_checked_context->select_lex, |
2227.4.8
by Olaf van der Spek
Session::lex() |
269 |
session->lex().current_select, this, fld); |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
270 |
/*
|
271 |
A reference is resolved to a nest level that's outer or the same as
|
|
272 |
the nest level of the enclosing set function : adjust the value of
|
|
273 |
max_arg_level for the function if it's needed.
|
|
274 |
*/
|
|
2227.4.8
by Olaf van der Spek
Session::lex() |
275 |
if (session->lex().in_sum_func && |
276 |
session->lex().in_sum_func->nest_level >= |
|
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
277 |
last_checked_context->select_lex->nest_level) |
2227.4.8
by Olaf van der Spek
Session::lex() |
278 |
set_if_bigger(session->lex().in_sum_func->max_arg_level, |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
279 |
last_checked_context->select_lex->nest_level); |
280 |
return false; |
|
281 |
}
|
|
282 |
if (ref == 0) |
|
283 |
{
|
|
284 |
/* The item was not a table field and not a reference */
|
|
2318.7.15
by Olaf van der Spek
Remove unused Name_resolution_context::error_reporter |
285 |
my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), session->where()); |
286 |
return true; |
|
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
287 |
}
|
288 |
/* Should be checked in resolve_ref_in_select_and_group(). */
|
|
289 |
assert(*ref && (*ref)->fixed); |
|
290 |
mark_as_dependent(session, last_checked_context->select_lex, |
|
291 |
context->select_lex, this, this); |
|
292 |
/*
|
|
293 |
A reference is resolved to a nest level that's outer or the same as
|
|
294 |
the nest level of the enclosing set function : adjust the value of
|
|
295 |
max_arg_level for the function if it's needed.
|
|
296 |
*/
|
|
2227.4.8
by Olaf van der Spek
Session::lex() |
297 |
if (session->lex().in_sum_func && |
298 |
session->lex().in_sum_func->nest_level >= |
|
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
299 |
last_checked_context->select_lex->nest_level) |
2227.4.8
by Olaf van der Spek
Session::lex() |
300 |
set_if_bigger(session->lex().in_sum_func->max_arg_level, |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
301 |
last_checked_context->select_lex->nest_level); |
302 |
}
|
|
303 |
}
|
|
304 |
||
305 |
assert(*ref); |
|
306 |
/*
|
|
307 |
Check if this is an incorrect reference in a group function or forward
|
|
308 |
reference. Do not issue an error if this is:
|
|
309 |
1. outer reference (will be fixed later by the fix_inner_refs function);
|
|
310 |
2. an unnamed reference inside an aggregate function.
|
|
311 |
*/
|
|
312 |
if (!((*ref)->type() == REF_ITEM && |
|
313 |
((Item_ref *)(*ref))->ref_type() == OUTER_REF) && |
|
314 |
(((*ref)->with_sum_func && name && |
|
315 |
!(current_sel->linkage != GLOBAL_OPTIONS_TYPE && |
|
316 |
current_sel->having_fix_field)) || |
|
317 |
!(*ref)->fixed)) |
|
318 |
{
|
|
2318.7.15
by Olaf van der Spek
Remove unused Name_resolution_context::error_reporter |
319 |
my_error(ER_ILLEGAL_REFERENCE, MYF(0), name, ((*ref)->with_sum_func ? "reference to group function" : "forward reference in item list")); |
320 |
return true; |
|
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
321 |
}
|
322 |
||
323 |
set_properties(); |
|
324 |
||
325 |
if ((*ref)->check_cols(1)) |
|
2318.7.15
by Olaf van der Spek
Remove unused Name_resolution_context::error_reporter |
326 |
return true; |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
327 |
return false; |
328 |
}
|
|
329 |
||
330 |
||
331 |
void Item_ref::set_properties() |
|
332 |
{
|
|
333 |
max_length= (*ref)->max_length; |
|
334 |
maybe_null= (*ref)->maybe_null; |
|
335 |
decimals= (*ref)->decimals; |
|
336 |
collation.set((*ref)->collation); |
|
337 |
/*
|
|
338 |
We have to remember if we refer to a sum function, to ensure that
|
|
339 |
split_sum_func() doesn't try to change the reference.
|
|
340 |
*/
|
|
341 |
with_sum_func= (*ref)->with_sum_func; |
|
342 |
unsigned_flag= (*ref)->unsigned_flag; |
|
343 |
fixed= 1; |
|
344 |
if (alias_name_used) |
|
345 |
return; |
|
346 |
if ((*ref)->type() == FIELD_ITEM) |
|
347 |
alias_name_used= ((Item_ident *) (*ref))->alias_name_used; |
|
348 |
else
|
|
349 |
alias_name_used= true; // it is not field, so it is was resolved by alias |
|
350 |
}
|
|
351 |
||
352 |
||
353 |
void Item_ref::cleanup() |
|
354 |
{
|
|
355 |
Item_ident::cleanup(); |
|
356 |
result_field= 0; |
|
357 |
return; |
|
358 |
}
|
|
359 |
||
360 |
||
2215.2.1
by Stewart Smith
remove enum_query_type which was effectively unused. It was set to one value once, compared to it once (i.e. always true) and passed around everywhere doing nothing. |
361 |
void Item_ref::print(String *str) |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
362 |
{
|
363 |
if (ref) |
|
364 |
{
|
|
365 |
if ((*ref)->type() != Item::CACHE_ITEM && |
|
366 |
!table_name && name && alias_name_used) |
|
367 |
{
|
|
2318.8.1
by Olaf van der Spek
Add data_ref.h |
368 |
str->append_identifier(str_ref(name)); |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
369 |
}
|
370 |
else
|
|
2215.2.1
by Stewart Smith
remove enum_query_type which was effectively unused. It was set to one value once, compared to it once (i.e. always true) and passed around everywhere doing nothing. |
371 |
(*ref)->print(str); |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
372 |
}
|
373 |
else
|
|
2215.2.1
by Stewart Smith
remove enum_query_type which was effectively unused. It was set to one value once, compared to it once (i.e. always true) and passed around everywhere doing nothing. |
374 |
Item_ident::print(str); |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
375 |
}
|
376 |
||
377 |
||
2313.3.7
by Olaf van der Spek
Return void |
378 |
void Item_ref::send(plugin::Client *client, String *tmp) |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
379 |
{
|
380 |
if (result_field) |
|
2313.3.6
by Olaf van der Spek
Return void |
381 |
{
|
382 |
client->store(result_field); |
|
2313.3.7
by Olaf van der Spek
Return void |
383 |
return; |
2313.3.6
by Olaf van der Spek
Return void |
384 |
}
|
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
385 |
return (*ref)->send(client, tmp); |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
386 |
}
|
387 |
||
388 |
||
389 |
double Item_ref::val_result() |
|
390 |
{
|
|
391 |
if (result_field) |
|
392 |
{
|
|
393 |
if ((null_value= result_field->is_null())) |
|
394 |
return 0.0; |
|
395 |
return result_field->val_real(); |
|
396 |
}
|
|
397 |
return val_real(); |
|
398 |
}
|
|
399 |
||
400 |
||
401 |
int64_t Item_ref::val_int_result() |
|
402 |
{
|
|
403 |
if (result_field) |
|
404 |
{
|
|
405 |
if ((null_value= result_field->is_null())) |
|
406 |
return 0; |
|
407 |
return result_field->val_int(); |
|
408 |
}
|
|
409 |
return val_int(); |
|
410 |
}
|
|
411 |
||
412 |
||
413 |
String *Item_ref::str_result(String* str) |
|
414 |
{
|
|
415 |
if (result_field) |
|
416 |
{
|
|
417 |
if ((null_value= result_field->is_null())) |
|
418 |
return 0; |
|
419 |
str->set_charset(str_value.charset()); |
|
420 |
return result_field->val_str(str, &str_value); |
|
421 |
}
|
|
422 |
return val_str(str); |
|
423 |
}
|
|
424 |
||
425 |
||
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
426 |
type::Decimal *Item_ref::val_decimal_result(type::Decimal *decimal_value) |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
427 |
{
|
428 |
if (result_field) |
|
429 |
{
|
|
430 |
if ((null_value= result_field->is_null())) |
|
431 |
return 0; |
|
432 |
return result_field->val_decimal(decimal_value); |
|
433 |
}
|
|
434 |
return val_decimal(decimal_value); |
|
435 |
}
|
|
436 |
||
437 |
||
438 |
bool Item_ref::val_bool_result() |
|
439 |
{
|
|
440 |
if (result_field) |
|
441 |
{
|
|
442 |
if ((null_value= result_field->is_null())) |
|
443 |
return 0; |
|
444 |
switch (result_field->result_type()) { |
|
445 |
case INT_RESULT: |
|
446 |
return result_field->val_int() != 0; |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
447 |
|
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
448 |
case DECIMAL_RESULT: |
2008
by Brian Aker
Formatting + remove default from switch/case. |
449 |
{
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
450 |
type::Decimal decimal_value; |
451 |
type::Decimal *val= result_field->val_decimal(&decimal_value); |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
452 |
if (val) |
2137.1.5
by Brian Aker
Additional decimal. |
453 |
return not val->isZero(); |
2008
by Brian Aker
Formatting + remove default from switch/case. |
454 |
return 0; |
455 |
}
|
|
456 |
||
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
457 |
case REAL_RESULT: |
458 |
case STRING_RESULT: |
|
459 |
return result_field->val_real() != 0.0; |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
460 |
|
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
461 |
case ROW_RESULT: |
462 |
assert(0); |
|
463 |
}
|
|
464 |
}
|
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
465 |
|
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
466 |
return val_bool(); |
467 |
}
|
|
468 |
||
469 |
||
470 |
double Item_ref::val_real() |
|
471 |
{
|
|
472 |
assert(fixed); |
|
473 |
double tmp=(*ref)->val_result(); |
|
474 |
null_value=(*ref)->null_value; |
|
475 |
return tmp; |
|
476 |
}
|
|
477 |
||
478 |
||
479 |
int64_t Item_ref::val_int() |
|
480 |
{
|
|
481 |
assert(fixed); |
|
482 |
int64_t tmp=(*ref)->val_int_result(); |
|
483 |
null_value=(*ref)->null_value; |
|
484 |
return tmp; |
|
485 |
}
|
|
486 |
||
487 |
||
488 |
bool Item_ref::val_bool() |
|
489 |
{
|
|
490 |
assert(fixed); |
|
491 |
bool tmp= (*ref)->val_bool_result(); |
|
492 |
null_value= (*ref)->null_value; |
|
493 |
return tmp; |
|
494 |
}
|
|
495 |
||
496 |
||
497 |
String *Item_ref::val_str(String* tmp) |
|
498 |
{
|
|
499 |
assert(fixed); |
|
500 |
tmp=(*ref)->str_result(tmp); |
|
501 |
null_value=(*ref)->null_value; |
|
502 |
return tmp; |
|
503 |
}
|
|
504 |
||
505 |
||
506 |
bool Item_ref::is_null() |
|
507 |
{
|
|
508 |
assert(fixed); |
|
509 |
return (*ref)->is_null(); |
|
510 |
}
|
|
511 |
||
512 |
||
2104.2.8
by Brian Aker
Merge in reference from pointer. |
513 |
bool Item_ref::get_date(type::Time <ime,uint32_t fuzzydate) |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
514 |
{
|
515 |
return (null_value=(*ref)->get_date_result(ltime,fuzzydate)); |
|
516 |
}
|
|
517 |
||
518 |
||
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
519 |
type::Decimal *Item_ref::val_decimal(type::Decimal *decimal_value) |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
520 |
{
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
521 |
type::Decimal *val= (*ref)->val_decimal_result(decimal_value); |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
522 |
null_value= (*ref)->null_value; |
523 |
return val; |
|
524 |
}
|
|
525 |
||
526 |
int Item_ref::save_in_field(Field *to, bool no_conversions) |
|
527 |
{
|
|
528 |
int res; |
|
529 |
assert(!result_field); |
|
530 |
res= (*ref)->save_in_field(to, no_conversions); |
|
531 |
null_value= (*ref)->null_value; |
|
532 |
return res; |
|
533 |
}
|
|
534 |
||
535 |
||
536 |
void Item_ref::save_org_in_field(Field *field) |
|
537 |
{
|
|
538 |
(*ref)->save_org_in_field(field); |
|
539 |
}
|
|
540 |
||
541 |
||
1052.2.4
by Nathan Williams
No actual code changes. Changed Send_field to SendField to be consistent with coding standards. |
542 |
void Item_ref::make_field(SendField *field) |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
543 |
{
|
544 |
(*ref)->make_field(field); |
|
545 |
/* Non-zero in case of a view */
|
|
546 |
if (name) |
|
547 |
field->col_name= name; |
|
548 |
if (table_name) |
|
549 |
field->table_name= table_name; |
|
550 |
if (db_name) |
|
551 |
field->db_name= db_name; |
|
552 |
}
|
|
553 |
||
554 |
||
555 |
Item *Item_ref::get_tmp_table_item(Session *session) |
|
556 |
{
|
|
557 |
if (!result_field) |
|
558 |
return (*ref)->get_tmp_table_item(session); |
|
559 |
||
560 |
Item_field *item= new Item_field(result_field); |
|
561 |
if (item) |
|
562 |
{
|
|
563 |
item->table_name= table_name; |
|
564 |
item->db_name= db_name; |
|
565 |
}
|
|
566 |
return item; |
|
567 |
}
|
|
568 |
||
846
by Brian Aker
Removing on typedeffed class. |
569 |
void Item_ref::fix_after_pullout(Select_Lex *new_parent, Item **) |
642.1.8
by Lee
move functions from item.cc/item.h to item directory |
570 |
{
|
571 |
if (depended_from == new_parent) |
|
572 |
{
|
|
573 |
(*ref)->fix_after_pullout(new_parent, ref); |
|
574 |
depended_from= NULL; |
|
575 |
}
|
|
576 |
}
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
577 |
|
578 |
} /* namespace drizzled */ |