492.3.31
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
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 |
*/
|
|
19 |
||
1241.9.36
by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h. |
20 |
#include "config.h" |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
21 |
|
670.1.20
by Monty Taylor
Renamed functions to function... everything else is singular. |
22 |
#include <drizzled/function/field.h> |
584.4.7
by Monty Taylor
Removed a big bank of includes from item.h. |
23 |
#include <drizzled/item/cmpfunc.h> |
492.3.31
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
24 |
|
25 |
// Conversion functions
|
|
26 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
27 |
namespace drizzled |
28 |
{
|
|
29 |
||
492.3.31
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
30 |
int64_t Item_func_field::val_int() |
31 |
{
|
|
32 |
assert(fixed == 1); |
|
33 |
||
34 |
if (cmp_type == STRING_RESULT) |
|
35 |
{
|
|
36 |
String *field; |
|
37 |
if (!(field= args[0]->val_str(&value))) |
|
38 |
return 0; |
|
39 |
for (uint32_t i=1 ; i < arg_count ; i++) |
|
40 |
{
|
|
41 |
String *tmp_value=args[i]->val_str(&tmp); |
|
42 |
if (tmp_value && !sortcmp(field,tmp_value,cmp_collation.collation)) |
|
43 |
return (int64_t) (i); |
|
44 |
}
|
|
45 |
}
|
|
46 |
else if (cmp_type == INT_RESULT) |
|
47 |
{
|
|
48 |
int64_t val= args[0]->val_int(); |
|
49 |
if (args[0]->null_value) |
|
50 |
return 0; |
|
51 |
for (uint32_t i=1; i < arg_count ; i++) |
|
52 |
{
|
|
53 |
if (val == args[i]->val_int() && !args[i]->null_value) |
|
54 |
return (int64_t) (i); |
|
55 |
}
|
|
56 |
}
|
|
57 |
else if (cmp_type == DECIMAL_RESULT) |
|
58 |
{
|
|
59 |
my_decimal dec_arg_buf, *dec_arg, |
|
60 |
dec_buf, *dec= args[0]->val_decimal(&dec_buf); |
|
61 |
if (args[0]->null_value) |
|
62 |
return 0; |
|
63 |
for (uint32_t i=1; i < arg_count; i++) |
|
64 |
{
|
|
65 |
dec_arg= args[i]->val_decimal(&dec_arg_buf); |
|
66 |
if (!args[i]->null_value && !my_decimal_cmp(dec_arg, dec)) |
|
67 |
return (int64_t) (i); |
|
68 |
}
|
|
69 |
}
|
|
70 |
else
|
|
71 |
{
|
|
72 |
double val= args[0]->val_real(); |
|
73 |
if (args[0]->null_value) |
|
74 |
return 0; |
|
75 |
for (uint32_t i=1; i < arg_count ; i++) |
|
76 |
{
|
|
77 |
if (val == args[i]->val_real() && !args[i]->null_value) |
|
78 |
return (int64_t) (i); |
|
79 |
}
|
|
80 |
}
|
|
81 |
return 0; |
|
82 |
}
|
|
83 |
||
84 |
void Item_func_field::fix_length_and_dec() |
|
85 |
{
|
|
86 |
maybe_null=0; max_length=3; |
|
87 |
cmp_type= args[0]->result_type(); |
|
88 |
for (uint32_t i=1; i < arg_count ; i++) |
|
89 |
cmp_type= item_cmp_type(cmp_type, args[i]->result_type()); |
|
90 |
if (cmp_type == STRING_RESULT) |
|
91 |
agg_arg_charsets(cmp_collation, args, arg_count, MY_COLL_CMP_CONV, 1); |
|
92 |
}
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
93 |
|
94 |
} /* namespace drizzled */ |