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
20
#include <drizzled/server_includes.h>
22
#include <drizzled/functions/field.h>
24
// Conversion functions
26
int64_t Item_func_field::val_int()
30
if (cmp_type == STRING_RESULT)
33
if (!(field= args[0]->val_str(&value)))
35
for (uint32_t i=1 ; i < arg_count ; i++)
37
String *tmp_value=args[i]->val_str(&tmp);
38
if (tmp_value && !sortcmp(field,tmp_value,cmp_collation.collation))
42
else if (cmp_type == INT_RESULT)
44
int64_t val= args[0]->val_int();
45
if (args[0]->null_value)
47
for (uint32_t i=1; i < arg_count ; i++)
49
if (val == args[i]->val_int() && !args[i]->null_value)
53
else if (cmp_type == DECIMAL_RESULT)
55
my_decimal dec_arg_buf, *dec_arg,
56
dec_buf, *dec= args[0]->val_decimal(&dec_buf);
57
if (args[0]->null_value)
59
for (uint32_t i=1; i < arg_count; i++)
61
dec_arg= args[i]->val_decimal(&dec_arg_buf);
62
if (!args[i]->null_value && !my_decimal_cmp(dec_arg, dec))
68
double val= args[0]->val_real();
69
if (args[0]->null_value)
71
for (uint32_t i=1; i < arg_count ; i++)
73
if (val == args[i]->val_real() && !args[i]->null_value)
80
void Item_func_field::fix_length_and_dec()
82
maybe_null=0; max_length=3;
83
cmp_type= args[0]->result_type();
84
for (uint32_t i=1; i < arg_count ; i++)
85
cmp_type= item_cmp_type(cmp_type, args[i]->result_type());
86
if (cmp_type == STRING_RESULT)
87
agg_arg_charsets(cmp_collation, args, arg_count, MY_COLL_CMP_CONV, 1);