drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
function/field.cc
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, Inc.
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
20#include <config.h>
21
22#include <drizzled/function/field.h>
23#include <drizzled/item/cmpfunc.h>
24
25// Conversion functions
26
27namespace drizzled
28{
29
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 type::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 && !class_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 (compare_double(val, args[i]->val_real()) && !args[i]->null_value)
78 {
79 return (int64_t) (i);
80 }
81 }
82 }
83 return 0;
84}
85
86void Item_func_field::fix_length_and_dec()
87{
88 maybe_null=0; max_length=3;
89 cmp_type= args[0]->result_type();
90 for (uint32_t i=1; i < arg_count ; i++)
91 cmp_type= item_cmp_type(cmp_type, args[i]->result_type());
92 if (cmp_type == STRING_RESULT)
93 agg_arg_charsets(cmp_collation, args, arg_count, MY_COLL_CMP_CONV, 1);
94}
95
96} /* namespace drizzled */
String * val_str(String *str)
bool fixed
Definition item.h:122
bool null_value
Definition item.h:124
bool maybe_null
Definition item.h:123
TODO: Rename this file - func.h is stupid.
int class_decimal_cmp(const type::Decimal *a, const type::Decimal *b)