489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
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.
|
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
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> |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
21 |
|
2154.2.19
by Brian Aker
Remove need for current_session in include. |
22 |
#include <drizzled/check_stack_overrun.h> |
23 |
#include <drizzled/current_session.h> |
|
24 |
#include <drizzled/error.h> |
|
25 |
#include <drizzled/field/decimal.h> |
|
26 |
#include <drizzled/field/double.h> |
|
2007
by Brian Aker
Refactor naming for integers. |
27 |
#include <drizzled/field/int32.h> |
28 |
#include <drizzled/field/int64.h> |
|
2008.2.3
by Brian Aker
Fixing up a, somewhat, hidden unsigned type to solve a few issues around |
29 |
#include <drizzled/field/size.h> |
2154.2.19
by Brian Aker
Remove need for current_session in include. |
30 |
#include <drizzled/function/math/int.h> |
2234.1.3
by Olaf van der Spek
Refactor includes |
31 |
#include <drizzled/item/field.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. |
32 |
#include <drizzled/session.h> |
2154.2.19
by Brian Aker
Remove need for current_session in include. |
33 |
#include <drizzled/sql_list.h> |
34 |
#include <drizzled/sql_string.h> |
|
35 |
||
919.2.11
by Monty Taylor
Removed C99 isnan() usage, which allows us to remove the util/math.{cc,h} workarounds. Yay for standards! |
36 |
#include <limits> |
1067.4.2
by Nathan Williams
All files in drizzled/function/ now use std::min instead of cmin. |
37 |
#include <algorithm> |
919.2.11
by Monty Taylor
Removed C99 isnan() usage, which allows us to remove the util/math.{cc,h} workarounds. Yay for standards! |
38 |
|
39 |
using namespace std; |
|
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
40 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
41 |
namespace drizzled |
42 |
{
|
|
43 |
||
44 |
||
2154.2.19
by Brian Aker
Remove need for current_session in include. |
45 |
Item_func::Item_func(void): |
46 |
allowed_arg_cols(1), arg_count(0), |
|
47 |
const_item_cache(false) |
|
48 |
{
|
|
49 |
with_sum_func= 0; |
|
50 |
collation.set(DERIVATION_SYSCONST); |
|
51 |
}
|
|
52 |
||
53 |
Item_func::Item_func(Item *a): |
|
54 |
allowed_arg_cols(1), arg_count(1), |
|
55 |
const_item_cache(false) |
|
56 |
{
|
|
57 |
args= tmp_arg; |
|
58 |
args[0]= a; |
|
59 |
with_sum_func= a->with_sum_func; |
|
60 |
collation.set(DERIVATION_SYSCONST); |
|
61 |
}
|
|
62 |
||
63 |
Item_func::Item_func(Item *a,Item *b): |
|
64 |
allowed_arg_cols(1), arg_count(2), |
|
65 |
const_item_cache(false) |
|
66 |
{
|
|
67 |
args= tmp_arg; |
|
68 |
args[0]= a; args[1]= b; |
|
69 |
with_sum_func= a->with_sum_func || b->with_sum_func; |
|
70 |
collation.set(DERIVATION_SYSCONST); |
|
71 |
}
|
|
72 |
||
73 |
Item_func::Item_func(Item *a,Item *b,Item *c): |
|
74 |
allowed_arg_cols(1), |
|
75 |
const_item_cache(false) |
|
76 |
{
|
|
77 |
arg_count= 0; |
|
78 |
if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*3))) |
|
79 |
{
|
|
80 |
arg_count= 3; |
|
81 |
args[0]= a; args[1]= b; args[2]= c; |
|
82 |
with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func; |
|
83 |
}
|
|
84 |
collation.set(DERIVATION_SYSCONST); |
|
85 |
}
|
|
86 |
||
87 |
Item_func::Item_func(Item *a,Item *b,Item *c,Item *d): |
|
88 |
allowed_arg_cols(1), |
|
89 |
const_item_cache(false) |
|
90 |
{
|
|
91 |
arg_count= 0; |
|
92 |
if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*4))) |
|
93 |
{
|
|
94 |
arg_count= 4; |
|
95 |
args[0]= a; args[1]= b; args[2]= c; args[3]= d; |
|
96 |
with_sum_func= a->with_sum_func || b->with_sum_func || |
|
97 |
c->with_sum_func || d->with_sum_func; |
|
98 |
}
|
|
99 |
collation.set(DERIVATION_SYSCONST); |
|
100 |
}
|
|
101 |
||
102 |
Item_func::Item_func(Item *a,Item *b,Item *c,Item *d,Item* e): |
|
103 |
allowed_arg_cols(1), |
|
104 |
const_item_cache(false) |
|
105 |
{
|
|
106 |
arg_count= 5; |
|
107 |
if ((args= (Item**) memory::sql_alloc(sizeof(Item*)*5))) |
|
108 |
{
|
|
109 |
args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e; |
|
110 |
with_sum_func= a->with_sum_func || b->with_sum_func || |
|
111 |
c->with_sum_func || d->with_sum_func || e->with_sum_func ; |
|
112 |
}
|
|
113 |
collation.set(DERIVATION_SYSCONST); |
|
114 |
}
|
|
115 |
||
116 |
||
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
117 |
void Item_func::set_arguments(List<Item> &list) |
118 |
{
|
|
119 |
allowed_arg_cols= 1; |
|
2183.2.17
by Olaf van der Spek
Use List::size() |
120 |
arg_count=list.size(); |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
121 |
args= tmp_arg; // If 2 arguments |
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
122 |
if (arg_count <= 2 || (args=(Item**) memory::sql_alloc(sizeof(Item*)*arg_count))) |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
123 |
{
|
2183.2.11
by Olaf van der Spek
Use List::begin() |
124 |
List<Item>::iterator li(list.begin()); |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
125 |
Item **save_args= args; |
126 |
||
2318.6.64
by Olaf van der Spek
Refactor |
127 |
while (Item* item=li++) |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
128 |
{
|
129 |
*(save_args++)= item; |
|
130 |
with_sum_func|=item->with_sum_func; |
|
131 |
}
|
|
132 |
}
|
|
2179.2.1
by Olaf van der Spek
Rename List::empty to clear (std::list uses clear) |
133 |
list.clear(); // Fields are used |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
134 |
}
|
135 |
||
1633.4.7
by Brian Aker
Put a copy of the Session in the root of function to make use of. |
136 |
Item_func::Item_func(List<Item> &list) : |
2060
by Brian Aker
Added native functions into the function table. |
137 |
allowed_arg_cols(1), |
138 |
const_item_cache(false) |
|
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
139 |
{
|
1717.1.2
by LinuxJedi
Set string functions to use DERIVATION_SYSCONST. |
140 |
collation.set(DERIVATION_SYSCONST); |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
141 |
set_arguments(list); |
142 |
}
|
|
143 |
||
1633.4.7
by Brian Aker
Put a copy of the Session in the root of function to make use of. |
144 |
Item_func::Item_func(Session *session, Item_func *item) : |
145 |
Item_result_field(session, item), |
|
146 |
allowed_arg_cols(item->allowed_arg_cols), |
|
147 |
arg_count(item->arg_count), |
|
148 |
used_tables_cache(item->used_tables_cache), |
|
149 |
not_null_tables_cache(item->not_null_tables_cache), |
|
150 |
const_item_cache(item->const_item_cache) |
|
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
151 |
{
|
152 |
if (arg_count) |
|
153 |
{
|
|
154 |
if (arg_count <=2) |
|
155 |
args= tmp_arg; |
|
156 |
else
|
|
157 |
{
|
|
2318.6.67
by Olaf van der Spek
Refactor |
158 |
args= new (getSession().mem) Item*[arg_count]; |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
159 |
}
|
160 |
memcpy(args, item->args, sizeof(Item*)*arg_count); |
|
161 |
}
|
|
1717.1.2
by LinuxJedi
Set string functions to use DERIVATION_SYSCONST. |
162 |
collation.set(DERIVATION_SYSCONST); |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
163 |
}
|
164 |
||
165 |
||
166 |
/*
|
|
167 |
Resolve references to table column for a function and its argument
|
|
168 |
||
169 |
SYNOPSIS:
|
|
170 |
fix_fields()
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
171 |
session Thread object
|
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
172 |
ref Pointer to where this object is used. This reference
|
173 |
is used if we want to replace this object with another
|
|
174 |
one (for example in the summary functions).
|
|
175 |
||
176 |
DESCRIPTION
|
|
177 |
Call fix_fields() for all arguments to the function. The main intention
|
|
178 |
is to allow all Item_field() objects to setup pointers to the table fields.
|
|
179 |
||
180 |
Sets as a side effect the following class variables:
|
|
181 |
maybe_null Set if any argument may return NULL
|
|
182 |
with_sum_func Set if any of the arguments contains a sum function
|
|
183 |
used_tables_cache Set to union of the tables used by arguments
|
|
184 |
||
185 |
str_value.charset If this is a string function, set this to the
|
|
186 |
character set for the first argument.
|
|
187 |
If any argument is binary, this is set to binary
|
|
188 |
||
189 |
If for any item any of the defaults are wrong, then this can
|
|
190 |
be fixed in the fix_length_and_dec() function that is called
|
|
191 |
after this one or by writing a specialized fix_fields() for the
|
|
192 |
item.
|
|
193 |
||
194 |
RETURN VALUES
|
|
195 |
false ok
|
|
196 |
true Got error. Stored with my_error().
|
|
197 |
*/
|
|
198 |
||
199 |
bool
|
|
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
200 |
Item_func::fix_fields(Session *session, Item **) |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
201 |
{
|
202 |
assert(fixed == 0); |
|
203 |
Item **arg,**arg_end; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
204 |
void *save_session_marker= session->session_marker; |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
205 |
unsigned char buff[STACK_BUFF_ALLOC]; // Max argument in function |
520.1.22
by Brian Aker
Second pass of thd cleanup |
206 |
session->session_marker= 0; |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
207 |
used_tables_cache= not_null_tables_cache= 0; |
2060
by Brian Aker
Added native functions into the function table. |
208 |
const_item_cache= true; |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
209 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
210 |
if (check_stack_overrun(session, STACK_MIN_SIZE, buff)) |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
211 |
return true; // Fatal error if flag is set! |
212 |
if (arg_count) |
|
213 |
{ // Print purify happy |
|
214 |
for (arg=args, arg_end=args+arg_count; arg != arg_end ; arg++) |
|
215 |
{
|
|
216 |
Item *item; |
|
217 |
/*
|
|
218 |
We can't yet set item to *arg as fix_fields may change *arg
|
|
219 |
We shouldn't call fix_fields() twice, so check 'fixed' field first
|
|
220 |
*/
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
221 |
if ((!(*arg)->fixed && (*arg)->fix_fields(session, arg))) |
971.6.11
by Eric Day
Removed purecov messages. |
222 |
return true; |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
223 |
item= *arg; |
224 |
||
225 |
if (allowed_arg_cols) |
|
226 |
{
|
|
227 |
if (item->check_cols(allowed_arg_cols)) |
|
228 |
return 1; |
|
229 |
}
|
|
230 |
else
|
|
231 |
{
|
|
232 |
/* we have to fetch allowed_arg_cols from first argument */
|
|
233 |
assert(arg == args); // it is first argument |
|
234 |
allowed_arg_cols= item->cols(); |
|
235 |
assert(allowed_arg_cols); // Can't be 0 any more |
|
236 |
}
|
|
237 |
||
238 |
if (item->maybe_null) |
|
239 |
maybe_null=1; |
|
240 |
||
241 |
with_sum_func= with_sum_func || item->with_sum_func; |
|
242 |
used_tables_cache|= item->used_tables(); |
|
243 |
not_null_tables_cache|= item->not_null_tables(); |
|
244 |
const_item_cache&= item->const_item(); |
|
245 |
with_subselect|= item->with_subselect; |
|
246 |
}
|
|
247 |
}
|
|
248 |
fix_length_and_dec(); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
249 |
if (session->is_error()) // An error inside fix_length_and_dec occured |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
250 |
return true; |
251 |
fixed= 1; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
252 |
session->session_marker= save_session_marker; |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
253 |
return false; |
254 |
}
|
|
255 |
||
256 |
||
846
by Brian Aker
Removing on typedeffed class. |
257 |
void Item_func::fix_after_pullout(Select_Lex *new_parent, |
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
258 |
Item **) |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
259 |
{
|
260 |
Item **arg,**arg_end; |
|
261 |
||
262 |
used_tables_cache= not_null_tables_cache= 0; |
|
2060
by Brian Aker
Added native functions into the function table. |
263 |
const_item_cache= false; |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
264 |
|
265 |
if (arg_count) |
|
266 |
{
|
|
267 |
for (arg=args, arg_end=args+arg_count; arg != arg_end ; arg++) |
|
268 |
{
|
|
269 |
(*arg)->fix_after_pullout(new_parent, arg); |
|
270 |
Item *item= *arg; |
|
271 |
||
272 |
used_tables_cache|= item->used_tables(); |
|
273 |
not_null_tables_cache|= item->not_null_tables(); |
|
274 |
const_item_cache&= item->const_item(); |
|
275 |
}
|
|
276 |
}
|
|
277 |
}
|
|
278 |
||
279 |
||
280 |
bool Item_func::walk(Item_processor processor, bool walk_subquery, |
|
281 |
unsigned char *argument) |
|
282 |
{
|
|
283 |
if (arg_count) |
|
284 |
{
|
|
285 |
Item **arg,**arg_end; |
|
286 |
for (arg= args, arg_end= args+arg_count; arg != arg_end; arg++) |
|
287 |
{
|
|
288 |
if ((*arg)->walk(processor, walk_subquery, argument)) |
|
289 |
return 1; |
|
290 |
}
|
|
291 |
}
|
|
292 |
return (this->*processor)(argument); |
|
293 |
}
|
|
294 |
||
295 |
void Item_func::traverse_cond(Cond_traverser traverser, |
|
296 |
void *argument, traverse_order order) |
|
297 |
{
|
|
298 |
if (arg_count) |
|
299 |
{
|
|
300 |
Item **arg,**arg_end; |
|
301 |
||
302 |
switch (order) { |
|
798.2.28
by Brian Aker
More pulling of code... master_pos function code removed. |
303 |
case (T_PREFIX): |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
304 |
(*traverser)(this, argument); |
305 |
for (arg= args, arg_end= args+arg_count; arg != arg_end; arg++) |
|
306 |
{
|
|
307 |
(*arg)->traverse_cond(traverser, argument, order); |
|
308 |
}
|
|
309 |
break; |
|
798.2.28
by Brian Aker
More pulling of code... master_pos function code removed. |
310 |
case (T_POSTFIX): |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
311 |
for (arg= args, arg_end= args+arg_count; arg != arg_end; arg++) |
312 |
{
|
|
313 |
(*arg)->traverse_cond(traverser, argument, order); |
|
314 |
}
|
|
315 |
(*traverser)(this, argument); |
|
316 |
}
|
|
317 |
}
|
|
318 |
else
|
|
319 |
(*traverser)(this, argument); |
|
320 |
}
|
|
321 |
||
322 |
||
323 |
/**
|
|
324 |
Transform an Item_func object with a transformer callback function.
|
|
325 |
||
326 |
The function recursively applies the transform method to each
|
|
327 |
argument of the Item_func node.
|
|
328 |
If the call of the method for an argument item returns a new item
|
|
329 |
the old item is substituted for a new one.
|
|
330 |
After this the transformer is applied to the root node
|
|
331 |
of the Item_func object.
|
|
332 |
@param transformer the transformer callback function to be applied to
|
|
333 |
the nodes of the tree of the object
|
|
334 |
@param argument parameter to be passed to the transformer
|
|
335 |
||
336 |
@return
|
|
337 |
Item returned as the result of transformation of the root node
|
|
338 |
*/
|
|
339 |
||
340 |
Item *Item_func::transform(Item_transformer transformer, unsigned char *argument) |
|
341 |
{
|
|
342 |
if (arg_count) |
|
343 |
{
|
|
344 |
Item **arg,**arg_end; |
|
345 |
for (arg= args, arg_end= args+arg_count; arg != arg_end; arg++) |
|
346 |
{
|
|
347 |
Item *new_item= (*arg)->transform(transformer, argument); |
|
348 |
if (!new_item) |
|
349 |
return 0; |
|
2197.3.2
by Olaf van der Spek
Remove Session::change_item_tree |
350 |
*arg= new_item; |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
351 |
}
|
352 |
}
|
|
353 |
return (this->*transformer)(argument); |
|
354 |
}
|
|
355 |
||
356 |
||
357 |
/**
|
|
358 |
Compile Item_func object with a processor and a transformer
|
|
359 |
callback functions.
|
|
360 |
||
361 |
First the function applies the analyzer to the root node of
|
|
362 |
the Item_func object. Then if the analizer succeeeds (returns true)
|
|
363 |
the function recursively applies the compile method to each argument
|
|
364 |
of the Item_func node.
|
|
365 |
If the call of the method for an argument item returns a new item
|
|
366 |
the old item is substituted for a new one.
|
|
367 |
After this the transformer is applied to the root node
|
|
368 |
of the Item_func object.
|
|
369 |
||
370 |
@param analyzer the analyzer callback function to be applied to the
|
|
371 |
nodes of the tree of the object
|
|
372 |
@param[in,out] arg_p parameter to be passed to the processor
|
|
373 |
@param transformer the transformer callback function to be applied to the
|
|
374 |
nodes of the tree of the object
|
|
375 |
@param arg_t parameter to be passed to the transformer
|
|
376 |
||
377 |
@return
|
|
378 |
Item returned as the result of transformation of the root node
|
|
379 |
*/
|
|
380 |
||
381 |
Item *Item_func::compile(Item_analyzer analyzer, unsigned char **arg_p, |
|
382 |
Item_transformer transformer, unsigned char *arg_t) |
|
383 |
{
|
|
384 |
if (!(this->*analyzer)(arg_p)) |
|
385 |
return 0; |
|
386 |
if (arg_count) |
|
387 |
{
|
|
388 |
Item **arg,**arg_end; |
|
389 |
for (arg= args, arg_end= args+arg_count; arg != arg_end; arg++) |
|
390 |
{
|
|
391 |
/*
|
|
392 |
The same parameter value of arg_p must be passed
|
|
393 |
to analyze any argument of the condition formula.
|
|
394 |
*/
|
|
395 |
unsigned char *arg_v= *arg_p; |
|
396 |
Item *new_item= (*arg)->compile(analyzer, &arg_v, transformer, arg_t); |
|
397 |
if (new_item && *arg != new_item) |
|
2197.3.1
by Olaf van der Spek
Remove Session::change_item_tree |
398 |
*arg= new_item; |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
399 |
}
|
400 |
}
|
|
401 |
return (this->*transformer)(arg_t); |
|
402 |
}
|
|
403 |
||
404 |
/**
|
|
405 |
See comments in Item_cmp_func::split_sum_func()
|
|
406 |
*/
|
|
407 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
408 |
void Item_func::split_sum_func(Session *session, Item **ref_pointer_array, |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
409 |
List<Item> &fields) |
410 |
{
|
|
411 |
Item **arg, **arg_end; |
|
412 |
for (arg= args, arg_end= args+arg_count; arg != arg_end ; arg++) |
|
584.4.9
by Monty Taylor
Renamed split_sum_func2 to split_sum_func. It's C++. |
413 |
(*arg)->split_sum_func(session, ref_pointer_array, fields, arg, true); |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
414 |
}
|
415 |
||
416 |
||
417 |
void Item_func::update_used_tables() |
|
418 |
{
|
|
419 |
used_tables_cache=0; |
|
2060
by Brian Aker
Added native functions into the function table. |
420 |
const_item_cache= true; |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
421 |
for (uint32_t i=0 ; i < arg_count ; i++) |
422 |
{
|
|
423 |
args[i]->update_used_tables(); |
|
424 |
used_tables_cache|=args[i]->used_tables(); |
|
425 |
const_item_cache&=args[i]->const_item(); |
|
426 |
}
|
|
427 |
}
|
|
428 |
||
429 |
||
430 |
table_map Item_func::used_tables() const |
|
431 |
{
|
|
432 |
return used_tables_cache; |
|
433 |
}
|
|
434 |
||
435 |
||
436 |
table_map Item_func::not_null_tables() const |
|
437 |
{
|
|
438 |
return not_null_tables_cache; |
|
439 |
}
|
|
440 |
||
441 |
||
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. |
442 |
void Item_func::print(String *str) |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
443 |
{
|
444 |
str->append(func_name()); |
|
445 |
str->append('('); |
|
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. |
446 |
print_args(str, 0); |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
447 |
str->append(')'); |
448 |
}
|
|
449 |
||
450 |
||
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. |
451 |
void Item_func::print_args(String *str, uint32_t from) |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
452 |
{
|
453 |
for (uint32_t i=from ; i < arg_count ; i++) |
|
454 |
{
|
|
455 |
if (i != from) |
|
456 |
str->append(','); |
|
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. |
457 |
args[i]->print(str); |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
458 |
}
|
459 |
}
|
|
460 |
||
461 |
||
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. |
462 |
void Item_func::print_op(String *str) |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
463 |
{
|
464 |
str->append('('); |
|
465 |
for (uint32_t i=0 ; i < arg_count-1 ; i++) |
|
466 |
{
|
|
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. |
467 |
args[i]->print(str); |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
468 |
str->append(' '); |
469 |
str->append(func_name()); |
|
470 |
str->append(' '); |
|
471 |
}
|
|
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. |
472 |
args[arg_count-1]->print(str); |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
473 |
str->append(')'); |
474 |
}
|
|
475 |
||
476 |
||
477 |
bool Item_func::eq(const Item *item, bool binary_cmp) const |
|
478 |
{
|
|
479 |
/* Assume we don't have rtti */
|
|
480 |
if (this == item) |
|
481 |
return 1; |
|
482 |
if (item->type() != FUNC_ITEM) |
|
483 |
return 0; |
|
484 |
Item_func *item_func=(Item_func*) item; |
|
485 |
Item_func::Functype func_type; |
|
486 |
if ((func_type= functype()) != item_func->functype() || |
|
487 |
arg_count != item_func->arg_count || |
|
488 |
(func_type != Item_func::FUNC_SP && |
|
489 |
func_name() != item_func->func_name()) || |
|
490 |
(func_type == Item_func::FUNC_SP && |
|
2456.1.4
by Olaf van der Spek
Refactor |
491 |
system_charset_info->strcasecmp(func_name(), item_func->func_name()))) |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
492 |
return 0; |
493 |
for (uint32_t i=0; i < arg_count ; i++) |
|
494 |
if (!args[i]->eq(item_func->args[i], binary_cmp)) |
|
495 |
return 0; |
|
496 |
return 1; |
|
497 |
}
|
|
498 |
||
499 |
||
2104.2.8
by Brian Aker
Merge in reference from pointer. |
500 |
bool Item_func::get_arg0_date(type::Time <ime, uint32_t fuzzy_date) |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
501 |
{
|
502 |
return (null_value=args[0]->get_date(ltime, fuzzy_date)); |
|
503 |
}
|
|
504 |
||
505 |
||
2104.2.8
by Brian Aker
Merge in reference from pointer. |
506 |
bool Item_func::get_arg0_time(type::Time <ime) |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
507 |
{
|
1999.4.12
by Brian Aker
Adds additional testing, and fixes CAST again. |
508 |
return (null_value= args[0]->get_time(ltime)); |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
509 |
}
|
510 |
||
511 |
||
512 |
bool Item_func::is_null() |
|
513 |
{
|
|
514 |
update_null_value(); |
|
515 |
return null_value; |
|
516 |
}
|
|
517 |
||
518 |
||
519 |
Field *Item_func::tmp_table_field(Table *table) |
|
520 |
{
|
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
521 |
Field *field= NULL; |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
522 |
|
523 |
switch (result_type()) { |
|
524 |
case INT_RESULT: |
|
2008.2.3
by Brian Aker
Fixing up a, somewhat, hidden unsigned type to solve a few issues around |
525 |
if (unsigned_flag) |
526 |
{
|
|
527 |
field= new field::Size(max_length, maybe_null, name, true); |
|
528 |
}
|
|
529 |
else if (max_length > MY_INT32_NUM_DECIMAL_DIGITS) |
|
530 |
{
|
|
531 |
field= new field::Int64(max_length, maybe_null, name, false); |
|
532 |
}
|
|
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
533 |
else
|
2008.2.3
by Brian Aker
Fixing up a, somewhat, hidden unsigned type to solve a few issues around |
534 |
{
|
535 |
field= new field::Int32(max_length, maybe_null, name, false); |
|
536 |
}
|
|
537 |
||
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
538 |
break; |
2008
by Brian Aker
Formatting + remove default from switch/case. |
539 |
|
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
540 |
case REAL_RESULT: |
541 |
field= new Field_double(max_length, maybe_null, name, decimals); |
|
542 |
break; |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
543 |
|
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
544 |
case STRING_RESULT: |
545 |
return make_string_field(table); |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
546 |
|
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
547 |
case DECIMAL_RESULT: |
2430.1.6
by Olaf van der Spek
Merge trunk |
548 |
field= new Field_decimal(class_decimal_precision_to_length(decimal_precision(), decimals, unsigned_flag), |
549 |
maybe_null, name, decimals, unsigned_flag); |
|
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
550 |
break; |
551 |
case ROW_RESULT: |
|
552 |
// This case should never be chosen
|
|
553 |
assert(0); |
|
554 |
break; |
|
555 |
}
|
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
556 |
|
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
557 |
if (field) |
558 |
field->init(table); |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
559 |
|
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
560 |
return field; |
561 |
}
|
|
562 |
||
563 |
||
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
564 |
type::Decimal *Item_func::val_decimal(type::Decimal *decimal_value) |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
565 |
{
|
566 |
assert(fixed); |
|
2030.1.3
by Brian Aker
Second pass through function names. |
567 |
int2_class_decimal(E_DEC_FATAL_ERROR, val_int(), unsigned_flag, decimal_value); |
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
568 |
return decimal_value; |
569 |
}
|
|
570 |
||
571 |
||
572 |
bool Item_func::agg_arg_collations(DTCollation &c, Item **items, |
|
573 |
uint32_t nitems, uint32_t flags) |
|
574 |
{
|
|
575 |
return agg_item_collations(c, func_name(), items, nitems, flags, 1); |
|
576 |
}
|
|
577 |
||
578 |
||
579 |
bool Item_func::agg_arg_collations_for_comparison(DTCollation &c, |
|
580 |
Item **items, |
|
581 |
uint32_t nitems, |
|
582 |
uint32_t flags) |
|
583 |
{
|
|
584 |
return agg_item_collations_for_comparison(c, func_name(), |
|
585 |
items, nitems, flags); |
|
586 |
}
|
|
587 |
||
588 |
||
589 |
bool Item_func::agg_arg_charsets(DTCollation &c, Item **items, uint32_t nitems, |
|
590 |
uint32_t flags, int item_sep) |
|
591 |
{
|
|
592 |
return agg_item_charsets(c, func_name(), items, nitems, flags, item_sep); |
|
593 |
}
|
|
594 |
||
595 |
||
596 |
double Item_func::fix_result(double value) |
|
597 |
{
|
|
919.2.10
by Monty Taylor
Remove C99 isfinite(). |
598 |
static double fix_infinity= numeric_limits<double>::infinity(); |
599 |
||
600 |
if (value != fix_infinity && value != -fix_infinity) |
|
489.1.8
by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one) |
601 |
return value; |
602 |
null_value=1; |
|
603 |
return 0.0; |
|
604 |
}
|
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
605 |
|
606 |
||
607 |
void Item_func::fix_num_length_and_dec() |
|
608 |
{
|
|
609 |
uint32_t fl_length= 0; |
|
610 |
decimals=0; |
|
611 |
for (uint32_t i=0 ; i < arg_count ; i++) |
|
612 |
{
|
|
613 |
set_if_bigger(decimals,args[i]->decimals); |
|
614 |
set_if_bigger(fl_length, args[i]->max_length); |
|
615 |
}
|
|
616 |
max_length=float_length(decimals); |
|
617 |
if (fl_length > max_length) |
|
618 |
{
|
|
619 |
decimals= NOT_FIXED_DEC; |
|
620 |
max_length= float_length(NOT_FIXED_DEC); |
|
621 |
}
|
|
622 |
}
|
|
623 |
||
624 |
/**
|
|
625 |
Set max_length/decimals of function if function is fixed point and
|
|
626 |
result length/precision depends on argument ones.
|
|
627 |
*/
|
|
628 |
||
629 |
void Item_func::count_decimal_length() |
|
630 |
{
|
|
631 |
int max_int_part= 0; |
|
632 |
decimals= 0; |
|
633 |
unsigned_flag= 1; |
|
1067.4.2
by Nathan Williams
All files in drizzled/function/ now use std::min instead of cmin. |
634 |
for (uint32_t i= 0 ; i < arg_count ; i++) |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
635 |
{
|
636 |
set_if_bigger(decimals, args[i]->decimals); |
|
637 |
set_if_bigger(max_int_part, args[i]->decimal_int_part()); |
|
638 |
set_if_smaller(unsigned_flag, args[i]->unsigned_flag); |
|
639 |
}
|
|
1067.4.2
by Nathan Williams
All files in drizzled/function/ now use std::min instead of cmin. |
640 |
int precision= min(max_int_part + decimals, DECIMAL_MAX_PRECISION); |
2030.1.2
by Brian Aker
First pass in refactoring of the name of my_decimal. |
641 |
max_length= class_decimal_precision_to_length(precision, decimals, |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
642 |
unsigned_flag); |
643 |
}
|
|
644 |
||
645 |
||
646 |
/**
|
|
647 |
Set max_length of if it is maximum length of its arguments.
|
|
648 |
*/
|
|
649 |
||
650 |
void Item_func::count_only_length() |
|
651 |
{
|
|
652 |
max_length= 0; |
|
653 |
unsigned_flag= 0; |
|
654 |
for (uint32_t i=0 ; i < arg_count ; i++) |
|
655 |
{
|
|
656 |
set_if_bigger(max_length, args[i]->max_length); |
|
657 |
set_if_bigger(unsigned_flag, args[i]->unsigned_flag); |
|
658 |
}
|
|
659 |
}
|
|
660 |
||
661 |
||
662 |
/**
|
|
663 |
Set max_length/decimals of function if function is floating point and
|
|
664 |
result length/precision depends on argument ones.
|
|
665 |
*/
|
|
666 |
||
667 |
void Item_func::count_real_length() |
|
668 |
{
|
|
669 |
uint32_t length= 0; |
|
670 |
decimals= 0; |
|
671 |
max_length= 0; |
|
672 |
for (uint32_t i=0 ; i < arg_count ; i++) |
|
673 |
{
|
|
674 |
if (decimals != NOT_FIXED_DEC) |
|
675 |
{
|
|
676 |
set_if_bigger(decimals, args[i]->decimals); |
|
677 |
set_if_bigger(length, (args[i]->max_length - args[i]->decimals)); |
|
678 |
}
|
|
679 |
set_if_bigger(max_length, args[i]->max_length); |
|
680 |
}
|
|
681 |
if (decimals != NOT_FIXED_DEC) |
|
682 |
{
|
|
683 |
max_length= length; |
|
684 |
length+= decimals; |
|
685 |
if (length < max_length) // If previous operation gave overflow |
|
686 |
max_length= UINT32_MAX; |
|
687 |
else
|
|
688 |
max_length= length; |
|
689 |
}
|
|
690 |
}
|
|
691 |
||
692 |
||
693 |
||
694 |
void Item_func::signal_divide_by_null() |
|
695 |
{
|
|
1812.4.2
by Brian Aker
Fix issue with divide by zero not being an error. |
696 |
my_error(ER_DIVISION_BY_ZERO, MYF(0)); |
697 |
null_value= 0; |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
698 |
}
|
699 |
||
700 |
||
701 |
Item *Item_func::get_tmp_table_item(Session *session) |
|
702 |
{
|
|
703 |
if (!with_sum_func && !const_item() && functype() != SUSERVAR_FUNC) |
|
704 |
return new Item_field(result_field); |
|
705 |
return copy_or_same(session); |
|
706 |
}
|
|
707 |
||
708 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
709 |
} /* namespace drizzled */ |