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
22
#include <drizzled/function/field.h>
23
#include <drizzled/item/cmpfunc.h>
25
// Conversion functions
27
int64_t Item_func_field::val_int()
31
if (cmp_type == STRING_RESULT)
34
if (!(field= args[0]->val_str(&value)))
36
for (uint32_t i=1 ; i < arg_count ; i++)
38
String *tmp_value=args[i]->val_str(&tmp);
39
if (tmp_value && !sortcmp(field,tmp_value,cmp_collation.collation))
43
else if (cmp_type == INT_RESULT)
45
int64_t val= args[0]->val_int();
46
if (args[0]->null_value)
48
for (uint32_t i=1; i < arg_count ; i++)
50
if (val == args[i]->val_int() && !args[i]->null_value)
54
else if (cmp_type == DECIMAL_RESULT)
56
my_decimal dec_arg_buf, *dec_arg,
57
dec_buf, *dec= args[0]->val_decimal(&dec_buf);
58
if (args[0]->null_value)
60
for (uint32_t i=1; i < arg_count; i++)
62
dec_arg= args[i]->val_decimal(&dec_arg_buf);
63
if (!args[i]->null_value && !my_decimal_cmp(dec_arg, dec))
69
double val= args[0]->val_real();
70
if (args[0]->null_value)
72
for (uint32_t i=1; i < arg_count ; i++)
74
if (val == args[i]->val_real() && !args[i]->null_value)
81
void Item_func_field::fix_length_and_dec()
83
maybe_null=0; max_length=3;
84
cmp_type= args[0]->result_type();
85
for (uint32_t i=1; i < arg_count ; i++)
86
cmp_type= item_cmp_type(cmp_type, args[i]->result_type());
87
if (cmp_type == STRING_RESULT)
88
agg_arg_charsets(cmp_collation, args, arg_count, MY_COLL_CMP_CONV, 1);